Skip to content

Commit 3b0e3dd

Browse files
committed
add a pretty option and fix most tests
1 parent 8604bf6 commit 3b0e3dd

File tree

7 files changed

+38
-20
lines changed

7 files changed

+38
-20
lines changed

mlir/include/mlir/Pass/Pass.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class Pass {
119119

120120
/// Prints out the pass in the textual representation of pipelines. If this is
121121
/// an adaptor pass, print its pass managers.
122-
void printAsTextualPipeline(raw_ostream &os);
122+
void printAsTextualPipeline(raw_ostream &os, bool pretty = false);
123123

124124
//===--------------------------------------------------------------------===//
125125
// Statistics

mlir/include/mlir/Pass/PassManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class OpPassManager {
143143
/// of pipelines.
144144
/// Note: The quality of the string representation depends entirely on the
145145
/// the correctness of per-pass overrides of Pass::printAsTextualPipeline.
146-
void printAsTextualPipeline(raw_ostream &os) const;
146+
void printAsTextualPipeline(raw_ostream &os, bool pretty = false) const;
147147

148148
/// Raw dump of the pass manager to llvm::errs().
149149
void dump();

mlir/lib/Pass/Pass.cpp

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ void Pass::copyOptionValuesFrom(const Pass *other) {
8282

8383
/// Prints out the pass in the textual representation of pipelines. If this is
8484
/// an adaptor pass, print its pass managers.
85-
void Pass::printAsTextualPipeline(raw_ostream &os) {
85+
void Pass::printAsTextualPipeline(raw_ostream &os, bool pretty) {
8686
// Special case for adaptors to print its pass managers.
8787
if (auto *adaptor = dyn_cast<OpToOpPassAdaptor>(this)) {
8888
llvm::interleave(
8989
adaptor->getPassManagers(),
90-
[&](OpPassManager &pm) { pm.printAsTextualPipeline(os); },
90+
[&](OpPassManager &pm) { pm.printAsTextualPipeline(os, pretty); },
9191
[&] { os << ","; });
9292
return;
9393
}
@@ -394,14 +394,24 @@ StringRef OpPassManager::getOpAnchorName() const {
394394
/// of pipelines.
395395
void printAsTextualPipeline(
396396
raw_indented_ostream &os, StringRef anchorName,
397-
const llvm::iterator_range<OpPassManager::pass_iterator> &passes) {
398-
os << anchorName << "(\n";
399-
os.indent();
397+
const llvm::iterator_range<OpPassManager::pass_iterator> &passes,
398+
bool pretty = false) {
399+
os << anchorName << "(";
400+
if (pretty) {
401+
os << "\n";
402+
os.indent();
403+
}
400404
llvm::interleave(
401405
passes, [&](mlir::Pass &pass) { pass.printAsTextualPipeline(os); },
402-
[&]() { os << ",\n"; });
403-
os << "\n";
404-
os.unindent();
406+
[&]() {
407+
os << ",";
408+
if (pretty)
409+
os << "\n";
410+
});
411+
if (pretty) {
412+
os << "\n";
413+
os.unindent();
414+
}
405415
os << ")";
406416
}
407417
void printAsTextualPipeline(
@@ -410,18 +420,19 @@ void printAsTextualPipeline(
410420
raw_indented_ostream indentedOS(os);
411421
printAsTextualPipeline(indentedOS, anchorName, passes);
412422
}
413-
void OpPassManager::printAsTextualPipeline(raw_ostream &os) const {
423+
void OpPassManager::printAsTextualPipeline(raw_ostream &os, bool pretty) const {
414424
StringRef anchorName = getOpAnchorName();
415425
raw_indented_ostream indentedOS(os);
416426
::printAsTextualPipeline(
417427
indentedOS, anchorName,
418428
{MutableArrayRef<std::unique_ptr<Pass>>{impl->passes}.begin(),
419-
MutableArrayRef<std::unique_ptr<Pass>>{impl->passes}.end()});
429+
MutableArrayRef<std::unique_ptr<Pass>>{impl->passes}.end()},
430+
pretty);
420431
}
421432

422433
void OpPassManager::dump() {
423434
llvm::errs() << "Pass Manager with " << impl->passes.size() << " passes:\n";
424-
printAsTextualPipeline(llvm::errs());
435+
printAsTextualPipeline(llvm::errs(), /*pretty=*/true);
425436
llvm::errs() << "\n";
426437
}
427438

@@ -477,7 +488,6 @@ llvm::hash_code OpPassManager::hash() {
477488
return hashCode;
478489
}
479490

480-
481491
//===----------------------------------------------------------------------===//
482492
// OpToOpPassAdaptor
483493
//===----------------------------------------------------------------------===//
@@ -882,7 +892,8 @@ LogicalResult PassManager::run(Operation *op) {
882892
// Initialize all of the passes within the pass manager with a new generation.
883893
llvm::hash_code newInitKey = context->getRegistryHash();
884894
llvm::hash_code pipelineKey = hash();
885-
if (newInitKey != initializationKey || pipelineKey != pipelineInitializationKey) {
895+
if (newInitKey != initializationKey ||
896+
pipelineKey != pipelineInitializationKey) {
886897
if (failed(initialize(context, impl->initializationGeneration + 1)))
887898
return failure();
888899
initializationKey = newInitKey;

mlir/test/Pass/pipeline-parsing.mlir

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
// CHECK_ERROR_7: can't run 'wrong-op' pass manager on 'builtin.module' op
2222

2323
// RUN: mlir-opt %s -pass-pipeline='any(cse)' -dump-pass-pipeline 2>&1 | FileCheck %s -check-prefix=CHECK_ROUNDTRIP
24-
// CHECK_ROUNDTRIP: any(cse)
24+
// CHECK_ROUNDTRIP: any(
25+
// CHECK_ROUNDTRIP-NEXT: cse
26+
// CHECK_ROUNDTRIP-NEXT: )
2527

2628
func.func @foo() {
2729
return

mlir/test/Pass/run-reproducer.mlir

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ func.func @bar() {
1414
external_resources: {
1515
mlir_reproducer: {
1616
verify_each: true,
17-
// CHECK: builtin.module(func.func(cse,canonicalize{ max-iterations=1 max-num-rewrites=-1 region-simplify=normal test-convergence=false top-down=false}))
17+
// CHECK: builtin.module(
18+
// CHECK-NEXT: func.func(cse,canonicalize{ max-iterations=1 max-num-rewrites=-1 region-simplify=normal test-convergence=false top-down=false})
19+
// CHECK-NEXT: )
1820
pipeline: "builtin.module(func.func(cse,canonicalize{max-iterations=1 max-num-rewrites=-1 region-simplify=normal top-down=false}))",
1921
disable_threading: true
2022
}

mlir/test/Transforms/composite-pass.mlir

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
// RUN: mlir-opt %s --log-actions-to=- --composite-fixed-point-pass='name=TestCompositePass pipeline=any(canonicalize,cse)' -split-input-file | FileCheck %s
33

44
// Ensure the composite pass correctly prints its options.
5-
// PIPELINE: builtin.module(composite-fixed-point-pass{max-iterations=10 name=TestCompositePass
6-
// PIPELINE-SAME: pipeline=canonicalize{ max-iterations=10 max-num-rewrites=-1 region-simplify=normal test-convergence=false top-down=true},cse})
5+
// PIPELINE: builtin.module(
6+
// PIPELINE-NEXT: composite-fixed-point-pass{max-iterations=10 name=TestCompositePass
7+
// PIPELINE-SAME: pipeline=canonicalize{ max-iterations=10 max-num-rewrites=-1 region-simplify=normal test-convergence=false top-down=true},cse}
78

89
// CHECK-LABEL: running `TestCompositePass`
910
// CHECK: running `Canonicalizer`
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
// RUN: mlir-opt %s -pass-pipeline="builtin.module(inline)" -dump-pass-pipeline 2>&1 | FileCheck %s
2-
// CHECK: builtin.module(inline{default-pipeline=canonicalize inlining-threshold=4294967295 max-iterations=4 })
2+
// CHECK: builtin.module(
3+
// CHECK-NEXT: inline{default-pipeline=canonicalize inlining-threshold=4294967295 max-iterations=4 }
4+
// CHECK-NEXT: )

0 commit comments

Comments
 (0)