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