[clang-tidy][NFC]remove deps of clang in clang tidy test (#116588)
[llvm-project.git] / mlir / test / mlir-tblgen / op-format-spec.td
blobad2a055bc78b033ee622f2ecb07bf498dfc66f16
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 {
9   let name = "test";
11 class TestFormat_Op<string fmt, list<Trait> traits = []>
12     : Op<TestDialect, "format_op", traits> {
13   let assemblyFormat = fmt;
16 //===----------------------------------------------------------------------===//
17 // Directives
18 //===----------------------------------------------------------------------===//
20 //===----------------------------------------------------------------------===//
21 // attr-dict
23 // CHECK-NOT: error
24 def DirectiveAttrDictValidA : TestFormat_Op<[{
25   attr-dict
26 }]>;
27 def DirectiveAttrDictValidB : TestFormat_Op<[{
28   attr-dict-with-keyword
29 }]>;
31 //===----------------------------------------------------------------------===//
32 // custom
34 // CHECK-NOT: error
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 //===----------------------------------------------------------------------===//
52 // functional-type
54 // CHECK-NOT: error
55 def DirectiveFunctionalTypeValid : TestFormat_Op<[{
56   functional-type(operands, results) attr-dict
57 }]>;
59 //===----------------------------------------------------------------------===//
60 // operands
62 // CHECK-NOT: error:
63 def DirectiveOperandsValid : TestFormat_Op<[{
64   operands attr-dict
65 }]>;
67 //===----------------------------------------------------------------------===//
68 // regions
70 // CHECK-NOT: error:
71 def DirectiveRegionsValid : TestFormat_Op<[{
72   regions attr-dict
73 }]>;
75 //===----------------------------------------------------------------------===//
76 // results
78 // CHECK-NOT: error:
79 def DirectiveResultsInvalidA : TestFormat_Op<[{
80   type(results) attr-dict
81 }]>;
83 //===----------------------------------------------------------------------===//
84 // successors
86 // CHECK-NOT: error:
87 def DirectiveSuccessorsInvalidA : TestFormat_Op<[{
88   successors attr-dict
89 }]>;
91 //===----------------------------------------------------------------------===//
92 // type
94 // CHECK-NOT: error:
95 def DirectiveTypeValid : TestFormat_Op<[{
96   type(operands) attr-dict
97 }]>;
99 //===----------------------------------------------------------------------===//
100 // Literals
101 //===----------------------------------------------------------------------===//
103 // CHECK-NOT: error
104 def LiteralValid : TestFormat_Op<[{
105   `_` `:` `,` `=` `<` `>` `(` `)` `[` `]` `?` `+` `*` ` ` `` `->` `\n` `abc$._`
106   attr-dict
107 }]>;
109 //===----------------------------------------------------------------------===//
110 // OIList Element
111 //===----------------------------------------------------------------------===//
113 // CHECK-NOT: error
114 def OIListTrivial : TestFormat_Op<[{
115   oilist(`keyword` `(` `)` | `otherkeyword` `(` `)`) attr-dict
116 }]>;
117 def OIListSimple : TestFormat_Op<[{
118   oilist( `keyword` $arg0 `:` type($arg0)
119         | `otherkeyword` $arg1 `:` type($arg1)
120         | `thirdkeyword` $arg2 `:` type($arg2) )
121   attr-dict
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) `)`)
127   attr-dict
128 }], [AttrSizedOperandSegments]>, Arguments<(ins Variadic<AnyType>:$args0, Variadic<AnyType>:$args1, Variadic<AnyType>:$args2)>;
129 def OIListCustom : TestFormat_Op<[{
130   oilist( `private` `(` $arg0 `:` type($arg0) `)`
131         | `nowait`
132         | `reduction` custom<ReductionClause>($arg1, type($arg1))) attr-dict
133 }], [AttrSizedOperandSegments]>, Arguments<(ins Optional<AnyType>:$arg0, Optional<AnyType>:$arg1)>;
135 //===----------------------------------------------------------------------===//
136 // Optional Groups
137 //===----------------------------------------------------------------------===//
139 // CHECK-NOT: error
140 def OptionalValidA : TestFormat_Op<[{
141   (` ` `` $arg^)? attr-dict
142 }]>, Arguments<(ins Optional<I32>:$arg)>;
144 //===----------------------------------------------------------------------===//
145 // Strings
146 //===----------------------------------------------------------------------===//
148 // CHECK-NOT: error
149 def StringInvalidA : TestFormat_Op<[{ custom<Foo>("foo") attr-dict }]>;
151 //===----------------------------------------------------------------------===//
152 // Variables
153 //===----------------------------------------------------------------------===//
155 // CHECK-NOT: error:
156 def VariableValidA : TestFormat_Op<[{
157   $attr `:` attr-dict
158 }]>, Arguments<(ins OptionalAttr<I1Attr>:$attr)>;
159 def VariableValidB : TestFormat_Op<[{
160   (`foo` $attr^)? `:` attr-dict
161 }]>, Arguments<(ins OptionalAttr<I1Attr>:$attr)>;
163 //===----------------------------------------------------------------------===//
164 // Coverage Checks
165 //===----------------------------------------------------------------------===//
167 // CHECK-NOT: error
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)>;