Skip to content

Commit c8939fe

Browse files
committed
[tblgen] Use emitError for inferResultTypes failures
1 parent 9a5ae34 commit c8939fe

File tree

4 files changed

+16
-19
lines changed

4 files changed

+16
-19
lines changed

mlir/include/mlir/Interfaces/InferTypeOpInterface.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,8 @@ inferReturnTensorTypes(ArrayRef<ShapedTypeComponents> retComponents,
245245
/// the op. Precondition: op implements InferTypeOpInterface.
246246
LogicalResult verifyInferredResultTypes(Operation *op);
247247

248-
/// Report a fatal error indicating that the result types could not be
249-
/// inferred.
250-
void reportFatalInferReturnTypesError(OperationState &state);
248+
/// Report an error indicating that the result types could not be inferred.
249+
void emitInferReturnTypesError(OperationState &state);
251250
} // namespace detail
252251

253252
namespace OpTrait {

mlir/lib/Interfaces/InferTypeOpInterface.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,12 @@ LogicalResult mlir::detail::verifyInferredResultTypes(Operation *op) {
240240
return result;
241241
}
242242

243-
void mlir::detail::reportFatalInferReturnTypesError(OperationState &state) {
244-
std::string buffer;
245-
llvm::raw_string_ostream os(buffer);
246-
os << "Failed to infer result type(s):\n"
247-
<< "\"" << state.name << "\"(...) "
248-
<< state.attributes.getDictionary(state.location.getContext()) << " : ("
249-
<< llvm::interleaved(llvm::map_range(
250-
state.operands, [](Value val) { return val.getType(); }))
251-
<< ") -> ( ??? )";
252-
emitRemark(state.location, "location of op");
253-
llvm::report_fatal_error(llvm::StringRef(buffer));
243+
void mlir::detail::emitInferReturnTypesError(OperationState &state) {
244+
mlir::emitError(state.location)
245+
<< "failed to infer result type(s):\n"
246+
<< "\"" << state.name << "\"(...) "
247+
<< state.attributes.getDictionary(state.location.getContext()) << " : ("
248+
<< llvm::interleaved(llvm::map_range(
249+
state.operands, [](Value val) { return val.getType(); }))
250+
<< ") -> ( ??? )";
254251
}

mlir/test/mlir-tblgen/op-decl-and-defs.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def NS_FOp : NS_Op<"op_with_all_types_constraint",
232232
// DEFS: void FOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value a) {
233233
// DEFS: if (::mlir::succeeded(FOp::inferReturnTypes(odsBuilder.getContext(),
234234
// DEFS: else
235-
// DEFS: ::mlir::detail::reportFatalInferReturnTypesError(odsState);
235+
// DEFS: ::mlir::detail::emitInferReturnTypesError(odsState);
236236

237237
// DEFS: FOp FOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Value a) {
238238
// DEFS: ::mlir::OperationState __state__(location, getOperationName());

mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2681,7 +2681,7 @@ void OpEmitter::genSeparateArgParamBuilder() {
26812681
{1}.regions, inferredReturnTypes)))
26822682
{1}.addTypes(inferredReturnTypes);
26832683
else
2684-
::mlir::detail::reportFatalInferReturnTypesError({1});
2684+
::mlir::detail::emitInferReturnTypesError({1});
26852685
)",
26862686
opClass.getClassName(), builderOpState);
26872687
return;
@@ -2967,10 +2967,11 @@ void OpEmitter::genInferredTypeCollectiveParamBuilder(
29672967
<< "u && \"mismatched number of return types\");";
29682968
body << "\n " << builderOpState << ".addTypes(inferredReturnTypes);";
29692969

2970-
body << R"(
2970+
body << formatv(R"(
29712971
} else {
2972-
::llvm::report_fatal_error("Failed to infer result type(s).");
2973-
})";
2972+
::mlir::detail::emitInferReturnTypesError({0});
2973+
})",
2974+
builderOpState);
29742975
}
29752976

29762977
void OpEmitter::genUseOperandAsResultTypeSeparateParamBuilder() {

0 commit comments

Comments
 (0)