blob: c0aeaa20468efe21ced65d2bf8819c62288550c0 [file] [log] [blame]
Devang Patel6e5a1132006-11-07 21:31:57 +00001//===- PassManager.cpp - LLVM Pass Infrastructure Implementation ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Devang Patelca58e352006-11-08 10:05:38 +00005// This file was developed by Devang Patel and is distributed under
Devang Patel6e5a1132006-11-07 21:31:57 +00006// 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"
Devang Patel6e5a1132006-11-07 21:31:57 +000016#include "llvm/Module.h"
Devang Patelff631ae2006-11-15 01:27:05 +000017#include "llvm/ModuleProvider.h"
Bill Wendlingdfc91892006-11-28 02:09:03 +000018#include "llvm/Support/Streams.h"
Devang Patela9844592006-11-11 01:31:05 +000019#include <vector>
Devang Patelf60b5d92006-11-14 01:59:59 +000020#include <map>
Devang Patel6e5a1132006-11-07 21:31:57 +000021using namespace llvm;
22
Devang Patel6fea2852006-12-07 18:23:30 +000023//===----------------------------------------------------------------------===//
24// Overview:
25// The Pass Manager Infrastructure manages passes. It's responsibilities are:
26//
27// o Manage optimization pass execution order
28// o Make required Analysis information available before pass P is run
29// o Release memory occupied by dead passes
30// o If Analysis information is dirtied by a pass then regenerate Analysis
31// information before it is consumed by another pass.
32//
33// Pass Manager Infrastructure uses multipe pass managers. They are PassManager,
34// FunctionPassManager, ModulePassManager, BasicBlockPassManager. This class
35// hierarcy uses multiple inheritance but pass managers do not derive from
36// another pass manager.
37//
38// PassManager and FunctionPassManager are two top level pass manager that
39// represents the external interface of this entire pass manager infrastucture.
40//
41// Important classes :
42//
43// [o] class PMTopLevelManager;
44//
45// Two top level managers, PassManager and FunctionPassManager, derive from
46// PMTopLevelManager. PMTopLevelManager manages information used by top level
47// managers such as last user info.
48//
49// [o] class PMDataManager;
50//
51// PMDataManager manages information, e.g. list of available analysis info,
52// used by a pass manager to manage execution order of passes. It also provides
53// a place to implement common pass manager APIs. All pass managers derive from
54// PMDataManager.
55//
56// [o] class BasicBlockPassManager : public FunctionPass, public PMDataManager;
57//
58// BasicBlockPassManager manages BasicBlockPasses.
59//
60// [o] class FunctionPassManager;
61//
62// This is a external interface used by JIT to manage FunctionPasses. This
63// interface relies on FunctionPassManagerImpl to do all the tasks.
64//
65// [o] class FunctionPassManagerImpl : public ModulePass, PMDataManager,
66// public PMTopLevelManager;
67//
68// FunctionPassManagerImpl is a top level manager. It manages FunctionPasses
69// and BasicBlockPassManagers.
70//
71// [o] class ModulePassManager : public Pass, public PMDataManager;
72//
73// ModulePassManager manages ModulePasses and FunctionPassManagerImpls.
74//
75// [o] class PassManager;
76//
77// This is a external interface used by various tools to manages passes. It
78// relies on PassManagerImpl to do all the tasks.
79//
80// [o] class PassManagerImpl : public Pass, public PMDataManager,
81// public PMDTopLevelManager
82//
83// PassManagerImpl is a top level pass manager responsible for managing
84// ModulePassManagers.
85//===----------------------------------------------------------------------===//
86
Devang Patelca58e352006-11-08 10:05:38 +000087namespace llvm {
88
Devang Patelf33f3eb2006-12-07 19:21:29 +000089//===----------------------------------------------------------------------===//
90// PMTopLevelManager
91//
92/// PMTopLevelManager manages LastUser info and collects common APIs used by
93/// top level pass managers.
94class PMTopLevelManager {
95
96public:
97
98 inline std::vector<Pass *>::iterator passManagersBegin() {
99 return PassManagers.begin();
100 }
101
102 inline std::vector<Pass *>::iterator passManagersEnd() {
103 return PassManagers.end();
104 }
105
106 /// Schedule pass P for execution. Make sure that passes required by
107 /// P are run before P is run. Update analysis info maintained by
108 /// the manager. Remove dead passes. This is a recursive function.
109 void schedulePass(Pass *P, Pass *PM);
110
111 /// This is implemented by top level pass manager and used by
112 /// schedulePass() to add analysis info passes that are not available.
113 virtual void addTopLevelPass(Pass *P) = 0;
114
115 /// Set pass P as the last user of the given analysis passes.
116 void setLastUser(std::vector<Pass *> &AnalysisPasses, Pass *P);
117
118 /// Collect passes whose last user is P
119 void collectLastUses(std::vector<Pass *> &LastUses, Pass *P);
120
121 virtual ~PMTopLevelManager() {
122 PassManagers.clear();
123 }
124
Devang Patele0eb9d82006-12-07 20:51:18 +0000125 /// Add immutable pass and initialize it.
126 inline void addImmutablePass(ImmutablePass *P) {
127 P->initializePass();
128 ImmutablePasses.push_back(P);
129 }
130
131 inline std::vector<ImmutablePass *>& getImmutablePasses() {
132 return ImmutablePasses;
133 }
134
Devang Patelf33f3eb2006-12-07 19:21:29 +0000135private:
136
137 /// Collection of pass managers
138 std::vector<Pass *> PassManagers;
139
140 // Map to keep track of last user of the analysis pass.
141 // LastUser->second is the last user of Lastuser->first.
142 std::map<Pass *, Pass *> LastUser;
Devang Patele0eb9d82006-12-07 20:51:18 +0000143
144 /// Immutable passes are managed by top level manager.
145 std::vector<ImmutablePass *> ImmutablePasses;
Devang Patelf33f3eb2006-12-07 19:21:29 +0000146};
147
148/// Set pass P as the last user of the given analysis passes.
149void PMTopLevelManager::setLastUser(std::vector<Pass *> &AnalysisPasses,
150 Pass *P) {
151
152 for (std::vector<Pass *>::iterator I = AnalysisPasses.begin(),
153 E = AnalysisPasses.end(); I != E; ++I) {
154 Pass *AP = *I;
155 LastUser[AP] = P;
156 // If AP is the last user of other passes then make P last user of
157 // such passes.
158 for (std::map<Pass *, Pass *>::iterator LUI = LastUser.begin(),
159 LUE = LastUser.end(); LUI != LUE; ++LUI) {
160 if (LUI->second == AP)
161 LastUser[LUI->first] = P;
162 }
163 }
164
165}
166
167/// Collect passes whose last user is P
168void PMTopLevelManager::collectLastUses(std::vector<Pass *> &LastUses,
169 Pass *P) {
170 for (std::map<Pass *, Pass *>::iterator LUI = LastUser.begin(),
171 LUE = LastUser.end(); LUI != LUE; ++LUI)
172 if (LUI->second == P)
173 LastUses.push_back(LUI->first);
174}
175
Devang Patelde124182006-12-07 21:10:57 +0000176/// Schedule pass P for execution. Make sure that passes required by
177/// P are run before P is run. Update analysis info maintained by
178/// the manager. Remove dead passes. This is a recursive function.
179void PMTopLevelManager::schedulePass(Pass *P, Pass *PM) {
180
181 // TODO : Allocate function manager for this pass, other wise required set
182 // may be inserted into previous function manager
183
184 AnalysisUsage AnUsage;
185 P->getAnalysisUsage(AnUsage);
186 const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet();
187 for (std::vector<AnalysisID>::const_iterator I = RequiredSet.begin(),
188 E = RequiredSet.end(); I != E; ++I) {
189
190 Pass *AnalysisPass = NULL; // FIXME PM->getAnalysisPass(*I, true);
191 if (!AnalysisPass) {
192 // Schedule this analysis run first.
193 AnalysisPass = (*I)->createPass();
194 schedulePass(AnalysisPass, PM);
195 }
196 }
197
198 // Now all required passes are available.
199 addTopLevelPass(P);
200}
201
202
Devang Patelf3827bc2006-12-07 19:54:15 +0000203//===----------------------------------------------------------------------===//
204// PMDataManager
Devang Patelf33f3eb2006-12-07 19:21:29 +0000205
Devang Pateldbe4a1e2006-12-07 18:36:24 +0000206/// PMDataManager provides the common place to manage the analysis data
207/// used by pass managers.
208class PMDataManager {
Devang Patela9844592006-11-11 01:31:05 +0000209
210public:
211
Devang Patelf3827bc2006-12-07 19:54:15 +0000212 PMDataManager() : TPM(NULL) {
213 initializeAnalysisInfo();
214 }
215
Devang Patela9844592006-11-11 01:31:05 +0000216 /// Return true IFF pass P's required analysis set does not required new
217 /// manager.
218 bool manageablePass(Pass *P);
219
Devang Patelf60b5d92006-11-14 01:59:59 +0000220 Pass *getAnalysisPass(AnalysisID AID) const {
221
222 std::map<AnalysisID, Pass*>::const_iterator I =
223 AvailableAnalysis.find(AID);
224
225 if (I != AvailableAnalysis.end())
226 return NULL;
227 else
228 return I->second;
Devang Patelebba9702006-11-13 22:40:09 +0000229 }
Devang Patela9844592006-11-11 01:31:05 +0000230
Devang Patela9844592006-11-11 01:31:05 +0000231 /// Augment AvailableAnalysis by adding analysis made available by pass P.
Devang Patele9976aa2006-12-07 19:33:53 +0000232 void recordAvailableAnalysis(Pass *P);
Devang Patela9844592006-11-11 01:31:05 +0000233
Devang Patela9844592006-11-11 01:31:05 +0000234 /// Remove Analysis that is not preserved by the pass
235 void removeNotPreservedAnalysis(Pass *P);
236
237 /// Remove dead passes
Devang Patelca189262006-11-14 03:05:08 +0000238 void removeDeadPasses(Pass *P);
Devang Patela9844592006-11-11 01:31:05 +0000239
Devang Patel8f677ce2006-12-07 18:47:25 +0000240 /// Add pass P into the PassVector. Update
Devang Patel90b05e02006-11-11 02:04:19 +0000241 /// AvailableAnalysis appropriately if ProcessAnalysis is true.
242 void addPassToManager (Pass *P, bool ProcessAnalysis = true);
Devang Patel8cad70d2006-11-11 01:51:02 +0000243
Devang Patela6b6dcb2006-12-07 18:41:09 +0000244 // Initialize available analysis information.
245 void initializeAnalysisInfo() {
Devang Patel050ec722006-11-14 01:23:29 +0000246 AvailableAnalysis.clear();
Devang Patel3f0832a2006-11-14 02:54:23 +0000247 LastUser.clear();
Devang Patelb3900322006-12-07 21:02:08 +0000248
249 // Include immutable passes into AvailableAnalysis vector.
250 std::vector<ImmutablePass *> &ImmutablePasses = TPM->getImmutablePasses();
251 for (std::vector<ImmutablePass *>::iterator I = ImmutablePasses.begin(),
252 E = ImmutablePasses.end(); I != E; ++I)
253 recordAvailableAnalysis(*I);
Devang Patel050ec722006-11-14 01:23:29 +0000254 }
255
Devang Patelf60b5d92006-11-14 01:59:59 +0000256 // All Required analyses should be available to the pass as it runs! Here
257 // we fill in the AnalysisImpls member of the pass so that it can
258 // successfully use the getAnalysis() method to retrieve the
259 // implementations it needs.
260 //
Devang Patel07f4f582006-11-14 21:49:36 +0000261 void initializeAnalysisImpl(Pass *P);
Devang Patelf60b5d92006-11-14 01:59:59 +0000262
Devang Patel8cad70d2006-11-11 01:51:02 +0000263 inline std::vector<Pass *>::iterator passVectorBegin() {
264 return PassVector.begin();
265 }
266
267 inline std::vector<Pass *>::iterator passVectorEnd() {
268 return PassVector.end();
269 }
270
Devang Patel4a3fa4f2006-11-15 01:48:14 +0000271 inline void setLastUser(Pass *P, Pass *LU) {
Devang Patel07f4f582006-11-14 21:49:36 +0000272 LastUser[P] = LU;
273 // TODO : Check if pass P is available.
Devang Patel07f4f582006-11-14 21:49:36 +0000274 }
Devang Patel3f0832a2006-11-14 02:54:23 +0000275
Devang Patelf3827bc2006-12-07 19:54:15 +0000276 // Access toplevel manager
277 PMTopLevelManager *getTopLevelManager() { return TPM; }
278 void setTopLevelManager(PMTopLevelManager *T) { TPM = T; }
279
Devang Patela9844592006-11-11 01:31:05 +0000280private:
Devang Pateldafa4dd2006-11-14 00:03:04 +0000281 // Set of available Analysis. This information is used while scheduling
282 // pass. If a pass requires an analysis which is not not available then
283 // equired analysis pass is scheduled to run before the pass itself is
284 // scheduled to run.
Devang Patelf60b5d92006-11-14 01:59:59 +0000285 std::map<AnalysisID, Pass*> AvailableAnalysis;
Devang Patel8cad70d2006-11-11 01:51:02 +0000286
Devang Patel3f0832a2006-11-14 02:54:23 +0000287 // Map to keep track of last user of the analysis pass.
288 // LastUser->second is the last user of Lastuser->first.
289 std::map<Pass *, Pass *> LastUser;
290
Devang Patel8cad70d2006-11-11 01:51:02 +0000291 // Collection of pass that are managed by this manager
292 std::vector<Pass *> PassVector;
Devang Patelf3827bc2006-12-07 19:54:15 +0000293
294 // Top level manager.
295 // TODO : Make it a reference.
296 PMTopLevelManager *TPM;
Devang Patela9844592006-11-11 01:31:05 +0000297};
298
Devang Patelca58e352006-11-08 10:05:38 +0000299/// BasicBlockPassManager_New manages BasicBlockPass. It batches all the
300/// pass together and sequence them to process one basic block before
301/// processing next basic block.
Devang Pateldbe4a1e2006-12-07 18:36:24 +0000302class BasicBlockPassManager_New : public PMDataManager,
Devang Patel42add712006-11-15 01:11:27 +0000303 public FunctionPass {
Devang Patelca58e352006-11-08 10:05:38 +0000304
305public:
306 BasicBlockPassManager_New() { }
307
308 /// Add a pass into a passmanager queue.
309 bool addPass(Pass *p);
310
311 /// Execute all of the passes scheduled for execution. Keep track of
312 /// whether any of the passes modifies the function, and if so, return true.
313 bool runOnFunction(Function &F);
314
Devang Patelebba9702006-11-13 22:40:09 +0000315 /// Return true IFF AnalysisID AID is currently available.
Devang Patel3f0832a2006-11-14 02:54:23 +0000316 Pass *getAnalysisPassFromManager(AnalysisID AID);
Devang Patelebba9702006-11-13 22:40:09 +0000317
Devang Patelf9d96b92006-12-07 19:57:52 +0000318 /// Pass Manager itself does not invalidate any analysis info.
319 void getAnalysisUsage(AnalysisUsage &Info) const {
320 Info.setPreservesAll();
321 }
322
Devang Patelca58e352006-11-08 10:05:38 +0000323private:
Devang Patelca58e352006-11-08 10:05:38 +0000324};
325
Devang Patel4e12f862006-11-08 10:44:40 +0000326/// FunctionPassManagerImpl_New manages FunctionPasses and BasicBlockPassManagers.
Devang Patelca58e352006-11-08 10:05:38 +0000327/// It batches all function passes and basic block pass managers together and
328/// sequence them to process one function at a time before processing next
329/// function.
Devang Pateldbe4a1e2006-12-07 18:36:24 +0000330class FunctionPassManagerImpl_New : public PMDataManager,
Devang Patel42add712006-11-15 01:11:27 +0000331 public ModulePass {
Devang Patelca58e352006-11-08 10:05:38 +0000332public:
Devang Patel4e12f862006-11-08 10:44:40 +0000333 FunctionPassManagerImpl_New(ModuleProvider *P) { /* TODO */ }
334 FunctionPassManagerImpl_New() {
Devang Patelca58e352006-11-08 10:05:38 +0000335 activeBBPassManager = NULL;
336 }
Devang Patel4e12f862006-11-08 10:44:40 +0000337 ~FunctionPassManagerImpl_New() { /* TODO */ };
Devang Patelca58e352006-11-08 10:05:38 +0000338
339 /// add - Add a pass to the queue of passes to run. This passes
340 /// ownership of the Pass to the PassManager. When the
341 /// PassManager_X is destroyed, the pass will be destroyed as well, so
342 /// there is no need to delete the pass. (TODO delete passes.)
343 /// This implies that all passes MUST be allocated with 'new'.
344 void add(Pass *P) { /* TODO*/ }
345
346 /// Add pass into the pass manager queue.
347 bool addPass(Pass *P);
348
349 /// Execute all of the passes scheduled for execution. Keep
350 /// track of whether any of the passes modifies the function, and if
351 /// so, return true.
352 bool runOnModule(Module &M);
Devang Patel9f3083e2006-11-15 19:39:54 +0000353 bool runOnFunction(Function &F);
Devang Patelca58e352006-11-08 10:05:38 +0000354
Devang Patelebba9702006-11-13 22:40:09 +0000355 /// Return true IFF AnalysisID AID is currently available.
Devang Patel3f0832a2006-11-14 02:54:23 +0000356 Pass *getAnalysisPassFromManager(AnalysisID AID);
Devang Patelebba9702006-11-13 22:40:09 +0000357
Devang Patelff631ae2006-11-15 01:27:05 +0000358 /// doInitialization - Run all of the initializers for the function passes.
359 ///
360 bool doInitialization(Module &M);
361
362 /// doFinalization - Run all of the initializers for the function passes.
363 ///
364 bool doFinalization(Module &M);
Devang Patelf9d96b92006-12-07 19:57:52 +0000365
366 /// Pass Manager itself does not invalidate any analysis info.
367 void getAnalysisUsage(AnalysisUsage &Info) const {
368 Info.setPreservesAll();
369 }
370
Devang Patelca58e352006-11-08 10:05:38 +0000371private:
Devang Patelca58e352006-11-08 10:05:38 +0000372 // Active Pass Managers
373 BasicBlockPassManager_New *activeBBPassManager;
374};
375
376/// ModulePassManager_New manages ModulePasses and function pass managers.
377/// It batches all Module passes passes and function pass managers together and
378/// sequence them to process one module.
Devang Pateldbe4a1e2006-12-07 18:36:24 +0000379class ModulePassManager_New : public PMDataManager {
Devang Patelca58e352006-11-08 10:05:38 +0000380
381public:
382 ModulePassManager_New() { activeFunctionPassManager = NULL; }
383
384 /// Add a pass into a passmanager queue.
385 bool addPass(Pass *p);
386
387 /// run - Execute all of the passes scheduled for execution. Keep track of
388 /// whether any of the passes modifies the module, and if so, return true.
389 bool runOnModule(Module &M);
Devang Patelebba9702006-11-13 22:40:09 +0000390
391 /// Return true IFF AnalysisID AID is currently available.
Devang Patel3f0832a2006-11-14 02:54:23 +0000392 Pass *getAnalysisPassFromManager(AnalysisID AID);
Devang Patelf9d96b92006-12-07 19:57:52 +0000393
394 /// Pass Manager itself does not invalidate any analysis info.
395 void getAnalysisUsage(AnalysisUsage &Info) const {
396 Info.setPreservesAll();
397 }
398
Devang Patelca58e352006-11-08 10:05:38 +0000399private:
Devang Patelca58e352006-11-08 10:05:38 +0000400 // Active Pass Manager
Devang Patel4e12f862006-11-08 10:44:40 +0000401 FunctionPassManagerImpl_New *activeFunctionPassManager;
Devang Patelca58e352006-11-08 10:05:38 +0000402};
403
Devang Patel376fefa2006-11-08 10:29:57 +0000404/// PassManager_New manages ModulePassManagers
Devang Pateldbe4a1e2006-12-07 18:36:24 +0000405class PassManagerImpl_New : public PMDataManager {
Devang Patel376fefa2006-11-08 10:29:57 +0000406
407public:
408
409 /// add - Add a pass to the queue of passes to run. This passes ownership of
410 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
411 /// will be destroyed as well, so there is no need to delete the pass. This
412 /// implies that all passes MUST be allocated with 'new'.
413 void add(Pass *P);
414
415 /// run - Execute all of the passes scheduled for execution. Keep track of
416 /// whether any of the passes modifies the module, and if so, return true.
417 bool run(Module &M);
418
Devang Patelebba9702006-11-13 22:40:09 +0000419 /// Return true IFF AnalysisID AID is currently available.
Devang Patel3f0832a2006-11-14 02:54:23 +0000420 Pass *getAnalysisPassFromManager(AnalysisID AID);
Devang Patelebba9702006-11-13 22:40:09 +0000421
Devang Patelf9d96b92006-12-07 19:57:52 +0000422 /// Pass Manager itself does not invalidate any analysis info.
423 void getAnalysisUsage(AnalysisUsage &Info) const {
424 Info.setPreservesAll();
425 }
426
Devang Patel376fefa2006-11-08 10:29:57 +0000427private:
428
Devang Patelde124182006-12-07 21:10:57 +0000429 /// Add a pass into a passmanager queue.
Devang Patel376fefa2006-11-08 10:29:57 +0000430 bool addPass(Pass *p);
431
Devang Patel376fefa2006-11-08 10:29:57 +0000432 // Collection of pass managers
433 std::vector<ModulePassManager_New *> PassManagers;
434
Devang Patel376fefa2006-11-08 10:29:57 +0000435 // Active Pass Manager
436 ModulePassManager_New *activeManager;
437};
438
Devang Patelca58e352006-11-08 10:05:38 +0000439} // End of llvm namespace
440
Devang Patela1514cb2006-12-07 19:39:39 +0000441//===----------------------------------------------------------------------===//
Devang Pateldbe4a1e2006-12-07 18:36:24 +0000442// PMDataManager implementation
Devang Patelf68a3492006-11-07 22:35:17 +0000443
Devang Pateld65e9e92006-11-08 01:31:28 +0000444/// Return true IFF pass P's required analysis set does not required new
Devang Patelf68a3492006-11-07 22:35:17 +0000445/// manager.
Devang Pateldbe4a1e2006-12-07 18:36:24 +0000446bool PMDataManager::manageablePass(Pass *P) {
Devang Patelf68a3492006-11-07 22:35:17 +0000447
Devang Patel8f677ce2006-12-07 18:47:25 +0000448 // TODO
449 // If this pass is not preserving information that is required by a
450 // pass maintained by higher level pass manager then do not insert
451 // this pass into current manager. Use new manager. For example,
452 // For example, If FunctionPass F is not preserving ModulePass Info M1
453 // that is used by another ModulePass M2 then do not insert F in
454 // current function pass manager.
Devang Patelf68a3492006-11-07 22:35:17 +0000455 return true;
456}
457
Devang Patel643676c2006-11-11 01:10:19 +0000458/// Augement AvailableAnalysis by adding analysis made available by pass P.
Devang Patele9976aa2006-12-07 19:33:53 +0000459void PMDataManager::recordAvailableAnalysis(Pass *P) {
Devang Patelf60b5d92006-11-14 01:59:59 +0000460
Devang Patel643676c2006-11-11 01:10:19 +0000461 if (const PassInfo *PI = P->getPassInfo()) {
Devang Patelf60b5d92006-11-14 01:59:59 +0000462 AvailableAnalysis[PI] = P;
Devang Patel643676c2006-11-11 01:10:19 +0000463
Devang Patele9976aa2006-12-07 19:33:53 +0000464 //This pass is the current implementation of all of the interfaces it
465 //implements as well.
466 const std::vector<const PassInfo*> &II = PI->getInterfacesImplemented();
467 for (unsigned i = 0, e = II.size(); i != e; ++i)
468 AvailableAnalysis[II[i]] = P;
Devang Patel643676c2006-11-11 01:10:19 +0000469 }
470}
471
Devang Patelf68a3492006-11-07 22:35:17 +0000472/// Remove Analyss not preserved by Pass P
Devang Pateldbe4a1e2006-12-07 18:36:24 +0000473void PMDataManager::removeNotPreservedAnalysis(Pass *P) {
Devang Patel349170f2006-11-11 01:24:55 +0000474 AnalysisUsage AnUsage;
475 P->getAnalysisUsage(AnUsage);
Devang Patelf68a3492006-11-07 22:35:17 +0000476
Devang Patel2e169c32006-12-07 20:03:49 +0000477 if (AnUsage.getPreservesAll())
478 return;
479
480 const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
Devang Patelf60b5d92006-11-14 01:59:59 +0000481 for (std::map<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(),
Devang Patel349170f2006-11-11 01:24:55 +0000482 E = AvailableAnalysis.end(); I != E; ++I ) {
Devang Patelf60b5d92006-11-14 01:59:59 +0000483 if (std::find(PreservedSet.begin(), PreservedSet.end(), I->first) ==
Devang Patel349170f2006-11-11 01:24:55 +0000484 PreservedSet.end()) {
485 // Remove this analysis
Devang Patelf60b5d92006-11-14 01:59:59 +0000486 std::map<AnalysisID, Pass*>::iterator J = I++;
Devang Patel349170f2006-11-11 01:24:55 +0000487 AvailableAnalysis.erase(J);
488 }
489 }
Devang Patelf68a3492006-11-07 22:35:17 +0000490}
491
Devang Patelca189262006-11-14 03:05:08 +0000492/// Remove analysis passes that are not used any longer
Devang Pateldbe4a1e2006-12-07 18:36:24 +0000493void PMDataManager::removeDeadPasses(Pass *P) {
Devang Patelca189262006-11-14 03:05:08 +0000494
495 for (std::map<Pass *, Pass *>::iterator I = LastUser.begin(),
496 E = LastUser.end(); I !=E; ++I) {
497 if (I->second == P) {
498 Pass *deadPass = I->first;
499 deadPass->releaseMemory();
500
501 std::map<AnalysisID, Pass*>::iterator Pos =
502 AvailableAnalysis.find(deadPass->getPassInfo());
503
504 assert (Pos != AvailableAnalysis.end() &&
505 "Pass is not available");
506 AvailableAnalysis.erase(Pos);
507 }
508 }
509}
510
Devang Patel8f677ce2006-12-07 18:47:25 +0000511/// Add pass P into the PassVector. Update
Devang Patel90b05e02006-11-11 02:04:19 +0000512/// AvailableAnalysis appropriately if ProcessAnalysis is true.
Devang Patel2e169c32006-12-07 20:03:49 +0000513void PMDataManager::addPassToManager(Pass *P,
514 bool ProcessAnalysis) {
Devang Patel8cad70d2006-11-11 01:51:02 +0000515
Devang Patel90b05e02006-11-11 02:04:19 +0000516 if (ProcessAnalysis) {
517 // Take a note of analysis required and made available by this pass
Devang Patel8f677ce2006-12-07 18:47:25 +0000518 initializeAnalysisImpl(P);
Devang Patele9976aa2006-12-07 19:33:53 +0000519 recordAvailableAnalysis(P);
Devang Patel90b05e02006-11-11 02:04:19 +0000520
521 // Remove the analysis not preserved by this pass
522 removeNotPreservedAnalysis(P);
523 }
Devang Patel8cad70d2006-11-11 01:51:02 +0000524
525 // Add pass
526 PassVector.push_back(P);
Devang Patel8cad70d2006-11-11 01:51:02 +0000527}
528
Devang Patel07f4f582006-11-14 21:49:36 +0000529// All Required analyses should be available to the pass as it runs! Here
530// we fill in the AnalysisImpls member of the pass so that it can
531// successfully use the getAnalysis() method to retrieve the
532// implementations it needs.
533//
Devang Pateldbe4a1e2006-12-07 18:36:24 +0000534void PMDataManager::initializeAnalysisImpl(Pass *P) {
Devang Patelff631ae2006-11-15 01:27:05 +0000535 AnalysisUsage AnUsage;
536 P->getAnalysisUsage(AnUsage);
Devang Patel07f4f582006-11-14 21:49:36 +0000537
538 for (std::vector<const PassInfo *>::const_iterator
539 I = AnUsage.getRequiredSet().begin(),
540 E = AnUsage.getRequiredSet().end(); I != E; ++I) {
541 Pass *Impl = getAnalysisPass(*I);
542 if (Impl == 0)
543 assert(0 && "Analysis used but not available!");
544 // TODO: P->AnalysisImpls.push_back(std::make_pair(*I, Impl));
545 }
546}
547
Devang Patela1514cb2006-12-07 19:39:39 +0000548//===----------------------------------------------------------------------===//
549// BasicBlockPassManager_New implementation
Devang Patel6e5a1132006-11-07 21:31:57 +0000550
Devang Pateld65e9e92006-11-08 01:31:28 +0000551/// Add pass P into PassVector and return true. If this pass is not
552/// manageable by this manager then return false.
Devang Patel6e5a1132006-11-07 21:31:57 +0000553bool
Devang Pateld65e9e92006-11-08 01:31:28 +0000554BasicBlockPassManager_New::addPass(Pass *P) {
Devang Patel6e5a1132006-11-07 21:31:57 +0000555
556 BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P);
557 if (!BP)
558 return false;
559
Devang Patel3c8eb622006-11-07 22:56:50 +0000560 // If this pass does not preserve anlysis that is used by other passes
561 // managed by this manager than it is not a suiable pass for this manager.
Devang Pateld65e9e92006-11-08 01:31:28 +0000562 if (!manageablePass(P))
Devang Patel3c8eb622006-11-07 22:56:50 +0000563 return false;
564
Devang Patel8cad70d2006-11-11 01:51:02 +0000565 addPassToManager (BP);
Devang Patel349170f2006-11-11 01:24:55 +0000566
Devang Patel6e5a1132006-11-07 21:31:57 +0000567 return true;
568}
569
570/// Execute all of the passes scheduled for execution by invoking
571/// runOnBasicBlock method. Keep track of whether any of the passes modifies
572/// the function, and if so, return true.
573bool
574BasicBlockPassManager_New::runOnFunction(Function &F) {
575
576 bool Changed = false;
Devang Patela6b6dcb2006-12-07 18:41:09 +0000577 initializeAnalysisInfo();
Devang Patel050ec722006-11-14 01:23:29 +0000578
Devang Patel6e5a1132006-11-07 21:31:57 +0000579 for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
Devang Patel8cad70d2006-11-11 01:51:02 +0000580 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
581 e = passVectorEnd(); itr != e; ++itr) {
Devang Patel6e5a1132006-11-07 21:31:57 +0000582 Pass *P = *itr;
Devang Patel050ec722006-11-14 01:23:29 +0000583
Devang Patele9976aa2006-12-07 19:33:53 +0000584 recordAvailableAnalysis(P);
Devang Patel6e5a1132006-11-07 21:31:57 +0000585 BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P);
586 Changed |= BP->runOnBasicBlock(*I);
Devang Patel050ec722006-11-14 01:23:29 +0000587 removeNotPreservedAnalysis(P);
Devang Patelca189262006-11-14 03:05:08 +0000588 removeDeadPasses(P);
Devang Patel6e5a1132006-11-07 21:31:57 +0000589 }
590 return Changed;
591}
592
Devang Patelebba9702006-11-13 22:40:09 +0000593/// Return true IFF AnalysisID AID is currently available.
Devang Patel3f0832a2006-11-14 02:54:23 +0000594Pass * BasicBlockPassManager_New::getAnalysisPassFromManager(AnalysisID AID) {
595 return getAnalysisPass(AID);
Devang Patelebba9702006-11-13 22:40:09 +0000596}
597
Devang Patela1514cb2006-12-07 19:39:39 +0000598//===----------------------------------------------------------------------===//
Devang Patel0c2012f2006-11-07 21:49:50 +0000599// FunctionPassManager_New implementation
Devang Patela1514cb2006-12-07 19:39:39 +0000600
Devang Patel4e12f862006-11-08 10:44:40 +0000601/// Create new Function pass manager
602FunctionPassManager_New::FunctionPassManager_New() {
603 FPM = new FunctionPassManagerImpl_New();
604}
605
606/// add - Add a pass to the queue of passes to run. This passes
607/// ownership of the Pass to the PassManager. When the
608/// PassManager_X is destroyed, the pass will be destroyed as well, so
609/// there is no need to delete the pass. (TODO delete passes.)
610/// This implies that all passes MUST be allocated with 'new'.
Devang Patel9f3083e2006-11-15 19:39:54 +0000611void FunctionPassManager_New::add(Pass *P) {
Devang Patel4e12f862006-11-08 10:44:40 +0000612 FPM->add(P);
613}
614
615/// Execute all of the passes scheduled for execution. Keep
616/// track of whether any of the passes modifies the function, and if
617/// so, return true.
Devang Patel9f3083e2006-11-15 19:39:54 +0000618bool FunctionPassManager_New::runOnModule(Module &M) {
Devang Patel4e12f862006-11-08 10:44:40 +0000619 return FPM->runOnModule(M);
620}
621
Devang Patel9f3083e2006-11-15 19:39:54 +0000622/// run - Execute all of the passes scheduled for execution. Keep
623/// track of whether any of the passes modifies the function, and if
624/// so, return true.
625///
626bool FunctionPassManager_New::run(Function &F) {
627 std::string errstr;
628 if (MP->materializeFunction(&F, &errstr)) {
Bill Wendlingf3baad32006-12-07 01:30:32 +0000629 cerr << "Error reading bytecode file: " << errstr << "\n";
Devang Patel9f3083e2006-11-15 19:39:54 +0000630 abort();
631 }
632 return FPM->runOnFunction(F);
633}
634
635
Devang Patelff631ae2006-11-15 01:27:05 +0000636/// doInitialization - Run all of the initializers for the function passes.
637///
638bool FunctionPassManager_New::doInitialization() {
639 return FPM->doInitialization(*MP->getModule());
640}
641
642/// doFinalization - Run all of the initializers for the function passes.
643///
644bool FunctionPassManager_New::doFinalization() {
645 return FPM->doFinalization(*MP->getModule());
646}
647
Devang Patela1514cb2006-12-07 19:39:39 +0000648//===----------------------------------------------------------------------===//
Devang Patel4e12f862006-11-08 10:44:40 +0000649// FunctionPassManagerImpl_New implementation
Devang Patel0c2012f2006-11-07 21:49:50 +0000650
Devang Patel0c2012f2006-11-07 21:49:50 +0000651/// Add pass P into the pass manager queue. If P is a BasicBlockPass then
652/// either use it into active basic block pass manager or create new basic
653/// block pass manager to handle pass P.
654bool
Devang Patel4e12f862006-11-08 10:44:40 +0000655FunctionPassManagerImpl_New::addPass(Pass *P) {
Devang Patel0c2012f2006-11-07 21:49:50 +0000656
657 // If P is a BasicBlockPass then use BasicBlockPassManager_New.
658 if (BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P)) {
659
660 if (!activeBBPassManager
661 || !activeBBPassManager->addPass(BP)) {
662
663 activeBBPassManager = new BasicBlockPassManager_New();
Devang Patel90b05e02006-11-11 02:04:19 +0000664 addPassToManager(activeBBPassManager, false);
Devang Pateld65e9e92006-11-08 01:31:28 +0000665 if (!activeBBPassManager->addPass(BP))
666 assert(0 && "Unable to add Pass");
Devang Patel0c2012f2006-11-07 21:49:50 +0000667 }
668 return true;
669 }
670
671 FunctionPass *FP = dynamic_cast<FunctionPass *>(P);
672 if (!FP)
673 return false;
674
Devang Patel3c8eb622006-11-07 22:56:50 +0000675 // If this pass does not preserve anlysis that is used by other passes
676 // managed by this manager than it is not a suiable pass for this manager.
Devang Pateld65e9e92006-11-08 01:31:28 +0000677 if (!manageablePass(P))
Devang Patel3c8eb622006-11-07 22:56:50 +0000678 return false;
679
Devang Patel8cad70d2006-11-11 01:51:02 +0000680 addPassToManager (FP);
Devang Patel0c2012f2006-11-07 21:49:50 +0000681 activeBBPassManager = NULL;
682 return true;
683}
684
685/// Execute all of the passes scheduled for execution by invoking
686/// runOnFunction method. Keep track of whether any of the passes modifies
687/// the function, and if so, return true.
Devang Patel9f3083e2006-11-15 19:39:54 +0000688bool FunctionPassManagerImpl_New::runOnModule(Module &M) {
Devang Patel0c2012f2006-11-07 21:49:50 +0000689
690 bool Changed = false;
Devang Patela6b6dcb2006-12-07 18:41:09 +0000691 initializeAnalysisInfo();
Devang Patel050ec722006-11-14 01:23:29 +0000692
Devang Patel0c2012f2006-11-07 21:49:50 +0000693 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
Devang Patel8cad70d2006-11-11 01:51:02 +0000694 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
695 e = passVectorEnd(); itr != e; ++itr) {
Devang Patel0c2012f2006-11-07 21:49:50 +0000696 Pass *P = *itr;
Devang Patel050ec722006-11-14 01:23:29 +0000697
Devang Patele9976aa2006-12-07 19:33:53 +0000698 recordAvailableAnalysis(P);
Devang Patel0c2012f2006-11-07 21:49:50 +0000699 FunctionPass *FP = dynamic_cast<FunctionPass*>(P);
700 Changed |= FP->runOnFunction(*I);
Devang Patel050ec722006-11-14 01:23:29 +0000701 removeNotPreservedAnalysis(P);
Devang Patelca189262006-11-14 03:05:08 +0000702 removeDeadPasses(P);
Devang Patel0c2012f2006-11-07 21:49:50 +0000703 }
704 return Changed;
705}
706
Devang Patel9f3083e2006-11-15 19:39:54 +0000707/// Execute all of the passes scheduled for execution by invoking
708/// runOnFunction method. Keep track of whether any of the passes modifies
709/// the function, and if so, return true.
710bool FunctionPassManagerImpl_New::runOnFunction(Function &F) {
711
712 bool Changed = false;
Devang Patela6b6dcb2006-12-07 18:41:09 +0000713 initializeAnalysisInfo();
Devang Patel9f3083e2006-11-15 19:39:54 +0000714
715 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
716 e = passVectorEnd(); itr != e; ++itr) {
717 Pass *P = *itr;
718
Devang Patele9976aa2006-12-07 19:33:53 +0000719 recordAvailableAnalysis(P);
Devang Patel9f3083e2006-11-15 19:39:54 +0000720 FunctionPass *FP = dynamic_cast<FunctionPass*>(P);
721 Changed |= FP->runOnFunction(F);
722 removeNotPreservedAnalysis(P);
723 removeDeadPasses(P);
724 }
725 return Changed;
726}
727
728
Devang Patelebba9702006-11-13 22:40:09 +0000729/// Return true IFF AnalysisID AID is currently available.
Devang Patel3f0832a2006-11-14 02:54:23 +0000730Pass *FunctionPassManagerImpl_New::getAnalysisPassFromManager(AnalysisID AID) {
Devang Patelebba9702006-11-13 22:40:09 +0000731
Devang Patel3f0832a2006-11-14 02:54:23 +0000732 Pass *P = getAnalysisPass(AID);
733 if (P)
734 return P;
Devang Patelebba9702006-11-13 22:40:09 +0000735
736 if (activeBBPassManager &&
Devang Patelf60b5d92006-11-14 01:59:59 +0000737 activeBBPassManager->getAnalysisPass(AID) != 0)
Devang Patel3f0832a2006-11-14 02:54:23 +0000738 return activeBBPassManager->getAnalysisPass(AID);
Devang Patelebba9702006-11-13 22:40:09 +0000739
740 // TODO : Check inactive managers
Devang Patel3f0832a2006-11-14 02:54:23 +0000741 return NULL;
Devang Patelebba9702006-11-13 22:40:09 +0000742}
Devang Patel0c2012f2006-11-07 21:49:50 +0000743
Devang Patelff631ae2006-11-15 01:27:05 +0000744inline bool FunctionPassManagerImpl_New::doInitialization(Module &M) {
745 bool Changed = false;
746
747 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
748 e = passVectorEnd(); itr != e; ++itr) {
749 Pass *P = *itr;
750
751 FunctionPass *FP = dynamic_cast<FunctionPass*>(P);
752 Changed |= FP->doInitialization(M);
753 }
754
755 return Changed;
756}
757
758inline bool FunctionPassManagerImpl_New::doFinalization(Module &M) {
759 bool Changed = false;
760
761 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
762 e = passVectorEnd(); itr != e; ++itr) {
763 Pass *P = *itr;
764
765 FunctionPass *FP = dynamic_cast<FunctionPass*>(P);
766 Changed |= FP->doFinalization(M);
767 }
768
769
770 return Changed;
771}
772
Devang Patela1514cb2006-12-07 19:39:39 +0000773//===----------------------------------------------------------------------===//
Devang Patel05e1a972006-11-07 22:03:15 +0000774// ModulePassManager implementation
775
776/// Add P into pass vector if it is manageble. If P is a FunctionPass
Devang Patel4e12f862006-11-08 10:44:40 +0000777/// then use FunctionPassManagerImpl_New to manage it. Return false if P
Devang Patel05e1a972006-11-07 22:03:15 +0000778/// is not manageable by this manager.
779bool
Devang Pateld65e9e92006-11-08 01:31:28 +0000780ModulePassManager_New::addPass(Pass *P) {
Devang Patel05e1a972006-11-07 22:03:15 +0000781
782 // If P is FunctionPass then use function pass maanager.
783 if (FunctionPass *FP = dynamic_cast<FunctionPass*>(P)) {
784
785 activeFunctionPassManager = NULL;
786
787 if (!activeFunctionPassManager
788 || !activeFunctionPassManager->addPass(P)) {
789
Devang Patel4e12f862006-11-08 10:44:40 +0000790 activeFunctionPassManager = new FunctionPassManagerImpl_New();
Devang Patel90b05e02006-11-11 02:04:19 +0000791 addPassToManager(activeFunctionPassManager, false);
Devang Pateld65e9e92006-11-08 01:31:28 +0000792 if (!activeFunctionPassManager->addPass(FP))
793 assert(0 && "Unable to add pass");
Devang Patel05e1a972006-11-07 22:03:15 +0000794 }
795 return true;
796 }
797
798 ModulePass *MP = dynamic_cast<ModulePass *>(P);
799 if (!MP)
800 return false;
801
Devang Patel3c8eb622006-11-07 22:56:50 +0000802 // If this pass does not preserve anlysis that is used by other passes
803 // managed by this manager than it is not a suiable pass for this manager.
Devang Pateld65e9e92006-11-08 01:31:28 +0000804 if (!manageablePass(P))
Devang Patel3c8eb622006-11-07 22:56:50 +0000805 return false;
806
Devang Patel8cad70d2006-11-11 01:51:02 +0000807 addPassToManager(MP);
Devang Patel05e1a972006-11-07 22:03:15 +0000808 activeFunctionPassManager = NULL;
809 return true;
810}
811
812
813/// Execute all of the passes scheduled for execution by invoking
814/// runOnModule method. Keep track of whether any of the passes modifies
815/// the module, and if so, return true.
816bool
817ModulePassManager_New::runOnModule(Module &M) {
818 bool Changed = false;
Devang Patela6b6dcb2006-12-07 18:41:09 +0000819 initializeAnalysisInfo();
Devang Patel050ec722006-11-14 01:23:29 +0000820
Devang Patel8cad70d2006-11-11 01:51:02 +0000821 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
822 e = passVectorEnd(); itr != e; ++itr) {
Devang Patel05e1a972006-11-07 22:03:15 +0000823 Pass *P = *itr;
Devang Patel050ec722006-11-14 01:23:29 +0000824
Devang Patele9976aa2006-12-07 19:33:53 +0000825 recordAvailableAnalysis(P);
Devang Patel05e1a972006-11-07 22:03:15 +0000826 ModulePass *MP = dynamic_cast<ModulePass*>(P);
827 Changed |= MP->runOnModule(M);
Devang Patel050ec722006-11-14 01:23:29 +0000828 removeNotPreservedAnalysis(P);
Devang Patelca189262006-11-14 03:05:08 +0000829 removeDeadPasses(P);
Devang Patel05e1a972006-11-07 22:03:15 +0000830 }
831 return Changed;
832}
833
Devang Patelebba9702006-11-13 22:40:09 +0000834/// Return true IFF AnalysisID AID is currently available.
Devang Patel3f0832a2006-11-14 02:54:23 +0000835Pass *ModulePassManager_New::getAnalysisPassFromManager(AnalysisID AID) {
Devang Patelebba9702006-11-13 22:40:09 +0000836
Devang Patel3f0832a2006-11-14 02:54:23 +0000837
838 Pass *P = getAnalysisPass(AID);
839 if (P)
840 return P;
Devang Patelebba9702006-11-13 22:40:09 +0000841
842 if (activeFunctionPassManager &&
Devang Patelf60b5d92006-11-14 01:59:59 +0000843 activeFunctionPassManager->getAnalysisPass(AID) != 0)
Devang Patel3f0832a2006-11-14 02:54:23 +0000844 return activeFunctionPassManager->getAnalysisPass(AID);
Devang Patelebba9702006-11-13 22:40:09 +0000845
846 // TODO : Check inactive managers
Devang Patel3f0832a2006-11-14 02:54:23 +0000847 return NULL;
Devang Patelebba9702006-11-13 22:40:09 +0000848}
849
Devang Patela1514cb2006-12-07 19:39:39 +0000850//===----------------------------------------------------------------------===//
851// PassManagerImpl implementation
852
Devang Patelebba9702006-11-13 22:40:09 +0000853/// Return true IFF AnalysisID AID is currently available.
Devang Patel3f0832a2006-11-14 02:54:23 +0000854Pass *PassManagerImpl_New::getAnalysisPassFromManager(AnalysisID AID) {
Devang Patelebba9702006-11-13 22:40:09 +0000855
Devang Patel3f0832a2006-11-14 02:54:23 +0000856 Pass *P = NULL;
Devang Patel70868442006-11-13 22:53:19 +0000857 for (std::vector<ModulePassManager_New *>::iterator itr = PassManagers.begin(),
Devang Patel3f0832a2006-11-14 02:54:23 +0000858 e = PassManagers.end(); !P && itr != e; ++itr)
859 P = (*itr)->getAnalysisPassFromManager(AID);
860 return P;
Devang Patelebba9702006-11-13 22:40:09 +0000861}
862
Devang Patelc290c8a2006-11-07 22:23:34 +0000863/// Add pass P to the queue of passes to run.
Devang Patel1a6eaa42006-11-11 02:22:31 +0000864void PassManagerImpl_New::add(Pass *P) {
865 // Do not process Analysis now. Analysis is process while scheduling
866 // the pass vector.
Devang Pateldb789fb2006-11-11 02:06:21 +0000867 addPassToManager(P, false);
Devang Patelc290c8a2006-11-07 22:23:34 +0000868}
869
870// PassManager_New implementation
871/// Add P into active pass manager or use new module pass manager to
872/// manage it.
Devang Patel1a6eaa42006-11-11 02:22:31 +0000873bool PassManagerImpl_New::addPass(Pass *P) {
Devang Patelc290c8a2006-11-07 22:23:34 +0000874
Devang Patel6c9f5482006-11-11 00:42:16 +0000875 if (!activeManager || !activeManager->addPass(P)) {
Devang Patelc290c8a2006-11-07 22:23:34 +0000876 activeManager = new ModulePassManager_New();
877 PassManagers.push_back(activeManager);
878 }
879
880 return activeManager->addPass(P);
881}
882
883/// run - Execute all of the passes scheduled for execution. Keep track of
884/// whether any of the passes modifies the module, and if so, return true.
Devang Patel1a6eaa42006-11-11 02:22:31 +0000885bool PassManagerImpl_New::run(Module &M) {
Devang Patelc290c8a2006-11-07 22:23:34 +0000886
Devang Patelc290c8a2006-11-07 22:23:34 +0000887 bool Changed = false;
888 for (std::vector<ModulePassManager_New *>::iterator itr = PassManagers.begin(),
889 e = PassManagers.end(); itr != e; ++itr) {
890 ModulePassManager_New *pm = *itr;
891 Changed |= pm->runOnModule(M);
892 }
893 return Changed;
894}
Devang Patel376fefa2006-11-08 10:29:57 +0000895
Devang Patela1514cb2006-12-07 19:39:39 +0000896//===----------------------------------------------------------------------===//
897// PassManager implementation
898
Devang Patel376fefa2006-11-08 10:29:57 +0000899/// Create new pass manager
900PassManager_New::PassManager_New() {
901 PM = new PassManagerImpl_New();
902}
903
904/// add - Add a pass to the queue of passes to run. This passes ownership of
905/// the Pass to the PassManager. When the PassManager is destroyed, the pass
906/// will be destroyed as well, so there is no need to delete the pass. This
907/// implies that all passes MUST be allocated with 'new'.
908void
909PassManager_New::add(Pass *P) {
910 PM->add(P);
911}
912
913/// run - Execute all of the passes scheduled for execution. Keep track of
914/// whether any of the passes modifies the module, and if so, return true.
915bool
916PassManager_New::run(Module &M) {
917 return PM->run(M);
918}
919