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"
22 #include "llvm-c/Core.h"
28 // See PassManagers.h for Pass Manager infrastructure overview.
32 //===----------------------------------------------------------------------===//
33 // Pass debugging information. Often it is useful to find out what pass is
34 // running when a crash occurs in a utility. When this library is compiled with
35 // debugging on, a command line option (--debug-pass) is enabled that causes the
36 // pass name to be printed before it executes.
39 // Different debug levels that can be enabled...
41 None, Arguments, Structure, Executions, Details
44 static cl::opt<enum PassDebugLevel>
45 PassDebugging("debug-pass", cl::Hidden,
46 cl::desc("Print PassManager debugging information"),
48 clEnumVal(None , "disable debug output"),
49 clEnumVal(Arguments , "print pass arguments to pass to 'opt'"),
50 clEnumVal(Structure , "print pass structure before run()"),
51 clEnumVal(Executions, "print pass name before it is executed"),
52 clEnumVal(Details , "print pass details when it is executed"),
54 } // End of llvm namespace
58 //===----------------------------------------------------------------------===//
61 /// BBPassManager manages BasicBlockPass. It batches all the
62 /// pass together and sequence them to process one basic block before
63 /// processing next basic block.
64 class VISIBILITY_HIDDEN BBPassManager : public PMDataManager,
69 explicit BBPassManager(int Depth)
70 : PMDataManager(Depth), FunctionPass((intptr_t)&ID) {}
72 /// Execute all of the passes scheduled for execution. Keep track of
73 /// whether any of the passes modifies the function, and if so, return true.
74 bool runOnFunction(Function &F);
76 /// Pass Manager itself does not invalidate any analysis info.
77 void getAnalysisUsage(AnalysisUsage &Info) const {
78 Info.setPreservesAll();
81 bool doInitialization(Module &M);
82 bool doInitialization(Function &F);
83 bool doFinalization(Module &M);
84 bool doFinalization(Function &F);
86 virtual const char *getPassName() const {
87 return "BasicBlock Pass Manager";
90 // Print passes managed by this manager
91 void dumpPassStructure(unsigned Offset) {
92 llvm::cerr << std::string(Offset*2, ' ') << "BasicBlockPass Manager\n";
93 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
94 BasicBlockPass *BP = getContainedPass(Index);
95 BP->dumpPassStructure(Offset + 1);
96 dumpLastUses(BP, Offset+1);
100 BasicBlockPass *getContainedPass(unsigned N) {
101 assert ( N < PassVector.size() && "Pass number out of range!");
102 BasicBlockPass *BP = static_cast<BasicBlockPass *>(PassVector[N]);
106 virtual PassManagerType getPassManagerType() const {
107 return PMT_BasicBlockPassManager;
111 char BBPassManager::ID = 0;
116 //===----------------------------------------------------------------------===//
117 // FunctionPassManagerImpl
119 /// FunctionPassManagerImpl manages FPPassManagers
120 class FunctionPassManagerImpl : public Pass,
121 public PMDataManager,
122 public PMTopLevelManager {
125 explicit FunctionPassManagerImpl(int Depth) :
126 Pass((intptr_t)&ID), PMDataManager(Depth),
127 PMTopLevelManager(TLM_Function) { }
129 /// add - Add a pass to the queue of passes to run. This passes ownership of
130 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
131 /// will be destroyed as well, so there is no need to delete the pass. This
132 /// implies that all passes MUST be allocated with 'new'.
137 /// run - Execute all of the passes scheduled for execution. Keep track of
138 /// whether any of the passes modifies the module, and if so, return true.
139 bool run(Function &F);
141 /// doInitialization - Run all of the initializers for the function passes.
143 bool doInitialization(Module &M);
145 /// doFinalization - Run all of the finalizers for the function passes.
147 bool doFinalization(Module &M);
149 /// Pass Manager itself does not invalidate any analysis info.
150 void getAnalysisUsage(AnalysisUsage &Info) const {
151 Info.setPreservesAll();
154 inline void addTopLevelPass(Pass *P) {
156 if (ImmutablePass *IP = dynamic_cast<ImmutablePass *> (P)) {
158 // P is a immutable pass and it will be managed by this
159 // top level manager. Set up analysis resolver to connect them.
160 AnalysisResolver *AR = new AnalysisResolver(*this);
162 initializeAnalysisImpl(P);
163 addImmutablePass(IP);
164 recordAvailableAnalysis(IP);
166 P->assignPassManager(activeStack);
171 FPPassManager *getContainedManager(unsigned N) {
172 assert ( N < PassManagers.size() && "Pass number out of range!");
173 FPPassManager *FP = static_cast<FPPassManager *>(PassManagers[N]);
178 char FunctionPassManagerImpl::ID = 0;
179 //===----------------------------------------------------------------------===//
182 /// MPPassManager manages ModulePasses and function pass managers.
183 /// It batches all Module passes and function pass managers together and
184 /// sequences them to process one module.
185 class MPPassManager : public Pass, public PMDataManager {
189 explicit MPPassManager(int Depth) :
190 Pass((intptr_t)&ID), PMDataManager(Depth) { }
192 // Delete on the fly managers.
193 virtual ~MPPassManager() {
194 for (std::map<Pass *, FunctionPassManagerImpl *>::iterator
195 I = OnTheFlyManagers.begin(), E = OnTheFlyManagers.end();
197 FunctionPassManagerImpl *FPP = I->second;
202 /// run - Execute all of the passes scheduled for execution. Keep track of
203 /// whether any of the passes modifies the module, and if so, return true.
204 bool runOnModule(Module &M);
206 /// Pass Manager itself does not invalidate any analysis info.
207 void getAnalysisUsage(AnalysisUsage &Info) const {
208 Info.setPreservesAll();
211 /// Add RequiredPass into list of lower level passes required by pass P.
212 /// RequiredPass is run on the fly by Pass Manager when P requests it
213 /// through getAnalysis interface.
214 virtual void addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass);
216 /// Return function pass corresponding to PassInfo PI, that is
217 /// required by module pass MP. Instantiate analysis pass, by using
218 /// its runOnFunction() for function F.
219 virtual Pass* getOnTheFlyPass(Pass *MP, const PassInfo *PI, Function &F);
221 virtual const char *getPassName() const {
222 return "Module Pass Manager";
225 // Print passes managed by this manager
226 void dumpPassStructure(unsigned Offset) {
227 llvm::cerr << std::string(Offset*2, ' ') << "ModulePass Manager\n";
228 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
229 ModulePass *MP = getContainedPass(Index);
230 MP->dumpPassStructure(Offset + 1);
231 if (FunctionPassManagerImpl *FPP = OnTheFlyManagers[MP])
232 FPP->dumpPassStructure(Offset + 2);
233 dumpLastUses(MP, Offset+1);
237 ModulePass *getContainedPass(unsigned N) {
238 assert ( N < PassVector.size() && "Pass number out of range!");
239 ModulePass *MP = static_cast<ModulePass *>(PassVector[N]);
243 virtual PassManagerType getPassManagerType() const {
244 return PMT_ModulePassManager;
248 /// Collection of on the fly FPPassManagers. These managers manage
249 /// function passes that are required by module passes.
250 std::map<Pass *, FunctionPassManagerImpl *> OnTheFlyManagers;
253 char MPPassManager::ID = 0;
254 //===----------------------------------------------------------------------===//
258 /// PassManagerImpl manages MPPassManagers
259 class PassManagerImpl : public Pass,
260 public PMDataManager,
261 public PMTopLevelManager {
265 explicit PassManagerImpl(int Depth) :
266 Pass((intptr_t)&ID), PMDataManager(Depth),
267 PMTopLevelManager(TLM_Pass) { }
269 /// add - Add a pass to the queue of passes to run. This passes ownership of
270 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
271 /// will be destroyed as well, so there is no need to delete the pass. This
272 /// implies that all passes MUST be allocated with 'new'.
277 /// run - Execute all of the passes scheduled for execution. Keep track of
278 /// whether any of the passes modifies the module, and if so, return true.
281 /// Pass Manager itself does not invalidate any analysis info.
282 void getAnalysisUsage(AnalysisUsage &Info) const {
283 Info.setPreservesAll();
286 inline void addTopLevelPass(Pass *P) {
288 if (ImmutablePass *IP = dynamic_cast<ImmutablePass *> (P)) {
290 // P is a immutable pass and it will be managed by this
291 // top level manager. Set up analysis resolver to connect them.
292 AnalysisResolver *AR = new AnalysisResolver(*this);
294 initializeAnalysisImpl(P);
295 addImmutablePass(IP);
296 recordAvailableAnalysis(IP);
298 P->assignPassManager(activeStack);
303 MPPassManager *getContainedManager(unsigned N) {
304 assert ( N < PassManagers.size() && "Pass number out of range!");
305 MPPassManager *MP = static_cast<MPPassManager *>(PassManagers[N]);
311 char PassManagerImpl::ID = 0;
312 } // End of llvm namespace
316 //===----------------------------------------------------------------------===//
317 // TimingInfo Class - This class is used to calculate information about the
318 // amount of time each pass takes to execute. This only happens when
319 // -time-passes is enabled on the command line.
322 class VISIBILITY_HIDDEN TimingInfo {
323 std::map<Pass*, Timer> TimingData;
327 // Use 'create' member to get this.
328 TimingInfo() : TG("... Pass execution timing report ...") {}
330 // TimingDtor - Print out information about timing information
332 // Delete all of the timers...
334 // TimerGroup is deleted next, printing the report.
337 // createTheTimeInfo - This method either initializes the TheTimeInfo pointer
338 // to a non null value (if the -time-passes option is enabled) or it leaves it
339 // null. It may be called multiple times.
340 static void createTheTimeInfo();
342 void passStarted(Pass *P) {
344 if (dynamic_cast<PMDataManager *>(P))
347 std::map<Pass*, Timer>::iterator I = TimingData.find(P);
348 if (I == TimingData.end())
349 I=TimingData.insert(std::make_pair(P, Timer(P->getPassName(), TG))).first;
350 I->second.startTimer();
352 void passEnded(Pass *P) {
354 if (dynamic_cast<PMDataManager *>(P))
357 std::map<Pass*, Timer>::iterator I = TimingData.find(P);
358 assert (I != TimingData.end() && "passStarted/passEnded not nested right!");
359 I->second.stopTimer();
363 static TimingInfo *TheTimeInfo;
365 } // End of anon namespace
367 //===----------------------------------------------------------------------===//
368 // PMTopLevelManager implementation
370 /// Initialize top level manager. Create first pass manager.
371 PMTopLevelManager::PMTopLevelManager (enum TopLevelManagerType t) {
374 MPPassManager *MPP = new MPPassManager(1);
375 MPP->setTopLevelManager(this);
377 activeStack.push(MPP);
379 else if (t == TLM_Function) {
380 FPPassManager *FPP = new FPPassManager(1);
381 FPP->setTopLevelManager(this);
383 activeStack.push(FPP);
387 /// Set pass P as the last user of the given analysis passes.
388 void PMTopLevelManager::setLastUser(SmallVector<Pass *, 12> &AnalysisPasses,
391 for (SmallVector<Pass *, 12>::iterator I = AnalysisPasses.begin(),
392 E = AnalysisPasses.end(); I != E; ++I) {
399 // If AP is the last user of other passes then make P last user of
401 for (std::map<Pass *, Pass *>::iterator LUI = LastUser.begin(),
402 LUE = LastUser.end(); LUI != LUE; ++LUI) {
403 if (LUI->second == AP)
404 LastUser[LUI->first] = P;
409 /// Collect passes whose last user is P
410 void PMTopLevelManager::collectLastUses(SmallVector<Pass *, 12> &LastUses,
412 for (std::map<Pass *, Pass *>::iterator LUI = LastUser.begin(),
413 LUE = LastUser.end(); LUI != LUE; ++LUI)
414 if (LUI->second == P)
415 LastUses.push_back(LUI->first);
418 /// Schedule pass P for execution. Make sure that passes required by
419 /// P are run before P is run. Update analysis info maintained by
420 /// the manager. Remove dead passes. This is a recursive function.
421 void PMTopLevelManager::schedulePass(Pass *P) {
423 // TODO : Allocate function manager for this pass, other wise required set
424 // may be inserted into previous function manager
426 // Give pass a chance to prepare the stage.
427 P->preparePassManager(activeStack);
429 // If P is an analysis pass and it is available then do not
430 // generate the analysis again. Stale analysis info should not be
431 // available at this point.
432 if (P->isAnalysis() && findAnalysisPass(P->getPassInfo()))
435 AnalysisUsage AnUsage;
436 P->getAnalysisUsage(AnUsage);
437 const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet();
438 for (std::vector<AnalysisID>::const_iterator I = RequiredSet.begin(),
439 E = RequiredSet.end(); I != E; ++I) {
441 Pass *AnalysisPass = findAnalysisPass(*I);
443 AnalysisPass = (*I)->createPass();
444 // Schedule this analysis run first only if it is not a lower level
445 // analysis pass. Lower level analsyis passes are run on the fly.
446 if (P->getPotentialPassManagerType () >=
447 AnalysisPass->getPotentialPassManagerType())
448 schedulePass(AnalysisPass);
454 // Now all required passes are available.
458 /// Find the pass that implements Analysis AID. Search immutable
459 /// passes and all pass managers. If desired pass is not found
460 /// then return NULL.
461 Pass *PMTopLevelManager::findAnalysisPass(AnalysisID AID) {
464 // Check pass managers
465 for (std::vector<PMDataManager *>::iterator I = PassManagers.begin(),
466 E = PassManagers.end(); P == NULL && I != E; ++I) {
467 PMDataManager *PMD = *I;
468 P = PMD->findAnalysisPass(AID, false);
471 // Check other pass managers
472 for (std::vector<PMDataManager *>::iterator I = IndirectPassManagers.begin(),
473 E = IndirectPassManagers.end(); P == NULL && I != E; ++I)
474 P = (*I)->findAnalysisPass(AID, false);
476 for (std::vector<ImmutablePass *>::iterator I = ImmutablePasses.begin(),
477 E = ImmutablePasses.end(); P == NULL && I != E; ++I) {
478 const PassInfo *PI = (*I)->getPassInfo();
482 // If Pass not found then check the interfaces implemented by Immutable Pass
484 const std::vector<const PassInfo*> &ImmPI =
485 PI->getInterfacesImplemented();
486 if (std::find(ImmPI.begin(), ImmPI.end(), AID) != ImmPI.end())
494 // Print passes managed by this top level manager.
495 void PMTopLevelManager::dumpPasses() const {
497 if (PassDebugging < Structure)
500 // Print out the immutable passes
501 for (unsigned i = 0, e = ImmutablePasses.size(); i != e; ++i) {
502 ImmutablePasses[i]->dumpPassStructure(0);
505 // Every class that derives from PMDataManager also derives from Pass
506 // (sometimes indirectly), but there's no inheritance relationship
507 // between PMDataManager and Pass, so we have to dynamic_cast to get
508 // from a PMDataManager* to a Pass*.
509 for (std::vector<PMDataManager *>::const_iterator I = PassManagers.begin(),
510 E = PassManagers.end(); I != E; ++I)
511 dynamic_cast<Pass *>(*I)->dumpPassStructure(1);
514 void PMTopLevelManager::dumpArguments() const {
516 if (PassDebugging < Arguments)
519 cerr << "Pass Arguments: ";
520 for (std::vector<PMDataManager *>::const_iterator I = PassManagers.begin(),
521 E = PassManagers.end(); I != E; ++I) {
522 PMDataManager *PMD = *I;
523 PMD->dumpPassArguments();
528 void PMTopLevelManager::initializeAllAnalysisInfo() {
530 for (std::vector<PMDataManager *>::iterator I = PassManagers.begin(),
531 E = PassManagers.end(); I != E; ++I) {
532 PMDataManager *PMD = *I;
533 PMD->initializeAnalysisInfo();
536 // Initailize other pass managers
537 for (std::vector<PMDataManager *>::iterator I = IndirectPassManagers.begin(),
538 E = IndirectPassManagers.end(); I != E; ++I)
539 (*I)->initializeAnalysisInfo();
543 PMTopLevelManager::~PMTopLevelManager() {
544 for (std::vector<PMDataManager *>::iterator I = PassManagers.begin(),
545 E = PassManagers.end(); I != E; ++I)
548 for (std::vector<ImmutablePass *>::iterator
549 I = ImmutablePasses.begin(), E = ImmutablePasses.end(); I != E; ++I)
553 //===----------------------------------------------------------------------===//
554 // PMDataManager implementation
556 /// Augement AvailableAnalysis by adding analysis made available by pass P.
557 void PMDataManager::recordAvailableAnalysis(Pass *P) {
559 if (const PassInfo *PI = P->getPassInfo()) {
560 AvailableAnalysis[PI] = P;
562 //This pass is the current implementation of all of the interfaces it
563 //implements as well.
564 const std::vector<const PassInfo*> &II = PI->getInterfacesImplemented();
565 for (unsigned i = 0, e = II.size(); i != e; ++i)
566 AvailableAnalysis[II[i]] = P;
570 // Return true if P preserves high level analysis used by other
571 // passes managed by this manager
572 bool PMDataManager::preserveHigherLevelAnalysis(Pass *P) {
574 AnalysisUsage AnUsage;
575 P->getAnalysisUsage(AnUsage);
577 if (AnUsage.getPreservesAll())
580 const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
581 for (std::vector<Pass *>::iterator I = HigherLevelAnalysis.begin(),
582 E = HigherLevelAnalysis.end(); I != E; ++I) {
584 if (!dynamic_cast<ImmutablePass*>(P1) &&
585 std::find(PreservedSet.begin(), PreservedSet.end(),
586 P1->getPassInfo()) ==
594 /// verifyPreservedAnalysis -- Verify analysis presreved by pass P.
595 void PMDataManager::verifyPreservedAnalysis(Pass *P) {
596 AnalysisUsage AnUsage;
597 P->getAnalysisUsage(AnUsage);
598 const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
600 // Verify preserved analysis
601 for (std::vector<AnalysisID>::const_iterator I = PreservedSet.begin(),
602 E = PreservedSet.end(); I != E; ++I) {
604 Pass *AP = findAnalysisPass(AID, true);
606 AP->verifyAnalysis();
610 /// Remove Analyss not preserved by Pass P
611 void PMDataManager::removeNotPreservedAnalysis(Pass *P) {
612 AnalysisUsage AnUsage;
613 P->getAnalysisUsage(AnUsage);
614 if (AnUsage.getPreservesAll())
617 const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
618 for (std::map<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(),
619 E = AvailableAnalysis.end(); I != E; ) {
620 std::map<AnalysisID, Pass*>::iterator Info = I++;
621 if (!dynamic_cast<ImmutablePass*>(Info->second)
622 && std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) ==
624 // Remove this analysis
625 AvailableAnalysis.erase(Info);
628 // Check inherited analysis also. If P is not preserving analysis
629 // provided by parent manager then remove it here.
630 for (unsigned Index = 0; Index < PMT_Last; ++Index) {
632 if (!InheritedAnalysis[Index])
635 for (std::map<AnalysisID, Pass*>::iterator
636 I = InheritedAnalysis[Index]->begin(),
637 E = InheritedAnalysis[Index]->end(); I != E; ) {
638 std::map<AnalysisID, Pass *>::iterator Info = I++;
639 if (!dynamic_cast<ImmutablePass*>(Info->second) &&
640 std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) ==
642 // Remove this analysis
643 InheritedAnalysis[Index]->erase(Info);
649 /// Remove analysis passes that are not used any longer
650 void PMDataManager::removeDeadPasses(Pass *P, const char *Msg,
651 enum PassDebuggingString DBG_STR) {
653 SmallVector<Pass *, 12> DeadPasses;
655 // If this is a on the fly manager then it does not have TPM.
659 TPM->collectLastUses(DeadPasses, P);
661 for (SmallVector<Pass *, 12>::iterator I = DeadPasses.begin(),
662 E = DeadPasses.end(); I != E; ++I) {
664 dumpPassInfo(*I, FREEING_MSG, DBG_STR, Msg);
666 if (TheTimeInfo) TheTimeInfo->passStarted(*I);
667 (*I)->releaseMemory();
668 if (TheTimeInfo) TheTimeInfo->passEnded(*I);
670 std::map<AnalysisID, Pass*>::iterator Pos =
671 AvailableAnalysis.find((*I)->getPassInfo());
673 // It is possible that pass is already removed from the AvailableAnalysis
674 if (Pos != AvailableAnalysis.end())
675 AvailableAnalysis.erase(Pos);
679 /// Add pass P into the PassVector. Update
680 /// AvailableAnalysis appropriately if ProcessAnalysis is true.
681 void PMDataManager::add(Pass *P,
682 bool ProcessAnalysis) {
684 // This manager is going to manage pass P. Set up analysis resolver
686 AnalysisResolver *AR = new AnalysisResolver(*this);
689 // If a FunctionPass F is the last user of ModulePass info M
690 // then the F's manager, not F, records itself as a last user of M.
691 SmallVector<Pass *, 12> TransferLastUses;
693 if (ProcessAnalysis) {
695 // At the moment, this pass is the last user of all required passes.
696 SmallVector<Pass *, 12> LastUses;
697 SmallVector<Pass *, 8> RequiredPasses;
698 SmallVector<AnalysisID, 8> ReqAnalysisNotAvailable;
700 unsigned PDepth = this->getDepth();
702 collectRequiredAnalysis(RequiredPasses,
703 ReqAnalysisNotAvailable, P);
704 for (SmallVector<Pass *, 8>::iterator I = RequiredPasses.begin(),
705 E = RequiredPasses.end(); I != E; ++I) {
706 Pass *PRequired = *I;
709 PMDataManager &DM = PRequired->getResolver()->getPMDataManager();
710 RDepth = DM.getDepth();
712 if (PDepth == RDepth)
713 LastUses.push_back(PRequired);
714 else if (PDepth > RDepth) {
715 // Let the parent claim responsibility of last use
716 TransferLastUses.push_back(PRequired);
717 // Keep track of higher level analysis used by this manager.
718 HigherLevelAnalysis.push_back(PRequired);
720 assert (0 && "Unable to accomodate Required Pass");
723 // Set P as P's last user until someone starts using P.
724 // However, if P is a Pass Manager then it does not need
725 // to record its last user.
726 if (!dynamic_cast<PMDataManager *>(P))
727 LastUses.push_back(P);
728 TPM->setLastUser(LastUses, P);
730 if (!TransferLastUses.empty()) {
731 Pass *My_PM = dynamic_cast<Pass *>(this);
732 TPM->setLastUser(TransferLastUses, My_PM);
733 TransferLastUses.clear();
736 // Now, take care of required analysises that are not available.
737 for (SmallVector<AnalysisID, 8>::iterator
738 I = ReqAnalysisNotAvailable.begin(),
739 E = ReqAnalysisNotAvailable.end() ;I != E; ++I) {
740 Pass *AnalysisPass = (*I)->createPass();
741 this->addLowerLevelRequiredPass(P, AnalysisPass);
744 // Take a note of analysis required and made available by this pass.
745 // Remove the analysis not preserved by this pass
746 removeNotPreservedAnalysis(P);
747 recordAvailableAnalysis(P);
751 PassVector.push_back(P);
755 /// Populate RP with analysis pass that are required by
756 /// pass P and are available. Populate RP_NotAvail with analysis
757 /// pass that are required by pass P but are not available.
758 void PMDataManager::collectRequiredAnalysis(SmallVector<Pass *, 8>&RP,
759 SmallVector<AnalysisID, 8> &RP_NotAvail,
761 AnalysisUsage AnUsage;
762 P->getAnalysisUsage(AnUsage);
763 const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet();
764 for (std::vector<AnalysisID>::const_iterator
765 I = RequiredSet.begin(), E = RequiredSet.end();
768 if (Pass *AnalysisPass = findAnalysisPass(*I, true))
769 RP.push_back(AnalysisPass);
771 RP_NotAvail.push_back(AID);
774 const std::vector<AnalysisID> &IDs = AnUsage.getRequiredTransitiveSet();
775 for (std::vector<AnalysisID>::const_iterator I = IDs.begin(),
776 E = IDs.end(); I != E; ++I) {
778 if (Pass *AnalysisPass = findAnalysisPass(*I, true))
779 RP.push_back(AnalysisPass);
781 RP_NotAvail.push_back(AID);
785 // All Required analyses should be available to the pass as it runs! Here
786 // we fill in the AnalysisImpls member of the pass so that it can
787 // successfully use the getAnalysis() method to retrieve the
788 // implementations it needs.
790 void PMDataManager::initializeAnalysisImpl(Pass *P) {
791 AnalysisUsage AnUsage;
792 P->getAnalysisUsage(AnUsage);
794 for (std::vector<const PassInfo *>::const_iterator
795 I = AnUsage.getRequiredSet().begin(),
796 E = AnUsage.getRequiredSet().end(); I != E; ++I) {
797 Pass *Impl = findAnalysisPass(*I, true);
799 // This may be analysis pass that is initialized on the fly.
800 // If that is not the case then it will raise an assert when it is used.
802 AnalysisResolver *AR = P->getResolver();
803 AR->addAnalysisImplsPair(*I, Impl);
807 /// Find the pass that implements Analysis AID. If desired pass is not found
808 /// then return NULL.
809 Pass *PMDataManager::findAnalysisPass(AnalysisID AID, bool SearchParent) {
811 // Check if AvailableAnalysis map has one entry.
812 std::map<AnalysisID, Pass*>::const_iterator I = AvailableAnalysis.find(AID);
814 if (I != AvailableAnalysis.end())
817 // Search Parents through TopLevelManager
819 return TPM->findAnalysisPass(AID);
824 // Print list of passes that are last used by P.
825 void PMDataManager::dumpLastUses(Pass *P, unsigned Offset) const{
827 SmallVector<Pass *, 12> LUses;
829 // If this is a on the fly manager then it does not have TPM.
833 TPM->collectLastUses(LUses, P);
835 for (SmallVector<Pass *, 12>::iterator I = LUses.begin(),
836 E = LUses.end(); I != E; ++I) {
837 llvm::cerr << "--" << std::string(Offset*2, ' ');
838 (*I)->dumpPassStructure(0);
842 void PMDataManager::dumpPassArguments() const {
843 for(std::vector<Pass *>::const_iterator I = PassVector.begin(),
844 E = PassVector.end(); I != E; ++I) {
845 if (PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I))
846 PMD->dumpPassArguments();
848 if (const PassInfo *PI = (*I)->getPassInfo())
849 if (!PI->isAnalysisGroup())
850 cerr << " -" << PI->getPassArgument();
854 void PMDataManager::dumpPassInfo(Pass *P, enum PassDebuggingString S1,
855 enum PassDebuggingString S2,
857 if (PassDebugging < Executions)
859 cerr << (void*)this << std::string(getDepth()*2+1, ' ');
862 cerr << "Executing Pass '" << P->getPassName();
864 case MODIFICATION_MSG:
865 cerr << "Made Modification '" << P->getPassName();
868 cerr << " Freeing Pass '" << P->getPassName();
874 case ON_BASICBLOCK_MSG:
875 cerr << "' on BasicBlock '" << Msg << "'...\n";
877 case ON_FUNCTION_MSG:
878 cerr << "' on Function '" << Msg << "'...\n";
881 cerr << "' on Module '" << Msg << "'...\n";
884 cerr << "' on Loop " << Msg << "'...\n";
887 cerr << "' on Call Graph " << Msg << "'...\n";
894 void PMDataManager::dumpAnalysisSetInfo(const char *Msg, Pass *P,
895 const std::vector<AnalysisID> &Set)
897 if (PassDebugging >= Details && !Set.empty()) {
898 cerr << (void*)P << std::string(getDepth()*2+3, ' ') << Msg << " Analyses:";
899 for (unsigned i = 0; i != Set.size(); ++i) {
901 cerr << " " << Set[i]->getPassName();
907 /// Add RequiredPass into list of lower level passes required by pass P.
908 /// RequiredPass is run on the fly by Pass Manager when P requests it
909 /// through getAnalysis interface.
910 /// This should be handled by specific pass manager.
911 void PMDataManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
913 TPM->dumpArguments();
917 // Module Level pass may required Function Level analysis info
918 // (e.g. dominator info). Pass manager uses on the fly function pass manager
919 // to provide this on demand. In that case, in Pass manager terminology,
920 // module level pass is requiring lower level analysis info managed by
921 // lower level pass manager.
923 // When Pass manager is not able to order required analysis info, Pass manager
924 // checks whether any lower level manager will be able to provide this
925 // analysis info on demand or not.
926 assert (0 && "Unable to handle Pass that requires lower level Analysis pass");
930 PMDataManager::~PMDataManager() {
932 for (std::vector<Pass *>::iterator I = PassVector.begin(),
933 E = PassVector.end(); I != E; ++I)
938 //===----------------------------------------------------------------------===//
939 // NOTE: Is this the right place to define this method ?
940 // getAnalysisToUpdate - Return an analysis result or null if it doesn't exist
941 Pass *AnalysisResolver::getAnalysisToUpdate(AnalysisID ID, bool dir) const {
942 return PM.findAnalysisPass(ID, dir);
945 Pass *AnalysisResolver::findImplPass(Pass *P, const PassInfo *AnalysisPI,
947 return PM.getOnTheFlyPass(P, AnalysisPI, F);
950 //===----------------------------------------------------------------------===//
951 // BBPassManager implementation
953 /// Execute all of the passes scheduled for execution by invoking
954 /// runOnBasicBlock method. Keep track of whether any of the passes modifies
955 /// the function, and if so, return true.
957 BBPassManager::runOnFunction(Function &F) {
959 if (F.isDeclaration())
962 bool Changed = doInitialization(F);
964 for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
965 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
966 BasicBlockPass *BP = getContainedPass(Index);
967 AnalysisUsage AnUsage;
968 BP->getAnalysisUsage(AnUsage);
970 dumpPassInfo(BP, EXECUTION_MSG, ON_BASICBLOCK_MSG, I->getNameStart());
971 dumpAnalysisSetInfo("Required", BP, AnUsage.getRequiredSet());
973 initializeAnalysisImpl(BP);
975 if (TheTimeInfo) TheTimeInfo->passStarted(BP);
976 Changed |= BP->runOnBasicBlock(*I);
977 if (TheTimeInfo) TheTimeInfo->passEnded(BP);
980 dumpPassInfo(BP, MODIFICATION_MSG, ON_BASICBLOCK_MSG,
982 dumpAnalysisSetInfo("Preserved", BP, AnUsage.getPreservedSet());
984 verifyPreservedAnalysis(BP);
985 removeNotPreservedAnalysis(BP);
986 recordAvailableAnalysis(BP);
987 removeDeadPasses(BP, I->getNameStart(), ON_BASICBLOCK_MSG);
990 return Changed |= doFinalization(F);
993 // Implement doInitialization and doFinalization
994 inline bool BBPassManager::doInitialization(Module &M) {
995 bool Changed = false;
997 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
998 BasicBlockPass *BP = getContainedPass(Index);
999 Changed |= BP->doInitialization(M);
1005 inline bool BBPassManager::doFinalization(Module &M) {
1006 bool Changed = false;
1008 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1009 BasicBlockPass *BP = getContainedPass(Index);
1010 Changed |= BP->doFinalization(M);
1016 inline bool BBPassManager::doInitialization(Function &F) {
1017 bool Changed = false;
1019 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1020 BasicBlockPass *BP = getContainedPass(Index);
1021 Changed |= BP->doInitialization(F);
1027 inline bool BBPassManager::doFinalization(Function &F) {
1028 bool Changed = false;
1030 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1031 BasicBlockPass *BP = getContainedPass(Index);
1032 Changed |= BP->doFinalization(F);
1039 //===----------------------------------------------------------------------===//
1040 // FunctionPassManager implementation
1042 /// Create new Function pass manager
1043 FunctionPassManager::FunctionPassManager(ModuleProvider *P) {
1044 FPM = new FunctionPassManagerImpl(0);
1045 // FPM is the top level manager.
1046 FPM->setTopLevelManager(FPM);
1048 AnalysisResolver *AR = new AnalysisResolver(*FPM);
1049 FPM->setResolver(AR);
1054 FunctionPassManager::~FunctionPassManager() {
1058 /// add - Add a pass to the queue of passes to run. This passes
1059 /// ownership of the Pass to the PassManager. When the
1060 /// PassManager_X is destroyed, the pass will be destroyed as well, so
1061 /// there is no need to delete the pass. (TODO delete passes.)
1062 /// This implies that all passes MUST be allocated with 'new'.
1063 void FunctionPassManager::add(Pass *P) {
1067 /// run - Execute all of the passes scheduled for execution. Keep
1068 /// track of whether any of the passes modifies the function, and if
1069 /// so, return true.
1071 bool FunctionPassManager::run(Function &F) {
1073 if (MP->materializeFunction(&F, &errstr)) {
1074 cerr << "Error reading bitcode file: " << errstr << "\n";
1081 /// doInitialization - Run all of the initializers for the function passes.
1083 bool FunctionPassManager::doInitialization() {
1084 return FPM->doInitialization(*MP->getModule());
1087 /// doFinalization - Run all of the finalizers for the function passes.
1089 bool FunctionPassManager::doFinalization() {
1090 return FPM->doFinalization(*MP->getModule());
1093 //===----------------------------------------------------------------------===//
1094 // FunctionPassManagerImpl implementation
1096 inline bool FunctionPassManagerImpl::doInitialization(Module &M) {
1097 bool Changed = false;
1099 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
1100 FPPassManager *FP = getContainedManager(Index);
1101 Changed |= FP->doInitialization(M);
1107 inline bool FunctionPassManagerImpl::doFinalization(Module &M) {
1108 bool Changed = false;
1110 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
1111 FPPassManager *FP = getContainedManager(Index);
1112 Changed |= FP->doFinalization(M);
1118 // Execute all the passes managed by this top level manager.
1119 // Return true if any function is modified by a pass.
1120 bool FunctionPassManagerImpl::run(Function &F) {
1122 bool Changed = false;
1124 TimingInfo::createTheTimeInfo();
1129 initializeAllAnalysisInfo();
1130 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
1131 FPPassManager *FP = getContainedManager(Index);
1132 Changed |= FP->runOnFunction(F);
1137 //===----------------------------------------------------------------------===//
1138 // FPPassManager implementation
1140 char FPPassManager::ID = 0;
1141 /// Print passes managed by this manager
1142 void FPPassManager::dumpPassStructure(unsigned Offset) {
1143 llvm::cerr << std::string(Offset*2, ' ') << "FunctionPass Manager\n";
1144 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1145 FunctionPass *FP = getContainedPass(Index);
1146 FP->dumpPassStructure(Offset + 1);
1147 dumpLastUses(FP, Offset+1);
1152 /// Execute all of the passes scheduled for execution by invoking
1153 /// runOnFunction method. Keep track of whether any of the passes modifies
1154 /// the function, and if so, return true.
1155 bool FPPassManager::runOnFunction(Function &F) {
1157 bool Changed = false;
1159 if (F.isDeclaration())
1162 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1163 FunctionPass *FP = getContainedPass(Index);
1165 AnalysisUsage AnUsage;
1166 FP->getAnalysisUsage(AnUsage);
1168 dumpPassInfo(FP, EXECUTION_MSG, ON_FUNCTION_MSG, F.getNameStart());
1169 dumpAnalysisSetInfo("Required", FP, AnUsage.getRequiredSet());
1171 initializeAnalysisImpl(FP);
1173 if (TheTimeInfo) TheTimeInfo->passStarted(FP);
1174 Changed |= FP->runOnFunction(F);
1175 if (TheTimeInfo) TheTimeInfo->passEnded(FP);
1178 dumpPassInfo(FP, MODIFICATION_MSG, ON_FUNCTION_MSG, F.getNameStart());
1179 dumpAnalysisSetInfo("Preserved", FP, AnUsage.getPreservedSet());
1181 verifyPreservedAnalysis(FP);
1182 removeNotPreservedAnalysis(FP);
1183 recordAvailableAnalysis(FP);
1184 removeDeadPasses(FP, F.getNameStart(), ON_FUNCTION_MSG);
1189 bool FPPassManager::runOnModule(Module &M) {
1191 bool Changed = doInitialization(M);
1193 for(Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
1194 this->runOnFunction(*I);
1196 return Changed |= doFinalization(M);
1199 inline bool FPPassManager::doInitialization(Module &M) {
1200 bool Changed = false;
1202 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1203 FunctionPass *FP = getContainedPass(Index);
1204 Changed |= FP->doInitialization(M);
1210 inline bool FPPassManager::doFinalization(Module &M) {
1211 bool Changed = false;
1213 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1214 FunctionPass *FP = getContainedPass(Index);
1215 Changed |= FP->doFinalization(M);
1221 //===----------------------------------------------------------------------===//
1222 // MPPassManager implementation
1224 /// Execute all of the passes scheduled for execution by invoking
1225 /// runOnModule method. Keep track of whether any of the passes modifies
1226 /// the module, and if so, return true.
1228 MPPassManager::runOnModule(Module &M) {
1229 bool Changed = false;
1231 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1232 ModulePass *MP = getContainedPass(Index);
1234 AnalysisUsage AnUsage;
1235 MP->getAnalysisUsage(AnUsage);
1237 dumpPassInfo(MP, EXECUTION_MSG, ON_MODULE_MSG,
1238 M.getModuleIdentifier().c_str());
1239 dumpAnalysisSetInfo("Required", MP, AnUsage.getRequiredSet());
1241 initializeAnalysisImpl(MP);
1243 if (TheTimeInfo) TheTimeInfo->passStarted(MP);
1244 Changed |= MP->runOnModule(M);
1245 if (TheTimeInfo) TheTimeInfo->passEnded(MP);
1248 dumpPassInfo(MP, MODIFICATION_MSG, ON_MODULE_MSG,
1249 M.getModuleIdentifier().c_str());
1250 dumpAnalysisSetInfo("Preserved", MP, AnUsage.getPreservedSet());
1252 verifyPreservedAnalysis(MP);
1253 removeNotPreservedAnalysis(MP);
1254 recordAvailableAnalysis(MP);
1255 removeDeadPasses(MP, M.getModuleIdentifier().c_str(), ON_MODULE_MSG);
1260 /// Add RequiredPass into list of lower level passes required by pass P.
1261 /// RequiredPass is run on the fly by Pass Manager when P requests it
1262 /// through getAnalysis interface.
1263 void MPPassManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
1265 assert (P->getPotentialPassManagerType() == PMT_ModulePassManager
1266 && "Unable to handle Pass that requires lower level Analysis pass");
1267 assert ((P->getPotentialPassManagerType() <
1268 RequiredPass->getPotentialPassManagerType())
1269 && "Unable to handle Pass that requires lower level Analysis pass");
1271 FunctionPassManagerImpl *FPP = OnTheFlyManagers[P];
1273 FPP = new FunctionPassManagerImpl(0);
1274 // FPP is the top level manager.
1275 FPP->setTopLevelManager(FPP);
1277 OnTheFlyManagers[P] = FPP;
1279 FPP->add(RequiredPass);
1281 // Register P as the last user of RequiredPass.
1282 SmallVector<Pass *, 12> LU;
1283 LU.push_back(RequiredPass);
1284 FPP->setLastUser(LU, P);
1287 /// Return function pass corresponding to PassInfo PI, that is
1288 /// required by module pass MP. Instantiate analysis pass, by using
1289 /// its runOnFunction() for function F.
1290 Pass* MPPassManager::getOnTheFlyPass(Pass *MP, const PassInfo *PI,
1292 AnalysisID AID = PI;
1293 FunctionPassManagerImpl *FPP = OnTheFlyManagers[MP];
1294 assert (FPP && "Unable to find on the fly pass");
1297 return (dynamic_cast<PMTopLevelManager *>(FPP))->findAnalysisPass(AID);
1301 //===----------------------------------------------------------------------===//
1302 // PassManagerImpl implementation
1304 /// run - Execute all of the passes scheduled for execution. Keep track of
1305 /// whether any of the passes modifies the module, and if so, return true.
1306 bool PassManagerImpl::run(Module &M) {
1308 bool Changed = false;
1310 TimingInfo::createTheTimeInfo();
1315 initializeAllAnalysisInfo();
1316 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
1317 MPPassManager *MP = getContainedManager(Index);
1318 Changed |= MP->runOnModule(M);
1323 //===----------------------------------------------------------------------===//
1324 // PassManager implementation
1326 /// Create new pass manager
1327 PassManager::PassManager() {
1328 PM = new PassManagerImpl(0);
1329 // PM is the top level manager
1330 PM->setTopLevelManager(PM);
1333 PassManager::~PassManager() {
1337 /// add - Add a pass to the queue of passes to run. This passes ownership of
1338 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
1339 /// will be destroyed as well, so there is no need to delete the pass. This
1340 /// implies that all passes MUST be allocated with 'new'.
1342 PassManager::add(Pass *P) {
1346 /// run - Execute all of the passes scheduled for execution. Keep track of
1347 /// whether any of the passes modifies the module, and if so, return true.
1349 PassManager::run(Module &M) {
1353 //===----------------------------------------------------------------------===//
1354 // TimingInfo Class - This class is used to calculate information about the
1355 // amount of time each pass takes to execute. This only happens with
1356 // -time-passes is enabled on the command line.
1358 bool llvm::TimePassesIsEnabled = false;
1359 static cl::opt<bool,true>
1360 EnableTiming("time-passes", cl::location(TimePassesIsEnabled),
1361 cl::desc("Time each pass, printing elapsed time for each on exit"));
1363 // createTheTimeInfo - This method either initializes the TheTimeInfo pointer to
1364 // a non null value (if the -time-passes option is enabled) or it leaves it
1365 // null. It may be called multiple times.
1366 void TimingInfo::createTheTimeInfo() {
1367 if (!TimePassesIsEnabled || TheTimeInfo) return;
1369 // Constructed the first time this is called, iff -time-passes is enabled.
1370 // This guarantees that the object will be constructed before static globals,
1371 // thus it will be destroyed before them.
1372 static ManagedStatic<TimingInfo> TTI;
1373 TheTimeInfo = &*TTI;
1376 /// If TimingInfo is enabled then start pass timer.
1377 void StartPassTimer(Pass *P) {
1379 TheTimeInfo->passStarted(P);
1382 /// If TimingInfo is enabled then stop pass timer.
1383 void StopPassTimer(Pass *P) {
1385 TheTimeInfo->passEnded(P);
1388 //===----------------------------------------------------------------------===//
1389 // PMStack implementation
1392 // Pop Pass Manager from the stack and clear its analysis info.
1393 void PMStack::pop() {
1395 PMDataManager *Top = this->top();
1396 Top->initializeAnalysisInfo();
1401 // Push PM on the stack and set its top level manager.
1402 void PMStack::push(PMDataManager *PM) {
1404 PMDataManager *Top = NULL;
1405 assert (PM && "Unable to push. Pass Manager expected");
1407 if (this->empty()) {
1412 PMTopLevelManager *TPM = Top->getTopLevelManager();
1414 assert (TPM && "Unable to find top level manager");
1415 TPM->addIndirectPassManager(PM);
1416 PM->setTopLevelManager(TPM);
1422 // Dump content of the pass manager stack.
1423 void PMStack::dump() {
1424 for(std::deque<PMDataManager *>::iterator I = S.begin(),
1425 E = S.end(); I != E; ++I) {
1426 Pass *P = dynamic_cast<Pass *>(*I);
1427 printf("%s ", P->getPassName());
1433 /// Find appropriate Module Pass Manager in the PM Stack and
1434 /// add self into that manager.
1435 void ModulePass::assignPassManager(PMStack &PMS,
1436 PassManagerType PreferredType) {
1438 // Find Module Pass Manager
1439 while(!PMS.empty()) {
1440 PassManagerType TopPMType = PMS.top()->getPassManagerType();
1441 if (TopPMType == PreferredType)
1442 break; // We found desired pass manager
1443 else if (TopPMType > PMT_ModulePassManager)
1444 PMS.pop(); // Pop children pass managers
1449 PMS.top()->add(this);
1452 /// Find appropriate Function Pass Manager or Call Graph Pass Manager
1453 /// in the PM Stack and add self into that manager.
1454 void FunctionPass::assignPassManager(PMStack &PMS,
1455 PassManagerType PreferredType) {
1457 // Find Module Pass Manager (TODO : Or Call Graph Pass Manager)
1458 while(!PMS.empty()) {
1459 if (PMS.top()->getPassManagerType() > PMT_FunctionPassManager)
1464 FPPassManager *FPP = dynamic_cast<FPPassManager *>(PMS.top());
1466 // Create new Function Pass Manager
1468 assert(!PMS.empty() && "Unable to create Function Pass Manager");
1469 PMDataManager *PMD = PMS.top();
1471 // [1] Create new Function Pass Manager
1472 FPP = new FPPassManager(PMD->getDepth() + 1);
1474 // [2] Set up new manager's top level manager
1475 PMTopLevelManager *TPM = PMD->getTopLevelManager();
1476 TPM->addIndirectPassManager(FPP);
1478 // [3] Assign manager to manage this new manager. This may create
1479 // and push new managers into PMS
1481 // If Call Graph Pass Manager is active then use it to manage
1482 // this new Function Pass manager.
1483 if (PMD->getPassManagerType() == PMT_CallGraphPassManager)
1484 FPP->assignPassManager(PMS, PMT_CallGraphPassManager);
1486 FPP->assignPassManager(PMS);
1488 // [4] Push new manager into PMS
1492 // Assign FPP as the manager of this pass.
1496 /// Find appropriate Basic Pass Manager or Call Graph Pass Manager
1497 /// in the PM Stack and add self into that manager.
1498 void BasicBlockPass::assignPassManager(PMStack &PMS,
1499 PassManagerType PreferredType) {
1501 BBPassManager *BBP = NULL;
1503 // Basic Pass Manager is a leaf pass manager. It does not handle
1504 // any other pass manager.
1506 BBP = dynamic_cast<BBPassManager *>(PMS.top());
1508 // If leaf manager is not Basic Block Pass manager then create new
1509 // basic Block Pass manager.
1512 assert(!PMS.empty() && "Unable to create BasicBlock Pass Manager");
1513 PMDataManager *PMD = PMS.top();
1515 // [1] Create new Basic Block Manager
1516 BBP = new BBPassManager(PMD->getDepth() + 1);
1518 // [2] Set up new manager's top level manager
1519 // Basic Block Pass Manager does not live by itself
1520 PMTopLevelManager *TPM = PMD->getTopLevelManager();
1521 TPM->addIndirectPassManager(BBP);
1523 // [3] Assign manager to manage this new manager. This may create
1524 // and push new managers into PMS
1525 BBP->assignPassManager(PMS);
1527 // [4] Push new manager into PMS
1531 // Assign BBP as the manager of this pass.
1535 PassManagerBase::~PassManagerBase() {}
1537 /*===-- C Bindings --------------------------------------------------------===*/
1539 LLVMPassManagerRef LLVMCreatePassManager() {
1540 return wrap(new PassManager());
1543 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef P) {
1544 return wrap(new FunctionPassManager(unwrap(P)));
1547 int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M) {
1548 return unwrap<PassManager>(PM)->run(*unwrap(M));
1551 int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM) {
1552 return unwrap<FunctionPassManager>(FPM)->doInitialization();
1555 int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F) {
1556 return unwrap<FunctionPassManager>(FPM)->run(*unwrap<Function>(F));
1559 int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM) {
1560 return unwrap<FunctionPassManager>(FPM)->doFinalization();
1563 void LLVMDisposePassManager(LLVMPassManagerRef PM) {