brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.6 KiB · b9e3a79 Raw
156 lines · plain
1// RUN: mlir-tblgen -gen-typedef-decls -I %S/../../include %s | FileCheck %s --check-prefix=DECL2// RUN: mlir-tblgen -gen-typedef-defs -I %S/../../include %s | FileCheck %s --check-prefix=DEF3 4include "mlir/IR/AttrTypeBase.td"5include "mlir/IR/OpBase.td"6 7// DECL: #ifdef GET_TYPEDEF_CLASSES8// DECL: #undef GET_TYPEDEF_CLASSES9 10// DECL: namespace mlir {11// DECL: class AsmParser;12// DECL: class AsmPrinter;13// DECL: } // namespace mlir14 15// DEF: #ifdef GET_TYPEDEF_LIST16// DEF: #undef GET_TYPEDEF_LIST17// DEF: ::test::SimpleAType,18// DEF: ::test::CompoundAType,19// DEF: ::test::IndexType,20// DEF: ::test::SingleParameterType,21// DEF: ::test::IntegerType22 23// DEF-LABEL: ::mlir::OptionalParseResult generatedTypeParser(24// DEF-SAME: ::mlir::AsmParser &parser,25// DEF-SAME: ::llvm::StringRef *mnemonic,26// DEF-SAME: ::mlir::Type &value) {27// DEF: .Case(::test::CompoundAType::getMnemonic()28// DEF-NEXT:   value = ::test::CompoundAType::parse(parser);29// DEF-NEXT:   return ::mlir::success(!!value);30// DEF-NEXT: })31// DEF-NEXT: .Case(::test::IndexType::getMnemonic()32// DEF-NEXT:   value = ::test::IndexType::parse(parser);33// DEF-NEXT:   return ::mlir::success(!!value);34// DEF: .Default([&](llvm::StringRef keyword,35// DEF-NEXT:   *mnemonic = keyword;36// DEF-NEXT:   return std::nullopt;37 38def Test_Dialect: Dialect {39// DECL-NOT: TestDialect40  let name = "TestDialect";41  let cppNamespace = "::test";42}43 44class TestType<string name> : TypeDef<Test_Dialect, name> { }45 46def A_SimpleTypeA : TestType<"SimpleA"> {47// DECL: class SimpleAType : public ::mlir::Type48  let typeName = "test.simple_a";49}50 51def RTLValueType : Type<CPred<"isRTLValueType($_self)">, "Type"> {52  string cppType = "::mlir::Type";53}54 55// A more complex parameterized type56def B_CompoundTypeA : TestType<"CompoundA"> {57  let summary = "A more complex parameterized type";58  let description = "This type is to test a reasonably complex type";59  let mnemonic = "cmpnd_a";60  let parameters = (ins61    "int":$widthOfSomething,62    "::test::SimpleTypeA": $exampleTdType,63    "SomeCppStruct": $exampleCppType,64    ArrayRefParameter<"int", "Matrix dimensions">:$dims,65    RTLValueType:$inner66  );67 68  let genVerifyDecl = 1;69  let hasCustomAssemblyFormat = 1;70 71// DECL-LABEL: class CompoundAType : public ::mlir::Type72// DECL: static CompoundAType getChecked(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::MLIRContext *context, int widthOfSomething, ::test::SimpleTypeA exampleTdType, SomeCppStruct exampleCppType, ::llvm::ArrayRef<int> dims, ::mlir::Type inner);73// DECL: static ::llvm::LogicalResult verify(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, int widthOfSomething, ::test::SimpleTypeA exampleTdType, SomeCppStruct exampleCppType, ::llvm::ArrayRef<int> dims, ::mlir::Type inner);74// DECL: static constexpr ::llvm::StringLiteral getMnemonic() {75// DECL:   return {"cmpnd_a"};76// DECL: }77// DECL: static ::mlir::Type parse(::mlir::AsmParser &odsParser);78// DECL: void print(::mlir::AsmPrinter &odsPrinter) const;79// DECL: int getWidthOfSomething() const;80// DECL: ::test::SimpleTypeA getExampleTdType() const;81// DECL: SomeCppStruct getExampleCppType() const;82}83 84def C_IndexType : TestType<"Index"> {85  let mnemonic = "index";86 87  let parameters = (ins88    StringRefParameter<"Label for index">:$label89  );90  let hasCustomAssemblyFormat = 1;91 92// DECL-LABEL: class IndexType : public ::mlir::Type93// DECL: static constexpr ::llvm::StringLiteral getMnemonic() {94// DECL:   return {"index"};95// DECL: }96// DECL: static ::mlir::Type parse(::mlir::AsmParser &odsParser);97// DECL: void print(::mlir::AsmPrinter &odsPrinter) const;98}99 100def D_SingleParameterType : TestType<"SingleParameter"> {101  let typeName = "test.d_single_parameter";102  let parameters = (ins103    "int": $num104  );105// DECL-LABEL: struct SingleParameterTypeStorage;106// DECL-LABEL: class SingleParameterType107// DECL-SAME:  detail::SingleParameterTypeStorage108}109 110def E_IntegerType : TestType<"Integer"> {111  let mnemonic = "int";112  let genVerifyDecl = 1;113  let hasCustomAssemblyFormat = 1;114  let parameters = (ins115      "SignednessSemantics":$signedness,116      TypeParameter<"unsigned", "Bitwidth of integer">:$width117  );118 119// DECL-LABEL: IntegerType : public ::mlir::Type120 121  let extraClassDeclaration = [{122  /// Signedness semantics.123  enum SignednessSemantics {124    Signless, /// No signedness semantics125    Signed,   /// Signed integer126    Unsigned, /// Unsigned integer127  };128 129  /// This extra function is necessary since it doesn't include signedness130  static IntegerType getChecked(unsigned width, Location location);131 132  /// Return true if this is a signless integer type.133  bool isSignless() const { return getSignedness() == Signless; }134  /// Return true if this is a signed integer type.135  bool isSigned() const { return getSignedness() == Signed; }136  /// Return true if this is an unsigned integer type.137  bool isUnsigned() const { return getSignedness() == Unsigned; }138  }];139 140// DECL: /// Signedness semantics.141// DECL-NEXT: enum SignednessSemantics {142// DECL-NEXT:   Signless, /// No signedness semantics143// DECL-NEXT:   Signed,   /// Signed integer144// DECL-NEXT:   Unsigned, /// Unsigned integer145// DECL-NEXT: };146// DECL: /// This extra function is necessary since it doesn't include signedness147// DECL-NEXT: static IntegerType getChecked(unsigned width, Location location);148 149// DECL: /// Return true if this is a signless integer type.150// DECL-NEXT: bool isSignless() const { return getSignedness() == Signless; }151// DECL-NEXT: /// Return true if this is a signed integer type.152// DECL-NEXT: bool isSigned() const { return getSignedness() == Signed; }153// DECL-NEXT: /// Return true if this is an unsigned integer type.154// DECL-NEXT: bool isUnsigned() const { return getSignedness() == Unsigned; }155}156