1 // RUN: mlir-tblgen -gen-op-decls -I %S/../../include %s -o=%t
3 // This file contains tests for the specification of the declarative op format.
5 include "mlir/IR/OpBase.td"
6 include "mlir/Interfaces/InferTypeOpInterface.td"
8 def TestDialect : Dialect {
11 class TestFormat_Op<string fmt, list<Trait> traits = []>
12 : Op<TestDialect, "format_op", traits> {
13 let assemblyFormat = fmt;
16 //===----------------------------------------------------------------------===//
18 //===----------------------------------------------------------------------===//
20 //===----------------------------------------------------------------------===//
24 def DirectiveAttrDictValidA : TestFormat_Op<[{
27 def DirectiveAttrDictValidB : TestFormat_Op<[{
28 attr-dict-with-keyword
31 //===----------------------------------------------------------------------===//
35 def DirectiveCustomValidA : TestFormat_Op<[{
36 custom<MyDirective>($operand) attr-dict
37 }]>, Arguments<(ins Optional<I64>:$operand)>;
38 def DirectiveCustomValidB : TestFormat_Op<[{
39 custom<MyDirective>($operand, type($operand), type($result)) attr-dict
40 }]>, Arguments<(ins I64:$operand)>, Results<(outs I64:$result)>;
41 def DirectiveCustomValidC : TestFormat_Op<[{
42 custom<MyDirective>($attr) attr-dict
43 }]>, Arguments<(ins I64Attr:$attr)>;
44 def DirectiveCustomValidD : TestFormat_Op<[{
45 (`(` custom<MyDirective>($operand)^ `)`)? attr-dict
46 }]>, Arguments<(ins Optional<I64>:$operand)>;
47 def DirectiveCustomValidE : TestFormat_Op<[{
48 custom<MyDirective>(prop-dict) attr-dict
49 }]>, Arguments<(ins UnitAttr:$flag)>;
51 //===----------------------------------------------------------------------===//
55 def DirectiveFunctionalTypeValid : TestFormat_Op<[{
56 functional-type(operands, results) attr-dict
59 //===----------------------------------------------------------------------===//
63 def DirectiveOperandsValid : TestFormat_Op<[{
67 //===----------------------------------------------------------------------===//
71 def DirectiveRegionsValid : TestFormat_Op<[{
75 //===----------------------------------------------------------------------===//
79 def DirectiveResultsInvalidA : TestFormat_Op<[{
80 type(results) attr-dict
83 //===----------------------------------------------------------------------===//
87 def DirectiveSuccessorsInvalidA : TestFormat_Op<[{
91 //===----------------------------------------------------------------------===//
95 def DirectiveTypeValid : TestFormat_Op<[{
96 type(operands) attr-dict
99 //===----------------------------------------------------------------------===//
101 //===----------------------------------------------------------------------===//
104 def LiteralValid : TestFormat_Op<[{
105 `_` `:` `,` `=` `<` `>` `(` `)` `[` `]` `?` `+` `*` ` ` `` `->` `\n` `abc$._`
109 //===----------------------------------------------------------------------===//
111 //===----------------------------------------------------------------------===//
114 def OIListTrivial : TestFormat_Op<[{
115 oilist(`keyword` `(` `)` | `otherkeyword` `(` `)`) attr-dict
117 def OIListSimple : TestFormat_Op<[{
118 oilist( `keyword` $arg0 `:` type($arg0)
119 | `otherkeyword` $arg1 `:` type($arg1)
120 | `thirdkeyword` $arg2 `:` type($arg2) )
122 }], [AttrSizedOperandSegments]>, Arguments<(ins Optional<AnyType>:$arg0, Optional<AnyType>:$arg1, Optional<AnyType>:$arg2)>;
123 def OIListVariadic : TestFormat_Op<[{
124 oilist( `keyword` `(` $args0 `:` type($args0) `)`
125 | `otherkeyword` `(` $args1 `:` type($args1) `)`
126 | `thirdkeyword` `(` $args2 `:` type($args2) `)`)
128 }], [AttrSizedOperandSegments]>, Arguments<(ins Variadic<AnyType>:$args0, Variadic<AnyType>:$args1, Variadic<AnyType>:$args2)>;
129 def OIListCustom : TestFormat_Op<[{
130 oilist( `private` `(` $arg0 `:` type($arg0) `)`
132 | `reduction` custom<ReductionClause>($arg1, type($arg1))) attr-dict
133 }], [AttrSizedOperandSegments]>, Arguments<(ins Optional<AnyType>:$arg0, Optional<AnyType>:$arg1)>;
135 //===----------------------------------------------------------------------===//
137 //===----------------------------------------------------------------------===//
140 def OptionalValidA : TestFormat_Op<[{
141 (` ` `` $arg^)? attr-dict
142 }]>, Arguments<(ins Optional<I32>:$arg)>;
144 //===----------------------------------------------------------------------===//
146 //===----------------------------------------------------------------------===//
149 def StringInvalidA : TestFormat_Op<[{ custom<Foo>("foo") attr-dict }]>;
151 //===----------------------------------------------------------------------===//
153 //===----------------------------------------------------------------------===//
156 def VariableValidA : TestFormat_Op<[{
158 }]>, Arguments<(ins OptionalAttr<I1Attr>:$attr)>;
159 def VariableValidB : TestFormat_Op<[{
160 (`foo` $attr^)? `:` attr-dict
161 }]>, Arguments<(ins OptionalAttr<I1Attr>:$attr)>;
163 //===----------------------------------------------------------------------===//
165 //===----------------------------------------------------------------------===//
168 def ZCoverageValidA : TestFormat_Op<[{
169 $operand type($operand) type($result) attr-dict
170 }]>, Arguments<(ins AnyMemRef:$operand)>, Results<(outs AnyMemRef:$result)>;
171 def ZCoverageValidB : TestFormat_Op<[{
172 $operand type(operands) type(results) attr-dict
173 }]>, Arguments<(ins AnyMemRef:$operand)>, Results<(outs AnyMemRef:$result)>;
174 def ZCoverageValidC : TestFormat_Op<[{
175 operands functional-type(operands, results) attr-dict
176 }]>, Arguments<(ins AnyMemRef:$operand)>, Results<(outs AnyMemRef:$result)>;
178 // Check that we can infer type equalities from certain traits.
179 def ZCoverageValidD : TestFormat_Op<[{
180 operands type($result) attr-dict
181 }], [SameOperandsAndResultType]>, Arguments<(ins AnyMemRef)>,
182 Results<(outs AnyMemRef:$result)>;
183 def ZCoverageValidE : TestFormat_Op<[{
184 $operand type($operand) attr-dict
185 }], [SameOperandsAndResultType]>, Arguments<(ins AnyMemRef:$operand)>,
186 Results<(outs AnyMemRef)>;
187 def ZCoverageValidF : TestFormat_Op<[{
188 operands type($other) attr-dict
189 }], [SameTypeOperands]>, Arguments<(ins AnyMemRef:$operand, AnyMemRef:$other)>;
190 def ZCoverageValidG : TestFormat_Op<[{
191 operands type($other) attr-dict
192 }], [AllTypesMatch<["operand", "other"]>]>,
193 Arguments<(ins AnyMemRef:$operand, AnyMemRef:$other)>;
194 def ZCoverageValidH : TestFormat_Op<[{
195 operands type($result) attr-dict
196 }], [AllTypesMatch<["operand", "result"]>]>,
197 Arguments<(ins AnyMemRef:$operand)>, Results<(outs AnyMemRef:$result)>;
198 def ZCoverageValidI : TestFormat_Op<[{
199 operands type(operands) attr-dict
200 }], [InferTypeOpInterface]>, Arguments<(ins Variadic<I64>:$inputs)>, Results<(outs I64:$result)>;