From 7f99761143cdf1ad23729708e3dcaa055b189406 Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Mon, 5 Mar 2007 20:01:30 +0000 Subject: [PATCH] Avoid constructing std::strings unless pass debugging is ON. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34933 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/PassManagers.h | 17 +++++- lib/Analysis/IPA/CallGraphSCCPass.cpp | 15 ++--- lib/Analysis/LoopPass.cpp | 10 +--- lib/VMCore/PassManager.cpp | 84 +++++++++++++++++---------- 4 files changed, 75 insertions(+), 51 deletions(-) diff --git a/include/llvm/PassManagers.h b/include/llvm/PassManagers.h index 2448ddad463..8e00fc6e435 100644 --- a/include/llvm/PassManagers.h +++ b/include/llvm/PassManagers.h @@ -93,6 +93,18 @@ enum TopLevelManagerType { TLM_Pass // PassManager }; +// enums for debugging strings +enum PassDebuggingString { + EXECUTION_MSG, // "Executing Pass '" + MODIFICATION_MSG, // "' Made Modification '" + FREEING_MSG, // " Freeing Pass '" + ON_BASICBLOCK_MSG, // "' on BasicBlock '" + PassName + "'...\n" + ON_FUNCTION_MSG, // "' on Function '" + FunctionName + "'...\n" + ON_MODULE_MSG, // "' on Module '" + ModuleName + "'...\n" + ON_LOOP_MSG, // " 'on Loop ...\n'" + ON_CG_MSG // "' on Call Graph ...\n'" +}; + //===----------------------------------------------------------------------===// // PMTopLevelManager // @@ -202,7 +214,7 @@ public: void removeNotPreservedAnalysis(Pass *P); /// Remove dead passes - void removeDeadPasses(Pass *P, std::string &Msg); + void removeDeadPasses(Pass *P, std::string Msg, enum PassDebuggingString); /// Add pass P into the PassVector. Update /// AvailableAnalysis appropriately if ProcessAnalysis is true. @@ -238,7 +250,8 @@ public: // Print routines used by debug-pass void dumpLastUses(Pass *P, unsigned Offset) const; void dumpPassArguments() const; - void dumpPassInfo(Pass *P, std::string &Msg1, std::string &Msg2) const; + void dumpPassInfo(Pass *P, enum PassDebuggingString S1, + enum PassDebuggingString S2, std::string Msg); void dumpAnalysisSetInfo(const char *Msg, Pass *P, const std::vector &Set) const; diff --git a/lib/Analysis/IPA/CallGraphSCCPass.cpp b/lib/Analysis/IPA/CallGraphSCCPass.cpp index c317a112f5a..fcf42028264 100644 --- a/lib/Analysis/IPA/CallGraphSCCPass.cpp +++ b/lib/Analysis/IPA/CallGraphSCCPass.cpp @@ -77,9 +77,6 @@ bool CGPassManager::runOnModule(Module &M) { CallGraph &CG = getAnalysis(); bool Changed = doInitialization(CG); - std::string Msg1 = "Executing Pass '"; - std::string Msg3 = "' Made Modification '"; - // Walk SCC for (scc_iterator I = scc_begin(&CG), E = scc_end(&CG); I != E; ++I) { @@ -91,8 +88,7 @@ bool CGPassManager::runOnModule(Module &M) { AnalysisUsage AnUsage; P->getAnalysisUsage(AnUsage); - std::string Msg2 = "' on Call Graph ...\n'"; - dumpPassInfo(P, Msg1, Msg2); + dumpPassInfo(P, EXECUTION_MSG, ON_CG_MSG, ""); dumpAnalysisSetInfo("Required", P, AnUsage.getRequiredSet()); initializeAnalysisImpl(P); @@ -109,21 +105,20 @@ bool CGPassManager::runOnModule(Module &M) { for (unsigned i = 0, e = SCC.size(); i != e; ++i) { Function *F = SCC[i]->getFunction(); if (F) { - std::string Msg4 = "' on Function '" + F->getName() + "'...\n"; - dumpPassInfo(P, Msg1, Msg4); - Changed |= FPP->runOnFunction(*F); + dumpPassInfo(P, EXECUTION_MSG, ON_FUNCTION_MSG, F->getName()); + Changed |= FPP->runOnFunction(*F); } } } StopPassTimer(P); if (Changed) - dumpPassInfo(P, Msg3, Msg2); + dumpPassInfo(P, MODIFICATION_MSG, ON_CG_MSG, ""); dumpAnalysisSetInfo("Preserved", P, AnUsage.getPreservedSet()); removeNotPreservedAnalysis(P); recordAvailableAnalysis(P); - removeDeadPasses(P, Msg2); + removeDeadPasses(P, "", ON_CG_MSG); } } Changed |= doFinalization(CG); diff --git a/lib/Analysis/LoopPass.cpp b/lib/Analysis/LoopPass.cpp index 4d2e2906082..40b38f37930 100644 --- a/lib/Analysis/LoopPass.cpp +++ b/lib/Analysis/LoopPass.cpp @@ -91,9 +91,6 @@ bool LPPassManager::runOnFunction(Function &F) { for (LoopInfo::iterator I = LI.begin(), E = LI.end(); I != E; ++I) addLoopIntoQueue(*I, LQ); - std::string Msg1 = "Executing Pass '"; - std::string Msg3 = "' Made Modification '"; - // Walk Loops while (!LQ->empty()) { @@ -108,8 +105,7 @@ bool LPPassManager::runOnFunction(Function &F) { AnalysisUsage AnUsage; P->getAnalysisUsage(AnUsage); - std::string Msg2 = "' on Loop ...\n'"; - dumpPassInfo(P, Msg1, Msg2); + dumpPassInfo(P, EXECUTION_MSG, ON_LOOP_MSG, ""); dumpAnalysisSetInfo("Required", P, AnUsage.getRequiredSet()); initializeAnalysisImpl(P); @@ -121,12 +117,12 @@ bool LPPassManager::runOnFunction(Function &F) { StopPassTimer(P); if (Changed) - dumpPassInfo(P, Msg3, Msg2); + dumpPassInfo(P, MODIFICATION_MSG, ON_LOOP_MSG, ""); dumpAnalysisSetInfo("Preserved", P, AnUsage.getPreservedSet()); removeNotPreservedAnalysis(P); recordAvailableAnalysis(P); - removeDeadPasses(P, Msg2); + removeDeadPasses(P, "", ON_LOOP_MSG); if (skipThisLoop) // Do not run other passes on this loop. diff --git a/lib/VMCore/PassManager.cpp b/lib/VMCore/PassManager.cpp index bca52973191..aebff50be7d 100644 --- a/lib/VMCore/PassManager.cpp +++ b/lib/VMCore/PassManager.cpp @@ -553,7 +553,8 @@ void PMDataManager::removeNotPreservedAnalysis(Pass *P) { } /// Remove analysis passes that are not used any longer -void PMDataManager::removeDeadPasses(Pass *P, std::string &Msg) { +void PMDataManager::removeDeadPasses(Pass *P, std::string Msg, + enum PassDebuggingString DBG_STR) { std::vector DeadPasses; TPM->collectLastUses(DeadPasses, P); @@ -561,8 +562,7 @@ void PMDataManager::removeDeadPasses(Pass *P, std::string &Msg) { for (std::vector::iterator I = DeadPasses.begin(), E = DeadPasses.end(); I != E; ++I) { - std::string Msg1 = " Freeing Pass '"; - dumpPassInfo(*I, Msg1, Msg); + dumpPassInfo(*I, FREEING_MSG, DBG_STR, Msg); if (TheTimeInfo) TheTimeInfo->passStarted(*I); (*I)->releaseMemory(); @@ -720,14 +720,44 @@ void PMDataManager::dumpPassArguments() const { } } -void PMDataManager:: dumpPassInfo(Pass *P, std::string &Msg1, - std::string &Msg2) const { +void PMDataManager:: dumpPassInfo(Pass *P, enum PassDebuggingString S1, + enum PassDebuggingString S2, + std::string Msg) { if (PassDebugging < Executions) return; cerr << (void*)this << std::string(getDepth()*2+1, ' '); - cerr << Msg1; - cerr << P->getPassName(); - cerr << Msg2; + switch (S1) { + case EXECUTION_MSG: + cerr << "Executing Pass '" << P->getPassName(); + break; + case MODIFICATION_MSG: + cerr << "' Made Modification '" << P->getPassName(); + break; + case FREEING_MSG: + cerr << " Freeing Pass '" << P->getPassName(); + break; + default: + break; + } + switch (S2) { + case ON_BASICBLOCK_MSG: + cerr << "' on BasicBlock '" << Msg << "...\n"; + break; + case ON_FUNCTION_MSG: + cerr << "' on Function '" << Msg << "...\n"; + break; + case ON_MODULE_MSG: + cerr << "' on Module '" << Msg << "...\n"; + break; + case ON_LOOP_MSG: + cerr << "' on Loop " << Msg << "...\n"; + break; + case ON_CG_MSG: + cerr << "' on Call Graph " << Msg << "...\n"; + break; + default: + break; + } } void PMDataManager::dumpAnalysisSetInfo(const char *Msg, Pass *P, @@ -774,17 +804,13 @@ BBPassManager::runOnFunction(Function &F) { bool Changed = doInitialization(F); - std::string Msg1 = "Executing Pass '"; - std::string Msg3 = "' Made Modification '"; - for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) { BasicBlockPass *BP = getContainedPass(Index); AnalysisUsage AnUsage; BP->getAnalysisUsage(AnUsage); - std::string Msg2 = "' on BasicBlock '" + (*I).getName() + "'...\n"; - dumpPassInfo(BP, Msg1, Msg2); + dumpPassInfo(BP, EXECUTION_MSG, ON_BASICBLOCK_MSG, (*I).getName()); dumpAnalysisSetInfo("Required", BP, AnUsage.getRequiredSet()); initializeAnalysisImpl(BP); @@ -793,13 +819,14 @@ BBPassManager::runOnFunction(Function &F) { Changed |= BP->runOnBasicBlock(*I); if (TheTimeInfo) TheTimeInfo->passEnded(BP); - if (Changed) - dumpPassInfo(BP, Msg3, Msg2); + if (Changed) + dumpPassInfo(BP, MODIFICATION_MSG, ON_BASICBLOCK_MSG, (*I).getName()); dumpAnalysisSetInfo("Preserved", BP, AnUsage.getPreservedSet()); removeNotPreservedAnalysis(BP); recordAvailableAnalysis(BP); - removeDeadPasses(BP, Msg2); + removeDeadPasses(BP, (*I).getName(), ON_BASICBLOCK_MSG); + } return Changed |= doFinalization(F); } @@ -973,17 +1000,13 @@ bool FPPassManager::runOnFunction(Function &F) { if (F.isDeclaration()) return false; - std::string Msg1 = "Executing Pass '"; - std::string Msg3 = "' Made Modification '"; - for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) { FunctionPass *FP = getContainedPass(Index); AnalysisUsage AnUsage; FP->getAnalysisUsage(AnUsage); - std::string Msg2 = "' on Function '" + F.getName() + "'...\n"; - dumpPassInfo(FP, Msg1, Msg2); + dumpPassInfo(FP, EXECUTION_MSG, ON_FUNCTION_MSG, F.getName()); dumpAnalysisSetInfo("Required", FP, AnUsage.getRequiredSet()); initializeAnalysisImpl(FP); @@ -992,13 +1015,13 @@ bool FPPassManager::runOnFunction(Function &F) { Changed |= FP->runOnFunction(F); if (TheTimeInfo) TheTimeInfo->passEnded(FP); - if (Changed) - dumpPassInfo(FP, Msg3, Msg2); + if (Changed) + dumpPassInfo(FP, MODIFICATION_MSG, ON_FUNCTION_MSG, F.getName()); dumpAnalysisSetInfo("Preserved", FP, AnUsage.getPreservedSet()); removeNotPreservedAnalysis(FP); recordAvailableAnalysis(FP); - removeDeadPasses(FP, Msg2); + removeDeadPasses(FP, F.getName(), ON_FUNCTION_MSG); } return Changed; } @@ -1045,17 +1068,13 @@ bool MPPassManager::runOnModule(Module &M) { bool Changed = false; - std::string Msg1 = "Executing Pass '"; - std::string Msg3 = "' Made Modification '"; - for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) { ModulePass *MP = getContainedPass(Index); AnalysisUsage AnUsage; MP->getAnalysisUsage(AnUsage); - std::string Msg2 = "' on Module '" + M.getModuleIdentifier() + "'...\n"; - dumpPassInfo(MP, Msg1, Msg2); + dumpPassInfo(MP, EXECUTION_MSG, ON_MODULE_MSG, M.getModuleIdentifier()); dumpAnalysisSetInfo("Required", MP, AnUsage.getRequiredSet()); initializeAnalysisImpl(MP); @@ -1064,13 +1083,14 @@ MPPassManager::runOnModule(Module &M) { Changed |= MP->runOnModule(M); if (TheTimeInfo) TheTimeInfo->passEnded(MP); - if (Changed) - dumpPassInfo(MP, Msg3, Msg2); + if (Changed) + dumpPassInfo(MP, MODIFICATION_MSG, ON_MODULE_MSG, + M.getModuleIdentifier()); dumpAnalysisSetInfo("Preserved", MP, AnUsage.getPreservedSet()); removeNotPreservedAnalysis(MP); recordAvailableAnalysis(MP); - removeDeadPasses(MP, Msg2); + removeDeadPasses(MP, M.getModuleIdentifier(), ON_MODULE_MSG); } return Changed; } -- 2.34.1