[Mlir-commits] [mlir] [mlir] Add `Operation::dumpPrettyPrinted` (PR #120117)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Dec 16 09:31:32 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir-core

Author: weiwei chen (weiweichen)

<details>
<summary>Changes</summary>

- [x] Add `Operation::dumpPrettyPrinted` to get more readable print during debugging when the IR may not be able to pass verify yet. 

---
Full diff: https://github.com/llvm/llvm-project/pull/120117.diff


2 Files Affected:

- (modified) mlir/include/mlir/IR/Operation.h (+3) 
- (modified) mlir/lib/IR/AsmPrinter.cpp (+5) 


``````````diff
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) {

``````````

</details>


https://github.com/llvm/llvm-project/pull/120117


More information about the Mlir-commits mailing list