[Mlir-commits] [mlir] [mlir][IR] Improve error message when return type could not be inferred (PR #112336)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Oct 15 02:20:31 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Matthias Springer (matthias-springer)
<details>
<summary>Changes</summary>
Print an error such as the following one before terminating program execution.
```
mlir/test/Dialect/SparseTensor/convert_dense2sparse.mlir:26:8: remark: location of new op
%0 = sparse_tensor.convert %arg0 : tensor<?xi32> to tensor<?xi32, #SparseVector>
^
LLVM ERROR: Failed to infer result type(s):
"sparse_tensor.positions"(...) {} : (index) -> ( ??? )
(stack trace follows)
```
---
Full diff: https://github.com/llvm/llvm-project/pull/112336.diff
3 Files Affected:
- (modified) mlir/include/mlir/Interfaces/InferTypeOpInterface.h (+4)
- (modified) mlir/lib/Interfaces/InferTypeOpInterface.cpp (+14)
- (modified) mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp (+2-1)
``````````diff
diff --git a/mlir/include/mlir/Interfaces/InferTypeOpInterface.h b/mlir/include/mlir/Interfaces/InferTypeOpInterface.h
index 47bcfc9bbd4f96..4fcbeff9df5609 100644
--- a/mlir/include/mlir/Interfaces/InferTypeOpInterface.h
+++ b/mlir/include/mlir/Interfaces/InferTypeOpInterface.h
@@ -244,6 +244,10 @@ inferReturnTensorTypes(ArrayRef<ShapedTypeComponents> retComponents,
/// Verifies that the inferred result types match the actual result types for
/// 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);
} // namespace detail
namespace OpTrait {
diff --git a/mlir/lib/Interfaces/InferTypeOpInterface.cpp b/mlir/lib/Interfaces/InferTypeOpInterface.cpp
index e52d0e17cda22b..f3b4d1b768b00f 100644
--- a/mlir/lib/Interfaces/InferTypeOpInterface.cpp
+++ b/mlir/lib/Interfaces/InferTypeOpInterface.cpp
@@ -247,3 +247,17 @@ 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";
+ os << "\"" << state.name << "\"(...) ";
+ os << state.attributes.getDictionary(state.location.getContext());
+ os << " : (";
+ llvm::interleaveComma(state.operands, os,
+ [&](Value val) { os << val.getType(); });
+ os << ") -> ( ??? )";
+ mlir::emitRemark(state.location, "location of op");
+ llvm::report_fatal_error(llvm::StringRef(buffer));
+}
diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index ce2b6ed94c3949..71fa5011a476b4 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -2503,7 +2503,8 @@ void OpEmitter::genSeparateArgParamBuilder() {
{1}.regions, inferredReturnTypes)))
{1}.addTypes(inferredReturnTypes);
else
- ::llvm::report_fatal_error("Failed to infer result type(s).");)",
+ ::mlir::detail::reportFatalInferReturnTypesError({1});
+ )",
opClass.getClassName(), builderOpState);
return;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/112336
More information about the Mlir-commits
mailing list