19f3f6d7bSStella Laurenzo//===-- python_test_ops.td - Python test Op definitions ----*- tablegen -*-===// 29f3f6d7bSStella Laurenzo// 39f3f6d7bSStella Laurenzo// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 49f3f6d7bSStella Laurenzo// See https://llvm.org/LICENSE.txt for license information. 59f3f6d7bSStella Laurenzo// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 69f3f6d7bSStella Laurenzo// 79f3f6d7bSStella Laurenzo//===----------------------------------------------------------------------===// 89f3f6d7bSStella Laurenzo 99f3f6d7bSStella Laurenzo#ifndef PYTHON_TEST_OPS 109f3f6d7bSStella Laurenzo#define PYTHON_TEST_OPS 119f3f6d7bSStella Laurenzo 129f3f6d7bSStella Laurenzoinclude "mlir/Bindings/Python/Attributes.td" 139f3f6d7bSStella Laurenzoinclude "mlir/IR/OpBase.td" 1414c92070SAlex Zinenkoinclude "mlir/Interfaces/InferTypeOpInterface.td" 159f3f6d7bSStella Laurenzo 169f3f6d7bSStella Laurenzodef Python_Test_Dialect : Dialect { 179f3f6d7bSStella Laurenzo let name = "python_test"; 1814c92070SAlex Zinenko let cppNamespace = "python_test"; 199f3f6d7bSStella Laurenzo} 209f3f6d7bSStella Laurenzoclass TestOp<string mnemonic, list<OpTrait> traits = []> 219f3f6d7bSStella Laurenzo : Op<Python_Test_Dialect, mnemonic, traits>; 229f3f6d7bSStella Laurenzo 239f3f6d7bSStella Laurenzodef AttributedOp : TestOp<"attributed_op"> { 249f3f6d7bSStella Laurenzo let arguments = (ins I32Attr:$mandatory_i32, 259f3f6d7bSStella Laurenzo OptionalAttr<I32Attr>:$optional_i32, 269f3f6d7bSStella Laurenzo UnitAttr:$unit); 279f3f6d7bSStella Laurenzo} 289f3f6d7bSStella Laurenzo 29b4c93eceSJohn Demmedef PropertyOp : TestOp<"property_op"> { 30b4c93eceSJohn Demme let arguments = (ins I32Attr:$property, 31b4c93eceSJohn Demme I32:$idx); 32b4c93eceSJohn Demme} 33b4c93eceSJohn Demme 3414c92070SAlex Zinenkodef DummyOp : TestOp<"dummy_op"> { 3514c92070SAlex Zinenko} 3614c92070SAlex Zinenko 3714c92070SAlex Zinenkodef InferResultsOp : TestOp<"infer_results_op", [InferTypeOpInterface]> { 3814c92070SAlex Zinenko let arguments = (ins); 3914c92070SAlex Zinenko let results = (outs AnyInteger:$single, AnyInteger:$doubled); 4014c92070SAlex Zinenko 4114c92070SAlex Zinenko let extraClassDeclaration = [{ 4214c92070SAlex Zinenko static ::mlir::LogicalResult inferReturnTypes( 4314c92070SAlex Zinenko ::mlir::MLIRContext *context, ::llvm::Optional<::mlir::Location> location, 4414c92070SAlex Zinenko ::mlir::ValueRange operands, ::mlir::DictionaryAttr attributes, 4514c92070SAlex Zinenko ::mlir::RegionRange regions, 4614c92070SAlex Zinenko ::llvm::SmallVectorImpl<::mlir::Type> &inferredReturnTypes) { 4714c92070SAlex Zinenko ::mlir::Builder b(context); 4814c92070SAlex Zinenko inferredReturnTypes.push_back(b.getI32Type()); 4914c92070SAlex Zinenko inferredReturnTypes.push_back(b.getI64Type()); 5014c92070SAlex Zinenko return ::mlir::success(); 5114c92070SAlex Zinenko } 5214c92070SAlex Zinenko }]; 5314c92070SAlex Zinenko} 5414c92070SAlex Zinenko 55*2995d29bSAlex Zinenko// If all result types are buildable, the InferTypeOpInterface is implied and is 56*2995d29bSAlex Zinenko// autogenerated by C++ ODS. 57*2995d29bSAlex Zinenkodef InferResultsImpliedOp : TestOp<"infer_results_implied_op"> { 58*2995d29bSAlex Zinenko let results = (outs I32:$integer, F64:$flt, Index:$index); 59*2995d29bSAlex Zinenko} 60*2995d29bSAlex Zinenko 61*2995d29bSAlex Zinenkodef SameOperandAndResultTypeOp : TestOp<"same_operand_and_result_type_op", 62*2995d29bSAlex Zinenko [SameOperandsAndResultType]> { 63*2995d29bSAlex Zinenko let arguments = (ins Variadic<AnyType>); 64*2995d29bSAlex Zinenko let results = (outs AnyType:$one, AnyType:$two); 65*2995d29bSAlex Zinenko} 66*2995d29bSAlex Zinenko 67*2995d29bSAlex Zinenkodef FirstAttrDeriveTypeAttrOp : TestOp<"first_attr_derive_type_attr_op", 68*2995d29bSAlex Zinenko [FirstAttrDerivedResultType]> { 69*2995d29bSAlex Zinenko let arguments = (ins AnyType:$input, TypeAttr:$type); 70*2995d29bSAlex Zinenko let results = (outs AnyType:$one, AnyType:$two); 71*2995d29bSAlex Zinenko} 72*2995d29bSAlex Zinenko 73*2995d29bSAlex Zinenkodef FirstAttrDeriveAttrOp : TestOp<"first_attr_derive_attr_op", 74*2995d29bSAlex Zinenko [FirstAttrDerivedResultType]> { 75*2995d29bSAlex Zinenko let arguments = (ins AnyAttr:$iattr); 76*2995d29bSAlex Zinenko let results = (outs AnyType:$one, AnyType:$two, AnyType:$three); 77*2995d29bSAlex Zinenko} 78*2995d29bSAlex Zinenko 799f3f6d7bSStella Laurenzo#endif // PYTHON_TEST_OPS 80