diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp --- 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 "asm-printer" + void OperationName::print(raw_ostream &os) const { os << getStringRef(); } void OperationName::dump() const { print(llvm::errs()); } @@ -1313,14 +1316,26 @@ printerFlags.shouldAssumeVerified()) return printerFlags; + LLVM_DEBUG(llvm::dbgs() << "Verify op before printing: " + << op->getName().getStringRef() << "\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(llvm::dbgs() << "op-printing verification:\n" + << diag.str() << "\n"); + return success(); + } + return failure(); }); - if (failed(verify(op))) + if (failed(verify(op))) { + LLVM_DEBUG(llvm::dbgs() + << op->getName().getStringRef() + << " failed on verification, will be printed in generic form\n"); printerFlags.printGenericOpForm(); + } return printerFlags; }