Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 1 | //===- PassManager.cpp - LLVM Pass Infrastructure Implementation ----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 5 | // This file was developed by Devang Patel and is distributed under |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 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" |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 16 | #include "llvm/Module.h" |
Devang Patel | ff631ae | 2006-11-15 01:27:05 +0000 | [diff] [blame] | 17 | #include "llvm/ModuleProvider.h" |
Bill Wendling | dfc9189 | 2006-11-28 02:09:03 +0000 | [diff] [blame] | 18 | #include "llvm/Support/Streams.h" |
Devang Patel | a984459 | 2006-11-11 01:31:05 +0000 | [diff] [blame] | 19 | #include <vector> |
Devang Patel | f60b5d9 | 2006-11-14 01:59:59 +0000 | [diff] [blame] | 20 | #include <map> |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 21 | using namespace llvm; |
| 22 | |
Devang Patel | 6fea285 | 2006-12-07 18:23:30 +0000 | [diff] [blame] | 23 | //===----------------------------------------------------------------------===// |
| 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 Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 87 | namespace llvm { |
| 88 | |
Devang Patel | f33f3eb | 2006-12-07 19:21:29 +0000 | [diff] [blame] | 89 | //===----------------------------------------------------------------------===// |
| 90 | // PMTopLevelManager |
| 91 | // |
| 92 | /// PMTopLevelManager manages LastUser info and collects common APIs used by |
| 93 | /// top level pass managers. |
| 94 | class PMTopLevelManager { |
| 95 | |
| 96 | public: |
| 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 Patel | e0eb9d8 | 2006-12-07 20:51:18 +0000 | [diff] [blame] | 125 | /// 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 Patel | f33f3eb | 2006-12-07 19:21:29 +0000 | [diff] [blame] | 135 | private: |
| 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 Patel | e0eb9d8 | 2006-12-07 20:51:18 +0000 | [diff] [blame] | 143 | |
| 144 | /// Immutable passes are managed by top level manager. |
| 145 | std::vector<ImmutablePass *> ImmutablePasses; |
Devang Patel | f33f3eb | 2006-12-07 19:21:29 +0000 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | /// Set pass P as the last user of the given analysis passes. |
| 149 | void 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 |
| 168 | void 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 Patel | de12418 | 2006-12-07 21:10:57 +0000 | [diff] [blame] | 176 | /// 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. |
| 179 | void 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 Patel | f3827bc | 2006-12-07 19:54:15 +0000 | [diff] [blame] | 203 | //===----------------------------------------------------------------------===// |
| 204 | // PMDataManager |
Devang Patel | f33f3eb | 2006-12-07 19:21:29 +0000 | [diff] [blame] | 205 | |
Devang Patel | dbe4a1e | 2006-12-07 18:36:24 +0000 | [diff] [blame] | 206 | /// PMDataManager provides the common place to manage the analysis data |
| 207 | /// used by pass managers. |
| 208 | class PMDataManager { |
Devang Patel | a984459 | 2006-11-11 01:31:05 +0000 | [diff] [blame] | 209 | |
| 210 | public: |
| 211 | |
Devang Patel | 4c36e6b | 2006-12-07 23:24:58 +0000 | [diff] [blame^] | 212 | PMDataManager(int D) : TPM(NULL), Depth(D) { |
Devang Patel | f3827bc | 2006-12-07 19:54:15 +0000 | [diff] [blame] | 213 | initializeAnalysisInfo(); |
| 214 | } |
| 215 | |
Devang Patel | a984459 | 2006-11-11 01:31:05 +0000 | [diff] [blame] | 216 | /// Return true IFF pass P's required analysis set does not required new |
| 217 | /// manager. |
| 218 | bool manageablePass(Pass *P); |
| 219 | |
Devang Patel | f60b5d9 | 2006-11-14 01:59:59 +0000 | [diff] [blame] | 220 | 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 Patel | ebba970 | 2006-11-13 22:40:09 +0000 | [diff] [blame] | 229 | } |
Devang Patel | a984459 | 2006-11-11 01:31:05 +0000 | [diff] [blame] | 230 | |
Devang Patel | a984459 | 2006-11-11 01:31:05 +0000 | [diff] [blame] | 231 | /// Augment AvailableAnalysis by adding analysis made available by pass P. |
Devang Patel | e9976aa | 2006-12-07 19:33:53 +0000 | [diff] [blame] | 232 | void recordAvailableAnalysis(Pass *P); |
Devang Patel | a984459 | 2006-11-11 01:31:05 +0000 | [diff] [blame] | 233 | |
Devang Patel | a984459 | 2006-11-11 01:31:05 +0000 | [diff] [blame] | 234 | /// Remove Analysis that is not preserved by the pass |
| 235 | void removeNotPreservedAnalysis(Pass *P); |
| 236 | |
| 237 | /// Remove dead passes |
Devang Patel | ca18926 | 2006-11-14 03:05:08 +0000 | [diff] [blame] | 238 | void removeDeadPasses(Pass *P); |
Devang Patel | a984459 | 2006-11-11 01:31:05 +0000 | [diff] [blame] | 239 | |
Devang Patel | 8f677ce | 2006-12-07 18:47:25 +0000 | [diff] [blame] | 240 | /// Add pass P into the PassVector. Update |
Devang Patel | 90b05e0 | 2006-11-11 02:04:19 +0000 | [diff] [blame] | 241 | /// AvailableAnalysis appropriately if ProcessAnalysis is true. |
| 242 | void addPassToManager (Pass *P, bool ProcessAnalysis = true); |
Devang Patel | 8cad70d | 2006-11-11 01:51:02 +0000 | [diff] [blame] | 243 | |
Devang Patel | 1d6267c | 2006-12-07 23:05:44 +0000 | [diff] [blame] | 244 | /// Initialize available analysis information. |
Devang Patel | a6b6dcb | 2006-12-07 18:41:09 +0000 | [diff] [blame] | 245 | void initializeAnalysisInfo() { |
Devang Patel | 050ec72 | 2006-11-14 01:23:29 +0000 | [diff] [blame] | 246 | AvailableAnalysis.clear(); |
Devang Patel | b390032 | 2006-12-07 21:02:08 +0000 | [diff] [blame] | 247 | |
| 248 | // Include immutable passes into AvailableAnalysis vector. |
| 249 | std::vector<ImmutablePass *> &ImmutablePasses = TPM->getImmutablePasses(); |
| 250 | for (std::vector<ImmutablePass *>::iterator I = ImmutablePasses.begin(), |
| 251 | E = ImmutablePasses.end(); I != E; ++I) |
| 252 | recordAvailableAnalysis(*I); |
Devang Patel | 050ec72 | 2006-11-14 01:23:29 +0000 | [diff] [blame] | 253 | } |
| 254 | |
Devang Patel | 1d6267c | 2006-12-07 23:05:44 +0000 | [diff] [blame] | 255 | /// Populate RequiredPasses with the analysis pass that are required by |
| 256 | /// pass P. |
| 257 | void collectRequiredAnalysisPasses(std::vector<Pass *> &RequiredPasses, |
| 258 | Pass *P); |
| 259 | |
| 260 | /// All Required analyses should be available to the pass as it runs! Here |
| 261 | /// we fill in the AnalysisImpls member of the pass so that it can |
| 262 | /// successfully use the getAnalysis() method to retrieve the |
| 263 | /// implementations it needs. |
| 264 | void initializeAnalysisImpl(Pass *P); |
Devang Patel | f60b5d9 | 2006-11-14 01:59:59 +0000 | [diff] [blame] | 265 | |
Devang Patel | 8cad70d | 2006-11-11 01:51:02 +0000 | [diff] [blame] | 266 | inline std::vector<Pass *>::iterator passVectorBegin() { |
| 267 | return PassVector.begin(); |
| 268 | } |
| 269 | |
| 270 | inline std::vector<Pass *>::iterator passVectorEnd() { |
| 271 | return PassVector.end(); |
| 272 | } |
| 273 | |
Devang Patel | f3827bc | 2006-12-07 19:54:15 +0000 | [diff] [blame] | 274 | // Access toplevel manager |
| 275 | PMTopLevelManager *getTopLevelManager() { return TPM; } |
| 276 | void setTopLevelManager(PMTopLevelManager *T) { TPM = T; } |
| 277 | |
Devang Patel | 4c36e6b | 2006-12-07 23:24:58 +0000 | [diff] [blame^] | 278 | unsigned getDepth() { return Depth; } |
| 279 | |
Devang Patel | a984459 | 2006-11-11 01:31:05 +0000 | [diff] [blame] | 280 | private: |
Devang Patel | dafa4dd | 2006-11-14 00:03:04 +0000 | [diff] [blame] | 281 | // 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 Patel | f60b5d9 | 2006-11-14 01:59:59 +0000 | [diff] [blame] | 285 | std::map<AnalysisID, Pass*> AvailableAnalysis; |
Devang Patel | 8cad70d | 2006-11-11 01:51:02 +0000 | [diff] [blame] | 286 | |
| 287 | // Collection of pass that are managed by this manager |
| 288 | std::vector<Pass *> PassVector; |
Devang Patel | f3827bc | 2006-12-07 19:54:15 +0000 | [diff] [blame] | 289 | |
| 290 | // Top level manager. |
| 291 | // TODO : Make it a reference. |
| 292 | PMTopLevelManager *TPM; |
Devang Patel | 4c36e6b | 2006-12-07 23:24:58 +0000 | [diff] [blame^] | 293 | |
| 294 | unsigned Depth; |
Devang Patel | a984459 | 2006-11-11 01:31:05 +0000 | [diff] [blame] | 295 | }; |
| 296 | |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 297 | /// BasicBlockPassManager_New manages BasicBlockPass. It batches all the |
| 298 | /// pass together and sequence them to process one basic block before |
| 299 | /// processing next basic block. |
Devang Patel | dbe4a1e | 2006-12-07 18:36:24 +0000 | [diff] [blame] | 300 | class BasicBlockPassManager_New : public PMDataManager, |
Devang Patel | 42add71 | 2006-11-15 01:11:27 +0000 | [diff] [blame] | 301 | public FunctionPass { |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 302 | |
| 303 | public: |
Devang Patel | 4c36e6b | 2006-12-07 23:24:58 +0000 | [diff] [blame^] | 304 | BasicBlockPassManager_New(int D) : PMDataManager(D) { } |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 305 | |
| 306 | /// Add a pass into a passmanager queue. |
| 307 | bool addPass(Pass *p); |
| 308 | |
| 309 | /// Execute all of the passes scheduled for execution. Keep track of |
| 310 | /// whether any of the passes modifies the function, and if so, return true. |
| 311 | bool runOnFunction(Function &F); |
| 312 | |
Devang Patel | ebba970 | 2006-11-13 22:40:09 +0000 | [diff] [blame] | 313 | /// Return true IFF AnalysisID AID is currently available. |
Devang Patel | 642c143 | 2006-12-07 21:58:50 +0000 | [diff] [blame] | 314 | /// TODO : Replace this method with getAnalysisPass() |
Devang Patel | 3f0832a | 2006-11-14 02:54:23 +0000 | [diff] [blame] | 315 | Pass *getAnalysisPassFromManager(AnalysisID AID); |
Devang Patel | ebba970 | 2006-11-13 22:40:09 +0000 | [diff] [blame] | 316 | |
Devang Patel | f9d96b9 | 2006-12-07 19:57:52 +0000 | [diff] [blame] | 317 | /// Pass Manager itself does not invalidate any analysis info. |
| 318 | void getAnalysisUsage(AnalysisUsage &Info) const { |
| 319 | Info.setPreservesAll(); |
| 320 | } |
| 321 | |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 322 | private: |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 323 | }; |
| 324 | |
Devang Patel | 4e12f86 | 2006-11-08 10:44:40 +0000 | [diff] [blame] | 325 | /// FunctionPassManagerImpl_New manages FunctionPasses and BasicBlockPassManagers. |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 326 | /// It batches all function passes and basic block pass managers together and |
| 327 | /// sequence them to process one function at a time before processing next |
| 328 | /// function. |
Devang Patel | abcd1d3 | 2006-12-07 21:27:23 +0000 | [diff] [blame] | 329 | class FunctionPassManagerImpl_New : public ModulePass, |
| 330 | public PMDataManager, |
| 331 | public PMTopLevelManager { |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 332 | public: |
Devang Patel | 4c36e6b | 2006-12-07 23:24:58 +0000 | [diff] [blame^] | 333 | FunctionPassManagerImpl_New(ModuleProvider *P, int D) : |
| 334 | PMDataManager(D) { /* TODO */ } |
| 335 | FunctionPassManagerImpl_New(int D) : PMDataManager(D) { |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 336 | activeBBPassManager = NULL; |
| 337 | } |
Devang Patel | 4e12f86 | 2006-11-08 10:44:40 +0000 | [diff] [blame] | 338 | ~FunctionPassManagerImpl_New() { /* TODO */ }; |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 339 | |
Devang Patel | abcd1d3 | 2006-12-07 21:27:23 +0000 | [diff] [blame] | 340 | inline void addTopLevelPass(Pass *P) { |
| 341 | addPass(P); |
| 342 | } |
| 343 | |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 344 | /// add - Add a pass to the queue of passes to run. This passes |
| 345 | /// ownership of the Pass to the PassManager. When the |
| 346 | /// PassManager_X is destroyed, the pass will be destroyed as well, so |
| 347 | /// there is no need to delete the pass. (TODO delete passes.) |
| 348 | /// This implies that all passes MUST be allocated with 'new'. |
Devang Patel | 31217af | 2006-12-07 21:32:57 +0000 | [diff] [blame] | 349 | void add(Pass *P) { |
| 350 | schedulePass(P, this); |
| 351 | } |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 352 | |
| 353 | /// Add pass into the pass manager queue. |
| 354 | bool addPass(Pass *P); |
| 355 | |
| 356 | /// Execute all of the passes scheduled for execution. Keep |
| 357 | /// track of whether any of the passes modifies the function, and if |
| 358 | /// so, return true. |
| 359 | bool runOnModule(Module &M); |
Devang Patel | 9f3083e | 2006-11-15 19:39:54 +0000 | [diff] [blame] | 360 | bool runOnFunction(Function &F); |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 361 | |
Devang Patel | ebba970 | 2006-11-13 22:40:09 +0000 | [diff] [blame] | 362 | /// Return true IFF AnalysisID AID is currently available. |
Devang Patel | 642c143 | 2006-12-07 21:58:50 +0000 | [diff] [blame] | 363 | /// TODO : Replace this method with getAnalysisPass() |
Devang Patel | 3f0832a | 2006-11-14 02:54:23 +0000 | [diff] [blame] | 364 | Pass *getAnalysisPassFromManager(AnalysisID AID); |
Devang Patel | ebba970 | 2006-11-13 22:40:09 +0000 | [diff] [blame] | 365 | |
Devang Patel | ff631ae | 2006-11-15 01:27:05 +0000 | [diff] [blame] | 366 | /// doInitialization - Run all of the initializers for the function passes. |
| 367 | /// |
| 368 | bool doInitialization(Module &M); |
| 369 | |
| 370 | /// doFinalization - Run all of the initializers for the function passes. |
| 371 | /// |
| 372 | bool doFinalization(Module &M); |
Devang Patel | f9d96b9 | 2006-12-07 19:57:52 +0000 | [diff] [blame] | 373 | |
| 374 | /// Pass Manager itself does not invalidate any analysis info. |
| 375 | void getAnalysisUsage(AnalysisUsage &Info) const { |
| 376 | Info.setPreservesAll(); |
| 377 | } |
| 378 | |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 379 | private: |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 380 | // Active Pass Managers |
| 381 | BasicBlockPassManager_New *activeBBPassManager; |
| 382 | }; |
| 383 | |
| 384 | /// ModulePassManager_New manages ModulePasses and function pass managers. |
| 385 | /// It batches all Module passes passes and function pass managers together and |
| 386 | /// sequence them to process one module. |
Devang Patel | dbe4a1e | 2006-12-07 18:36:24 +0000 | [diff] [blame] | 387 | class ModulePassManager_New : public PMDataManager { |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 388 | |
| 389 | public: |
Devang Patel | 4c36e6b | 2006-12-07 23:24:58 +0000 | [diff] [blame^] | 390 | ModulePassManager_New(int D) : PMDataManager(D) { |
| 391 | activeFunctionPassManager = NULL; |
| 392 | } |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 393 | |
| 394 | /// Add a pass into a passmanager queue. |
| 395 | bool addPass(Pass *p); |
| 396 | |
| 397 | /// run - Execute all of the passes scheduled for execution. Keep track of |
| 398 | /// whether any of the passes modifies the module, and if so, return true. |
| 399 | bool runOnModule(Module &M); |
Devang Patel | ebba970 | 2006-11-13 22:40:09 +0000 | [diff] [blame] | 400 | |
| 401 | /// Return true IFF AnalysisID AID is currently available. |
Devang Patel | 642c143 | 2006-12-07 21:58:50 +0000 | [diff] [blame] | 402 | /// TODO : Replace this method with getAnalysisPass() |
Devang Patel | 3f0832a | 2006-11-14 02:54:23 +0000 | [diff] [blame] | 403 | Pass *getAnalysisPassFromManager(AnalysisID AID); |
Devang Patel | f9d96b9 | 2006-12-07 19:57:52 +0000 | [diff] [blame] | 404 | |
| 405 | /// Pass Manager itself does not invalidate any analysis info. |
| 406 | void getAnalysisUsage(AnalysisUsage &Info) const { |
| 407 | Info.setPreservesAll(); |
| 408 | } |
| 409 | |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 410 | private: |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 411 | // Active Pass Manager |
Devang Patel | 4e12f86 | 2006-11-08 10:44:40 +0000 | [diff] [blame] | 412 | FunctionPassManagerImpl_New *activeFunctionPassManager; |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 413 | }; |
| 414 | |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 415 | /// PassManager_New manages ModulePassManagers |
Devang Patel | 31217af | 2006-12-07 21:32:57 +0000 | [diff] [blame] | 416 | class PassManagerImpl_New : public Pass, |
| 417 | public PMDataManager, |
Devang Patel | abcd1d3 | 2006-12-07 21:27:23 +0000 | [diff] [blame] | 418 | public PMTopLevelManager { |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 419 | |
| 420 | public: |
| 421 | |
Devang Patel | 4c36e6b | 2006-12-07 23:24:58 +0000 | [diff] [blame^] | 422 | PassManagerImpl_New(int D) : PMDataManager(D) {} |
| 423 | |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 424 | /// add - Add a pass to the queue of passes to run. This passes ownership of |
| 425 | /// the Pass to the PassManager. When the PassManager is destroyed, the pass |
| 426 | /// will be destroyed as well, so there is no need to delete the pass. This |
| 427 | /// implies that all passes MUST be allocated with 'new'. |
Devang Patel | 31217af | 2006-12-07 21:32:57 +0000 | [diff] [blame] | 428 | void add(Pass *P) { |
| 429 | schedulePass(P, this); |
| 430 | } |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 431 | |
| 432 | /// run - Execute all of the passes scheduled for execution. Keep track of |
| 433 | /// whether any of the passes modifies the module, and if so, return true. |
| 434 | bool run(Module &M); |
| 435 | |
Devang Patel | ebba970 | 2006-11-13 22:40:09 +0000 | [diff] [blame] | 436 | /// Return true IFF AnalysisID AID is currently available. |
Devang Patel | 642c143 | 2006-12-07 21:58:50 +0000 | [diff] [blame] | 437 | /// TODO : Replace this method with getAnalysisPass() |
Devang Patel | 3f0832a | 2006-11-14 02:54:23 +0000 | [diff] [blame] | 438 | Pass *getAnalysisPassFromManager(AnalysisID AID); |
Devang Patel | ebba970 | 2006-11-13 22:40:09 +0000 | [diff] [blame] | 439 | |
Devang Patel | f9d96b9 | 2006-12-07 19:57:52 +0000 | [diff] [blame] | 440 | /// Pass Manager itself does not invalidate any analysis info. |
| 441 | void getAnalysisUsage(AnalysisUsage &Info) const { |
| 442 | Info.setPreservesAll(); |
| 443 | } |
| 444 | |
Devang Patel | abcd1d3 | 2006-12-07 21:27:23 +0000 | [diff] [blame] | 445 | inline void addTopLevelPass(Pass *P) { |
| 446 | addPass(P); |
| 447 | } |
| 448 | |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 449 | private: |
| 450 | |
Devang Patel | de12418 | 2006-12-07 21:10:57 +0000 | [diff] [blame] | 451 | /// Add a pass into a passmanager queue. |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 452 | bool addPass(Pass *p); |
| 453 | |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 454 | // Collection of pass managers |
| 455 | std::vector<ModulePassManager_New *> PassManagers; |
| 456 | |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 457 | // Active Pass Manager |
| 458 | ModulePassManager_New *activeManager; |
| 459 | }; |
| 460 | |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 461 | } // End of llvm namespace |
| 462 | |
Devang Patel | a1514cb | 2006-12-07 19:39:39 +0000 | [diff] [blame] | 463 | //===----------------------------------------------------------------------===// |
Devang Patel | dbe4a1e | 2006-12-07 18:36:24 +0000 | [diff] [blame] | 464 | // PMDataManager implementation |
Devang Patel | f68a349 | 2006-11-07 22:35:17 +0000 | [diff] [blame] | 465 | |
Devang Patel | d65e9e9 | 2006-11-08 01:31:28 +0000 | [diff] [blame] | 466 | /// Return true IFF pass P's required analysis set does not required new |
Devang Patel | f68a349 | 2006-11-07 22:35:17 +0000 | [diff] [blame] | 467 | /// manager. |
Devang Patel | dbe4a1e | 2006-12-07 18:36:24 +0000 | [diff] [blame] | 468 | bool PMDataManager::manageablePass(Pass *P) { |
Devang Patel | f68a349 | 2006-11-07 22:35:17 +0000 | [diff] [blame] | 469 | |
Devang Patel | 8f677ce | 2006-12-07 18:47:25 +0000 | [diff] [blame] | 470 | // TODO |
| 471 | // If this pass is not preserving information that is required by a |
| 472 | // pass maintained by higher level pass manager then do not insert |
| 473 | // this pass into current manager. Use new manager. For example, |
| 474 | // For example, If FunctionPass F is not preserving ModulePass Info M1 |
| 475 | // that is used by another ModulePass M2 then do not insert F in |
| 476 | // current function pass manager. |
Devang Patel | f68a349 | 2006-11-07 22:35:17 +0000 | [diff] [blame] | 477 | return true; |
| 478 | } |
| 479 | |
Devang Patel | 643676c | 2006-11-11 01:10:19 +0000 | [diff] [blame] | 480 | /// Augement AvailableAnalysis by adding analysis made available by pass P. |
Devang Patel | e9976aa | 2006-12-07 19:33:53 +0000 | [diff] [blame] | 481 | void PMDataManager::recordAvailableAnalysis(Pass *P) { |
Devang Patel | f60b5d9 | 2006-11-14 01:59:59 +0000 | [diff] [blame] | 482 | |
Devang Patel | 643676c | 2006-11-11 01:10:19 +0000 | [diff] [blame] | 483 | if (const PassInfo *PI = P->getPassInfo()) { |
Devang Patel | f60b5d9 | 2006-11-14 01:59:59 +0000 | [diff] [blame] | 484 | AvailableAnalysis[PI] = P; |
Devang Patel | 643676c | 2006-11-11 01:10:19 +0000 | [diff] [blame] | 485 | |
Devang Patel | e9976aa | 2006-12-07 19:33:53 +0000 | [diff] [blame] | 486 | //This pass is the current implementation of all of the interfaces it |
| 487 | //implements as well. |
| 488 | const std::vector<const PassInfo*> &II = PI->getInterfacesImplemented(); |
| 489 | for (unsigned i = 0, e = II.size(); i != e; ++i) |
| 490 | AvailableAnalysis[II[i]] = P; |
Devang Patel | 643676c | 2006-11-11 01:10:19 +0000 | [diff] [blame] | 491 | } |
| 492 | } |
| 493 | |
Devang Patel | f68a349 | 2006-11-07 22:35:17 +0000 | [diff] [blame] | 494 | /// Remove Analyss not preserved by Pass P |
Devang Patel | dbe4a1e | 2006-12-07 18:36:24 +0000 | [diff] [blame] | 495 | void PMDataManager::removeNotPreservedAnalysis(Pass *P) { |
Devang Patel | 349170f | 2006-11-11 01:24:55 +0000 | [diff] [blame] | 496 | AnalysisUsage AnUsage; |
| 497 | P->getAnalysisUsage(AnUsage); |
Devang Patel | f68a349 | 2006-11-07 22:35:17 +0000 | [diff] [blame] | 498 | |
Devang Patel | 2e169c3 | 2006-12-07 20:03:49 +0000 | [diff] [blame] | 499 | if (AnUsage.getPreservesAll()) |
| 500 | return; |
| 501 | |
| 502 | const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet(); |
Devang Patel | f60b5d9 | 2006-11-14 01:59:59 +0000 | [diff] [blame] | 503 | for (std::map<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(), |
Devang Patel | 349170f | 2006-11-11 01:24:55 +0000 | [diff] [blame] | 504 | E = AvailableAnalysis.end(); I != E; ++I ) { |
Devang Patel | f60b5d9 | 2006-11-14 01:59:59 +0000 | [diff] [blame] | 505 | if (std::find(PreservedSet.begin(), PreservedSet.end(), I->first) == |
Devang Patel | 349170f | 2006-11-11 01:24:55 +0000 | [diff] [blame] | 506 | PreservedSet.end()) { |
| 507 | // Remove this analysis |
Devang Patel | f60b5d9 | 2006-11-14 01:59:59 +0000 | [diff] [blame] | 508 | std::map<AnalysisID, Pass*>::iterator J = I++; |
Devang Patel | 349170f | 2006-11-11 01:24:55 +0000 | [diff] [blame] | 509 | AvailableAnalysis.erase(J); |
| 510 | } |
| 511 | } |
Devang Patel | f68a349 | 2006-11-07 22:35:17 +0000 | [diff] [blame] | 512 | } |
| 513 | |
Devang Patel | ca18926 | 2006-11-14 03:05:08 +0000 | [diff] [blame] | 514 | /// Remove analysis passes that are not used any longer |
Devang Patel | dbe4a1e | 2006-12-07 18:36:24 +0000 | [diff] [blame] | 515 | void PMDataManager::removeDeadPasses(Pass *P) { |
Devang Patel | f4805ce | 2006-12-07 22:17:09 +0000 | [diff] [blame] | 516 | // TODO : reimplement |
Devang Patel | ca18926 | 2006-11-14 03:05:08 +0000 | [diff] [blame] | 517 | } |
| 518 | |
Devang Patel | 8f677ce | 2006-12-07 18:47:25 +0000 | [diff] [blame] | 519 | /// Add pass P into the PassVector. Update |
Devang Patel | 90b05e0 | 2006-11-11 02:04:19 +0000 | [diff] [blame] | 520 | /// AvailableAnalysis appropriately if ProcessAnalysis is true. |
Devang Patel | 2e169c3 | 2006-12-07 20:03:49 +0000 | [diff] [blame] | 521 | void PMDataManager::addPassToManager(Pass *P, |
| 522 | bool ProcessAnalysis) { |
Devang Patel | 8cad70d | 2006-11-11 01:51:02 +0000 | [diff] [blame] | 523 | |
Devang Patel | 90b05e0 | 2006-11-11 02:04:19 +0000 | [diff] [blame] | 524 | if (ProcessAnalysis) { |
Devang Patel | 17bff0d | 2006-12-07 22:09:36 +0000 | [diff] [blame] | 525 | // Take a note of analysis required and made available by this pass. |
Devang Patel | 90b05e0 | 2006-11-11 02:04:19 +0000 | [diff] [blame] | 526 | // Remove the analysis not preserved by this pass |
Devang Patel | 17bff0d | 2006-12-07 22:09:36 +0000 | [diff] [blame] | 527 | initializeAnalysisImpl(P); |
Devang Patel | 90b05e0 | 2006-11-11 02:04:19 +0000 | [diff] [blame] | 528 | removeNotPreservedAnalysis(P); |
Devang Patel | 17bff0d | 2006-12-07 22:09:36 +0000 | [diff] [blame] | 529 | recordAvailableAnalysis(P); |
Devang Patel | 90b05e0 | 2006-11-11 02:04:19 +0000 | [diff] [blame] | 530 | } |
Devang Patel | 8cad70d | 2006-11-11 01:51:02 +0000 | [diff] [blame] | 531 | |
| 532 | // Add pass |
| 533 | PassVector.push_back(P); |
Devang Patel | 8cad70d | 2006-11-11 01:51:02 +0000 | [diff] [blame] | 534 | } |
| 535 | |
Devang Patel | 1d6267c | 2006-12-07 23:05:44 +0000 | [diff] [blame] | 536 | /// Populate RequiredPasses with the analysis pass that are required by |
| 537 | /// pass P. |
| 538 | void PMDataManager::collectRequiredAnalysisPasses(std::vector<Pass *> &RP, |
| 539 | Pass *P) { |
| 540 | AnalysisUsage AnUsage; |
| 541 | P->getAnalysisUsage(AnUsage); |
| 542 | const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet(); |
| 543 | for (std::vector<AnalysisID>::const_iterator |
| 544 | I = RequiredSet.begin(), E = RequiredSet.end(); |
| 545 | I != E; ++I) { |
| 546 | Pass *AnalysisPass = NULL; //FIXME findAnalysisPass(*I,true); |
| 547 | assert (AnalysisPass && "Analysis pass is not available"); |
| 548 | RP.push_back(AnalysisPass); |
| 549 | } |
| 550 | } |
| 551 | |
Devang Patel | 07f4f58 | 2006-11-14 21:49:36 +0000 | [diff] [blame] | 552 | // All Required analyses should be available to the pass as it runs! Here |
| 553 | // we fill in the AnalysisImpls member of the pass so that it can |
| 554 | // successfully use the getAnalysis() method to retrieve the |
| 555 | // implementations it needs. |
| 556 | // |
Devang Patel | dbe4a1e | 2006-12-07 18:36:24 +0000 | [diff] [blame] | 557 | void PMDataManager::initializeAnalysisImpl(Pass *P) { |
Devang Patel | ff631ae | 2006-11-15 01:27:05 +0000 | [diff] [blame] | 558 | AnalysisUsage AnUsage; |
| 559 | P->getAnalysisUsage(AnUsage); |
Devang Patel | 07f4f58 | 2006-11-14 21:49:36 +0000 | [diff] [blame] | 560 | |
| 561 | for (std::vector<const PassInfo *>::const_iterator |
| 562 | I = AnUsage.getRequiredSet().begin(), |
| 563 | E = AnUsage.getRequiredSet().end(); I != E; ++I) { |
| 564 | Pass *Impl = getAnalysisPass(*I); |
| 565 | if (Impl == 0) |
| 566 | assert(0 && "Analysis used but not available!"); |
| 567 | // TODO: P->AnalysisImpls.push_back(std::make_pair(*I, Impl)); |
| 568 | } |
| 569 | } |
| 570 | |
Devang Patel | a1514cb | 2006-12-07 19:39:39 +0000 | [diff] [blame] | 571 | //===----------------------------------------------------------------------===// |
| 572 | // BasicBlockPassManager_New implementation |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 573 | |
Devang Patel | d65e9e9 | 2006-11-08 01:31:28 +0000 | [diff] [blame] | 574 | /// Add pass P into PassVector and return true. If this pass is not |
| 575 | /// manageable by this manager then return false. |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 576 | bool |
Devang Patel | d65e9e9 | 2006-11-08 01:31:28 +0000 | [diff] [blame] | 577 | BasicBlockPassManager_New::addPass(Pass *P) { |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 578 | |
| 579 | BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P); |
| 580 | if (!BP) |
| 581 | return false; |
| 582 | |
Devang Patel | 3c8eb62 | 2006-11-07 22:56:50 +0000 | [diff] [blame] | 583 | // If this pass does not preserve anlysis that is used by other passes |
| 584 | // managed by this manager than it is not a suiable pass for this manager. |
Devang Patel | d65e9e9 | 2006-11-08 01:31:28 +0000 | [diff] [blame] | 585 | if (!manageablePass(P)) |
Devang Patel | 3c8eb62 | 2006-11-07 22:56:50 +0000 | [diff] [blame] | 586 | return false; |
| 587 | |
Devang Patel | 8cad70d | 2006-11-11 01:51:02 +0000 | [diff] [blame] | 588 | addPassToManager (BP); |
Devang Patel | 349170f | 2006-11-11 01:24:55 +0000 | [diff] [blame] | 589 | |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 590 | return true; |
| 591 | } |
| 592 | |
| 593 | /// Execute all of the passes scheduled for execution by invoking |
| 594 | /// runOnBasicBlock method. Keep track of whether any of the passes modifies |
| 595 | /// the function, and if so, return true. |
| 596 | bool |
| 597 | BasicBlockPassManager_New::runOnFunction(Function &F) { |
| 598 | |
| 599 | bool Changed = false; |
Devang Patel | a6b6dcb | 2006-12-07 18:41:09 +0000 | [diff] [blame] | 600 | initializeAnalysisInfo(); |
Devang Patel | 050ec72 | 2006-11-14 01:23:29 +0000 | [diff] [blame] | 601 | |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 602 | for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) |
Devang Patel | 8cad70d | 2006-11-11 01:51:02 +0000 | [diff] [blame] | 603 | for (std::vector<Pass *>::iterator itr = passVectorBegin(), |
| 604 | e = passVectorEnd(); itr != e; ++itr) { |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 605 | Pass *P = *itr; |
Devang Patel | 050ec72 | 2006-11-14 01:23:29 +0000 | [diff] [blame] | 606 | |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 607 | BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P); |
| 608 | Changed |= BP->runOnBasicBlock(*I); |
Devang Patel | 050ec72 | 2006-11-14 01:23:29 +0000 | [diff] [blame] | 609 | removeNotPreservedAnalysis(P); |
Devang Patel | 17bff0d | 2006-12-07 22:09:36 +0000 | [diff] [blame] | 610 | recordAvailableAnalysis(P); |
Devang Patel | ca18926 | 2006-11-14 03:05:08 +0000 | [diff] [blame] | 611 | removeDeadPasses(P); |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 612 | } |
| 613 | return Changed; |
| 614 | } |
| 615 | |
Devang Patel | ebba970 | 2006-11-13 22:40:09 +0000 | [diff] [blame] | 616 | /// Return true IFF AnalysisID AID is currently available. |
Devang Patel | 642c143 | 2006-12-07 21:58:50 +0000 | [diff] [blame] | 617 | /// TODO : Replace this method with getAnalysisPass() |
Devang Patel | 3f0832a | 2006-11-14 02:54:23 +0000 | [diff] [blame] | 618 | Pass * BasicBlockPassManager_New::getAnalysisPassFromManager(AnalysisID AID) { |
| 619 | return getAnalysisPass(AID); |
Devang Patel | ebba970 | 2006-11-13 22:40:09 +0000 | [diff] [blame] | 620 | } |
| 621 | |
Devang Patel | a1514cb | 2006-12-07 19:39:39 +0000 | [diff] [blame] | 622 | //===----------------------------------------------------------------------===// |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 623 | // FunctionPassManager_New implementation |
Devang Patel | a1514cb | 2006-12-07 19:39:39 +0000 | [diff] [blame] | 624 | |
Devang Patel | 4e12f86 | 2006-11-08 10:44:40 +0000 | [diff] [blame] | 625 | /// Create new Function pass manager |
| 626 | FunctionPassManager_New::FunctionPassManager_New() { |
Devang Patel | 4c36e6b | 2006-12-07 23:24:58 +0000 | [diff] [blame^] | 627 | FPM = new FunctionPassManagerImpl_New(0); |
Devang Patel | 4e12f86 | 2006-11-08 10:44:40 +0000 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | /// add - Add a pass to the queue of passes to run. This passes |
| 631 | /// ownership of the Pass to the PassManager. When the |
| 632 | /// PassManager_X is destroyed, the pass will be destroyed as well, so |
| 633 | /// there is no need to delete the pass. (TODO delete passes.) |
| 634 | /// This implies that all passes MUST be allocated with 'new'. |
Devang Patel | 9f3083e | 2006-11-15 19:39:54 +0000 | [diff] [blame] | 635 | void FunctionPassManager_New::add(Pass *P) { |
Devang Patel | 4e12f86 | 2006-11-08 10:44:40 +0000 | [diff] [blame] | 636 | FPM->add(P); |
| 637 | } |
| 638 | |
| 639 | /// Execute all of the passes scheduled for execution. Keep |
| 640 | /// track of whether any of the passes modifies the function, and if |
| 641 | /// so, return true. |
Devang Patel | 9f3083e | 2006-11-15 19:39:54 +0000 | [diff] [blame] | 642 | bool FunctionPassManager_New::runOnModule(Module &M) { |
Devang Patel | 4e12f86 | 2006-11-08 10:44:40 +0000 | [diff] [blame] | 643 | return FPM->runOnModule(M); |
| 644 | } |
| 645 | |
Devang Patel | 9f3083e | 2006-11-15 19:39:54 +0000 | [diff] [blame] | 646 | /// run - Execute all of the passes scheduled for execution. Keep |
| 647 | /// track of whether any of the passes modifies the function, and if |
| 648 | /// so, return true. |
| 649 | /// |
| 650 | bool FunctionPassManager_New::run(Function &F) { |
| 651 | std::string errstr; |
| 652 | if (MP->materializeFunction(&F, &errstr)) { |
Bill Wendling | f3baad3 | 2006-12-07 01:30:32 +0000 | [diff] [blame] | 653 | cerr << "Error reading bytecode file: " << errstr << "\n"; |
Devang Patel | 9f3083e | 2006-11-15 19:39:54 +0000 | [diff] [blame] | 654 | abort(); |
| 655 | } |
| 656 | return FPM->runOnFunction(F); |
| 657 | } |
| 658 | |
| 659 | |
Devang Patel | ff631ae | 2006-11-15 01:27:05 +0000 | [diff] [blame] | 660 | /// doInitialization - Run all of the initializers for the function passes. |
| 661 | /// |
| 662 | bool FunctionPassManager_New::doInitialization() { |
| 663 | return FPM->doInitialization(*MP->getModule()); |
| 664 | } |
| 665 | |
| 666 | /// doFinalization - Run all of the initializers for the function passes. |
| 667 | /// |
| 668 | bool FunctionPassManager_New::doFinalization() { |
| 669 | return FPM->doFinalization(*MP->getModule()); |
| 670 | } |
| 671 | |
Devang Patel | a1514cb | 2006-12-07 19:39:39 +0000 | [diff] [blame] | 672 | //===----------------------------------------------------------------------===// |
Devang Patel | 4e12f86 | 2006-11-08 10:44:40 +0000 | [diff] [blame] | 673 | // FunctionPassManagerImpl_New implementation |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 674 | |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 675 | /// Add pass P into the pass manager queue. If P is a BasicBlockPass then |
| 676 | /// either use it into active basic block pass manager or create new basic |
| 677 | /// block pass manager to handle pass P. |
| 678 | bool |
Devang Patel | 4e12f86 | 2006-11-08 10:44:40 +0000 | [diff] [blame] | 679 | FunctionPassManagerImpl_New::addPass(Pass *P) { |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 680 | |
| 681 | // If P is a BasicBlockPass then use BasicBlockPassManager_New. |
| 682 | if (BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P)) { |
| 683 | |
Devang Patel | 4949fe0 | 2006-12-07 22:34:21 +0000 | [diff] [blame] | 684 | if (!activeBBPassManager || !activeBBPassManager->addPass(BP)) { |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 685 | |
Devang Patel | 4949fe0 | 2006-12-07 22:34:21 +0000 | [diff] [blame] | 686 | // If active manager exists then clear its analysis info. |
| 687 | if (activeBBPassManager) |
| 688 | activeBBPassManager->initializeAnalysisInfo(); |
Devang Patel | 642c143 | 2006-12-07 21:58:50 +0000 | [diff] [blame] | 689 | |
Devang Patel | 4949fe0 | 2006-12-07 22:34:21 +0000 | [diff] [blame] | 690 | // Create and add new manager |
Devang Patel | 4c36e6b | 2006-12-07 23:24:58 +0000 | [diff] [blame^] | 691 | activeBBPassManager = |
| 692 | new BasicBlockPassManager_New(getDepth() + 1); |
Devang Patel | 90b05e0 | 2006-11-11 02:04:19 +0000 | [diff] [blame] | 693 | addPassToManager(activeBBPassManager, false); |
Devang Patel | 4949fe0 | 2006-12-07 22:34:21 +0000 | [diff] [blame] | 694 | |
| 695 | // Add pass into new manager. This time it must succeed. |
Devang Patel | d65e9e9 | 2006-11-08 01:31:28 +0000 | [diff] [blame] | 696 | if (!activeBBPassManager->addPass(BP)) |
| 697 | assert(0 && "Unable to add Pass"); |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 698 | } |
| 699 | return true; |
| 700 | } |
| 701 | |
| 702 | FunctionPass *FP = dynamic_cast<FunctionPass *>(P); |
| 703 | if (!FP) |
| 704 | return false; |
| 705 | |
Devang Patel | 3c8eb62 | 2006-11-07 22:56:50 +0000 | [diff] [blame] | 706 | // If this pass does not preserve anlysis that is used by other passes |
| 707 | // managed by this manager than it is not a suiable pass for this manager. |
Devang Patel | d65e9e9 | 2006-11-08 01:31:28 +0000 | [diff] [blame] | 708 | if (!manageablePass(P)) |
Devang Patel | 3c8eb62 | 2006-11-07 22:56:50 +0000 | [diff] [blame] | 709 | return false; |
| 710 | |
Devang Patel | 8cad70d | 2006-11-11 01:51:02 +0000 | [diff] [blame] | 711 | addPassToManager (FP); |
Devang Patel | 4949fe0 | 2006-12-07 22:34:21 +0000 | [diff] [blame] | 712 | |
| 713 | // If active manager exists then clear its analysis info. |
| 714 | if (activeBBPassManager) { |
| 715 | activeBBPassManager->initializeAnalysisInfo(); |
| 716 | activeBBPassManager = NULL; |
| 717 | } |
| 718 | |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 719 | return true; |
| 720 | } |
| 721 | |
| 722 | /// Execute all of the passes scheduled for execution by invoking |
| 723 | /// runOnFunction method. Keep track of whether any of the passes modifies |
| 724 | /// the function, and if so, return true. |
Devang Patel | 9f3083e | 2006-11-15 19:39:54 +0000 | [diff] [blame] | 725 | bool FunctionPassManagerImpl_New::runOnModule(Module &M) { |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 726 | |
| 727 | bool Changed = false; |
Devang Patel | a6b6dcb | 2006-12-07 18:41:09 +0000 | [diff] [blame] | 728 | initializeAnalysisInfo(); |
Devang Patel | 050ec72 | 2006-11-14 01:23:29 +0000 | [diff] [blame] | 729 | |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 730 | for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) |
Devang Patel | 8cad70d | 2006-11-11 01:51:02 +0000 | [diff] [blame] | 731 | for (std::vector<Pass *>::iterator itr = passVectorBegin(), |
| 732 | e = passVectorEnd(); itr != e; ++itr) { |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 733 | Pass *P = *itr; |
Devang Patel | 050ec72 | 2006-11-14 01:23:29 +0000 | [diff] [blame] | 734 | |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 735 | FunctionPass *FP = dynamic_cast<FunctionPass*>(P); |
| 736 | Changed |= FP->runOnFunction(*I); |
Devang Patel | 050ec72 | 2006-11-14 01:23:29 +0000 | [diff] [blame] | 737 | removeNotPreservedAnalysis(P); |
Devang Patel | 17bff0d | 2006-12-07 22:09:36 +0000 | [diff] [blame] | 738 | recordAvailableAnalysis(P); |
Devang Patel | ca18926 | 2006-11-14 03:05:08 +0000 | [diff] [blame] | 739 | removeDeadPasses(P); |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 740 | } |
| 741 | return Changed; |
| 742 | } |
| 743 | |
Devang Patel | 9f3083e | 2006-11-15 19:39:54 +0000 | [diff] [blame] | 744 | /// Execute all of the passes scheduled for execution by invoking |
| 745 | /// runOnFunction method. Keep track of whether any of the passes modifies |
| 746 | /// the function, and if so, return true. |
| 747 | bool FunctionPassManagerImpl_New::runOnFunction(Function &F) { |
| 748 | |
| 749 | bool Changed = false; |
Devang Patel | a6b6dcb | 2006-12-07 18:41:09 +0000 | [diff] [blame] | 750 | initializeAnalysisInfo(); |
Devang Patel | 9f3083e | 2006-11-15 19:39:54 +0000 | [diff] [blame] | 751 | |
| 752 | for (std::vector<Pass *>::iterator itr = passVectorBegin(), |
| 753 | e = passVectorEnd(); itr != e; ++itr) { |
| 754 | Pass *P = *itr; |
| 755 | |
Devang Patel | 9f3083e | 2006-11-15 19:39:54 +0000 | [diff] [blame] | 756 | FunctionPass *FP = dynamic_cast<FunctionPass*>(P); |
| 757 | Changed |= FP->runOnFunction(F); |
| 758 | removeNotPreservedAnalysis(P); |
Devang Patel | 17bff0d | 2006-12-07 22:09:36 +0000 | [diff] [blame] | 759 | recordAvailableAnalysis(P); |
Devang Patel | 9f3083e | 2006-11-15 19:39:54 +0000 | [diff] [blame] | 760 | removeDeadPasses(P); |
| 761 | } |
| 762 | return Changed; |
| 763 | } |
| 764 | |
| 765 | |
Devang Patel | ebba970 | 2006-11-13 22:40:09 +0000 | [diff] [blame] | 766 | /// Return true IFF AnalysisID AID is currently available. |
Devang Patel | 642c143 | 2006-12-07 21:58:50 +0000 | [diff] [blame] | 767 | /// TODO : Replace this method with getAnalysisPass() |
Devang Patel | 3f0832a | 2006-11-14 02:54:23 +0000 | [diff] [blame] | 768 | Pass *FunctionPassManagerImpl_New::getAnalysisPassFromManager(AnalysisID AID) { |
Devang Patel | ebba970 | 2006-11-13 22:40:09 +0000 | [diff] [blame] | 769 | |
Devang Patel | 3f0832a | 2006-11-14 02:54:23 +0000 | [diff] [blame] | 770 | Pass *P = getAnalysisPass(AID); |
| 771 | if (P) |
| 772 | return P; |
Devang Patel | ebba970 | 2006-11-13 22:40:09 +0000 | [diff] [blame] | 773 | |
| 774 | if (activeBBPassManager && |
Devang Patel | f60b5d9 | 2006-11-14 01:59:59 +0000 | [diff] [blame] | 775 | activeBBPassManager->getAnalysisPass(AID) != 0) |
Devang Patel | 3f0832a | 2006-11-14 02:54:23 +0000 | [diff] [blame] | 776 | return activeBBPassManager->getAnalysisPass(AID); |
Devang Patel | ebba970 | 2006-11-13 22:40:09 +0000 | [diff] [blame] | 777 | |
| 778 | // TODO : Check inactive managers |
Devang Patel | 3f0832a | 2006-11-14 02:54:23 +0000 | [diff] [blame] | 779 | return NULL; |
Devang Patel | ebba970 | 2006-11-13 22:40:09 +0000 | [diff] [blame] | 780 | } |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 781 | |
Devang Patel | ff631ae | 2006-11-15 01:27:05 +0000 | [diff] [blame] | 782 | inline bool FunctionPassManagerImpl_New::doInitialization(Module &M) { |
| 783 | bool Changed = false; |
| 784 | |
| 785 | for (std::vector<Pass *>::iterator itr = passVectorBegin(), |
| 786 | e = passVectorEnd(); itr != e; ++itr) { |
| 787 | Pass *P = *itr; |
| 788 | |
| 789 | FunctionPass *FP = dynamic_cast<FunctionPass*>(P); |
| 790 | Changed |= FP->doInitialization(M); |
| 791 | } |
| 792 | |
| 793 | return Changed; |
| 794 | } |
| 795 | |
| 796 | inline bool FunctionPassManagerImpl_New::doFinalization(Module &M) { |
| 797 | bool Changed = false; |
| 798 | |
| 799 | for (std::vector<Pass *>::iterator itr = passVectorBegin(), |
| 800 | e = passVectorEnd(); itr != e; ++itr) { |
| 801 | Pass *P = *itr; |
| 802 | |
| 803 | FunctionPass *FP = dynamic_cast<FunctionPass*>(P); |
| 804 | Changed |= FP->doFinalization(M); |
| 805 | } |
| 806 | |
| 807 | |
| 808 | return Changed; |
| 809 | } |
| 810 | |
Devang Patel | a1514cb | 2006-12-07 19:39:39 +0000 | [diff] [blame] | 811 | //===----------------------------------------------------------------------===// |
Devang Patel | 05e1a97 | 2006-11-07 22:03:15 +0000 | [diff] [blame] | 812 | // ModulePassManager implementation |
| 813 | |
| 814 | /// Add P into pass vector if it is manageble. If P is a FunctionPass |
Devang Patel | 4e12f86 | 2006-11-08 10:44:40 +0000 | [diff] [blame] | 815 | /// then use FunctionPassManagerImpl_New to manage it. Return false if P |
Devang Patel | 05e1a97 | 2006-11-07 22:03:15 +0000 | [diff] [blame] | 816 | /// is not manageable by this manager. |
| 817 | bool |
Devang Patel | d65e9e9 | 2006-11-08 01:31:28 +0000 | [diff] [blame] | 818 | ModulePassManager_New::addPass(Pass *P) { |
Devang Patel | 05e1a97 | 2006-11-07 22:03:15 +0000 | [diff] [blame] | 819 | |
| 820 | // If P is FunctionPass then use function pass maanager. |
| 821 | if (FunctionPass *FP = dynamic_cast<FunctionPass*>(P)) { |
| 822 | |
Devang Patel | 05e1a97 | 2006-11-07 22:03:15 +0000 | [diff] [blame] | 823 | if (!activeFunctionPassManager |
| 824 | || !activeFunctionPassManager->addPass(P)) { |
| 825 | |
Devang Patel | 4949fe0 | 2006-12-07 22:34:21 +0000 | [diff] [blame] | 826 | // If active manager exists then clear its analysis info. |
| 827 | if (activeFunctionPassManager) |
| 828 | activeFunctionPassManager->initializeAnalysisInfo(); |
Devang Patel | 642c143 | 2006-12-07 21:58:50 +0000 | [diff] [blame] | 829 | |
Devang Patel | 4949fe0 | 2006-12-07 22:34:21 +0000 | [diff] [blame] | 830 | // Create and add new manager |
Devang Patel | 4c36e6b | 2006-12-07 23:24:58 +0000 | [diff] [blame^] | 831 | activeFunctionPassManager = |
| 832 | new FunctionPassManagerImpl_New(getDepth() + 1); |
Devang Patel | 90b05e0 | 2006-11-11 02:04:19 +0000 | [diff] [blame] | 833 | addPassToManager(activeFunctionPassManager, false); |
Devang Patel | 4949fe0 | 2006-12-07 22:34:21 +0000 | [diff] [blame] | 834 | |
| 835 | // Add pass into new manager. This time it must succeed. |
Devang Patel | d65e9e9 | 2006-11-08 01:31:28 +0000 | [diff] [blame] | 836 | if (!activeFunctionPassManager->addPass(FP)) |
| 837 | assert(0 && "Unable to add pass"); |
Devang Patel | 05e1a97 | 2006-11-07 22:03:15 +0000 | [diff] [blame] | 838 | } |
| 839 | return true; |
| 840 | } |
| 841 | |
| 842 | ModulePass *MP = dynamic_cast<ModulePass *>(P); |
| 843 | if (!MP) |
| 844 | return false; |
| 845 | |
Devang Patel | 3c8eb62 | 2006-11-07 22:56:50 +0000 | [diff] [blame] | 846 | // If this pass does not preserve anlysis that is used by other passes |
| 847 | // managed by this manager than it is not a suiable pass for this manager. |
Devang Patel | d65e9e9 | 2006-11-08 01:31:28 +0000 | [diff] [blame] | 848 | if (!manageablePass(P)) |
Devang Patel | 3c8eb62 | 2006-11-07 22:56:50 +0000 | [diff] [blame] | 849 | return false; |
| 850 | |
Devang Patel | 8cad70d | 2006-11-11 01:51:02 +0000 | [diff] [blame] | 851 | addPassToManager(MP); |
Devang Patel | 4949fe0 | 2006-12-07 22:34:21 +0000 | [diff] [blame] | 852 | // If active manager exists then clear its analysis info. |
| 853 | if (activeFunctionPassManager) { |
| 854 | activeFunctionPassManager->initializeAnalysisInfo(); |
| 855 | activeFunctionPassManager = NULL; |
| 856 | } |
| 857 | |
Devang Patel | 05e1a97 | 2006-11-07 22:03:15 +0000 | [diff] [blame] | 858 | return true; |
| 859 | } |
| 860 | |
| 861 | |
| 862 | /// Execute all of the passes scheduled for execution by invoking |
| 863 | /// runOnModule method. Keep track of whether any of the passes modifies |
| 864 | /// the module, and if so, return true. |
| 865 | bool |
| 866 | ModulePassManager_New::runOnModule(Module &M) { |
| 867 | bool Changed = false; |
Devang Patel | a6b6dcb | 2006-12-07 18:41:09 +0000 | [diff] [blame] | 868 | initializeAnalysisInfo(); |
Devang Patel | 050ec72 | 2006-11-14 01:23:29 +0000 | [diff] [blame] | 869 | |
Devang Patel | 8cad70d | 2006-11-11 01:51:02 +0000 | [diff] [blame] | 870 | for (std::vector<Pass *>::iterator itr = passVectorBegin(), |
| 871 | e = passVectorEnd(); itr != e; ++itr) { |
Devang Patel | 05e1a97 | 2006-11-07 22:03:15 +0000 | [diff] [blame] | 872 | Pass *P = *itr; |
Devang Patel | 050ec72 | 2006-11-14 01:23:29 +0000 | [diff] [blame] | 873 | |
Devang Patel | 05e1a97 | 2006-11-07 22:03:15 +0000 | [diff] [blame] | 874 | ModulePass *MP = dynamic_cast<ModulePass*>(P); |
| 875 | Changed |= MP->runOnModule(M); |
Devang Patel | 050ec72 | 2006-11-14 01:23:29 +0000 | [diff] [blame] | 876 | removeNotPreservedAnalysis(P); |
Devang Patel | 17bff0d | 2006-12-07 22:09:36 +0000 | [diff] [blame] | 877 | recordAvailableAnalysis(P); |
Devang Patel | ca18926 | 2006-11-14 03:05:08 +0000 | [diff] [blame] | 878 | removeDeadPasses(P); |
Devang Patel | 05e1a97 | 2006-11-07 22:03:15 +0000 | [diff] [blame] | 879 | } |
| 880 | return Changed; |
| 881 | } |
| 882 | |
Devang Patel | ebba970 | 2006-11-13 22:40:09 +0000 | [diff] [blame] | 883 | /// Return true IFF AnalysisID AID is currently available. |
Devang Patel | 642c143 | 2006-12-07 21:58:50 +0000 | [diff] [blame] | 884 | /// TODO : Replace this method with getAnalysisPass() |
Devang Patel | 3f0832a | 2006-11-14 02:54:23 +0000 | [diff] [blame] | 885 | Pass *ModulePassManager_New::getAnalysisPassFromManager(AnalysisID AID) { |
Devang Patel | ebba970 | 2006-11-13 22:40:09 +0000 | [diff] [blame] | 886 | |
Devang Patel | 3f0832a | 2006-11-14 02:54:23 +0000 | [diff] [blame] | 887 | Pass *P = getAnalysisPass(AID); |
| 888 | if (P) |
| 889 | return P; |
Devang Patel | ebba970 | 2006-11-13 22:40:09 +0000 | [diff] [blame] | 890 | |
| 891 | if (activeFunctionPassManager && |
Devang Patel | f60b5d9 | 2006-11-14 01:59:59 +0000 | [diff] [blame] | 892 | activeFunctionPassManager->getAnalysisPass(AID) != 0) |
Devang Patel | 3f0832a | 2006-11-14 02:54:23 +0000 | [diff] [blame] | 893 | return activeFunctionPassManager->getAnalysisPass(AID); |
Devang Patel | ebba970 | 2006-11-13 22:40:09 +0000 | [diff] [blame] | 894 | |
| 895 | // TODO : Check inactive managers |
Devang Patel | 3f0832a | 2006-11-14 02:54:23 +0000 | [diff] [blame] | 896 | return NULL; |
Devang Patel | ebba970 | 2006-11-13 22:40:09 +0000 | [diff] [blame] | 897 | } |
| 898 | |
Devang Patel | a1514cb | 2006-12-07 19:39:39 +0000 | [diff] [blame] | 899 | //===----------------------------------------------------------------------===// |
| 900 | // PassManagerImpl implementation |
| 901 | |
Devang Patel | ebba970 | 2006-11-13 22:40:09 +0000 | [diff] [blame] | 902 | /// Return true IFF AnalysisID AID is currently available. |
Devang Patel | 642c143 | 2006-12-07 21:58:50 +0000 | [diff] [blame] | 903 | /// TODO : Replace this method with getAnalysisPass() |
Devang Patel | 3f0832a | 2006-11-14 02:54:23 +0000 | [diff] [blame] | 904 | Pass *PassManagerImpl_New::getAnalysisPassFromManager(AnalysisID AID) { |
Devang Patel | ebba970 | 2006-11-13 22:40:09 +0000 | [diff] [blame] | 905 | |
Devang Patel | 3f0832a | 2006-11-14 02:54:23 +0000 | [diff] [blame] | 906 | Pass *P = NULL; |
Devang Patel | 7086844 | 2006-11-13 22:53:19 +0000 | [diff] [blame] | 907 | for (std::vector<ModulePassManager_New *>::iterator itr = PassManagers.begin(), |
Devang Patel | 3f0832a | 2006-11-14 02:54:23 +0000 | [diff] [blame] | 908 | e = PassManagers.end(); !P && itr != e; ++itr) |
| 909 | P = (*itr)->getAnalysisPassFromManager(AID); |
| 910 | return P; |
Devang Patel | ebba970 | 2006-11-13 22:40:09 +0000 | [diff] [blame] | 911 | } |
| 912 | |
Devang Patel | c290c8a | 2006-11-07 22:23:34 +0000 | [diff] [blame] | 913 | // PassManager_New implementation |
| 914 | /// Add P into active pass manager or use new module pass manager to |
| 915 | /// manage it. |
Devang Patel | 1a6eaa4 | 2006-11-11 02:22:31 +0000 | [diff] [blame] | 916 | bool PassManagerImpl_New::addPass(Pass *P) { |
Devang Patel | c290c8a | 2006-11-07 22:23:34 +0000 | [diff] [blame] | 917 | |
Devang Patel | 6c9f548 | 2006-11-11 00:42:16 +0000 | [diff] [blame] | 918 | if (!activeManager || !activeManager->addPass(P)) { |
Devang Patel | 4c36e6b | 2006-12-07 23:24:58 +0000 | [diff] [blame^] | 919 | activeManager = new ModulePassManager_New(getDepth() + 1); |
Devang Patel | c290c8a | 2006-11-07 22:23:34 +0000 | [diff] [blame] | 920 | PassManagers.push_back(activeManager); |
Devang Patel | 28bbcbe | 2006-12-07 21:44:12 +0000 | [diff] [blame] | 921 | return activeManager->addPass(P); |
Devang Patel | c290c8a | 2006-11-07 22:23:34 +0000 | [diff] [blame] | 922 | } |
Devang Patel | 28bbcbe | 2006-12-07 21:44:12 +0000 | [diff] [blame] | 923 | return true; |
Devang Patel | c290c8a | 2006-11-07 22:23:34 +0000 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | /// run - Execute all of the passes scheduled for execution. Keep track of |
| 927 | /// whether any of the passes modifies the module, and if so, return true. |
Devang Patel | 1a6eaa4 | 2006-11-11 02:22:31 +0000 | [diff] [blame] | 928 | bool PassManagerImpl_New::run(Module &M) { |
Devang Patel | c290c8a | 2006-11-07 22:23:34 +0000 | [diff] [blame] | 929 | |
Devang Patel | c290c8a | 2006-11-07 22:23:34 +0000 | [diff] [blame] | 930 | bool Changed = false; |
| 931 | for (std::vector<ModulePassManager_New *>::iterator itr = PassManagers.begin(), |
| 932 | e = PassManagers.end(); itr != e; ++itr) { |
| 933 | ModulePassManager_New *pm = *itr; |
| 934 | Changed |= pm->runOnModule(M); |
| 935 | } |
| 936 | return Changed; |
| 937 | } |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 938 | |
Devang Patel | a1514cb | 2006-12-07 19:39:39 +0000 | [diff] [blame] | 939 | //===----------------------------------------------------------------------===// |
| 940 | // PassManager implementation |
| 941 | |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 942 | /// Create new pass manager |
| 943 | PassManager_New::PassManager_New() { |
Devang Patel | 4c36e6b | 2006-12-07 23:24:58 +0000 | [diff] [blame^] | 944 | PM = new PassManagerImpl_New(0); |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | /// add - Add a pass to the queue of passes to run. This passes ownership of |
| 948 | /// the Pass to the PassManager. When the PassManager is destroyed, the pass |
| 949 | /// will be destroyed as well, so there is no need to delete the pass. This |
| 950 | /// implies that all passes MUST be allocated with 'new'. |
| 951 | void |
| 952 | PassManager_New::add(Pass *P) { |
| 953 | PM->add(P); |
| 954 | } |
| 955 | |
| 956 | /// run - Execute all of the passes scheduled for execution. Keep track of |
| 957 | /// whether any of the passes modifies the module, and if so, return true. |
| 958 | bool |
| 959 | PassManager_New::run(Module &M) { |
| 960 | return PM->run(M); |
| 961 | } |
| 962 | |