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 552995d29bSAlex Zinenko// If all result types are buildable, the InferTypeOpInterface is implied and is 562995d29bSAlex Zinenko// autogenerated by C++ ODS. 572995d29bSAlex Zinenkodef InferResultsImpliedOp : TestOp<"infer_results_implied_op"> { 582995d29bSAlex Zinenko let results = (outs I32:$integer, F64:$flt, Index:$index); 592995d29bSAlex Zinenko} 602995d29bSAlex Zinenko 612995d29bSAlex Zinenkodef SameOperandAndResultTypeOp : TestOp<"same_operand_and_result_type_op", 622995d29bSAlex Zinenko [SameOperandsAndResultType]> { 632995d29bSAlex Zinenko let arguments = (ins Variadic<AnyType>); 642995d29bSAlex Zinenko let results = (outs AnyType:$one, AnyType:$two); 652995d29bSAlex Zinenko} 662995d29bSAlex Zinenko 672995d29bSAlex Zinenkodef FirstAttrDeriveTypeAttrOp : TestOp<"first_attr_derive_type_attr_op", 682995d29bSAlex Zinenko [FirstAttrDerivedResultType]> { 692995d29bSAlex Zinenko let arguments = (ins AnyType:$input, TypeAttr:$type); 702995d29bSAlex Zinenko let results = (outs AnyType:$one, AnyType:$two); 712995d29bSAlex Zinenko} 722995d29bSAlex Zinenko 732995d29bSAlex Zinenkodef FirstAttrDeriveAttrOp : TestOp<"first_attr_derive_attr_op", 742995d29bSAlex Zinenko [FirstAttrDerivedResultType]> { 752995d29bSAlex Zinenko let arguments = (ins AnyAttr:$iattr); 762995d29bSAlex Zinenko let results = (outs AnyType:$one, AnyType:$two, AnyType:$three); 772995d29bSAlex Zinenko} 782995d29bSAlex Zinenko 79*54c99842SMichal Terepetadef OptionalOperandOp : TestOp<"optional_operand_op"> { 80*54c99842SMichal Terepeta let arguments = (ins Optional<AnyType>:$input); 81*54c99842SMichal Terepeta let results = (outs I32:$result); 82*54c99842SMichal Terepeta} 83*54c99842SMichal Terepeta 849f3f6d7bSStella Laurenzo#endif // PYTHON_TEST_OPS 85