1 //===- PassManager.cpp - LLVM Pass Infrastructure Implementation ----------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Devang Patel and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the LLVM Pass Manager infrastructure.
12 //===----------------------------------------------------------------------===//
15 #include "llvm/PassManagers.h"
16 #include "llvm/Support/CommandLine.h"
17 #include "llvm/Support/Timer.h"
18 #include "llvm/Module.h"
19 #include "llvm/ModuleProvider.h"
20 #include "llvm/Support/Streams.h"
21 #include "llvm/Support/ManagedStatic.h"
27 // See PassManagers.h for Pass Manager infrastructure overview.
31 //===----------------------------------------------------------------------===//
32 // Pass debugging information. Often it is useful to find out what pass is
33 // running when a crash occurs in a utility. When this library is compiled with
34 // debugging on, a command line option (--debug-pass) is enabled that causes the
35 // pass name to be printed before it executes.
38 // Different debug levels that can be enabled...
40 None, Arguments, Structure, Executions, Details
43 static cl::opt<enum PassDebugLevel>
44 PassDebugging("debug-pass", cl::Hidden,
45 cl::desc("Print PassManager debugging information"),
47 clEnumVal(None , "disable debug output"),
48 clEnumVal(Arguments , "print pass arguments to pass to 'opt'"),
49 clEnumVal(Structure , "print pass structure before run()"),
50 clEnumVal(Executions, "print pass name before it is executed"),
51 clEnumVal(Details , "print pass details when it is executed"),
53 } // End of llvm namespace
57 //===----------------------------------------------------------------------===//
60 /// BBPassManager manages BasicBlockPass. It batches all the
61 /// pass together and sequence them to process one basic block before
62 /// processing next basic block.
63 class VISIBILITY_HIDDEN BBPassManager : public PMDataManager,
68 BBPassManager(int Depth)
69 : PMDataManager(Depth), FunctionPass((intptr_t)&ID) {}
71 /// Execute all of the passes scheduled for execution. Keep track of
72 /// whether any of the passes modifies the function, and if so, return true.
73 bool runOnFunction(Function &F);
75 /// Pass Manager itself does not invalidate any analysis info.
76 void getAnalysisUsage(AnalysisUsage &Info) const {
77 Info.setPreservesAll();
80 bool doInitialization(Module &M);
81 bool doInitialization(Function &F);
82 bool doFinalization(Module &M);
83 bool doFinalization(Function &F);
85 virtual const char *getPassName() const {
86 return "BasicBlock Pass Manager";
89 // Print passes managed by this manager
90 void dumpPassStructure(unsigned Offset) {
91 llvm::cerr << std::string(Offset*2, ' ') << "BasicBlockPass Manager\n";
92 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
93 BasicBlockPass *BP = getContainedPass(Index);
94 BP->dumpPassStructure(Offset + 1);
95 dumpLastUses(BP, Offset+1);
99 BasicBlockPass *getContainedPass(unsigned N) {
100 assert ( N < PassVector.size() && "Pass number out of range!");
101 BasicBlockPass *BP = static_cast<BasicBlockPass *>(PassVector[N]);
105 virtual PassManagerType getPassManagerType() const {
106 return PMT_BasicBlockPassManager;
110 char BBPassManager::ID = 0;
115 //===----------------------------------------------------------------------===//
116 // FunctionPassManagerImpl
118 /// FunctionPassManagerImpl manages FPPassManagers
119 class FunctionPassManagerImpl : public Pass,
120 public PMDataManager,
121 public PMTopLevelManager {
124 FunctionPassManagerImpl(int Depth) :
125 Pass((intptr_t)&ID), PMDataManager(Depth),
126 PMTopLevelManager(TLM_Function) { }
128 /// add - Add a pass to the queue of passes to run. This passes ownership of
129 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
130 /// will be destroyed as well, so there is no need to delete the pass. This
131 /// implies that all passes MUST be allocated with 'new'.
136 /// run - Execute all of the passes scheduled for execution. Keep track of
137 /// whether any of the passes modifies the module, and if so, return true.
138 bool run(Function &F);
140 /// doInitialization - Run all of the initializers for the function passes.
142 bool doInitialization(Module &M);
144 /// doFinalization - Run all of the finalizers for the function passes.
146 bool doFinalization(Module &M);
148 /// Pass Manager itself does not invalidate any analysis info.
149 void getAnalysisUsage(AnalysisUsage &Info) const {
150 Info.setPreservesAll();
153 inline void addTopLevelPass(Pass *P) {
155 if (ImmutablePass *IP = dynamic_cast<ImmutablePass *> (P)) {
157 // P is a immutable pass and it will be managed by this
158 // top level manager. Set up analysis resolver to connect them.
159 AnalysisResolver *AR = new AnalysisResolver(*this);
161 initializeAnalysisImpl(P);
162 addImmutablePass(IP);
163 recordAvailableAnalysis(IP);
165 P->assignPassManager(activeStack);
170 FPPassManager *getContainedManager(unsigned N) {
171 assert ( N < PassManagers.size() && "Pass number out of range!");
172 FPPassManager *FP = static_cast<FPPassManager *>(PassManagers[N]);
177 char FunctionPassManagerImpl::ID = 0;
178 //===----------------------------------------------------------------------===//
181 /// MPPassManager manages ModulePasses and function pass managers.
182 /// It batches all Module passes passes and function pass managers together and
183 /// sequence them to process one module.
184 class MPPassManager : public Pass, public PMDataManager {
188 MPPassManager(int Depth) : Pass((intptr_t)&ID), PMDataManager(Depth) { }
190 // Delete on the fly managers.
191 virtual ~MPPassManager() {
192 for (std::map<Pass *, FunctionPassManagerImpl *>::iterator
193 I = OnTheFlyManagers.begin(), E = OnTheFlyManagers.end();
195 FunctionPassManagerImpl *FPP = I->second;
200 /// run - Execute all of the passes scheduled for execution. Keep track of
201 /// whether any of the passes modifies the module, and if so, return true.
202 bool runOnModule(Module &M);
204 /// Pass Manager itself does not invalidate any analysis info.
205 void getAnalysisUsage(AnalysisUsage &Info) const {
206 Info.setPreservesAll();
209 /// Add RequiredPass into list of lower level passes required by pass P.
210 /// RequiredPass is run on the fly by Pass Manager when P requests it
211 /// through getAnalysis interface.
212 virtual void addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass);
214 /// Return function pass corresponding to PassInfo PI, that is
215 /// required by module pass MP. Instantiate analysis pass, by using
216 /// its runOnFunction() for function F.
217 virtual Pass* getOnTheFlyPass(Pass *MP, const PassInfo *PI, Function &F);
219 virtual const char *getPassName() const {
220 return "Module Pass Manager";
223 // Print passes managed by this manager
224 void dumpPassStructure(unsigned Offset) {
225 llvm::cerr << std::string(Offset*2, ' ') << "ModulePass Manager\n";
226 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
227 ModulePass *MP = getContainedPass(Index);
228 MP->dumpPassStructure(Offset + 1);
229 if (FunctionPassManagerImpl *FPP = OnTheFlyManagers[MP])
230 FPP->dumpPassStructure(Offset + 2);
231 dumpLastUses(MP, Offset+1);
235 ModulePass *getContainedPass(unsigned N) {
236 assert ( N < PassVector.size() && "Pass number out of range!");
237 ModulePass *MP = static_cast<ModulePass *>(PassVector[N]);
241 virtual PassManagerType getPassManagerType() const {
242 return PMT_ModulePassManager;
246 /// Collection of on the fly FPPassManagers. These managers manage
247 /// function passes that are required by module passes.
248 std::map<Pass *, FunctionPassManagerImpl *> OnTheFlyManagers;
251 char MPPassManager::ID = 0;
252 //===----------------------------------------------------------------------===//
256 /// PassManagerImpl manages MPPassManagers
257 class PassManagerImpl : public Pass,
258 public PMDataManager,
259 public PMTopLevelManager {
263 PassManagerImpl(int Depth) : Pass((intptr_t)&ID), PMDataManager(Depth),
264 PMTopLevelManager(TLM_Pass) { }
266 /// add - Add a pass to the queue of passes to run. This passes ownership of
267 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
268 /// will be destroyed as well, so there is no need to delete the pass. This
269 /// implies that all passes MUST be allocated with 'new'.
274 /// run - Execute all of the passes scheduled for execution. Keep track of
275 /// whether any of the passes modifies the module, and if so, return true.
278 /// Pass Manager itself does not invalidate any analysis info.
279 void getAnalysisUsage(AnalysisUsage &Info) const {
280 Info.setPreservesAll();
283 inline void addTopLevelPass(Pass *P) {
285 if (ImmutablePass *IP = dynamic_cast<ImmutablePass *> (P)) {
287 // P is a immutable pass and it will be managed by this
288 // top level manager. Set up analysis resolver to connect them.
289 AnalysisResolver *AR = new AnalysisResolver(*this);
291 initializeAnalysisImpl(P);
292 addImmutablePass(IP);
293 recordAvailableAnalysis(IP);
295 P->assignPassManager(activeStack);
300 MPPassManager *getContainedManager(unsigned N) {
301 assert ( N < PassManagers.size() && "Pass number out of range!");
302 MPPassManager *MP = static_cast<MPPassManager *>(PassManagers[N]);
308 char PassManagerImpl::ID = 0;
309 } // End of llvm namespace
313 //===----------------------------------------------------------------------===//
314 // TimingInfo Class - This class is used to calculate information about the
315 // amount of time each pass takes to execute. This only happens when
316 // -time-passes is enabled on the command line.
319 class VISIBILITY_HIDDEN TimingInfo {
320 std::map<Pass*, Timer> TimingData;
324 // Use 'create' member to get this.
325 TimingInfo() : TG("... Pass execution timing report ...") {}
327 // TimingDtor - Print out information about timing information
329 // Delete all of the timers...
331 // TimerGroup is deleted next, printing the report.
334 // createTheTimeInfo - This method either initializes the TheTimeInfo pointer
335 // to a non null value (if the -time-passes option is enabled) or it leaves it
336 // null. It may be called multiple times.
337 static void createTheTimeInfo();
339 void passStarted(Pass *P) {
341 if (dynamic_cast<PMDataManager *>(P))
344 std::map<Pass*, Timer>::iterator I = TimingData.find(P);
345 if (I == TimingData.end())
346 I=TimingData.insert(std::make_pair(P, Timer(P->getPassName(), TG))).first;
347 I->second.startTimer();
349 void passEnded(Pass *P) {
351 if (dynamic_cast<PMDataManager *>(P))
354 std::map<Pass*, Timer>::iterator I = TimingData.find(P);
355 assert (I != TimingData.end() && "passStarted/passEnded not nested right!");
356 I->second.stopTimer();
360 static TimingInfo *TheTimeInfo;
362 } // End of anon namespace
364 //===----------------------------------------------------------------------===//
365 // PMTopLevelManager implementation
367 /// Initialize top level manager. Create first pass manager.
368 PMTopLevelManager::PMTopLevelManager (enum TopLevelManagerType t) {
371 MPPassManager *MPP = new MPPassManager(1);
372 MPP->setTopLevelManager(this);
374 activeStack.push(MPP);
376 else if (t == TLM_Function) {
377 FPPassManager *FPP = new FPPassManager(1);
378 FPP->setTopLevelManager(this);
380 activeStack.push(FPP);
384 /// Set pass P as the last user of the given analysis passes.
385 void PMTopLevelManager::setLastUser(SmallVector<Pass *, 12> &AnalysisPasses,
388 for (SmallVector<Pass *, 12>::iterator I = AnalysisPasses.begin(),
389 E = AnalysisPasses.end(); I != E; ++I) {
396 // If AP is the last user of other passes then make P last user of
398 for (std::map<Pass *, Pass *>::iterator LUI = LastUser.begin(),
399 LUE = LastUser.end(); LUI != LUE; ++LUI) {
400 if (LUI->second == AP)
401 LastUser[LUI->first] = P;
406 /// Collect passes whose last user is P
407 void PMTopLevelManager::collectLastUses(SmallVector<Pass *, 12> &LastUses,
409 for (std::map<Pass *, Pass *>::iterator LUI = LastUser.begin(),
410 LUE = LastUser.end(); LUI != LUE; ++LUI)
411 if (LUI->second == P)
412 LastUses.push_back(LUI->first);
415 /// Schedule pass P for execution. Make sure that passes required by
416 /// P are run before P is run. Update analysis info maintained by
417 /// the manager. Remove dead passes. This is a recursive function.
418 void PMTopLevelManager::schedulePass(Pass *P) {
420 // TODO : Allocate function manager for this pass, other wise required set
421 // may be inserted into previous function manager
423 // Give pass a chance to prepare the stage.
424 P->preparePassManager(activeStack);
426 AnalysisUsage AnUsage;
427 P->getAnalysisUsage(AnUsage);
428 const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet();
429 for (std::vector<AnalysisID>::const_iterator I = RequiredSet.begin(),
430 E = RequiredSet.end(); I != E; ++I) {
432 Pass *AnalysisPass = findAnalysisPass(*I);
434 AnalysisPass = (*I)->createPass();
435 // Schedule this analysis run first only if it is not a lower level
436 // analysis pass. Lower level analsyis passes are run on the fly.
437 if (P->getPotentialPassManagerType () >=
438 AnalysisPass->getPotentialPassManagerType())
439 schedulePass(AnalysisPass);
445 // Now all required passes are available.
449 /// Find the pass that implements Analysis AID. Search immutable
450 /// passes and all pass managers. If desired pass is not found
451 /// then return NULL.
452 Pass *PMTopLevelManager::findAnalysisPass(AnalysisID AID) {
455 // Check pass managers
456 for (std::vector<Pass *>::iterator I = PassManagers.begin(),
457 E = PassManagers.end(); P == NULL && I != E; ++I) {
458 PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I);
459 assert(PMD && "This is not a PassManager");
460 P = PMD->findAnalysisPass(AID, false);
463 // Check other pass managers
464 for (std::vector<PMDataManager *>::iterator I = IndirectPassManagers.begin(),
465 E = IndirectPassManagers.end(); P == NULL && I != E; ++I)
466 P = (*I)->findAnalysisPass(AID, false);
468 for (std::vector<ImmutablePass *>::iterator I = ImmutablePasses.begin(),
469 E = ImmutablePasses.end(); P == NULL && I != E; ++I) {
470 const PassInfo *PI = (*I)->getPassInfo();
474 // If Pass not found then check the interfaces implemented by Immutable Pass
476 const std::vector<const PassInfo*> &ImmPI = PI->getInterfacesImplemented();
477 if (std::find(ImmPI.begin(), ImmPI.end(), AID) != ImmPI.end())
485 // Print passes managed by this top level manager.
486 void PMTopLevelManager::dumpPasses() const {
488 if (PassDebugging < Structure)
491 // Print out the immutable passes
492 for (unsigned i = 0, e = ImmutablePasses.size(); i != e; ++i) {
493 ImmutablePasses[i]->dumpPassStructure(0);
496 for (std::vector<Pass *>::const_iterator I = PassManagers.begin(),
497 E = PassManagers.end(); I != E; ++I)
498 (*I)->dumpPassStructure(1);
501 void PMTopLevelManager::dumpArguments() const {
503 if (PassDebugging < Arguments)
506 cerr << "Pass Arguments: ";
507 for (std::vector<Pass *>::const_iterator I = PassManagers.begin(),
508 E = PassManagers.end(); I != E; ++I) {
509 PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I);
510 assert(PMD && "This is not a PassManager");
511 PMD->dumpPassArguments();
516 void PMTopLevelManager::initializeAllAnalysisInfo() {
518 for (std::vector<Pass *>::iterator I = PassManagers.begin(),
519 E = PassManagers.end(); I != E; ++I) {
520 PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I);
521 assert(PMD && "This is not a PassManager");
522 PMD->initializeAnalysisInfo();
525 // Initailize other pass managers
526 for (std::vector<PMDataManager *>::iterator I = IndirectPassManagers.begin(),
527 E = IndirectPassManagers.end(); I != E; ++I)
528 (*I)->initializeAnalysisInfo();
532 PMTopLevelManager::~PMTopLevelManager() {
533 for (std::vector<Pass *>::iterator I = PassManagers.begin(),
534 E = PassManagers.end(); I != E; ++I)
537 for (std::vector<ImmutablePass *>::iterator
538 I = ImmutablePasses.begin(), E = ImmutablePasses.end(); I != E; ++I)
541 PassManagers.clear();
544 //===----------------------------------------------------------------------===//
545 // PMDataManager implementation
547 /// Return true IFF pass P's required analysis set does not required new
549 bool PMDataManager::manageablePass(Pass *P) {
552 // If this pass is not preserving information that is required by a
553 // pass maintained by higher level pass manager then do not insert
554 // this pass into current manager. Use new manager. For example,
555 // For example, If FunctionPass F is not preserving ModulePass Info M1
556 // that is used by another ModulePass M2 then do not insert F in
557 // current function pass manager.
561 /// Augement AvailableAnalysis by adding analysis made available by pass P.
562 void PMDataManager::recordAvailableAnalysis(Pass *P) {
564 if (const PassInfo *PI = P->getPassInfo()) {
565 AvailableAnalysis[PI] = P;
567 //This pass is the current implementation of all of the interfaces it
568 //implements as well.
569 const std::vector<const PassInfo*> &II = PI->getInterfacesImplemented();
570 for (unsigned i = 0, e = II.size(); i != e; ++i)
571 AvailableAnalysis[II[i]] = P;
575 // Return true if P preserves high level analysis used by other
576 // passes managed by this manager
577 bool PMDataManager::preserveHigherLevelAnalysis(Pass *P) {
579 AnalysisUsage AnUsage;
580 P->getAnalysisUsage(AnUsage);
582 if (AnUsage.getPreservesAll())
585 const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
586 for (std::vector<Pass *>::iterator I = HigherLevelAnalysis.begin(),
587 E = HigherLevelAnalysis.end(); I != E; ++I) {
589 if (!dynamic_cast<ImmutablePass*>(P1)
590 && std::find(PreservedSet.begin(), PreservedSet.end(), P1->getPassInfo()) ==
598 /// verifyPreservedAnalysis -- Verify analysis presreved by pass P.
599 void PMDataManager::verifyPreservedAnalysis(Pass *P) {
600 AnalysisUsage AnUsage;
601 P->getAnalysisUsage(AnUsage);
602 const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
604 // Verify preserved analysis
605 for (std::vector<AnalysisID>::const_iterator I = PreservedSet.begin(),
606 E = PreservedSet.end(); I != E; ++I) {
608 Pass *AP = findAnalysisPass(AID, true);
610 AP->verifyAnalysis();
614 /// Remove Analyss not preserved by Pass P
615 void PMDataManager::removeNotPreservedAnalysis(Pass *P) {
616 AnalysisUsage AnUsage;
617 P->getAnalysisUsage(AnUsage);
618 if (AnUsage.getPreservesAll())
621 const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
622 for (std::map<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(),
623 E = AvailableAnalysis.end(); I != E; ) {
624 std::map<AnalysisID, Pass*>::iterator Info = I++;
625 if (!dynamic_cast<ImmutablePass*>(Info->second)
626 && std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) ==
628 // Remove this analysis
629 AvailableAnalysis.erase(Info);
632 // Check inherited analysis also. If P is not preserving analysis
633 // provided by parent manager then remove it here.
634 for (unsigned Index = 0; Index < PMT_Last; ++Index) {
636 if (!InheritedAnalysis[Index])
639 for (std::map<AnalysisID, Pass*>::iterator
640 I = InheritedAnalysis[Index]->begin(),
641 E = InheritedAnalysis[Index]->end(); I != E; ) {
642 std::map<AnalysisID, Pass *>::iterator Info = I++;
643 if (!dynamic_cast<ImmutablePass*>(Info->second)
644 && std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) ==
646 // Remove this analysis
647 InheritedAnalysis[Index]->erase(Info);
653 /// Remove analysis passes that are not used any longer
654 void PMDataManager::removeDeadPasses(Pass *P, const char *Msg,
655 enum PassDebuggingString DBG_STR) {
657 SmallVector<Pass *, 12> DeadPasses;
659 // If this is a on the fly manager then it does not have TPM.
663 TPM->collectLastUses(DeadPasses, P);
665 for (SmallVector<Pass *, 12>::iterator I = DeadPasses.begin(),
666 E = DeadPasses.end(); I != E; ++I) {
668 dumpPassInfo(*I, FREEING_MSG, DBG_STR, Msg);
670 if (TheTimeInfo) TheTimeInfo->passStarted(*I);
671 (*I)->releaseMemory();
672 if (TheTimeInfo) TheTimeInfo->passEnded(*I);
674 std::map<AnalysisID, Pass*>::iterator Pos =
675 AvailableAnalysis.find((*I)->getPassInfo());
677 // It is possible that pass is already removed from the AvailableAnalysis
678 if (Pos != AvailableAnalysis.end())
679 AvailableAnalysis.erase(Pos);
683 /// Add pass P into the PassVector. Update
684 /// AvailableAnalysis appropriately if ProcessAnalysis is true.
685 void PMDataManager::add(Pass *P,
686 bool ProcessAnalysis) {
688 // This manager is going to manage pass P. Set up analysis resolver
690 AnalysisResolver *AR = new AnalysisResolver(*this);
693 // If a FunctionPass F is the last user of ModulePass info M
694 // then the F's manager, not F, records itself as a last user of M.
695 SmallVector<Pass *, 12> TransferLastUses;
697 if (ProcessAnalysis) {
699 // At the moment, this pass is the last user of all required passes.
700 SmallVector<Pass *, 12> LastUses;
701 SmallVector<Pass *, 8> RequiredPasses;
702 SmallVector<AnalysisID, 8> ReqAnalysisNotAvailable;
704 unsigned PDepth = this->getDepth();
706 collectRequiredAnalysis(RequiredPasses,
707 ReqAnalysisNotAvailable, P);
708 for (SmallVector<Pass *, 8>::iterator I = RequiredPasses.begin(),
709 E = RequiredPasses.end(); I != E; ++I) {
710 Pass *PRequired = *I;
713 PMDataManager &DM = PRequired->getResolver()->getPMDataManager();
714 RDepth = DM.getDepth();
716 if (PDepth == RDepth)
717 LastUses.push_back(PRequired);
718 else if (PDepth > RDepth) {
719 // Let the parent claim responsibility of last use
720 TransferLastUses.push_back(PRequired);
721 // Keep track of higher level analysis used by this manager.
722 HigherLevelAnalysis.push_back(PRequired);
724 assert (0 && "Unable to accomodate Required Pass");
727 // Set P as P's last user until someone starts using P.
728 // However, if P is a Pass Manager then it does not need
729 // to record its last user.
730 if (!dynamic_cast<PMDataManager *>(P))
731 LastUses.push_back(P);
732 TPM->setLastUser(LastUses, P);
734 if (!TransferLastUses.empty()) {
735 Pass *My_PM = dynamic_cast<Pass *>(this);
736 TPM->setLastUser(TransferLastUses, My_PM);
737 TransferLastUses.clear();
740 // Now, take care of required analysises that are not available.
741 for (SmallVector<AnalysisID, 8>::iterator
742 I = ReqAnalysisNotAvailable.begin(),
743 E = ReqAnalysisNotAvailable.end() ;I != E; ++I) {
744 Pass *AnalysisPass = (*I)->createPass();
745 this->addLowerLevelRequiredPass(P, AnalysisPass);
748 // Take a note of analysis required and made available by this pass.
749 // Remove the analysis not preserved by this pass
750 removeNotPreservedAnalysis(P);
751 recordAvailableAnalysis(P);
755 PassVector.push_back(P);
759 /// Populate RP with analysis pass that are required by
760 /// pass P and are available. Populate RP_NotAvail with analysis
761 /// pass that are required by pass P but are not available.
762 void PMDataManager::collectRequiredAnalysis(SmallVector<Pass *, 8>&RP,
763 SmallVector<AnalysisID, 8> &RP_NotAvail,
765 AnalysisUsage AnUsage;
766 P->getAnalysisUsage(AnUsage);
767 const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet();
768 for (std::vector<AnalysisID>::const_iterator
769 I = RequiredSet.begin(), E = RequiredSet.end();
772 if (Pass *AnalysisPass = findAnalysisPass(*I, true))
773 RP.push_back(AnalysisPass);
775 RP_NotAvail.push_back(AID);
778 const std::vector<AnalysisID> &IDs = AnUsage.getRequiredTransitiveSet();
779 for (std::vector<AnalysisID>::const_iterator I = IDs.begin(),
780 E = IDs.end(); I != E; ++I) {
782 if (Pass *AnalysisPass = findAnalysisPass(*I, true))
783 RP.push_back(AnalysisPass);
785 RP_NotAvail.push_back(AID);
789 // All Required analyses should be available to the pass as it runs! Here
790 // we fill in the AnalysisImpls member of the pass so that it can
791 // successfully use the getAnalysis() method to retrieve the
792 // implementations it needs.
794 void PMDataManager::initializeAnalysisImpl(Pass *P) {
795 AnalysisUsage AnUsage;
796 P->getAnalysisUsage(AnUsage);
798 for (std::vector<const PassInfo *>::const_iterator
799 I = AnUsage.getRequiredSet().begin(),
800 E = AnUsage.getRequiredSet().end(); I != E; ++I) {
801 Pass *Impl = findAnalysisPass(*I, true);
803 // This may be analysis pass that is initialized on the fly.
804 // If that is not the case then it will raise an assert when it is used.
806 AnalysisResolver *AR = P->getResolver();
807 AR->addAnalysisImplsPair(*I, Impl);
811 /// Find the pass that implements Analysis AID. If desired pass is not found
812 /// then return NULL.
813 Pass *PMDataManager::findAnalysisPass(AnalysisID AID, bool SearchParent) {
815 // Check if AvailableAnalysis map has one entry.
816 std::map<AnalysisID, Pass*>::const_iterator I = AvailableAnalysis.find(AID);
818 if (I != AvailableAnalysis.end())
821 // Search Parents through TopLevelManager
823 return TPM->findAnalysisPass(AID);
828 // Print list of passes that are last used by P.
829 void PMDataManager::dumpLastUses(Pass *P, unsigned Offset) const{
831 SmallVector<Pass *, 12> LUses;
833 // If this is a on the fly manager then it does not have TPM.
837 TPM->collectLastUses(LUses, P);
839 for (SmallVector<Pass *, 12>::iterator I = LUses.begin(),
840 E = LUses.end(); I != E; ++I) {
841 llvm::cerr << "--" << std::string(Offset*2, ' ');
842 (*I)->dumpPassStructure(0);
846 void PMDataManager::dumpPassArguments() const {
847 for(std::vector<Pass *>::const_iterator I = PassVector.begin(),
848 E = PassVector.end(); I != E; ++I) {
849 if (PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I))
850 PMD->dumpPassArguments();
852 if (const PassInfo *PI = (*I)->getPassInfo())
853 if (!PI->isAnalysisGroup())
854 cerr << " -" << PI->getPassArgument();
858 void PMDataManager::dumpPassInfo(Pass *P, enum PassDebuggingString S1,
859 enum PassDebuggingString S2,
861 if (PassDebugging < Executions)
863 cerr << (void*)this << std::string(getDepth()*2+1, ' ');
866 cerr << "Executing Pass '" << P->getPassName();
868 case MODIFICATION_MSG:
869 cerr << "Made Modification '" << P->getPassName();
872 cerr << " Freeing Pass '" << P->getPassName();
878 case ON_BASICBLOCK_MSG:
879 cerr << "' on BasicBlock '" << Msg << "'...\n";
881 case ON_FUNCTION_MSG:
882 cerr << "' on Function '" << Msg << "'...\n";
885 cerr << "' on Module '" << Msg << "'...\n";
888 cerr << "' on Loop " << Msg << "'...\n";
891 cerr << "' on Call Graph " << Msg << "'...\n";
898 void PMDataManager::dumpAnalysisSetInfo(const char *Msg, Pass *P,
899 const std::vector<AnalysisID> &Set)
901 if (PassDebugging >= Details && !Set.empty()) {
902 cerr << (void*)P << std::string(getDepth()*2+3, ' ') << Msg << " Analyses:";
903 for (unsigned i = 0; i != Set.size(); ++i) {
905 cerr << " " << Set[i]->getPassName();
911 /// Add RequiredPass into list of lower level passes required by pass P.
912 /// RequiredPass is run on the fly by Pass Manager when P requests it
913 /// through getAnalysis interface.
914 /// This should be handled by specific pass manager.
915 void PMDataManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
917 TPM->dumpArguments();
920 assert (0 && "Unable to handle Pass that requires lower level Analysis pass");
924 PMDataManager::~PMDataManager() {
926 for (std::vector<Pass *>::iterator I = PassVector.begin(),
927 E = PassVector.end(); I != E; ++I)
933 //===----------------------------------------------------------------------===//
934 // NOTE: Is this the right place to define this method ?
935 // getAnalysisToUpdate - Return an analysis result or null if it doesn't exist
936 Pass *AnalysisResolver::getAnalysisToUpdate(AnalysisID ID, bool dir) const {
937 return PM.findAnalysisPass(ID, dir);
940 Pass *AnalysisResolver::findImplPass(Pass *P, const PassInfo *AnalysisPI,
942 return PM.getOnTheFlyPass(P, AnalysisPI, F);
945 //===----------------------------------------------------------------------===//
946 // BBPassManager implementation
948 /// Execute all of the passes scheduled for execution by invoking
949 /// runOnBasicBlock method. Keep track of whether any of the passes modifies
950 /// the function, and if so, return true.
952 BBPassManager::runOnFunction(Function &F) {
954 if (F.isDeclaration())
957 bool Changed = doInitialization(F);
959 for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
960 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
961 BasicBlockPass *BP = getContainedPass(Index);
962 AnalysisUsage AnUsage;
963 BP->getAnalysisUsage(AnUsage);
965 dumpPassInfo(BP, EXECUTION_MSG, ON_BASICBLOCK_MSG, I->getNameStart());
966 dumpAnalysisSetInfo("Required", BP, AnUsage.getRequiredSet());
968 initializeAnalysisImpl(BP);
970 if (TheTimeInfo) TheTimeInfo->passStarted(BP);
971 Changed |= BP->runOnBasicBlock(*I);
972 if (TheTimeInfo) TheTimeInfo->passEnded(BP);
975 dumpPassInfo(BP, MODIFICATION_MSG, ON_BASICBLOCK_MSG, I->getNameStart());
976 dumpAnalysisSetInfo("Preserved", BP, AnUsage.getPreservedSet());
978 verifyPreservedAnalysis(BP);
979 removeNotPreservedAnalysis(BP);
980 recordAvailableAnalysis(BP);
981 removeDeadPasses(BP, I->getNameStart(), ON_BASICBLOCK_MSG);
984 return Changed |= doFinalization(F);
987 // Implement doInitialization and doFinalization
988 inline bool BBPassManager::doInitialization(Module &M) {
989 bool Changed = false;
991 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
992 BasicBlockPass *BP = getContainedPass(Index);
993 Changed |= BP->doInitialization(M);
999 inline bool BBPassManager::doFinalization(Module &M) {
1000 bool Changed = false;
1002 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1003 BasicBlockPass *BP = getContainedPass(Index);
1004 Changed |= BP->doFinalization(M);
1010 inline bool BBPassManager::doInitialization(Function &F) {
1011 bool Changed = false;
1013 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1014 BasicBlockPass *BP = getContainedPass(Index);
1015 Changed |= BP->doInitialization(F);
1021 inline bool BBPassManager::doFinalization(Function &F) {
1022 bool Changed = false;
1024 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1025 BasicBlockPass *BP = getContainedPass(Index);
1026 Changed |= BP->doFinalization(F);
1033 //===----------------------------------------------------------------------===//
1034 // FunctionPassManager implementation
1036 /// Create new Function pass manager
1037 FunctionPassManager::FunctionPassManager(ModuleProvider *P) {
1038 FPM = new FunctionPassManagerImpl(0);
1039 // FPM is the top level manager.
1040 FPM->setTopLevelManager(FPM);
1042 PMDataManager *PMD = dynamic_cast<PMDataManager *>(FPM);
1043 AnalysisResolver *AR = new AnalysisResolver(*PMD);
1044 FPM->setResolver(AR);
1049 FunctionPassManager::~FunctionPassManager() {
1053 /// add - Add a pass to the queue of passes to run. This passes
1054 /// ownership of the Pass to the PassManager. When the
1055 /// PassManager_X is destroyed, the pass will be destroyed as well, so
1056 /// there is no need to delete the pass. (TODO delete passes.)
1057 /// This implies that all passes MUST be allocated with 'new'.
1058 void FunctionPassManager::add(Pass *P) {
1062 /// run - Execute all of the passes scheduled for execution. Keep
1063 /// track of whether any of the passes modifies the function, and if
1064 /// so, return true.
1066 bool FunctionPassManager::run(Function &F) {
1068 if (MP->materializeFunction(&F, &errstr)) {
1069 cerr << "Error reading bitcode file: " << errstr << "\n";
1076 /// doInitialization - Run all of the initializers for the function passes.
1078 bool FunctionPassManager::doInitialization() {
1079 return FPM->doInitialization(*MP->getModule());
1082 /// doFinalization - Run all of the finalizers for the function passes.
1084 bool FunctionPassManager::doFinalization() {
1085 return FPM->doFinalization(*MP->getModule());
1088 //===----------------------------------------------------------------------===//
1089 // FunctionPassManagerImpl implementation
1091 inline bool FunctionPassManagerImpl::doInitialization(Module &M) {
1092 bool Changed = false;
1094 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
1095 FPPassManager *FP = getContainedManager(Index);
1096 Changed |= FP->doInitialization(M);
1102 inline bool FunctionPassManagerImpl::doFinalization(Module &M) {
1103 bool Changed = false;
1105 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
1106 FPPassManager *FP = getContainedManager(Index);
1107 Changed |= FP->doFinalization(M);
1113 // Execute all the passes managed by this top level manager.
1114 // Return true if any function is modified by a pass.
1115 bool FunctionPassManagerImpl::run(Function &F) {
1117 bool Changed = false;
1119 TimingInfo::createTheTimeInfo();
1124 initializeAllAnalysisInfo();
1125 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
1126 FPPassManager *FP = getContainedManager(Index);
1127 Changed |= FP->runOnFunction(F);
1132 //===----------------------------------------------------------------------===//
1133 // FPPassManager implementation
1135 char FPPassManager::ID = 0;
1136 /// Print passes managed by this manager
1137 void FPPassManager::dumpPassStructure(unsigned Offset) {
1138 llvm::cerr << std::string(Offset*2, ' ') << "FunctionPass Manager\n";
1139 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1140 FunctionPass *FP = getContainedPass(Index);
1141 FP->dumpPassStructure(Offset + 1);
1142 dumpLastUses(FP, Offset+1);
1147 /// Execute all of the passes scheduled for execution by invoking
1148 /// runOnFunction method. Keep track of whether any of the passes modifies
1149 /// the function, and if so, return true.
1150 bool FPPassManager::runOnFunction(Function &F) {
1152 bool Changed = false;
1154 if (F.isDeclaration())
1157 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1158 FunctionPass *FP = getContainedPass(Index);
1160 AnalysisUsage AnUsage;
1161 FP->getAnalysisUsage(AnUsage);
1163 dumpPassInfo(FP, EXECUTION_MSG, ON_FUNCTION_MSG, F.getNameStart());
1164 dumpAnalysisSetInfo("Required", FP, AnUsage.getRequiredSet());
1166 initializeAnalysisImpl(FP);
1168 if (TheTimeInfo) TheTimeInfo->passStarted(FP);
1169 Changed |= FP->runOnFunction(F);
1170 if (TheTimeInfo) TheTimeInfo->passEnded(FP);
1173 dumpPassInfo(FP, MODIFICATION_MSG, ON_FUNCTION_MSG, F.getNameStart());
1174 dumpAnalysisSetInfo("Preserved", FP, AnUsage.getPreservedSet());
1176 verifyPreservedAnalysis(FP);
1177 removeNotPreservedAnalysis(FP);
1178 recordAvailableAnalysis(FP);
1179 removeDeadPasses(FP, F.getNameStart(), ON_FUNCTION_MSG);
1184 bool FPPassManager::runOnModule(Module &M) {
1186 bool Changed = doInitialization(M);
1188 for(Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
1189 this->runOnFunction(*I);
1191 return Changed |= doFinalization(M);
1194 inline bool FPPassManager::doInitialization(Module &M) {
1195 bool Changed = false;
1197 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1198 FunctionPass *FP = getContainedPass(Index);
1199 Changed |= FP->doInitialization(M);
1205 inline bool FPPassManager::doFinalization(Module &M) {
1206 bool Changed = false;
1208 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1209 FunctionPass *FP = getContainedPass(Index);
1210 Changed |= FP->doFinalization(M);
1216 //===----------------------------------------------------------------------===//
1217 // MPPassManager implementation
1219 /// Execute all of the passes scheduled for execution by invoking
1220 /// runOnModule method. Keep track of whether any of the passes modifies
1221 /// the module, and if so, return true.
1223 MPPassManager::runOnModule(Module &M) {
1224 bool Changed = false;
1226 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1227 ModulePass *MP = getContainedPass(Index);
1229 AnalysisUsage AnUsage;
1230 MP->getAnalysisUsage(AnUsage);
1232 dumpPassInfo(MP, EXECUTION_MSG, ON_MODULE_MSG, M.getModuleIdentifier().c_str());
1233 dumpAnalysisSetInfo("Required", MP, AnUsage.getRequiredSet());
1235 initializeAnalysisImpl(MP);
1237 if (TheTimeInfo) TheTimeInfo->passStarted(MP);
1238 Changed |= MP->runOnModule(M);
1239 if (TheTimeInfo) TheTimeInfo->passEnded(MP);
1242 dumpPassInfo(MP, MODIFICATION_MSG, ON_MODULE_MSG, M.getModuleIdentifier().c_str());
1243 dumpAnalysisSetInfo("Preserved", MP, AnUsage.getPreservedSet());
1245 verifyPreservedAnalysis(MP);
1246 removeNotPreservedAnalysis(MP);
1247 recordAvailableAnalysis(MP);
1248 removeDeadPasses(MP, M.getModuleIdentifier().c_str(), ON_MODULE_MSG);
1253 /// Add RequiredPass into list of lower level passes required by pass P.
1254 /// RequiredPass is run on the fly by Pass Manager when P requests it
1255 /// through getAnalysis interface.
1256 void MPPassManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
1258 assert (P->getPotentialPassManagerType() == PMT_ModulePassManager
1259 && "Unable to handle Pass that requires lower level Analysis pass");
1260 assert ((P->getPotentialPassManagerType() <
1261 RequiredPass->getPotentialPassManagerType())
1262 && "Unable to handle Pass that requires lower level Analysis pass");
1264 FunctionPassManagerImpl *FPP = OnTheFlyManagers[P];
1266 FPP = new FunctionPassManagerImpl(0);
1267 // FPP is the top level manager.
1268 FPP->setTopLevelManager(FPP);
1270 OnTheFlyManagers[P] = FPP;
1272 FPP->add(RequiredPass);
1274 // Register P as the last user of RequiredPass.
1275 SmallVector<Pass *, 12> LU;
1276 LU.push_back(RequiredPass);
1277 FPP->setLastUser(LU, P);
1280 /// Return function pass corresponding to PassInfo PI, that is
1281 /// required by module pass MP. Instantiate analysis pass, by using
1282 /// its runOnFunction() for function F.
1283 Pass* MPPassManager::getOnTheFlyPass(Pass *MP, const PassInfo *PI,
1285 AnalysisID AID = PI;
1286 FunctionPassManagerImpl *FPP = OnTheFlyManagers[MP];
1287 assert (FPP && "Unable to find on the fly pass");
1290 return (dynamic_cast<PMTopLevelManager *>(FPP))->findAnalysisPass(AID);
1294 //===----------------------------------------------------------------------===//
1295 // PassManagerImpl implementation
1297 /// run - Execute all of the passes scheduled for execution. Keep track of
1298 /// whether any of the passes modifies the module, and if so, return true.
1299 bool PassManagerImpl::run(Module &M) {
1301 bool Changed = false;
1303 TimingInfo::createTheTimeInfo();
1308 initializeAllAnalysisInfo();
1309 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
1310 MPPassManager *MP = getContainedManager(Index);
1311 Changed |= MP->runOnModule(M);
1316 //===----------------------------------------------------------------------===//
1317 // PassManager implementation
1319 /// Create new pass manager
1320 PassManager::PassManager() {
1321 PM = new PassManagerImpl(0);
1322 // PM is the top level manager
1323 PM->setTopLevelManager(PM);
1326 PassManager::~PassManager() {
1330 /// add - Add a pass to the queue of passes to run. This passes ownership of
1331 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
1332 /// will be destroyed as well, so there is no need to delete the pass. This
1333 /// implies that all passes MUST be allocated with 'new'.
1335 PassManager::add(Pass *P) {
1339 /// run - Execute all of the passes scheduled for execution. Keep track of
1340 /// whether any of the passes modifies the module, and if so, return true.
1342 PassManager::run(Module &M) {
1346 //===----------------------------------------------------------------------===//
1347 // TimingInfo Class - This class is used to calculate information about the
1348 // amount of time each pass takes to execute. This only happens with
1349 // -time-passes is enabled on the command line.
1351 bool llvm::TimePassesIsEnabled = false;
1352 static cl::opt<bool,true>
1353 EnableTiming("time-passes", cl::location(TimePassesIsEnabled),
1354 cl::desc("Time each pass, printing elapsed time for each on exit"));
1356 // createTheTimeInfo - This method either initializes the TheTimeInfo pointer to
1357 // a non null value (if the -time-passes option is enabled) or it leaves it
1358 // null. It may be called multiple times.
1359 void TimingInfo::createTheTimeInfo() {
1360 if (!TimePassesIsEnabled || TheTimeInfo) return;
1362 // Constructed the first time this is called, iff -time-passes is enabled.
1363 // This guarantees that the object will be constructed before static globals,
1364 // thus it will be destroyed before them.
1365 static ManagedStatic<TimingInfo> TTI;
1366 TheTimeInfo = &*TTI;
1369 /// If TimingInfo is enabled then start pass timer.
1370 void StartPassTimer(Pass *P) {
1372 TheTimeInfo->passStarted(P);
1375 /// If TimingInfo is enabled then stop pass timer.
1376 void StopPassTimer(Pass *P) {
1378 TheTimeInfo->passEnded(P);
1381 //===----------------------------------------------------------------------===//
1382 // PMStack implementation
1385 // Pop Pass Manager from the stack and clear its analysis info.
1386 void PMStack::pop() {
1388 PMDataManager *Top = this->top();
1389 Top->initializeAnalysisInfo();
1394 // Push PM on the stack and set its top level manager.
1395 void PMStack::push(Pass *P) {
1397 PMDataManager *Top = NULL;
1398 PMDataManager *PM = dynamic_cast<PMDataManager *>(P);
1399 assert (PM && "Unable to push. Pass Manager expected");
1401 if (this->empty()) {
1406 PMTopLevelManager *TPM = Top->getTopLevelManager();
1408 assert (TPM && "Unable to find top level manager");
1409 TPM->addIndirectPassManager(PM);
1410 PM->setTopLevelManager(TPM);
1416 // Dump content of the pass manager stack.
1417 void PMStack::dump() {
1418 for(std::deque<PMDataManager *>::iterator I = S.begin(),
1419 E = S.end(); I != E; ++I) {
1420 Pass *P = dynamic_cast<Pass *>(*I);
1421 printf("%s ", P->getPassName());
1427 /// Find appropriate Module Pass Manager in the PM Stack and
1428 /// add self into that manager.
1429 void ModulePass::assignPassManager(PMStack &PMS,
1430 PassManagerType PreferredType) {
1432 // Find Module Pass Manager
1433 while(!PMS.empty()) {
1434 PassManagerType TopPMType = PMS.top()->getPassManagerType();
1435 if (TopPMType == PreferredType)
1436 break; // We found desired pass manager
1437 else if (TopPMType > PMT_ModulePassManager)
1438 PMS.pop(); // Pop children pass managers
1443 PMS.top()->add(this);
1446 /// Find appropriate Function Pass Manager or Call Graph Pass Manager
1447 /// in the PM Stack and add self into that manager.
1448 void FunctionPass::assignPassManager(PMStack &PMS,
1449 PassManagerType PreferredType) {
1451 // Find Module Pass Manager (TODO : Or Call Graph Pass Manager)
1452 while(!PMS.empty()) {
1453 if (PMS.top()->getPassManagerType() > PMT_FunctionPassManager)
1458 FPPassManager *FPP = dynamic_cast<FPPassManager *>(PMS.top());
1460 // Create new Function Pass Manager
1462 assert(!PMS.empty() && "Unable to create Function Pass Manager");
1463 PMDataManager *PMD = PMS.top();
1465 // [1] Create new Function Pass Manager
1466 FPP = new FPPassManager(PMD->getDepth() + 1);
1468 // [2] Set up new manager's top level manager
1469 PMTopLevelManager *TPM = PMD->getTopLevelManager();
1470 TPM->addIndirectPassManager(FPP);
1472 // [3] Assign manager to manage this new manager. This may create
1473 // and push new managers into PMS
1474 Pass *P = dynamic_cast<Pass *>(FPP);
1476 // If Call Graph Pass Manager is active then use it to manage
1477 // this new Function Pass manager.
1478 if (PMD->getPassManagerType() == PMT_CallGraphPassManager)
1479 P->assignPassManager(PMS, PMT_CallGraphPassManager);
1481 P->assignPassManager(PMS);
1483 // [4] Push new manager into PMS
1487 // Assign FPP as the manager of this pass.
1491 /// Find appropriate Basic Pass Manager or Call Graph Pass Manager
1492 /// in the PM Stack and add self into that manager.
1493 void BasicBlockPass::assignPassManager(PMStack &PMS,
1494 PassManagerType PreferredType) {
1496 BBPassManager *BBP = NULL;
1498 // Basic Pass Manager is a leaf pass manager. It does not handle
1499 // any other pass manager.
1501 BBP = dynamic_cast<BBPassManager *>(PMS.top());
1503 // If leaf manager is not Basic Block Pass manager then create new
1504 // basic Block Pass manager.
1507 assert(!PMS.empty() && "Unable to create BasicBlock Pass Manager");
1508 PMDataManager *PMD = PMS.top();
1510 // [1] Create new Basic Block Manager
1511 BBP = new BBPassManager(PMD->getDepth() + 1);
1513 // [2] Set up new manager's top level manager
1514 // Basic Block Pass Manager does not live by itself
1515 PMTopLevelManager *TPM = PMD->getTopLevelManager();
1516 TPM->addIndirectPassManager(BBP);
1518 // [3] Assign manager to manage this new manager. This may create
1519 // and push new managers into PMS
1520 Pass *P = dynamic_cast<Pass *>(BBP);
1521 P->assignPassManager(PMS);
1523 // [4] Push new manager into PMS
1527 // Assign BBP as the manager of this pass.