Copy initializeAnalysisImpl() implementation from PassManagerT.
[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/PassManager.h"
16 #include "llvm/Module.h"
17 #include <vector>
18 #include <map>
19
20 using namespace llvm;
21
22 namespace llvm {
23
24 /// CommonPassManagerImpl helps pass manager analysis required by
25 /// the managed passes. It provides methods to add/remove analysis
26 /// available and query if certain analysis is available or not.
27 class CommonPassManagerImpl : public Pass {
28
29 public:
30
31   /// Return true IFF pass P's required analysis set does not required new
32   /// manager.
33   bool manageablePass(Pass *P);
34
35   Pass *getAnalysisPass(AnalysisID AID) const {
36
37     std::map<AnalysisID, Pass*>::const_iterator I = 
38       AvailableAnalysis.find(AID);
39
40     if (I != AvailableAnalysis.end())
41       return NULL;
42     else
43       return I->second;
44   }
45
46   /// Augment RequiredAnalysis by adding analysis required by pass P.
47   void noteDownRequiredAnalysis(Pass *P);
48
49   /// Augment AvailableAnalysis by adding analysis made available by pass P.
50   void noteDownAvailableAnalysis(Pass *P);
51
52   /// Remove Analysis that is not preserved by the pass
53   void removeNotPreservedAnalysis(Pass *P);
54   
55   /// Remove dead passes
56   void removeDeadPasses(Pass *P);
57
58   /// Add pass P into the PassVector. Update RequiredAnalysis and
59   /// AvailableAnalysis appropriately if ProcessAnalysis is true.
60   void addPassToManager (Pass *P, bool ProcessAnalysis = true);
61
62   /// Clear analysis vectors RequiredAnalysis and AvailableAnalysis.
63   /// This is used before running passes managed by the manager.
64   void clearAnalysis() { 
65     RequiredAnalysis.clear();
66     AvailableAnalysis.clear();
67     LastUser.clear();
68   }
69
70   // All Required analyses should be available to the pass as it runs!  Here
71   // we fill in the AnalysisImpls member of the pass so that it can
72   // successfully use the getAnalysis() method to retrieve the
73   // implementations it needs.
74   //
75  void initializeAnalysisImpl(Pass *P);
76
77   inline std::vector<Pass *>::iterator passVectorBegin() { 
78     return PassVector.begin(); 
79   }
80
81   inline std::vector<Pass *>::iterator passVectorEnd() { 
82     return PassVector.end();
83   }
84
85   inline void setLastUser(Pass *P, Pass *LU) { 
86     LastUser[P] = LU; 
87     // TODO : Check if pass P is available.
88
89     // Prolong live range of analyses that are needed after an analysis pass
90     // is destroyed, for querying by subsequent passes
91     AnalysisUsage AnUsage;
92     P->getAnalysisUsage(AnUsage);
93     const std::vector<AnalysisID> &IDs = AnUsage.getRequiredTransitiveSet();
94     for (std::vector<AnalysisID>::const_iterator I = IDs.begin(),
95            E = IDs.end(); I != E; ++I) {
96       Pass *AnalysisPass = getAnalysisPass(*I); // getAnalysisPassFromManager(*I);
97       assert (AnalysisPass && "Analysis pass is not available");
98       setLastUser(AnalysisPass, LU);
99     }
100
101   }
102
103 private:
104   // Analysis required by the passes managed by this manager. This information
105   // used while selecting pass manager during addPass. If a pass does not
106   // preserve any analysis required by other passes managed by current
107   // pass manager then new pass manager is used.
108   std::vector<AnalysisID> RequiredAnalysis;
109
110   // Set of available Analysis. This information is used while scheduling 
111   // pass. If a pass requires an analysis which is not not available then 
112   // equired analysis pass is scheduled to run before the pass itself is 
113   // scheduled to run.
114   std::map<AnalysisID, Pass*> AvailableAnalysis;
115
116   // Map to keep track of last user of the analysis pass.
117   // LastUser->second is the last user of Lastuser->first.
118   std::map<Pass *, Pass *> LastUser;
119
120   // Collection of pass that are managed by this manager
121   std::vector<Pass *> PassVector;
122 };
123
124 /// BasicBlockPassManager_New manages BasicBlockPass. It batches all the
125 /// pass together and sequence them to process one basic block before
126 /// processing next basic block.
127 class BasicBlockPassManager_New : public CommonPassManagerImpl {
128
129 public:
130   BasicBlockPassManager_New() { }
131
132   /// Add a pass into a passmanager queue. 
133   bool addPass(Pass *p);
134   
135   /// Execute all of the passes scheduled for execution.  Keep track of
136   /// whether any of the passes modifies the function, and if so, return true.
137   bool runOnFunction(Function &F);
138
139   /// Return true IFF AnalysisID AID is currently available.
140   Pass *getAnalysisPassFromManager(AnalysisID AID);
141
142 private:
143 };
144
145 /// FunctionPassManagerImpl_New manages FunctionPasses and BasicBlockPassManagers.
146 /// It batches all function passes and basic block pass managers together and
147 /// sequence them to process one function at a time before processing next
148 /// function.
149 class FunctionPassManagerImpl_New : public CommonPassManagerImpl {
150 public:
151   FunctionPassManagerImpl_New(ModuleProvider *P) { /* TODO */ }
152   FunctionPassManagerImpl_New() { 
153     activeBBPassManager = NULL;
154   }
155   ~FunctionPassManagerImpl_New() { /* TODO */ };
156  
157   /// add - Add a pass to the queue of passes to run.  This passes
158   /// ownership of the Pass to the PassManager.  When the
159   /// PassManager_X is destroyed, the pass will be destroyed as well, so
160   /// there is no need to delete the pass. (TODO delete passes.)
161   /// This implies that all passes MUST be allocated with 'new'.
162   void add(Pass *P) { /* TODO*/  }
163
164   /// Add pass into the pass manager queue.
165   bool addPass(Pass *P);
166
167   /// Execute all of the passes scheduled for execution.  Keep
168   /// track of whether any of the passes modifies the function, and if
169   /// so, return true.
170   bool runOnModule(Module &M);
171
172   /// Return true IFF AnalysisID AID is currently available.
173   Pass *getAnalysisPassFromManager(AnalysisID AID);
174
175 private:
176   // Active Pass Managers
177   BasicBlockPassManager_New *activeBBPassManager;
178 };
179
180 /// ModulePassManager_New manages ModulePasses and function pass managers.
181 /// It batches all Module passes  passes and function pass managers together and
182 /// sequence them to process one module.
183 class ModulePassManager_New : public CommonPassManagerImpl {
184  
185 public:
186   ModulePassManager_New() { activeFunctionPassManager = NULL; }
187   
188   /// Add a pass into a passmanager queue. 
189   bool addPass(Pass *p);
190   
191   /// run - Execute all of the passes scheduled for execution.  Keep track of
192   /// whether any of the passes modifies the module, and if so, return true.
193   bool runOnModule(Module &M);
194
195   /// Return true IFF AnalysisID AID is currently available.
196   Pass *getAnalysisPassFromManager(AnalysisID AID);
197   
198 private:
199   // Active Pass Manager
200   FunctionPassManagerImpl_New *activeFunctionPassManager;
201 };
202
203 /// PassManager_New manages ModulePassManagers
204 class PassManagerImpl_New : public CommonPassManagerImpl {
205
206 public:
207
208   /// add - Add a pass to the queue of passes to run.  This passes ownership of
209   /// the Pass to the PassManager.  When the PassManager is destroyed, the pass
210   /// will be destroyed as well, so there is no need to delete the pass.  This
211   /// implies that all passes MUST be allocated with 'new'.
212   void add(Pass *P);
213  
214   /// run - Execute all of the passes scheduled for execution.  Keep track of
215   /// whether any of the passes modifies the module, and if so, return true.
216   bool run(Module &M);
217
218   /// Return true IFF AnalysisID AID is currently available.
219   Pass *getAnalysisPassFromManager(AnalysisID AID);
220
221 private:
222
223   /// Add a pass into a passmanager queue. This is used by schedulePasses
224   bool addPass(Pass *p);
225
226   /// Schedule pass P for execution. Make sure that passes required by
227   /// P are run before P is run. Update analysis info maintained by
228   /// the manager. Remove dead passes. This is a recursive function.
229   void schedulePass(Pass *P);
230
231   /// Schedule all passes collected in pass queue using add(). Add all the
232   /// schedule passes into various manager's queue using addPass().
233   void schedulePasses();
234
235   // Collection of pass managers
236   std::vector<ModulePassManager_New *> PassManagers;
237
238   // Active Pass Manager
239   ModulePassManager_New *activeManager;
240 };
241
242 } // End of llvm namespace
243
244 // CommonPassManagerImpl implementation
245
246 /// Return true IFF pass P's required analysis set does not required new
247 /// manager.
248 bool CommonPassManagerImpl::manageablePass(Pass *P) {
249
250   AnalysisUsage AnUsage;
251   P->getAnalysisUsage(AnUsage);
252
253   // If this pass is not preserving information that is required by the other
254   // passes managed by this manager then use new manager
255   if (!AnUsage.getPreservesAll()) {
256     const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
257     for (std::vector<AnalysisID>::iterator I = RequiredAnalysis.begin(),
258            E = RequiredAnalysis.end(); I != E; ++I) {
259       if (std::find(PreservedSet.begin(), PreservedSet.end(), *I) == 
260           PreservedSet.end())
261         // This analysis is not preserved. Need new manager.
262         return false;
263     }
264   }
265   return true;
266 }
267
268 /// Augment RequiredAnalysis by adding analysis required by pass P.
269 void CommonPassManagerImpl::noteDownRequiredAnalysis(Pass *P) {
270   AnalysisUsage AnUsage;
271   P->getAnalysisUsage(AnUsage);
272   const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet();
273
274   // FIXME: What about duplicates ?
275   RequiredAnalysis.insert(RequiredAnalysis.end(), RequiredSet.begin(), 
276                           RequiredSet.end());
277
278   initializeAnalysisImpl(P);
279 }
280
281 /// Augement AvailableAnalysis by adding analysis made available by pass P.
282 void CommonPassManagerImpl::noteDownAvailableAnalysis(Pass *P) {
283                                                 
284   if (const PassInfo *PI = P->getPassInfo()) {
285     AvailableAnalysis[PI] = P;
286
287     //TODO This pass is the current implementation of all of the interfaces it
288     //TODO implements as well.
289     //TODO
290     //TODO const std::vector<const PassInfo*> &II = PI->getInterfacesImplemented();
291     //TODO for (unsigned i = 0, e = II.size(); i != e; ++i)
292     //TODO CurrentAnalyses[II[i]] = P;
293   }
294 }
295
296 /// Remove Analyss not preserved by Pass P
297 void CommonPassManagerImpl::removeNotPreservedAnalysis(Pass *P) {
298   AnalysisUsage AnUsage;
299   P->getAnalysisUsage(AnUsage);
300   const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
301
302   for (std::map<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(),
303          E = AvailableAnalysis.end(); I != E; ++I ) {
304     if (std::find(PreservedSet.begin(), PreservedSet.end(), I->first) == 
305         PreservedSet.end()) {
306       // Remove this analysis
307       std::map<AnalysisID, Pass*>::iterator J = I++;
308       AvailableAnalysis.erase(J);
309     }
310   }
311 }
312
313 /// Remove analysis passes that are not used any longer
314 void CommonPassManagerImpl::removeDeadPasses(Pass *P) {
315
316   for (std::map<Pass *, Pass *>::iterator I = LastUser.begin(),
317          E = LastUser.end(); I !=E; ++I) {
318     if (I->second == P) {
319       Pass *deadPass = I->first;
320       deadPass->releaseMemory();
321
322       std::map<AnalysisID, Pass*>::iterator Pos = 
323         AvailableAnalysis.find(deadPass->getPassInfo());
324       
325       assert (Pos != AvailableAnalysis.end() &&
326               "Pass is not available");
327       AvailableAnalysis.erase(Pos);
328     }
329   }
330 }
331
332 /// Add pass P into the PassVector. Update RequiredAnalysis and
333 /// AvailableAnalysis appropriately if ProcessAnalysis is true.
334 void CommonPassManagerImpl::addPassToManager (Pass *P, 
335                                               bool ProcessAnalysis) {
336
337   if (ProcessAnalysis) {
338     // Take a note of analysis required and made available by this pass
339     noteDownRequiredAnalysis(P);
340     noteDownAvailableAnalysis(P);
341
342     // Remove the analysis not preserved by this pass
343     removeNotPreservedAnalysis(P);
344   }
345
346   // Add pass
347   PassVector.push_back(P);
348 }
349
350 // All Required analyses should be available to the pass as it runs!  Here
351 // we fill in the AnalysisImpls member of the pass so that it can
352 // successfully use the getAnalysis() method to retrieve the
353 // implementations it needs.
354 //
355 void CommonPassManagerImpl::initializeAnalysisImpl(Pass *P) {
356   AnalysisUsage AnUsage;
357   P->getAnalysisUsage(AnUsage);
358  
359   for (std::vector<const PassInfo *>::const_iterator
360          I = AnUsage.getRequiredSet().begin(),
361          E = AnUsage.getRequiredSet().end(); I != E; ++I) {
362     Pass *Impl = getAnalysisPass(*I);
363     if (Impl == 0)
364       assert(0 && "Analysis used but not available!");
365     // TODO:  P->AnalysisImpls.push_back(std::make_pair(*I, Impl));
366   }
367 }
368
369 /// BasicBlockPassManager implementation
370
371 /// Add pass P into PassVector and return true. If this pass is not
372 /// manageable by this manager then return false.
373 bool
374 BasicBlockPassManager_New::addPass(Pass *P) {
375
376   BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P);
377   if (!BP)
378     return false;
379
380   // If this pass does not preserve anlysis that is used by other passes
381   // managed by this manager than it is not a suiable pass for this manager.
382   if (!manageablePass(P))
383     return false;
384
385   addPassToManager (BP);
386
387   return true;
388 }
389
390 /// Execute all of the passes scheduled for execution by invoking 
391 /// runOnBasicBlock method.  Keep track of whether any of the passes modifies 
392 /// the function, and if so, return true.
393 bool
394 BasicBlockPassManager_New::runOnFunction(Function &F) {
395
396   bool Changed = false;
397   clearAnalysis();
398
399   for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
400     for (std::vector<Pass *>::iterator itr = passVectorBegin(),
401            e = passVectorEnd(); itr != e; ++itr) {
402       Pass *P = *itr;
403       
404       noteDownAvailableAnalysis(P);
405       BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P);
406       Changed |= BP->runOnBasicBlock(*I);
407       removeNotPreservedAnalysis(P);
408       removeDeadPasses(P);
409     }
410   return Changed;
411 }
412
413 /// Return true IFF AnalysisID AID is currently available.
414 Pass * BasicBlockPassManager_New::getAnalysisPassFromManager(AnalysisID AID) {
415   return getAnalysisPass(AID);
416 }
417
418 // FunctionPassManager_New implementation
419 /// Create new Function pass manager
420 FunctionPassManager_New::FunctionPassManager_New() {
421   FPM = new FunctionPassManagerImpl_New();
422 }
423
424 /// add - Add a pass to the queue of passes to run.  This passes
425 /// ownership of the Pass to the PassManager.  When the
426 /// PassManager_X is destroyed, the pass will be destroyed as well, so
427 /// there is no need to delete the pass. (TODO delete passes.)
428 /// This implies that all passes MUST be allocated with 'new'.
429 void 
430 FunctionPassManager_New::add(Pass *P) { 
431   FPM->add(P);
432 }
433
434 /// Execute all of the passes scheduled for execution.  Keep
435 /// track of whether any of the passes modifies the function, and if
436 /// so, return true.
437 bool 
438 FunctionPassManager_New::runOnModule(Module &M) {
439   return FPM->runOnModule(M);
440 }
441
442 // FunctionPassManagerImpl_New implementation
443
444 // FunctionPassManager
445
446 /// Add pass P into the pass manager queue. If P is a BasicBlockPass then
447 /// either use it into active basic block pass manager or create new basic
448 /// block pass manager to handle pass P.
449 bool
450 FunctionPassManagerImpl_New::addPass(Pass *P) {
451
452   // If P is a BasicBlockPass then use BasicBlockPassManager_New.
453   if (BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P)) {
454
455     if (!activeBBPassManager
456         || !activeBBPassManager->addPass(BP)) {
457
458       activeBBPassManager = new BasicBlockPassManager_New();
459       addPassToManager(activeBBPassManager, false);
460       if (!activeBBPassManager->addPass(BP))
461         assert(0 && "Unable to add Pass");
462     }
463     return true;
464   }
465
466   FunctionPass *FP = dynamic_cast<FunctionPass *>(P);
467   if (!FP)
468     return false;
469
470   // If this pass does not preserve anlysis that is used by other passes
471   // managed by this manager than it is not a suiable pass for this manager.
472   if (!manageablePass(P))
473     return false;
474
475   addPassToManager (FP);
476   activeBBPassManager = NULL;
477   return true;
478 }
479
480 /// Execute all of the passes scheduled for execution by invoking 
481 /// runOnFunction method.  Keep track of whether any of the passes modifies 
482 /// the function, and if so, return true.
483 bool
484 FunctionPassManagerImpl_New::runOnModule(Module &M) {
485
486   bool Changed = false;
487   clearAnalysis();
488
489   for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
490     for (std::vector<Pass *>::iterator itr = passVectorBegin(),
491            e = passVectorEnd(); itr != e; ++itr) {
492       Pass *P = *itr;
493       
494       noteDownAvailableAnalysis(P);
495       FunctionPass *FP = dynamic_cast<FunctionPass*>(P);
496       Changed |= FP->runOnFunction(*I);
497       removeNotPreservedAnalysis(P);
498       removeDeadPasses(P);
499     }
500   return Changed;
501 }
502
503 /// Return true IFF AnalysisID AID is currently available.
504 Pass *FunctionPassManagerImpl_New::getAnalysisPassFromManager(AnalysisID AID) {
505
506   Pass *P = getAnalysisPass(AID);
507   if (P)
508     return P;
509
510   if (activeBBPassManager && 
511       activeBBPassManager->getAnalysisPass(AID) != 0)
512     return activeBBPassManager->getAnalysisPass(AID);
513
514   // TODO : Check inactive managers
515   return NULL;
516 }
517
518 // ModulePassManager implementation
519
520 /// Add P into pass vector if it is manageble. If P is a FunctionPass
521 /// then use FunctionPassManagerImpl_New to manage it. Return false if P
522 /// is not manageable by this manager.
523 bool
524 ModulePassManager_New::addPass(Pass *P) {
525
526   // If P is FunctionPass then use function pass maanager.
527   if (FunctionPass *FP = dynamic_cast<FunctionPass*>(P)) {
528
529     activeFunctionPassManager = NULL;
530
531     if (!activeFunctionPassManager
532         || !activeFunctionPassManager->addPass(P)) {
533
534       activeFunctionPassManager = new FunctionPassManagerImpl_New();
535       addPassToManager(activeFunctionPassManager, false);
536       if (!activeFunctionPassManager->addPass(FP))
537         assert(0 && "Unable to add pass");
538     }
539     return true;
540   }
541
542   ModulePass *MP = dynamic_cast<ModulePass *>(P);
543   if (!MP)
544     return false;
545
546   // If this pass does not preserve anlysis that is used by other passes
547   // managed by this manager than it is not a suiable pass for this manager.
548   if (!manageablePass(P))
549     return false;
550
551   addPassToManager(MP);
552   activeFunctionPassManager = NULL;
553   return true;
554 }
555
556
557 /// Execute all of the passes scheduled for execution by invoking 
558 /// runOnModule method.  Keep track of whether any of the passes modifies 
559 /// the module, and if so, return true.
560 bool
561 ModulePassManager_New::runOnModule(Module &M) {
562   bool Changed = false;
563   clearAnalysis();
564
565   for (std::vector<Pass *>::iterator itr = passVectorBegin(),
566          e = passVectorEnd(); itr != e; ++itr) {
567     Pass *P = *itr;
568
569     noteDownAvailableAnalysis(P);
570     ModulePass *MP = dynamic_cast<ModulePass*>(P);
571     Changed |= MP->runOnModule(M);
572     removeNotPreservedAnalysis(P);
573     removeDeadPasses(P);
574   }
575   return Changed;
576 }
577
578 /// Return true IFF AnalysisID AID is currently available.
579 Pass *ModulePassManager_New::getAnalysisPassFromManager(AnalysisID AID) {
580
581   
582   Pass *P = getAnalysisPass(AID);
583   if (P)
584     return P;
585
586   if (activeFunctionPassManager && 
587       activeFunctionPassManager->getAnalysisPass(AID) != 0)
588     return activeFunctionPassManager->getAnalysisPass(AID);
589
590   // TODO : Check inactive managers
591   return NULL;
592 }
593
594 /// Return true IFF AnalysisID AID is currently available.
595 Pass *PassManagerImpl_New::getAnalysisPassFromManager(AnalysisID AID) {
596
597   Pass *P = NULL;
598   for (std::vector<ModulePassManager_New *>::iterator itr = PassManagers.begin(),
599          e = PassManagers.end(); !P && itr != e; ++itr)
600     P  = (*itr)->getAnalysisPassFromManager(AID);
601   return P;
602 }
603
604 /// Schedule pass P for execution. Make sure that passes required by
605 /// P are run before P is run. Update analysis info maintained by
606 /// the manager. Remove dead passes. This is a recursive function.
607 void PassManagerImpl_New::schedulePass(Pass *P) {
608
609   AnalysisUsage AnUsage;
610   P->getAnalysisUsage(AnUsage);
611   const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet();
612   for (std::vector<AnalysisID>::const_iterator I = RequiredSet.begin(),
613          E = RequiredSet.end(); I != E; ++I) {
614
615     Pass *AnalysisPass = getAnalysisPassFromManager(*I);
616     if (!AnalysisPass) {
617       // Schedule this analysis run first.
618       AnalysisPass = (*I)->createPass();
619       schedulePass(AnalysisPass);
620     }
621     setLastUser (AnalysisPass, P);
622   }
623     
624   addPass(P);
625 }
626
627 /// Schedule all passes from the queue by adding them in their
628 /// respective manager's queue. 
629 void PassManagerImpl_New::schedulePasses() {
630   for (std::vector<Pass *>::iterator I = passVectorBegin(),
631          E = passVectorEnd(); I != E; ++I)
632     schedulePass (*I);
633 }
634
635 /// Add pass P to the queue of passes to run.
636 void PassManagerImpl_New::add(Pass *P) {
637   // Do not process Analysis now. Analysis is process while scheduling
638   // the pass vector.
639   addPassToManager(P, false);
640 }
641
642 // PassManager_New implementation
643 /// Add P into active pass manager or use new module pass manager to
644 /// manage it.
645 bool PassManagerImpl_New::addPass(Pass *P) {
646
647   if (!activeManager || !activeManager->addPass(P)) {
648     activeManager = new ModulePassManager_New();
649     PassManagers.push_back(activeManager);
650   }
651
652   return activeManager->addPass(P);
653 }
654
655 /// run - Execute all of the passes scheduled for execution.  Keep track of
656 /// whether any of the passes modifies the module, and if so, return true.
657 bool PassManagerImpl_New::run(Module &M) {
658
659   schedulePasses();
660   bool Changed = false;
661   for (std::vector<ModulePassManager_New *>::iterator itr = PassManagers.begin(),
662          e = PassManagers.end(); itr != e; ++itr) {
663     ModulePassManager_New *pm = *itr;
664     Changed |= pm->runOnModule(M);
665   }
666   return Changed;
667 }
668
669 /// Create new pass manager
670 PassManager_New::PassManager_New() {
671   PM = new PassManagerImpl_New();
672 }
673
674 /// add - Add a pass to the queue of passes to run.  This passes ownership of
675 /// the Pass to the PassManager.  When the PassManager is destroyed, the pass
676 /// will be destroyed as well, so there is no need to delete the pass.  This
677 /// implies that all passes MUST be allocated with 'new'.
678 void 
679 PassManager_New::add(Pass *P) {
680   PM->add(P);
681 }
682
683 /// run - Execute all of the passes scheduled for execution.  Keep track of
684 /// whether any of the passes modifies the module, and if so, return true.
685 bool
686 PassManager_New::run(Module &M) {
687   return PM->run(M);
688 }
689