[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
This commit is contained in:
Chia-hung Duan 2022-05-10 22:48:46 +00:00
parent 15bcc36eed
commit 96e642652b

View File

@ -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;
}