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

weiwei chen llvmlistbot at llvm.org
Mon Dec 16 09:30:54 PST 2024


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

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

>From 4cbb253c5d5dc0382d881ef211b7f8676c0393b4 Mon Sep 17 00:00:00 2001
From: Weiwei Chen <weiwei.chen at modular.com>
Date: Mon, 16 Dec 2024 12:24:01 -0500
Subject: [PATCH] [mlir] Add Operation::dumpPrettyPrinted.

Pretty print Operation that may not be verified for ease
of readabilty while debugging.
---
 mlir/include/mlir/IR/Operation.h | 3 +++
 mlir/lib/IR/AsmPrinter.cpp       | 5 +++++
 2 files changed, 8 insertions(+)

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



More information about the Mlir-commits mailing list