public FunctionPass {
public:
- BBPassManager(int Depth) : PMDataManager(Depth) { }
+ static char ID;
+ BBPassManager(int Depth)
+ : PMDataManager(Depth), FunctionPass((intptr_t)&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.
}
};
+char BBPassManager::ID = 0;
}
namespace llvm {
public PMDataManager,
public PMTopLevelManager {
public:
-
- FunctionPassManagerImpl(int Depth) : PMDataManager(Depth),
- PMTopLevelManager(TLM_Function) { }
+ static char ID;
+ FunctionPassManagerImpl(int Depth) :
+ Pass((intptr_t)&ID), PMDataManager(Depth),
+ PMTopLevelManager(TLM_Function) { }
/// 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
FPPassManager *FP = static_cast<FPPassManager *>(PassManagers[N]);
return FP;
}
-
};
+char FunctionPassManagerImpl::ID = 0;
//===----------------------------------------------------------------------===//
// MPPassManager
//
class MPPassManager : public Pass, public PMDataManager {
public:
- MPPassManager(int Depth) : PMDataManager(Depth) { }
-
+ static char ID;
+ MPPassManager(int Depth) : Pass((intptr_t)&ID), PMDataManager(Depth) { }
+
+ // Delete on the fly managers.
+ virtual ~MPPassManager() {
+ for (std::map<Pass *, FunctionPassManagerImpl *>::iterator
+ I = OnTheFlyManagers.begin(), E = OnTheFlyManagers.end();
+ I != E; ++I) {
+ FunctionPassManagerImpl *FPP = I->second;
+ delete FPP;
+ }
+ }
+
/// run - Execute all of the passes scheduled for execution. Keep track of
/// whether any of the passes modifies the module, and if so, return true.
bool runOnModule(Module &M);
/// through getAnalysis interface.
virtual void addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass);
+ /// Return function pass corresponding to PassInfo PI, that is
+ /// required by module pass MP. Instantiate analysis pass, by using
+ /// its runOnFunction() for function F.
+ virtual Pass* getOnTheFlyPass(Pass *MP, const PassInfo *PI, Function &F);
+
virtual const char *getPassName() const {
return "Module Pass Manager";
}
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
ModulePass *MP = getContainedPass(Index);
MP->dumpPassStructure(Offset + 1);
+ if (FunctionPassManagerImpl *FPP = OnTheFlyManagers[MP])
+ FPP->dumpPassStructure(Offset + 2);
dumpLastUses(MP, Offset+1);
}
}
virtual PassManagerType getPassManagerType() const {
return PMT_ModulePassManager;
}
+
+ private:
+ /// Collection of on the fly FPPassManagers. These managers manage
+ /// function passes that are required by module passes.
+ std::map<Pass *, FunctionPassManagerImpl *> OnTheFlyManagers;
};
+char MPPassManager::ID = 0;
//===----------------------------------------------------------------------===//
// PassManagerImpl
//
+
/// PassManagerImpl manages MPPassManagers
class PassManagerImpl : public Pass,
public PMDataManager,
public PMTopLevelManager {
public:
-
- PassManagerImpl(int Depth) : PMDataManager(Depth),
+ static char ID;
+ PassManagerImpl(int Depth) : Pass((intptr_t)&ID), PMDataManager(Depth),
PMTopLevelManager(TLM_Pass) { }
/// add - Add a pass to the queue of passes to run. This passes ownership of
};
+char PassManagerImpl::ID = 0;
} // End of llvm namespace
namespace {
enum PassDebuggingString DBG_STR) {
std::vector<Pass *> DeadPasses;
+
+ // If this is a on the fly manager then it does not have TPM.
+ if (!TPM)
+ return;
+
TPM->collectLastUses(DeadPasses, P);
for (std::vector<Pass *>::iterator I = DeadPasses.begin(),
assert (0 && "Unable to accomodate Required Pass");
}
- // Now, take care of required analysises that are not available.
- for (SmallVector<AnalysisID, 8>::iterator
- I = ReqAnalysisNotAvailable.begin(),
- E = ReqAnalysisNotAvailable.end() ;I != E; ++I) {
- Pass *AnalysisPass = (*I)->createPass();
- this->addLowerLevelRequiredPass(P, AnalysisPass);
- }
-
// Set P as P's last user until someone starts using P.
// However, if P is a Pass Manager then it does not need
// to record its last user.
TransferLastUses.clear();
}
+ // Now, take care of required analysises that are not available.
+ for (SmallVector<AnalysisID, 8>::iterator
+ I = ReqAnalysisNotAvailable.begin(),
+ E = ReqAnalysisNotAvailable.end() ;I != E; ++I) {
+ Pass *AnalysisPass = (*I)->createPass();
+ this->addLowerLevelRequiredPass(P, AnalysisPass);
+ }
+
// Take a note of analysis required and made available by this pass.
// Remove the analysis not preserved by this pass
removeNotPreservedAnalysis(P);
E = AnUsage.getRequiredSet().end(); I != E; ++I) {
Pass *Impl = findAnalysisPass(*I, true);
if (Impl == 0)
- assert(0 && "Analysis used but not available!");
+ // This may be analysis pass that is initialized on the fly.
+ // If that is not the case then it will raise an assert when it is used.
+ continue;
AnalysisResolver *AR = P->getResolver();
AR->addAnalysisImplsPair(*I, Impl);
}
void PMDataManager::dumpLastUses(Pass *P, unsigned Offset) const{
std::vector<Pass *> LUses;
-
- assert (TPM && "Top Level Manager is missing");
+
+ // If this is a on the fly manager then it does not have TPM.
+ if (!TPM)
+ return;
+
TPM->collectLastUses(LUses, P);
for (std::vector<Pass *>::iterator I = LUses.begin(),
return PM.findAnalysisPass(ID, dir);
}
+Pass *AnalysisResolver::findImplPass(Pass *P, const PassInfo *AnalysisPI,
+ Function &F) {
+ return PM.getOnTheFlyPass(P, AnalysisPI, F);
+}
+
//===----------------------------------------------------------------------===//
// BBPassManager implementation
//===----------------------------------------------------------------------===//
// FPPassManager implementation
+char FPPassManager::ID = 0;
/// Print passes managed by this manager
void FPPassManager::dumpPassStructure(unsigned Offset) {
llvm::cerr << std::string(Offset*2, ' ') << "FunctionPass Manager\n";
RequiredPass->getPotentialPassManagerType())
&& "Unable to handle Pass that requires lower level Analysis pass");
- assert (0 &&
- "Unable to handle Pass that requires lower level Analysis pass");
+ FunctionPassManagerImpl *FPP = OnTheFlyManagers[P];
+ if (!FPP) {
+ FPP = new FunctionPassManagerImpl(0);
+ // FPP is the top level manager.
+ FPP->setTopLevelManager(FPP);
+
+ OnTheFlyManagers[P] = FPP;
+ }
+ FPP->add(RequiredPass);
+
+ // Register P as the last user of RequiredPass.
+ std::vector<Pass *> LU;
+ LU.push_back(RequiredPass);
+ FPP->setLastUser(LU, P);
}
-
+
+/// Return function pass corresponding to PassInfo PI, that is
+/// required by module pass MP. Instantiate analysis pass, by using
+/// its runOnFunction() for function F.
+Pass* MPPassManager::getOnTheFlyPass(Pass *MP, const PassInfo *PI,
+ Function &F) {
+ AnalysisID AID = PI;
+ FunctionPassManagerImpl *FPP = OnTheFlyManagers[MP];
+ assert (FPP && "Unable to find on the fly pass");
+
+ FPP->run(F);
+ return (dynamic_cast<PMTopLevelManager *>(FPP))->findAnalysisPass(AID);
+}
+
+
//===----------------------------------------------------------------------===//
// PassManagerImpl implementation
//