+/// Add RequiredPass into list of lower level passes required by pass P.
+/// RequiredPass is run on the fly by Pass Manager when P requests it
+/// through getAnalysis interface.
+void MPPassManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
+
+ assert (P->getPotentialPassManagerType() == PMT_ModulePassManager
+ && "Unable to handle Pass that requires lower level Analysis pass");
+ assert ((P->getPotentialPassManagerType() <
+ RequiredPass->getPotentialPassManagerType())
+ && "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);
+}
+
+