X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FVMCore%2FPassManager.cpp;h=4335757a5093ca7f81c83fae037ba51b064161d2;hb=2625f9b2e4388a957286063f6c7fe5406fd0ca7a;hp=68a856a4d519ca976a351b045ee117b80dc6d0ad;hpb=78766ff67cb9222a2dd5e2cda2e1488b5288a79d;p=oota-llvm.git diff --git a/lib/VMCore/PassManager.cpp b/lib/VMCore/PassManager.cpp index 68a856a4d51..4335757a509 100644 --- a/lib/VMCore/PassManager.cpp +++ b/lib/VMCore/PassManager.cpp @@ -22,6 +22,7 @@ #include "llvm/Analysis/Dominators.h" #include "llvm-c/Core.h" #include +#include #include #include using namespace llvm; @@ -73,7 +74,7 @@ class VISIBILITY_HIDDEN BBPassManager : public PMDataManager, public: static char ID; explicit BBPassManager(int Depth) - : PMDataManager(Depth), FunctionPass((intptr_t)&ID) {} + : PMDataManager(Depth), FunctionPass(&ID) {} /// Execute all of the passes scheduled for execution. Keep track of /// whether any of the passes modifies the function, and if so, return true. @@ -129,7 +130,7 @@ class FunctionPassManagerImpl : public Pass, public: static char ID; explicit FunctionPassManagerImpl(int Depth) : - Pass((intptr_t)&ID), PMDataManager(Depth), + Pass(&ID), PMDataManager(Depth), PMTopLevelManager(TLM_Function) { } /// add - Add a pass to the queue of passes to run. This passes ownership of @@ -193,7 +194,7 @@ class MPPassManager : public Pass, public PMDataManager { public: static char ID; explicit MPPassManager(int Depth) : - Pass((intptr_t)&ID), PMDataManager(Depth) { } + Pass(&ID), PMDataManager(Depth) { } // Delete on the fly managers. virtual ~MPPassManager() { @@ -269,8 +270,7 @@ class PassManagerImpl : public Pass, public: static char ID; explicit PassManagerImpl(int Depth) : - Pass((intptr_t)&ID), PMDataManager(Depth), - PMTopLevelManager(TLM_Pass) { } + Pass(&ID), PMDataManager(Depth), PMTopLevelManager(TLM_Pass) { } /// add - Add a pass to the queue of passes to run. This passes ownership of /// the Pass to the PassManager. When the PassManager is destroyed, the pass @@ -458,25 +458,41 @@ void PMTopLevelManager::schedulePass(Pass *P) { // generate the analysis again. Stale analysis info should not be // available at this point. if (P->getPassInfo() && - P->getPassInfo()->isAnalysis() && findAnalysisPass(P->getPassInfo())) + P->getPassInfo()->isAnalysis() && findAnalysisPass(P->getPassInfo())) { + delete P; return; + } AnalysisUsage *AnUsage = findAnalysisUsage(P); - const AnalysisUsage::VectorType &RequiredSet = AnUsage->getRequiredSet(); - for (AnalysisUsage::VectorType::const_iterator I = RequiredSet.begin(), - E = RequiredSet.end(); I != E; ++I) { - - Pass *AnalysisPass = findAnalysisPass(*I); - if (!AnalysisPass) { - AnalysisPass = (*I)->createPass(); - // Schedule this analysis run first only if it is not a lower level - // analysis pass. Lower level analsyis passes are run on the fly. - if (P->getPotentialPassManagerType () >= - AnalysisPass->getPotentialPassManagerType()) - schedulePass(AnalysisPass); - else - delete AnalysisPass; + bool checkAnalysis = true; + while (checkAnalysis) { + checkAnalysis = false; + + const AnalysisUsage::VectorType &RequiredSet = AnUsage->getRequiredSet(); + for (AnalysisUsage::VectorType::const_iterator I = RequiredSet.begin(), + E = RequiredSet.end(); I != E; ++I) { + + Pass *AnalysisPass = findAnalysisPass(*I); + if (!AnalysisPass) { + AnalysisPass = (*I)->createPass(); + if (P->getPotentialPassManagerType () == + AnalysisPass->getPotentialPassManagerType()) + // Schedule analysis pass that is managed by the same pass manager. + schedulePass(AnalysisPass); + else if (P->getPotentialPassManagerType () > + AnalysisPass->getPotentialPassManagerType()) { + // Schedule analysis pass that is managed by a new manager. + schedulePass(AnalysisPass); + // Recheck analysis passes to ensure that required analysises that + // are already checked are still available. + checkAnalysis = true; + } + else + // Do not schedule this analysis. Lower level analsyis + // passes are run on the fly. + delete AnalysisPass; + } } } @@ -663,7 +679,7 @@ void PMDataManager::verifyDomInfo(Pass &P, Function &F) { if (!VerifyDomInfo || !P.getResolver()) return; - DominatorTree *DT = P.getAnalysisToUpdate(); + DominatorTree *DT = P.getAnalysisIfAvailable(); if (!DT) return; @@ -679,7 +695,7 @@ void PMDataManager::verifyDomInfo(Pass &P, Function &F) { assert (0 && "Invalid dominator info"); } - DominanceFrontier *DF = P.getAnalysisToUpdate(); + DominanceFrontier *DF = P.getAnalysisIfAvailable(); if (!DF) return; @@ -711,12 +727,12 @@ void PMDataManager::removeNotPreservedAnalysis(Pass *P) { && std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) == PreservedSet.end()) { // Remove this analysis - AvailableAnalysis.erase(Info); if (PassDebugging >= Details) { Pass *S = Info->second; cerr << " -- '" << P->getPassName() << "' is not preserving '"; cerr << S->getPassName() << "'\n"; } + AvailableAnalysis.erase(Info); } } @@ -766,13 +782,23 @@ void PMDataManager::removeDeadPasses(Pass *P, const char *Msg, if (TheTimeInfo) TheTimeInfo->passStarted(*I); (*I)->releaseMemory(); if (TheTimeInfo) TheTimeInfo->passEnded(*I); - - std::map::iterator Pos = - AvailableAnalysis.find((*I)->getPassInfo()); - - // It is possible that pass is already removed from the AvailableAnalysis - if (Pos != AvailableAnalysis.end()) - AvailableAnalysis.erase(Pos); + if (const PassInfo *PI = (*I)->getPassInfo()) { + std::map::iterator Pos = + AvailableAnalysis.find(PI); + + // It is possible that pass is already removed from the AvailableAnalysis + if (Pos != AvailableAnalysis.end()) + AvailableAnalysis.erase(Pos); + + // Remove all interfaces this pass implements, for which it is also + // listed as the available implementation. + const std::vector &II = PI->getInterfacesImplemented(); + for (unsigned i = 0, e = II.size(); i != e; ++i) { + Pos = AvailableAnalysis.find(II[i]); + if (Pos != AvailableAnalysis.end() && Pos->second == *I) + AvailableAnalysis.erase(Pos); + } + } } } @@ -1062,8 +1088,8 @@ PMDataManager::~PMDataManager() { //===----------------------------------------------------------------------===// // NOTE: Is this the right place to define this method ? -// getAnalysisToUpdate - Return an analysis result or null if it doesn't exist -Pass *AnalysisResolver::getAnalysisToUpdate(AnalysisID ID, bool dir) const { +// getAnalysisIfAvailable - Return analysis result or null if it doesn't exist. +Pass *AnalysisResolver::getAnalysisIfAvailable(AnalysisID ID, bool dir) const { return PM.findAnalysisPass(ID, dir); } @@ -1114,7 +1140,7 @@ BBPassManager::runOnFunction(Function &F) { } // Implement doInitialization and doFinalization -inline bool BBPassManager::doInitialization(Module &M) { +bool BBPassManager::doInitialization(Module &M) { bool Changed = false; for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) { @@ -1125,7 +1151,7 @@ inline bool BBPassManager::doInitialization(Module &M) { return Changed; } -inline bool BBPassManager::doFinalization(Module &M) { +bool BBPassManager::doFinalization(Module &M) { bool Changed = false; for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) { @@ -1136,7 +1162,7 @@ inline bool BBPassManager::doFinalization(Module &M) { return Changed; } -inline bool BBPassManager::doInitialization(Function &F) { +bool BBPassManager::doInitialization(Function &F) { bool Changed = false; for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) { @@ -1147,7 +1173,7 @@ inline bool BBPassManager::doInitialization(Function &F) { return Changed; } -inline bool BBPassManager::doFinalization(Function &F) { +bool BBPassManager::doFinalization(Function &F) { bool Changed = false; for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) { @@ -1216,7 +1242,7 @@ bool FunctionPassManager::doFinalization() { //===----------------------------------------------------------------------===// // FunctionPassManagerImpl implementation // -inline bool FunctionPassManagerImpl::doInitialization(Module &M) { +bool FunctionPassManagerImpl::doInitialization(Module &M) { bool Changed = false; for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) { @@ -1227,7 +1253,7 @@ inline bool FunctionPassManagerImpl::doInitialization(Module &M) { return Changed; } -inline bool FunctionPassManagerImpl::doFinalization(Module &M) { +bool FunctionPassManagerImpl::doFinalization(Module &M) { bool Changed = false; for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) { @@ -1322,7 +1348,7 @@ bool FPPassManager::runOnModule(Module &M) { return Changed |= doFinalization(M); } -inline bool FPPassManager::doInitialization(Module &M) { +bool FPPassManager::doInitialization(Module &M) { bool Changed = false; for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) { @@ -1333,7 +1359,7 @@ inline bool FPPassManager::doInitialization(Module &M) { return Changed; } -inline bool FPPassManager::doFinalization(Module &M) { +bool FPPassManager::doFinalization(Module &M) { bool Changed = false; for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) { @@ -1568,7 +1594,7 @@ void ModulePass::assignPassManager(PMStack &PMS, else break; } - + assert(!PMS.empty() && "Unable to find appropriate Pass Manager"); PMS.top()->add(this); } @@ -1577,7 +1603,7 @@ void ModulePass::assignPassManager(PMStack &PMS, void FunctionPass::assignPassManager(PMStack &PMS, PassManagerType PreferredType) { - // Find Module Pass Manager (TODO : Or Call Graph Pass Manager) + // Find Module Pass Manager while(!PMS.empty()) { if (PMS.top()->getPassManagerType() > PMT_FunctionPassManager) PMS.pop(); @@ -1601,13 +1627,7 @@ void FunctionPass::assignPassManager(PMStack &PMS, // [3] Assign manager to manage this new manager. This may create // and push new managers into PMS - - // If Call Graph Pass Manager is active then use it to manage - // this new Function Pass manager. - if (PMD->getPassManagerType() == PMT_CallGraphPassManager) - FPP->assignPassManager(PMS, PMT_CallGraphPassManager); - else - FPP->assignPassManager(PMS); + FPP->assignPassManager(PMS, PMD->getPassManagerType()); // [4] Push new manager into PMS PMS.push(FPP);