[Mlir-commits] [mlir] Pretty print on -dump-pass-pipeline (PR #143223)
Jeremy Kun
llvmlistbot at llvm.org
Fri Jun 6 18:33:08 PDT 2025
https://github.com/j2kun created https://github.com/llvm/llvm-project/pull/143223
This PR makes `dump-pass-pipeline` pretty-print the dumped pipeline. For large pipelines the current behavior produces a wall of text that is hard to visually navigate.
For the command
```bash
mlir-opt --pass-pipeline="builtin.module(flatten-memref, expand-strided-metadata,func.func(arith-expand,func.func(affine-scalrep)))" --dump-pass-pipeline
```
Before:
```bash
Pass Manager with 3 passes:
builtin.module(flatten-memref,expand-strided-metadata,func.func(arith-expand{include-bf16=false include-f8e8m0=false},func.func(affine-scalrep)))
```
After:
```bash
Pass Manager with 3 passes:
builtin.module(
flatten-memref,
expand-strided-metadata,
func.func(
arith-expand{include-bf16=false include-f8e8m0=false},
func.func(
affine-scalrep
)
)
)
```
Another nice feature of this is that the pretty-printed string can still be copy/pasted into `-pass-pipeline` using a quote:
```bash
$ bin/mlir-opt --dump-pass-pipeline test.mlir --pass-pipeline='
builtin.module(
flatten-memref,
expand-strided-metadata,
func.func(
arith-expand{include-bf16=false include-f8e8m0=false},
func.func(
affine-scalrep
)
)
)'
```
>From 8604bf62da04f5a79c6ff220ae45316a22d08cb7 Mon Sep 17 00:00:00 2001
From: Jeremy Kun <j2kun at users.noreply.github.com>
Date: Fri, 6 Jun 2025 18:29:22 -0700
Subject: [PATCH] Pretty print on -dump-pass-pipeline
---
mlir/lib/Pass/Pass.cpp | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/mlir/lib/Pass/Pass.cpp b/mlir/lib/Pass/Pass.cpp
index e0e9b5f54042a..6e8d3bbfdff81 100644
--- a/mlir/lib/Pass/Pass.cpp
+++ b/mlir/lib/Pass/Pass.cpp
@@ -18,6 +18,7 @@
#include "mlir/IR/Threading.h"
#include "mlir/IR/Verifier.h"
#include "mlir/Support/FileUtilities.h"
+#include "mlir/Support/IndentedOstream.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/ScopeExit.h"
@@ -392,18 +393,28 @@ StringRef OpPassManager::getOpAnchorName() const {
/// Prints out the passes of the pass manager as the textual representation
/// of pipelines.
void printAsTextualPipeline(
- raw_ostream &os, StringRef anchorName,
+ raw_indented_ostream &os, StringRef anchorName,
const llvm::iterator_range<OpPassManager::pass_iterator> &passes) {
- os << anchorName << "(";
+ os << anchorName << "(\n";
+ os.indent();
llvm::interleave(
passes, [&](mlir::Pass &pass) { pass.printAsTextualPipeline(os); },
- [&]() { os << ","; });
+ [&]() { os << ",\n"; });
+ os << "\n";
+ os.unindent();
os << ")";
}
+void printAsTextualPipeline(
+ raw_ostream &os, StringRef anchorName,
+ const llvm::iterator_range<OpPassManager::pass_iterator> &passes) {
+ raw_indented_ostream indentedOS(os);
+ printAsTextualPipeline(indentedOS, anchorName, passes);
+}
void OpPassManager::printAsTextualPipeline(raw_ostream &os) const {
StringRef anchorName = getOpAnchorName();
+ raw_indented_ostream indentedOS(os);
::printAsTextualPipeline(
- os, anchorName,
+ indentedOS, anchorName,
{MutableArrayRef<std::unique_ptr<Pass>>{impl->passes}.begin(),
MutableArrayRef<std::unique_ptr<Pass>>{impl->passes}.end()});
}
More information about the Mlir-commits
mailing list