-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir] Add Operation::dumpPrettyPrinted
#120117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mlir] Add Operation::dumpPrettyPrinted
#120117
Conversation
Pretty print Operation that may not be verified for ease of readabilty while debugging.
…eic/mlir/dump-pretty-printed
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-core Author: weiwei chen (weiweichen) Changes
Full diff: https://github.com/llvm/llvm-project/pull/120117.diff 2 Files Affected:
diff --git a/mlir/include/mlir/IR/Operation.h b/mlir/include/mlir/IR/Operation.h
index f0dd7c51780566..4f6bea3dcf113c 100644
--- a/mlir/include/mlir/IR/Operation.h
+++ b/mlir/include/mlir/IR/Operation.h
@@ -322,6 +322,9 @@ class alignas(8) Operation final
void print(raw_ostream &os, AsmState &state);
void dump();
+ /// Pretty print for ease of debugging readabilty with unverified IR.
+ void dumpPrettyPrinted();
+
//===--------------------------------------------------------------------===//
// Operands
//===--------------------------------------------------------------------===//
diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp
index 61b90bc9b0a7bb..7beb2ab1fb0444 100644
--- a/mlir/lib/IR/AsmPrinter.cpp
+++ b/mlir/lib/IR/AsmPrinter.cpp
@@ -3985,6 +3985,11 @@ void Operation::dump() {
llvm::errs() << "\n";
}
+void Operation::dumpPrettyPrinted() {
+ print(llvm::errs(), OpPrintingFlags().useLocalScope().assumeVerified());
+ llvm::errs() << "\n";
+}
+
void Block::print(raw_ostream &os) {
Operation *parentOp = getParentOp();
if (!parentOp) {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not really sure I'm following this API, it seems very narrow and specific. Have you considered instead the possibility of adding an argument to dump
for providing extra flags?
Fair enough! Putting in this patch mostly because @lattner mentioned about 👇 to me the other day when I was asking about why sometime I see a module being printed in generic mode.
If debugger is ok to run |
I think the idea is that in the debugger you can type: |
…eic/mlir/dump-pretty-printed
Sounds good! Updated the API accordingly. |
LGTM, assuming you checked in the debugger that this work as expected! |
mlir/include/mlir/IR/Operation.h
Outdated
@@ -320,7 +320,7 @@ class alignas(8) Operation final | |||
|
|||
void print(raw_ostream &os, const OpPrintingFlags &flags = std::nullopt); | |||
void print(raw_ostream &os, AsmState &state); | |||
void dump(); | |||
void dump(bool assumeVerified = false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to ensure dump
is available, we should mark it with LLVM_DUMP_METHOD. Helps prevent the symbol from being killed off.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, please use LLVM_DUMP_METHOD
For me, the #1 usecase is when working on mlir that is under construction when in LLDB. E.g. working on building a funciton, it has no terminator, it's like "please just dump it, not in the horrible way". I'm not sure how well LLDB works with default arguments these days, but this would definitely reduce my suffering on a near daily basis if we had it :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thank you! +1 with the LLVM_DUMP_METHOD attribute.
lldb doesn't seem to be able to pick up the default arguments 😢. I asked our in-house lldb expert @walter-erquinigo who said that "expr eval is based on the information on DWARF, and not on source code, so it doesn’t know your .h files". I don't think I want to change the behavior of |
Just a nit on the naming: I would call this |
I'm not sure on the name |
The only effect of "AssumeVerified" is to not disable pretty-printing (that is: not disable custom printers and falling back to generic printer). From a user point of view, it seemed to me |
We have some options (like prettyPrintLocations or something) that I had in my mind that made it weird (even if I'd love to remove that flag) |
Not using default argument (because lldb doesn't understand it) with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great outcome, thank you!
Operation::dumpPrettyPrinted
to get more readable print during debugging when the IR may not be able to pass verify yet.