Skip to content

Commit 288c801

Browse files
committed
[mlir] Make fold result type check more verbose
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 ddd6acd commit 288c801

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+
llvm::errs() << "Folder produced a value of incorrect type for: "
622+
<< *op << "\nOriginal type: '" << value.getType()
623+
<< "'\nNew type: '" << opResult.getType() << "'\n";
624+
assert(false && "incorrect fold result type");
625+
}
626+
}
627+
}
619628
}
620629
#endif // NDEBUG
621630

0 commit comments

Comments
 (0)