1 //===- PassManager.cpp - LLVM Pass Infrastructure Implementation ----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // 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 explicit 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 explicit 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 explicit MPPassManager(int Depth) :
189 Pass((intptr_t)&ID), PMDataManager(Depth) { }
191 // Delete on the fly managers.
192 virtual ~MPPassManager() {
193 for (std::map<Pass *, FunctionPassManagerImpl *>::iterator
194 I = OnTheFlyManagers.begin(), E = OnTheFlyManagers.end();
196 FunctionPassManagerImpl *FPP = I->second;
201 /// run - Execute all of the passes scheduled for execution. Keep track of
202 /// whether any of the passes modifies the module, and if so, return true.
203 bool runOnModule(Module &M);
205 /// Pass Manager itself does not invalidate any analysis info.
206 void getAnalysisUsage(AnalysisUsage &Info) const {
207 Info.setPreservesAll();
210 /// Add RequiredPass into list of lower level passes required by pass P.
211 /// RequiredPass is run on the fly by Pass Manager when P requests it
212 /// through getAnalysis interface.
213 virtual void addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass);
215 /// Return function pass corresponding to PassInfo PI, that is
216 /// required by module pass MP. Instantiate analysis pass, by using
217 /// its runOnFunction() for function F.
218 virtual Pass* getOnTheFlyPass(Pass *MP, const PassInfo *PI, Function &F);
220 virtual const char *getPassName() const {
221 return "Module Pass Manager";
224 // Print passes managed by this manager
225 void dumpPassStructure(unsigned Offset) {
226 llvm::cerr << std::string(Offset*2, ' ') << "ModulePass Manager\n";
227 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
228 ModulePass *MP = getContainedPass(Index);
229 MP->dumpPassStructure(Offset + 1);
230 if (FunctionPassManagerImpl *FPP = OnTheFlyManagers[MP])
231 FPP->dumpPassStructure(Offset + 2);
232 dumpLastUses(MP, Offset+1);
236 ModulePass *getContainedPass(unsigned N) {
237 assert ( N < PassVector.size() && "Pass number out of range!");
238 ModulePass *MP = static_cast<ModulePass *>(PassVector[N]);
242 virtual PassManagerType getPassManagerType() const {
243 return PMT_ModulePassManager;
247 /// Collection of on the fly FPPassManagers. These managers manage
248 /// function passes that are required by module passes.
249 std::map<Pass *, FunctionPassManagerImpl *> OnTheFlyManagers;
252 char MPPassManager::ID = 0;
253 //===----------------------------------------------------------------------===//
257 /// PassManagerImpl manages MPPassManagers
258 class PassManagerImpl : public Pass,
259 public PMDataManager,
260 public PMTopLevelManager {
264 explicit PassManagerImpl(int Depth) :
265 Pass((intptr_t)&ID), PMDataManager(Depth),
266 PMTopLevelManager(TLM_Pass) { }
268 /// add - Add a pass to the queue of passes to run. This passes ownership of
269 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
270 /// will be destroyed as well, so there is no need to delete the pass. This
271 /// implies that all passes MUST be allocated with 'new'.
276 /// run - Execute all of the passes scheduled for execution. Keep track of
277 /// whether any of the passes modifies the module, and if so, return true.
280 /// Pass Manager itself does not invalidate any analysis info.
281 void getAnalysisUsage(AnalysisUsage &Info) const {
282 Info.setPreservesAll();
285 inline void addTopLevelPass(Pass *P) {
287 if (ImmutablePass *IP = dynamic_cast<ImmutablePass *> (P)) {
289 // P is a immutable pass and it will be managed by this
290 // top level manager. Set up analysis resolver to connect them.
291 AnalysisResolver *AR = new AnalysisResolver(*this);
293 initializeAnalysisImpl(P);
294 addImmutablePass(IP);
295 recordAvailableAnalysis(IP);
297 P->assignPassManager(activeStack);
302 MPPassManager *getContainedManager(unsigned N) {
303 assert ( N < PassManagers.size() && "Pass number out of range!");
304 MPPassManager *MP = static_cast<MPPassManager *>(PassManagers[N]);
310 char PassManagerImpl::ID = 0;
311 } // End of llvm namespace
315 //===----------------------------------------------------------------------===//
316 // TimingInfo Class - This class is used to calculate information about the
317 // amount of time each pass takes to execute. This only happens when
318 // -time-passes is enabled on the command line.
321 class VISIBILITY_HIDDEN TimingInfo {
322 std::map<Pass*, Timer> TimingData;
326 // Use 'create' member to get this.
327 TimingInfo() : TG("... Pass execution timing report ...") {}
329 // TimingDtor - Print out information about timing information
331 // Delete all of the timers...
333 // TimerGroup is deleted next, printing the report.
336 // createTheTimeInfo - This method either initializes the TheTimeInfo pointer
337 // to a non null value (if the -time-passes option is enabled) or it leaves it
338 // null. It may be called multiple times.
339 static void createTheTimeInfo();
341 void passStarted(Pass *P) {
343 if (dynamic_cast<PMDataManager *>(P))
346 std::map<Pass*, Timer>::iterator I = TimingData.find(P);
347 if (I == TimingData.end())
348 I=TimingData.insert(std::make_pair(P, Timer(P->getPassName(), TG))).first;
349 I->second.startTimer();
351 void passEnded(Pass *P) {
353 if (dynamic_cast<PMDataManager *>(P))
356 std::map<Pass*, Timer>::iterator I = TimingData.find(P);
357 assert (I != TimingData.end() && "passStarted/passEnded not nested right!");
358 I->second.stopTimer();
362 static TimingInfo *TheTimeInfo;
364 } // End of anon namespace
366 //===----------------------------------------------------------------------===//
367 // PMTopLevelManager implementation
369 /// Initialize top level manager. Create first pass manager.
370 PMTopLevelManager::PMTopLevelManager (enum TopLevelManagerType t) {
373 MPPassManager *MPP = new MPPassManager(1);
374 MPP->setTopLevelManager(this);
376 activeStack.push(MPP);
378 else if (t == TLM_Function) {
379 FPPassManager *FPP = new FPPassManager(1);
380 FPP->setTopLevelManager(this);
382 activeStack.push(FPP);
386 /// Set pass P as the last user of the given analysis passes.
387 void PMTopLevelManager::setLastUser(SmallVector<Pass *, 12> &AnalysisPasses,
390 for (SmallVector<Pass *, 12>::iterator I = AnalysisPasses.begin(),
391 E = AnalysisPasses.end(); I != E; ++I) {
398 // If AP is the last user of other passes then make P last user of
400 for (std::map<Pass *, Pass *>::iterator LUI = LastUser.begin(),
401 LUE = LastUser.end(); LUI != LUE; ++LUI) {
402 if (LUI->second == AP)
403 LastUser[LUI->first] = P;
408 /// Collect passes whose last user is P
409 void PMTopLevelManager::collectLastUses(SmallVector<Pass *, 12> &LastUses,
411 for (std::map<Pass *, Pass *>::iterator LUI = LastUser.begin(),
412 LUE = LastUser.end(); LUI != LUE; ++LUI)
413 if (LUI->second == P)
414 LastUses.push_back(LUI->first);
417 /// Schedule pass P for execution. Make sure that passes required by
418 /// P are run before P is run. Update analysis info maintained by
419 /// the manager. Remove dead passes. This is a recursive function.
420 void PMTopLevelManager::schedulePass(Pass *P) {
422 // TODO : Allocate function manager for this pass, other wise required set
423 // may be inserted into previous function manager
425 // Give pass a chance to prepare the stage.
426 P->preparePassManager(activeStack);
428 AnalysisUsage AnUsage;
429 P->getAnalysisUsage(AnUsage);
430 const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet();
431 for (std::vector<AnalysisID>::const_iterator I = RequiredSet.begin(),
432 E = RequiredSet.end(); I != E; ++I) {
434 Pass *AnalysisPass = findAnalysisPass(*I);
436 AnalysisPass = (*I)->createPass();
437 // Schedule this analysis run first only if it is not a lower level
438 // analysis pass. Lower level analsyis passes are run on the fly.
439 if (P->getPotentialPassManagerType () >=
440 AnalysisPass->getPotentialPassManagerType())
441 schedulePass(AnalysisPass);
447 // Now all required passes are available.
451 /// Find the pass that implements Analysis AID. Search immutable
452 /// passes and all pass managers. If desired pass is not found
453 /// then return NULL.
454 Pass *PMTopLevelManager::findAnalysisPass(AnalysisID AID) {
457 // Check pass managers
458 for (std::vector<Pass *>::iterator I = PassManagers.begin(),
459 E = PassManagers.end(); P == NULL && I != E; ++I) {
460 PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I);
461 assert(PMD && "This is not a PassManager");
462 P = PMD->findAnalysisPass(AID, false);
465 // Check other pass managers
466 for (std::vector<PMDataManager *>::iterator I = IndirectPassManagers.begin(),
467 E = IndirectPassManagers.end(); P == NULL && I != E; ++I)
468 P = (*I)->findAnalysisPass(AID, false);
470 for (std::vector<ImmutablePass *>::iterator I = ImmutablePasses.begin(),
471 E = ImmutablePasses.end(); P == NULL && I != E; ++I) {
472 const PassInfo *PI = (*I)->getPassInfo();
476 // If Pass not found then check the interfaces implemented by Immutable Pass
478 const std::vector<const PassInfo*> &ImmPI =
479 PI->getInterfacesImplemented();
480 if (std::find(ImmPI.begin(), ImmPI.end(), AID) != ImmPI.end())
488 // Print passes managed by this top level manager.
489 void PMTopLevelManager::dumpPasses() const {
491 if (PassDebugging < Structure)
494 // Print out the immutable passes
495 for (unsigned i = 0, e = ImmutablePasses.size(); i != e; ++i) {
496 ImmutablePasses[i]->dumpPassStructure(0);
499 for (std::vector<Pass *>::const_iterator I = PassManagers.begin(),
500 E = PassManagers.end(); I != E; ++I)
501 (*I)->dumpPassStructure(1);
504 void PMTopLevelManager::dumpArguments() const {
506 if (PassDebugging < Arguments)
509 cerr << "Pass Arguments: ";
510 for (std::vector<Pass *>::const_iterator I = PassManagers.begin(),
511 E = PassManagers.end(); I != E; ++I) {
512 PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I);
513 assert(PMD && "This is not a PassManager");
514 PMD->dumpPassArguments();
519 void PMTopLevelManager::initializeAllAnalysisInfo() {
521 for (std::vector<Pass *>::iterator I = PassManagers.begin(),
522 E = PassManagers.end(); I != E; ++I) {
523 PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I);
524 assert(PMD && "This is not a PassManager");
525 PMD->initializeAnalysisInfo();
528 // Initailize other pass managers
529 for (std::vector<PMDataManager *>::iterator I = IndirectPassManagers.begin(),
530 E = IndirectPassManagers.end(); I != E; ++I)
531 (*I)->initializeAnalysisInfo();
535 PMTopLevelManager::~PMTopLevelManager() {
536 for (std::vector<Pass *>::iterator I = PassManagers.begin(),
537 E = PassManagers.end(); I != E; ++I)
540 for (std::vector<ImmutablePass *>::iterator
541 I = ImmutablePasses.begin(), E = ImmutablePasses.end(); I != E; ++I)
544 PassManagers.clear();
547 //===----------------------------------------------------------------------===//
548 // PMDataManager implementation
550 /// Return true IFF pass P's required analysis set does not required new
552 bool PMDataManager::manageablePass(Pass *P) {
555 // If this pass is not preserving information that is required by a
556 // pass maintained by higher level pass manager then do not insert
557 // this pass into current manager. Use new manager. For example,
558 // For example, If FunctionPass F is not preserving ModulePass Info M1
559 // that is used by another ModulePass M2 then do not insert F in
560 // current function pass manager.
564 /// Augement AvailableAnalysis by adding analysis made available by pass P.
565 void PMDataManager::recordAvailableAnalysis(Pass *P) {
567 if (const PassInfo *PI = P->getPassInfo()) {
568 AvailableAnalysis[PI] = P;
570 //This pass is the current implementation of all of the interfaces it
571 //implements as well.
572 const std::vector<const PassInfo*> &II = PI->getInterfacesImplemented();
573 for (unsigned i = 0, e = II.size(); i != e; ++i)
574 AvailableAnalysis[II[i]] = P;
578 // Return true if P preserves high level analysis used by other
579 // passes managed by this manager
580 bool PMDataManager::preserveHigherLevelAnalysis(Pass *P) {
582 AnalysisUsage AnUsage;
583 P->getAnalysisUsage(AnUsage);
585 if (AnUsage.getPreservesAll())
588 const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
589 for (std::vector<Pass *>::iterator I = HigherLevelAnalysis.begin(),
590 E = HigherLevelAnalysis.end(); I != E; ++I) {
592 if (!dynamic_cast<ImmutablePass*>(P1) &&
593 std::find(PreservedSet.begin(), PreservedSet.end(),
594 P1->getPassInfo()) ==
602 /// verifyPreservedAnalysis -- Verify analysis presreved by pass P.
603 void PMDataManager::verifyPreservedAnalysis(Pass *P) {
604 AnalysisUsage AnUsage;
605 P->getAnalysisUsage(AnUsage);
606 const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
608 // Verify preserved analysis
609 for (std::vector<AnalysisID>::const_iterator I = PreservedSet.begin(),
610 E = PreservedSet.end(); I != E; ++I) {
612 Pass *AP = findAnalysisPass(AID, true);
614 AP->verifyAnalysis();
618 /// Remove Analyss not preserved by Pass P
619 void PMDataManager::removeNotPreservedAnalysis(Pass *P) {
620 AnalysisUsage AnUsage;
621 P->getAnalysisUsage(AnUsage);
622 if (AnUsage.getPreservesAll())
625 const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
626 for (std::map<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(),
627 E = AvailableAnalysis.end(); I != E; ) {
628 std::map<AnalysisID, Pass*>::iterator Info = I++;
629 if (!dynamic_cast<ImmutablePass*>(Info->second)
630 && std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) ==
632 // Remove this analysis
633 AvailableAnalysis.erase(Info);
636 // Check inherited analysis also. If P is not preserving analysis
637 // provided by parent manager then remove it here.
638 for (unsigned Index = 0; Index < PMT_Last; ++Index) {
640 if (!InheritedAnalysis[Index])
643 for (std::map<AnalysisID, Pass*>::iterator
644 I = InheritedAnalysis[Index]->begin(),
645 E = InheritedAnalysis[Index]->end(); I != E; ) {
646 std::map<AnalysisID, Pass *>::iterator Info = I++;
647 if (!dynamic_cast<ImmutablePass*>(Info->second) &&
648 std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) ==
650 // Remove this analysis
651 InheritedAnalysis[Index]->erase(Info);
657 /// Remove analysis passes that are not used any longer
658 void PMDataManager::removeDeadPasses(Pass *P, const char *Msg,
659 enum PassDebuggingString DBG_STR) {
661 SmallVector<Pass *, 12> DeadPasses;
663 // If this is a on the fly manager then it does not have TPM.
667 TPM->collectLastUses(DeadPasses, P);
669 for (SmallVector<Pass *, 12>::iterator I = DeadPasses.begin(),
670 E = DeadPasses.end(); I != E; ++I) {
672 dumpPassInfo(*I, FREEING_MSG, DBG_STR, Msg);
674 if (TheTimeInfo) TheTimeInfo->passStarted(*I);
675 (*I)->releaseMemory();
676 if (TheTimeInfo) TheTimeInfo->passEnded(*I);
678 std::map<AnalysisID, Pass*>::iterator Pos =
679 AvailableAnalysis.find((*I)->getPassInfo());
681 // It is possible that pass is already removed from the AvailableAnalysis
682 if (Pos != AvailableAnalysis.end())
683 AvailableAnalysis.erase(Pos);
687 /// Add pass P into the PassVector. Update
688 /// AvailableAnalysis appropriately if ProcessAnalysis is true.
689 void PMDataManager::add(Pass *P,
690 bool ProcessAnalysis) {
692 // This manager is going to manage pass P. Set up analysis resolver
694 AnalysisResolver *AR = new AnalysisResolver(*this);
697 // If a FunctionPass F is the last user of ModulePass info M
698 // then the F's manager, not F, records itself as a last user of M.
699 SmallVector<Pass *, 12> TransferLastUses;
701 if (ProcessAnalysis) {
703 // At the moment, this pass is the last user of all required passes.
704 SmallVector<Pass *, 12> LastUses;
705 SmallVector<Pass *, 8> RequiredPasses;
706 SmallVector<AnalysisID, 8> ReqAnalysisNotAvailable;
708 unsigned PDepth = this->getDepth();
710 collectRequiredAnalysis(RequiredPasses,
711 ReqAnalysisNotAvailable, P);
712 for (SmallVector<Pass *, 8>::iterator I = RequiredPasses.begin(),
713 E = RequiredPasses.end(); I != E; ++I) {
714 Pass *PRequired = *I;
717 PMDataManager &DM = PRequired->getResolver()->getPMDataManager();
718 RDepth = DM.getDepth();
720 if (PDepth == RDepth)
721 LastUses.push_back(PRequired);
722 else if (PDepth > RDepth) {
723 // Let the parent claim responsibility of last use
724 TransferLastUses.push_back(PRequired);
725 // Keep track of higher level analysis used by this manager.
726 HigherLevelAnalysis.push_back(PRequired);
728 assert (0 && "Unable to accomodate Required Pass");
731 // Set P as P's last user until someone starts using P.
732 // However, if P is a Pass Manager then it does not need
733 // to record its last user.
734 if (!dynamic_cast<PMDataManager *>(P))
735 LastUses.push_back(P);
736 TPM->setLastUser(LastUses, P);
738 if (!TransferLastUses.empty()) {
739 Pass *My_PM = dynamic_cast<Pass *>(this);
740 TPM->setLastUser(TransferLastUses, My_PM);
741 TransferLastUses.clear();
744 // Now, take care of required analysises that are not available.
745 for (SmallVector<AnalysisID, 8>::iterator
746 I = ReqAnalysisNotAvailable.begin(),
747 E = ReqAnalysisNotAvailable.end() ;I != E; ++I) {
748 Pass *AnalysisPass = (*I)->createPass();
749 this->addLowerLevelRequiredPass(P, AnalysisPass);
752 // Take a note of analysis required and made available by this pass.
753 // Remove the analysis not preserved by this pass
754 removeNotPreservedAnalysis(P);
755 recordAvailableAnalysis(P);
759 PassVector.push_back(P);
763 /// Populate RP with analysis pass that are required by
764 /// pass P and are available. Populate RP_NotAvail with analysis
765 /// pass that are required by pass P but are not available.
766 void PMDataManager::collectRequiredAnalysis(SmallVector<Pass *, 8>&RP,
767 SmallVector<AnalysisID, 8> &RP_NotAvail,
769 AnalysisUsage AnUsage;
770 P->getAnalysisUsage(AnUsage);
771 const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet();
772 for (std::vector<AnalysisID>::const_iterator
773 I = RequiredSet.begin(), E = RequiredSet.end();
776 if (Pass *AnalysisPass = findAnalysisPass(*I, true))
777 RP.push_back(AnalysisPass);
779 RP_NotAvail.push_back(AID);
782 const std::vector<AnalysisID> &IDs = AnUsage.getRequiredTransitiveSet();
783 for (std::vector<AnalysisID>::const_iterator I = IDs.begin(),
784 E = IDs.end(); I != E; ++I) {
786 if (Pass *AnalysisPass = findAnalysisPass(*I, true))
787 RP.push_back(AnalysisPass);
789 RP_NotAvail.push_back(AID);
793 // All Required analyses should be available to the pass as it runs! Here
794 // we fill in the AnalysisImpls member of the pass so that it can
795 // successfully use the getAnalysis() method to retrieve the
796 // implementations it needs.
798 void PMDataManager::initializeAnalysisImpl(Pass *P) {
799 AnalysisUsage AnUsage;
800 P->getAnalysisUsage(AnUsage);
802 for (std::vector<const PassInfo *>::const_iterator
803 I = AnUsage.getRequiredSet().begin(),
804 E = AnUsage.getRequiredSet().end(); I != E; ++I) {
805 Pass *Impl = findAnalysisPass(*I, true);
807 // This may be analysis pass that is initialized on the fly.
808 // If that is not the case then it will raise an assert when it is used.
810 AnalysisResolver *AR = P->getResolver();
811 AR->addAnalysisImplsPair(*I, Impl);
815 /// Find the pass that implements Analysis AID. If desired pass is not found
816 /// then return NULL.
817 Pass *PMDataManager::findAnalysisPass(AnalysisID AID, bool SearchParent) {
819 // Check if AvailableAnalysis map has one entry.
820 std::map<AnalysisID, Pass*>::const_iterator I = AvailableAnalysis.find(AID);
822 if (I != AvailableAnalysis.end())
825 // Search Parents through TopLevelManager
827 return TPM->findAnalysisPass(AID);
832 // Print list of passes that are last used by P.
833 void PMDataManager::dumpLastUses(Pass *P, unsigned Offset) const{
835 SmallVector<Pass *, 12> LUses;
837 // If this is a on the fly manager then it does not have TPM.
841 TPM->collectLastUses(LUses, P);
843 for (SmallVector<Pass *, 12>::iterator I = LUses.begin(),
844 E = LUses.end(); I != E; ++I) {
845 llvm::cerr << "--" << std::string(Offset*2, ' ');
846 (*I)->dumpPassStructure(0);
850 void PMDataManager::dumpPassArguments() const {
851 for(std::vector<Pass *>::const_iterator I = PassVector.begin(),
852 E = PassVector.end(); I != E; ++I) {
853 if (PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I))
854 PMD->dumpPassArguments();
856 if (const PassInfo *PI = (*I)->getPassInfo())
857 if (!PI->isAnalysisGroup())
858 cerr << " -" << PI->getPassArgument();
862 void PMDataManager::dumpPassInfo(Pass *P, enum PassDebuggingString S1,
863 enum PassDebuggingString S2,
865 if (PassDebugging < Executions)
867 cerr << (void*)this << std::string(getDepth()*2+1, ' ');
870 cerr << "Executing Pass '" << P->getPassName();
872 case MODIFICATION_MSG:
873 cerr << "Made Modification '" << P->getPassName();
876 cerr << " Freeing Pass '" << P->getPassName();
882 case ON_BASICBLOCK_MSG:
883 cerr << "' on BasicBlock '" << Msg << "'...\n";
885 case ON_FUNCTION_MSG:
886 cerr << "' on Function '" << Msg << "'...\n";
889 cerr << "' on Module '" << Msg << "'...\n";
892 cerr << "' on Loop " << Msg << "'...\n";
895 cerr << "' on Call Graph " << Msg << "'...\n";
902 void PMDataManager::dumpAnalysisSetInfo(const char *Msg, Pass *P,
903 const std::vector<AnalysisID> &Set)
905 if (PassDebugging >= Details && !Set.empty()) {
906 cerr << (void*)P << std::string(getDepth()*2+3, ' ') << Msg << " Analyses:";
907 for (unsigned i = 0; i != Set.size(); ++i) {
909 cerr << " " << Set[i]->getPassName();
915 /// Add RequiredPass into list of lower level passes required by pass P.
916 /// RequiredPass is run on the fly by Pass Manager when P requests it
917 /// through getAnalysis interface.
918 /// This should be handled by specific pass manager.
919 void PMDataManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
921 TPM->dumpArguments();
925 // Module Level pass may required Function Level analysis info
926 // (e.g. dominator info). Pass manager uses on the fly function pass manager
927 // to provide this on demand. In that case, in Pass manager terminology,
928 // module level pass is requiring lower level analysis info managed by
929 // lower level pass manager.
931 // When Pass manager is not able to order required analysis info, Pass manager
932 // checks whether any lower level manager will be able to provide this
933 // analysis info on demand or not.
934 assert (0 && "Unable to handle Pass that requires lower level Analysis pass");
938 PMDataManager::~PMDataManager() {
940 for (std::vector<Pass *>::iterator I = PassVector.begin(),
941 E = PassVector.end(); I != E; ++I)
947 //===----------------------------------------------------------------------===//
948 // NOTE: Is this the right place to define this method ?
949 // getAnalysisToUpdate - Return an analysis result or null if it doesn't exist
950 Pass *AnalysisResolver::getAnalysisToUpdate(AnalysisID ID, bool dir) const {
951 return PM.findAnalysisPass(ID, dir);
954 Pass *AnalysisResolver::findImplPass(Pass *P, const PassInfo *AnalysisPI,
956 return PM.getOnTheFlyPass(P, AnalysisPI, F);
959 //===----------------------------------------------------------------------===//
960 // BBPassManager implementation
962 /// Execute all of the passes scheduled for execution by invoking
963 /// runOnBasicBlock method. Keep track of whether any of the passes modifies
964 /// the function, and if so, return true.
966 BBPassManager::runOnFunction(Function &F) {
968 if (F.isDeclaration())
971 bool Changed = doInitialization(F);
973 for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
974 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
975 BasicBlockPass *BP = getContainedPass(Index);
976 AnalysisUsage AnUsage;
977 BP->getAnalysisUsage(AnUsage);
979 dumpPassInfo(BP, EXECUTION_MSG, ON_BASICBLOCK_MSG, I->getNameStart());
980 dumpAnalysisSetInfo("Required", BP, AnUsage.getRequiredSet());
982 initializeAnalysisImpl(BP);
984 if (TheTimeInfo) TheTimeInfo->passStarted(BP);
985 Changed |= BP->runOnBasicBlock(*I);
986 if (TheTimeInfo) TheTimeInfo->passEnded(BP);
989 dumpPassInfo(BP, MODIFICATION_MSG, ON_BASICBLOCK_MSG,
991 dumpAnalysisSetInfo("Preserved", BP, AnUsage.getPreservedSet());
993 verifyPreservedAnalysis(BP);
994 removeNotPreservedAnalysis(BP);
995 recordAvailableAnalysis(BP);
996 removeDeadPasses(BP, I->getNameStart(), ON_BASICBLOCK_MSG);
999 return Changed |= doFinalization(F);
1002 // Implement doInitialization and doFinalization
1003 inline bool BBPassManager::doInitialization(Module &M) {
1004 bool Changed = false;
1006 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1007 BasicBlockPass *BP = getContainedPass(Index);
1008 Changed |= BP->doInitialization(M);
1014 inline bool BBPassManager::doFinalization(Module &M) {
1015 bool Changed = false;
1017 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1018 BasicBlockPass *BP = getContainedPass(Index);
1019 Changed |= BP->doFinalization(M);
1025 inline bool BBPassManager::doInitialization(Function &F) {
1026 bool Changed = false;
1028 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1029 BasicBlockPass *BP = getContainedPass(Index);
1030 Changed |= BP->doInitialization(F);
1036 inline bool BBPassManager::doFinalization(Function &F) {
1037 bool Changed = false;
1039 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1040 BasicBlockPass *BP = getContainedPass(Index);
1041 Changed |= BP->doFinalization(F);
1048 //===----------------------------------------------------------------------===//
1049 // FunctionPassManager implementation
1051 /// Create new Function pass manager
1052 FunctionPassManager::FunctionPassManager(ModuleProvider *P) {
1053 FPM = new FunctionPassManagerImpl(0);
1054 // FPM is the top level manager.
1055 FPM->setTopLevelManager(FPM);
1057 PMDataManager *PMD = dynamic_cast<PMDataManager *>(FPM);
1058 AnalysisResolver *AR = new AnalysisResolver(*PMD);
1059 FPM->setResolver(AR);
1064 FunctionPassManager::~FunctionPassManager() {
1068 /// add - Add a pass to the queue of passes to run. This passes
1069 /// ownership of the Pass to the PassManager. When the
1070 /// PassManager_X is destroyed, the pass will be destroyed as well, so
1071 /// there is no need to delete the pass. (TODO delete passes.)
1072 /// This implies that all passes MUST be allocated with 'new'.
1073 void FunctionPassManager::add(Pass *P) {
1077 /// run - Execute all of the passes scheduled for execution. Keep
1078 /// track of whether any of the passes modifies the function, and if
1079 /// so, return true.
1081 bool FunctionPassManager::run(Function &F) {
1083 if (MP->materializeFunction(&F, &errstr)) {
1084 cerr << "Error reading bitcode file: " << errstr << "\n";
1091 /// doInitialization - Run all of the initializers for the function passes.
1093 bool FunctionPassManager::doInitialization() {
1094 return FPM->doInitialization(*MP->getModule());
1097 /// doFinalization - Run all of the finalizers for the function passes.
1099 bool FunctionPassManager::doFinalization() {
1100 return FPM->doFinalization(*MP->getModule());
1103 //===----------------------------------------------------------------------===//
1104 // FunctionPassManagerImpl implementation
1106 inline bool FunctionPassManagerImpl::doInitialization(Module &M) {
1107 bool Changed = false;
1109 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
1110 FPPassManager *FP = getContainedManager(Index);
1111 Changed |= FP->doInitialization(M);
1117 inline bool FunctionPassManagerImpl::doFinalization(Module &M) {
1118 bool Changed = false;
1120 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
1121 FPPassManager *FP = getContainedManager(Index);
1122 Changed |= FP->doFinalization(M);
1128 // Execute all the passes managed by this top level manager.
1129 // Return true if any function is modified by a pass.
1130 bool FunctionPassManagerImpl::run(Function &F) {
1132 bool Changed = false;
1134 TimingInfo::createTheTimeInfo();
1139 initializeAllAnalysisInfo();
1140 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
1141 FPPassManager *FP = getContainedManager(Index);
1142 Changed |= FP->runOnFunction(F);
1147 //===----------------------------------------------------------------------===//
1148 // FPPassManager implementation
1150 char FPPassManager::ID = 0;
1151 /// Print passes managed by this manager
1152 void FPPassManager::dumpPassStructure(unsigned Offset) {
1153 llvm::cerr << std::string(Offset*2, ' ') << "FunctionPass Manager\n";
1154 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1155 FunctionPass *FP = getContainedPass(Index);
1156 FP->dumpPassStructure(Offset + 1);
1157 dumpLastUses(FP, Offset+1);
1162 /// Execute all of the passes scheduled for execution by invoking
1163 /// runOnFunction method. Keep track of whether any of the passes modifies
1164 /// the function, and if so, return true.
1165 bool FPPassManager::runOnFunction(Function &F) {
1167 bool Changed = false;
1169 if (F.isDeclaration())
1172 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1173 FunctionPass *FP = getContainedPass(Index);
1175 AnalysisUsage AnUsage;
1176 FP->getAnalysisUsage(AnUsage);
1178 dumpPassInfo(FP, EXECUTION_MSG, ON_FUNCTION_MSG, F.getNameStart());
1179 dumpAnalysisSetInfo("Required", FP, AnUsage.getRequiredSet());
1181 initializeAnalysisImpl(FP);
1183 if (TheTimeInfo) TheTimeInfo->passStarted(FP);
1184 Changed |= FP->runOnFunction(F);
1185 if (TheTimeInfo) TheTimeInfo->passEnded(FP);
1188 dumpPassInfo(FP, MODIFICATION_MSG, ON_FUNCTION_MSG, F.getNameStart());
1189 dumpAnalysisSetInfo("Preserved", FP, AnUsage.getPreservedSet());
1191 verifyPreservedAnalysis(FP);
1192 removeNotPreservedAnalysis(FP);
1193 recordAvailableAnalysis(FP);
1194 removeDeadPasses(FP, F.getNameStart(), ON_FUNCTION_MSG);
1199 bool FPPassManager::runOnModule(Module &M) {
1201 bool Changed = doInitialization(M);
1203 for(Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
1204 this->runOnFunction(*I);
1206 return Changed |= doFinalization(M);
1209 inline bool FPPassManager::doInitialization(Module &M) {
1210 bool Changed = false;
1212 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1213 FunctionPass *FP = getContainedPass(Index);
1214 Changed |= FP->doInitialization(M);
1220 inline bool FPPassManager::doFinalization(Module &M) {
1221 bool Changed = false;
1223 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1224 FunctionPass *FP = getContainedPass(Index);
1225 Changed |= FP->doFinalization(M);
1231 //===----------------------------------------------------------------------===//
1232 // MPPassManager implementation
1234 /// Execute all of the passes scheduled for execution by invoking
1235 /// runOnModule method. Keep track of whether any of the passes modifies
1236 /// the module, and if so, return true.
1238 MPPassManager::runOnModule(Module &M) {
1239 bool Changed = false;
1241 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1242 ModulePass *MP = getContainedPass(Index);
1244 AnalysisUsage AnUsage;
1245 MP->getAnalysisUsage(AnUsage);
1247 dumpPassInfo(MP, EXECUTION_MSG, ON_MODULE_MSG,
1248 M.getModuleIdentifier().c_str());
1249 dumpAnalysisSetInfo("Required", MP, AnUsage.getRequiredSet());
1251 initializeAnalysisImpl(MP);
1253 if (TheTimeInfo) TheTimeInfo->passStarted(MP);
1254 Changed |= MP->runOnModule(M);
1255 if (TheTimeInfo) TheTimeInfo->passEnded(MP);
1258 dumpPassInfo(MP, MODIFICATION_MSG, ON_MODULE_MSG,
1259 M.getModuleIdentifier().c_str());
1260 dumpAnalysisSetInfo("Preserved", MP, AnUsage.getPreservedSet());
1262 verifyPreservedAnalysis(MP);
1263 removeNotPreservedAnalysis(MP);
1264 recordAvailableAnalysis(MP);
1265 removeDeadPasses(MP, M.getModuleIdentifier().c_str(), ON_MODULE_MSG);
1270 /// Add RequiredPass into list of lower level passes required by pass P.
1271 /// RequiredPass is run on the fly by Pass Manager when P requests it
1272 /// through getAnalysis interface.
1273 void MPPassManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
1275 assert (P->getPotentialPassManagerType() == PMT_ModulePassManager
1276 && "Unable to handle Pass that requires lower level Analysis pass");
1277 assert ((P->getPotentialPassManagerType() <
1278 RequiredPass->getPotentialPassManagerType())
1279 && "Unable to handle Pass that requires lower level Analysis pass");
1281 FunctionPassManagerImpl *FPP = OnTheFlyManagers[P];
1283 FPP = new FunctionPassManagerImpl(0);
1284 // FPP is the top level manager.
1285 FPP->setTopLevelManager(FPP);
1287 OnTheFlyManagers[P] = FPP;
1289 FPP->add(RequiredPass);
1291 // Register P as the last user of RequiredPass.
1292 SmallVector<Pass *, 12> LU;
1293 LU.push_back(RequiredPass);
1294 FPP->setLastUser(LU, P);
1297 /// Return function pass corresponding to PassInfo PI, that is
1298 /// required by module pass MP. Instantiate analysis pass, by using
1299 /// its runOnFunction() for function F.
1300 Pass* MPPassManager::getOnTheFlyPass(Pass *MP, const PassInfo *PI,
1302 AnalysisID AID = PI;
1303 FunctionPassManagerImpl *FPP = OnTheFlyManagers[MP];
1304 assert (FPP && "Unable to find on the fly pass");
1307 return (dynamic_cast<PMTopLevelManager *>(FPP))->findAnalysisPass(AID);
1311 //===----------------------------------------------------------------------===//
1312 // PassManagerImpl implementation
1314 /// run - Execute all of the passes scheduled for execution. Keep track of
1315 /// whether any of the passes modifies the module, and if so, return true.
1316 bool PassManagerImpl::run(Module &M) {
1318 bool Changed = false;
1320 TimingInfo::createTheTimeInfo();
1325 initializeAllAnalysisInfo();
1326 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
1327 MPPassManager *MP = getContainedManager(Index);
1328 Changed |= MP->runOnModule(M);
1333 //===----------------------------------------------------------------------===//
1334 // PassManager implementation
1336 /// Create new pass manager
1337 PassManager::PassManager() {
1338 PM = new PassManagerImpl(0);
1339 // PM is the top level manager
1340 PM->setTopLevelManager(PM);
1343 PassManager::~PassManager() {
1347 /// add - Add a pass to the queue of passes to run. This passes ownership of
1348 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
1349 /// will be destroyed as well, so there is no need to delete the pass. This
1350 /// implies that all passes MUST be allocated with 'new'.
1352 PassManager::add(Pass *P) {
1356 /// run - Execute all of the passes scheduled for execution. Keep track of
1357 /// whether any of the passes modifies the module, and if so, return true.
1359 PassManager::run(Module &M) {
1363 //===----------------------------------------------------------------------===//
1364 // TimingInfo Class - This class is used to calculate information about the
1365 // amount of time each pass takes to execute. This only happens with
1366 // -time-passes is enabled on the command line.
1368 bool llvm::TimePassesIsEnabled = false;
1369 static cl::opt<bool,true>
1370 EnableTiming("time-passes", cl::location(TimePassesIsEnabled),
1371 cl::desc("Time each pass, printing elapsed time for each on exit"));
1373 // createTheTimeInfo - This method either initializes the TheTimeInfo pointer to
1374 // a non null value (if the -time-passes option is enabled) or it leaves it
1375 // null. It may be called multiple times.
1376 void TimingInfo::createTheTimeInfo() {
1377 if (!TimePassesIsEnabled || TheTimeInfo) return;
1379 // Constructed the first time this is called, iff -time-passes is enabled.
1380 // This guarantees that the object will be constructed before static globals,
1381 // thus it will be destroyed before them.
1382 static ManagedStatic<TimingInfo> TTI;
1383 TheTimeInfo = &*TTI;
1386 /// If TimingInfo is enabled then start pass timer.
1387 void StartPassTimer(Pass *P) {
1389 TheTimeInfo->passStarted(P);
1392 /// If TimingInfo is enabled then stop pass timer.
1393 void StopPassTimer(Pass *P) {
1395 TheTimeInfo->passEnded(P);
1398 //===----------------------------------------------------------------------===//
1399 // PMStack implementation
1402 // Pop Pass Manager from the stack and clear its analysis info.
1403 void PMStack::pop() {
1405 PMDataManager *Top = this->top();
1406 Top->initializeAnalysisInfo();
1411 // Push PM on the stack and set its top level manager.
1412 void PMStack::push(Pass *P) {
1414 PMDataManager *Top = NULL;
1415 PMDataManager *PM = dynamic_cast<PMDataManager *>(P);
1416 assert (PM && "Unable to push. Pass Manager expected");
1418 if (this->empty()) {
1423 PMTopLevelManager *TPM = Top->getTopLevelManager();
1425 assert (TPM && "Unable to find top level manager");
1426 TPM->addIndirectPassManager(PM);
1427 PM->setTopLevelManager(TPM);
1433 // Dump content of the pass manager stack.
1434 void PMStack::dump() {
1435 for(std::deque<PMDataManager *>::iterator I = S.begin(),
1436 E = S.end(); I != E; ++I) {
1437 Pass *P = dynamic_cast<Pass *>(*I);
1438 printf("%s ", P->getPassName());
1444 /// Find appropriate Module Pass Manager in the PM Stack and
1445 /// add self into that manager.
1446 void ModulePass::assignPassManager(PMStack &PMS,
1447 PassManagerType PreferredType) {
1449 // Find Module Pass Manager
1450 while(!PMS.empty()) {
1451 PassManagerType TopPMType = PMS.top()->getPassManagerType();
1452 if (TopPMType == PreferredType)
1453 break; // We found desired pass manager
1454 else if (TopPMType > PMT_ModulePassManager)
1455 PMS.pop(); // Pop children pass managers
1460 PMS.top()->add(this);
1463 /// Find appropriate Function Pass Manager or Call Graph Pass Manager
1464 /// in the PM Stack and add self into that manager.
1465 void FunctionPass::assignPassManager(PMStack &PMS,
1466 PassManagerType PreferredType) {
1468 // Find Module Pass Manager (TODO : Or Call Graph Pass Manager)
1469 while(!PMS.empty()) {
1470 if (PMS.top()->getPassManagerType() > PMT_FunctionPassManager)
1475 FPPassManager *FPP = dynamic_cast<FPPassManager *>(PMS.top());
1477 // Create new Function Pass Manager
1479 assert(!PMS.empty() && "Unable to create Function Pass Manager");
1480 PMDataManager *PMD = PMS.top();
1482 // [1] Create new Function Pass Manager
1483 FPP = new FPPassManager(PMD->getDepth() + 1);
1485 // [2] Set up new manager's top level manager
1486 PMTopLevelManager *TPM = PMD->getTopLevelManager();
1487 TPM->addIndirectPassManager(FPP);
1489 // [3] Assign manager to manage this new manager. This may create
1490 // and push new managers into PMS
1491 Pass *P = dynamic_cast<Pass *>(FPP);
1493 // If Call Graph Pass Manager is active then use it to manage
1494 // this new Function Pass manager.
1495 if (PMD->getPassManagerType() == PMT_CallGraphPassManager)
1496 P->assignPassManager(PMS, PMT_CallGraphPassManager);
1498 P->assignPassManager(PMS);
1500 // [4] Push new manager into PMS
1504 // Assign FPP as the manager of this pass.
1508 /// Find appropriate Basic Pass Manager or Call Graph Pass Manager
1509 /// in the PM Stack and add self into that manager.
1510 void BasicBlockPass::assignPassManager(PMStack &PMS,
1511 PassManagerType PreferredType) {
1513 BBPassManager *BBP = NULL;
1515 // Basic Pass Manager is a leaf pass manager. It does not handle
1516 // any other pass manager.
1518 BBP = dynamic_cast<BBPassManager *>(PMS.top());
1520 // If leaf manager is not Basic Block Pass manager then create new
1521 // basic Block Pass manager.
1524 assert(!PMS.empty() && "Unable to create BasicBlock Pass Manager");
1525 PMDataManager *PMD = PMS.top();
1527 // [1] Create new Basic Block Manager
1528 BBP = new BBPassManager(PMD->getDepth() + 1);
1530 // [2] Set up new manager's top level manager
1531 // Basic Block Pass Manager does not live by itself
1532 PMTopLevelManager *TPM = PMD->getTopLevelManager();
1533 TPM->addIndirectPassManager(BBP);
1535 // [3] Assign manager to manage this new manager. This may create
1536 // and push new managers into PMS
1537 Pass *P = dynamic_cast<Pass *>(BBP);
1538 P->assignPassManager(PMS);
1540 // [4] Push new manager into PMS
1544 // Assign BBP as the manager of this pass.