[Mlir-commits] [mlir] e874bbc - [mlir] Include anchor op when printing pass managers
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Oct 20 16:17:50 PDT 2022
Author: rkayaith
Date: 2022-10-20T19:17:45-04:00
New Revision: e874bbc2925cb1fc96f060ab681098219b7b2b28
URL: https://github.com/llvm/llvm-project/commit/e874bbc2925cb1fc96f060ab681098219b7b2b28
DIFF: https://github.com/llvm/llvm-project/commit/e874bbc2925cb1fc96f060ab681098219b7b2b28.diff
LOG: [mlir] Include anchor op when printing pass managers
Previously a pipeline nested on `anchor-op` would print as just
`'pipeline'`, now it will print as `'anchor-op(pipeline)'`. This ensures
the text form includes all information needed to reconstruct the pass
manager.
Reviewed By: rriddle, mehdi_amini
Differential Revision: https://reviews.llvm.org/D134622
Added:
Modified:
mlir/include/mlir/Pass/Pass.h
mlir/lib/Pass/Pass.cpp
mlir/test/CAPI/pass.c
mlir/test/Pass/pipeline-options-parsing.mlir
mlir/test/python/pass_manager.py
Removed:
################################################################################
diff --git a/mlir/include/mlir/Pass/Pass.h b/mlir/include/mlir/Pass/Pass.h
index 1db6ef6e61444..45dc8188cba0f 100644
--- a/mlir/include/mlir/Pass/Pass.h
+++ b/mlir/include/mlir/Pass/Pass.h
@@ -118,7 +118,7 @@ class Pass {
virtual LogicalResult initializeOptions(StringRef options);
/// Prints out the pass in the textual representation of pipelines. If this is
- /// an adaptor pass, print with the op_name(sub_pass,...) format.
+ /// an adaptor pass, print its pass managers.
void printAsTextualPipeline(raw_ostream &os);
//===--------------------------------------------------------------------===//
diff --git a/mlir/lib/Pass/Pass.cpp b/mlir/lib/Pass/Pass.cpp
index 40b8d164505db..3ca6bceab1301 100644
--- a/mlir/lib/Pass/Pass.cpp
+++ b/mlir/lib/Pass/Pass.cpp
@@ -50,17 +50,13 @@ void Pass::copyOptionValuesFrom(const Pass *other) {
}
/// Prints out the pass in the textual representation of pipelines. If this is
-/// an adaptor pass, print with the op_name(sub_pass,...) format.
+/// an adaptor pass, print its pass managers.
void Pass::printAsTextualPipeline(raw_ostream &os) {
- // Special case for adaptors to use the 'op_name(sub_passes)' format.
+ // Special case for adaptors to print its pass managers.
if (auto *adaptor = dyn_cast<OpToOpPassAdaptor>(this)) {
llvm::interleave(
adaptor->getPassManagers(),
- [&](OpPassManager &pm) {
- os << pm.getOpAnchorName() << "(";
- pm.printAsTextualPipeline(os);
- os << ")";
- },
+ [&](OpPassManager &pm) { pm.printAsTextualPipeline(os); },
[&] { os << ","; });
return;
}
@@ -355,26 +351,22 @@ StringRef OpPassManager::getOpAnchorName() const {
return impl->getOpAnchorName();
}
-/// Prints out the given passes as the textual representation of a pipeline.
-static void printAsTextualPipeline(ArrayRef<std::unique_ptr<Pass>> passes,
- raw_ostream &os) {
+/// Prints out the passes of the pass manager as the textual representation
+/// of pipelines.
+void OpPassManager::printAsTextualPipeline(raw_ostream &os) const {
+ os << getOpAnchorName() << "(";
llvm::interleave(
- passes,
+ impl->passes,
[&](const std::unique_ptr<Pass> &pass) {
pass->printAsTextualPipeline(os);
},
- [&] { os << ","; });
-}
-
-/// Prints out the passes of the pass manager as the textual representation
-/// of pipelines.
-void OpPassManager::printAsTextualPipeline(raw_ostream &os) const {
- ::printAsTextualPipeline(impl->passes, os);
+ [&]() { os << ","; });
+ os << ")";
}
void OpPassManager::dump() {
llvm::errs() << "Pass Manager with " << impl->passes.size() << " passes: ";
- ::printAsTextualPipeline(impl->passes, llvm::errs());
+ printAsTextualPipeline(llvm::errs());
llvm::errs() << "\n";
}
diff --git a/mlir/test/CAPI/pass.c b/mlir/test/CAPI/pass.c
index e48045ac15720..4c68a3ef7963b 100644
--- a/mlir/test/CAPI/pass.c
+++ b/mlir/test/CAPI/pass.c
@@ -145,20 +145,22 @@ void testPrintPassPipeline() {
mlirOpPassManagerAddOwnedPass(nestedFuncPm, printOpStatPass);
// Print the top level pass manager
- // CHECK: Top-level: builtin.module(func.func(print-op-stats{json=false}))
+ // CHECK: Top-level: builtin.module(
+ // CHECK-SAME: builtin.module(func.func(print-op-stats{json=false}))
+ // CHECK-SAME: )
fprintf(stderr, "Top-level: ");
mlirPrintPassPipeline(mlirPassManagerGetAsOpPassManager(pm), printToStderr,
NULL);
fprintf(stderr, "\n");
// Print the pipeline nested one level down
- // CHECK: Nested Module: func.func(print-op-stats{json=false})
+ // CHECK: Nested Module: builtin.module(func.func(print-op-stats{json=false}))
fprintf(stderr, "Nested Module: ");
mlirPrintPassPipeline(nestedModulePm, printToStderr, NULL);
fprintf(stderr, "\n");
// Print the pipeline nested two levels down
- // CHECK: Nested Module>Func: print-op-stats
+ // CHECK: Nested Module>Func: func.func(print-op-stats{json=false})
fprintf(stderr, "Nested Module>Func: ");
mlirPrintPassPipeline(nestedFuncPm, printToStderr, NULL);
fprintf(stderr, "\n");
@@ -197,8 +199,10 @@ void testParsePassPipeline() {
exit(EXIT_FAILURE);
}
- // CHECK: Round-trip: builtin.module(func.func(print-op-stats{json=false}),
- // func.func(print-op-stats{json=false}))
+ // CHECK: Round-trip: builtin.module(builtin.module(
+ // CHECK-SAME: func.func(print-op-stats{json=false}),
+ // CHECK-SAME: func.func(print-op-stats{json=false})
+ // CHECK-SAME: ))
fprintf(stderr, "Round-trip: ");
mlirPrintPassPipeline(mlirPassManagerGetAsOpPassManager(pm), printToStderr,
NULL);
diff --git a/mlir/test/Pass/pipeline-options-parsing.mlir b/mlir/test/Pass/pipeline-options-parsing.mlir
index 74eea1a210188..34e812ffb0085 100644
--- a/mlir/test/Pass/pipeline-options-parsing.mlir
+++ b/mlir/test/Pass/pipeline-options-parsing.mlir
@@ -14,4 +14,4 @@
// CHECK_1: test-options-pass{list=1,2,3,4,5 string=nested_pipeline{arg1=10 arg2=" {} " arg3=true} string-list=a,b,c,d}
// CHECK_2: test-options-pass{list=1 string= string-list=a,b}
-// CHECK_3: builtin.module(func.func(test-options-pass{list=3 string= }),func.func(test-options-pass{list=1,2,3,4 string= }))
+// CHECK_3: builtin.module(builtin.module(func.func(test-options-pass{list=3 string= }),func.func(test-options-pass{list=1,2,3,4 string= })))
diff --git a/mlir/test/python/pass_manager.py b/mlir/test/python/pass_manager.py
index 173042603f3cc..df55f205c541d 100644
--- a/mlir/test/python/pass_manager.py
+++ b/mlir/test/python/pass_manager.py
@@ -46,7 +46,7 @@ def testParseSuccess():
# A registered pass should parse successfully.
pm = PassManager.parse("builtin.module(func.func(print-op-stats{json=false}))")
- # CHECK: Roundtrip: builtin.module(func.func(print-op-stats{json=false}))
+ # CHECK: Roundtrip: builtin.module(builtin.module(func.func(print-op-stats{json=false})))
log("Roundtrip: ", pm)
run(testParseSuccess)
More information about the Mlir-commits
mailing list