1//===-- python_test_ops.td - Python test Op definitions ----*- tablegen -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef PYTHON_TEST_OPS
10#define PYTHON_TEST_OPS
11
12include "mlir/Bindings/Python/Attributes.td"
13include "mlir/IR/OpBase.td"
14include "mlir/Interfaces/InferTypeOpInterface.td"
15
16def Python_Test_Dialect : Dialect {
17  let name = "python_test";
18  let cppNamespace = "python_test";
19}
20class TestOp<string mnemonic, list<OpTrait> traits = []>
21    : Op<Python_Test_Dialect, mnemonic, traits>;
22
23def AttributedOp : TestOp<"attributed_op"> {
24  let arguments = (ins I32Attr:$mandatory_i32,
25                   OptionalAttr<I32Attr>:$optional_i32,
26                   UnitAttr:$unit);
27}
28
29def PropertyOp : TestOp<"property_op"> {
30  let arguments = (ins I32Attr:$property,
31                   I32:$idx);
32}
33
34def DummyOp : TestOp<"dummy_op"> {
35}
36
37def InferResultsOp : TestOp<"infer_results_op", [InferTypeOpInterface]> {
38  let arguments = (ins);
39  let results = (outs AnyInteger:$single, AnyInteger:$doubled);
40
41  let extraClassDeclaration = [{
42    static ::mlir::LogicalResult inferReturnTypes(
43      ::mlir::MLIRContext *context, ::llvm::Optional<::mlir::Location> location,
44      ::mlir::ValueRange operands, ::mlir::DictionaryAttr attributes,
45      ::mlir::RegionRange regions,
46      ::llvm::SmallVectorImpl<::mlir::Type> &inferredReturnTypes) {
47      ::mlir::Builder b(context);
48      inferredReturnTypes.push_back(b.getI32Type());
49      inferredReturnTypes.push_back(b.getI64Type());
50      return ::mlir::success();
51    }
52  }];
53}
54
55// If all result types are buildable, the InferTypeOpInterface is implied and is
56// autogenerated by C++ ODS.
57def InferResultsImpliedOp : TestOp<"infer_results_implied_op"> {
58  let results = (outs I32:$integer, F64:$flt, Index:$index);
59}
60
61def SameOperandAndResultTypeOp : TestOp<"same_operand_and_result_type_op",
62                                        [SameOperandsAndResultType]> {
63  let arguments = (ins Variadic<AnyType>);
64  let results = (outs AnyType:$one, AnyType:$two);
65}
66
67def FirstAttrDeriveTypeAttrOp : TestOp<"first_attr_derive_type_attr_op",
68                               [FirstAttrDerivedResultType]> {
69  let arguments = (ins AnyType:$input, TypeAttr:$type);
70  let results = (outs AnyType:$one, AnyType:$two);
71}
72
73def FirstAttrDeriveAttrOp : TestOp<"first_attr_derive_attr_op",
74                               [FirstAttrDerivedResultType]> {
75  let arguments = (ins AnyAttr:$iattr);
76  let results = (outs AnyType:$one, AnyType:$two, AnyType:$three);
77}
78
79def OptionalOperandOp : TestOp<"optional_operand_op"> {
80  let arguments = (ins Optional<AnyType>:$input);
81  let results = (outs I32:$result);
82}
83
84#endif // PYTHON_TEST_OPS
85