#include "llvm/Analysis/Dominators.h"
#include "llvm-c/Core.h"
#include <algorithm>
+#include <cstdio>
#include <vector>
#include <map>
using namespace llvm;
// 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);
if (!VerifyDomInfo || !P.getResolver())
return;
- DominatorTree *DT = P.getAnalysisToUpdate<DominatorTree>();
+ DominatorTree *DT = P.getAnalysisIfAvailable<DominatorTree>();
if (!DT)
return;
assert (0 && "Invalid dominator info");
}
- DominanceFrontier *DF = P.getAnalysisToUpdate<DominanceFrontier>();
+ DominanceFrontier *DF = P.getAnalysisIfAvailable<DominanceFrontier>();
if (!DF)
return;
&& 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);
}
}
if (TheTimeInfo) TheTimeInfo->passStarted(*I);
(*I)->releaseMemory();
if (TheTimeInfo) TheTimeInfo->passEnded(*I);
-
- std::map<AnalysisID, Pass*>::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<AnalysisID, Pass*>::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<const PassInfo*> &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);
+ }
+ }
}
}
//===----------------------------------------------------------------------===//
// 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);
}
}
// 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) {
return Changed;
}
-inline bool BBPassManager::doFinalization(Module &M) {
+bool BBPassManager::doFinalization(Module &M) {
bool Changed = false;
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
return Changed;
}
-inline bool BBPassManager::doInitialization(Function &F) {
+bool BBPassManager::doInitialization(Function &F) {
bool Changed = false;
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
return Changed;
}
-inline bool BBPassManager::doFinalization(Function &F) {
+bool BBPassManager::doFinalization(Function &F) {
bool Changed = false;
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
//===----------------------------------------------------------------------===//
// FunctionPassManagerImpl implementation
//
-inline bool FunctionPassManagerImpl::doInitialization(Module &M) {
+bool FunctionPassManagerImpl::doInitialization(Module &M) {
bool Changed = false;
for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
return Changed;
}
-inline bool FunctionPassManagerImpl::doFinalization(Module &M) {
+bool FunctionPassManagerImpl::doFinalization(Module &M) {
bool Changed = false;
for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
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) {
return Changed;
}
-inline bool FPPassManager::doFinalization(Module &M) {
+bool FPPassManager::doFinalization(Module &M) {
bool Changed = false;
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
else
break;
}
-
+ assert(!PMS.empty() && "Unable to find appropriate Pass Manager");
PMS.top()->add(this);
}
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();
// [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);