Add a dump() method on the pass manager for debugging purpose (NFC)
authorMehdi Amini <joker.eph@gmail.com>
Wed, 23 Sep 2020 05:50:05 +0000 (05:50 +0000)
committerMehdi Amini <joker.eph@gmail.com>
Wed, 23 Sep 2020 05:53:41 +0000 (05:53 +0000)
Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D88008

mlir/include/mlir/Pass/Pass.h
mlir/include/mlir/Pass/PassManager.h
mlir/lib/Pass/Pass.cpp

index e21e3e7..70e1cd1 100644 (file)
@@ -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
index 9b9214f..4008911 100644 (file)
@@ -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);
index 7098b4b..d84b71c 100644 (file)
@@ -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<OpToOpPassAdaptor>(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<std::unique_ptr<Pass>> 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> &pass) {
-        return !isa<VerifierPass>(pass);
+      llvm::make_filter_range(passes, [&](const std::unique_ptr<Pass> &pass) {
+        return !filterVerifier || !isa<VerifierPass>(pass);
       });
   llvm::interleaveComma(filteredPasses, os,
                         [&](const std::unique_ptr<Pass> &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,