From abe68f59174c7418ae73de0a87587abe0be1fb03 Mon Sep 17 00:00:00 2001 From: Andrew Trick Date: Thu, 19 Sep 2013 06:02:43 +0000 Subject: Revert "Encapsulate PassManager debug flags to avoid static init and cxa_exit." Working on a better solution to this. This reverts commit 7d4e9934e7ca83094c5cf41346966c8350179ff2. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190990 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/Core.cpp | 1 - lib/IR/PassManager.cpp | 171 +++++++++++++++++++++---------------------------- 2 files changed, 74 insertions(+), 98 deletions(-) (limited to 'lib/IR') diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp index 749ae60146..95c516a251 100644 --- a/lib/IR/Core.cpp +++ b/lib/IR/Core.cpp @@ -40,7 +40,6 @@ using namespace llvm; void llvm::initializeCore(PassRegistry &Registry) { - initializePassManager(); initializeDominatorTreePass(Registry); initializePrintModulePassPass(Registry); initializePrintFunctionPassPass(Registry); diff --git a/lib/IR/PassManager.cpp b/lib/IR/PassManager.cpp index 99933a89b0..8d2e2ca89b 100644 --- a/lib/IR/PassManager.cpp +++ b/lib/IR/PassManager.cpp @@ -45,94 +45,65 @@ enum PassDebugLevel { Disabled, Arguments, Structure, Executions, Details }; -bool TimePassesIsEnabled = false; - -/// Encapsulate PassManager debug options. These are convenient options that -/// should be available to any LLVM-based tool. They exist purely as -/// command-line debug options, therefore don't need to be local to an LLVM -/// context or captured by a formal API. In all respects they are handled like -/// global variables, but being defined in the LLVMCore library cannot have -/// static initializers and must be destroyed only at llvm_shutdown. -struct PassDebugOpts { - cl::opt PassDebugging; - - typedef llvm::cl::list - PassOptionList; - - // Print IR out before/after specified passes. - PassOptionList PrintBefore; - - PassOptionList PrintAfter; - - cl::opt PrintBeforeAll; - cl::opt PrintAfterAll; - - cl::opt EnableTiming; - - PassDebugOpts(): - PassDebugging("debug-pass", cl::Hidden, +static cl::opt +PassDebugging("debug-pass", cl::Hidden, cl::desc("Print PassManager debugging information"), cl::values( - clEnumVal(Disabled , "disable debug output"), - clEnumVal(Arguments, - "print pass arguments to pass to 'opt'"), - clEnumVal(Structure, "print pass structure before run()"), - clEnumVal(Executions, - "print pass name before it is executed"), - clEnumVal(Details, - "print pass details when it is executed"), - clEnumValEnd)), - PrintBefore("print-before", - llvm::cl::desc("Print IR before specified passes"), - cl::Hidden), - PrintAfter("print-after", - llvm::cl::desc("Print IR after specified passes"), - cl::Hidden), - PrintBeforeAll("print-before-all", - llvm::cl::desc("Print IR before each pass"), - cl::init(false)), - PrintAfterAll("print-after-all", - llvm::cl::desc("Print IR after each pass"), - cl::init(false)), - EnableTiming("time-passes", cl::location(TimePassesIsEnabled), - cl::desc( - "Time each pass, printing elapsed time for each on exit")) - {} - - /// This is a helper to determine whether to print IR before or - /// after a pass. - bool ShouldPrintBeforeOrAfterPass(const PassInfo *PI, - PassOptionList &PassesToPrint) { - for (unsigned i = 0, ie = PassesToPrint.size(); i < ie; ++i) { - const llvm::PassInfo *PassInf = PassesToPrint[i]; - if (PassInf) - if (PassInf->getPassArgument() == PI->getPassArgument()) { - return true; - } - } - return false; - } - - /// This is a utility to check whether a pass should have IR dumped - /// before it. - bool ShouldPrintBeforePass(const PassInfo *PI) { - return PrintBeforeAll || ShouldPrintBeforeOrAfterPass(PI, PrintBefore); - } - - /// This is a utility to check whether a pass should have IR dumped - /// after it. - bool ShouldPrintAfterPass(const PassInfo *PI) { - return PrintAfterAll || ShouldPrintBeforeOrAfterPass(PI, PrintAfter); + clEnumVal(Disabled , "disable debug output"), + clEnumVal(Arguments , "print pass arguments to pass to 'opt'"), + clEnumVal(Structure , "print pass structure before run()"), + clEnumVal(Executions, "print pass name before it is executed"), + clEnumVal(Details , "print pass details when it is executed"), + clEnumValEnd)); + +typedef llvm::cl::list +PassOptionList; + +// Print IR out before/after specified passes. +static PassOptionList +PrintBefore("print-before", + llvm::cl::desc("Print IR before specified passes"), + cl::Hidden); + +static PassOptionList +PrintAfter("print-after", + llvm::cl::desc("Print IR after specified passes"), + cl::Hidden); + +static cl::opt +PrintBeforeAll("print-before-all", + llvm::cl::desc("Print IR before each pass"), + cl::init(false)); +static cl::opt +PrintAfterAll("print-after-all", + llvm::cl::desc("Print IR after each pass"), + cl::init(false)); + +/// This is a helper to determine whether to print IR before or +/// after a pass. + +static bool ShouldPrintBeforeOrAfterPass(const PassInfo *PI, + PassOptionList &PassesToPrint) { + for (unsigned i = 0, ie = PassesToPrint.size(); i < ie; ++i) { + const llvm::PassInfo *PassInf = PassesToPrint[i]; + if (PassInf) + if (PassInf->getPassArgument() == PI->getPassArgument()) { + return true; + } } -}; + return false; +} -static ManagedStatic GlobalPassDebugOpts; +/// This is a utility to check whether a pass should have IR dumped +/// before it. +static bool ShouldPrintBeforePass(const PassInfo *PI) { + return PrintBeforeAll || ShouldPrintBeforeOrAfterPass(PI, PrintBefore); +} -/// This is called by tools to force registration of debugging options and -/// ensure they appear in the tool's -help usage. -void initializePassManager() { - // Force instantiation of PassDebugOpts. - *GlobalPassDebugOpts; +/// This is a utility to check whether a pass should have IR dumped +/// after it. +static bool ShouldPrintAfterPass(const PassInfo *PI) { + return PrintAfterAll || ShouldPrintBeforeOrAfterPass(PI, PrintAfter); } } // End of llvm namespace @@ -140,9 +111,12 @@ void initializePassManager() { /// isPassDebuggingExecutionsOrMore - Return true if -debug-pass=Executions /// or higher is specified. bool PMDataManager::isPassDebuggingExecutionsOrMore() const { - return GlobalPassDebugOpts->PassDebugging >= Executions; + return PassDebugging >= Executions; } + + + void PassManagerPrettyStackEntry::print(raw_ostream &OS) const { if (V == 0 && M == 0) OS << "Releasing pass '"; @@ -694,8 +668,7 @@ void PMTopLevelManager::schedulePass(Pass *P) { return; } - if (PI && !PI->isAnalysis() && - GlobalPassDebugOpts->ShouldPrintBeforePass(PI)) { + if (PI && !PI->isAnalysis() && ShouldPrintBeforePass(PI)) { Pass *PP = P->createPrinterPass( dbgs(), std::string("*** IR Dump Before ") + P->getPassName() + " ***"); PP->assignPassManager(activeStack, getTopLevelPassManagerType()); @@ -704,8 +677,7 @@ void PMTopLevelManager::schedulePass(Pass *P) { // Add the requested pass to the best available pass manager. P->assignPassManager(activeStack, getTopLevelPassManagerType()); - if (PI && !PI->isAnalysis() && - GlobalPassDebugOpts->ShouldPrintAfterPass(PI)) { + if (PI && !PI->isAnalysis() && ShouldPrintAfterPass(PI)) { Pass *PP = P->createPrinterPass( dbgs(), std::string("*** IR Dump After ") + P->getPassName() + " ***"); PP->assignPassManager(activeStack, getTopLevelPassManagerType()); @@ -757,7 +729,7 @@ Pass *PMTopLevelManager::findAnalysisPass(AnalysisID AID) { // Print passes managed by this top level manager. void PMTopLevelManager::dumpPasses() const { - if (GlobalPassDebugOpts->PassDebugging < Structure) + if (PassDebugging < Structure) return; // Print out the immutable passes @@ -776,7 +748,7 @@ void PMTopLevelManager::dumpPasses() const { void PMTopLevelManager::dumpArguments() const { - if (GlobalPassDebugOpts->PassDebugging < Arguments) + if (PassDebugging < Arguments) return; dbgs() << "Pass Arguments: "; @@ -909,7 +881,7 @@ void PMDataManager::removeNotPreservedAnalysis(Pass *P) { std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) == PreservedSet.end()) { // Remove this analysis - if (GlobalPassDebugOpts->PassDebugging >= Details) { + if (PassDebugging >= Details) { Pass *S = Info->second; dbgs() << " -- '" << P->getPassName() << "' is not preserving '"; dbgs() << S->getPassName() << "'\n"; @@ -933,7 +905,7 @@ void PMDataManager::removeNotPreservedAnalysis(Pass *P) { std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) == PreservedSet.end()) { // Remove this analysis - if (GlobalPassDebugOpts->PassDebugging >= Details) { + if (PassDebugging >= Details) { Pass *S = Info->second; dbgs() << " -- '" << P->getPassName() << "' is not preserving '"; dbgs() << S->getPassName() << "'\n"; @@ -956,7 +928,7 @@ void PMDataManager::removeDeadPasses(Pass *P, StringRef Msg, TPM->collectLastUses(DeadPasses, P); - if (GlobalPassDebugOpts->PassDebugging >= Details && !DeadPasses.empty()) { + if (PassDebugging >= Details && !DeadPasses.empty()) { dbgs() << " -*- '" << P->getPassName(); dbgs() << "' is the last user of following pass instances."; dbgs() << " Free these instances\n"; @@ -1174,7 +1146,7 @@ void PMDataManager::dumpPassArguments() const { void PMDataManager::dumpPassInfo(Pass *P, enum PassDebuggingString S1, enum PassDebuggingString S2, StringRef Msg) { - if (GlobalPassDebugOpts->PassDebugging < Executions) + if (PassDebugging < Executions) return; dbgs() << (void*)this << std::string(getDepth()*2+1, ' '); switch (S1) { @@ -1215,7 +1187,7 @@ void PMDataManager::dumpPassInfo(Pass *P, enum PassDebuggingString S1, } void PMDataManager::dumpRequiredSet(const Pass *P) const { - if (GlobalPassDebugOpts->PassDebugging < Details) + if (PassDebugging < Details) return; AnalysisUsage analysisUsage; @@ -1224,7 +1196,7 @@ void PMDataManager::dumpRequiredSet(const Pass *P) const { } void PMDataManager::dumpPreservedSet(const Pass *P) const { - if (GlobalPassDebugOpts->PassDebugging < Details) + if (PassDebugging < Details) return; AnalysisUsage analysisUsage; @@ -1234,7 +1206,7 @@ void PMDataManager::dumpPreservedSet(const Pass *P) const { void PMDataManager::dumpAnalysisUsage(StringRef Msg, const Pass *P, const AnalysisUsage::VectorType &Set) const { - assert(GlobalPassDebugOpts->PassDebugging >= Details); + assert(PassDebugging >= Details); if (Set.empty()) return; dbgs() << (const void*)P << std::string(getDepth()*2+3, ' ') << Msg << " Analyses:"; @@ -1769,6 +1741,11 @@ bool PassManager::run(Module &M) { //===----------------------------------------------------------------------===// // TimingInfo implementation +bool llvm::TimePassesIsEnabled = false; +static cl::opt +EnableTiming("time-passes", cl::location(TimePassesIsEnabled), + cl::desc("Time each pass, printing elapsed time for each on exit")); + // createTheTimeInfo - This method either initializes the TheTimeInfo pointer to // a non null value (if the -time-passes option is enabled) or it leaves it // null. It may be called multiple times. -- cgit v1.2.3