- // Run all of the passes
- for (unsigned i = 0, e = Passes.size(); i < e; ++i) {
- PassClass *P = Passes[i];
-
- PMDebug::PrintPassInformation(getDepth(), "Executing Pass", P,
- (Annotable*)M);
-
- // Get information about what analyses the pass uses...
- AnalysisUsage AnUsage;
- P->getAnalysisUsage(AnUsage);
- PMDebug::PrintAnalysisSetInfo(getDepth(), "Required", P,
- AnUsage.getRequiredSet());
-
- // All Required analyses should be available to the pass as it runs! Here
- // we fill in the AnalysisImpls member of the pass so that it can
- // successfully use the getAnalysis() method to retrieve the
- // implementations it needs.
- //
- P->AnalysisImpls.clear();
- P->AnalysisImpls.reserve(AnUsage.getRequiredSet().size());
- for (std::vector<const PassInfo *>::const_iterator
- I = AnUsage.getRequiredSet().begin(),
- E = AnUsage.getRequiredSet().end(); I != E; ++I) {
- Pass *Impl = getAnalysisOrNullUp(*I);
- if (Impl == 0) {
- std::cerr << "Analysis '" << (*I)->getPassName()
- << "' used but not available!";
- assert(0 && "Analysis used but not available!");
- } else if (PassDebugging == Details) {
- if ((*I)->getPassName() != std::string(Impl->getPassName()))
- std::cerr << " Interface '" << (*I)->getPassName()
- << "' implemented by '" << Impl->getPassName() << "'\n";
- }
- P->AnalysisImpls.push_back(std::make_pair(*I, Impl));
- }
-
- // Run the sub pass!
- if (TheTimeInfo) TheTimeInfo->passStarted(P);
- bool Changed = runPass(P, M);
- if (TheTimeInfo) TheTimeInfo->passEnded(P);
- MadeChanges |= Changed;
-
- // Check for memory leaks by the pass...
- LeakDetector::checkForGarbage(std::string("after running pass '") +
- P->getPassName() + "'");
-
- if (Changed)
- PMDebug::PrintPassInformation(getDepth()+1, "Made Modification", P,
- (Annotable*)M);
- PMDebug::PrintAnalysisSetInfo(getDepth(), "Preserved", P,
- AnUsage.getPreservedSet());
-
-
- // Erase all analyses not in the preserved set...
- if (!AnUsage.getPreservesAll()) {
- const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
- for (std::map<AnalysisID, Pass*>::iterator I = CurrentAnalyses.begin(),
- E = CurrentAnalyses.end(); I != E; )
- if (std::find(PreservedSet.begin(), PreservedSet.end(), I->first) !=
- PreservedSet.end())
- ++I; // This analysis is preserved, leave it in the available set...
- else {
- if (!dynamic_cast<ImmutablePass*>(I->second)) {
- std::map<AnalysisID, Pass*>::iterator J = I++;
- CurrentAnalyses.erase(J); // Analysis not preserved!
- } else {
- ++I;
- }
- }
- }
-
- // Add the current pass to the set of passes that have been run, and are
- // thus available to users.
- //
- if (const PassInfo *PI = P->getPassInfo()) {
- CurrentAnalyses[PI] = P;
-
- // This pass is the current implementation of all of the interfaces it
- // implements as well.
- //
- const std::vector<const PassInfo*> &II = PI->getInterfacesImplemented();
- for (unsigned i = 0, e = II.size(); i != e; ++i)
- CurrentAnalyses[II[i]] = P;
- }
-
- // Free memory for any passes that we are the last use of...
- std::vector<Pass*> &DeadPass = LastUserOf[P];
- for (std::vector<Pass*>::iterator I = DeadPass.begin(),E = DeadPass.end();
- I != E; ++I) {
- PMDebug::PrintPassInformation(getDepth()+1, "Freeing Pass", *I,
- (Annotable*)M);
- (*I)->releaseMemory();
- }
-
- // Make sure to remove dead passes from the CurrentAnalyses list...
- for (std::map<AnalysisID, Pass*>::iterator I = CurrentAnalyses.begin();
- I != CurrentAnalyses.end(); ) {
- std::vector<Pass*>::iterator DPI = std::find(DeadPass.begin(),
- DeadPass.end(), I->second);
- if (DPI != DeadPass.end()) { // This pass is dead now... remove it
- std::map<AnalysisID, Pass*>::iterator IDead = I++;
- CurrentAnalyses.erase(IDead);
- } else {
- ++I; // Move on to the next element...
- }
- }
- }
-
- return MadeChanges;