[Mlir-commits] [mlir] [mlir] Make fold result type check more verbose (PR #76867)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Jan 3 13:22:08 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-core
Author: Jakub Kuderski (kuhar)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/76867.diff
1 Files Affected:
- (modified) mlir/lib/IR/Operation.cpp (+14-5)
``````````diff
diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp
index a726790391a0c5..a7d5904faa5980 100644
--- a/mlir/lib/IR/Operation.cpp
+++ b/mlir/lib/IR/Operation.cpp
@@ -20,6 +20,7 @@
#include "mlir/Interfaces/FoldInterfaces.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/ErrorHandling.h"
#include <numeric>
#include <optional>
@@ -611,11 +612,19 @@ void Operation::setSuccessor(Block *block, unsigned index) {
/// the results of the given op.
static void checkFoldResultTypes(Operation *op,
SmallVectorImpl<OpFoldResult> &results) {
- if (!results.empty())
- for (auto [ofr, opResult] : llvm::zip_equal(results, op->getResults()))
- if (auto value = ofr.dyn_cast<Value>())
- assert(value.getType() == opResult.getType() &&
- "folder produced value of incorrect type");
+ if (results.empty())
+ return;
+
+ for (auto [ofr, opResult] : llvm::zip_equal(results, op->getResults())) {
+ if (auto value = dyn_cast<Value>(ofr)) {
+ if (value.getType() != opResult.getType()) {
+ llvm::errs() << "Folder produced a value of incorrect type for: '"
+ << *op << "'\nOriginal type: '" << value.getType()
+ << "'\nNew type: '" << opResult.getType() << "'\n";
+ assert(false && "incorrect fold result type");
+ }
+ }
+ }
}
#endif // NDEBUG
``````````
</details>
https://github.com/llvm/llvm-project/pull/76867
More information about the Mlir-commits
mailing list