[Mlir-commits] [mlir] [tblgen] Use `emitError` for inferResultTypes failures (PR #165488)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Oct 28 16:06:45 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-core
Author: Stef Lindall (bethebunny)
<details>
<summary>Changes</summary>
Tablegen builders generated for InferTypeOpTrait currently generate a call to `llvm::report_fatal_error`. This prevents error recovery even though the underlying machinery, including the generic builder, support failing result type inference.
This PR updates `reportFatalInferReturnTypesError` -> `emitInferReturnTypesError`, using `mlir::emitError()` instead of `llvm::report_fatal_error`, and then updates `OpDefinitionsGen` to use this function.
---
Full diff: https://github.com/llvm/llvm-project/pull/165488.diff
3 Files Affected:
- (modified) mlir/include/mlir/Interfaces/InferTypeOpInterface.h (+2-3)
- (modified) mlir/lib/Interfaces/InferTypeOpInterface.cpp (+8-11)
- (modified) mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp (+1-1)
``````````diff
diff --git a/mlir/include/mlir/Interfaces/InferTypeOpInterface.h b/mlir/include/mlir/Interfaces/InferTypeOpInterface.h
index 4fcbeff9df560..3cae45e17a15b 100644
--- a/mlir/include/mlir/Interfaces/InferTypeOpInterface.h
+++ b/mlir/include/mlir/Interfaces/InferTypeOpInterface.h
@@ -245,9 +245,8 @@ inferReturnTensorTypes(ArrayRef<ShapedTypeComponents> retComponents,
/// the op. Precondition: op implements InferTypeOpInterface.
LogicalResult verifyInferredResultTypes(Operation *op);
-/// Report a fatal error indicating that the result types could not be
-/// inferred.
-void reportFatalInferReturnTypesError(OperationState &state);
+/// Report an error indicating that the result types could not be inferred.
+void emitInferReturnTypesError(OperationState &state);
} // namespace detail
namespace OpTrait {
diff --git a/mlir/lib/Interfaces/InferTypeOpInterface.cpp b/mlir/lib/Interfaces/InferTypeOpInterface.cpp
index 9f4f672fb9f4d..add0101f226d7 100644
--- a/mlir/lib/Interfaces/InferTypeOpInterface.cpp
+++ b/mlir/lib/Interfaces/InferTypeOpInterface.cpp
@@ -240,15 +240,12 @@ LogicalResult mlir::detail::verifyInferredResultTypes(Operation *op) {
return result;
}
-void mlir::detail::reportFatalInferReturnTypesError(OperationState &state) {
- std::string buffer;
- llvm::raw_string_ostream os(buffer);
- os << "Failed to infer result type(s):\n"
- << "\"" << state.name << "\"(...) "
- << state.attributes.getDictionary(state.location.getContext()) << " : ("
- << llvm::interleaved(llvm::map_range(
- state.operands, [](Value val) { return val.getType(); }))
- << ") -> ( ??? )";
- emitRemark(state.location, "location of op");
- llvm::report_fatal_error(llvm::StringRef(buffer));
+void mlir::detail::emitInferReturnTypesError(OperationState &state) {
+ mlir::emitError(state.location)
+ << "Failed to infer result type(s):\n"
+ << "\"" << state.name << "\"(...) "
+ << state.attributes.getDictionary(state.location.getContext()) << " : ("
+ << llvm::interleaved(llvm::map_range(
+ state.operands, [](Value val) { return val.getType(); }))
+ << ") -> ( ??? )";
}
diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index 371864830a3c1..d75261186f45a 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -2681,7 +2681,7 @@ void OpEmitter::genSeparateArgParamBuilder() {
{1}.regions, inferredReturnTypes)))
{1}.addTypes(inferredReturnTypes);
else
- ::mlir::detail::reportFatalInferReturnTypesError({1});
+ ::mlir::detail::emitInferReturnTypesError({1});
)",
opClass.getClassName(), builderOpState);
return;
``````````
</details>
https://github.com/llvm/llvm-project/pull/165488
More information about the Mlir-commits
mailing list