[Mlir-commits] [mlir] 9215741 - [mlir] Make fold result type check more verbose (#76867)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Jan 4 08:08:40 PST 2024


Author: Jakub Kuderski
Date: 2024-01-04T11:08:36-05:00
New Revision: 9215741726e295d09ae7db4d235b26c1214a19ae

URL: https://github.com/llvm/llvm-project/commit/9215741726e295d09ae7db4d235b26c1214a19ae
DIFF: https://github.com/llvm/llvm-project/commit/9215741726e295d09ae7db4d235b26c1214a19ae.diff

LOG: [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.

Added: 
    

Modified: 
    mlir/lib/IR/Operation.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp
index a726790391a0c5..311f5bb5ef77c0 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()) {
+        op->emitOpError() << "folder produced a value of incorrect type: "
+                          << opResult.getType()
+                          << ", expected: " << value.getType();
+        assert(false && "incorrect fold result type");
+      }
+    }
+  }
 }
 #endif // NDEBUG
 


        


More information about the Mlir-commits mailing list