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/IR/AttrTypeBase.td" 13include "mlir/Bindings/Python/Attributes.td" 14include "mlir/IR/OpBase.td" 15include "mlir/Interfaces/InferTypeOpInterface.td" 16 17def Python_Test_Dialect : Dialect { 18 let name = "python_test"; 19 let cppNamespace = "python_test"; 20 21 let useDefaultTypePrinterParser = 1; 22 let useDefaultAttributePrinterParser = 1; 23} 24 25class TestType<string name, string typeMnemonic> 26 : TypeDef<Python_Test_Dialect, name> { 27 let mnemonic = typeMnemonic; 28} 29 30class TestAttr<string name, string attrMnemonic> 31 : AttrDef<Python_Test_Dialect, name> { 32 let mnemonic = attrMnemonic; 33} 34 35class TestOp<string mnemonic, list<Trait> traits = []> 36 : Op<Python_Test_Dialect, mnemonic, traits>; 37 38//===----------------------------------------------------------------------===// 39// Type definitions. 40//===----------------------------------------------------------------------===// 41 42def TestType : TestType<"TestType", "test_type">; 43 44//===----------------------------------------------------------------------===// 45// Attribute definitions. 46//===----------------------------------------------------------------------===// 47 48def TestAttr : TestAttr<"TestAttr", "test_attr">; 49 50//===----------------------------------------------------------------------===// 51// Operation definitions. 52//===----------------------------------------------------------------------===// 53 54def AttributedOp : TestOp<"attributed_op"> { 55 let arguments = (ins I32Attr:$mandatory_i32, 56 OptionalAttr<I32Attr>:$optional_i32, 57 UnitAttr:$unit); 58} 59 60def PropertyOp : TestOp<"property_op"> { 61 let arguments = (ins I32Attr:$property, 62 I32:$idx); 63} 64 65def DummyOp : TestOp<"dummy_op"> { 66} 67 68def InferResultsOp : TestOp<"infer_results_op", [InferTypeOpInterface]> { 69 let arguments = (ins); 70 let results = (outs AnyInteger:$single, AnyInteger:$doubled); 71 72 let extraClassDeclaration = [{ 73 static ::mlir::LogicalResult inferReturnTypes( 74 ::mlir::MLIRContext *context, ::llvm::Optional<::mlir::Location> location, 75 ::mlir::ValueRange operands, ::mlir::DictionaryAttr attributes, 76 ::mlir::RegionRange regions, 77 ::llvm::SmallVectorImpl<::mlir::Type> &inferredReturnTypes) { 78 ::mlir::Builder b(context); 79 inferredReturnTypes.push_back(b.getI32Type()); 80 inferredReturnTypes.push_back(b.getI64Type()); 81 return ::mlir::success(); 82 } 83 }]; 84} 85 86// If all result types are buildable, the InferTypeOpInterface is implied and is 87// autogenerated by C++ ODS. 88def InferResultsImpliedOp : TestOp<"infer_results_implied_op"> { 89 let results = (outs I32:$integer, F64:$flt, Index:$index); 90} 91 92def SameOperandAndResultTypeOp : TestOp<"same_operand_and_result_type_op", 93 [SameOperandsAndResultType]> { 94 let arguments = (ins Variadic<AnyType>); 95 let results = (outs AnyType:$one, AnyType:$two); 96} 97 98def FirstAttrDeriveTypeAttrOp : TestOp<"first_attr_derive_type_attr_op", 99 [FirstAttrDerivedResultType]> { 100 let arguments = (ins AnyType:$input, TypeAttr:$type); 101 let results = (outs AnyType:$one, AnyType:$two); 102} 103 104def FirstAttrDeriveAttrOp : TestOp<"first_attr_derive_attr_op", 105 [FirstAttrDerivedResultType]> { 106 let arguments = (ins AnyAttr:$iattr); 107 let results = (outs AnyType:$one, AnyType:$two, AnyType:$three); 108} 109 110def OptionalOperandOp : TestOp<"optional_operand_op"> { 111 let arguments = (ins Optional<AnyType>:$input); 112 let results = (outs I32:$result); 113} 114 115#endif // PYTHON_TEST_OPS 116