xref: /llvm-project/mlir/test/mlir-tblgen/op-python-bindings.td (revision acde3f722ff3766f6f793884108d342b78623fe4)
1ee6255d2SAlex Zinenko// RUN: mlir-tblgen -gen-python-op-bindings -bind-dialect=test -I %S/../../include %s | FileCheck %s
2fd407e1fSAlex Zinenko
3fd407e1fSAlex Zinenkoinclude "mlir/IR/OpBase.td"
482bbebbfSRahul Kayaithinclude "mlir/IR/AttrTypeBase.td"
52995d29bSAlex Zinenkoinclude "mlir/Interfaces/InferTypeOpInterface.td"
6fd407e1fSAlex Zinenko
78a1f1a10SStella Laurenzo// CHECK: @_ods_cext.register_dialect
88a1f1a10SStella Laurenzo// CHECK: class _Dialect(_ods_ir.Dialect):
9fd407e1fSAlex Zinenko  // CHECK: DIALECT_NAMESPACE = "test"
10fd407e1fSAlex Zinenkodef Test_Dialect : Dialect {
11fd407e1fSAlex Zinenko  let name = "test";
12fd407e1fSAlex Zinenko  let cppNamespace = "Test";
13fd407e1fSAlex Zinenko}
1482bbebbfSRahul Kayaith
15697a5036SSanjoy Dasclass TestOp<string mnemonic, list<Trait> traits = []> :
16fd407e1fSAlex Zinenko    Op<Test_Dialect, mnemonic, traits>;
17fd407e1fSAlex Zinenko
188a1f1a10SStella Laurenzo// CHECK: @_ods_cext.register_operation(_Dialect)
198a1f1a10SStella Laurenzo// CHECK: class AttrSizedOperandsOp(_ods_ir.OpView):
20fd407e1fSAlex Zinenko// CHECK-LABEL: OPERATION_NAME = "test.attr_sized_operands"
216981e5ecSAlex Zinenko// CHECK: _ODS_OPERAND_SEGMENTS = [-1,1,0,]
22fd407e1fSAlex Zinenkodef AttrSizedOperandsOp : TestOp<"attr_sized_operands",
23fd407e1fSAlex Zinenko                                 [AttrSizedOperandSegments]> {
249b79f50bSJeremy Furtek  // CHECK: def __init__(self, variadic1, non_variadic, *, variadic2=None, loc=None, ip=None):
25f9265de8SAlex Zinenko  // CHECK:   operands = []
26f9265de8SAlex Zinenko  // CHECK:   results = []
27f9265de8SAlex Zinenko  // CHECK:   attributes = {}
2818fbd5feSAlex Zinenko  // CHECK:   regions = None
29b164f23cSAlex Zinenko  // CHECK:   operands.append(_get_op_results_or_values(variadic1))
30*acde3f72SPeter Hawkins  // CHECK:   operands.append(non_variadic)
31*acde3f72SPeter Hawkins  // CHECK:   operands.append(variadic2)
328e6c55c9SStella Laurenzo  // CHECK:   _ods_successors = None
33f4125e02SPeter Hawkins  // CHECK:   super().__init__(
34f4125e02SPeter Hawkins  // CHECK:     self.OPERATION_NAME, self._ODS_REGIONS, self._ODS_OPERAND_SEGMENTS, self._ODS_RESULT_SEGMENTS,
35fd226c9bSStella Laurenzo  // CHECK:     attributes=attributes, results=results, operands=operands,
36f4125e02SPeter Hawkins  // CHECK:     successors=_ods_successors, regions=regions, loc=loc, ip=ip)
37f9265de8SAlex Zinenko
38b4c93eceSJohn Demme  // CHECK: @builtins.property
39fd407e1fSAlex Zinenko  // CHECK: def variadic1(self):
408a1f1a10SStella Laurenzo  // CHECK:   operand_range = _ods_segmented_accessor(
41fd407e1fSAlex Zinenko  // CHECK:       self.operation.operands,
42363b6559SMehdi Amini  // CHECK:       self.operation.attributes["operandSegmentSizes"], 0)
43fd407e1fSAlex Zinenko  // CHECK:   return operand_range
446981e5ecSAlex Zinenko  // CHECK-NOT: if len(operand_range)
45fd407e1fSAlex Zinenko  //
46b4c93eceSJohn Demme  // CHECK: @builtins.property
47fd407e1fSAlex Zinenko  // CHECK: def non_variadic(self):
488a1f1a10SStella Laurenzo  // CHECK:   operand_range = _ods_segmented_accessor(
49fd407e1fSAlex Zinenko  // CHECK:       self.operation.operands,
50363b6559SMehdi Amini  // CHECK:       self.operation.attributes["operandSegmentSizes"], 1)
51fd407e1fSAlex Zinenko  // CHECK:   return operand_range[0]
52fd407e1fSAlex Zinenko  //
53b4c93eceSJohn Demme  // CHECK: @builtins.property
54fd407e1fSAlex Zinenko  // CHECK: def variadic2(self):
558a1f1a10SStella Laurenzo  // CHECK:   operand_range = _ods_segmented_accessor(
56fd407e1fSAlex Zinenko  // CHECK:       self.operation.operands,
57363b6559SMehdi Amini  // CHECK:       self.operation.attributes["operandSegmentSizes"], 2)
58fd407e1fSAlex Zinenko  // CHECK:   return operand_range[0] if len(operand_range) > 0 else None
59fd407e1fSAlex Zinenko  let arguments = (ins Variadic<AnyType>:$variadic1, AnyType:$non_variadic,
60fd407e1fSAlex Zinenko                   Optional<AnyType>:$variadic2);
61fd407e1fSAlex Zinenko}
62fd407e1fSAlex Zinenko
6327c6d55cSMaksim Levental// CHECK: def attr_sized_operands(variadic1, non_variadic, *, variadic2=None, loc=None, ip=None)
6451a4f319SPeter Hawkins// CHECK:   return AttrSizedOperandsOp(variadic1=variadic1, non_variadic=non_variadic, variadic2=variadic2, loc=loc, ip=ip)
6527c6d55cSMaksim Levental
668a1f1a10SStella Laurenzo// CHECK: @_ods_cext.register_operation(_Dialect)
678a1f1a10SStella Laurenzo// CHECK: class AttrSizedResultsOp(_ods_ir.OpView):
68fd407e1fSAlex Zinenko// CHECK-LABEL: OPERATION_NAME = "test.attr_sized_results"
696981e5ecSAlex Zinenko// CHECK: _ODS_RESULT_SEGMENTS = [0,1,-1,]
70fd407e1fSAlex Zinenkodef AttrSizedResultsOp : TestOp<"attr_sized_results",
71fd407e1fSAlex Zinenko                               [AttrSizedResultSegments]> {
72fd226c9bSStella Laurenzo  // CHECK: def __init__(self, variadic1, non_variadic, variadic2, *, loc=None, ip=None):
73f9265de8SAlex Zinenko  // CHECK:   operands = []
74f9265de8SAlex Zinenko  // CHECK:   results = []
75f9265de8SAlex Zinenko  // CHECK:   attributes = {}
7618fbd5feSAlex Zinenko  // CHECK:   regions = None
77f9265de8SAlex Zinenko  // CHECK:   if variadic1 is not None: results.append(variadic1)
78f9265de8SAlex Zinenko  // CHECK:   results.append(non_variadic)
796981e5ecSAlex Zinenko  // CHECK:   results.append(variadic2)
808e6c55c9SStella Laurenzo  // CHECK:   _ods_successors = None
81f4125e02SPeter Hawkins  // CHECK:   super().__init__(
82f4125e02SPeter Hawkins  // CHECK:     self.OPERATION_NAME, self._ODS_REGIONS, self._ODS_OPERAND_SEGMENTS, self._ODS_RESULT_SEGMENTS,
83fd226c9bSStella Laurenzo  // CHECK:     attributes=attributes, results=results, operands=operands,
84f4125e02SPeter Hawkins  // CHECK:     successors=_ods_successors, regions=regions, loc=loc, ip=ip)
85f9265de8SAlex Zinenko
86b4c93eceSJohn Demme  // CHECK: @builtins.property
87fd407e1fSAlex Zinenko  // CHECK: def variadic1(self):
888a1f1a10SStella Laurenzo  // CHECK:   result_range = _ods_segmented_accessor(
89fd407e1fSAlex Zinenko  // CHECK:       self.operation.results,
90363b6559SMehdi Amini  // CHECK:       self.operation.attributes["resultSegmentSizes"], 0)
91fd407e1fSAlex Zinenko  // CHECK:   return result_range[0] if len(result_range) > 0 else None
92fd407e1fSAlex Zinenko  //
93b4c93eceSJohn Demme  // CHECK: @builtins.property
94fd407e1fSAlex Zinenko  // CHECK: def non_variadic(self):
958a1f1a10SStella Laurenzo  // CHECK:   result_range = _ods_segmented_accessor(
96fd407e1fSAlex Zinenko  // CHECK:       self.operation.results,
97363b6559SMehdi Amini  // CHECK:       self.operation.attributes["resultSegmentSizes"], 1)
98fd407e1fSAlex Zinenko  // CHECK:   return result_range[0]
99fd407e1fSAlex Zinenko  //
100b4c93eceSJohn Demme  // CHECK: @builtins.property
101fd407e1fSAlex Zinenko  // CHECK: def variadic2(self):
1028a1f1a10SStella Laurenzo  // CHECK:   result_range = _ods_segmented_accessor(
103fd407e1fSAlex Zinenko  // CHECK:       self.operation.results,
104363b6559SMehdi Amini  // CHECK:       self.operation.attributes["resultSegmentSizes"], 2)
105fd407e1fSAlex Zinenko  // CHECK:   return result_range
1066981e5ecSAlex Zinenko  // CHECK-NOT: if len(result_range)
107fd407e1fSAlex Zinenko  let results = (outs Optional<AnyType>:$variadic1, AnyType:$non_variadic,
1086981e5ecSAlex Zinenko                 Variadic<AnyType>:$variadic2);
109fd407e1fSAlex Zinenko}
110fd407e1fSAlex Zinenko
11127c6d55cSMaksim Levental// CHECK: def attr_sized_results(variadic1, non_variadic, variadic2, *, loc=None, ip=None)
11227c6d55cSMaksim Levental// CHECK:   return _get_op_result_or_op_results(AttrSizedResultsOp(variadic1=variadic1, non_variadic=non_variadic, variadic2=variadic2, loc=loc, ip=ip))
11327c6d55cSMaksim Levental
114c5a6712fSAlex Zinenko
1158a1f1a10SStella Laurenzo// CHECK: @_ods_cext.register_operation(_Dialect)
1168a1f1a10SStella Laurenzo// CHECK: class AttributedOp(_ods_ir.OpView):
117c5a6712fSAlex Zinenko// CHECK-LABEL: OPERATION_NAME = "test.attributed_op"
11871b6b010SStella Laurenzo// CHECK-NOT: _ODS_OPERAND_SEGMENTS
11971b6b010SStella Laurenzo// CHECK-NOT: _ODS_RESULT_SEGMENTS
120c5a6712fSAlex Zinenkodef AttributedOp : TestOp<"attributed_op"> {
12167a910bbSRahul Kayaith  // CHECK: def __init__(self, i32attr, in_, *, optionalF32Attr=None, unitAttr=None, loc=None, ip=None):
122c5a6712fSAlex Zinenko  // CHECK:   operands = []
123c5a6712fSAlex Zinenko  // CHECK:   results = []
124c5a6712fSAlex Zinenko  // CHECK:   attributes = {}
12518fbd5feSAlex Zinenko  // CHECK:   regions = None
126b57acb9aSJacques Pienaar  // CHECK:   attributes["i32attr"] = (i32attr if (
12735593f66SSergei Lebedev  // CHECK-NEXT:   isinstance(i32attr, _ods_ir.Attribute) or
128b57acb9aSJacques Pienaar  // CHECK-NEXT:   not _ods_ir.AttrBuilder.contains('I32Attr')
129b57acb9aSJacques Pienaar  // CHECK-NEXT:   _ods_ir.AttrBuilder.get('I32Attr')(i32attr, context=_ods_context)
130b57acb9aSJacques Pienaar  // CHECK:   if optionalF32Attr is not None: attributes["optionalF32Attr"] = (optionalF32Attr
1318a1f1a10SStella Laurenzo  // CHECK:   if bool(unitAttr): attributes["unitAttr"] = _ods_ir.UnitAttr.get(
1328a1f1a10SStella Laurenzo  // CHECK:     _ods_get_default_loc_context(loc))
133b57acb9aSJacques Pienaar  // CHECK:   attributes["in"] = (in_
1348e6c55c9SStella Laurenzo  // CHECK:   _ods_successors = None
135f4125e02SPeter Hawkins  // CHECK:   super().__init__(
136f4125e02SPeter Hawkins  // CHECK:     self.OPERATION_NAME, self._ODS_REGIONS, self._ODS_OPERAND_SEGMENTS, self._ODS_RESULT_SEGMENTS,
137fd226c9bSStella Laurenzo  // CHECK:     attributes=attributes, results=results, operands=operands,
138f4125e02SPeter Hawkins  // CHECK:     successors=_ods_successors, regions=regions, loc=loc, ip=ip)
139c5a6712fSAlex Zinenko
140b4c93eceSJohn Demme  // CHECK: @builtins.property
141c5a6712fSAlex Zinenko  // CHECK: def i32attr(self):
14267a910bbSRahul Kayaith  // CHECK:   return self.operation.attributes["i32attr"]
143c5a6712fSAlex Zinenko
144b4c93eceSJohn Demme  // CHECK: @builtins.property
145c5a6712fSAlex Zinenko  // CHECK: def optionalF32Attr(self):
146c5a6712fSAlex Zinenko  // CHECK:   if "optionalF32Attr" not in self.operation.attributes:
147c5a6712fSAlex Zinenko  // CHECK:     return None
14867a910bbSRahul Kayaith  // CHECK:   return self.operation.attributes["optionalF32Attr"]
149c5a6712fSAlex Zinenko
150b4c93eceSJohn Demme  // CHECK: @builtins.property
151c5a6712fSAlex Zinenko  // CHECK: def unitAttr(self):
152c5a6712fSAlex Zinenko  // CHECK:   return "unitAttr" in self.operation.attributes
153c5a6712fSAlex Zinenko
154b4c93eceSJohn Demme  // CHECK: @builtins.property
155c5a6712fSAlex Zinenko  // CHECK: def in_(self):
15667a910bbSRahul Kayaith  // CHECK:   return self.operation.attributes["in"]
15782bbebbfSRahul Kayaith
158c5a6712fSAlex Zinenko  let arguments = (ins I32Attr:$i32attr, OptionalAttr<F32Attr>:$optionalF32Attr,
15967a910bbSRahul Kayaith                   UnitAttr:$unitAttr, I32Attr:$in);
160c5a6712fSAlex Zinenko}
161c5a6712fSAlex Zinenko
16227c6d55cSMaksim Levental// CHECK: def attributed_op(i32attr, in_, *, optional_f32_attr=None, unit_attr=None, loc=None, ip=None)
16351a4f319SPeter Hawkins// CHECK:     return AttributedOp(i32attr=i32attr, in_=in_, optionalF32Attr=optional_f32_attr, unitAttr=unit_attr, loc=loc, ip=ip)
16427c6d55cSMaksim Levental
1658a1f1a10SStella Laurenzo// CHECK: @_ods_cext.register_operation(_Dialect)
1668a1f1a10SStella Laurenzo// CHECK: class AttributedOpWithOperands(_ods_ir.OpView):
167c5a6712fSAlex Zinenko// CHECK-LABEL: OPERATION_NAME = "test.attributed_op_with_operands"
16871b6b010SStella Laurenzo// CHECK-NOT: _ODS_OPERAND_SEGMENTS
16971b6b010SStella Laurenzo// CHECK-NOT: _ODS_RESULT_SEGMENTS
170c5a6712fSAlex Zinenkodef AttributedOpWithOperands : TestOp<"attributed_op_with_operands"> {
1719b79f50bSJeremy Furtek  // CHECK: def __init__(self, _gen_arg_0, _gen_arg_2, *, in_=None, is_=None, loc=None, ip=None):
172c5a6712fSAlex Zinenko  // CHECK:   operands = []
173c5a6712fSAlex Zinenko  // CHECK:   results = []
174c5a6712fSAlex Zinenko  // CHECK:   attributes = {}
17518fbd5feSAlex Zinenko  // CHECK:   regions = None
176*acde3f72SPeter Hawkins  // CHECK:   operands.append(_gen_arg_0)
177*acde3f72SPeter Hawkins  // CHECK:   operands.append(_gen_arg_2)
1788a1f1a10SStella Laurenzo  // CHECK:   if bool(in_): attributes["in"] = _ods_ir.UnitAttr.get(
1798a1f1a10SStella Laurenzo  // CHECK:     _ods_get_default_loc_context(loc))
180b57acb9aSJacques Pienaar  // CHECK:   if is_ is not None: attributes["is"] = (is_
1818e6c55c9SStella Laurenzo  // CHECK:   _ods_successors = None
182f4125e02SPeter Hawkins  // CHECK:   super().__init__(
183f4125e02SPeter Hawkins  // CHECK:     self.OPERATION_NAME, self._ODS_REGIONS, self._ODS_OPERAND_SEGMENTS, self._ODS_RESULT_SEGMENTS,
184fd226c9bSStella Laurenzo  // CHECK:     attributes=attributes, results=results, operands=operands,
185f4125e02SPeter Hawkins  // CHECK:     successors=_ods_successors, regions=regions, loc=loc, ip=ip)
186c5a6712fSAlex Zinenko
187b4c93eceSJohn Demme  // CHECK: @builtins.property
188c5a6712fSAlex Zinenko  // CHECK: def in_(self):
189c5a6712fSAlex Zinenko  // CHECK:   return "in" in self.operation.attributes
190c5a6712fSAlex Zinenko
191b4c93eceSJohn Demme  // CHECK: @builtins.property
192c5a6712fSAlex Zinenko  // CHECK: def is_(self):
193c5a6712fSAlex Zinenko  // CHECK:   if "is" not in self.operation.attributes:
194c5a6712fSAlex Zinenko  // CHECK:     return None
19567a910bbSRahul Kayaith  // CHECK:   return self.operation.attributes["is"]
196c5a6712fSAlex Zinenko  let arguments = (ins I32, UnitAttr:$in, F32, OptionalAttr<F32Attr>:$is);
197c5a6712fSAlex Zinenko}
198c5a6712fSAlex Zinenko
19927c6d55cSMaksim Levental// CHECK: def attributed_op_with_operands(_gen_arg_0, _gen_arg_2, *, in_=None, is_=None, loc=None, ip=None)
20051a4f319SPeter Hawkins// CHECK:   return AttributedOpWithOperands(_gen_arg_0=_gen_arg_0, _gen_arg_2=_gen_arg_2, in_=in_, is_=is_, loc=loc, ip=ip)
20127c6d55cSMaksim Levental
202989d2b51SMatthias Springer// CHECK: @_ods_cext.register_operation(_Dialect)
203989d2b51SMatthias Springer// CHECK: class DefaultValuedAttrsOp(_ods_ir.OpView):
204989d2b51SMatthias Springer// CHECK-LABEL: OPERATION_NAME = "test.default_valued_attrs"
205989d2b51SMatthias Springerdef DefaultValuedAttrsOp : TestOp<"default_valued_attrs"> {
206989d2b51SMatthias Springer  // CHECK: def __init__(self, *, arr=None, unsupported=None, loc=None, ip=None):
207989d2b51SMatthias Springer  // CHECK:   operands = []
208989d2b51SMatthias Springer  // CHECK:   results = []
209989d2b51SMatthias Springer  // CHECK:   attributes = {}
210989d2b51SMatthias Springer  // CHECK:   regions = None
211b57acb9aSJacques Pienaar  // CHECK:   if arr is not None: attributes["arr"] = (arr
212b57acb9aSJacques Pienaar  // CHECK:   if unsupported is not None: attributes["unsupported"] = (unsupported
213989d2b51SMatthias Springer  // CHECK:   _ods_successors = None
214f4125e02SPeter Hawkins  // CHECK:   super().__init__(
215f4125e02SPeter Hawkins  // CHECK:     self.OPERATION_NAME, self._ODS_REGIONS, self._ODS_OPERAND_SEGMENTS, self._ODS_RESULT_SEGMENTS,
216989d2b51SMatthias Springer  // CHECK:     attributes=attributes, results=results, operands=operands,
217f4125e02SPeter Hawkins  // CHECK:     successors=_ods_successors, regions=regions, loc=loc, ip=ip)
218989d2b51SMatthias Springer
219989d2b51SMatthias Springer  let arguments = (ins DefaultValuedAttr<I64ArrayAttr, "{}">:$arr,
220989d2b51SMatthias Springer                       DefaultValuedAttr<I64ArrayAttr, "dummy_func()">:$unsupported);
221989d2b51SMatthias Springer  let results = (outs);
222989d2b51SMatthias Springer}
223989d2b51SMatthias Springer
22427c6d55cSMaksim Levental// CHECK: def default_valued_attrs(*, arr=None, unsupported=None, loc=None, ip=None)
22551a4f319SPeter Hawkins// CHECK:   return DefaultValuedAttrsOp(arr=arr, unsupported=unsupported, loc=loc, ip=ip)
22627c6d55cSMaksim Levental
2272995d29bSAlex Zinenko// CHECK-LABEL: OPERATION_NAME = "test.derive_result_types_op"
2282995d29bSAlex Zinenkodef DeriveResultTypesOp : TestOp<"derive_result_types_op", [FirstAttrDerivedResultType]> {
229b57acb9aSJacques Pienaar  // CHECK: def __init__(self, type_, *, loc=None, ip=None):
2302995d29bSAlex Zinenko  // CHECK:   operands = []
2312995d29bSAlex Zinenko  // CHECK:   results = []
2322995d29bSAlex Zinenko  // CHECK:   _ods_result_type_source_attr = attributes["type"]
2332995d29bSAlex Zinenko  // CHECK:   _ods_derived_result_type = (
2342995d29bSAlex Zinenko  // CHECK:       _ods_ir.TypeAttr(_ods_result_type_source_attr).value
2352995d29bSAlex Zinenko  // CHECK:       if _ods_ir.TypeAttr.isinstance(_ods_result_type_source_attr) else
2362995d29bSAlex Zinenko  // CHECK:       _ods_result_type_source_attr.type)
2372995d29bSAlex Zinenko  // CHECK:   results.extend([_ods_derived_result_type] * 2)
2382995d29bSAlex Zinenko  let arguments = (ins TypeAttr:$type);
2392995d29bSAlex Zinenko  let results = (outs AnyType:$res, AnyType);
2402995d29bSAlex Zinenko}
2412995d29bSAlex Zinenko
24227c6d55cSMaksim Levental// CHECK: def derive_result_types_op(type_, *, loc=None, ip=None)
24351a4f319SPeter Hawkins// CHECK:   return DeriveResultTypesOp(type_=type_, loc=loc, ip=ip).results
24427c6d55cSMaksim Levental
2452995d29bSAlex Zinenko// CHECK-LABEL: OPERATION_NAME = "test.derive_result_types_variadic_op"
2462995d29bSAlex Zinenkodef DeriveResultTypesVariadicOp : TestOp<"derive_result_types_variadic_op", [FirstAttrDerivedResultType]> {
247b57acb9aSJacques Pienaar  // CHECK: def __init__(self, res, _gen_res_1, type_, *, loc=None, ip=None):
2482995d29bSAlex Zinenko  let arguments = (ins TypeAttr:$type);
2492995d29bSAlex Zinenko  let results = (outs AnyType:$res, Variadic<AnyType>);
2502995d29bSAlex Zinenko}
251c5a6712fSAlex Zinenko
25227c6d55cSMaksim Levental// CHECK: def derive_result_types_variadic_op(res, _gen_res_1, type_, *, loc=None, ip=None)
25327c6d55cSMaksim Levental// CHECK:   return _get_op_result_or_op_results(DeriveResultTypesVariadicOp(res=res, _gen_res_1=_gen_res_1, type_=type_, loc=loc, ip=ip))
25427c6d55cSMaksim Levental
2558a1f1a10SStella Laurenzo// CHECK: @_ods_cext.register_operation(_Dialect)
2568a1f1a10SStella Laurenzo// CHECK: class EmptyOp(_ods_ir.OpView):
257fd407e1fSAlex Zinenko// CHECK-LABEL: OPERATION_NAME = "test.empty"
258fd407e1fSAlex Zinenkodef EmptyOp : TestOp<"empty">;
259fd226c9bSStella Laurenzo  // CHECK: def __init__(self, *, loc=None, ip=None):
260f9265de8SAlex Zinenko  // CHECK:   operands = []
261f9265de8SAlex Zinenko  // CHECK:   results = []
262f9265de8SAlex Zinenko  // CHECK:   attributes = {}
26318fbd5feSAlex Zinenko  // CHECK:   regions = None
2648e6c55c9SStella Laurenzo  // CHECK:   _ods_successors = None
265f4125e02SPeter Hawkins  // CHECK:   super().__init__(
266f4125e02SPeter Hawkins  // CHECK:     self.OPERATION_NAME, self._ODS_REGIONS, self._ODS_OPERAND_SEGMENTS, self._ODS_RESULT_SEGMENTS,
267fd226c9bSStella Laurenzo  // CHECK:     attributes=attributes, results=results, operands=operands,
268f4125e02SPeter Hawkins  // CHECK:     successors=_ods_successors, regions=regions, loc=loc, ip=ip)
269fd407e1fSAlex Zinenko
27027c6d55cSMaksim Levental// CHECK: def empty(*, loc=None, ip=None)
27151a4f319SPeter Hawkins// CHECK:   return EmptyOp(loc=loc, ip=ip)
2722995d29bSAlex Zinenko
2732995d29bSAlex Zinenko// CHECK-LABEL: OPERATION_NAME = "test.infer_result_types_implied_op"
2742995d29bSAlex Zinenkodef InferResultTypesImpliedOp : TestOp<"infer_result_types_implied_op"> {
2752995d29bSAlex Zinenko  // CHECK:  def __init__(self, *, loc=None, ip=None):
2762995d29bSAlex Zinenko  // CHECK:    _ods_context = _ods_get_default_loc_context(loc)
277f4125e02SPeter Hawkins  // CHECK:   super().__init__(
278f4125e02SPeter Hawkins  // CHECK:     self.OPERATION_NAME, self._ODS_REGIONS, self._ODS_OPERAND_SEGMENTS, self._ODS_RESULT_SEGMENTS,
279f573bc24SJacques Pienaar  // CHECK:     attributes=attributes, operands=operands,
280f4125e02SPeter Hawkins  // CHECK:     successors=_ods_successors, regions=regions, loc=loc, ip=ip)
2812995d29bSAlex Zinenko  let results = (outs I32:$i32, F32:$f32);
2822995d29bSAlex Zinenko}
2832995d29bSAlex Zinenko
28427c6d55cSMaksim Levental// CHECK: def infer_result_types_implied_op(*, loc=None, ip=None)
28551a4f319SPeter Hawkins// CHECK:   return InferResultTypesImpliedOp(loc=loc, ip=ip).results
28627c6d55cSMaksim Levental
2872995d29bSAlex Zinenko// CHECK-LABEL: OPERATION_NAME = "test.infer_result_types_op"
2882995d29bSAlex Zinenkodef InferResultTypesOp : TestOp<"infer_result_types_op", [InferTypeOpInterface]> {
2892995d29bSAlex Zinenko  // CHECK:  def __init__(self, *, loc=None, ip=None):
2902995d29bSAlex Zinenko  // CHECK:    operands = []
291f4125e02SPeter Hawkins  // CHECK:   super().__init__(
292f4125e02SPeter Hawkins  // CHECK:     self.OPERATION_NAME, self._ODS_REGIONS, self._ODS_OPERAND_SEGMENTS, self._ODS_RESULT_SEGMENTS,
293f573bc24SJacques Pienaar  // CHECK:     attributes=attributes, operands=operands,
294f4125e02SPeter Hawkins  // CHECK:     successors=_ods_successors, regions=regions, loc=loc, ip=ip)
2952995d29bSAlex Zinenko  let results = (outs AnyType, AnyType, AnyType);
2962995d29bSAlex Zinenko}
2972995d29bSAlex Zinenko
29827c6d55cSMaksim Levental// CHECK: def infer_result_types_op(*, loc=None, ip=None)
29951a4f319SPeter Hawkins// CHECK:   return InferResultTypesOp(loc=loc, ip=ip).results
30027c6d55cSMaksim Levental
3018a1f1a10SStella Laurenzo// CHECK: @_ods_cext.register_operation(_Dialect)
3028a1f1a10SStella Laurenzo// CHECK: class MissingNamesOp(_ods_ir.OpView):
303fd407e1fSAlex Zinenko// CHECK-LABEL: OPERATION_NAME = "test.missing_names"
304fd407e1fSAlex Zinenkodef MissingNamesOp : TestOp<"missing_names"> {
305fd226c9bSStella Laurenzo  // CHECK: def __init__(self, i32, _gen_res_1, i64, _gen_arg_0, f32, _gen_arg_2, *, loc=None, ip=None):
306f9265de8SAlex Zinenko  // CHECK:   operands = []
307f9265de8SAlex Zinenko  // CHECK:   results = []
308f9265de8SAlex Zinenko  // CHECK:   attributes = {}
30918fbd5feSAlex Zinenko  // CHECK:   regions = None
310*acde3f72SPeter Hawkins  // CHECK:   operands.append(_gen_arg_0)
311*acde3f72SPeter Hawkins  // CHECK:   operands.append(f32)
312*acde3f72SPeter Hawkins  // CHECK:   operands.append(_gen_arg_2)
3132995d29bSAlex Zinenko  // CHECK:   results.append(i32)
3142995d29bSAlex Zinenko  // CHECK:   results.append(_gen_res_1)
3152995d29bSAlex Zinenko  // CHECK:   results.append(i64)
3168e6c55c9SStella Laurenzo  // CHECK:   _ods_successors = None
317f4125e02SPeter Hawkins  // CHECK:   super().__init__(
318f4125e02SPeter Hawkins  // CHECK:     self.OPERATION_NAME, self._ODS_REGIONS, self._ODS_OPERAND_SEGMENTS, self._ODS_RESULT_SEGMENTS
319fd226c9bSStella Laurenzo  // CHECK:     attributes=attributes, results=results, operands=operands,
320f4125e02SPeter Hawkins  // CHECK:     successors=_ods_successors, regions=regions, loc=loc, ip=ip)
321f9265de8SAlex Zinenko
322b4c93eceSJohn Demme  // CHECK: @builtins.property
323fd407e1fSAlex Zinenko  // CHECK: def f32(self):
324fd407e1fSAlex Zinenko  // CHECK:   return self.operation.operands[1]
325fd407e1fSAlex Zinenko  let arguments = (ins I32, F32:$f32, I64);
326fd407e1fSAlex Zinenko
327b4c93eceSJohn Demme  // CHECK: @builtins.property
328fd407e1fSAlex Zinenko  // CHECK: def i32(self):
329fd407e1fSAlex Zinenko  // CHECK:   return self.operation.results[0]
330fd407e1fSAlex Zinenko  //
331b4c93eceSJohn Demme  // CHECK: @builtins.property
332fd407e1fSAlex Zinenko  // CHECK: def i64(self):
333fd407e1fSAlex Zinenko  // CHECK:   return self.operation.results[2]
3342995d29bSAlex Zinenko  let results = (outs I32:$i32, AnyFloat, I64:$i64);
335fd407e1fSAlex Zinenko}
336fd407e1fSAlex Zinenko
33727c6d55cSMaksim Levental// CHECK: def missing_names(i32, _gen_res_1, i64, _gen_arg_0, f32, _gen_arg_2, *, loc=None, ip=None)
33851a4f319SPeter Hawkins// 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
33927c6d55cSMaksim Levental
3408a1f1a10SStella Laurenzo// CHECK: @_ods_cext.register_operation(_Dialect)
3416981e5ecSAlex Zinenko// CHECK: class OneOptionalOperandOp(_ods_ir.OpView):
3426981e5ecSAlex Zinenko// CHECK-LABEL: OPERATION_NAME = "test.one_optional_operand"
3436981e5ecSAlex Zinenko// CHECK-NOT: _ODS_OPERAND_SEGMENTS
3446981e5ecSAlex Zinenko// CHECK-NOT: _ODS_RESULT_SEGMENTS
3456981e5ecSAlex Zinenkodef OneOptionalOperandOp : TestOp<"one_optional_operand"> {
3466981e5ecSAlex Zinenko  let arguments = (ins AnyType:$non_optional, Optional<AnyType>:$optional);
3479b79f50bSJeremy Furtek  // CHECK: def __init__(self, non_optional, *, optional=None, loc=None, ip=None):
3486981e5ecSAlex Zinenko  // CHECK:   operands = []
3496981e5ecSAlex Zinenko  // CHECK:   results = []
3506981e5ecSAlex Zinenko  // CHECK:   attributes = {}
3516981e5ecSAlex Zinenko  // CHECK:   regions = None
352*acde3f72SPeter Hawkins  // CHECK:   operands.append(non_optional)
353*acde3f72SPeter Hawkins  // CHECK:   if optional is not None: operands.append(optional)
3546981e5ecSAlex Zinenko  // CHECK:   _ods_successors = None
355f4125e02SPeter Hawkins  // CHECK:   super().__init__(
356f4125e02SPeter Hawkins  // CHECK:     self.OPERATION_NAME, self._ODS_REGIONS, self._ODS_OPERAND_SEGMENTS, self._ODS_RESULT_SEGMENTS
3576981e5ecSAlex Zinenko  // CHECK:     attributes=attributes, results=results, operands=operands,
358f4125e02SPeter Hawkins  // CHECK:     successors=_ods_successors, regions=regions, loc=loc, ip=ip)
3596981e5ecSAlex Zinenko
3606981e5ecSAlex Zinenko  // CHECK: @builtins.property
3616981e5ecSAlex Zinenko  // CHECK: def non_optional(self):
3626981e5ecSAlex Zinenko  // CHECK:   return self.operation.operands[0]
3636981e5ecSAlex Zinenko
3646981e5ecSAlex Zinenko  // CHECK: @builtins.property
3656981e5ecSAlex Zinenko  // CHECK: def optional(self):
36654c99842SMichal Terepeta  // CHECK:   return None if len(self.operation.operands) < 2 else self.operation.operands[1]
3676981e5ecSAlex Zinenko}
3686981e5ecSAlex Zinenko
36927c6d55cSMaksim Levental// CHECK: def one_optional_operand(non_optional, *, optional=None, loc=None, ip=None)
37051a4f319SPeter Hawkins// CHECK:   return OneOptionalOperandOp(non_optional=non_optional, optional=optional, loc=loc, ip=ip)
37127c6d55cSMaksim Levental
3726981e5ecSAlex Zinenko// CHECK: @_ods_cext.register_operation(_Dialect)
3738a1f1a10SStella Laurenzo// CHECK: class OneVariadicOperandOp(_ods_ir.OpView):
374fd407e1fSAlex Zinenko// CHECK-LABEL: OPERATION_NAME = "test.one_variadic_operand"
37571b6b010SStella Laurenzo// CHECK-NOT: _ODS_OPERAND_SEGMENTS
37671b6b010SStella Laurenzo// CHECK-NOT: _ODS_RESULT_SEGMENTS
377fd407e1fSAlex Zinenkodef OneVariadicOperandOp : TestOp<"one_variadic_operand"> {
378fd226c9bSStella Laurenzo  // CHECK: def __init__(self, non_variadic, variadic, *, loc=None, ip=None):
379f9265de8SAlex Zinenko  // CHECK:   operands = []
380f9265de8SAlex Zinenko  // CHECK:   results = []
381f9265de8SAlex Zinenko  // CHECK:   attributes = {}
38218fbd5feSAlex Zinenko  // CHECK:   regions = None
383*acde3f72SPeter Hawkins  // CHECK:   operands.append(non_variadic)
384b164f23cSAlex Zinenko  // CHECK:   operands.extend(_get_op_results_or_values(variadic))
3858e6c55c9SStella Laurenzo  // CHECK:   _ods_successors = None
386f4125e02SPeter Hawkins  // CHECK:   super().__init__(
387f4125e02SPeter Hawkins  // CHECK:     self.OPERATION_NAME, self._ODS_REGIONS, self._ODS_OPERAND_SEGMENTS, self._ODS_RESULT_SEGMENTS
388fd226c9bSStella Laurenzo  // CHECK:     attributes=attributes, results=results, operands=operands,
389f4125e02SPeter Hawkins  // CHECK:     successors=_ods_successors, regions=regions, loc=loc, ip=ip)
390f9265de8SAlex Zinenko
391b4c93eceSJohn Demme  // CHECK: @builtins.property
392fd407e1fSAlex Zinenko  // CHECK: def non_variadic(self):
393fd407e1fSAlex Zinenko  // CHECK:   return self.operation.operands[0]
394fd407e1fSAlex Zinenko  //
395b4c93eceSJohn Demme  // CHECK: @builtins.property
396fd407e1fSAlex Zinenko  // CHECK: def variadic(self):
3978a1f1a10SStella Laurenzo  // CHECK:   _ods_variadic_group_length = len(self.operation.operands) - 2 + 1
3988a1f1a10SStella Laurenzo  // CHECK:   return self.operation.operands[1:1 + _ods_variadic_group_length]
399fd407e1fSAlex Zinenko  let arguments = (ins AnyType:$non_variadic, Variadic<AnyType>:$variadic);
400fd407e1fSAlex Zinenko}
401fd407e1fSAlex Zinenko
40227c6d55cSMaksim Levental// CHECK: def one_variadic_operand(non_variadic, variadic, *, loc=None, ip=None)
40351a4f319SPeter Hawkins// CHECK:   return OneVariadicOperandOp(non_variadic=non_variadic, variadic=variadic, loc=loc, ip=ip)
40427c6d55cSMaksim Levental
4058a1f1a10SStella Laurenzo// CHECK: @_ods_cext.register_operation(_Dialect)
4068a1f1a10SStella Laurenzo// CHECK: class OneVariadicResultOp(_ods_ir.OpView):
407fd407e1fSAlex Zinenko// CHECK-LABEL: OPERATION_NAME = "test.one_variadic_result"
40871b6b010SStella Laurenzo// CHECK-NOT: _ODS_OPERAND_SEGMENTS
40971b6b010SStella Laurenzo// CHECK-NOT: _ODS_RESULT_SEGMENTS
410fd407e1fSAlex Zinenkodef OneVariadicResultOp : TestOp<"one_variadic_result"> {
411fd226c9bSStella Laurenzo  // CHECK: def __init__(self, variadic, non_variadic, *, loc=None, ip=None):
412f9265de8SAlex Zinenko  // CHECK:   operands = []
413f9265de8SAlex Zinenko  // CHECK:   results = []
414f9265de8SAlex Zinenko  // CHECK:   attributes = {}
41518fbd5feSAlex Zinenko  // CHECK:   regions = None
41671b6b010SStella Laurenzo  // CHECK:   results.extend(variadic)
417f9265de8SAlex Zinenko  // CHECK:   results.append(non_variadic)
4188e6c55c9SStella Laurenzo  // CHECK:   _ods_successors = None
419f4125e02SPeter Hawkins  // CHECK:   super().__init__(
420f4125e02SPeter Hawkins  // CHECK:     self.OPERATION_NAME, self._ODS_REGIONS, self._ODS_OPERAND_SEGMENTS, self._ODS_RESULT_SEGMENTS
421fd226c9bSStella Laurenzo  // CHECK:     attributes=attributes, results=results, operands=operands,
422f4125e02SPeter Hawkins  // CHECK:     successors=_ods_successors, regions=regions, loc=loc, ip=ip)
423f9265de8SAlex Zinenko
424b4c93eceSJohn Demme  // CHECK: @builtins.property
425fd407e1fSAlex Zinenko  // CHECK: def variadic(self):
4268a1f1a10SStella Laurenzo  // CHECK:   _ods_variadic_group_length = len(self.operation.results) - 2 + 1
4278a1f1a10SStella Laurenzo  // CHECK:   return self.operation.results[0:0 + _ods_variadic_group_length]
428fd407e1fSAlex Zinenko  //
429b4c93eceSJohn Demme  // CHECK: @builtins.property
430fd407e1fSAlex Zinenko  // CHECK: def non_variadic(self):
4318a1f1a10SStella Laurenzo  // CHECK:   _ods_variadic_group_length = len(self.operation.results) - 2 + 1
4328a1f1a10SStella Laurenzo  // CHECK:   return self.operation.results[1 + _ods_variadic_group_length - 1]
433fd407e1fSAlex Zinenko  let results = (outs Variadic<AnyType>:$variadic, AnyType:$non_variadic);
434fd407e1fSAlex Zinenko}
435fd407e1fSAlex Zinenko
43627c6d55cSMaksim Levental// CHECK: def one_variadic_result(variadic, non_variadic, *, loc=None, ip=None)
43727c6d55cSMaksim Levental// CHECK:   return _get_op_result_or_op_results(OneVariadicResultOp(variadic=variadic, non_variadic=non_variadic, loc=loc, ip=ip))
43827c6d55cSMaksim Levental
4398a1f1a10SStella Laurenzo// CHECK: @_ods_cext.register_operation(_Dialect)
4408a1f1a10SStella Laurenzo// CHECK: class PythonKeywordOp(_ods_ir.OpView):
441fd407e1fSAlex Zinenko// CHECK-LABEL: OPERATION_NAME = "test.python_keyword"
442fd407e1fSAlex Zinenkodef PythonKeywordOp : TestOp<"python_keyword"> {
443fd226c9bSStella Laurenzo  // CHECK: def __init__(self, in_, *, loc=None, ip=None):
444f9265de8SAlex Zinenko  // CHECK:   operands = []
445f9265de8SAlex Zinenko  // CHECK:   results = []
446f9265de8SAlex Zinenko  // CHECK:   attributes = {}
44718fbd5feSAlex Zinenko  // CHECK:   regions = None
448*acde3f72SPeter Hawkins  // CHECK:   operands.append(in_)
4498e6c55c9SStella Laurenzo  // CHECK:   _ods_successors = None
450f4125e02SPeter Hawkins  // CHECK:   super().__init__(
451f4125e02SPeter Hawkins  // CHECK:     self.OPERATION_NAME, self._ODS_REGIONS, self._ODS_OPERAND_SEGMENTS, self._ODS_RESULT_SEGMENTS
452fd226c9bSStella Laurenzo  // CHECK:     attributes=attributes, results=results, operands=operands,
453f4125e02SPeter Hawkins  // CHECK:     successors=_ods_successors, regions=regions, loc=loc, ip=ip)
454f9265de8SAlex Zinenko
455b4c93eceSJohn Demme  // CHECK: @builtins.property
456fd407e1fSAlex Zinenko  // CHECK: def in_(self):
457fd407e1fSAlex Zinenko  // CHECK:   return self.operation.operands[0]
458fd407e1fSAlex Zinenko  let arguments = (ins AnyType:$in);
459fd407e1fSAlex Zinenko}
46027c6d55cSMaksim Levental
46127c6d55cSMaksim Levental// CHECK: def python_keyword(in_, *, loc=None, ip=None)
46251a4f319SPeter Hawkins// CHECK:   return PythonKeywordOp(in_=in_, loc=loc, ip=ip)
46327c6d55cSMaksim Levental
4642995d29bSAlex Zinenko// CHECK-LABEL: OPERATION_NAME = "test.same_results"
4652995d29bSAlex Zinenkodef SameResultsOp : TestOp<"same_results", [SameOperandsAndResultType]> {
4662995d29bSAlex Zinenko  // CHECK: def __init__(self, in1, in2, *, loc=None, ip=None):
4672995d29bSAlex Zinenko  // CHECK: operands = []
4682995d29bSAlex Zinenko  // CHECK: results = []
4692995d29bSAlex Zinenko  // CHECK: operands.append
4702995d29bSAlex Zinenko  // CHECK: results.extend([operands[0].type] * 1)
4712995d29bSAlex Zinenko  let arguments = (ins AnyType:$in1, AnyType:$in2);
4722995d29bSAlex Zinenko  let results = (outs AnyType:$res);
4732995d29bSAlex Zinenko}
4742995d29bSAlex Zinenko
47527c6d55cSMaksim Levental// CHECK: def same_results(in1, in2, *, loc=None, ip=None)
47651a4f319SPeter Hawkins// CHECK:   return SameResultsOp(in1=in1, in2=in2, loc=loc, ip=ip)
47727c6d55cSMaksim Levental
4782995d29bSAlex Zinenko// CHECK-LABEL: OPERATION_NAME = "test.same_results_variadic"
4792995d29bSAlex Zinenkodef SameResultsVariadicOp : TestOp<"same_results_variadic", [SameOperandsAndResultType]> {
4802995d29bSAlex Zinenko  // CHECK: def __init__(self, res, in1, in2, *, loc=None, ip=None):
4812995d29bSAlex Zinenko  let arguments = (ins AnyType:$in1, AnyType:$in2);
4822995d29bSAlex Zinenko  let results = (outs Variadic<AnyType>:$res);
4832995d29bSAlex Zinenko}
4842995d29bSAlex Zinenko
48527c6d55cSMaksim Levental// CHECK: def same_results_variadic(res, in1, in2, *, loc=None, ip=None)
48627c6d55cSMaksim Levental// CHECK:   return _get_op_result_or_op_results(SameResultsVariadicOp(res=res, in1=in1, in2=in2, loc=loc, ip=ip))
48727c6d55cSMaksim Levental
488fd407e1fSAlex Zinenko
4898a1f1a10SStella Laurenzo// CHECK: @_ods_cext.register_operation(_Dialect)
4908a1f1a10SStella Laurenzo// CHECK: class SameVariadicOperandSizeOp(_ods_ir.OpView):
491fd407e1fSAlex Zinenko// CHECK-LABEL: OPERATION_NAME = "test.same_variadic_operand"
492fd407e1fSAlex Zinenkodef SameVariadicOperandSizeOp : TestOp<"same_variadic_operand",
493fd407e1fSAlex Zinenko                                       [SameVariadicOperandSize]> {
494b4c93eceSJohn Demme  // CHECK: @builtins.property
495fd407e1fSAlex Zinenko  // CHECK: def variadic1(self):
4963766ba44SKasper Nielsen  // CHECK:   start, elements_per_group = _ods_equally_sized_accessor(self.operation.operands, 1, 2, 0, 0)
4973766ba44SKasper Nielsen  // CHECK:   return self.operation.operands[start:start + elements_per_group]
498fd407e1fSAlex Zinenko  //
499b4c93eceSJohn Demme  // CHECK: @builtins.property
500fd407e1fSAlex Zinenko  // CHECK: def non_variadic(self):
5013766ba44SKasper Nielsen  // CHECK:   start, elements_per_group = _ods_equally_sized_accessor(self.operation.operands, 1, 2, 0, 1)
502fd407e1fSAlex Zinenko  // CHECK:   return self.operation.operands[start]
503fd407e1fSAlex Zinenko  //
504b4c93eceSJohn Demme  // CHECK: @builtins.property
505fd407e1fSAlex Zinenko  // CHECK: def variadic2(self):
5063766ba44SKasper Nielsen  // CHECK:   start, elements_per_group = _ods_equally_sized_accessor(self.operation.operands, 1, 2, 1, 1)
5073766ba44SKasper Nielsen  // CHECK:   return self.operation.operands[start:start + elements_per_group]
508fd407e1fSAlex Zinenko  let arguments = (ins Variadic<AnyType>:$variadic1, AnyType:$non_variadic,
509fd407e1fSAlex Zinenko                   Variadic<AnyType>:$variadic2);
510fd407e1fSAlex Zinenko}
511fd407e1fSAlex Zinenko
51227c6d55cSMaksim Levental// CHECK: def same_variadic_operand(variadic1, non_variadic, variadic2, *, loc=None, ip=None)
51351a4f319SPeter Hawkins// CHECK:   return SameVariadicOperandSizeOp(variadic1=variadic1, non_variadic=non_variadic, variadic2=variadic2, loc=loc, ip=ip)
51427c6d55cSMaksim Levental
5158a1f1a10SStella Laurenzo// CHECK: @_ods_cext.register_operation(_Dialect)
5168a1f1a10SStella Laurenzo// CHECK: class SameVariadicResultSizeOp(_ods_ir.OpView):
517fd407e1fSAlex Zinenko// CHECK-LABEL: OPERATION_NAME = "test.same_variadic_result"
518fd407e1fSAlex Zinenkodef SameVariadicResultSizeOp : TestOp<"same_variadic_result",
519fd407e1fSAlex Zinenko                                      [SameVariadicResultSize]> {
520b4c93eceSJohn Demme  // CHECK: @builtins.property
521fd407e1fSAlex Zinenko  // CHECK: def variadic1(self):
5223766ba44SKasper Nielsen  // CHECK:   start, elements_per_group = _ods_equally_sized_accessor(self.operation.results, 1, 2, 0, 0)
5233766ba44SKasper Nielsen  // CHECK:   return self.operation.results[start:start + elements_per_group]
524fd407e1fSAlex Zinenko  //
525b4c93eceSJohn Demme  // CHECK: @builtins.property
526fd407e1fSAlex Zinenko  // CHECK: def non_variadic(self):
5273766ba44SKasper Nielsen  // CHECK:   start, elements_per_group = _ods_equally_sized_accessor(self.operation.results, 1, 2, 0, 1)
528fd407e1fSAlex Zinenko  // CHECK:   return self.operation.results[start]
529fd407e1fSAlex Zinenko  //
530b4c93eceSJohn Demme  // CHECK: @builtins.property
531fd407e1fSAlex Zinenko  // CHECK: def variadic2(self):
5323766ba44SKasper Nielsen  // CHECK:   start, elements_per_group = _ods_equally_sized_accessor(self.operation.results, 1, 2, 1, 1)
5333766ba44SKasper Nielsen  // CHECK:   return self.operation.results[start:start + elements_per_group]
534fd407e1fSAlex Zinenko  let results = (outs Variadic<AnyType>:$variadic1, AnyType:$non_variadic,
535fd407e1fSAlex Zinenko                 Variadic<AnyType>:$variadic2);
536fd407e1fSAlex Zinenko}
537fd407e1fSAlex Zinenko
53827c6d55cSMaksim Levental// CHECK: def same_variadic_result(variadic1, non_variadic, variadic2, *, loc=None, ip=None)
53927c6d55cSMaksim Levental// CHECK:   return _get_op_result_or_op_results(SameVariadicResultSizeOp(variadic1=variadic1, non_variadic=non_variadic, variadic2=variadic2, loc=loc, ip=ip))
54027c6d55cSMaksim Levental
5418a1f1a10SStella Laurenzo// CHECK: @_ods_cext.register_operation(_Dialect)
5428a1f1a10SStella Laurenzo// CHECK: class SimpleOp(_ods_ir.OpView):
543fd407e1fSAlex Zinenko// CHECK-LABEL: OPERATION_NAME = "test.simple"
544fd407e1fSAlex Zinenkodef SimpleOp : TestOp<"simple"> {
545fd226c9bSStella Laurenzo  // CHECK: def __init__(self, i64, f64, i32, f32, *, loc=None, ip=None):
546f9265de8SAlex Zinenko  // CHECK:   operands = []
547f9265de8SAlex Zinenko  // CHECK:   results = []
548f9265de8SAlex Zinenko  // CHECK:   attributes = {}
54918fbd5feSAlex Zinenko  // CHECK:   regions = None
550*acde3f72SPeter Hawkins  // CHECK:   operands.append(i32)
551*acde3f72SPeter Hawkins  // CHECK:   operands.append(f32)
5522995d29bSAlex Zinenko  // CHECK:   results.append(i64)
5532995d29bSAlex Zinenko  // CHECK:   results.append(f64)
5548e6c55c9SStella Laurenzo  // CHECK:   _ods_successors = None
555f4125e02SPeter Hawkins  // CHECK:   super().__init__(
556f4125e02SPeter Hawkins  // CHECK:     self.OPERATION_NAME, self._ODS_REGIONS, self._ODS_OPERAND_SEGMENTS, self._ODS_RESULT_SEGMENTS
557fd226c9bSStella Laurenzo  // CHECK:     attributes=attributes, results=results, operands=operands,
558f4125e02SPeter Hawkins  // CHECK:     successors=_ods_successors, regions=regions, loc=loc, ip=ip)
559f9265de8SAlex Zinenko
560b4c93eceSJohn Demme  // CHECK: @builtins.property
561fd407e1fSAlex Zinenko  // CHECK: def i32(self):
562fd407e1fSAlex Zinenko  // CHECK:   return self.operation.operands[0]
563fd407e1fSAlex Zinenko  //
564b4c93eceSJohn Demme  // CHECK: @builtins.property
565fd407e1fSAlex Zinenko  // CHECK: def f32(self):
566fd407e1fSAlex Zinenko  // CHECK:   return self.operation.operands[1]
567fd407e1fSAlex Zinenko  let arguments = (ins I32:$i32, F32:$f32);
568fd407e1fSAlex Zinenko
569b4c93eceSJohn Demme  // CHECK: @builtins.property
570fd407e1fSAlex Zinenko  // CHECK: def i64(self):
571fd407e1fSAlex Zinenko  // CHECK:   return self.operation.results[0]
572fd407e1fSAlex Zinenko  //
573b4c93eceSJohn Demme  // CHECK: @builtins.property
574fd407e1fSAlex Zinenko  // CHECK: def f64(self):
575fd407e1fSAlex Zinenko  // CHECK:   return self.operation.results[1]
5762995d29bSAlex Zinenko  let results = (outs I64:$i64, AnyFloat:$f64);
577fd407e1fSAlex Zinenko}
5788e6c55c9SStella Laurenzo
57927c6d55cSMaksim Levental// CHECK: def simple(i64, f64, i32, f32, *, loc=None, ip=None)
58051a4f319SPeter Hawkins// CHECK:   return SimpleOp(i64=i64, f64=f64, i32=i32, f32=f32, loc=loc, ip=ip).results
58127c6d55cSMaksim Levental
58218fbd5feSAlex Zinenko// CHECK: class VariadicAndNormalRegionOp(_ods_ir.OpView):
58318fbd5feSAlex Zinenko// CHECK-LABEL: OPERATION_NAME = "test.variadic_and_normal_region"
58418fbd5feSAlex Zinenkodef VariadicAndNormalRegionOp : TestOp<"variadic_and_normal_region"> {
58518fbd5feSAlex Zinenko  // CHECK:  def __init__(self, num_variadic, *, loc=None, ip=None):
58618fbd5feSAlex Zinenko  // CHECK:    operands = []
58718fbd5feSAlex Zinenko  // CHECK:    results = []
58818fbd5feSAlex Zinenko  // CHECK:    attributes = {}
58918fbd5feSAlex Zinenko  // CHECK:    regions = None
59018fbd5feSAlex Zinenko  // CHECK:    _ods_successors = None
59118fbd5feSAlex Zinenko  // CHECK:    regions = 2 + num_variadic
592f4125e02SPeter Hawkins  // CHECK:    super().__init__(
593f4125e02SPeter Hawkins  // CHECK:     self.OPERATION_NAME, self._ODS_REGIONS, self._ODS_OPERAND_SEGMENTS, self._ODS_RESULT_SEGMENTS
59418fbd5feSAlex Zinenko  // CHECK:      attributes=attributes, results=results, operands=operands,
595f4125e02SPeter Hawkins  // CHECK:      successors=_ods_successors, regions=regions, loc=loc, ip=ip)
59618fbd5feSAlex Zinenko  let regions = (region AnyRegion:$region, AnyRegion, VariadicRegion<AnyRegion>:$variadic);
59718fbd5feSAlex Zinenko
59818fbd5feSAlex Zinenko  // CHECK:  @builtins.property
599310736e0SAlex Zinenko  // CHECK:  def region(self):
60018fbd5feSAlex Zinenko  // CHECK:    return self.regions[0]
60118fbd5feSAlex Zinenko
60218fbd5feSAlex Zinenko  // CHECK:  @builtins.property
603310736e0SAlex Zinenko  // CHECK:  def variadic(self):
60418fbd5feSAlex Zinenko  // CHECK:    return self.regions[2:]
60518fbd5feSAlex Zinenko}
60618fbd5feSAlex Zinenko
60727c6d55cSMaksim Levental// CHECK: def variadic_and_normal_region(num_variadic, *, loc=None, ip=None)
60851a4f319SPeter Hawkins// CHECK:   return VariadicAndNormalRegionOp(num_variadic=num_variadic, loc=loc, ip=ip)
60927c6d55cSMaksim Levental
61018fbd5feSAlex Zinenko// CHECK: class VariadicRegionOp(_ods_ir.OpView):
61118fbd5feSAlex Zinenko// CHECK-LABEL: OPERATION_NAME = "test.variadic_region"
61218fbd5feSAlex Zinenkodef VariadicRegionOp : TestOp<"variadic_region"> {
61318fbd5feSAlex Zinenko  // CHECK:  def __init__(self, num_variadic, *, loc=None, ip=None):
61418fbd5feSAlex Zinenko  // CHECK:    operands = []
61518fbd5feSAlex Zinenko  // CHECK:    results = []
61618fbd5feSAlex Zinenko  // CHECK:    attributes = {}
61718fbd5feSAlex Zinenko  // CHECK:    regions = None
61818fbd5feSAlex Zinenko  // CHECK:    _ods_successors = None
61918fbd5feSAlex Zinenko  // CHECK:    regions = 0 + num_variadic
620f4125e02SPeter Hawkins  // CHECK:    super().__init__(
621f4125e02SPeter Hawkins  // CHECK:     self.OPERATION_NAME, self._ODS_REGIONS, self._ODS_OPERAND_SEGMENTS, self._ODS_RESULT_SEGMENTS
62218fbd5feSAlex Zinenko  // CHECK:      attributes=attributes, results=results, operands=operands,
623f4125e02SPeter Hawkins  // CHECK:      successors=_ods_successors, regions=regions, loc=loc, ip=ip)
62418fbd5feSAlex Zinenko  let regions = (region VariadicRegion<AnyRegion>:$Variadic);
62518fbd5feSAlex Zinenko
62618fbd5feSAlex Zinenko  // CHECK:  @builtins.property
627310736e0SAlex Zinenko  // CHECK:  def Variadic(self):
62818fbd5feSAlex Zinenko  // CHECK:    return self.regions[0:]
62918fbd5feSAlex Zinenko}
63018fbd5feSAlex Zinenko
63127c6d55cSMaksim Levental// CHECK: def variadic_region(num_variadic, *, loc=None, ip=None)
63251a4f319SPeter Hawkins// CHECK:   return VariadicRegionOp(num_variadic=num_variadic, loc=loc, ip=ip)
63327c6d55cSMaksim Levental
6348e6c55c9SStella Laurenzo// CHECK: @_ods_cext.register_operation(_Dialect)
63544600baeSJoelWee// CHECK: class WithSpecialCharactersOp(_ods_ir.OpView):
63644600baeSJoelWee// CHECK-LABEL: OPERATION_NAME = "test.123with--special.characters"
63744600baeSJoelWeedef WithSpecialCharactersOp : TestOp<"123with--special.characters"> {
63844600baeSJoelWee}
63944600baeSJoelWee
64044600baeSJoelWee// CHECK: def _123with__special_characters(*, loc=None, ip=None)
64151a4f319SPeter Hawkins// CHECK:   return WithSpecialCharactersOp(loc=loc, ip=ip)
64244600baeSJoelWee
64344600baeSJoelWee// CHECK: @_ods_cext.register_operation(_Dialect)
6448e6c55c9SStella Laurenzo// CHECK: class WithSuccessorsOp(_ods_ir.OpView):
6458e6c55c9SStella Laurenzo// CHECK-LABEL: OPERATION_NAME = "test.with_successors"
6468e6c55c9SStella Laurenzodef WithSuccessorsOp : TestOp<"with_successors"> {
6478e6c55c9SStella Laurenzo  // CHECK-NOT:  _ods_successors = None
6488e6c55c9SStella Laurenzo  // CHECK:      _ods_successors = []
6498e6c55c9SStella Laurenzo  // CHECK-NEXT: _ods_successors.append(successor)
6508e6c55c9SStella Laurenzo  // CHECK-NEXT: _ods_successors.extend(successors)
6518e6c55c9SStella Laurenzo  let successors = (successor AnySuccessor:$successor,
6528e6c55c9SStella Laurenzo                              VariadicSuccessor<AnySuccessor>:$successors);
6538e6c55c9SStella Laurenzo}
65427c6d55cSMaksim Levental
65527c6d55cSMaksim Levental// CHECK: def with_successors(successor, successors, *, loc=None, ip=None)
65651a4f319SPeter Hawkins// CHECK:   return WithSuccessorsOp(successor=successor, successors=successors, loc=loc, ip=ip)
657