[Mlir-commits] [mlir] [MLIR][Python] Add optional `results` parameter for building op with inferable result types (PR #156818)
Maksim Levental
llvmlistbot at llvm.org
Thu Sep 4 09:17:13 PDT 2025
================
@@ -738,18 +737,24 @@ populateBuilderLinesOperand(const Operator &op, ArrayRef<std::string> names,
}
}
-/// Python code template for deriving the operation result types from its
-/// attribute:
+/// Python code template of generating result types for
+/// FirstAttrDerivedResultType trait
/// - {0} is the name of the attribute from which to derive the types.
-constexpr const char *deriveTypeFromAttrTemplate =
- R"Py(_ods_result_type_source_attr = attributes["{0}"]
-_ods_derived_result_type = (
+/// - {1} is the number of results.
+constexpr const char *firstAttrDerivedResultTypeTemplate =
+ R"Py(if results is None:
+ _ods_result_type_source_attr = attributes["{0}"]
+ _ods_derived_result_type = (
_ods_ir.TypeAttr(_ods_result_type_source_attr).value
if _ods_ir.TypeAttr.isinstance(_ods_result_type_source_attr) else
- _ods_result_type_source_attr.type))Py";
+ _ods_result_type_source_attr.type)
+ results = [_ods_derived_result_type] * {1})Py";
-/// Python code template appending {0} type {1} times to the results list.
-constexpr const char *appendSameResultsTemplate = "results.extend([{0}] * {1})";
+/// Python code template of generating result types for
+/// SameOperandsAndResultType trait
+/// - {0} is the number of results.
+constexpr const char *sameOperandsAndResultTypeTemplate =
+ R"Py(if results is None: results = [operands[0].type] * {0})Py";
----------------
makslevental wrote:
This isn't really a question for you (unless you know the answer...) but shouldn't the `SameOperandsAndResultType` support mixed tuples of operand/result types? Like
```
operand_types = [i16, i32, i64]
...
inferred_result_types = [i16, i32, i64]
```
https://github.com/llvm/llvm-project/pull/156818
More information about the Mlir-commits
mailing list