blob: 9585b0dbce36c7c54f4e6a31797cff93ea1bed67 [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
125private:
126
127 /// Collection of pass managers
128 std::vector<Pass *> PassManagers;
129
130 // Map to keep track of last user of the analysis pass.
131 // LastUser->second is the last user of Lastuser->first.
132 std::map<Pass *, Pass *> LastUser;
133};
134
135/// Set pass P as the last user of the given analysis passes.
136void PMTopLevelManager::setLastUser(std::vector<Pass *> &AnalysisPasses,
137 Pass *P) {
138
139 for (std::vector<Pass *>::iterator I = AnalysisPasses.begin(),
140 E = AnalysisPasses.end(); I != E; ++I) {
141 Pass *AP = *I;
142 LastUser[AP] = P;
143 // If AP is the last user of other passes then make P last user of
144 // such passes.
145 for (std::map<Pass *, Pass *>::iterator LUI = LastUser.begin(),
146 LUE = LastUser.end(); LUI != LUE; ++LUI) {
147 if (LUI->second == AP)
148 LastUser[LUI->first] = P;
149 }
150 }
151
152}
153
154/// Collect passes whose last user is P
155void PMTopLevelManager::collectLastUses(std::vector<Pass *> &LastUses,
156 Pass *P) {
157 for (std::map<Pass *, Pass *>::iterator LUI = LastUser.begin(),
158 LUE = LastUser.end(); LUI != LUE; ++LUI)
159 if (LUI->second == P)
160 LastUses.push_back(LUI->first);
161}
162
Devang Patelf3827bc2006-12-07 19:54:15 +0000163//===----------------------------------------------------------------------===//
164// PMDataManager
Devang Patelf33f3eb2006-12-07 19:21:29 +0000165
Devang Pateldbe4a1e2006-12-07 18:36:24 +0000166/// PMDataManager provides the common place to manage the analysis data
167/// used by pass managers.
168class PMDataManager {
Devang Patela9844592006-11-11 01:31:05 +0000169
170public:
171
Devang Patelf3827bc2006-12-07 19:54:15 +0000172 PMDataManager() : TPM(NULL) {
173 initializeAnalysisInfo();
174 }
175
Devang Patela9844592006-11-11 01:31:05 +0000176 /// Return true IFF pass P's required analysis set does not required new
177 /// manager.
178 bool manageablePass(Pass *P);
179
Devang Patelf60b5d92006-11-14 01:59:59 +0000180 Pass *getAnalysisPass(AnalysisID AID) const {
181
182 std::map<AnalysisID, Pass*>::const_iterator I =
183 AvailableAnalysis.find(AID);
184
185 if (I != AvailableAnalysis.end())
186 return NULL;
187 else
188 return I->second;
Devang Patelebba9702006-11-13 22:40:09 +0000189 }
Devang Patela9844592006-11-11 01:31:05 +0000190
Devang Patela9844592006-11-11 01:31:05 +0000191 /// Augment AvailableAnalysis by adding analysis made available by pass P.
Devang Patele9976aa2006-12-07 19:33:53 +0000192 void recordAvailableAnalysis(Pass *P);
Devang Patela9844592006-11-11 01:31:05 +0000193
Devang Patela9844592006-11-11 01:31:05 +0000194 /// Remove Analysis that is not preserved by the pass
195 void removeNotPreservedAnalysis(Pass *P);
196
197 /// Remove dead passes
Devang Patelca189262006-11-14 03:05:08 +0000198 void removeDeadPasses(Pass *P);
Devang Patela9844592006-11-11 01:31:05 +0000199
Devang Patel8f677ce2006-12-07 18:47:25 +0000200 /// Add pass P into the PassVector. Update
Devang Patel90b05e02006-11-11 02:04:19 +0000201 /// AvailableAnalysis appropriately if ProcessAnalysis is true.
202 void addPassToManager (Pass *P, bool ProcessAnalysis = true);
Devang Patel8cad70d2006-11-11 01:51:02 +0000203
Devang Patela6b6dcb2006-12-07 18:41:09 +0000204 // Initialize available analysis information.
205 void initializeAnalysisInfo() {
Devang Patel050ec722006-11-14 01:23:29 +0000206 AvailableAnalysis.clear();
Devang Patel3f0832a2006-11-14 02:54:23 +0000207 LastUser.clear();
Devang Patel050ec722006-11-14 01:23:29 +0000208 }
209
Devang Patelf60b5d92006-11-14 01:59:59 +0000210 // All Required analyses should be available to the pass as it runs! Here
211 // we fill in the AnalysisImpls member of the pass so that it can
212 // successfully use the getAnalysis() method to retrieve the
213 // implementations it needs.
214 //
Devang Patel07f4f582006-11-14 21:49:36 +0000215 void initializeAnalysisImpl(Pass *P);
Devang Patelf60b5d92006-11-14 01:59:59 +0000216
Devang Patel8cad70d2006-11-11 01:51:02 +0000217 inline std::vector<Pass *>::iterator passVectorBegin() {
218 return PassVector.begin();
219 }
220
221 inline std::vector<Pass *>::iterator passVectorEnd() {
222 return PassVector.end();
223 }
224
Devang Patel4a3fa4f2006-11-15 01:48:14 +0000225 inline void setLastUser(Pass *P, Pass *LU) {
Devang Patel07f4f582006-11-14 21:49:36 +0000226 LastUser[P] = LU;
227 // TODO : Check if pass P is available.
Devang Patel07f4f582006-11-14 21:49:36 +0000228 }
Devang Patel3f0832a2006-11-14 02:54:23 +0000229
Devang Patelf3827bc2006-12-07 19:54:15 +0000230 // Access toplevel manager
231 PMTopLevelManager *getTopLevelManager() { return TPM; }
232 void setTopLevelManager(PMTopLevelManager *T) { TPM = T; }
233
Devang Patela9844592006-11-11 01:31:05 +0000234private:
Devang Pateldafa4dd2006-11-14 00:03:04 +0000235 // Set of available Analysis. This information is used while scheduling
236 // pass. If a pass requires an analysis which is not not available then
237 // equired analysis pass is scheduled to run before the pass itself is
238 // scheduled to run.
Devang Patelf60b5d92006-11-14 01:59:59 +0000239 std::map<AnalysisID, Pass*> AvailableAnalysis;
Devang Patel8cad70d2006-11-11 01:51:02 +0000240
Devang Patel3f0832a2006-11-14 02:54:23 +0000241 // Map to keep track of last user of the analysis pass.
242 // LastUser->second is the last user of Lastuser->first.
243 std::map<Pass *, Pass *> LastUser;
244
Devang Patel8cad70d2006-11-11 01:51:02 +0000245 // Collection of pass that are managed by this manager
246 std::vector<Pass *> PassVector;
Devang Patelf3827bc2006-12-07 19:54:15 +0000247
248 // Top level manager.
249 // TODO : Make it a reference.
250 PMTopLevelManager *TPM;
Devang Patela9844592006-11-11 01:31:05 +0000251};
252
Devang Patelca58e352006-11-08 10:05:38 +0000253/// BasicBlockPassManager_New manages BasicBlockPass. It batches all the
254/// pass together and sequence them to process one basic block before
255/// processing next basic block.
Devang Pateldbe4a1e2006-12-07 18:36:24 +0000256class BasicBlockPassManager_New : public PMDataManager,
Devang Patel42add712006-11-15 01:11:27 +0000257 public FunctionPass {
Devang Patelca58e352006-11-08 10:05:38 +0000258
259public:
260 BasicBlockPassManager_New() { }
261
262 /// Add a pass into a passmanager queue.
263 bool addPass(Pass *p);
264
265 /// Execute all of the passes scheduled for execution. Keep track of
266 /// whether any of the passes modifies the function, and if so, return true.
267 bool runOnFunction(Function &F);
268
Devang Patelebba9702006-11-13 22:40:09 +0000269 /// Return true IFF AnalysisID AID is currently available.
Devang Patel3f0832a2006-11-14 02:54:23 +0000270 Pass *getAnalysisPassFromManager(AnalysisID AID);
Devang Patelebba9702006-11-13 22:40:09 +0000271
Devang Patelf9d96b92006-12-07 19:57:52 +0000272 /// Pass Manager itself does not invalidate any analysis info.
273 void getAnalysisUsage(AnalysisUsage &Info) const {
274 Info.setPreservesAll();
275 }
276
Devang Patelca58e352006-11-08 10:05:38 +0000277private:
Devang Patelca58e352006-11-08 10:05:38 +0000278};
279
Devang Patel4e12f862006-11-08 10:44:40 +0000280/// FunctionPassManagerImpl_New manages FunctionPasses and BasicBlockPassManagers.
Devang Patelca58e352006-11-08 10:05:38 +0000281/// It batches all function passes and basic block pass managers together and
282/// sequence them to process one function at a time before processing next
283/// function.
Devang Pateldbe4a1e2006-12-07 18:36:24 +0000284class FunctionPassManagerImpl_New : public PMDataManager,
Devang Patel42add712006-11-15 01:11:27 +0000285 public ModulePass {
Devang Patelca58e352006-11-08 10:05:38 +0000286public:
Devang Patel4e12f862006-11-08 10:44:40 +0000287 FunctionPassManagerImpl_New(ModuleProvider *P) { /* TODO */ }
288 FunctionPassManagerImpl_New() {
Devang Patelca58e352006-11-08 10:05:38 +0000289 activeBBPassManager = NULL;
290 }
Devang Patel4e12f862006-11-08 10:44:40 +0000291 ~FunctionPassManagerImpl_New() { /* TODO */ };
Devang Patelca58e352006-11-08 10:05:38 +0000292
293 /// add - Add a pass to the queue of passes to run. This passes
294 /// ownership of the Pass to the PassManager. When the
295 /// PassManager_X is destroyed, the pass will be destroyed as well, so
296 /// there is no need to delete the pass. (TODO delete passes.)
297 /// This implies that all passes MUST be allocated with 'new'.
298 void add(Pass *P) { /* TODO*/ }
299
300 /// Add pass into the pass manager queue.
301 bool addPass(Pass *P);
302
303 /// Execute all of the passes scheduled for execution. Keep
304 /// track of whether any of the passes modifies the function, and if
305 /// so, return true.
306 bool runOnModule(Module &M);
Devang Patel9f3083e2006-11-15 19:39:54 +0000307 bool runOnFunction(Function &F);
Devang Patelca58e352006-11-08 10:05:38 +0000308
Devang Patelebba9702006-11-13 22:40:09 +0000309 /// Return true IFF AnalysisID AID is currently available.
Devang Patel3f0832a2006-11-14 02:54:23 +0000310 Pass *getAnalysisPassFromManager(AnalysisID AID);
Devang Patelebba9702006-11-13 22:40:09 +0000311
Devang Patelff631ae2006-11-15 01:27:05 +0000312 /// doInitialization - Run all of the initializers for the function passes.
313 ///
314 bool doInitialization(Module &M);
315
316 /// doFinalization - Run all of the initializers for the function passes.
317 ///
318 bool doFinalization(Module &M);
Devang Patelf9d96b92006-12-07 19:57:52 +0000319
320 /// Pass Manager itself does not invalidate any analysis info.
321 void getAnalysisUsage(AnalysisUsage &Info) const {
322 Info.setPreservesAll();
323 }
324
Devang Patelca58e352006-11-08 10:05:38 +0000325private:
Devang Patelca58e352006-11-08 10:05:38 +0000326 // Active Pass Managers
327 BasicBlockPassManager_New *activeBBPassManager;
328};
329
330/// ModulePassManager_New manages ModulePasses and function pass managers.
331/// It batches all Module passes passes and function pass managers together and
332/// sequence them to process one module.
Devang Pateldbe4a1e2006-12-07 18:36:24 +0000333class ModulePassManager_New : public PMDataManager {
Devang Patelca58e352006-11-08 10:05:38 +0000334
335public:
336 ModulePassManager_New() { activeFunctionPassManager = NULL; }
337
338 /// Add a pass into a passmanager queue.
339 bool addPass(Pass *p);
340
341 /// run - Execute all of the passes scheduled for execution. Keep track of
342 /// whether any of the passes modifies the module, and if so, return true.
343 bool runOnModule(Module &M);
Devang Patelebba9702006-11-13 22:40:09 +0000344
345 /// Return true IFF AnalysisID AID is currently available.
Devang Patel3f0832a2006-11-14 02:54:23 +0000346 Pass *getAnalysisPassFromManager(AnalysisID AID);
Devang Patelf9d96b92006-12-07 19:57:52 +0000347
348 /// Pass Manager itself does not invalidate any analysis info.
349 void getAnalysisUsage(AnalysisUsage &Info) const {
350 Info.setPreservesAll();
351 }
352
Devang Patelca58e352006-11-08 10:05:38 +0000353private:
Devang Patelca58e352006-11-08 10:05:38 +0000354 // Active Pass Manager
Devang Patel4e12f862006-11-08 10:44:40 +0000355 FunctionPassManagerImpl_New *activeFunctionPassManager;
Devang Patelca58e352006-11-08 10:05:38 +0000356};
357
Devang Patel376fefa2006-11-08 10:29:57 +0000358/// PassManager_New manages ModulePassManagers
Devang Pateldbe4a1e2006-12-07 18:36:24 +0000359class PassManagerImpl_New : public PMDataManager {
Devang Patel376fefa2006-11-08 10:29:57 +0000360
361public:
362
363 /// add - Add a pass to the queue of passes to run. This passes ownership of
364 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
365 /// will be destroyed as well, so there is no need to delete the pass. This
366 /// implies that all passes MUST be allocated with 'new'.
367 void add(Pass *P);
368
369 /// run - Execute all of the passes scheduled for execution. Keep track of
370 /// whether any of the passes modifies the module, and if so, return true.
371 bool run(Module &M);
372
Devang Patelebba9702006-11-13 22:40:09 +0000373 /// Return true IFF AnalysisID AID is currently available.
Devang Patel3f0832a2006-11-14 02:54:23 +0000374 Pass *getAnalysisPassFromManager(AnalysisID AID);
Devang Patelebba9702006-11-13 22:40:09 +0000375
Devang Patelf9d96b92006-12-07 19:57:52 +0000376 /// Pass Manager itself does not invalidate any analysis info.
377 void getAnalysisUsage(AnalysisUsage &Info) const {
378 Info.setPreservesAll();
379 }
380
Devang Patel376fefa2006-11-08 10:29:57 +0000381private:
382
383 /// Add a pass into a passmanager queue. This is used by schedulePasses
384 bool addPass(Pass *p);
385
Devang Patel1a6eaa42006-11-11 02:22:31 +0000386 /// Schedule pass P for execution. Make sure that passes required by
387 /// P are run before P is run. Update analysis info maintained by
388 /// the manager. Remove dead passes. This is a recursive function.
389 void schedulePass(Pass *P);
390
Devang Patel376fefa2006-11-08 10:29:57 +0000391 /// Schedule all passes collected in pass queue using add(). Add all the
392 /// schedule passes into various manager's queue using addPass().
393 void schedulePasses();
394
395 // Collection of pass managers
396 std::vector<ModulePassManager_New *> PassManagers;
397
Devang Patel376fefa2006-11-08 10:29:57 +0000398 // Active Pass Manager
399 ModulePassManager_New *activeManager;
400};
401
Devang Patelca58e352006-11-08 10:05:38 +0000402} // End of llvm namespace
403
Devang Patela1514cb2006-12-07 19:39:39 +0000404//===----------------------------------------------------------------------===//
Devang Pateldbe4a1e2006-12-07 18:36:24 +0000405// PMDataManager implementation
Devang Patelf68a3492006-11-07 22:35:17 +0000406
Devang Pateld65e9e92006-11-08 01:31:28 +0000407/// Return true IFF pass P's required analysis set does not required new
Devang Patelf68a3492006-11-07 22:35:17 +0000408/// manager.
Devang Pateldbe4a1e2006-12-07 18:36:24 +0000409bool PMDataManager::manageablePass(Pass *P) {
Devang Patelf68a3492006-11-07 22:35:17 +0000410
Devang Patel8f677ce2006-12-07 18:47:25 +0000411 // TODO
412 // If this pass is not preserving information that is required by a
413 // pass maintained by higher level pass manager then do not insert
414 // this pass into current manager. Use new manager. For example,
415 // For example, If FunctionPass F is not preserving ModulePass Info M1
416 // that is used by another ModulePass M2 then do not insert F in
417 // current function pass manager.
Devang Patelf68a3492006-11-07 22:35:17 +0000418 return true;
419}
420
Devang Patel643676c2006-11-11 01:10:19 +0000421/// Augement AvailableAnalysis by adding analysis made available by pass P.
Devang Patele9976aa2006-12-07 19:33:53 +0000422void PMDataManager::recordAvailableAnalysis(Pass *P) {
Devang Patelf60b5d92006-11-14 01:59:59 +0000423
Devang Patel643676c2006-11-11 01:10:19 +0000424 if (const PassInfo *PI = P->getPassInfo()) {
Devang Patelf60b5d92006-11-14 01:59:59 +0000425 AvailableAnalysis[PI] = P;
Devang Patel643676c2006-11-11 01:10:19 +0000426
Devang Patele9976aa2006-12-07 19:33:53 +0000427 //This pass is the current implementation of all of the interfaces it
428 //implements as well.
429 const std::vector<const PassInfo*> &II = PI->getInterfacesImplemented();
430 for (unsigned i = 0, e = II.size(); i != e; ++i)
431 AvailableAnalysis[II[i]] = P;
Devang Patel643676c2006-11-11 01:10:19 +0000432 }
433}
434
Devang Patelf68a3492006-11-07 22:35:17 +0000435/// Remove Analyss not preserved by Pass P
Devang Pateldbe4a1e2006-12-07 18:36:24 +0000436void PMDataManager::removeNotPreservedAnalysis(Pass *P) {
Devang Patel349170f2006-11-11 01:24:55 +0000437 AnalysisUsage AnUsage;
438 P->getAnalysisUsage(AnUsage);
439 const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
Devang Patelf68a3492006-11-07 22:35:17 +0000440
Devang Patelf60b5d92006-11-14 01:59:59 +0000441 for (std::map<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(),
Devang Patel349170f2006-11-11 01:24:55 +0000442 E = AvailableAnalysis.end(); I != E; ++I ) {
Devang Patelf60b5d92006-11-14 01:59:59 +0000443 if (std::find(PreservedSet.begin(), PreservedSet.end(), I->first) ==
Devang Patel349170f2006-11-11 01:24:55 +0000444 PreservedSet.end()) {
445 // Remove this analysis
Devang Patelf60b5d92006-11-14 01:59:59 +0000446 std::map<AnalysisID, Pass*>::iterator J = I++;
Devang Patel349170f2006-11-11 01:24:55 +0000447 AvailableAnalysis.erase(J);
448 }
449 }
Devang Patelf68a3492006-11-07 22:35:17 +0000450}
451
Devang Patelca189262006-11-14 03:05:08 +0000452/// Remove analysis passes that are not used any longer
Devang Pateldbe4a1e2006-12-07 18:36:24 +0000453void PMDataManager::removeDeadPasses(Pass *P) {
Devang Patelca189262006-11-14 03:05:08 +0000454
455 for (std::map<Pass *, Pass *>::iterator I = LastUser.begin(),
456 E = LastUser.end(); I !=E; ++I) {
457 if (I->second == P) {
458 Pass *deadPass = I->first;
459 deadPass->releaseMemory();
460
461 std::map<AnalysisID, Pass*>::iterator Pos =
462 AvailableAnalysis.find(deadPass->getPassInfo());
463
464 assert (Pos != AvailableAnalysis.end() &&
465 "Pass is not available");
466 AvailableAnalysis.erase(Pos);
467 }
468 }
469}
470
Devang Patel8f677ce2006-12-07 18:47:25 +0000471/// Add pass P into the PassVector. Update
Devang Patel90b05e02006-11-11 02:04:19 +0000472/// AvailableAnalysis appropriately if ProcessAnalysis is true.
Devang Pateldbe4a1e2006-12-07 18:36:24 +0000473void PMDataManager::addPassToManager (Pass *P,
Devang Patel90b05e02006-11-11 02:04:19 +0000474 bool ProcessAnalysis) {
Devang Patel8cad70d2006-11-11 01:51:02 +0000475
Devang Patel90b05e02006-11-11 02:04:19 +0000476 if (ProcessAnalysis) {
477 // Take a note of analysis required and made available by this pass
Devang Patel8f677ce2006-12-07 18:47:25 +0000478 initializeAnalysisImpl(P);
Devang Patele9976aa2006-12-07 19:33:53 +0000479 recordAvailableAnalysis(P);
Devang Patel90b05e02006-11-11 02:04:19 +0000480
481 // Remove the analysis not preserved by this pass
482 removeNotPreservedAnalysis(P);
483 }
Devang Patel8cad70d2006-11-11 01:51:02 +0000484
485 // Add pass
486 PassVector.push_back(P);
Devang Patel8cad70d2006-11-11 01:51:02 +0000487}
488
Devang Patel07f4f582006-11-14 21:49:36 +0000489// All Required analyses should be available to the pass as it runs! Here
490// we fill in the AnalysisImpls member of the pass so that it can
491// successfully use the getAnalysis() method to retrieve the
492// implementations it needs.
493//
Devang Pateldbe4a1e2006-12-07 18:36:24 +0000494void PMDataManager::initializeAnalysisImpl(Pass *P) {
Devang Patelff631ae2006-11-15 01:27:05 +0000495 AnalysisUsage AnUsage;
496 P->getAnalysisUsage(AnUsage);
Devang Patel07f4f582006-11-14 21:49:36 +0000497
498 for (std::vector<const PassInfo *>::const_iterator
499 I = AnUsage.getRequiredSet().begin(),
500 E = AnUsage.getRequiredSet().end(); I != E; ++I) {
501 Pass *Impl = getAnalysisPass(*I);
502 if (Impl == 0)
503 assert(0 && "Analysis used but not available!");
504 // TODO: P->AnalysisImpls.push_back(std::make_pair(*I, Impl));
505 }
506}
507
Devang Patela1514cb2006-12-07 19:39:39 +0000508//===----------------------------------------------------------------------===//
509// BasicBlockPassManager_New implementation
Devang Patel6e5a1132006-11-07 21:31:57 +0000510
Devang Pateld65e9e92006-11-08 01:31:28 +0000511/// Add pass P into PassVector and return true. If this pass is not
512/// manageable by this manager then return false.
Devang Patel6e5a1132006-11-07 21:31:57 +0000513bool
Devang Pateld65e9e92006-11-08 01:31:28 +0000514BasicBlockPassManager_New::addPass(Pass *P) {
Devang Patel6e5a1132006-11-07 21:31:57 +0000515
516 BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P);
517 if (!BP)
518 return false;
519
Devang Patel3c8eb622006-11-07 22:56:50 +0000520 // If this pass does not preserve anlysis that is used by other passes
521 // managed by this manager than it is not a suiable pass for this manager.
Devang Pateld65e9e92006-11-08 01:31:28 +0000522 if (!manageablePass(P))
Devang Patel3c8eb622006-11-07 22:56:50 +0000523 return false;
524
Devang Patel8cad70d2006-11-11 01:51:02 +0000525 addPassToManager (BP);
Devang Patel349170f2006-11-11 01:24:55 +0000526
Devang Patel6e5a1132006-11-07 21:31:57 +0000527 return true;
528}
529
530/// Execute all of the passes scheduled for execution by invoking
531/// runOnBasicBlock method. Keep track of whether any of the passes modifies
532/// the function, and if so, return true.
533bool
534BasicBlockPassManager_New::runOnFunction(Function &F) {
535
536 bool Changed = false;
Devang Patela6b6dcb2006-12-07 18:41:09 +0000537 initializeAnalysisInfo();
Devang Patel050ec722006-11-14 01:23:29 +0000538
Devang Patel6e5a1132006-11-07 21:31:57 +0000539 for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
Devang Patel8cad70d2006-11-11 01:51:02 +0000540 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
541 e = passVectorEnd(); itr != e; ++itr) {
Devang Patel6e5a1132006-11-07 21:31:57 +0000542 Pass *P = *itr;
Devang Patel050ec722006-11-14 01:23:29 +0000543
Devang Patele9976aa2006-12-07 19:33:53 +0000544 recordAvailableAnalysis(P);
Devang Patel6e5a1132006-11-07 21:31:57 +0000545 BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P);
546 Changed |= BP->runOnBasicBlock(*I);
Devang Patel050ec722006-11-14 01:23:29 +0000547 removeNotPreservedAnalysis(P);
Devang Patelca189262006-11-14 03:05:08 +0000548 removeDeadPasses(P);
Devang Patel6e5a1132006-11-07 21:31:57 +0000549 }
550 return Changed;
551}
552
Devang Patelebba9702006-11-13 22:40:09 +0000553/// Return true IFF AnalysisID AID is currently available.
Devang Patel3f0832a2006-11-14 02:54:23 +0000554Pass * BasicBlockPassManager_New::getAnalysisPassFromManager(AnalysisID AID) {
555 return getAnalysisPass(AID);
Devang Patelebba9702006-11-13 22:40:09 +0000556}
557
Devang Patela1514cb2006-12-07 19:39:39 +0000558//===----------------------------------------------------------------------===//
Devang Patel0c2012f2006-11-07 21:49:50 +0000559// FunctionPassManager_New implementation
Devang Patela1514cb2006-12-07 19:39:39 +0000560
Devang Patel4e12f862006-11-08 10:44:40 +0000561/// Create new Function pass manager
562FunctionPassManager_New::FunctionPassManager_New() {
563 FPM = new FunctionPassManagerImpl_New();
564}
565
566/// add - Add a pass to the queue of passes to run. This passes
567/// ownership of the Pass to the PassManager. When the
568/// PassManager_X is destroyed, the pass will be destroyed as well, so
569/// there is no need to delete the pass. (TODO delete passes.)
570/// This implies that all passes MUST be allocated with 'new'.
Devang Patel9f3083e2006-11-15 19:39:54 +0000571void FunctionPassManager_New::add(Pass *P) {
Devang Patel4e12f862006-11-08 10:44:40 +0000572 FPM->add(P);
573}
574
575/// Execute all of the passes scheduled for execution. Keep
576/// track of whether any of the passes modifies the function, and if
577/// so, return true.
Devang Patel9f3083e2006-11-15 19:39:54 +0000578bool FunctionPassManager_New::runOnModule(Module &M) {
Devang Patel4e12f862006-11-08 10:44:40 +0000579 return FPM->runOnModule(M);
580}
581
Devang Patel9f3083e2006-11-15 19:39:54 +0000582/// run - Execute all of the passes scheduled for execution. Keep
583/// track of whether any of the passes modifies the function, and if
584/// so, return true.
585///
586bool FunctionPassManager_New::run(Function &F) {
587 std::string errstr;
588 if (MP->materializeFunction(&F, &errstr)) {
Bill Wendlingf3baad32006-12-07 01:30:32 +0000589 cerr << "Error reading bytecode file: " << errstr << "\n";
Devang Patel9f3083e2006-11-15 19:39:54 +0000590 abort();
591 }
592 return FPM->runOnFunction(F);
593}
594
595
Devang Patelff631ae2006-11-15 01:27:05 +0000596/// doInitialization - Run all of the initializers for the function passes.
597///
598bool FunctionPassManager_New::doInitialization() {
599 return FPM->doInitialization(*MP->getModule());
600}
601
602/// doFinalization - Run all of the initializers for the function passes.
603///
604bool FunctionPassManager_New::doFinalization() {
605 return FPM->doFinalization(*MP->getModule());
606}
607
Devang Patela1514cb2006-12-07 19:39:39 +0000608//===----------------------------------------------------------------------===//
Devang Patel4e12f862006-11-08 10:44:40 +0000609// FunctionPassManagerImpl_New implementation
Devang Patel0c2012f2006-11-07 21:49:50 +0000610
Devang Patel0c2012f2006-11-07 21:49:50 +0000611/// Add pass P into the pass manager queue. If P is a BasicBlockPass then
612/// either use it into active basic block pass manager or create new basic
613/// block pass manager to handle pass P.
614bool
Devang Patel4e12f862006-11-08 10:44:40 +0000615FunctionPassManagerImpl_New::addPass(Pass *P) {
Devang Patel0c2012f2006-11-07 21:49:50 +0000616
617 // If P is a BasicBlockPass then use BasicBlockPassManager_New.
618 if (BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P)) {
619
620 if (!activeBBPassManager
621 || !activeBBPassManager->addPass(BP)) {
622
623 activeBBPassManager = new BasicBlockPassManager_New();
Devang Patel90b05e02006-11-11 02:04:19 +0000624 addPassToManager(activeBBPassManager, false);
Devang Pateld65e9e92006-11-08 01:31:28 +0000625 if (!activeBBPassManager->addPass(BP))
626 assert(0 && "Unable to add Pass");
Devang Patel0c2012f2006-11-07 21:49:50 +0000627 }
628 return true;
629 }
630
631 FunctionPass *FP = dynamic_cast<FunctionPass *>(P);
632 if (!FP)
633 return false;
634
Devang Patel3c8eb622006-11-07 22:56:50 +0000635 // If this pass does not preserve anlysis that is used by other passes
636 // managed by this manager than it is not a suiable pass for this manager.
Devang Pateld65e9e92006-11-08 01:31:28 +0000637 if (!manageablePass(P))
Devang Patel3c8eb622006-11-07 22:56:50 +0000638 return false;
639
Devang Patel8cad70d2006-11-11 01:51:02 +0000640 addPassToManager (FP);
Devang Patel0c2012f2006-11-07 21:49:50 +0000641 activeBBPassManager = NULL;
642 return true;
643}
644
645/// Execute all of the passes scheduled for execution by invoking
646/// runOnFunction method. Keep track of whether any of the passes modifies
647/// the function, and if so, return true.
Devang Patel9f3083e2006-11-15 19:39:54 +0000648bool FunctionPassManagerImpl_New::runOnModule(Module &M) {
Devang Patel0c2012f2006-11-07 21:49:50 +0000649
650 bool Changed = false;
Devang Patela6b6dcb2006-12-07 18:41:09 +0000651 initializeAnalysisInfo();
Devang Patel050ec722006-11-14 01:23:29 +0000652
Devang Patel0c2012f2006-11-07 21:49:50 +0000653 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
Devang Patel8cad70d2006-11-11 01:51:02 +0000654 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
655 e = passVectorEnd(); itr != e; ++itr) {
Devang Patel0c2012f2006-11-07 21:49:50 +0000656 Pass *P = *itr;
Devang Patel050ec722006-11-14 01:23:29 +0000657
Devang Patele9976aa2006-12-07 19:33:53 +0000658 recordAvailableAnalysis(P);
Devang Patel0c2012f2006-11-07 21:49:50 +0000659 FunctionPass *FP = dynamic_cast<FunctionPass*>(P);
660 Changed |= FP->runOnFunction(*I);
Devang Patel050ec722006-11-14 01:23:29 +0000661 removeNotPreservedAnalysis(P);
Devang Patelca189262006-11-14 03:05:08 +0000662 removeDeadPasses(P);
Devang Patel0c2012f2006-11-07 21:49:50 +0000663 }
664 return Changed;
665}
666
Devang Patel9f3083e2006-11-15 19:39:54 +0000667/// Execute all of the passes scheduled for execution by invoking
668/// runOnFunction method. Keep track of whether any of the passes modifies
669/// the function, and if so, return true.
670bool FunctionPassManagerImpl_New::runOnFunction(Function &F) {
671
672 bool Changed = false;
Devang Patela6b6dcb2006-12-07 18:41:09 +0000673 initializeAnalysisInfo();
Devang Patel9f3083e2006-11-15 19:39:54 +0000674
675 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
676 e = passVectorEnd(); itr != e; ++itr) {
677 Pass *P = *itr;
678
Devang Patele9976aa2006-12-07 19:33:53 +0000679 recordAvailableAnalysis(P);
Devang Patel9f3083e2006-11-15 19:39:54 +0000680 FunctionPass *FP = dynamic_cast<FunctionPass*>(P);
681 Changed |= FP->runOnFunction(F);
682 removeNotPreservedAnalysis(P);
683 removeDeadPasses(P);
684 }
685 return Changed;
686}
687
688
Devang Patelebba9702006-11-13 22:40:09 +0000689/// Return true IFF AnalysisID AID is currently available.
Devang Patel3f0832a2006-11-14 02:54:23 +0000690Pass *FunctionPassManagerImpl_New::getAnalysisPassFromManager(AnalysisID AID) {
Devang Patelebba9702006-11-13 22:40:09 +0000691
Devang Patel3f0832a2006-11-14 02:54:23 +0000692 Pass *P = getAnalysisPass(AID);
693 if (P)
694 return P;
Devang Patelebba9702006-11-13 22:40:09 +0000695
696 if (activeBBPassManager &&
Devang Patelf60b5d92006-11-14 01:59:59 +0000697 activeBBPassManager->getAnalysisPass(AID) != 0)
Devang Patel3f0832a2006-11-14 02:54:23 +0000698 return activeBBPassManager->getAnalysisPass(AID);
Devang Patelebba9702006-11-13 22:40:09 +0000699
700 // TODO : Check inactive managers
Devang Patel3f0832a2006-11-14 02:54:23 +0000701 return NULL;
Devang Patelebba9702006-11-13 22:40:09 +0000702}
Devang Patel0c2012f2006-11-07 21:49:50 +0000703
Devang Patelff631ae2006-11-15 01:27:05 +0000704inline bool FunctionPassManagerImpl_New::doInitialization(Module &M) {
705 bool Changed = false;
706
707 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
708 e = passVectorEnd(); itr != e; ++itr) {
709 Pass *P = *itr;
710
711 FunctionPass *FP = dynamic_cast<FunctionPass*>(P);
712 Changed |= FP->doInitialization(M);
713 }
714
715 return Changed;
716}
717
718inline bool FunctionPassManagerImpl_New::doFinalization(Module &M) {
719 bool Changed = false;
720
721 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
722 e = passVectorEnd(); itr != e; ++itr) {
723 Pass *P = *itr;
724
725 FunctionPass *FP = dynamic_cast<FunctionPass*>(P);
726 Changed |= FP->doFinalization(M);
727 }
728
729
730 return Changed;
731}
732
Devang Patela1514cb2006-12-07 19:39:39 +0000733//===----------------------------------------------------------------------===//
Devang Patel05e1a972006-11-07 22:03:15 +0000734// ModulePassManager implementation
735
736/// Add P into pass vector if it is manageble. If P is a FunctionPass
Devang Patel4e12f862006-11-08 10:44:40 +0000737/// then use FunctionPassManagerImpl_New to manage it. Return false if P
Devang Patel05e1a972006-11-07 22:03:15 +0000738/// is not manageable by this manager.
739bool
Devang Pateld65e9e92006-11-08 01:31:28 +0000740ModulePassManager_New::addPass(Pass *P) {
Devang Patel05e1a972006-11-07 22:03:15 +0000741
742 // If P is FunctionPass then use function pass maanager.
743 if (FunctionPass *FP = dynamic_cast<FunctionPass*>(P)) {
744
745 activeFunctionPassManager = NULL;
746
747 if (!activeFunctionPassManager
748 || !activeFunctionPassManager->addPass(P)) {
749
Devang Patel4e12f862006-11-08 10:44:40 +0000750 activeFunctionPassManager = new FunctionPassManagerImpl_New();
Devang Patel90b05e02006-11-11 02:04:19 +0000751 addPassToManager(activeFunctionPassManager, false);
Devang Pateld65e9e92006-11-08 01:31:28 +0000752 if (!activeFunctionPassManager->addPass(FP))
753 assert(0 && "Unable to add pass");
Devang Patel05e1a972006-11-07 22:03:15 +0000754 }
755 return true;
756 }
757
758 ModulePass *MP = dynamic_cast<ModulePass *>(P);
759 if (!MP)
760 return false;
761
Devang Patel3c8eb622006-11-07 22:56:50 +0000762 // If this pass does not preserve anlysis that is used by other passes
763 // managed by this manager than it is not a suiable pass for this manager.
Devang Pateld65e9e92006-11-08 01:31:28 +0000764 if (!manageablePass(P))
Devang Patel3c8eb622006-11-07 22:56:50 +0000765 return false;
766
Devang Patel8cad70d2006-11-11 01:51:02 +0000767 addPassToManager(MP);
Devang Patel05e1a972006-11-07 22:03:15 +0000768 activeFunctionPassManager = NULL;
769 return true;
770}
771
772
773/// Execute all of the passes scheduled for execution by invoking
774/// runOnModule method. Keep track of whether any of the passes modifies
775/// the module, and if so, return true.
776bool
777ModulePassManager_New::runOnModule(Module &M) {
778 bool Changed = false;
Devang Patela6b6dcb2006-12-07 18:41:09 +0000779 initializeAnalysisInfo();
Devang Patel050ec722006-11-14 01:23:29 +0000780
Devang Patel8cad70d2006-11-11 01:51:02 +0000781 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
782 e = passVectorEnd(); itr != e; ++itr) {
Devang Patel05e1a972006-11-07 22:03:15 +0000783 Pass *P = *itr;
Devang Patel050ec722006-11-14 01:23:29 +0000784
Devang Patele9976aa2006-12-07 19:33:53 +0000785 recordAvailableAnalysis(P);
Devang Patel05e1a972006-11-07 22:03:15 +0000786 ModulePass *MP = dynamic_cast<ModulePass*>(P);
787 Changed |= MP->runOnModule(M);
Devang Patel050ec722006-11-14 01:23:29 +0000788 removeNotPreservedAnalysis(P);
Devang Patelca189262006-11-14 03:05:08 +0000789 removeDeadPasses(P);
Devang Patel05e1a972006-11-07 22:03:15 +0000790 }
791 return Changed;
792}
793
Devang Patelebba9702006-11-13 22:40:09 +0000794/// Return true IFF AnalysisID AID is currently available.
Devang Patel3f0832a2006-11-14 02:54:23 +0000795Pass *ModulePassManager_New::getAnalysisPassFromManager(AnalysisID AID) {
Devang Patelebba9702006-11-13 22:40:09 +0000796
Devang Patel3f0832a2006-11-14 02:54:23 +0000797
798 Pass *P = getAnalysisPass(AID);
799 if (P)
800 return P;
Devang Patelebba9702006-11-13 22:40:09 +0000801
802 if (activeFunctionPassManager &&
Devang Patelf60b5d92006-11-14 01:59:59 +0000803 activeFunctionPassManager->getAnalysisPass(AID) != 0)
Devang Patel3f0832a2006-11-14 02:54:23 +0000804 return activeFunctionPassManager->getAnalysisPass(AID);
Devang Patelebba9702006-11-13 22:40:09 +0000805
806 // TODO : Check inactive managers
Devang Patel3f0832a2006-11-14 02:54:23 +0000807 return NULL;
Devang Patelebba9702006-11-13 22:40:09 +0000808}
809
Devang Patela1514cb2006-12-07 19:39:39 +0000810//===----------------------------------------------------------------------===//
811// PassManagerImpl implementation
812
Devang Patelebba9702006-11-13 22:40:09 +0000813/// Return true IFF AnalysisID AID is currently available.
Devang Patel3f0832a2006-11-14 02:54:23 +0000814Pass *PassManagerImpl_New::getAnalysisPassFromManager(AnalysisID AID) {
Devang Patelebba9702006-11-13 22:40:09 +0000815
Devang Patel3f0832a2006-11-14 02:54:23 +0000816 Pass *P = NULL;
Devang Patel70868442006-11-13 22:53:19 +0000817 for (std::vector<ModulePassManager_New *>::iterator itr = PassManagers.begin(),
Devang Patel3f0832a2006-11-14 02:54:23 +0000818 e = PassManagers.end(); !P && itr != e; ++itr)
819 P = (*itr)->getAnalysisPassFromManager(AID);
820 return P;
Devang Patelebba9702006-11-13 22:40:09 +0000821}
822
Devang Patel1a6eaa42006-11-11 02:22:31 +0000823/// Schedule pass P for execution. Make sure that passes required by
824/// P are run before P is run. Update analysis info maintained by
825/// the manager. Remove dead passes. This is a recursive function.
826void PassManagerImpl_New::schedulePass(Pass *P) {
827
828 AnalysisUsage AnUsage;
829 P->getAnalysisUsage(AnUsage);
830 const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet();
831 for (std::vector<AnalysisID>::const_iterator I = RequiredSet.begin(),
832 E = RequiredSet.end(); I != E; ++I) {
833
Devang Patel3f0832a2006-11-14 02:54:23 +0000834 Pass *AnalysisPass = getAnalysisPassFromManager(*I);
835 if (!AnalysisPass) {
Devang Patel1a6eaa42006-11-11 02:22:31 +0000836 // Schedule this analysis run first.
Devang Patel3f0832a2006-11-14 02:54:23 +0000837 AnalysisPass = (*I)->createPass();
838 schedulePass(AnalysisPass);
Devang Patel1a6eaa42006-11-11 02:22:31 +0000839 }
Devang Patel3f0832a2006-11-14 02:54:23 +0000840 setLastUser (AnalysisPass, P);
Devang Patel4a3fa4f2006-11-15 01:48:14 +0000841
842 // Prolong live range of analyses that are needed after an analysis pass
843 // is destroyed, for querying by subsequent passes
844 const std::vector<AnalysisID> &IDs = AnUsage.getRequiredTransitiveSet();
845 for (std::vector<AnalysisID>::const_iterator I = IDs.begin(),
846 E = IDs.end(); I != E; ++I) {
847 Pass *AP = getAnalysisPassFromManager(*I);
848 assert (AP && "Analysis pass is not available");
849 setLastUser(AP, P);
850 }
Devang Patel1a6eaa42006-11-11 02:22:31 +0000851 }
Devang Patel1a6eaa42006-11-11 02:22:31 +0000852 addPass(P);
Devang Patel1a6eaa42006-11-11 02:22:31 +0000853}
854
Devang Patelc290c8a2006-11-07 22:23:34 +0000855/// Schedule all passes from the queue by adding them in their
856/// respective manager's queue.
Devang Patel1a6eaa42006-11-11 02:22:31 +0000857void PassManagerImpl_New::schedulePasses() {
858 for (std::vector<Pass *>::iterator I = passVectorBegin(),
859 E = passVectorEnd(); I != E; ++I)
860 schedulePass (*I);
Devang Patelc290c8a2006-11-07 22:23:34 +0000861}
862
863/// 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
887 schedulePasses();
888 bool Changed = false;
889 for (std::vector<ModulePassManager_New *>::iterator itr = PassManagers.begin(),
890 e = PassManagers.end(); itr != e; ++itr) {
891 ModulePassManager_New *pm = *itr;
892 Changed |= pm->runOnModule(M);
893 }
894 return Changed;
895}
Devang Patel376fefa2006-11-08 10:29:57 +0000896
Devang Patela1514cb2006-12-07 19:39:39 +0000897//===----------------------------------------------------------------------===//
898// PassManager implementation
899
Devang Patel376fefa2006-11-08 10:29:57 +0000900/// Create new pass manager
901PassManager_New::PassManager_New() {
902 PM = new PassManagerImpl_New();
903}
904
905/// add - Add a pass to the queue of passes to run. This passes ownership of
906/// the Pass to the PassManager. When the PassManager is destroyed, the pass
907/// will be destroyed as well, so there is no need to delete the pass. This
908/// implies that all passes MUST be allocated with 'new'.
909void
910PassManager_New::add(Pass *P) {
911 PM->add(P);
912}
913
914/// run - Execute all of the passes scheduled for execution. Keep track of
915/// whether any of the passes modifies the module, and if so, return true.
916bool
917PassManager_New::run(Module &M) {
918 return PM->run(M);
919}
920