1 // RUN: mlir-tblgen -gen-op-decls -I %S/../../include %s | FileCheck %s
3 include "mlir/IR/AttrTypeBase.td"
4 include "mlir/IR/EnumAttr.td"
5 include "mlir/IR/OpBase.td"
7 def Test_Dialect : Dialect {
9 let cppNamespace = "foobar";
11 class NS_Op<string mnemonic, list<Trait> traits> :
12 Op<Test_Dialect, mnemonic, traits>;
14 def SomeAttr : Attr<CPred<"some-condition">, "some attribute kind"> {
15 let storageType = "some-attr-kind";
16 let returnType = "some-return-type";
17 let convertFromStorage = "$_self.some-convert-from-storage()";
18 let constBuilderCall = "some-const-builder-call($_builder, $0)";
21 def AOp : NS_Op<"a_op", []> {
25 DefaultValuedAttr<SomeAttr, "4.2">:$bAttr,
26 OptionalAttr<SomeAttr>:$cAttr,
27 DefaultValuedOptionalAttr<SomeAttr, "7.2">:$dAttr
31 // CHECK-LABEL: AOp declarations
32 // Note: `cAttr` below could be conditionally optional and so the generation is
33 // currently conservative.
34 // CHECK-DAG: ::mlir::Value lhs, some-attr-kind aAttr, some-attr-kind bAttr, /*optional*/some-attr-kind cAttr, /*optional*/some-attr-kind dAttr);
35 // CHECK-DAG: ::mlir::Value lhs, some-return-type aAttr, some-return-type bAttr, /*optional*/some-attr-kind cAttr, /*optional*/some-return-type dAttr = 7.2);
36 // CHECK-DAG: ::mlir::TypeRange resultTypes, ::mlir::Value lhs, some-attr-kind aAttr, some-attr-kind bAttr, /*optional*/some-attr-kind cAttr, /*optional*/some-attr-kind dAttr);
37 // CHECK-DAG: ::mlir::TypeRange resultTypes, ::mlir::Value lhs, some-return-type aAttr, some-return-type bAttr, /*optional*/some-attr-kind cAttr, /*optional*/some-return-type dAttr = 7.2);
39 def BOp : NS_Op<"b_op", []> {
41 DefaultValuedAttr<SomeAttr, "6.2">:$aAttr,
42 DefaultValuedAttr<SomeAttr, "4.2">:$bAttr
46 // Verify that non-overlapping builders created where all could be elided.
47 // CHECK-LABEL: BOp declarations
48 // CHECK-DAG: some-attr-kind aAttr, some-attr-kind bAttr = nullptr);
49 // CHECK-DAG: some-return-type aAttr = 6.2, some-return-type bAttr = 4.2);
50 // CHECK-DAG: ::mlir::TypeRange resultTypes, some-attr-kind aAttr, some-attr-kind bAttr = nullptr);
51 // CHECK-DAG: ::mlir::TypeRange resultTypes, some-return-type aAttr = 6.2, some-return-type bAttr = 4.2);
53 def COp : NS_Op<"c_op", []> {
56 OptionalAttr<SymbolRefArrayAttr>:$ag,
57 OptionalAttr<SymbolRefArrayAttr>:$as,
58 OptionalAttr<SymbolRefArrayAttr>:$nos,
59 OptionalAttr<I64Attr>:$al,
65 // CHECK-LABEL: COp declarations
66 // Note: `al` below could be conditionally optional and so the generation is
67 // currently conservative.
68 // CHECK-DAG: ::mlir::Value value, /*optional*/::mlir::ArrayAttr ag, /*optional*/::mlir::ArrayAttr as, /*optional*/::mlir::ArrayAttr nos, /*optional*/::mlir::IntegerAttr al, /*optional*/::mlir::UnitAttr vo, /*optional*/::mlir::UnitAttr non = nullptr);
69 // CHECK-DAG: ::mlir::Value value, /*optional*/::mlir::ArrayAttr ag, /*optional*/::mlir::ArrayAttr as, /*optional*/::mlir::ArrayAttr nos, /*optional*/::mlir::IntegerAttr al, /*optional*/bool vo = false, /*optional*/bool non = false);
70 // CHECK-DAG: ::mlir::TypeRange resultTypes, ::mlir::Value value, /*optional*/::mlir::ArrayAttr ag, /*optional*/::mlir::ArrayAttr as, /*optional*/::mlir::ArrayAttr nos, /*optional*/::mlir::IntegerAttr al, /*optional*/::mlir::UnitAttr vo, /*optional*/::mlir::UnitAttr non = nullptr);
71 // CHECK-DAG: ::mlir::TypeRange resultTypes, ::mlir::Value value, /*optional*/::mlir::ArrayAttr ag, /*optional*/::mlir::ArrayAttr as, /*optional*/::mlir::ArrayAttr nos, /*optional*/::mlir::IntegerAttr al, /*optional*/bool vo = false, /*optional*/bool non = false);