summaryrefslogtreecommitdiff
path: root/mlir/test/python/python_test_ops.td
diff options
context:
space:
mode:
authorAlex Zinenko <zinenko@google.com>2021-10-14 17:19:06 +0200
committerAlex Zinenko <zinenko@google.com>2021-10-25 12:50:44 +0200
commit2995d29bb42729043e707161bd7a7e4e428afbcf (patch)
treedf01d76ca84e04c50bc8a102228fc52c8a89f5cb /mlir/test/python/python_test_ops.td
parent14c9207063bb00823a5126131e50c93f6e288bd3 (diff)
[mlir][python] Infer result types in generated constructors whenever possible
In several cases, operation result types can be unambiguously inferred from operands and attributes at operation construction time. Stop requiring the user to provide these types as arguments in the ODS-generated constructors in Python bindings. In particular, handle the SameOperandAndResultTypes and FirstAttrDerivedResultType traits as well as InferTypeOpInterface using the recently added interface support. This is a significant usability improvement for IR construction, similar to what C++ ODS provides. Depends On D111656 Reviewed By: gysit Differential Revision: https://reviews.llvm.org/D111811
Diffstat (limited to 'mlir/test/python/python_test_ops.td')
-rw-r--r--mlir/test/python/python_test_ops.td24
1 files changed, 24 insertions, 0 deletions
diff --git a/mlir/test/python/python_test_ops.td b/mlir/test/python/python_test_ops.td
index 74c90a311f04..0f947e7e536b 100644
--- a/mlir/test/python/python_test_ops.td
+++ b/mlir/test/python/python_test_ops.td
@@ -52,4 +52,28 @@ def InferResultsOp : TestOp<"infer_results_op", [InferTypeOpInterface]> {
}];
}
+// If all result types are buildable, the InferTypeOpInterface is implied and is
+// autogenerated by C++ ODS.
+def InferResultsImpliedOp : TestOp<"infer_results_implied_op"> {
+ let results = (outs I32:$integer, F64:$flt, Index:$index);
+}
+
+def SameOperandAndResultTypeOp : TestOp<"same_operand_and_result_type_op",
+ [SameOperandsAndResultType]> {
+ let arguments = (ins Variadic<AnyType>);
+ let results = (outs AnyType:$one, AnyType:$two);
+}
+
+def FirstAttrDeriveTypeAttrOp : TestOp<"first_attr_derive_type_attr_op",
+ [FirstAttrDerivedResultType]> {
+ let arguments = (ins AnyType:$input, TypeAttr:$type);
+ let results = (outs AnyType:$one, AnyType:$two);
+}
+
+def FirstAttrDeriveAttrOp : TestOp<"first_attr_derive_attr_op",
+ [FirstAttrDerivedResultType]> {
+ let arguments = (ins AnyAttr:$iattr);
+ let results = (outs AnyType:$one, AnyType:$two, AnyType:$three);
+}
+
#endif // PYTHON_TEST_OPS