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