1 // RUN: mlir-tblgen -gen-typedef-decls -I %S/../../include %s | FileCheck %s --check-prefix=DECL
2 // RUN: mlir-tblgen -gen-typedef-defs -I %S/../../include %s | FileCheck %s --check-prefix=DEF
4 include "mlir/IR/AttrTypeBase.td"
5 include "mlir/IR/OpBase.td"
7 // DECL: #ifdef GET_TYPEDEF_CLASSES
8 // DECL: #undef GET_TYPEDEF_CLASSES
10 // DECL: namespace mlir {
11 // DECL: class AsmParser;
12 // DECL: class AsmPrinter;
13 // DECL: } // namespace mlir
15 // DEF: #ifdef GET_TYPEDEF_LIST
16 // DEF: #undef GET_TYPEDEF_LIST
17 // DEF: ::test::SimpleAType,
18 // DEF: ::test::CompoundAType,
19 // DEF: ::test::IndexType,
20 // DEF: ::test::SingleParameterType,
21 // DEF: ::test::IntegerType
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);
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;
38 def Test_Dialect: Dialect {
39 // DECL-NOT: TestDialect
40 let name = "TestDialect";
41 let cppNamespace = "::test";
44 class TestType<string name> : TypeDef<Test_Dialect, name> { }
46 def A_SimpleTypeA : TestType<"SimpleA"> {
47 // DECL: class SimpleAType : public ::mlir::Type
48 let typeName = "test.simple_a";
51 def RTLValueType : Type<CPred<"isRTLValueType($_self)">, "Type"> {
52 string cppType = "::mlir::Type";
55 // A more complex parameterized type
56 def 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";
61 "int":$widthOfSomething,
62 "::test::SimpleTypeA": $exampleTdType,
63 "SomeCppStruct": $exampleCppType,
64 ArrayRefParameter<"int", "Matrix dimensions">:$dims,
68 let genVerifyDecl = 1;
69 let hasCustomAssemblyFormat = 1;
71 // DECL-LABEL: class CompoundAType : public ::mlir::Type
72 // 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"};
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;
84 def C_IndexType : TestType<"Index"> {
85 let mnemonic = "index";
88 StringRefParameter<"Label for index">:$label
90 let hasCustomAssemblyFormat = 1;
92 // DECL-LABEL: class IndexType : public ::mlir::Type
93 // DECL: static constexpr ::llvm::StringLiteral getMnemonic() {
94 // DECL: return {"index"};
96 // DECL: static ::mlir::Type parse(::mlir::AsmParser &odsParser);
97 // DECL: void print(::mlir::AsmPrinter &odsPrinter) const;
100 def D_SingleParameterType : TestType<"SingleParameter"> {
101 let typeName = "test.d_single_parameter";
102 let parameters = (ins
105 // DECL-LABEL: struct SingleParameterTypeStorage;
106 // DECL-LABEL: class SingleParameterType
107 // DECL-SAME: detail::SingleParameterTypeStorage
110 def E_IntegerType : TestType<"Integer"> {
111 let mnemonic = "int";
112 let genVerifyDecl = 1;
113 let hasCustomAssemblyFormat = 1;
114 let parameters = (ins
115 "SignednessSemantics":$signedness,
116 TypeParameter<"unsigned", "Bitwidth of integer">:$width
119 // DECL-LABEL: IntegerType : public ::mlir::Type
121 let extraClassDeclaration = [{
122 /// Signedness semantics.
123 enum SignednessSemantics {
124 Signless, /// No signedness semantics
125 Signed, /// Signed integer
126 Unsigned, /// Unsigned integer
129 /// This extra function is necessary since it doesn't include signedness
130 static IntegerType getChecked(unsigned width, Location location);
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; }
140 // DECL: /// Signedness semantics.
141 // DECL-NEXT: enum SignednessSemantics {
142 // DECL-NEXT: Signless, /// No signedness semantics
143 // DECL-NEXT: Signed, /// Signed integer
144 // DECL-NEXT: Unsigned, /// Unsigned integer
146 // DECL: /// This extra function is necessary since it doesn't include signedness
147 // DECL-NEXT: static IntegerType getChecked(unsigned width, Location location);
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; }