[clang-tidy][NFC]remove deps of clang in clang tidy test (#116588)
[llvm-project.git] / mlir / test / mlir-tblgen / op-python-bindings.td
blob632046389e12cff0e7c2454f1c3b95f6adc50525
1 // RUN: mlir-tblgen -gen-python-op-bindings -bind-dialect=test -I %S/../../include %s | FileCheck %s
3 include "mlir/IR/OpBase.td"
4 include "mlir/IR/AttrTypeBase.td"
5 include "mlir/Interfaces/InferTypeOpInterface.td"
7 // CHECK: @_ods_cext.register_dialect
8 // CHECK: class _Dialect(_ods_ir.Dialect):
9   // CHECK: DIALECT_NAMESPACE = "test"
10 def Test_Dialect : Dialect {
11   let name = "test";
12   let cppNamespace = "Test";
15 class TestOp<string mnemonic, list<Trait> traits = []> :
16     Op<Test_Dialect, mnemonic, traits>;
18 // CHECK: @_ods_cext.register_operation(_Dialect)
19 // CHECK: class AttrSizedOperandsOp(_ods_ir.OpView):
20 // CHECK-LABEL: OPERATION_NAME = "test.attr_sized_operands"
21 // CHECK: _ODS_OPERAND_SEGMENTS = [-1,1,0,]
22 def AttrSizedOperandsOp : TestOp<"attr_sized_operands",
23                                  [AttrSizedOperandSegments]> {
24   // CHECK: def __init__(self, variadic1, non_variadic, *, variadic2=None, loc=None, ip=None):
25   // CHECK:   operands = []
26   // CHECK:   results = []
27   // CHECK:   attributes = {}
28   // CHECK:   regions = None
29   // CHECK:   operands.append(_get_op_results_or_values(variadic1))
30   // CHECK:   operands.append(_get_op_result_or_value(non_variadic))
31   // CHECK:   operands.append(_get_op_result_or_value(variadic2) if variadic2 is not None else None)
32   // CHECK:   _ods_successors = None
33   // CHECK:   super().__init__(self.build_generic(
34   // CHECK:     attributes=attributes, results=results, operands=operands,
35   // CHECK:     successors=_ods_successors, regions=regions, loc=loc, ip=ip))
37   // CHECK: @builtins.property
38   // CHECK: def variadic1(self):
39   // CHECK:   operand_range = _ods_segmented_accessor(
40   // CHECK:       self.operation.operands,
41   // CHECK:       self.operation.attributes["operandSegmentSizes"], 0)
42   // CHECK:   return operand_range
43   // CHECK-NOT: if len(operand_range)
44   //
45   // CHECK: @builtins.property
46   // CHECK: def non_variadic(self):
47   // CHECK:   operand_range = _ods_segmented_accessor(
48   // CHECK:       self.operation.operands,
49   // CHECK:       self.operation.attributes["operandSegmentSizes"], 1)
50   // CHECK:   return operand_range[0]
51   //
52   // CHECK: @builtins.property
53   // CHECK: def variadic2(self):
54   // CHECK:   operand_range = _ods_segmented_accessor(
55   // CHECK:       self.operation.operands,
56   // CHECK:       self.operation.attributes["operandSegmentSizes"], 2)
57   // CHECK:   return operand_range[0] if len(operand_range) > 0 else None
58   let arguments = (ins Variadic<AnyType>:$variadic1, AnyType:$non_variadic,
59                    Optional<AnyType>:$variadic2);
62 // CHECK: def attr_sized_operands(variadic1, non_variadic, *, variadic2=None, loc=None, ip=None)
63 // CHECK:   return AttrSizedOperandsOp(variadic1=variadic1, non_variadic=non_variadic, variadic2=variadic2, loc=loc, ip=ip)
65 // CHECK: @_ods_cext.register_operation(_Dialect)
66 // CHECK: class AttrSizedResultsOp(_ods_ir.OpView):
67 // CHECK-LABEL: OPERATION_NAME = "test.attr_sized_results"
68 // CHECK: _ODS_RESULT_SEGMENTS = [0,1,-1,]
69 def AttrSizedResultsOp : TestOp<"attr_sized_results",
70                                [AttrSizedResultSegments]> {
71   // CHECK: def __init__(self, variadic1, non_variadic, variadic2, *, loc=None, ip=None):
72   // CHECK:   operands = []
73   // CHECK:   results = []
74   // CHECK:   attributes = {}
75   // CHECK:   regions = None
76   // CHECK:   if variadic1 is not None: results.append(variadic1)
77   // CHECK:   results.append(non_variadic)
78   // CHECK:   results.append(variadic2)
79   // CHECK:   _ods_successors = None
80   // CHECK:   super().__init__(self.build_generic(
81   // CHECK:     attributes=attributes, results=results, operands=operands,
82   // CHECK:     successors=_ods_successors, regions=regions, loc=loc, ip=ip))
84   // CHECK: @builtins.property
85   // CHECK: def variadic1(self):
86   // CHECK:   result_range = _ods_segmented_accessor(
87   // CHECK:       self.operation.results,
88   // CHECK:       self.operation.attributes["resultSegmentSizes"], 0)
89   // CHECK:   return result_range[0] if len(result_range) > 0 else None
90   //
91   // CHECK: @builtins.property
92   // CHECK: def non_variadic(self):
93   // CHECK:   result_range = _ods_segmented_accessor(
94   // CHECK:       self.operation.results,
95   // CHECK:       self.operation.attributes["resultSegmentSizes"], 1)
96   // CHECK:   return result_range[0]
97   //
98   // CHECK: @builtins.property
99   // CHECK: def variadic2(self):
100   // CHECK:   result_range = _ods_segmented_accessor(
101   // CHECK:       self.operation.results,
102   // CHECK:       self.operation.attributes["resultSegmentSizes"], 2)
103   // CHECK:   return result_range
104   // CHECK-NOT: if len(result_range)
105   let results = (outs Optional<AnyType>:$variadic1, AnyType:$non_variadic,
106                  Variadic<AnyType>:$variadic2);
109 // CHECK: def attr_sized_results(variadic1, non_variadic, variadic2, *, loc=None, ip=None)
110 // CHECK:   return _get_op_result_or_op_results(AttrSizedResultsOp(variadic1=variadic1, non_variadic=non_variadic, variadic2=variadic2, loc=loc, ip=ip))
113 // CHECK: @_ods_cext.register_operation(_Dialect)
114 // CHECK: class AttributedOp(_ods_ir.OpView):
115 // CHECK-LABEL: OPERATION_NAME = "test.attributed_op"
116 // CHECK-NOT: _ODS_OPERAND_SEGMENTS
117 // CHECK-NOT: _ODS_RESULT_SEGMENTS
118 def AttributedOp : TestOp<"attributed_op"> {
119   // CHECK: def __init__(self, i32attr, in_, *, optionalF32Attr=None, unitAttr=None, loc=None, ip=None):
120   // CHECK:   operands = []
121   // CHECK:   results = []
122   // CHECK:   attributes = {}
123   // CHECK:   regions = None
124   // CHECK:   attributes["i32attr"] = (i32attr if (
125   // CHECK-NEXT:   isinstance(i32attr, _ods_ir.Attribute) or
126   // CHECK-NEXT:   not _ods_ir.AttrBuilder.contains('I32Attr')
127   // CHECK-NEXT:   _ods_ir.AttrBuilder.get('I32Attr')(i32attr, context=_ods_context)
128   // CHECK:   if optionalF32Attr is not None: attributes["optionalF32Attr"] = (optionalF32Attr
129   // CHECK:   if bool(unitAttr): attributes["unitAttr"] = _ods_ir.UnitAttr.get(
130   // CHECK:     _ods_get_default_loc_context(loc))
131   // CHECK:   attributes["in"] = (in_
132   // CHECK:   _ods_successors = None
133   // CHECK:   super().__init__(self.build_generic(
134   // CHECK:     attributes=attributes, results=results, operands=operands,
135   // CHECK:     successors=_ods_successors, regions=regions, loc=loc, ip=ip))
137   // CHECK: @builtins.property
138   // CHECK: def i32attr(self):
139   // CHECK:   return self.operation.attributes["i32attr"]
141   // CHECK: @builtins.property
142   // CHECK: def optionalF32Attr(self):
143   // CHECK:   if "optionalF32Attr" not in self.operation.attributes:
144   // CHECK:     return None
145   // CHECK:   return self.operation.attributes["optionalF32Attr"]
147   // CHECK: @builtins.property
148   // CHECK: def unitAttr(self):
149   // CHECK:   return "unitAttr" in self.operation.attributes
151   // CHECK: @builtins.property
152   // CHECK: def in_(self):
153   // CHECK:   return self.operation.attributes["in"]
155   let arguments = (ins I32Attr:$i32attr, OptionalAttr<F32Attr>:$optionalF32Attr,
156                    UnitAttr:$unitAttr, I32Attr:$in);
159 // CHECK: def attributed_op(i32attr, in_, *, optional_f32_attr=None, unit_attr=None, loc=None, ip=None)
160 // CHECK:     return AttributedOp(i32attr=i32attr, in_=in_, optionalF32Attr=optional_f32_attr, unitAttr=unit_attr, loc=loc, ip=ip)
162 // CHECK: @_ods_cext.register_operation(_Dialect)
163 // CHECK: class AttributedOpWithOperands(_ods_ir.OpView):
164 // CHECK-LABEL: OPERATION_NAME = "test.attributed_op_with_operands"
165 // CHECK-NOT: _ODS_OPERAND_SEGMENTS
166 // CHECK-NOT: _ODS_RESULT_SEGMENTS
167 def AttributedOpWithOperands : TestOp<"attributed_op_with_operands"> {
168   // CHECK: def __init__(self, _gen_arg_0, _gen_arg_2, *, in_=None, is_=None, loc=None, ip=None):
169   // CHECK:   operands = []
170   // CHECK:   results = []
171   // CHECK:   attributes = {}
172   // CHECK:   regions = None
173   // CHECK:   operands.append(_get_op_result_or_value(_gen_arg_0))
174   // CHECK:   operands.append(_get_op_result_or_value(_gen_arg_2))
175   // CHECK:   if bool(in_): attributes["in"] = _ods_ir.UnitAttr.get(
176   // CHECK:     _ods_get_default_loc_context(loc))
177   // CHECK:   if is_ is not None: attributes["is"] = (is_
178   // CHECK:   _ods_successors = None
179   // CHECK:   super().__init__(self.build_generic(
180   // CHECK:     attributes=attributes, results=results, operands=operands,
181   // CHECK:     successors=_ods_successors, regions=regions, loc=loc, ip=ip))
183   // CHECK: @builtins.property
184   // CHECK: def in_(self):
185   // CHECK:   return "in" in self.operation.attributes
187   // CHECK: @builtins.property
188   // CHECK: def is_(self):
189   // CHECK:   if "is" not in self.operation.attributes:
190   // CHECK:     return None
191   // CHECK:   return self.operation.attributes["is"]
192   let arguments = (ins I32, UnitAttr:$in, F32, OptionalAttr<F32Attr>:$is);
195 // CHECK: def attributed_op_with_operands(_gen_arg_0, _gen_arg_2, *, in_=None, is_=None, loc=None, ip=None)
196 // CHECK:   return AttributedOpWithOperands(_gen_arg_0=_gen_arg_0, _gen_arg_2=_gen_arg_2, in_=in_, is_=is_, loc=loc, ip=ip)
198 // CHECK: @_ods_cext.register_operation(_Dialect)
199 // CHECK: class DefaultValuedAttrsOp(_ods_ir.OpView):
200 // CHECK-LABEL: OPERATION_NAME = "test.default_valued_attrs"
201 def DefaultValuedAttrsOp : TestOp<"default_valued_attrs"> {
202   // CHECK: def __init__(self, *, arr=None, unsupported=None, loc=None, ip=None):
203   // CHECK:   operands = []
204   // CHECK:   results = []
205   // CHECK:   attributes = {}
206   // CHECK:   regions = None
207   // CHECK:   if arr is not None: attributes["arr"] = (arr
208   // CHECK:   if unsupported is not None: attributes["unsupported"] = (unsupported
209   // CHECK:   _ods_successors = None
210   // CHECK:   super().__init__(self.build_generic(
211   // CHECK:     attributes=attributes, results=results, operands=operands,
212   // CHECK:     successors=_ods_successors, regions=regions, loc=loc, ip=ip))
214   let arguments = (ins DefaultValuedAttr<I64ArrayAttr, "{}">:$arr,
215                        DefaultValuedAttr<I64ArrayAttr, "dummy_func()">:$unsupported);
216   let results = (outs);
219 // CHECK: def default_valued_attrs(*, arr=None, unsupported=None, loc=None, ip=None)
220 // CHECK:   return DefaultValuedAttrsOp(arr=arr, unsupported=unsupported, loc=loc, ip=ip)
222 // CHECK-LABEL: OPERATION_NAME = "test.derive_result_types_op"
223 def DeriveResultTypesOp : TestOp<"derive_result_types_op", [FirstAttrDerivedResultType]> {
224   // CHECK: def __init__(self, type_, *, loc=None, ip=None):
225   // CHECK:   operands = []
226   // CHECK:   results = []
227   // CHECK:   _ods_result_type_source_attr = attributes["type"]
228   // CHECK:   _ods_derived_result_type = (
229   // CHECK:       _ods_ir.TypeAttr(_ods_result_type_source_attr).value
230   // CHECK:       if _ods_ir.TypeAttr.isinstance(_ods_result_type_source_attr) else
231   // CHECK:       _ods_result_type_source_attr.type)
232   // CHECK:   results.extend([_ods_derived_result_type] * 2)
233   let arguments = (ins TypeAttr:$type);
234   let results = (outs AnyType:$res, AnyType);
237 // CHECK: def derive_result_types_op(type_, *, loc=None, ip=None)
238 // CHECK:   return DeriveResultTypesOp(type_=type_, loc=loc, ip=ip).results
240 // CHECK-LABEL: OPERATION_NAME = "test.derive_result_types_variadic_op"
241 def DeriveResultTypesVariadicOp : TestOp<"derive_result_types_variadic_op", [FirstAttrDerivedResultType]> {
242   // CHECK: def __init__(self, res, _gen_res_1, type_, *, loc=None, ip=None):
243   let arguments = (ins TypeAttr:$type);
244   let results = (outs AnyType:$res, Variadic<AnyType>);
247 // CHECK: def derive_result_types_variadic_op(res, _gen_res_1, type_, *, loc=None, ip=None)
248 // CHECK:   return _get_op_result_or_op_results(DeriveResultTypesVariadicOp(res=res, _gen_res_1=_gen_res_1, type_=type_, loc=loc, ip=ip))
250 // CHECK: @_ods_cext.register_operation(_Dialect)
251 // CHECK: class EmptyOp(_ods_ir.OpView):
252 // CHECK-LABEL: OPERATION_NAME = "test.empty"
253 def EmptyOp : TestOp<"empty">;
254   // CHECK: def __init__(self, *, loc=None, ip=None):
255   // CHECK:   operands = []
256   // CHECK:   results = []
257   // CHECK:   attributes = {}
258   // CHECK:   regions = None
259   // CHECK:   _ods_successors = None
260   // CHECK:   super().__init__(self.build_generic(
261   // CHECK:     attributes=attributes, results=results, operands=operands,
262   // CHECK:     successors=_ods_successors, regions=regions, loc=loc, ip=ip))
264 // CHECK: def empty(*, loc=None, ip=None)
265 // CHECK:   return EmptyOp(loc=loc, ip=ip)
267 // CHECK-LABEL: OPERATION_NAME = "test.infer_result_types_implied_op"
268 def InferResultTypesImpliedOp : TestOp<"infer_result_types_implied_op"> {
269   // CHECK:  def __init__(self, *, loc=None, ip=None):
270   // CHECK:    _ods_context = _ods_get_default_loc_context(loc)
271   // CHECK:   super().__init__(self.build_generic(
272   // CHECK:     attributes=attributes, operands=operands,
273   // CHECK:     successors=_ods_successors, regions=regions, loc=loc, ip=ip))
274   let results = (outs I32:$i32, F32:$f32);
277 // CHECK: def infer_result_types_implied_op(*, loc=None, ip=None)
278 // CHECK:   return InferResultTypesImpliedOp(loc=loc, ip=ip).results
280 // CHECK-LABEL: OPERATION_NAME = "test.infer_result_types_op"
281 def InferResultTypesOp : TestOp<"infer_result_types_op", [InferTypeOpInterface]> {
282   // CHECK:  def __init__(self, *, loc=None, ip=None):
283   // CHECK:    operands = []
284   // CHECK:   super().__init__(self.build_generic(
285   // CHECK:     attributes=attributes, operands=operands,
286   // CHECK:     successors=_ods_successors, regions=regions, loc=loc, ip=ip))
287   let results = (outs AnyType, AnyType, AnyType);
290 // CHECK: def infer_result_types_op(*, loc=None, ip=None)
291 // CHECK:   return InferResultTypesOp(loc=loc, ip=ip).results
293 // CHECK: @_ods_cext.register_operation(_Dialect)
294 // CHECK: class MissingNamesOp(_ods_ir.OpView):
295 // CHECK-LABEL: OPERATION_NAME = "test.missing_names"
296 def MissingNamesOp : TestOp<"missing_names"> {
297   // CHECK: def __init__(self, i32, _gen_res_1, i64, _gen_arg_0, f32, _gen_arg_2, *, loc=None, ip=None):
298   // CHECK:   operands = []
299   // CHECK:   results = []
300   // CHECK:   attributes = {}
301   // CHECK:   regions = None
302   // CHECK:   operands.append(_get_op_result_or_value(_gen_arg_0))
303   // CHECK:   operands.append(_get_op_result_or_value(f32))
304   // CHECK:   operands.append(_get_op_result_or_value(_gen_arg_2))
305   // CHECK:   results.append(i32)
306   // CHECK:   results.append(_gen_res_1)
307   // CHECK:   results.append(i64)
308   // CHECK:   _ods_successors = None
309   // CHECK:   super().__init__(self.build_generic(
310   // CHECK:     attributes=attributes, results=results, operands=operands,
311   // CHECK:     successors=_ods_successors, regions=regions, loc=loc, ip=ip))
313   // CHECK: @builtins.property
314   // CHECK: def f32(self):
315   // CHECK:   return self.operation.operands[1]
316   let arguments = (ins I32, F32:$f32, I64);
318   // CHECK: @builtins.property
319   // CHECK: def i32(self):
320   // CHECK:   return self.operation.results[0]
321   //
322   // CHECK: @builtins.property
323   // CHECK: def i64(self):
324   // CHECK:   return self.operation.results[2]
325   let results = (outs I32:$i32, AnyFloat, I64:$i64);
328 // CHECK: def missing_names(i32, _gen_res_1, i64, _gen_arg_0, f32, _gen_arg_2, *, loc=None, ip=None)
329 // CHECK:   return MissingNamesOp(i32=i32, _gen_res_1=_gen_res_1, i64=i64, _gen_arg_0=_gen_arg_0, f32=f32, _gen_arg_2=_gen_arg_2, loc=loc, ip=ip).results
331 // CHECK: @_ods_cext.register_operation(_Dialect)
332 // CHECK: class OneOptionalOperandOp(_ods_ir.OpView):
333 // CHECK-LABEL: OPERATION_NAME = "test.one_optional_operand"
334 // CHECK-NOT: _ODS_OPERAND_SEGMENTS
335 // CHECK-NOT: _ODS_RESULT_SEGMENTS
336 def OneOptionalOperandOp : TestOp<"one_optional_operand"> {
337   let arguments = (ins AnyType:$non_optional, Optional<AnyType>:$optional);
338   // CHECK: def __init__(self, non_optional, *, optional=None, loc=None, ip=None):
339   // CHECK:   operands = []
340   // CHECK:   results = []
341   // CHECK:   attributes = {}
342   // CHECK:   regions = None
343   // CHECK:   operands.append(_get_op_result_or_value(non_optional))
344   // CHECK:   if optional is not None: operands.append(_get_op_result_or_value(optional))
345   // CHECK:   _ods_successors = None
346   // CHECK:   super().__init__(self.build_generic(
347   // CHECK:     attributes=attributes, results=results, operands=operands,
348   // CHECK:     successors=_ods_successors, regions=regions, loc=loc, ip=ip))
350   // CHECK: @builtins.property
351   // CHECK: def non_optional(self):
352   // CHECK:   return self.operation.operands[0]
354   // CHECK: @builtins.property
355   // CHECK: def optional(self):
356   // CHECK:   return None if len(self.operation.operands) < 2 else self.operation.operands[1]
359 // CHECK: def one_optional_operand(non_optional, *, optional=None, loc=None, ip=None)
360 // CHECK:   return OneOptionalOperandOp(non_optional=non_optional, optional=optional, loc=loc, ip=ip)
362 // CHECK: @_ods_cext.register_operation(_Dialect)
363 // CHECK: class OneVariadicOperandOp(_ods_ir.OpView):
364 // CHECK-LABEL: OPERATION_NAME = "test.one_variadic_operand"
365 // CHECK-NOT: _ODS_OPERAND_SEGMENTS
366 // CHECK-NOT: _ODS_RESULT_SEGMENTS
367 def OneVariadicOperandOp : TestOp<"one_variadic_operand"> {
368   // CHECK: def __init__(self, non_variadic, variadic, *, loc=None, ip=None):
369   // CHECK:   operands = []
370   // CHECK:   results = []
371   // CHECK:   attributes = {}
372   // CHECK:   regions = None
373   // CHECK:   operands.append(_get_op_result_or_value(non_variadic))
374   // CHECK:   operands.extend(_get_op_results_or_values(variadic))
375   // CHECK:   _ods_successors = None
376   // CHECK:   super().__init__(self.build_generic(
377   // CHECK:     attributes=attributes, results=results, operands=operands,
378   // CHECK:     successors=_ods_successors, regions=regions, loc=loc, ip=ip))
380   // CHECK: @builtins.property
381   // CHECK: def non_variadic(self):
382   // CHECK:   return self.operation.operands[0]
383   //
384   // CHECK: @builtins.property
385   // CHECK: def variadic(self):
386   // CHECK:   _ods_variadic_group_length = len(self.operation.operands) - 2 + 1
387   // CHECK:   return self.operation.operands[1:1 + _ods_variadic_group_length]
388   let arguments = (ins AnyType:$non_variadic, Variadic<AnyType>:$variadic);
391 // CHECK: def one_variadic_operand(non_variadic, variadic, *, loc=None, ip=None)
392 // CHECK:   return OneVariadicOperandOp(non_variadic=non_variadic, variadic=variadic, loc=loc, ip=ip)
394 // CHECK: @_ods_cext.register_operation(_Dialect)
395 // CHECK: class OneVariadicResultOp(_ods_ir.OpView):
396 // CHECK-LABEL: OPERATION_NAME = "test.one_variadic_result"
397 // CHECK-NOT: _ODS_OPERAND_SEGMENTS
398 // CHECK-NOT: _ODS_RESULT_SEGMENTS
399 def OneVariadicResultOp : TestOp<"one_variadic_result"> {
400   // CHECK: def __init__(self, variadic, non_variadic, *, loc=None, ip=None):
401   // CHECK:   operands = []
402   // CHECK:   results = []
403   // CHECK:   attributes = {}
404   // CHECK:   regions = None
405   // CHECK:   results.extend(variadic)
406   // CHECK:   results.append(non_variadic)
407   // CHECK:   _ods_successors = None
408   // CHECK:   super().__init__(self.build_generic(
409   // CHECK:     attributes=attributes, results=results, operands=operands,
410   // CHECK:     successors=_ods_successors, regions=regions, loc=loc, ip=ip))
412   // CHECK: @builtins.property
413   // CHECK: def variadic(self):
414   // CHECK:   _ods_variadic_group_length = len(self.operation.results) - 2 + 1
415   // CHECK:   return self.operation.results[0:0 + _ods_variadic_group_length]
416   //
417   // CHECK: @builtins.property
418   // CHECK: def non_variadic(self):
419   // CHECK:   _ods_variadic_group_length = len(self.operation.results) - 2 + 1
420   // CHECK:   return self.operation.results[1 + _ods_variadic_group_length - 1]
421   let results = (outs Variadic<AnyType>:$variadic, AnyType:$non_variadic);
424 // CHECK: def one_variadic_result(variadic, non_variadic, *, loc=None, ip=None)
425 // CHECK:   return _get_op_result_or_op_results(OneVariadicResultOp(variadic=variadic, non_variadic=non_variadic, loc=loc, ip=ip))
427 // CHECK: @_ods_cext.register_operation(_Dialect)
428 // CHECK: class PythonKeywordOp(_ods_ir.OpView):
429 // CHECK-LABEL: OPERATION_NAME = "test.python_keyword"
430 def PythonKeywordOp : TestOp<"python_keyword"> {
431   // CHECK: def __init__(self, in_, *, loc=None, ip=None):
432   // CHECK:   operands = []
433   // CHECK:   results = []
434   // CHECK:   attributes = {}
435   // CHECK:   regions = None
436   // CHECK:   operands.append(_get_op_result_or_value(in_))
437   // CHECK:   _ods_successors = None
438   // CHECK:   super().__init__(self.build_generic(
439   // CHECK:     attributes=attributes, results=results, operands=operands,
440   // CHECK:     successors=_ods_successors, regions=regions, loc=loc, ip=ip))
442   // CHECK: @builtins.property
443   // CHECK: def in_(self):
444   // CHECK:   return self.operation.operands[0]
445   let arguments = (ins AnyType:$in);
448 // CHECK: def python_keyword(in_, *, loc=None, ip=None)
449 // CHECK:   return PythonKeywordOp(in_=in_, loc=loc, ip=ip)
451 // CHECK-LABEL: OPERATION_NAME = "test.same_results"
452 def SameResultsOp : TestOp<"same_results", [SameOperandsAndResultType]> {
453   // CHECK: def __init__(self, in1, in2, *, loc=None, ip=None):
454   // CHECK: operands = []
455   // CHECK: results = []
456   // CHECK: operands.append
457   // CHECK: results.extend([operands[0].type] * 1)
458   let arguments = (ins AnyType:$in1, AnyType:$in2);
459   let results = (outs AnyType:$res);
462 // CHECK: def same_results(in1, in2, *, loc=None, ip=None)
463 // CHECK:   return SameResultsOp(in1=in1, in2=in2, loc=loc, ip=ip)
465 // CHECK-LABEL: OPERATION_NAME = "test.same_results_variadic"
466 def SameResultsVariadicOp : TestOp<"same_results_variadic", [SameOperandsAndResultType]> {
467   // CHECK: def __init__(self, res, in1, in2, *, loc=None, ip=None):
468   let arguments = (ins AnyType:$in1, AnyType:$in2);
469   let results = (outs Variadic<AnyType>:$res);
472 // CHECK: def same_results_variadic(res, in1, in2, *, loc=None, ip=None)
473 // CHECK:   return _get_op_result_or_op_results(SameResultsVariadicOp(res=res, in1=in1, in2=in2, loc=loc, ip=ip))
476 // CHECK: @_ods_cext.register_operation(_Dialect)
477 // CHECK: class SameVariadicOperandSizeOp(_ods_ir.OpView):
478 // CHECK-LABEL: OPERATION_NAME = "test.same_variadic_operand"
479 def SameVariadicOperandSizeOp : TestOp<"same_variadic_operand",
480                                        [SameVariadicOperandSize]> {
481   // CHECK: @builtins.property
482   // CHECK: def variadic1(self):
483   // CHECK:   start, elements_per_group = _ods_equally_sized_accessor(self.operation.operands, 1, 2, 0, 0)
484   // CHECK:   return self.operation.operands[start:start + elements_per_group]
485   //
486   // CHECK: @builtins.property
487   // CHECK: def non_variadic(self):
488   // CHECK:   start, elements_per_group = _ods_equally_sized_accessor(self.operation.operands, 1, 2, 0, 1)
489   // CHECK:   return self.operation.operands[start]
490   //
491   // CHECK: @builtins.property
492   // CHECK: def variadic2(self):
493   // CHECK:   start, elements_per_group = _ods_equally_sized_accessor(self.operation.operands, 1, 2, 1, 1)
494   // CHECK:   return self.operation.operands[start:start + elements_per_group]
495   let arguments = (ins Variadic<AnyType>:$variadic1, AnyType:$non_variadic,
496                    Variadic<AnyType>:$variadic2);
499 // CHECK: def same_variadic_operand(variadic1, non_variadic, variadic2, *, loc=None, ip=None)
500 // CHECK:   return SameVariadicOperandSizeOp(variadic1=variadic1, non_variadic=non_variadic, variadic2=variadic2, loc=loc, ip=ip)
502 // CHECK: @_ods_cext.register_operation(_Dialect)
503 // CHECK: class SameVariadicResultSizeOp(_ods_ir.OpView):
504 // CHECK-LABEL: OPERATION_NAME = "test.same_variadic_result"
505 def SameVariadicResultSizeOp : TestOp<"same_variadic_result",
506                                       [SameVariadicResultSize]> {
507   // CHECK: @builtins.property
508   // CHECK: def variadic1(self):
509   // CHECK:   start, elements_per_group = _ods_equally_sized_accessor(self.operation.results, 1, 2, 0, 0)
510   // CHECK:   return self.operation.results[start:start + elements_per_group]
511   //
512   // CHECK: @builtins.property
513   // CHECK: def non_variadic(self):
514   // CHECK:   start, elements_per_group = _ods_equally_sized_accessor(self.operation.results, 1, 2, 0, 1)
515   // CHECK:   return self.operation.results[start]
516   //
517   // CHECK: @builtins.property
518   // CHECK: def variadic2(self):
519   // CHECK:   start, elements_per_group = _ods_equally_sized_accessor(self.operation.results, 1, 2, 1, 1)
520   // CHECK:   return self.operation.results[start:start + elements_per_group]
521   let results = (outs Variadic<AnyType>:$variadic1, AnyType:$non_variadic,
522                  Variadic<AnyType>:$variadic2);
525 // CHECK: def same_variadic_result(variadic1, non_variadic, variadic2, *, loc=None, ip=None)
526 // CHECK:   return _get_op_result_or_op_results(SameVariadicResultSizeOp(variadic1=variadic1, non_variadic=non_variadic, variadic2=variadic2, loc=loc, ip=ip))
528 // CHECK: @_ods_cext.register_operation(_Dialect)
529 // CHECK: class SimpleOp(_ods_ir.OpView):
530 // CHECK-LABEL: OPERATION_NAME = "test.simple"
531 def SimpleOp : TestOp<"simple"> {
532   // CHECK: def __init__(self, i64, f64, i32, f32, *, loc=None, ip=None):
533   // CHECK:   operands = []
534   // CHECK:   results = []
535   // CHECK:   attributes = {}
536   // CHECK:   regions = None
537   // CHECK:   operands.append(_get_op_result_or_value(i32))
538   // CHECK:   operands.append(_get_op_result_or_value(f32))
539   // CHECK:   results.append(i64)
540   // CHECK:   results.append(f64)
541   // CHECK:   _ods_successors = None
542   // CHECK:   super().__init__(self.build_generic(
543   // CHECK:     attributes=attributes, results=results, operands=operands,
544   // CHECK:     successors=_ods_successors, regions=regions, loc=loc, ip=ip))
546   // CHECK: @builtins.property
547   // CHECK: def i32(self):
548   // CHECK:   return self.operation.operands[0]
549   //
550   // CHECK: @builtins.property
551   // CHECK: def f32(self):
552   // CHECK:   return self.operation.operands[1]
553   let arguments = (ins I32:$i32, F32:$f32);
555   // CHECK: @builtins.property
556   // CHECK: def i64(self):
557   // CHECK:   return self.operation.results[0]
558   //
559   // CHECK: @builtins.property
560   // CHECK: def f64(self):
561   // CHECK:   return self.operation.results[1]
562   let results = (outs I64:$i64, AnyFloat:$f64);
565 // CHECK: def simple(i64, f64, i32, f32, *, loc=None, ip=None)
566 // CHECK:   return SimpleOp(i64=i64, f64=f64, i32=i32, f32=f32, loc=loc, ip=ip).results
568 // CHECK: class VariadicAndNormalRegionOp(_ods_ir.OpView):
569 // CHECK-LABEL: OPERATION_NAME = "test.variadic_and_normal_region"
570 def VariadicAndNormalRegionOp : TestOp<"variadic_and_normal_region"> {
571   // CHECK:  def __init__(self, num_variadic, *, loc=None, ip=None):
572   // CHECK:    operands = []
573   // CHECK:    results = []
574   // CHECK:    attributes = {}
575   // CHECK:    regions = None
576   // CHECK:    _ods_successors = None
577   // CHECK:    regions = 2 + num_variadic
578   // CHECK:    super().__init__(self.build_generic(
579   // CHECK:      attributes=attributes, results=results, operands=operands,
580   // CHECK:      successors=_ods_successors, regions=regions, loc=loc, ip=ip))
581   let regions = (region AnyRegion:$region, AnyRegion, VariadicRegion<AnyRegion>:$variadic);
583   // CHECK:  @builtins.property
584   // CHECK:  def region(self):
585   // CHECK:    return self.regions[0]
587   // CHECK:  @builtins.property
588   // CHECK:  def variadic(self):
589   // CHECK:    return self.regions[2:]
592 // CHECK: def variadic_and_normal_region(num_variadic, *, loc=None, ip=None)
593 // CHECK:   return VariadicAndNormalRegionOp(num_variadic=num_variadic, loc=loc, ip=ip)
595 // CHECK: class VariadicRegionOp(_ods_ir.OpView):
596 // CHECK-LABEL: OPERATION_NAME = "test.variadic_region"
597 def VariadicRegionOp : TestOp<"variadic_region"> {
598   // CHECK:  def __init__(self, num_variadic, *, loc=None, ip=None):
599   // CHECK:    operands = []
600   // CHECK:    results = []
601   // CHECK:    attributes = {}
602   // CHECK:    regions = None
603   // CHECK:    _ods_successors = None
604   // CHECK:    regions = 0 + num_variadic
605   // CHECK:    super().__init__(self.build_generic(
606   // CHECK:      attributes=attributes, results=results, operands=operands,
607   // CHECK:      successors=_ods_successors, regions=regions, loc=loc, ip=ip))
608   let regions = (region VariadicRegion<AnyRegion>:$Variadic);
610   // CHECK:  @builtins.property
611   // CHECK:  def Variadic(self):
612   // CHECK:    return self.regions[0:]
615 // CHECK: def variadic_region(num_variadic, *, loc=None, ip=None)
616 // CHECK:   return VariadicRegionOp(num_variadic=num_variadic, loc=loc, ip=ip)
618 // CHECK: @_ods_cext.register_operation(_Dialect)
619 // CHECK: class WithSpecialCharactersOp(_ods_ir.OpView):
620 // CHECK-LABEL: OPERATION_NAME = "test.123with--special.characters"
621 def WithSpecialCharactersOp : TestOp<"123with--special.characters"> {
624 // CHECK: def _123with__special_characters(*, loc=None, ip=None)
625 // CHECK:   return WithSpecialCharactersOp(loc=loc, ip=ip)
627 // CHECK: @_ods_cext.register_operation(_Dialect)
628 // CHECK: class WithSuccessorsOp(_ods_ir.OpView):
629 // CHECK-LABEL: OPERATION_NAME = "test.with_successors"
630 def WithSuccessorsOp : TestOp<"with_successors"> {
631   // CHECK-NOT:  _ods_successors = None
632   // CHECK:      _ods_successors = []
633   // CHECK-NEXT: _ods_successors.append(successor)
634   // CHECK-NEXT: _ods_successors.extend(successors)
635   let successors = (successor AnySuccessor:$successor,
636                               VariadicSuccessor<AnySuccessor>:$successors);
639 // CHECK: def with_successors(successor, successors, *, loc=None, ip=None)
640 // CHECK:   return WithSuccessorsOp(successor=successor, successors=successors, loc=loc, ip=ip)