diff --git a/mlir/include/mlir/Pass/Pass.h b/mlir/include/mlir/Pass/Pass.h --- a/mlir/include/mlir/Pass/Pass.h +++ b/mlir/include/mlir/Pass/Pass.h @@ -15,6 +15,7 @@ #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/Statistic.h" #include +#include namespace mlir { namespace detail { @@ -66,6 +67,10 @@ /// Returns the derived pass name. virtual StringRef getName() const = 0; + /// Returns the long derived pass name. This includes the pass managers + /// for an adaptor. + virtual std::string getLongName() { return getName().str(); } + /// Register dependent dialects for the current pass. /// A pass is expected to register the dialects it will create entities for /// (Operations, Types, Attributes), other than dialect that exists in the diff --git a/mlir/lib/Pass/IRPrinting.cpp b/mlir/lib/Pass/IRPrinting.cpp --- a/mlir/lib/Pass/IRPrinting.cpp +++ b/mlir/lib/Pass/IRPrinting.cpp @@ -64,14 +64,12 @@ /// Instrumentation hooks. void IRPrinterInstrumentation::runBeforePass(Pass *pass, Operation *op) { - if (isa(pass)) - return; // If the config asked to detect changes, record the current fingerprint. if (config->shouldPrintAfterOnlyOnChange()) beforePassFingerPrints.try_emplace(pass, op); config->printBeforeIfEnabled(pass, op, [&](raw_ostream &out) { - out << "// -----// IR Dump Before " << pass->getName() << " (" + out << "// -----// IR Dump Before " << pass->getLongName() << " (" << pass->getArgument() << ")"; printIR(op, config->shouldPrintAtModuleScope(), out, config->getOpPrintingFlags()); @@ -80,9 +78,6 @@ } void IRPrinterInstrumentation::runAfterPass(Pass *pass, Operation *op) { - if (isa(pass)) - return; - // Check to see if we are only printing on failure. if (config->shouldPrintAfterOnlyOnFailure()) return; @@ -102,7 +97,7 @@ } config->printAfterIfEnabled(pass, op, [&](raw_ostream &out) { - out << "// -----// IR Dump After " << pass->getName() << " (" + out << "// -----// IR Dump After " << pass->getLongName() << " (" << pass->getArgument() << ")"; printIR(op, config->shouldPrintAtModuleScope(), out, config->getOpPrintingFlags()); @@ -111,14 +106,12 @@ } void IRPrinterInstrumentation::runAfterPassFailed(Pass *pass, Operation *op) { - if (isa(pass)) - return; if (config->shouldPrintAfterOnlyOnChange()) beforePassFingerPrints.erase(pass); config->printAfterIfEnabled(pass, op, [&](raw_ostream &out) { - out << formatv("// -----// IR Dump After {0} Failed ({1})", pass->getName(), - pass->getArgument()); + out << formatv("// -----// IR Dump After {0} Failed ({1})", + pass->getLongName(), pass->getArgument()); printIR(op, config->shouldPrintAtModuleScope(), out, OpPrintingFlags()); out << "\n\n"; }); diff --git a/mlir/lib/Pass/Pass.cpp b/mlir/lib/Pass/Pass.cpp --- a/mlir/lib/Pass/Pass.cpp +++ b/mlir/lib/Pass/Pass.cpp @@ -658,6 +658,20 @@ return os.str(); } +/// Returns the adaptor pass long name, including the nested passes. +std::string OpToOpPassAdaptor::getLongName() { + std::string name = "OpToOpPassAdaptor"; + llvm::raw_string_ostream os(name); + os << '('; + llvm::interleaveComma(getPassManagers(), os, [&](OpPassManager &pm) { + os << '['; + llvm::interleaveComma(pm.getPasses(), os, + [&](Pass &pass) { os << pass.getName(); }); + os << ']'; + }); + os << ')'; + return os.str(); +} void OpToOpPassAdaptor::runOnOperation() { llvm_unreachable( "Unexpected call to Pass::runOnOperation() on OpToOpPassAdaptor"); @@ -677,6 +691,7 @@ PassInstrumentation::PipelineParentInfo parentInfo = {llvm::get_threadid(), this}; auto *instrumentor = am.getPassInstrumentor(); + for (auto ®ion : getOperation()->getRegions()) { for (auto &block : region) { for (auto &op : block) { diff --git a/mlir/lib/Pass/PassDetail.h b/mlir/lib/Pass/PassDetail.h --- a/mlir/lib/Pass/PassDetail.h +++ b/mlir/lib/Pass/PassDetail.h @@ -78,6 +78,10 @@ /// Returns the adaptor pass name. std::string getAdaptorName(); + /// Returns the long pass name. For Adaptor pass, the long name includes + /// names of the nested passes. + std::string getLongName() override; + private: /// Run this pass adaptor synchronously. void runOnOperationImpl(bool verifyPasses); diff --git a/mlir/test/Pass/dynamic-pipeline-nested.mlir b/mlir/test/Pass/dynamic-pipeline-nested.mlir --- a/mlir/test/Pass/dynamic-pipeline-nested.mlir +++ b/mlir/test/Pass/dynamic-pipeline-nested.mlir @@ -9,7 +9,9 @@ } // CHECK: IR Dump Before -// CHECK-SAME: TestDynamicPipelinePass +// CHECK-SAME: OpToOpPassAdaptor([{anonymous}::TestDynamicPipelinePass]) +// CHECK: IR Dump Before +// CHECK-SAME: {anonymous}::TestDynamicPipelinePass // CHECK-NEXT: module @inner_mod1 module @inner_mod1 { // We use the mlir-print-ir-after-all dumps to check the granularity of the diff --git a/mlir/test/Pass/dynamic-pipeline.mlir b/mlir/test/Pass/dynamic-pipeline.mlir --- a/mlir/test/Pass/dynamic-pipeline.mlir +++ b/mlir/test/Pass/dynamic-pipeline.mlir @@ -9,7 +9,9 @@ } // CHECK: IR Dump Before -// CHECK-SAME: TestDynamicPipelinePass +// CHECK-SAME: OpToOpPassAdaptor([{anonymous}::TestDynamicPipelinePass]) +// CHECK: IR Dump Before +// CHECK-SAME: {anonymous}::TestDynamicPipelinePass // CHECK-NEXT: module @inner_mod1 // MOD2-ONLY: dynamic-pipeline skip op name: inner_mod1 module @inner_mod1 { @@ -30,7 +32,7 @@ } // CHECK: IR Dump Before -// CHECK-SAME: TestDynamicPipelinePass +// CHECK-SAME: {anonymous}::TestDynamicPipelinePass // CHECK-NEXT: module @inner_mod2 // MOD1-ONLY: dynamic-pipeline skip op name: inner_mod2 module @inner_mod2 {