Skip to content

Commit 495f8b2

Browse files
ChiaHungDuanmemfrob
authored and
memfrob
committed
[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
1 parent 3233785 commit 495f8b2

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

mlir/lib/IR/AsmPrinter.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "llvm/ADT/StringSet.h"
3939
#include "llvm/ADT/TypeSwitch.h"
4040
#include "llvm/Support/CommandLine.h"
41+
#include "llvm/Support/Debug.h"
4142
#include "llvm/Support/Endian.h"
4243
#include "llvm/Support/Regex.h"
4344
#include "llvm/Support/SaveAndRestore.h"
@@ -48,6 +49,8 @@
4849
using namespace mlir;
4950
using namespace mlir::detail;
5051

52+
#define DEBUG_TYPE "mlir-asm-printer"
53+
5154
void OperationName::print(raw_ostream &os) const { os << getStringRef(); }
5255

5356
void OperationName::dump() const { print(llvm::errs()); }
@@ -1313,14 +1316,28 @@ static OpPrintingFlags verifyOpAndAdjustFlags(Operation *op,
13131316
printerFlags.shouldAssumeVerified())
13141317
return printerFlags;
13151318

1319+
LLVM_DEBUG(llvm::dbgs() << DEBUG_TYPE << ": Verifying operation: "
1320+
<< op->getName() << "\n");
1321+
13161322
// Ignore errors emitted by the verifier. We check the thread id to avoid
13171323
// consuming other threads' errors.
13181324
auto parentThreadId = llvm::get_threadid();
1319-
ScopedDiagnosticHandler diagHandler(op->getContext(), [&](Diagnostic &) {
1320-
return success(parentThreadId == llvm::get_threadid());
1325+
ScopedDiagnosticHandler diagHandler(op->getContext(), [&](Diagnostic &diag) {
1326+
if (parentThreadId == llvm::get_threadid()) {
1327+
LLVM_DEBUG({
1328+
diag.print(llvm::dbgs());
1329+
llvm::dbgs() << "\n";
1330+
});
1331+
return success();
1332+
}
1333+
return failure();
13211334
});
1322-
if (failed(verify(op)))
1335+
if (failed(verify(op))) {
1336+
LLVM_DEBUG(llvm::dbgs()
1337+
<< DEBUG_TYPE << ": '" << op->getName()
1338+
<< "' failed to verify and will be printed in generic form\n");
13231339
printerFlags.printGenericOpForm();
1340+
}
13241341

13251342
return printerFlags;
13261343
}

0 commit comments

Comments
 (0)