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

Jakub Kuderski llvmlistbot at llvm.org
Wed Jan 3 14:09:52 PST 2024


https://github.com/kuhar updated https://github.com/llvm/llvm-project/pull/76867

>From 288c80165b50ad0edf54b398e6293e0234a10ddc Mon Sep 17 00:00:00 2001
From: Jakub Kuderski <jakub at nod-labs.com>
Date: Wed, 3 Jan 2024 16:19:30 -0500
Subject: [PATCH 1/2] [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.
---
 mlir/lib/IR/Operation.cpp | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp
index a726790391a0c5..92182c5d24b51c 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
 

>From 813993e21fdfbfd3502fee8c30a9269700bc3292 Mon Sep 17 00:00:00 2001
From: Jakub Kuderski <jakub at nod-labs.com>
Date: Wed, 3 Jan 2024 17:09:42 -0500
Subject: [PATCH 2/2] Format

---
 mlir/lib/IR/Operation.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp
index 92182c5d24b51c..b399e9f0e3f192 100644
--- a/mlir/lib/IR/Operation.cpp
+++ b/mlir/lib/IR/Operation.cpp
@@ -618,8 +618,8 @@ static void checkFoldResultTypes(Operation *op,
   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()
+        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");
       }



More information about the Mlir-commits mailing list