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#endif // PYTHON_TEST_OPS 56