-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[mlir][IR] Improve error message when return type could not be inferred #112336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mlir][IR] Improve error message when return type could not be inferred #112336
Conversation
@llvm/pr-subscribers-mlir-core Author: Matthias Springer (matthias-springer) ChangesPrint an error such as the following one before terminating program execution.
Full diff: https://github.com/llvm/llvm-project/pull/112336.diff 3 Files Affected:
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;
}
|
@llvm/pr-subscribers-mlir Author: Matthias Springer (matthias-springer) ChangesPrint an error such as the following one before terminating program execution.
Full diff: https://github.com/llvm/llvm-project/pull/112336.diff 3 Files Affected:
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;
}
|
991d5aa
to
a430578
Compare
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) ```
a430578
to
5d64b16
Compare
Print an error such as the following one before terminating program execution.