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 AnalysisUsage AnUsage;
430 P->getAnalysisUsage(AnUsage);
431 const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet();
432 for (std::vector<AnalysisID>::const_iterator I = RequiredSet.begin(),
433 E = RequiredSet.end(); I != E; ++I) {
435 Pass *AnalysisPass = findAnalysisPass(*I);
437 AnalysisPass = (*I)->createPass();
438 // Schedule this analysis run first only if it is not a lower level
439 // analysis pass. Lower level analsyis passes are run on the fly.
440 if (P->getPotentialPassManagerType () >=
441 AnalysisPass->getPotentialPassManagerType())
442 schedulePass(AnalysisPass);
448 // Now all required passes are available.
452 /// Find the pass that implements Analysis AID. Search immutable
453 /// passes and all pass managers. If desired pass is not found
454 /// then return NULL.
455 Pass *PMTopLevelManager::findAnalysisPass(AnalysisID AID) {
458 // Check pass managers
459 for (std::vector<PMDataManager *>::iterator I = PassManagers.begin(),
460 E = PassManagers.end(); P == NULL && I != E; ++I) {
461 PMDataManager *PMD = *I;
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 // Every class that derives from PMDataManager also derives from Pass
500 // (sometimes indirectly), but there's no inheritance relationship
501 // between PMDataManager and Pass, so we have to dynamic_cast to get
502 // from a PMDataManager* to a Pass*.
503 for (std::vector<PMDataManager *>::const_iterator I = PassManagers.begin(),
504 E = PassManagers.end(); I != E; ++I)
505 dynamic_cast<Pass *>(*I)->dumpPassStructure(1);
508 void PMTopLevelManager::dumpArguments() const {
510 if (PassDebugging < Arguments)
513 cerr << "Pass Arguments: ";
514 for (std::vector<PMDataManager *>::const_iterator I = PassManagers.begin(),
515 E = PassManagers.end(); I != E; ++I) {
516 PMDataManager *PMD = *I;
517 PMD->dumpPassArguments();
522 void PMTopLevelManager::initializeAllAnalysisInfo() {
524 for (std::vector<PMDataManager *>::iterator I = PassManagers.begin(),
525 E = PassManagers.end(); I != E; ++I) {
526 PMDataManager *PMD = *I;
527 PMD->initializeAnalysisInfo();
530 // Initailize other pass managers
531 for (std::vector<PMDataManager *>::iterator I = IndirectPassManagers.begin(),
532 E = IndirectPassManagers.end(); I != E; ++I)
533 (*I)->initializeAnalysisInfo();
537 PMTopLevelManager::~PMTopLevelManager() {
538 for (std::vector<PMDataManager *>::iterator I = PassManagers.begin(),
539 E = PassManagers.end(); I != E; ++I)
542 for (std::vector<ImmutablePass *>::iterator
543 I = ImmutablePasses.begin(), E = ImmutablePasses.end(); I != E; ++I)
547 //===----------------------------------------------------------------------===//
548 // PMDataManager implementation
550 /// Augement AvailableAnalysis by adding analysis made available by pass P.
551 void PMDataManager::recordAvailableAnalysis(Pass *P) {
553 if (const PassInfo *PI = P->getPassInfo()) {
554 AvailableAnalysis[PI] = P;
556 //This pass is the current implementation of all of the interfaces it
557 //implements as well.
558 const std::vector<const PassInfo*> &II = PI->getInterfacesImplemented();
559 for (unsigned i = 0, e = II.size(); i != e; ++i)
560 AvailableAnalysis[II[i]] = P;
564 // Return true if P preserves high level analysis used by other
565 // passes managed by this manager
566 bool PMDataManager::preserveHigherLevelAnalysis(Pass *P) {
568 AnalysisUsage AnUsage;
569 P->getAnalysisUsage(AnUsage);
571 if (AnUsage.getPreservesAll())
574 const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
575 for (std::vector<Pass *>::iterator I = HigherLevelAnalysis.begin(),
576 E = HigherLevelAnalysis.end(); I != E; ++I) {
578 if (!dynamic_cast<ImmutablePass*>(P1) &&
579 std::find(PreservedSet.begin(), PreservedSet.end(),
580 P1->getPassInfo()) ==
588 /// verifyPreservedAnalysis -- Verify analysis presreved by pass P.
589 void PMDataManager::verifyPreservedAnalysis(Pass *P) {
590 AnalysisUsage AnUsage;
591 P->getAnalysisUsage(AnUsage);
592 const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
594 // Verify preserved analysis
595 for (std::vector<AnalysisID>::const_iterator I = PreservedSet.begin(),
596 E = PreservedSet.end(); I != E; ++I) {
598 Pass *AP = findAnalysisPass(AID, true);
600 AP->verifyAnalysis();
604 /// Remove Analyss not preserved by Pass P
605 void PMDataManager::removeNotPreservedAnalysis(Pass *P) {
606 AnalysisUsage AnUsage;
607 P->getAnalysisUsage(AnUsage);
608 if (AnUsage.getPreservesAll())
611 const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
612 for (std::map<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(),
613 E = AvailableAnalysis.end(); I != E; ) {
614 std::map<AnalysisID, Pass*>::iterator Info = I++;
615 if (!dynamic_cast<ImmutablePass*>(Info->second)
616 && std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) ==
618 // Remove this analysis
619 AvailableAnalysis.erase(Info);
622 // Check inherited analysis also. If P is not preserving analysis
623 // provided by parent manager then remove it here.
624 for (unsigned Index = 0; Index < PMT_Last; ++Index) {
626 if (!InheritedAnalysis[Index])
629 for (std::map<AnalysisID, Pass*>::iterator
630 I = InheritedAnalysis[Index]->begin(),
631 E = InheritedAnalysis[Index]->end(); I != E; ) {
632 std::map<AnalysisID, Pass *>::iterator Info = I++;
633 if (!dynamic_cast<ImmutablePass*>(Info->second) &&
634 std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) ==
636 // Remove this analysis
637 InheritedAnalysis[Index]->erase(Info);
643 /// Remove analysis passes that are not used any longer
644 void PMDataManager::removeDeadPasses(Pass *P, const char *Msg,
645 enum PassDebuggingString DBG_STR) {
647 SmallVector<Pass *, 12> DeadPasses;
649 // If this is a on the fly manager then it does not have TPM.
653 TPM->collectLastUses(DeadPasses, P);
655 for (SmallVector<Pass *, 12>::iterator I = DeadPasses.begin(),
656 E = DeadPasses.end(); I != E; ++I) {
658 dumpPassInfo(*I, FREEING_MSG, DBG_STR, Msg);
660 if (TheTimeInfo) TheTimeInfo->passStarted(*I);
661 (*I)->releaseMemory();
662 if (TheTimeInfo) TheTimeInfo->passEnded(*I);
664 std::map<AnalysisID, Pass*>::iterator Pos =
665 AvailableAnalysis.find((*I)->getPassInfo());
667 // It is possible that pass is already removed from the AvailableAnalysis
668 if (Pos != AvailableAnalysis.end())
669 AvailableAnalysis.erase(Pos);
673 /// Add pass P into the PassVector. Update
674 /// AvailableAnalysis appropriately if ProcessAnalysis is true.
675 void PMDataManager::add(Pass *P,
676 bool ProcessAnalysis) {
678 // This manager is going to manage pass P. Set up analysis resolver
680 AnalysisResolver *AR = new AnalysisResolver(*this);
683 // If a FunctionPass F is the last user of ModulePass info M
684 // then the F's manager, not F, records itself as a last user of M.
685 SmallVector<Pass *, 12> TransferLastUses;
687 if (ProcessAnalysis) {
689 // At the moment, this pass is the last user of all required passes.
690 SmallVector<Pass *, 12> LastUses;
691 SmallVector<Pass *, 8> RequiredPasses;
692 SmallVector<AnalysisID, 8> ReqAnalysisNotAvailable;
694 unsigned PDepth = this->getDepth();
696 collectRequiredAnalysis(RequiredPasses,
697 ReqAnalysisNotAvailable, P);
698 for (SmallVector<Pass *, 8>::iterator I = RequiredPasses.begin(),
699 E = RequiredPasses.end(); I != E; ++I) {
700 Pass *PRequired = *I;
703 PMDataManager &DM = PRequired->getResolver()->getPMDataManager();
704 RDepth = DM.getDepth();
706 if (PDepth == RDepth)
707 LastUses.push_back(PRequired);
708 else if (PDepth > RDepth) {
709 // Let the parent claim responsibility of last use
710 TransferLastUses.push_back(PRequired);
711 // Keep track of higher level analysis used by this manager.
712 HigherLevelAnalysis.push_back(PRequired);
714 assert (0 && "Unable to accomodate Required Pass");
717 // Set P as P's last user until someone starts using P.
718 // However, if P is a Pass Manager then it does not need
719 // to record its last user.
720 if (!dynamic_cast<PMDataManager *>(P))
721 LastUses.push_back(P);
722 TPM->setLastUser(LastUses, P);
724 if (!TransferLastUses.empty()) {
725 Pass *My_PM = dynamic_cast<Pass *>(this);
726 TPM->setLastUser(TransferLastUses, My_PM);
727 TransferLastUses.clear();
730 // Now, take care of required analysises that are not available.
731 for (SmallVector<AnalysisID, 8>::iterator
732 I = ReqAnalysisNotAvailable.begin(),
733 E = ReqAnalysisNotAvailable.end() ;I != E; ++I) {
734 Pass *AnalysisPass = (*I)->createPass();
735 this->addLowerLevelRequiredPass(P, AnalysisPass);
738 // Take a note of analysis required and made available by this pass.
739 // Remove the analysis not preserved by this pass
740 removeNotPreservedAnalysis(P);
741 recordAvailableAnalysis(P);
745 PassVector.push_back(P);
749 /// Populate RP with analysis pass that are required by
750 /// pass P and are available. Populate RP_NotAvail with analysis
751 /// pass that are required by pass P but are not available.
752 void PMDataManager::collectRequiredAnalysis(SmallVector<Pass *, 8>&RP,
753 SmallVector<AnalysisID, 8> &RP_NotAvail,
755 AnalysisUsage AnUsage;
756 P->getAnalysisUsage(AnUsage);
757 const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet();
758 for (std::vector<AnalysisID>::const_iterator
759 I = RequiredSet.begin(), E = RequiredSet.end();
762 if (Pass *AnalysisPass = findAnalysisPass(*I, true))
763 RP.push_back(AnalysisPass);
765 RP_NotAvail.push_back(AID);
768 const std::vector<AnalysisID> &IDs = AnUsage.getRequiredTransitiveSet();
769 for (std::vector<AnalysisID>::const_iterator I = IDs.begin(),
770 E = IDs.end(); I != E; ++I) {
772 if (Pass *AnalysisPass = findAnalysisPass(*I, true))
773 RP.push_back(AnalysisPass);
775 RP_NotAvail.push_back(AID);
779 // All Required analyses should be available to the pass as it runs! Here
780 // we fill in the AnalysisImpls member of the pass so that it can
781 // successfully use the getAnalysis() method to retrieve the
782 // implementations it needs.
784 void PMDataManager::initializeAnalysisImpl(Pass *P) {
785 AnalysisUsage AnUsage;
786 P->getAnalysisUsage(AnUsage);
788 for (std::vector<const PassInfo *>::const_iterator
789 I = AnUsage.getRequiredSet().begin(),
790 E = AnUsage.getRequiredSet().end(); I != E; ++I) {
791 Pass *Impl = findAnalysisPass(*I, true);
793 // This may be analysis pass that is initialized on the fly.
794 // If that is not the case then it will raise an assert when it is used.
796 AnalysisResolver *AR = P->getResolver();
797 AR->addAnalysisImplsPair(*I, Impl);
801 /// Find the pass that implements Analysis AID. If desired pass is not found
802 /// then return NULL.
803 Pass *PMDataManager::findAnalysisPass(AnalysisID AID, bool SearchParent) {
805 // Check if AvailableAnalysis map has one entry.
806 std::map<AnalysisID, Pass*>::const_iterator I = AvailableAnalysis.find(AID);
808 if (I != AvailableAnalysis.end())
811 // Search Parents through TopLevelManager
813 return TPM->findAnalysisPass(AID);
818 // Print list of passes that are last used by P.
819 void PMDataManager::dumpLastUses(Pass *P, unsigned Offset) const{
821 SmallVector<Pass *, 12> LUses;
823 // If this is a on the fly manager then it does not have TPM.
827 TPM->collectLastUses(LUses, P);
829 for (SmallVector<Pass *, 12>::iterator I = LUses.begin(),
830 E = LUses.end(); I != E; ++I) {
831 llvm::cerr << "--" << std::string(Offset*2, ' ');
832 (*I)->dumpPassStructure(0);
836 void PMDataManager::dumpPassArguments() const {
837 for(std::vector<Pass *>::const_iterator I = PassVector.begin(),
838 E = PassVector.end(); I != E; ++I) {
839 if (PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I))
840 PMD->dumpPassArguments();
842 if (const PassInfo *PI = (*I)->getPassInfo())
843 if (!PI->isAnalysisGroup())
844 cerr << " -" << PI->getPassArgument();
848 void PMDataManager::dumpPassInfo(Pass *P, enum PassDebuggingString S1,
849 enum PassDebuggingString S2,
851 if (PassDebugging < Executions)
853 cerr << (void*)this << std::string(getDepth()*2+1, ' ');
856 cerr << "Executing Pass '" << P->getPassName();
858 case MODIFICATION_MSG:
859 cerr << "Made Modification '" << P->getPassName();
862 cerr << " Freeing Pass '" << P->getPassName();
868 case ON_BASICBLOCK_MSG:
869 cerr << "' on BasicBlock '" << Msg << "'...\n";
871 case ON_FUNCTION_MSG:
872 cerr << "' on Function '" << Msg << "'...\n";
875 cerr << "' on Module '" << Msg << "'...\n";
878 cerr << "' on Loop " << Msg << "'...\n";
881 cerr << "' on Call Graph " << Msg << "'...\n";
888 void PMDataManager::dumpAnalysisSetInfo(const char *Msg, Pass *P,
889 const std::vector<AnalysisID> &Set)
891 if (PassDebugging >= Details && !Set.empty()) {
892 cerr << (void*)P << std::string(getDepth()*2+3, ' ') << Msg << " Analyses:";
893 for (unsigned i = 0; i != Set.size(); ++i) {
895 cerr << " " << Set[i]->getPassName();
901 /// Add RequiredPass into list of lower level passes required by pass P.
902 /// RequiredPass is run on the fly by Pass Manager when P requests it
903 /// through getAnalysis interface.
904 /// This should be handled by specific pass manager.
905 void PMDataManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
907 TPM->dumpArguments();
911 // Module Level pass may required Function Level analysis info
912 // (e.g. dominator info). Pass manager uses on the fly function pass manager
913 // to provide this on demand. In that case, in Pass manager terminology,
914 // module level pass is requiring lower level analysis info managed by
915 // lower level pass manager.
917 // When Pass manager is not able to order required analysis info, Pass manager
918 // checks whether any lower level manager will be able to provide this
919 // analysis info on demand or not.
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)
932 //===----------------------------------------------------------------------===//
933 // NOTE: Is this the right place to define this method ?
934 // getAnalysisToUpdate - Return an analysis result or null if it doesn't exist
935 Pass *AnalysisResolver::getAnalysisToUpdate(AnalysisID ID, bool dir) const {
936 return PM.findAnalysisPass(ID, dir);
939 Pass *AnalysisResolver::findImplPass(Pass *P, const PassInfo *AnalysisPI,
941 return PM.getOnTheFlyPass(P, AnalysisPI, F);
944 //===----------------------------------------------------------------------===//
945 // BBPassManager implementation
947 /// Execute all of the passes scheduled for execution by invoking
948 /// runOnBasicBlock method. Keep track of whether any of the passes modifies
949 /// the function, and if so, return true.
951 BBPassManager::runOnFunction(Function &F) {
953 if (F.isDeclaration())
956 bool Changed = doInitialization(F);
958 for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
959 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
960 BasicBlockPass *BP = getContainedPass(Index);
961 AnalysisUsage AnUsage;
962 BP->getAnalysisUsage(AnUsage);
964 dumpPassInfo(BP, EXECUTION_MSG, ON_BASICBLOCK_MSG, I->getNameStart());
965 dumpAnalysisSetInfo("Required", BP, AnUsage.getRequiredSet());
967 initializeAnalysisImpl(BP);
969 if (TheTimeInfo) TheTimeInfo->passStarted(BP);
970 Changed |= BP->runOnBasicBlock(*I);
971 if (TheTimeInfo) TheTimeInfo->passEnded(BP);
974 dumpPassInfo(BP, MODIFICATION_MSG, ON_BASICBLOCK_MSG,
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 AnalysisResolver *AR = new AnalysisResolver(*FPM);
1043 FPM->setResolver(AR);
1048 FunctionPassManager::~FunctionPassManager() {
1052 /// add - Add a pass to the queue of passes to run. This passes
1053 /// ownership of the Pass to the PassManager. When the
1054 /// PassManager_X is destroyed, the pass will be destroyed as well, so
1055 /// there is no need to delete the pass. (TODO delete passes.)
1056 /// This implies that all passes MUST be allocated with 'new'.
1057 void FunctionPassManager::add(Pass *P) {
1061 /// run - Execute all of the passes scheduled for execution. Keep
1062 /// track of whether any of the passes modifies the function, and if
1063 /// so, return true.
1065 bool FunctionPassManager::run(Function &F) {
1067 if (MP->materializeFunction(&F, &errstr)) {
1068 cerr << "Error reading bitcode file: " << errstr << "\n";
1075 /// doInitialization - Run all of the initializers for the function passes.
1077 bool FunctionPassManager::doInitialization() {
1078 return FPM->doInitialization(*MP->getModule());
1081 /// doFinalization - Run all of the finalizers for the function passes.
1083 bool FunctionPassManager::doFinalization() {
1084 return FPM->doFinalization(*MP->getModule());
1087 //===----------------------------------------------------------------------===//
1088 // FunctionPassManagerImpl implementation
1090 inline bool FunctionPassManagerImpl::doInitialization(Module &M) {
1091 bool Changed = false;
1093 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
1094 FPPassManager *FP = getContainedManager(Index);
1095 Changed |= FP->doInitialization(M);
1101 inline bool FunctionPassManagerImpl::doFinalization(Module &M) {
1102 bool Changed = false;
1104 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
1105 FPPassManager *FP = getContainedManager(Index);
1106 Changed |= FP->doFinalization(M);
1112 // Execute all the passes managed by this top level manager.
1113 // Return true if any function is modified by a pass.
1114 bool FunctionPassManagerImpl::run(Function &F) {
1116 bool Changed = false;
1118 TimingInfo::createTheTimeInfo();
1123 initializeAllAnalysisInfo();
1124 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
1125 FPPassManager *FP = getContainedManager(Index);
1126 Changed |= FP->runOnFunction(F);
1131 //===----------------------------------------------------------------------===//
1132 // FPPassManager implementation
1134 char FPPassManager::ID = 0;
1135 /// Print passes managed by this manager
1136 void FPPassManager::dumpPassStructure(unsigned Offset) {
1137 llvm::cerr << std::string(Offset*2, ' ') << "FunctionPass Manager\n";
1138 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1139 FunctionPass *FP = getContainedPass(Index);
1140 FP->dumpPassStructure(Offset + 1);
1141 dumpLastUses(FP, Offset+1);
1146 /// Execute all of the passes scheduled for execution by invoking
1147 /// runOnFunction method. Keep track of whether any of the passes modifies
1148 /// the function, and if so, return true.
1149 bool FPPassManager::runOnFunction(Function &F) {
1151 bool Changed = false;
1153 if (F.isDeclaration())
1156 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1157 FunctionPass *FP = getContainedPass(Index);
1159 AnalysisUsage AnUsage;
1160 FP->getAnalysisUsage(AnUsage);
1162 dumpPassInfo(FP, EXECUTION_MSG, ON_FUNCTION_MSG, F.getNameStart());
1163 dumpAnalysisSetInfo("Required", FP, AnUsage.getRequiredSet());
1165 initializeAnalysisImpl(FP);
1167 if (TheTimeInfo) TheTimeInfo->passStarted(FP);
1168 Changed |= FP->runOnFunction(F);
1169 if (TheTimeInfo) TheTimeInfo->passEnded(FP);
1172 dumpPassInfo(FP, MODIFICATION_MSG, ON_FUNCTION_MSG, F.getNameStart());
1173 dumpAnalysisSetInfo("Preserved", FP, AnUsage.getPreservedSet());
1175 verifyPreservedAnalysis(FP);
1176 removeNotPreservedAnalysis(FP);
1177 recordAvailableAnalysis(FP);
1178 removeDeadPasses(FP, F.getNameStart(), ON_FUNCTION_MSG);
1183 bool FPPassManager::runOnModule(Module &M) {
1185 bool Changed = doInitialization(M);
1187 for(Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
1188 this->runOnFunction(*I);
1190 return Changed |= doFinalization(M);
1193 inline bool FPPassManager::doInitialization(Module &M) {
1194 bool Changed = false;
1196 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1197 FunctionPass *FP = getContainedPass(Index);
1198 Changed |= FP->doInitialization(M);
1204 inline bool FPPassManager::doFinalization(Module &M) {
1205 bool Changed = false;
1207 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1208 FunctionPass *FP = getContainedPass(Index);
1209 Changed |= FP->doFinalization(M);
1215 //===----------------------------------------------------------------------===//
1216 // MPPassManager implementation
1218 /// Execute all of the passes scheduled for execution by invoking
1219 /// runOnModule method. Keep track of whether any of the passes modifies
1220 /// the module, and if so, return true.
1222 MPPassManager::runOnModule(Module &M) {
1223 bool Changed = false;
1225 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1226 ModulePass *MP = getContainedPass(Index);
1228 AnalysisUsage AnUsage;
1229 MP->getAnalysisUsage(AnUsage);
1231 dumpPassInfo(MP, EXECUTION_MSG, ON_MODULE_MSG,
1232 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,
1243 M.getModuleIdentifier().c_str());
1244 dumpAnalysisSetInfo("Preserved", MP, AnUsage.getPreservedSet());
1246 verifyPreservedAnalysis(MP);
1247 removeNotPreservedAnalysis(MP);
1248 recordAvailableAnalysis(MP);
1249 removeDeadPasses(MP, M.getModuleIdentifier().c_str(), ON_MODULE_MSG);
1254 /// Add RequiredPass into list of lower level passes required by pass P.
1255 /// RequiredPass is run on the fly by Pass Manager when P requests it
1256 /// through getAnalysis interface.
1257 void MPPassManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
1259 assert (P->getPotentialPassManagerType() == PMT_ModulePassManager
1260 && "Unable to handle Pass that requires lower level Analysis pass");
1261 assert ((P->getPotentialPassManagerType() <
1262 RequiredPass->getPotentialPassManagerType())
1263 && "Unable to handle Pass that requires lower level Analysis pass");
1265 FunctionPassManagerImpl *FPP = OnTheFlyManagers[P];
1267 FPP = new FunctionPassManagerImpl(0);
1268 // FPP is the top level manager.
1269 FPP->setTopLevelManager(FPP);
1271 OnTheFlyManagers[P] = FPP;
1273 FPP->add(RequiredPass);
1275 // Register P as the last user of RequiredPass.
1276 SmallVector<Pass *, 12> LU;
1277 LU.push_back(RequiredPass);
1278 FPP->setLastUser(LU, P);
1281 /// Return function pass corresponding to PassInfo PI, that is
1282 /// required by module pass MP. Instantiate analysis pass, by using
1283 /// its runOnFunction() for function F.
1284 Pass* MPPassManager::getOnTheFlyPass(Pass *MP, const PassInfo *PI,
1286 AnalysisID AID = PI;
1287 FunctionPassManagerImpl *FPP = OnTheFlyManagers[MP];
1288 assert (FPP && "Unable to find on the fly pass");
1291 return (dynamic_cast<PMTopLevelManager *>(FPP))->findAnalysisPass(AID);
1295 //===----------------------------------------------------------------------===//
1296 // PassManagerImpl implementation
1298 /// run - Execute all of the passes scheduled for execution. Keep track of
1299 /// whether any of the passes modifies the module, and if so, return true.
1300 bool PassManagerImpl::run(Module &M) {
1302 bool Changed = false;
1304 TimingInfo::createTheTimeInfo();
1309 initializeAllAnalysisInfo();
1310 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
1311 MPPassManager *MP = getContainedManager(Index);
1312 Changed |= MP->runOnModule(M);
1317 //===----------------------------------------------------------------------===//
1318 // PassManager implementation
1320 /// Create new pass manager
1321 PassManager::PassManager() {
1322 PM = new PassManagerImpl(0);
1323 // PM is the top level manager
1324 PM->setTopLevelManager(PM);
1327 PassManager::~PassManager() {
1331 /// add - Add a pass to the queue of passes to run. This passes ownership of
1332 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
1333 /// will be destroyed as well, so there is no need to delete the pass. This
1334 /// implies that all passes MUST be allocated with 'new'.
1336 PassManager::add(Pass *P) {
1340 /// run - Execute all of the passes scheduled for execution. Keep track of
1341 /// whether any of the passes modifies the module, and if so, return true.
1343 PassManager::run(Module &M) {
1347 //===----------------------------------------------------------------------===//
1348 // TimingInfo Class - This class is used to calculate information about the
1349 // amount of time each pass takes to execute. This only happens with
1350 // -time-passes is enabled on the command line.
1352 bool llvm::TimePassesIsEnabled = false;
1353 static cl::opt<bool,true>
1354 EnableTiming("time-passes", cl::location(TimePassesIsEnabled),
1355 cl::desc("Time each pass, printing elapsed time for each on exit"));
1357 // createTheTimeInfo - This method either initializes the TheTimeInfo pointer to
1358 // a non null value (if the -time-passes option is enabled) or it leaves it
1359 // null. It may be called multiple times.
1360 void TimingInfo::createTheTimeInfo() {
1361 if (!TimePassesIsEnabled || TheTimeInfo) return;
1363 // Constructed the first time this is called, iff -time-passes is enabled.
1364 // This guarantees that the object will be constructed before static globals,
1365 // thus it will be destroyed before them.
1366 static ManagedStatic<TimingInfo> TTI;
1367 TheTimeInfo = &*TTI;
1370 /// If TimingInfo is enabled then start pass timer.
1371 void StartPassTimer(Pass *P) {
1373 TheTimeInfo->passStarted(P);
1376 /// If TimingInfo is enabled then stop pass timer.
1377 void StopPassTimer(Pass *P) {
1379 TheTimeInfo->passEnded(P);
1382 //===----------------------------------------------------------------------===//
1383 // PMStack implementation
1386 // Pop Pass Manager from the stack and clear its analysis info.
1387 void PMStack::pop() {
1389 PMDataManager *Top = this->top();
1390 Top->initializeAnalysisInfo();
1395 // Push PM on the stack and set its top level manager.
1396 void PMStack::push(PMDataManager *PM) {
1398 PMDataManager *Top = NULL;
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
1475 // If Call Graph Pass Manager is active then use it to manage
1476 // this new Function Pass manager.
1477 if (PMD->getPassManagerType() == PMT_CallGraphPassManager)
1478 FPP->assignPassManager(PMS, PMT_CallGraphPassManager);
1480 FPP->assignPassManager(PMS);
1482 // [4] Push new manager into PMS
1486 // Assign FPP as the manager of this pass.
1490 /// Find appropriate Basic Pass Manager or Call Graph Pass Manager
1491 /// in the PM Stack and add self into that manager.
1492 void BasicBlockPass::assignPassManager(PMStack &PMS,
1493 PassManagerType PreferredType) {
1495 BBPassManager *BBP = NULL;
1497 // Basic Pass Manager is a leaf pass manager. It does not handle
1498 // any other pass manager.
1500 BBP = dynamic_cast<BBPassManager *>(PMS.top());
1502 // If leaf manager is not Basic Block Pass manager then create new
1503 // basic Block Pass manager.
1506 assert(!PMS.empty() && "Unable to create BasicBlock Pass Manager");
1507 PMDataManager *PMD = PMS.top();
1509 // [1] Create new Basic Block Manager
1510 BBP = new BBPassManager(PMD->getDepth() + 1);
1512 // [2] Set up new manager's top level manager
1513 // Basic Block Pass Manager does not live by itself
1514 PMTopLevelManager *TPM = PMD->getTopLevelManager();
1515 TPM->addIndirectPassManager(BBP);
1517 // [3] Assign manager to manage this new manager. This may create
1518 // and push new managers into PMS
1519 BBP->assignPassManager(PMS);
1521 // [4] Push new manager into PMS
1525 // Assign BBP as the manager of this pass.
1529 PassManagerBase::~PassManagerBase() {}
1531 /*===-- C Bindings --------------------------------------------------------===*/
1533 LLVMPassManagerRef LLVMCreatePassManager() {
1534 return wrap(new PassManager());
1537 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef P) {
1538 return wrap(new FunctionPassManager(unwrap(P)));
1541 int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M) {
1542 return unwrap<PassManager>(PM)->run(*unwrap(M));
1545 int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM) {
1546 return unwrap<FunctionPassManager>(FPM)->doInitialization();
1549 int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F) {
1550 return unwrap<FunctionPassManager>(FPM)->run(*unwrap<Function>(F));
1553 int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM) {
1554 return unwrap<FunctionPassManager>(FPM)->doFinalization();
1557 void LLVMDisposePassManager(LLVMPassManagerRef PM) {