Add preparePassManager() hook. This allows each pass to check whether
[oota-llvm.git] / lib / VMCore / PassManager.cpp
1 //===- PassManager.cpp - LLVM Pass Infrastructure Implementation ----------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Devang Patel and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the LLVM Pass Manager infrastructure. 
11 //
12 //===----------------------------------------------------------------------===//
13
14
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 <algorithm>
23 #include <vector>
24 #include <map>
25
26 // See PassManagers.h for Pass Manager infrastructure overview.
27
28 namespace llvm {
29
30 //===----------------------------------------------------------------------===//
31 // Pass debugging information.  Often it is useful to find out what pass is
32 // running when a crash occurs in a utility.  When this library is compiled with
33 // debugging on, a command line option (--debug-pass) is enabled that causes the
34 // pass name to be printed before it executes.
35 //
36
37 // Different debug levels that can be enabled...
38 enum PassDebugLevel {
39   None, Arguments, Structure, Executions, Details
40 };
41
42 static cl::opt<enum PassDebugLevel>
43 PassDebugging("debug-pass", cl::Hidden,
44                   cl::desc("Print PassManager debugging information"),
45                   cl::values(
46   clEnumVal(None      , "disable debug output"),
47   clEnumVal(Arguments , "print pass arguments to pass to 'opt'"),
48   clEnumVal(Structure , "print pass structure before run()"),
49   clEnumVal(Executions, "print pass name before it is executed"),
50   clEnumVal(Details   , "print pass details when it is executed"),
51                              clEnumValEnd));
52 } // End of llvm namespace
53
54 namespace {
55
56 //===----------------------------------------------------------------------===//
57 // BBPassManager
58 //
59 /// BBPassManager manages BasicBlockPass. It batches all the
60 /// pass together and sequence them to process one basic block before
61 /// processing next basic block.
62 class VISIBILITY_HIDDEN BBPassManager : public PMDataManager, 
63                                         public FunctionPass {
64
65 public:
66   BBPassManager(int Depth) : PMDataManager(Depth) { }
67
68   /// Execute all of the passes scheduled for execution.  Keep track of
69   /// whether any of the passes modifies the function, and if so, return true.
70   bool runOnFunction(Function &F);
71
72   /// Pass Manager itself does not invalidate any analysis info.
73   void getAnalysisUsage(AnalysisUsage &Info) const {
74     Info.setPreservesAll();
75   }
76
77   bool doInitialization(Module &M);
78   bool doInitialization(Function &F);
79   bool doFinalization(Module &M);
80   bool doFinalization(Function &F);
81
82   virtual const char *getPassName() const {
83     return "BasicBlock Pass  Manager";
84   }
85
86   // Print passes managed by this manager
87   void dumpPassStructure(unsigned Offset) {
88     llvm::cerr << std::string(Offset*2, ' ') << "BasicBlockPass Manager\n";
89     for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
90       BasicBlockPass *BP = getContainedPass(Index);
91       BP->dumpPassStructure(Offset + 1);
92       dumpLastUses(BP, Offset+1);
93     }
94   }
95
96   BasicBlockPass *getContainedPass(unsigned N) {
97     assert ( N < PassVector.size() && "Pass number out of range!");
98     BasicBlockPass *BP = static_cast<BasicBlockPass *>(PassVector[N]);
99     return BP;
100   }
101
102   virtual PassManagerType getPassManagerType() const { 
103     return PMT_BasicBlockPassManager; 
104   }
105 };
106
107 }
108
109 namespace llvm {
110
111 //===----------------------------------------------------------------------===//
112 // FunctionPassManagerImpl
113 //
114 /// FunctionPassManagerImpl manages FPPassManagers
115 class FunctionPassManagerImpl : public Pass,
116                                 public PMDataManager,
117                                 public PMTopLevelManager {
118 public:
119
120   FunctionPassManagerImpl(int Depth) : PMDataManager(Depth),
121                                        PMTopLevelManager(TLM_Function) { }
122
123   /// add - Add a pass to the queue of passes to run.  This passes ownership of
124   /// the Pass to the PassManager.  When the PassManager is destroyed, the pass
125   /// will be destroyed as well, so there is no need to delete the pass.  This
126   /// implies that all passes MUST be allocated with 'new'.
127   void add(Pass *P) {
128     schedulePass(P);
129   }
130  
131   /// run - Execute all of the passes scheduled for execution.  Keep track of
132   /// whether any of the passes modifies the module, and if so, return true.
133   bool run(Function &F);
134
135   /// doInitialization - Run all of the initializers for the function passes.
136   ///
137   bool doInitialization(Module &M);
138   
139   /// doFinalization - Run all of the initializers for the function passes.
140   ///
141   bool doFinalization(Module &M);
142
143   /// Pass Manager itself does not invalidate any analysis info.
144   void getAnalysisUsage(AnalysisUsage &Info) const {
145     Info.setPreservesAll();
146   }
147
148   inline void addTopLevelPass(Pass *P) {
149
150     if (ImmutablePass *IP = dynamic_cast<ImmutablePass *> (P)) {
151       
152       // P is a immutable pass and it will be managed by this
153       // top level manager. Set up analysis resolver to connect them.
154       AnalysisResolver *AR = new AnalysisResolver(*this);
155       P->setResolver(AR);
156       initializeAnalysisImpl(P);
157       addImmutablePass(IP);
158       recordAvailableAnalysis(IP);
159     } else {
160       P->assignPassManager(activeStack);
161     }
162
163   }
164
165   FPPassManager *getContainedManager(unsigned N) {
166     assert ( N < PassManagers.size() && "Pass number out of range!");
167     FPPassManager *FP = static_cast<FPPassManager *>(PassManagers[N]);
168     return FP;
169   }
170
171 };
172
173 //===----------------------------------------------------------------------===//
174 // MPPassManager
175 //
176 /// MPPassManager manages ModulePasses and function pass managers.
177 /// It batches all Module passes  passes and function pass managers together and
178 /// sequence them to process one module.
179 class MPPassManager : public Pass, public PMDataManager {
180  
181 public:
182   MPPassManager(int Depth) : PMDataManager(Depth) { }
183   
184   /// run - Execute all of the passes scheduled for execution.  Keep track of
185   /// whether any of the passes modifies the module, and if so, return true.
186   bool runOnModule(Module &M);
187
188   /// Pass Manager itself does not invalidate any analysis info.
189   void getAnalysisUsage(AnalysisUsage &Info) const {
190     Info.setPreservesAll();
191   }
192
193   virtual const char *getPassName() const {
194     return "Module Pass Manager";
195   }
196
197   // Print passes managed by this manager
198   void dumpPassStructure(unsigned Offset) {
199     llvm::cerr << std::string(Offset*2, ' ') << "ModulePass Manager\n";
200     for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
201       ModulePass *MP = getContainedPass(Index);
202       MP->dumpPassStructure(Offset + 1);
203       dumpLastUses(MP, Offset+1);
204     }
205   }
206
207   ModulePass *getContainedPass(unsigned N) {
208     assert ( N < PassVector.size() && "Pass number out of range!");
209     ModulePass *MP = static_cast<ModulePass *>(PassVector[N]);
210     return MP;
211   }
212
213   virtual PassManagerType getPassManagerType() const { 
214     return PMT_ModulePassManager; 
215   }
216 };
217
218 //===----------------------------------------------------------------------===//
219 // PassManagerImpl
220 //
221 /// PassManagerImpl manages MPPassManagers
222 class PassManagerImpl : public Pass,
223                         public PMDataManager,
224                         public PMTopLevelManager {
225
226 public:
227
228   PassManagerImpl(int Depth) : PMDataManager(Depth),
229                                PMTopLevelManager(TLM_Pass) { }
230
231   /// add - Add a pass to the queue of passes to run.  This passes ownership of
232   /// the Pass to the PassManager.  When the PassManager is destroyed, the pass
233   /// will be destroyed as well, so there is no need to delete the pass.  This
234   /// implies that all passes MUST be allocated with 'new'.
235   void add(Pass *P) {
236     schedulePass(P);
237   }
238  
239   /// run - Execute all of the passes scheduled for execution.  Keep track of
240   /// whether any of the passes modifies the module, and if so, return true.
241   bool run(Module &M);
242
243   /// Pass Manager itself does not invalidate any analysis info.
244   void getAnalysisUsage(AnalysisUsage &Info) const {
245     Info.setPreservesAll();
246   }
247
248   inline void addTopLevelPass(Pass *P) {
249
250     if (ImmutablePass *IP = dynamic_cast<ImmutablePass *> (P)) {
251       
252       // P is a immutable pass and it will be managed by this
253       // top level manager. Set up analysis resolver to connect them.
254       AnalysisResolver *AR = new AnalysisResolver(*this);
255       P->setResolver(AR);
256       initializeAnalysisImpl(P);
257       addImmutablePass(IP);
258       recordAvailableAnalysis(IP);
259     } else {
260       P->assignPassManager(activeStack);
261     }
262
263   }
264
265   MPPassManager *getContainedManager(unsigned N) {
266     assert ( N < PassManagers.size() && "Pass number out of range!");
267     MPPassManager *MP = static_cast<MPPassManager *>(PassManagers[N]);
268     return MP;
269   }
270
271 };
272
273 } // End of llvm namespace
274
275 namespace {
276
277 //===----------------------------------------------------------------------===//
278 // TimingInfo Class - This class is used to calculate information about the
279 // amount of time each pass takes to execute.  This only happens when
280 // -time-passes is enabled on the command line.
281 //
282
283 class VISIBILITY_HIDDEN TimingInfo {
284   std::map<Pass*, Timer> TimingData;
285   TimerGroup TG;
286
287 public:
288   // Use 'create' member to get this.
289   TimingInfo() : TG("... Pass execution timing report ...") {}
290   
291   // TimingDtor - Print out information about timing information
292   ~TimingInfo() {
293     // Delete all of the timers...
294     TimingData.clear();
295     // TimerGroup is deleted next, printing the report.
296   }
297
298   // createTheTimeInfo - This method either initializes the TheTimeInfo pointer
299   // to a non null value (if the -time-passes option is enabled) or it leaves it
300   // null.  It may be called multiple times.
301   static void createTheTimeInfo();
302
303   void passStarted(Pass *P) {
304
305     if (dynamic_cast<PMDataManager *>(P)) 
306       return;
307
308     std::map<Pass*, Timer>::iterator I = TimingData.find(P);
309     if (I == TimingData.end())
310       I=TimingData.insert(std::make_pair(P, Timer(P->getPassName(), TG))).first;
311     I->second.startTimer();
312   }
313   void passEnded(Pass *P) {
314
315     if (dynamic_cast<PMDataManager *>(P)) 
316       return;
317
318     std::map<Pass*, Timer>::iterator I = TimingData.find(P);
319     assert (I != TimingData.end() && "passStarted/passEnded not nested right!");
320     I->second.stopTimer();
321   }
322 };
323
324 static TimingInfo *TheTimeInfo;
325
326 } // End of anon namespace
327
328 //===----------------------------------------------------------------------===//
329 // PMTopLevelManager implementation
330
331 /// Initialize top level manager. Create first pass manager.
332 PMTopLevelManager::PMTopLevelManager (enum TopLevelManagerType t) {
333
334   if (t == TLM_Pass) {
335     MPPassManager *MPP = new MPPassManager(1);
336     MPP->setTopLevelManager(this);
337     addPassManager(MPP);
338     activeStack.push(MPP);
339   } 
340   else if (t == TLM_Function) {
341     FPPassManager *FPP = new FPPassManager(1);
342     FPP->setTopLevelManager(this);
343     addPassManager(FPP);
344     activeStack.push(FPP);
345   } 
346 }
347
348 /// Set pass P as the last user of the given analysis passes.
349 void PMTopLevelManager::setLastUser(std::vector<Pass *> &AnalysisPasses, 
350                                     Pass *P) {
351
352   for (std::vector<Pass *>::iterator I = AnalysisPasses.begin(),
353          E = AnalysisPasses.end(); I != E; ++I) {
354     Pass *AP = *I;
355     LastUser[AP] = P;
356     // If AP is the last user of other passes then make P last user of
357     // such passes.
358     for (std::map<Pass *, Pass *>::iterator LUI = LastUser.begin(),
359            LUE = LastUser.end(); LUI != LUE; ++LUI) {
360       if (LUI->second == AP)
361         LastUser[LUI->first] = P;
362     }
363   }
364 }
365
366 /// Collect passes whose last user is P
367 void PMTopLevelManager::collectLastUses(std::vector<Pass *> &LastUses,
368                                             Pass *P) {
369    for (std::map<Pass *, Pass *>::iterator LUI = LastUser.begin(),
370           LUE = LastUser.end(); LUI != LUE; ++LUI)
371       if (LUI->second == P)
372         LastUses.push_back(LUI->first);
373 }
374
375 /// Schedule pass P for execution. Make sure that passes required by
376 /// P are run before P is run. Update analysis info maintained by
377 /// the manager. Remove dead passes. This is a recursive function.
378 void PMTopLevelManager::schedulePass(Pass *P) {
379
380   // TODO : Allocate function manager for this pass, other wise required set
381   // may be inserted into previous function manager
382
383   // If this Analysis is already requested by one of the previous pass
384   // and it is still available then do not insert new pass in the queue again.
385   if (findAnalysisPass(P->getPassInfo()))
386       return;
387
388   // Give pass a chance to prepare the stage.
389   P->preparePassManager(activeStack);
390
391   AnalysisUsage AnUsage;
392   P->getAnalysisUsage(AnUsage);
393   const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet();
394   for (std::vector<AnalysisID>::const_iterator I = RequiredSet.begin(),
395          E = RequiredSet.end(); I != E; ++I) {
396
397     Pass *AnalysisPass = findAnalysisPass(*I);
398     if (!AnalysisPass) {
399       // Schedule this analysis run first.
400       AnalysisPass = (*I)->createPass();
401       schedulePass(AnalysisPass);
402     }
403   }
404
405   // Now all required passes are available.
406   addTopLevelPass(P);
407 }
408
409 /// Find the pass that implements Analysis AID. Search immutable
410 /// passes and all pass managers. If desired pass is not found
411 /// then return NULL.
412 Pass *PMTopLevelManager::findAnalysisPass(AnalysisID AID) {
413
414   Pass *P = NULL;
415   // Check pass managers
416   for (std::vector<Pass *>::iterator I = PassManagers.begin(),
417          E = PassManagers.end(); P == NULL && I != E; ++I) {
418     PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I);
419     assert(PMD && "This is not a PassManager");
420     P = PMD->findAnalysisPass(AID, false);
421   }
422
423   // Check other pass managers
424   for (std::vector<PMDataManager *>::iterator I = IndirectPassManagers.begin(),
425          E = IndirectPassManagers.end(); P == NULL && I != E; ++I)
426     P = (*I)->findAnalysisPass(AID, false);
427
428   for (std::vector<ImmutablePass *>::iterator I = ImmutablePasses.begin(),
429          E = ImmutablePasses.end(); P == NULL && I != E; ++I) {
430     const PassInfo *PI = (*I)->getPassInfo();
431     if (PI == AID)
432       P = *I;
433
434     // If Pass not found then check the interfaces implemented by Immutable Pass
435     if (!P) {
436       const std::vector<const PassInfo*> &ImmPI = PI->getInterfacesImplemented();
437       if (std::find(ImmPI.begin(), ImmPI.end(), AID) != ImmPI.end())
438         P = *I;
439     }
440   }
441
442   return P;
443 }
444
445 // Print passes managed by this top level manager.
446 void PMTopLevelManager::dumpPasses() const {
447
448   if (PassDebugging < Structure)
449     return;
450
451   // Print out the immutable passes
452   for (unsigned i = 0, e = ImmutablePasses.size(); i != e; ++i) {
453     ImmutablePasses[i]->dumpPassStructure(0);
454   }
455   
456   for (std::vector<Pass *>::const_iterator I = PassManagers.begin(),
457          E = PassManagers.end(); I != E; ++I)
458     (*I)->dumpPassStructure(1);
459 }
460
461 void PMTopLevelManager::dumpArguments() const {
462
463   if (PassDebugging < Arguments)
464     return;
465
466   cerr << "Pass Arguments: ";
467   for (std::vector<Pass *>::const_iterator I = PassManagers.begin(),
468          E = PassManagers.end(); I != E; ++I) {
469     PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I);
470     assert(PMD && "This is not a PassManager");
471     PMD->dumpPassArguments();
472   }
473   cerr << "\n";
474 }
475
476 void PMTopLevelManager::initializeAllAnalysisInfo() {
477   
478   for (std::vector<Pass *>::iterator I = PassManagers.begin(),
479          E = PassManagers.end(); I != E; ++I) {
480     PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I);
481     assert(PMD && "This is not a PassManager");
482     PMD->initializeAnalysisInfo();
483   }
484   
485   // Initailize other pass managers
486   for (std::vector<PMDataManager *>::iterator I = IndirectPassManagers.begin(),
487          E = IndirectPassManagers.end(); I != E; ++I)
488     (*I)->initializeAnalysisInfo();
489 }
490
491 /// Destructor
492 PMTopLevelManager::~PMTopLevelManager() {
493   for (std::vector<Pass *>::iterator I = PassManagers.begin(),
494          E = PassManagers.end(); I != E; ++I)
495     delete *I;
496   
497   for (std::vector<ImmutablePass *>::iterator
498          I = ImmutablePasses.begin(), E = ImmutablePasses.end(); I != E; ++I)
499     delete *I;
500   
501   PassManagers.clear();
502 }
503
504 //===----------------------------------------------------------------------===//
505 // PMDataManager implementation
506
507 /// Return true IFF pass P's required analysis set does not required new
508 /// manager.
509 bool PMDataManager::manageablePass(Pass *P) {
510
511   // TODO 
512   // If this pass is not preserving information that is required by a
513   // pass maintained by higher level pass manager then do not insert
514   // this pass into current manager. Use new manager. For example,
515   // For example, If FunctionPass F is not preserving ModulePass Info M1
516   // that is used by another ModulePass M2 then do not insert F in
517   // current function pass manager.
518   return true;
519 }
520
521 /// Augement AvailableAnalysis by adding analysis made available by pass P.
522 void PMDataManager::recordAvailableAnalysis(Pass *P) {
523                                                 
524   if (const PassInfo *PI = P->getPassInfo()) {
525     AvailableAnalysis[PI] = P;
526
527     //This pass is the current implementation of all of the interfaces it
528     //implements as well.
529     const std::vector<const PassInfo*> &II = PI->getInterfacesImplemented();
530     for (unsigned i = 0, e = II.size(); i != e; ++i)
531       AvailableAnalysis[II[i]] = P;
532   }
533 }
534
535 /// Remove Analyss not preserved by Pass P
536 void PMDataManager::removeNotPreservedAnalysis(Pass *P) {
537   AnalysisUsage AnUsage;
538   P->getAnalysisUsage(AnUsage);
539
540   if (AnUsage.getPreservesAll())
541     return;
542
543   const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
544   for (std::map<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(),
545          E = AvailableAnalysis.end(); I != E; ) {
546     std::map<AnalysisID, Pass*>::iterator Info = I++;
547     if (std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) == 
548         PreservedSet.end()) {
549       // Remove this analysis
550       if (!dynamic_cast<ImmutablePass*>(Info->second))
551         AvailableAnalysis.erase(Info);
552     }
553   }
554 }
555
556 /// Remove analysis passes that are not used any longer
557 void PMDataManager::removeDeadPasses(Pass *P, std::string Msg,
558                                      enum PassDebuggingString DBG_STR) {
559
560   std::vector<Pass *> DeadPasses;
561   TPM->collectLastUses(DeadPasses, P);
562
563   for (std::vector<Pass *>::iterator I = DeadPasses.begin(),
564          E = DeadPasses.end(); I != E; ++I) {
565
566     dumpPassInfo(*I, FREEING_MSG, DBG_STR, Msg);
567
568     if (TheTimeInfo) TheTimeInfo->passStarted(*I);
569     (*I)->releaseMemory();
570     if (TheTimeInfo) TheTimeInfo->passEnded(*I);
571
572     std::map<AnalysisID, Pass*>::iterator Pos = 
573       AvailableAnalysis.find((*I)->getPassInfo());
574     
575     // It is possible that pass is already removed from the AvailableAnalysis
576     if (Pos != AvailableAnalysis.end())
577       AvailableAnalysis.erase(Pos);
578   }
579 }
580
581 /// Add pass P into the PassVector. Update 
582 /// AvailableAnalysis appropriately if ProcessAnalysis is true.
583 void PMDataManager::add(Pass *P, 
584                         bool ProcessAnalysis) {
585
586   // This manager is going to manage pass P. Set up analysis resolver
587   // to connect them.
588   AnalysisResolver *AR = new AnalysisResolver(*this);
589   P->setResolver(AR);
590
591   // If a FunctionPass F is the last user of ModulePass info M
592   // then the F's manager, not F, records itself as a last user of M.
593   std::vector<Pass *> TransferLastUses;
594
595   if (ProcessAnalysis) {
596
597     // At the moment, this pass is the last user of all required passes.
598     std::vector<Pass *> LastUses;
599     std::vector<Pass *> RequiredPasses;
600     unsigned PDepth = this->getDepth();
601
602     collectRequiredAnalysisPasses(RequiredPasses, P);
603     for (std::vector<Pass *>::iterator I = RequiredPasses.begin(),
604            E = RequiredPasses.end(); I != E; ++I) {
605       Pass *PRequired = *I;
606       unsigned RDepth = 0;
607
608       PMDataManager &DM = PRequired->getResolver()->getPMDataManager();
609       RDepth = DM.getDepth();
610
611       if (PDepth == RDepth)
612         LastUses.push_back(PRequired);
613       else if (PDepth >  RDepth) {
614         // Let the parent claim responsibility of last use
615         TransferLastUses.push_back(PRequired);
616       } else {
617         // Note : This feature is not yet implemented
618         assert (0 && 
619                 "Unable to handle Pass that requires lower level Analysis pass");
620       }
621     }
622
623     // Set P as P's last user until someone starts using P.
624     // However, if P is a Pass Manager then it does not need
625     // to record its last user.
626     if (!dynamic_cast<PMDataManager *>(P))
627       LastUses.push_back(P);
628     TPM->setLastUser(LastUses, P);
629
630     if (!TransferLastUses.empty()) {
631       Pass *My_PM = dynamic_cast<Pass *>(this);
632       TPM->setLastUser(TransferLastUses, My_PM);
633       TransferLastUses.clear();
634     }
635
636     // Take a note of analysis required and made available by this pass.
637     // Remove the analysis not preserved by this pass
638     removeNotPreservedAnalysis(P);
639     recordAvailableAnalysis(P);
640   }
641
642   // Add pass
643   PassVector.push_back(P);
644 }
645
646 /// Populate RequiredPasses with the analysis pass that are required by
647 /// pass P.
648 void PMDataManager::collectRequiredAnalysisPasses(std::vector<Pass *> &RP,
649                                                   Pass *P) {
650   AnalysisUsage AnUsage;
651   P->getAnalysisUsage(AnUsage);
652   const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet();
653   for (std::vector<AnalysisID>::const_iterator 
654          I = RequiredSet.begin(), E = RequiredSet.end();
655        I != E; ++I) {
656     Pass *AnalysisPass = findAnalysisPass(*I, true);
657     assert (AnalysisPass && "Analysis pass is not available");
658     RP.push_back(AnalysisPass);
659   }
660
661   const std::vector<AnalysisID> &IDs = AnUsage.getRequiredTransitiveSet();
662   for (std::vector<AnalysisID>::const_iterator I = IDs.begin(),
663          E = IDs.end(); I != E; ++I) {
664     Pass *AnalysisPass = findAnalysisPass(*I, true);
665     assert (AnalysisPass && "Analysis pass is not available");
666     RP.push_back(AnalysisPass);
667   }
668 }
669
670 // All Required analyses should be available to the pass as it runs!  Here
671 // we fill in the AnalysisImpls member of the pass so that it can
672 // successfully use the getAnalysis() method to retrieve the
673 // implementations it needs.
674 //
675 void PMDataManager::initializeAnalysisImpl(Pass *P) {
676   AnalysisUsage AnUsage;
677   P->getAnalysisUsage(AnUsage);
678  
679   for (std::vector<const PassInfo *>::const_iterator
680          I = AnUsage.getRequiredSet().begin(),
681          E = AnUsage.getRequiredSet().end(); I != E; ++I) {
682     Pass *Impl = findAnalysisPass(*I, true);
683     if (Impl == 0)
684       assert(0 && "Analysis used but not available!");
685     AnalysisResolver *AR = P->getResolver();
686     AR->addAnalysisImplsPair(*I, Impl);
687   }
688 }
689
690 /// Find the pass that implements Analysis AID. If desired pass is not found
691 /// then return NULL.
692 Pass *PMDataManager::findAnalysisPass(AnalysisID AID, bool SearchParent) {
693
694   // Check if AvailableAnalysis map has one entry.
695   std::map<AnalysisID, Pass*>::const_iterator I =  AvailableAnalysis.find(AID);
696
697   if (I != AvailableAnalysis.end())
698     return I->second;
699
700   // Search Parents through TopLevelManager
701   if (SearchParent)
702     return TPM->findAnalysisPass(AID);
703   
704   return NULL;
705 }
706
707 // Print list of passes that are last used by P.
708 void PMDataManager::dumpLastUses(Pass *P, unsigned Offset) const{
709
710   std::vector<Pass *> LUses;
711   
712   assert (TPM && "Top Level Manager is missing");
713   TPM->collectLastUses(LUses, P);
714   
715   for (std::vector<Pass *>::iterator I = LUses.begin(),
716          E = LUses.end(); I != E; ++I) {
717     llvm::cerr << "--" << std::string(Offset*2, ' ');
718     (*I)->dumpPassStructure(0);
719   }
720 }
721
722 void PMDataManager::dumpPassArguments() const {
723   for(std::vector<Pass *>::const_iterator I = PassVector.begin(),
724         E = PassVector.end(); I != E; ++I) {
725     if (PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I))
726       PMD->dumpPassArguments();
727     else
728       if (const PassInfo *PI = (*I)->getPassInfo())
729         if (!PI->isAnalysisGroup())
730           cerr << " -" << PI->getPassArgument();
731   }
732 }
733
734 void PMDataManager:: dumpPassInfo(Pass *P, enum PassDebuggingString S1,
735                                   enum PassDebuggingString S2,
736                                   std::string Msg) {
737   if (PassDebugging < Executions)
738     return;
739   cerr << (void*)this << std::string(getDepth()*2+1, ' ');
740   switch (S1) {
741   case EXECUTION_MSG:
742     cerr << "Executing Pass '" << P->getPassName();
743     break;
744   case MODIFICATION_MSG:
745     cerr << "' Made Modification '" << P->getPassName();
746     break;
747   case FREEING_MSG:
748     cerr << " Freeing Pass '" << P->getPassName();
749     break;
750   default:
751     break;
752   }
753   switch (S2) {
754   case ON_BASICBLOCK_MSG:
755     cerr << "' on BasicBlock '" << Msg << "...\n";
756     break;
757   case ON_FUNCTION_MSG:
758     cerr << "' on Function '" << Msg << "...\n";
759     break;
760   case ON_MODULE_MSG:
761     cerr << "' on Module '"  << Msg << "...\n";
762     break;
763   case ON_LOOP_MSG:
764     cerr << "' on Loop " << Msg << "...\n";
765     break;
766   case ON_CG_MSG:
767     cerr << "' on Call Graph " << Msg << "...\n";
768     break;
769   default:
770     break;
771   }
772 }
773
774 void PMDataManager::dumpAnalysisSetInfo(const char *Msg, Pass *P,
775                                         const std::vector<AnalysisID> &Set) 
776   const {
777   if (PassDebugging >= Details && !Set.empty()) {
778     cerr << (void*)P << std::string(getDepth()*2+3, ' ') << Msg << " Analyses:";
779       for (unsigned i = 0; i != Set.size(); ++i) {
780         if (i) cerr << ",";
781         cerr << " " << Set[i]->getPassName();
782       }
783       cerr << "\n";
784   }
785 }
786
787 // Destructor
788 PMDataManager::~PMDataManager() {
789   
790   for (std::vector<Pass *>::iterator I = PassVector.begin(),
791          E = PassVector.end(); I != E; ++I)
792     delete *I;
793   
794   PassVector.clear();
795 }
796
797 //===----------------------------------------------------------------------===//
798 // NOTE: Is this the right place to define this method ?
799 // getAnalysisToUpdate - Return an analysis result or null if it doesn't exist
800 Pass *AnalysisResolver::getAnalysisToUpdate(AnalysisID ID, bool dir) const {
801   return PM.findAnalysisPass(ID, dir);
802 }
803
804 //===----------------------------------------------------------------------===//
805 // BBPassManager implementation
806
807 /// Execute all of the passes scheduled for execution by invoking 
808 /// runOnBasicBlock method.  Keep track of whether any of the passes modifies 
809 /// the function, and if so, return true.
810 bool
811 BBPassManager::runOnFunction(Function &F) {
812
813   if (F.isDeclaration())
814     return false;
815
816   bool Changed = doInitialization(F);
817
818   for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
819     for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
820       BasicBlockPass *BP = getContainedPass(Index);
821       AnalysisUsage AnUsage;
822       BP->getAnalysisUsage(AnUsage);
823
824       dumpPassInfo(BP, EXECUTION_MSG, ON_BASICBLOCK_MSG, (*I).getName());
825       dumpAnalysisSetInfo("Required", BP, AnUsage.getRequiredSet());
826
827       initializeAnalysisImpl(BP);
828
829       if (TheTimeInfo) TheTimeInfo->passStarted(BP);
830       Changed |= BP->runOnBasicBlock(*I);
831       if (TheTimeInfo) TheTimeInfo->passEnded(BP);
832
833       if (Changed) 
834         dumpPassInfo(BP, MODIFICATION_MSG, ON_BASICBLOCK_MSG, (*I).getName());
835       dumpAnalysisSetInfo("Preserved", BP, AnUsage.getPreservedSet());
836
837       removeNotPreservedAnalysis(BP);
838       recordAvailableAnalysis(BP);
839       removeDeadPasses(BP, (*I).getName(), ON_BASICBLOCK_MSG);
840                        
841     }
842   return Changed |= doFinalization(F);
843 }
844
845 // Implement doInitialization and doFinalization
846 inline bool BBPassManager::doInitialization(Module &M) {
847   bool Changed = false;
848
849   for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
850     BasicBlockPass *BP = getContainedPass(Index);
851     Changed |= BP->doInitialization(M);
852   }
853
854   return Changed;
855 }
856
857 inline bool BBPassManager::doFinalization(Module &M) {
858   bool Changed = false;
859
860   for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
861     BasicBlockPass *BP = getContainedPass(Index);
862     Changed |= BP->doFinalization(M);
863   }
864
865   return Changed;
866 }
867
868 inline bool BBPassManager::doInitialization(Function &F) {
869   bool Changed = false;
870
871   for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
872     BasicBlockPass *BP = getContainedPass(Index);
873     Changed |= BP->doInitialization(F);
874   }
875
876   return Changed;
877 }
878
879 inline bool BBPassManager::doFinalization(Function &F) {
880   bool Changed = false;
881
882   for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
883     BasicBlockPass *BP = getContainedPass(Index);
884     Changed |= BP->doFinalization(F);
885   }
886
887   return Changed;
888 }
889
890
891 //===----------------------------------------------------------------------===//
892 // FunctionPassManager implementation
893
894 /// Create new Function pass manager
895 FunctionPassManager::FunctionPassManager(ModuleProvider *P) {
896   FPM = new FunctionPassManagerImpl(0);
897   // FPM is the top level manager.
898   FPM->setTopLevelManager(FPM);
899
900   PMDataManager *PMD = dynamic_cast<PMDataManager *>(FPM);
901   AnalysisResolver *AR = new AnalysisResolver(*PMD);
902   FPM->setResolver(AR);
903   
904   MP = P;
905 }
906
907 FunctionPassManager::~FunctionPassManager() {
908   delete FPM;
909 }
910
911 /// add - Add a pass to the queue of passes to run.  This passes
912 /// ownership of the Pass to the PassManager.  When the
913 /// PassManager_X is destroyed, the pass will be destroyed as well, so
914 /// there is no need to delete the pass. (TODO delete passes.)
915 /// This implies that all passes MUST be allocated with 'new'.
916 void FunctionPassManager::add(Pass *P) { 
917   FPM->add(P);
918 }
919
920 /// run - Execute all of the passes scheduled for execution.  Keep
921 /// track of whether any of the passes modifies the function, and if
922 /// so, return true.
923 ///
924 bool FunctionPassManager::run(Function &F) {
925   std::string errstr;
926   if (MP->materializeFunction(&F, &errstr)) {
927     cerr << "Error reading bytecode file: " << errstr << "\n";
928     abort();
929   }
930   return FPM->run(F);
931 }
932
933
934 /// doInitialization - Run all of the initializers for the function passes.
935 ///
936 bool FunctionPassManager::doInitialization() {
937   return FPM->doInitialization(*MP->getModule());
938 }
939
940 /// doFinalization - Run all of the initializers for the function passes.
941 ///
942 bool FunctionPassManager::doFinalization() {
943   return FPM->doFinalization(*MP->getModule());
944 }
945
946 //===----------------------------------------------------------------------===//
947 // FunctionPassManagerImpl implementation
948 //
949 inline bool FunctionPassManagerImpl::doInitialization(Module &M) {
950   bool Changed = false;
951
952   for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {  
953     FPPassManager *FP = getContainedManager(Index);
954     Changed |= FP->doInitialization(M);
955   }
956
957   return Changed;
958 }
959
960 inline bool FunctionPassManagerImpl::doFinalization(Module &M) {
961   bool Changed = false;
962
963   for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {  
964     FPPassManager *FP = getContainedManager(Index);
965     Changed |= FP->doFinalization(M);
966   }
967
968   return Changed;
969 }
970
971 // Execute all the passes managed by this top level manager.
972 // Return true if any function is modified by a pass.
973 bool FunctionPassManagerImpl::run(Function &F) {
974
975   bool Changed = false;
976
977   TimingInfo::createTheTimeInfo();
978
979   dumpArguments();
980   dumpPasses();
981
982   initializeAllAnalysisInfo();
983   for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {  
984     FPPassManager *FP = getContainedManager(Index);
985     Changed |= FP->runOnFunction(F);
986   }
987   return Changed;
988 }
989
990 //===----------------------------------------------------------------------===//
991 // FPPassManager implementation
992
993 /// Print passes managed by this manager
994 void FPPassManager::dumpPassStructure(unsigned Offset) {
995   llvm::cerr << std::string(Offset*2, ' ') << "FunctionPass Manager\n";
996   for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
997     FunctionPass *FP = getContainedPass(Index);
998     FP->dumpPassStructure(Offset + 1);
999     dumpLastUses(FP, Offset+1);
1000   }
1001 }
1002
1003
1004 /// Execute all of the passes scheduled for execution by invoking 
1005 /// runOnFunction method.  Keep track of whether any of the passes modifies 
1006 /// the function, and if so, return true.
1007 bool FPPassManager::runOnFunction(Function &F) {
1008
1009   bool Changed = false;
1010
1011   if (F.isDeclaration())
1012     return false;
1013
1014   for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1015     FunctionPass *FP = getContainedPass(Index);
1016
1017     AnalysisUsage AnUsage;
1018     FP->getAnalysisUsage(AnUsage);
1019
1020     dumpPassInfo(FP, EXECUTION_MSG, ON_FUNCTION_MSG, F.getName());
1021     dumpAnalysisSetInfo("Required", FP, AnUsage.getRequiredSet());
1022
1023     initializeAnalysisImpl(FP);
1024
1025     if (TheTimeInfo) TheTimeInfo->passStarted(FP);
1026     Changed |= FP->runOnFunction(F);
1027     if (TheTimeInfo) TheTimeInfo->passEnded(FP);
1028
1029     if (Changed) 
1030       dumpPassInfo(FP, MODIFICATION_MSG, ON_FUNCTION_MSG, F.getName());
1031     dumpAnalysisSetInfo("Preserved", FP, AnUsage.getPreservedSet());
1032
1033     removeNotPreservedAnalysis(FP);
1034     recordAvailableAnalysis(FP);
1035     removeDeadPasses(FP, F.getName(), ON_FUNCTION_MSG);
1036   }
1037   return Changed;
1038 }
1039
1040 bool FPPassManager::runOnModule(Module &M) {
1041
1042   bool Changed = doInitialization(M);
1043
1044   for(Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
1045     this->runOnFunction(*I);
1046
1047   return Changed |= doFinalization(M);
1048 }
1049
1050 inline bool FPPassManager::doInitialization(Module &M) {
1051   bool Changed = false;
1052
1053   for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {  
1054     FunctionPass *FP = getContainedPass(Index);
1055     Changed |= FP->doInitialization(M);
1056   }
1057
1058   return Changed;
1059 }
1060
1061 inline bool FPPassManager::doFinalization(Module &M) {
1062   bool Changed = false;
1063
1064   for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {  
1065     FunctionPass *FP = getContainedPass(Index);
1066     Changed |= FP->doFinalization(M);
1067   }
1068
1069   return Changed;
1070 }
1071
1072 //===----------------------------------------------------------------------===//
1073 // MPPassManager implementation
1074
1075 /// Execute all of the passes scheduled for execution by invoking 
1076 /// runOnModule method.  Keep track of whether any of the passes modifies 
1077 /// the module, and if so, return true.
1078 bool
1079 MPPassManager::runOnModule(Module &M) {
1080   bool Changed = false;
1081
1082   for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1083     ModulePass *MP = getContainedPass(Index);
1084
1085     AnalysisUsage AnUsage;
1086     MP->getAnalysisUsage(AnUsage);
1087
1088     dumpPassInfo(MP, EXECUTION_MSG, ON_MODULE_MSG, M.getModuleIdentifier());
1089     dumpAnalysisSetInfo("Required", MP, AnUsage.getRequiredSet());
1090
1091     initializeAnalysisImpl(MP);
1092
1093     if (TheTimeInfo) TheTimeInfo->passStarted(MP);
1094     Changed |= MP->runOnModule(M);
1095     if (TheTimeInfo) TheTimeInfo->passEnded(MP);
1096
1097     if (Changed) 
1098       dumpPassInfo(MP, MODIFICATION_MSG, ON_MODULE_MSG,
1099                    M.getModuleIdentifier());
1100     dumpAnalysisSetInfo("Preserved", MP, AnUsage.getPreservedSet());
1101       
1102     removeNotPreservedAnalysis(MP);
1103     recordAvailableAnalysis(MP);
1104     removeDeadPasses(MP, M.getModuleIdentifier(), ON_MODULE_MSG);
1105   }
1106   return Changed;
1107 }
1108
1109 //===----------------------------------------------------------------------===//
1110 // PassManagerImpl implementation
1111 //
1112 /// run - Execute all of the passes scheduled for execution.  Keep track of
1113 /// whether any of the passes modifies the module, and if so, return true.
1114 bool PassManagerImpl::run(Module &M) {
1115
1116   bool Changed = false;
1117
1118   TimingInfo::createTheTimeInfo();
1119
1120   dumpArguments();
1121   dumpPasses();
1122
1123   initializeAllAnalysisInfo();
1124   for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {  
1125     MPPassManager *MP = getContainedManager(Index);
1126     Changed |= MP->runOnModule(M);
1127   }
1128   return Changed;
1129 }
1130
1131 //===----------------------------------------------------------------------===//
1132 // PassManager implementation
1133
1134 /// Create new pass manager
1135 PassManager::PassManager() {
1136   PM = new PassManagerImpl(0);
1137   // PM is the top level manager
1138   PM->setTopLevelManager(PM);
1139 }
1140
1141 PassManager::~PassManager() {
1142   delete PM;
1143 }
1144
1145 /// add - Add a pass to the queue of passes to run.  This passes ownership of
1146 /// the Pass to the PassManager.  When the PassManager is destroyed, the pass
1147 /// will be destroyed as well, so there is no need to delete the pass.  This
1148 /// implies that all passes MUST be allocated with 'new'.
1149 void 
1150 PassManager::add(Pass *P) {
1151   PM->add(P);
1152 }
1153
1154 /// run - Execute all of the passes scheduled for execution.  Keep track of
1155 /// whether any of the passes modifies the module, and if so, return true.
1156 bool
1157 PassManager::run(Module &M) {
1158   return PM->run(M);
1159 }
1160
1161 //===----------------------------------------------------------------------===//
1162 // TimingInfo Class - This class is used to calculate information about the
1163 // amount of time each pass takes to execute.  This only happens with
1164 // -time-passes is enabled on the command line.
1165 //
1166 bool llvm::TimePassesIsEnabled = false;
1167 static cl::opt<bool,true>
1168 EnableTiming("time-passes", cl::location(TimePassesIsEnabled),
1169             cl::desc("Time each pass, printing elapsed time for each on exit"));
1170
1171 // createTheTimeInfo - This method either initializes the TheTimeInfo pointer to
1172 // a non null value (if the -time-passes option is enabled) or it leaves it
1173 // null.  It may be called multiple times.
1174 void TimingInfo::createTheTimeInfo() {
1175   if (!TimePassesIsEnabled || TheTimeInfo) return;
1176
1177   // Constructed the first time this is called, iff -time-passes is enabled.
1178   // This guarantees that the object will be constructed before static globals,
1179   // thus it will be destroyed before them.
1180   static ManagedStatic<TimingInfo> TTI;
1181   TheTimeInfo = &*TTI;
1182 }
1183
1184 /// If TimingInfo is enabled then start pass timer.
1185 void StartPassTimer(Pass *P) {
1186   if (TheTimeInfo) 
1187     TheTimeInfo->passStarted(P);
1188 }
1189
1190 /// If TimingInfo is enabled then stop pass timer.
1191 void StopPassTimer(Pass *P) {
1192   if (TheTimeInfo) 
1193     TheTimeInfo->passEnded(P);
1194 }
1195
1196 //===----------------------------------------------------------------------===//
1197 // PMStack implementation
1198 //
1199
1200 // Pop Pass Manager from the stack and clear its analysis info.
1201 void PMStack::pop() {
1202
1203   PMDataManager *Top = this->top();
1204   Top->initializeAnalysisInfo();
1205
1206   S.pop_back();
1207 }
1208
1209 // Push PM on the stack and set its top level manager.
1210 void PMStack::push(Pass *P) {
1211
1212   PMDataManager *Top = NULL;
1213   PMDataManager *PM = dynamic_cast<PMDataManager *>(P);
1214   assert (PM && "Unable to push. Pass Manager expected");
1215
1216   if (this->empty()) {
1217     Top = PM;
1218   } 
1219   else {
1220     Top = this->top();
1221     PMTopLevelManager *TPM = Top->getTopLevelManager();
1222
1223     assert (TPM && "Unable to find top level manager");
1224     TPM->addIndirectPassManager(PM);
1225     PM->setTopLevelManager(TPM);
1226   }
1227
1228   AnalysisResolver *AR = new AnalysisResolver(*Top);
1229   P->setResolver(AR);
1230
1231   S.push_back(PM);
1232 }
1233
1234 // Dump content of the pass manager stack.
1235 void PMStack::dump() {
1236   for(std::deque<PMDataManager *>::iterator I = S.begin(),
1237         E = S.end(); I != E; ++I) {
1238     Pass *P = dynamic_cast<Pass *>(*I);
1239     printf ("%s ", P->getPassName());
1240   }
1241   if (!S.empty())
1242     printf ("\n");
1243 }
1244
1245 /// Find appropriate Module Pass Manager in the PM Stack and
1246 /// add self into that manager. 
1247 void ModulePass::assignPassManager(PMStack &PMS, 
1248                                    PassManagerType PreferredType) {
1249
1250   // Find Module Pass Manager
1251   while(!PMS.empty()) {
1252     PassManagerType TopPMType = PMS.top()->getPassManagerType();
1253     if (TopPMType == PreferredType)
1254       break; // We found desired pass manager
1255     else if (TopPMType > PMT_ModulePassManager)
1256       PMS.pop();    // Pop children pass managers
1257     else
1258       break;
1259   }
1260
1261   PMS.top()->add(this);
1262 }
1263
1264 /// Find appropriate Function Pass Manager or Call Graph Pass Manager
1265 /// in the PM Stack and add self into that manager. 
1266 void FunctionPass::assignPassManager(PMStack &PMS,
1267                                      PassManagerType PreferredType) {
1268
1269   // Find Module Pass Manager (TODO : Or Call Graph Pass Manager)
1270   while(!PMS.empty()) {
1271     if (PMS.top()->getPassManagerType() > PMT_FunctionPassManager)
1272       PMS.pop();
1273     else
1274       break; 
1275   }
1276   FPPassManager *FPP = dynamic_cast<FPPassManager *>(PMS.top());
1277
1278   // Create new Function Pass Manager
1279   if (!FPP) {
1280     assert(!PMS.empty() && "Unable to create Function Pass Manager");
1281     PMDataManager *PMD = PMS.top();
1282
1283     // [1] Create new Function Pass Manager
1284     FPP = new FPPassManager(PMD->getDepth() + 1);
1285
1286     // [2] Set up new manager's top level manager
1287     PMTopLevelManager *TPM = PMD->getTopLevelManager();
1288     TPM->addIndirectPassManager(FPP);
1289
1290     // [3] Assign manager to manage this new manager. This may create
1291     // and push new managers into PMS
1292     Pass *P = dynamic_cast<Pass *>(FPP);
1293
1294     // If Call Graph Pass Manager is active then use it to manage
1295     // this new Function Pass manager.
1296     if (PMD->getPassManagerType() == PMT_CallGraphPassManager)
1297       P->assignPassManager(PMS, PMT_CallGraphPassManager);
1298     else
1299       P->assignPassManager(PMS);
1300
1301     // [4] Push new manager into PMS
1302     PMS.push(FPP);
1303   }
1304
1305   // Assign FPP as the manager of this pass.
1306   FPP->add(this);
1307 }
1308
1309 /// Find appropriate Basic Pass Manager or Call Graph Pass Manager
1310 /// in the PM Stack and add self into that manager. 
1311 void BasicBlockPass::assignPassManager(PMStack &PMS,
1312                                        PassManagerType PreferredType) {
1313
1314   BBPassManager *BBP = NULL;
1315
1316   // Basic Pass Manager is a leaf pass manager. It does not handle
1317   // any other pass manager.
1318   if (!PMS.empty()) {
1319     BBP = dynamic_cast<BBPassManager *>(PMS.top());
1320   }
1321
1322   // If leaf manager is not Basic Block Pass manager then create new
1323   // basic Block Pass manager.
1324
1325   if (!BBP) {
1326     assert(!PMS.empty() && "Unable to create BasicBlock Pass Manager");
1327     PMDataManager *PMD = PMS.top();
1328
1329     // [1] Create new Basic Block Manager
1330     BBP = new BBPassManager(PMD->getDepth() + 1);
1331
1332     // [2] Set up new manager's top level manager
1333     // Basic Block Pass Manager does not live by itself
1334     PMTopLevelManager *TPM = PMD->getTopLevelManager();
1335     TPM->addIndirectPassManager(BBP);
1336
1337     // [3] Assign manager to manage this new manager. This may create
1338     // and push new managers into PMS
1339     Pass *P = dynamic_cast<Pass *>(BBP);
1340     P->assignPassManager(PMS);
1341
1342     // [4] Push new manager into PMS
1343     PMS.push(BBP);
1344   }
1345
1346   // Assign BBP as the manager of this pass.
1347   BBP->add(this);
1348 }
1349
1350