[Mlir-commits] [mlir] 96e6426 - [mlir] Print some message for op-printing verification

Chia-hung Duan llvmlistbot at llvm.org
Tue May 10 15:56:17 PDT 2022


Author: Chia-hung Duan
Date: 2022-05-10T22:48:47Z
New Revision: 96e642652b9b7cfe5a50819a217b9994bdc219fd

URL: https://github.com/llvm/llvm-project/commit/96e642652b9b7cfe5a50819a217b9994bdc219fd
DIFF: https://github.com/llvm/llvm-project/commit/96e642652b9b7cfe5a50819a217b9994bdc219fd.diff

LOG: [mlir] Print some message for op-printing verification

Before dump, Insetad of switching to generic form silently after
verification failure. Print some debug logs to help identify why an op
may be printed in a different way.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D125136

Added: 
    

Modified: 
    mlir/lib/IR/AsmPrinter.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp
index 013bf162211b..c9c7d4b103c2 100644
--- a/mlir/lib/IR/AsmPrinter.cpp
+++ b/mlir/lib/IR/AsmPrinter.cpp
@@ -38,6 +38,7 @@
 #include "llvm/ADT/StringSet.h"
 #include "llvm/ADT/TypeSwitch.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Debug.h"
 #include "llvm/Support/Endian.h"
 #include "llvm/Support/Regex.h"
 #include "llvm/Support/SaveAndRestore.h"
@@ -48,6 +49,8 @@
 using namespace mlir;
 using namespace mlir::detail;
 
+#define DEBUG_TYPE "mlir-asm-printer"
+
 void OperationName::print(raw_ostream &os) const { os << getStringRef(); }
 
 void OperationName::dump() const { print(llvm::errs()); }
@@ -1313,14 +1316,28 @@ static OpPrintingFlags verifyOpAndAdjustFlags(Operation *op,
       printerFlags.shouldAssumeVerified())
     return printerFlags;
 
+  LLVM_DEBUG(llvm::dbgs() << DEBUG_TYPE << ": Verifying operation: "
+                          << op->getName() << "\n");
+
   // Ignore errors emitted by the verifier. We check the thread id to avoid
   // consuming other threads' errors.
   auto parentThreadId = llvm::get_threadid();
-  ScopedDiagnosticHandler diagHandler(op->getContext(), [&](Diagnostic &) {
-    return success(parentThreadId == llvm::get_threadid());
+  ScopedDiagnosticHandler diagHandler(op->getContext(), [&](Diagnostic &diag) {
+    if (parentThreadId == llvm::get_threadid()) {
+      LLVM_DEBUG({
+        diag.print(llvm::dbgs());
+        llvm::dbgs() << "\n";
+      });
+      return success();
+    }
+    return failure();
   });
-  if (failed(verify(op)))
+  if (failed(verify(op))) {
+    LLVM_DEBUG(llvm::dbgs()
+               << DEBUG_TYPE << ": '" << op->getName()
+               << "' failed to verify and will be printed in generic form\n");
     printerFlags.printGenericOpForm();
+  }
 
   return printerFlags;
 }


        


More information about the Mlir-commits mailing list