From 03153c70de080e4c184ad29f0d78e456019b9a4c Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Tue, 14 Nov 2006 02:54:23 +0000 Subject: [PATCH] Keep track of Last user of analysis phase. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31721 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/PassManager.cpp | 60 +++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/lib/VMCore/PassManager.cpp b/lib/VMCore/PassManager.cpp index 90f3e948a82..2332fed5de5 100644 --- a/lib/VMCore/PassManager.cpp +++ b/lib/VMCore/PassManager.cpp @@ -64,6 +64,7 @@ public: void clearAnalysis() { RequiredAnalysis.clear(); AvailableAnalysis.clear(); + LastUser.clear(); } // All Required analyses should be available to the pass as it runs! Here @@ -81,6 +82,8 @@ public: return PassVector.end(); } + inline void setLastUser(Pass *P, Pass *LU) { LastUser[P] = LU; } + private: // Analysis required by the passes managed by this manager. This information // used while selecting pass manager during addPass. If a pass does not @@ -94,6 +97,10 @@ private: // scheduled to run. std::map AvailableAnalysis; + // Map to keep track of last user of the analysis pass. + // LastUser->second is the last user of Lastuser->first. + std::map LastUser; + // Collection of pass that are managed by this manager std::vector PassVector; }; @@ -114,7 +121,7 @@ public: bool runOnFunction(Function &F); /// Return true IFF AnalysisID AID is currently available. - bool analysisCurrentlyAvailable(AnalysisID AID); + Pass *getAnalysisPassFromManager(AnalysisID AID); private: }; @@ -147,7 +154,7 @@ public: bool runOnModule(Module &M); /// Return true IFF AnalysisID AID is currently available. - bool analysisCurrentlyAvailable(AnalysisID AID); + Pass *getAnalysisPassFromManager(AnalysisID AID); private: // Active Pass Managers @@ -170,7 +177,7 @@ public: bool runOnModule(Module &M); /// Return true IFF AnalysisID AID is currently available. - bool analysisCurrentlyAvailable(AnalysisID AID); + Pass *getAnalysisPassFromManager(AnalysisID AID); private: // Active Pass Manager @@ -193,7 +200,7 @@ public: bool run(Module &M); /// Return true IFF AnalysisID AID is currently available. - bool analysisCurrentlyAvailable(AnalysisID AID); + Pass *getAnalysisPassFromManager(AnalysisID AID); private: @@ -348,8 +355,8 @@ BasicBlockPassManager_New::runOnFunction(Function &F) { } /// Return true IFF AnalysisID AID is currently available. -bool BasicBlockPassManager_New::analysisCurrentlyAvailable(AnalysisID AID) { - return (getAnalysisPass(AID) != 0); +Pass * BasicBlockPassManager_New::getAnalysisPassFromManager(AnalysisID AID) { + return getAnalysisPass(AID); } // FunctionPassManager_New implementation @@ -438,17 +445,18 @@ FunctionPassManagerImpl_New::runOnModule(Module &M) { } /// Return true IFF AnalysisID AID is currently available. -bool FunctionPassManagerImpl_New::analysisCurrentlyAvailable(AnalysisID AID) { +Pass *FunctionPassManagerImpl_New::getAnalysisPassFromManager(AnalysisID AID) { - if (getAnalysisPass(AID) != 0) - return true; + Pass *P = getAnalysisPass(AID); + if (P) + return P; if (activeBBPassManager && activeBBPassManager->getAnalysisPass(AID) != 0) - return true; + return activeBBPassManager->getAnalysisPass(AID); // TODO : Check inactive managers - return false; + return NULL; } // ModulePassManager implementation @@ -512,27 +520,29 @@ ModulePassManager_New::runOnModule(Module &M) { } /// Return true IFF AnalysisID AID is currently available. -bool ModulePassManager_New::analysisCurrentlyAvailable(AnalysisID AID) { +Pass *ModulePassManager_New::getAnalysisPassFromManager(AnalysisID AID) { - if (getAnalysisPass(AID) != 0) - return true; + + Pass *P = getAnalysisPass(AID); + if (P) + return P; if (activeFunctionPassManager && activeFunctionPassManager->getAnalysisPass(AID) != 0) - return true; + return activeFunctionPassManager->getAnalysisPass(AID); // TODO : Check inactive managers - return false; + return NULL; } /// Return true IFF AnalysisID AID is currently available. -bool PassManagerImpl_New::analysisCurrentlyAvailable(AnalysisID AID) { +Pass *PassManagerImpl_New::getAnalysisPassFromManager(AnalysisID AID) { - bool available = false; + Pass *P = NULL; for (std::vector::iterator itr = PassManagers.begin(), - e = PassManagers.end(); !available && itr != e; ++itr) - available = (*itr)->analysisCurrentlyAvailable(AID); - return available; + e = PassManagers.end(); !P && itr != e; ++itr) + P = (*itr)->getAnalysisPassFromManager(AID); + return P; } /// Schedule pass P for execution. Make sure that passes required by @@ -546,11 +556,13 @@ void PassManagerImpl_New::schedulePass(Pass *P) { for (std::vector::const_iterator I = RequiredSet.begin(), E = RequiredSet.end(); I != E; ++I) { - if (!analysisCurrentlyAvailable(*I)) { + Pass *AnalysisPass = getAnalysisPassFromManager(*I); + if (!AnalysisPass) { // Schedule this analysis run first. - Pass *AP = (*I)->createPass(); - schedulePass(AP); + AnalysisPass = (*I)->createPass(); + schedulePass(AnalysisPass); } + setLastUser (AnalysisPass, P); } addPass(P);