From fe3c1195cfd027fdd28b6d373b3cd9519d5253ec Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Wed, 23 Sep 2020 05:50:05 +0000 Subject: [PATCH] Add a dump() method on the pass manager for debugging purpose (NFC) Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D88008 --- mlir/include/mlir/Pass/Pass.h | 2 +- mlir/include/mlir/Pass/PassManager.h | 5 ++++- mlir/lib/Pass/Pass.cpp | 26 +++++++++++++++++--------- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/mlir/include/mlir/Pass/Pass.h b/mlir/include/mlir/Pass/Pass.h index e21e3e7..70e1cd1 100644 --- a/mlir/include/mlir/Pass/Pass.h +++ b/mlir/include/mlir/Pass/Pass.h @@ -118,7 +118,7 @@ public: /// Prints out the pass in the textual representation of pipelines. If this is /// an adaptor pass, print with the op_name(sub_pass,...) format. - void printAsTextualPipeline(raw_ostream &os); + void printAsTextualPipeline(raw_ostream &os, bool filterVerifier = true); //===--------------------------------------------------------------------===// // Statistics diff --git a/mlir/include/mlir/Pass/PassManager.h b/mlir/include/mlir/Pass/PassManager.h index 9b9214f..4008911e 100644 --- a/mlir/include/mlir/Pass/PassManager.h +++ b/mlir/include/mlir/Pass/PassManager.h @@ -104,7 +104,10 @@ public: /// of pipelines. /// Note: The quality of the string representation depends entirely on the /// the correctness of per-pass overrides of Pass::printAsTextualPipeline. - void printAsTextualPipeline(raw_ostream &os); + void printAsTextualPipeline(raw_ostream &os, bool filterVerifier = true); + + /// Raw dump of the pass manager to llvm::errs(). + void dump(); /// Merge the pass statistics of this class into 'other'. void mergeStatisticsInto(OpPassManager &other); diff --git a/mlir/lib/Pass/Pass.cpp b/mlir/lib/Pass/Pass.cpp index 7098b4b..d84b71c 100644 --- a/mlir/lib/Pass/Pass.cpp +++ b/mlir/lib/Pass/Pass.cpp @@ -52,13 +52,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. -void Pass::printAsTextualPipeline(raw_ostream &os) { +void Pass::printAsTextualPipeline(raw_ostream &os, bool filterVerifier) { // Special case for adaptors to use the 'op_name(sub_passes)' format. if (auto *adaptor = dyn_cast(this)) { llvm::interleaveComma(adaptor->getPassManagers(), os, [&](OpPassManager &pm) { os << pm.getOpName() << "("; - pm.printAsTextualPipeline(os); + pm.printAsTextualPipeline(os, filterVerifier); os << ")"; }); return; @@ -74,7 +74,6 @@ void Pass::printAsTextualPipeline(raw_ostream &os) { passOptions.print(os); } - //===----------------------------------------------------------------------===// // Verifier Passes //===----------------------------------------------------------------------===// @@ -315,22 +314,31 @@ Identifier OpPassManager::getOpName(MLIRContext &context) const { /// Prints out the given passes as the textual representation of a pipeline. static void printAsTextualPipeline(ArrayRef> passes, - raw_ostream &os) { + raw_ostream &os, + bool filterVerifier = true) { // Filter out passes that are not part of the public pipeline. auto filteredPasses = - llvm::make_filter_range(passes, [](const std::unique_ptr &pass) { - return !isa(pass); + llvm::make_filter_range(passes, [&](const std::unique_ptr &pass) { + return !filterVerifier || !isa(pass); }); llvm::interleaveComma(filteredPasses, os, [&](const std::unique_ptr &pass) { - pass->printAsTextualPipeline(os); + pass->printAsTextualPipeline(os, filterVerifier); }); } /// Prints out the passes of the pass manager as the textual representation /// of pipelines. -void OpPassManager::printAsTextualPipeline(raw_ostream &os) { - ::printAsTextualPipeline(impl->passes, os); +void OpPassManager::printAsTextualPipeline(raw_ostream &os, + bool filterVerifier) { + ::printAsTextualPipeline(impl->passes, os, filterVerifier); +} + +void OpPassManager::dump() { + llvm::errs() << "Pass Manager with " << impl->passes.size() << " passes: "; + ::printAsTextualPipeline(impl->passes, llvm::errs(), + /*filterVerifier=*/false); + llvm::errs() << "\n"; } static void registerDialectsForPipeline(const OpPassManager &pm, -- 2.7.4