From b56749c3b7bd3867d5a500b9882decd957244620 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Sat, 11 Jan 2014 11:52:05 +0000 Subject: [PATCH] [PM] Add names to passes under the new pass manager, and a debug output mode that can be used to debug the execution of everything. No support for analyses here, that will come later. This already helps show parts of the opt commandline integration that isn't working. Tests of that will start using it as the bugs are fixed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199004 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/PassManager.h | 11 +++++++++++ lib/IR/PassManager.cpp | 30 +++++++++++++++++++++++++++++- tools/opt/Passes.cpp | 1 + unittests/IR/PassManagerTest.cpp | 10 ++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) diff --git a/include/llvm/IR/PassManager.h b/include/llvm/IR/PassManager.h index b85f7f17627..09eb10b8464 100644 --- a/include/llvm/IR/PassManager.h +++ b/include/llvm/IR/PassManager.h @@ -168,6 +168,9 @@ template struct PassConcept { /// desired. Also that the analysis manager may be null if there is no /// analysis manager in the pass pipeline. virtual PreservedAnalyses run(IRUnitT IR, AnalysisManagerT *AM) = 0; + + /// \brief Polymorphic method to access the name of a pass. + virtual StringRef name() = 0; }; /// \brief SFINAE metafunction for computing whether \c PassT has a run method @@ -208,6 +211,7 @@ struct PassModel(llvm_move(Pass))); } + static StringRef name() { return "ModulePassManager"; } + private: // Pull in the concept type and model template specialized for modules. typedef detail::PassConcept ModulePassConcept; @@ -428,6 +435,8 @@ public: PreservedAnalyses run(Function *F, FunctionAnalysisManager *AM = 0); + static StringRef name() { return "FunctionPassManager"; } + private: // Pull in the concept type and model template specialized for functions. typedef detail::PassConcept @@ -808,6 +817,8 @@ public: return PA; } + static StringRef name() { return "ModuleToFunctionPassAdaptor"; } + private: FunctionPassT Pass; }; diff --git a/lib/IR/PassManager.cpp b/lib/IR/PassManager.cpp index 30b46b01c1d..70533fef587 100644 --- a/lib/IR/PassManager.cpp +++ b/lib/IR/PassManager.cpp @@ -7,19 +7,36 @@ // //===----------------------------------------------------------------------===// -#include "llvm/IR/PassManager.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/IR/PassManager.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/Debug.h" using namespace llvm; +static cl::opt +DebugPM("debug-pass-manager", cl::Hidden, + cl::desc("Print pass management debugging information")); + PreservedAnalyses ModulePassManager::run(Module *M, ModuleAnalysisManager *AM) { PreservedAnalyses PA = PreservedAnalyses::all(); + + if (DebugPM) + dbgs() << "Starting module pass manager run.\n"; + for (unsigned Idx = 0, Size = Passes.size(); Idx != Size; ++Idx) { + if (DebugPM) + dbgs() << "Running module pass: " << Passes[Idx]->name() << "\n"; + PreservedAnalyses PassPA = Passes[Idx]->run(M, AM); if (AM) AM->invalidate(M, PassPA); PA.intersect(llvm_move(PassPA)); } + + if (DebugPM) + dbgs() << "Finished module pass manager run.\n"; + return PA; } @@ -61,12 +78,23 @@ void ModuleAnalysisManager::invalidateImpl(Module *M, PreservedAnalyses FunctionPassManager::run(Function *F, FunctionAnalysisManager *AM) { PreservedAnalyses PA = PreservedAnalyses::all(); + + if (DebugPM) + dbgs() << "Starting function pass manager run.\n"; + for (unsigned Idx = 0, Size = Passes.size(); Idx != Size; ++Idx) { + if (DebugPM) + dbgs() << "Running function pass: " << Passes[Idx]->name() << "\n"; + PreservedAnalyses PassPA = Passes[Idx]->run(F, AM); if (AM) AM->invalidate(F, PassPA); PA.intersect(llvm_move(PassPA)); } + + if (DebugPM) + dbgs() << "Finished function pass manager run.\n"; + return PA; } diff --git a/tools/opt/Passes.cpp b/tools/opt/Passes.cpp index 49751269df9..d58acaf1f6d 100644 --- a/tools/opt/Passes.cpp +++ b/tools/opt/Passes.cpp @@ -24,6 +24,7 @@ namespace { /// \brief No-op module pass which does nothing. struct NoOpModulePass { PreservedAnalyses run(Module *M) { return PreservedAnalyses::all(); } + static StringRef name() { return "NoOpModulePass"; } }; } // End anonymous namespace. diff --git a/unittests/IR/PassManagerTest.cpp b/unittests/IR/PassManagerTest.cpp index 8db9c67e7dd..7b2b46a934e 100644 --- a/unittests/IR/PassManagerTest.cpp +++ b/unittests/IR/PassManagerTest.cpp @@ -86,6 +86,8 @@ struct TestModulePass { return PreservedAnalyses::none(); } + static StringRef name() { return "TestModulePass"; } + int &RunCount; }; @@ -93,6 +95,8 @@ struct TestPreservingModulePass { PreservedAnalyses run(Module *M) { return PreservedAnalyses::all(); } + + static StringRef name() { return "TestPreservingModulePass"; } }; struct TestMinPreservingModulePass { @@ -105,6 +109,8 @@ struct TestMinPreservingModulePass { PA.preserve(); return PA; } + + static StringRef name() { return "TestMinPreservingModulePass"; } }; struct TestFunctionPass { @@ -138,6 +144,8 @@ struct TestFunctionPass { return PreservedAnalyses::all(); } + static StringRef name() { return "TestFunctionPass"; } + int &RunCount; int &AnalyzedInstrCount; int &AnalyzedFunctionCount; @@ -154,6 +162,8 @@ struct TestInvalidationFunctionPass { : PreservedAnalyses::all(); } + static StringRef name() { return "TestInvalidationFunctionPass"; } + StringRef Name; }; -- 2.34.1