Skip to content

Commit 9215741

Browse files
authored
[mlir] Make fold result type check more verbose (#76867)
Print the op and its types when the fold type check fails. This is to speed up debuging as it should be trivial to map the offending op to its folder based on the op name.
1 parent a87fa7f commit 9215741

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

mlir/lib/IR/Operation.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "mlir/Interfaces/FoldInterfaces.h"
2121
#include "llvm/ADT/SmallVector.h"
2222
#include "llvm/ADT/StringExtras.h"
23+
#include "llvm/Support/ErrorHandling.h"
2324
#include <numeric>
2425
#include <optional>
2526

@@ -611,11 +612,19 @@ void Operation::setSuccessor(Block *block, unsigned index) {
611612
/// the results of the given op.
612613
static void checkFoldResultTypes(Operation *op,
613614
SmallVectorImpl<OpFoldResult> &results) {
614-
if (!results.empty())
615-
for (auto [ofr, opResult] : llvm::zip_equal(results, op->getResults()))
616-
if (auto value = ofr.dyn_cast<Value>())
617-
assert(value.getType() == opResult.getType() &&
618-
"folder produced value of incorrect type");
615+
if (results.empty())
616+
return;
617+
618+
for (auto [ofr, opResult] : llvm::zip_equal(results, op->getResults())) {
619+
if (auto value = dyn_cast<Value>(ofr)) {
620+
if (value.getType() != opResult.getType()) {
621+
op->emitOpError() << "folder produced a value of incorrect type: "
622+
<< opResult.getType()
623+
<< ", expected: " << value.getType();
624+
assert(false && "incorrect fold result type");
625+
}
626+
}
627+
}
619628
}
620629
#endif // NDEBUG
621630

0 commit comments

Comments
 (0)