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 | f1567a5 | 2006-12-13 20:03:48 +0000 | [diff] [blame] | 16 | #include "llvm/Support/CommandLine.h" |
Devang Patel | b8817b9 | 2006-12-14 00:59:42 +0000 | [diff] [blame] | 17 | #include "llvm/Support/Timer.h" |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 18 | #include "llvm/Module.h" |
Devang Patel | ff631ae | 2006-11-15 01:27:05 +0000 | [diff] [blame] | 19 | #include "llvm/ModuleProvider.h" |
Bill Wendling | dfc9189 | 2006-11-28 02:09:03 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Streams.h" |
Devang Patel | b8817b9 | 2006-12-14 00:59:42 +0000 | [diff] [blame] | 21 | #include "llvm/Support/ManagedStatic.h" |
Devang Patel | a984459 | 2006-11-11 01:31:05 +0000 | [diff] [blame] | 22 | #include <vector> |
Devang Patel | f60b5d9 | 2006-11-14 01:59:59 +0000 | [diff] [blame] | 23 | #include <map> |
Devang Patel | ffca910 | 2006-12-15 19:39:30 +0000 | [diff] [blame] | 24 | |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 25 | using namespace llvm; |
Devang Patel | ffca910 | 2006-12-15 19:39:30 +0000 | [diff] [blame] | 26 | class llvm::PMDataManager; |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 27 | |
Devang Patel | 6fea285 | 2006-12-07 18:23:30 +0000 | [diff] [blame] | 28 | //===----------------------------------------------------------------------===// |
| 29 | // Overview: |
| 30 | // The Pass Manager Infrastructure manages passes. It's responsibilities are: |
| 31 | // |
| 32 | // o Manage optimization pass execution order |
| 33 | // o Make required Analysis information available before pass P is run |
| 34 | // o Release memory occupied by dead passes |
| 35 | // o If Analysis information is dirtied by a pass then regenerate Analysis |
| 36 | // information before it is consumed by another pass. |
| 37 | // |
Chris Lattner | ce22ca3 | 2006-12-14 18:22:14 +0000 | [diff] [blame] | 38 | // Pass Manager Infrastructure uses multiple pass managers. They are |
| 39 | // PassManager, FunctionPassManager, ModulePassManager, BasicBlockPassManager. |
| 40 | // This class hierarcy uses multiple inheritance but pass managers do not derive |
| 41 | // from another pass manager. |
Devang Patel | 6fea285 | 2006-12-07 18:23:30 +0000 | [diff] [blame] | 42 | // |
Chris Lattner | ce22ca3 | 2006-12-14 18:22:14 +0000 | [diff] [blame] | 43 | // PassManager and FunctionPassManager are two top-level pass manager that |
Devang Patel | 6fea285 | 2006-12-07 18:23:30 +0000 | [diff] [blame] | 44 | // represents the external interface of this entire pass manager infrastucture. |
| 45 | // |
| 46 | // Important classes : |
| 47 | // |
| 48 | // [o] class PMTopLevelManager; |
| 49 | // |
| 50 | // Two top level managers, PassManager and FunctionPassManager, derive from |
| 51 | // PMTopLevelManager. PMTopLevelManager manages information used by top level |
| 52 | // managers such as last user info. |
| 53 | // |
| 54 | // [o] class PMDataManager; |
| 55 | // |
| 56 | // PMDataManager manages information, e.g. list of available analysis info, |
| 57 | // used by a pass manager to manage execution order of passes. It also provides |
| 58 | // a place to implement common pass manager APIs. All pass managers derive from |
| 59 | // PMDataManager. |
| 60 | // |
| 61 | // [o] class BasicBlockPassManager : public FunctionPass, public PMDataManager; |
| 62 | // |
| 63 | // BasicBlockPassManager manages BasicBlockPasses. |
| 64 | // |
| 65 | // [o] class FunctionPassManager; |
| 66 | // |
| 67 | // This is a external interface used by JIT to manage FunctionPasses. This |
| 68 | // interface relies on FunctionPassManagerImpl to do all the tasks. |
| 69 | // |
| 70 | // [o] class FunctionPassManagerImpl : public ModulePass, PMDataManager, |
| 71 | // public PMTopLevelManager; |
| 72 | // |
| 73 | // FunctionPassManagerImpl is a top level manager. It manages FunctionPasses |
| 74 | // and BasicBlockPassManagers. |
| 75 | // |
| 76 | // [o] class ModulePassManager : public Pass, public PMDataManager; |
| 77 | // |
| 78 | // ModulePassManager manages ModulePasses and FunctionPassManagerImpls. |
| 79 | // |
| 80 | // [o] class PassManager; |
| 81 | // |
| 82 | // This is a external interface used by various tools to manages passes. It |
| 83 | // relies on PassManagerImpl to do all the tasks. |
| 84 | // |
| 85 | // [o] class PassManagerImpl : public Pass, public PMDataManager, |
| 86 | // public PMDTopLevelManager |
| 87 | // |
| 88 | // PassManagerImpl is a top level pass manager responsible for managing |
| 89 | // ModulePassManagers. |
| 90 | //===----------------------------------------------------------------------===// |
| 91 | |
Devang Patel | f1567a5 | 2006-12-13 20:03:48 +0000 | [diff] [blame] | 92 | namespace llvm { |
| 93 | |
| 94 | //===----------------------------------------------------------------------===// |
| 95 | // Pass debugging information. Often it is useful to find out what pass is |
| 96 | // running when a crash occurs in a utility. When this library is compiled with |
| 97 | // debugging on, a command line option (--debug-pass) is enabled that causes the |
| 98 | // pass name to be printed before it executes. |
| 99 | // |
| 100 | |
Devang Patel | 03fb587 | 2006-12-13 21:13:31 +0000 | [diff] [blame] | 101 | // Different debug levels that can be enabled... |
| 102 | enum PassDebugLevel { |
| 103 | None, Arguments, Structure, Executions, Details |
| 104 | }; |
| 105 | |
Devang Patel | f1567a5 | 2006-12-13 20:03:48 +0000 | [diff] [blame] | 106 | static cl::opt<enum PassDebugLevel> |
| 107 | PassDebugging_New("debug-pass", cl::Hidden, |
| 108 | cl::desc("Print PassManager debugging information"), |
| 109 | cl::values( |
Devang Patel | 03fb587 | 2006-12-13 21:13:31 +0000 | [diff] [blame] | 110 | clEnumVal(None , "disable debug output"), |
| 111 | clEnumVal(Arguments , "print pass arguments to pass to 'opt'"), |
| 112 | clEnumVal(Structure , "print pass structure before run()"), |
| 113 | clEnumVal(Executions, "print pass name before it is executed"), |
| 114 | clEnumVal(Details , "print pass details when it is executed"), |
Devang Patel | f1567a5 | 2006-12-13 20:03:48 +0000 | [diff] [blame] | 115 | clEnumValEnd)); |
| 116 | } // End of llvm namespace |
| 117 | |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 118 | #ifndef USE_OLD_PASSMANAGER |
Devang Patel | ffca910 | 2006-12-15 19:39:30 +0000 | [diff] [blame] | 119 | namespace { |
Devang Patel | afb1f362 | 2006-12-12 22:35:25 +0000 | [diff] [blame] | 120 | |
Devang Patel | f33f3eb | 2006-12-07 19:21:29 +0000 | [diff] [blame] | 121 | //===----------------------------------------------------------------------===// |
| 122 | // PMTopLevelManager |
| 123 | // |
| 124 | /// PMTopLevelManager manages LastUser info and collects common APIs used by |
| 125 | /// top level pass managers. |
Devang Patel | ffca910 | 2006-12-15 19:39:30 +0000 | [diff] [blame] | 126 | class VISIBILITY_HIDDEN PMTopLevelManager { |
Devang Patel | f33f3eb | 2006-12-07 19:21:29 +0000 | [diff] [blame] | 127 | public: |
| 128 | |
| 129 | inline std::vector<Pass *>::iterator passManagersBegin() { |
| 130 | return PassManagers.begin(); |
| 131 | } |
| 132 | |
| 133 | inline std::vector<Pass *>::iterator passManagersEnd() { |
| 134 | return PassManagers.end(); |
| 135 | } |
| 136 | |
| 137 | /// Schedule pass P for execution. Make sure that passes required by |
| 138 | /// P are run before P is run. Update analysis info maintained by |
| 139 | /// the manager. Remove dead passes. This is a recursive function. |
Devang Patel | df6c9ae | 2006-12-08 22:34:02 +0000 | [diff] [blame] | 140 | void schedulePass(Pass *P); |
Devang Patel | f33f3eb | 2006-12-07 19:21:29 +0000 | [diff] [blame] | 141 | |
| 142 | /// This is implemented by top level pass manager and used by |
| 143 | /// schedulePass() to add analysis info passes that are not available. |
| 144 | virtual void addTopLevelPass(Pass *P) = 0; |
| 145 | |
| 146 | /// Set pass P as the last user of the given analysis passes. |
| 147 | void setLastUser(std::vector<Pass *> &AnalysisPasses, Pass *P); |
| 148 | |
| 149 | /// Collect passes whose last user is P |
| 150 | void collectLastUses(std::vector<Pass *> &LastUses, Pass *P); |
| 151 | |
Devang Patel | 640c5bb | 2006-12-08 22:30:11 +0000 | [diff] [blame] | 152 | /// Find the pass that implements Analysis AID. Search immutable |
| 153 | /// passes and all pass managers. If desired pass is not found |
| 154 | /// then return NULL. |
| 155 | Pass *findAnalysisPass(AnalysisID AID); |
| 156 | |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 157 | inline void clearManagers() { |
| 158 | PassManagers.clear(); |
| 159 | } |
| 160 | |
Devang Patel | f33f3eb | 2006-12-07 19:21:29 +0000 | [diff] [blame] | 161 | virtual ~PMTopLevelManager() { |
Devang Patel | ab97cf4 | 2006-12-13 00:09:23 +0000 | [diff] [blame] | 162 | for (std::vector<Pass *>::iterator I = PassManagers.begin(), |
| 163 | E = PassManagers.end(); I != E; ++I) |
| 164 | delete *I; |
| 165 | |
| 166 | for (std::vector<ImmutablePass *>::iterator |
| 167 | I = ImmutablePasses.begin(), E = ImmutablePasses.end(); I != E; ++I) |
| 168 | delete *I; |
| 169 | |
Devang Patel | f33f3eb | 2006-12-07 19:21:29 +0000 | [diff] [blame] | 170 | PassManagers.clear(); |
| 171 | } |
| 172 | |
Devang Patel | e0eb9d8 | 2006-12-07 20:51:18 +0000 | [diff] [blame] | 173 | /// Add immutable pass and initialize it. |
| 174 | inline void addImmutablePass(ImmutablePass *P) { |
| 175 | P->initializePass(); |
| 176 | ImmutablePasses.push_back(P); |
| 177 | } |
| 178 | |
| 179 | inline std::vector<ImmutablePass *>& getImmutablePasses() { |
| 180 | return ImmutablePasses; |
| 181 | } |
| 182 | |
Devang Patel | 5bbeb49 | 2006-12-08 22:47:25 +0000 | [diff] [blame] | 183 | void addPassManager(Pass *Manager) { |
| 184 | PassManagers.push_back(Manager); |
| 185 | } |
| 186 | |
Devang Patel | af1fca5 | 2006-12-08 23:11:43 +0000 | [diff] [blame] | 187 | // Add Manager into the list of managers that are not directly |
| 188 | // maintained by this top level pass manager |
Devang Patel | afb1f362 | 2006-12-12 22:35:25 +0000 | [diff] [blame] | 189 | inline void addIndirectPassManager(PMDataManager *Manager) { |
| 190 | IndirectPassManagers.push_back(Manager); |
Devang Patel | af1fca5 | 2006-12-08 23:11:43 +0000 | [diff] [blame] | 191 | } |
| 192 | |
Devang Patel | eda5617 | 2006-12-12 23:34:33 +0000 | [diff] [blame] | 193 | // Print passes managed by this top level manager. |
Devang Patel | 991aeba | 2006-12-15 20:13:01 +0000 | [diff] [blame] | 194 | void dumpPasses() const; |
| 195 | void dumpArguments() const; |
Devang Patel | eda5617 | 2006-12-12 23:34:33 +0000 | [diff] [blame] | 196 | |
Devang Patel | f33f3eb | 2006-12-07 19:21:29 +0000 | [diff] [blame] | 197 | private: |
| 198 | |
| 199 | /// Collection of pass managers |
| 200 | std::vector<Pass *> PassManagers; |
| 201 | |
Devang Patel | af1fca5 | 2006-12-08 23:11:43 +0000 | [diff] [blame] | 202 | /// Collection of pass managers that are not directly maintained |
| 203 | /// by this pass manager |
Devang Patel | afb1f362 | 2006-12-12 22:35:25 +0000 | [diff] [blame] | 204 | std::vector<PMDataManager *> IndirectPassManagers; |
Devang Patel | af1fca5 | 2006-12-08 23:11:43 +0000 | [diff] [blame] | 205 | |
Devang Patel | f33f3eb | 2006-12-07 19:21:29 +0000 | [diff] [blame] | 206 | // Map to keep track of last user of the analysis pass. |
| 207 | // LastUser->second is the last user of Lastuser->first. |
| 208 | std::map<Pass *, Pass *> LastUser; |
Devang Patel | e0eb9d8 | 2006-12-07 20:51:18 +0000 | [diff] [blame] | 209 | |
| 210 | /// Immutable passes are managed by top level manager. |
| 211 | std::vector<ImmutablePass *> ImmutablePasses; |
Devang Patel | f33f3eb | 2006-12-07 19:21:29 +0000 | [diff] [blame] | 212 | }; |
Devang Patel | ffca910 | 2006-12-15 19:39:30 +0000 | [diff] [blame] | 213 | |
| 214 | } // End of anon namespace |
Devang Patel | f33f3eb | 2006-12-07 19:21:29 +0000 | [diff] [blame] | 215 | |
Devang Patel | f3827bc | 2006-12-07 19:54:15 +0000 | [diff] [blame] | 216 | //===----------------------------------------------------------------------===// |
| 217 | // PMDataManager |
Devang Patel | f33f3eb | 2006-12-07 19:21:29 +0000 | [diff] [blame] | 218 | |
Devang Patel | ffca910 | 2006-12-15 19:39:30 +0000 | [diff] [blame] | 219 | namespace llvm { |
Devang Patel | dbe4a1e | 2006-12-07 18:36:24 +0000 | [diff] [blame] | 220 | /// PMDataManager provides the common place to manage the analysis data |
| 221 | /// used by pass managers. |
| 222 | class PMDataManager { |
Devang Patel | a984459 | 2006-11-11 01:31:05 +0000 | [diff] [blame] | 223 | public: |
Devang Patel | 56d48ec | 2006-12-15 22:57:49 +0000 | [diff] [blame^] | 224 | PMDataManager(int Depth) : TPM(NULL), Depth(Depth) { |
Devang Patel | f3827bc | 2006-12-07 19:54:15 +0000 | [diff] [blame] | 225 | initializeAnalysisInfo(); |
| 226 | } |
| 227 | |
Devang Patel | ab97cf4 | 2006-12-13 00:09:23 +0000 | [diff] [blame] | 228 | virtual ~PMDataManager() { |
| 229 | |
| 230 | for (std::vector<Pass *>::iterator I = PassVector.begin(), |
| 231 | E = PassVector.end(); I != E; ++I) |
| 232 | delete *I; |
| 233 | |
| 234 | PassVector.clear(); |
| 235 | } |
| 236 | |
Devang Patel | a984459 | 2006-11-11 01:31:05 +0000 | [diff] [blame] | 237 | /// Return true IFF pass P's required analysis set does not required new |
| 238 | /// manager. |
| 239 | bool manageablePass(Pass *P); |
| 240 | |
Devang Patel | a984459 | 2006-11-11 01:31:05 +0000 | [diff] [blame] | 241 | /// Augment AvailableAnalysis by adding analysis made available by pass P. |
Devang Patel | e9976aa | 2006-12-07 19:33:53 +0000 | [diff] [blame] | 242 | void recordAvailableAnalysis(Pass *P); |
Devang Patel | a984459 | 2006-11-11 01:31:05 +0000 | [diff] [blame] | 243 | |
Devang Patel | a984459 | 2006-11-11 01:31:05 +0000 | [diff] [blame] | 244 | /// Remove Analysis that is not preserved by the pass |
| 245 | void removeNotPreservedAnalysis(Pass *P); |
| 246 | |
| 247 | /// Remove dead passes |
Devang Patel | 200d305 | 2006-12-13 23:50:44 +0000 | [diff] [blame] | 248 | void removeDeadPasses(Pass *P, std::string &Msg); |
Devang Patel | a984459 | 2006-11-11 01:31:05 +0000 | [diff] [blame] | 249 | |
Devang Patel | 8f677ce | 2006-12-07 18:47:25 +0000 | [diff] [blame] | 250 | /// Add pass P into the PassVector. Update |
Devang Patel | 90b05e0 | 2006-11-11 02:04:19 +0000 | [diff] [blame] | 251 | /// AvailableAnalysis appropriately if ProcessAnalysis is true. |
Chris Lattner | ce22ca3 | 2006-12-14 18:22:14 +0000 | [diff] [blame] | 252 | void addPassToManager(Pass *P, bool ProcessAnalysis = true); |
Devang Patel | 8cad70d | 2006-11-11 01:51:02 +0000 | [diff] [blame] | 253 | |
Devang Patel | 1d6267c | 2006-12-07 23:05:44 +0000 | [diff] [blame] | 254 | /// Initialize available analysis information. |
Devang Patel | a6b6dcb | 2006-12-07 18:41:09 +0000 | [diff] [blame] | 255 | void initializeAnalysisInfo() { |
Devang Patel | 832bc07 | 2006-12-15 00:08:26 +0000 | [diff] [blame] | 256 | TransferLastUses.clear(); |
Devang Patel | 050ec72 | 2006-11-14 01:23:29 +0000 | [diff] [blame] | 257 | AvailableAnalysis.clear(); |
| 258 | } |
| 259 | |
Devang Patel | 1d6267c | 2006-12-07 23:05:44 +0000 | [diff] [blame] | 260 | /// Populate RequiredPasses with the analysis pass that are required by |
| 261 | /// pass P. |
| 262 | void collectRequiredAnalysisPasses(std::vector<Pass *> &RequiredPasses, |
| 263 | Pass *P); |
| 264 | |
| 265 | /// All Required analyses should be available to the pass as it runs! Here |
| 266 | /// we fill in the AnalysisImpls member of the pass so that it can |
| 267 | /// successfully use the getAnalysis() method to retrieve the |
| 268 | /// implementations it needs. |
| 269 | void initializeAnalysisImpl(Pass *P); |
Devang Patel | f60b5d9 | 2006-11-14 01:59:59 +0000 | [diff] [blame] | 270 | |
Devang Patel | 640c5bb | 2006-12-08 22:30:11 +0000 | [diff] [blame] | 271 | /// Find the pass that implements Analysis AID. If desired pass is not found |
| 272 | /// then return NULL. |
| 273 | Pass *findAnalysisPass(AnalysisID AID, bool Direction); |
| 274 | |
Devang Patel | 8cad70d | 2006-11-11 01:51:02 +0000 | [diff] [blame] | 275 | inline std::vector<Pass *>::iterator passVectorBegin() { |
| 276 | return PassVector.begin(); |
| 277 | } |
| 278 | |
| 279 | inline std::vector<Pass *>::iterator passVectorEnd() { |
| 280 | return PassVector.end(); |
| 281 | } |
| 282 | |
Devang Patel | f3827bc | 2006-12-07 19:54:15 +0000 | [diff] [blame] | 283 | // Access toplevel manager |
| 284 | PMTopLevelManager *getTopLevelManager() { return TPM; } |
| 285 | void setTopLevelManager(PMTopLevelManager *T) { TPM = T; } |
| 286 | |
Devang Patel | 991aeba | 2006-12-15 20:13:01 +0000 | [diff] [blame] | 287 | unsigned getDepth() const { return Depth; } |
Devang Patel | 4c36e6b | 2006-12-07 23:24:58 +0000 | [diff] [blame] | 288 | |
Devang Patel | 991aeba | 2006-12-15 20:13:01 +0000 | [diff] [blame] | 289 | // Print routines used by debug-pass |
| 290 | void dumpLastUses(Pass *P, unsigned Offset) const; |
| 291 | void dumpPassArguments() const; |
| 292 | void dumpPassInfo(Pass *P, std::string &Msg1, std::string &Msg2) const; |
Devang Patel | f6d1d21 | 2006-12-14 00:25:06 +0000 | [diff] [blame] | 293 | void dumpAnalysisSetInfo(const char *Msg, Pass *P, |
Devang Patel | 991aeba | 2006-12-15 20:13:01 +0000 | [diff] [blame] | 294 | const std::vector<AnalysisID> &Set) const; |
Devang Patel | 832bc07 | 2006-12-15 00:08:26 +0000 | [diff] [blame] | 295 | |
| 296 | std::vector<Pass *>& getTransferredLastUses() { |
| 297 | return TransferLastUses; |
| 298 | } |
| 299 | |
Devang Patel | bc03f13 | 2006-12-07 23:55:10 +0000 | [diff] [blame] | 300 | protected: |
| 301 | |
Devang Patel | 832bc07 | 2006-12-15 00:08:26 +0000 | [diff] [blame] | 302 | // If a FunctionPass F is the last user of ModulePass info M |
Devang Patel | bc03f13 | 2006-12-07 23:55:10 +0000 | [diff] [blame] | 303 | // then the F's manager, not F, records itself as a last user of M. |
Devang Patel | 832bc07 | 2006-12-15 00:08:26 +0000 | [diff] [blame] | 304 | // Current pass manage is requesting parent manager to record parent |
| 305 | // manager as the last user of these TrransferLastUses passes. |
| 306 | std::vector<Pass *> TransferLastUses; |
Devang Patel | bc03f13 | 2006-12-07 23:55:10 +0000 | [diff] [blame] | 307 | |
| 308 | // Top level manager. |
Devang Patel | bc03f13 | 2006-12-07 23:55:10 +0000 | [diff] [blame] | 309 | PMTopLevelManager *TPM; |
| 310 | |
Devang Patel | a984459 | 2006-11-11 01:31:05 +0000 | [diff] [blame] | 311 | private: |
Devang Patel | dafa4dd | 2006-11-14 00:03:04 +0000 | [diff] [blame] | 312 | // Set of available Analysis. This information is used while scheduling |
| 313 | // pass. If a pass requires an analysis which is not not available then |
| 314 | // equired analysis pass is scheduled to run before the pass itself is |
| 315 | // scheduled to run. |
Devang Patel | f60b5d9 | 2006-11-14 01:59:59 +0000 | [diff] [blame] | 316 | std::map<AnalysisID, Pass*> AvailableAnalysis; |
Devang Patel | 8cad70d | 2006-11-11 01:51:02 +0000 | [diff] [blame] | 317 | |
| 318 | // Collection of pass that are managed by this manager |
| 319 | std::vector<Pass *> PassVector; |
Devang Patel | f3827bc | 2006-12-07 19:54:15 +0000 | [diff] [blame] | 320 | |
Devang Patel | 4c36e6b | 2006-12-07 23:24:58 +0000 | [diff] [blame] | 321 | unsigned Depth; |
Devang Patel | a984459 | 2006-11-11 01:31:05 +0000 | [diff] [blame] | 322 | }; |
| 323 | |
Devang Patel | 10c2ca6 | 2006-12-12 22:47:13 +0000 | [diff] [blame] | 324 | //===----------------------------------------------------------------------===// |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 325 | // BasicBlockPassManager |
Devang Patel | 10c2ca6 | 2006-12-12 22:47:13 +0000 | [diff] [blame] | 326 | // |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 327 | /// BasicBlockPassManager manages BasicBlockPass. It batches all the |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 328 | /// pass together and sequence them to process one basic block before |
| 329 | /// processing next basic block. |
Devang Patel | ffca910 | 2006-12-15 19:39:30 +0000 | [diff] [blame] | 330 | class VISIBILITY_HIDDEN BasicBlockPassManager : public PMDataManager, |
Chris Lattner | ce22ca3 | 2006-12-14 18:22:14 +0000 | [diff] [blame] | 331 | public FunctionPass { |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 332 | |
| 333 | public: |
Devang Patel | 56d48ec | 2006-12-15 22:57:49 +0000 | [diff] [blame^] | 334 | BasicBlockPassManager(int Depth) : PMDataManager(Depth) { } |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 335 | |
| 336 | /// Add a pass into a passmanager queue. |
| 337 | bool addPass(Pass *p); |
| 338 | |
| 339 | /// Execute all of the passes scheduled for execution. Keep track of |
| 340 | /// whether any of the passes modifies the function, and if so, return true. |
| 341 | bool runOnFunction(Function &F); |
| 342 | |
Devang Patel | f9d96b9 | 2006-12-07 19:57:52 +0000 | [diff] [blame] | 343 | /// Pass Manager itself does not invalidate any analysis info. |
| 344 | void getAnalysisUsage(AnalysisUsage &Info) const { |
| 345 | Info.setPreservesAll(); |
| 346 | } |
| 347 | |
Devang Patel | 475c453 | 2006-12-08 00:59:05 +0000 | [diff] [blame] | 348 | bool doInitialization(Module &M); |
| 349 | bool doInitialization(Function &F); |
| 350 | bool doFinalization(Module &M); |
| 351 | bool doFinalization(Function &F); |
| 352 | |
Devang Patel | eda5617 | 2006-12-12 23:34:33 +0000 | [diff] [blame] | 353 | // Print passes managed by this manager |
| 354 | void dumpPassStructure(unsigned Offset) { |
Devang Patel | ffca910 | 2006-12-15 19:39:30 +0000 | [diff] [blame] | 355 | llvm::cerr << std::string(Offset*2, ' ') << "BasicBlockPass Manager\n"; |
Devang Patel | eda5617 | 2006-12-12 23:34:33 +0000 | [diff] [blame] | 356 | for (std::vector<Pass *>::iterator I = passVectorBegin(), |
| 357 | E = passVectorEnd(); I != E; ++I) { |
| 358 | (*I)->dumpPassStructure(Offset + 1); |
| 359 | dumpLastUses(*I, Offset+1); |
| 360 | } |
| 361 | } |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 362 | }; |
| 363 | |
Devang Patel | 10c2ca6 | 2006-12-12 22:47:13 +0000 | [diff] [blame] | 364 | //===----------------------------------------------------------------------===// |
| 365 | // FunctionPassManagerImpl_New |
| 366 | // |
Chris Lattner | f0f611a | 2006-12-13 21:56:10 +0000 | [diff] [blame] | 367 | /// FunctionPassManagerImpl_New manages FunctionPasses and |
| 368 | /// BasicBlockPassManagers. It batches all function passes and basic block pass |
| 369 | /// managers together and sequence them to process one function at a time before |
| 370 | /// processing next function. |
Devang Patel | abcd1d3 | 2006-12-07 21:27:23 +0000 | [diff] [blame] | 371 | class FunctionPassManagerImpl_New : public ModulePass, |
| 372 | public PMDataManager, |
| 373 | public PMTopLevelManager { |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 374 | public: |
Devang Patel | 56d48ec | 2006-12-15 22:57:49 +0000 | [diff] [blame^] | 375 | FunctionPassManagerImpl_New(int Depth) : PMDataManager(Depth) { |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 376 | activeBBPassManager = NULL; |
| 377 | } |
Devang Patel | 4e12f86 | 2006-11-08 10:44:40 +0000 | [diff] [blame] | 378 | ~FunctionPassManagerImpl_New() { /* TODO */ }; |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 379 | |
Devang Patel | abcd1d3 | 2006-12-07 21:27:23 +0000 | [diff] [blame] | 380 | inline void addTopLevelPass(Pass *P) { |
Devang Patel | d440cd9 | 2006-12-08 23:53:00 +0000 | [diff] [blame] | 381 | |
Devang Patel | fa971cd | 2006-12-08 23:57:43 +0000 | [diff] [blame] | 382 | if (ImmutablePass *IP = dynamic_cast<ImmutablePass *> (P)) { |
Devang Patel | d440cd9 | 2006-12-08 23:53:00 +0000 | [diff] [blame] | 383 | |
| 384 | // P is a immutable pass then it will be managed by this |
| 385 | // top level manager. Set up analysis resolver to connect them. |
| 386 | AnalysisResolver_New *AR = new AnalysisResolver_New(*this); |
| 387 | P->setResolver(AR); |
Devang Patel | 9525754 | 2006-12-12 22:21:37 +0000 | [diff] [blame] | 388 | initializeAnalysisImpl(P); |
Devang Patel | fa971cd | 2006-12-08 23:57:43 +0000 | [diff] [blame] | 389 | addImmutablePass(IP); |
Devang Patel | 9525754 | 2006-12-12 22:21:37 +0000 | [diff] [blame] | 390 | recordAvailableAnalysis(IP); |
Devang Patel | fa971cd | 2006-12-08 23:57:43 +0000 | [diff] [blame] | 391 | } |
| 392 | else |
| 393 | addPass(P); |
Devang Patel | abcd1d3 | 2006-12-07 21:27:23 +0000 | [diff] [blame] | 394 | } |
| 395 | |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 396 | /// add - Add a pass to the queue of passes to run. This passes |
| 397 | /// ownership of the Pass to the PassManager. When the |
| 398 | /// PassManager_X is destroyed, the pass will be destroyed as well, so |
| 399 | /// there is no need to delete the pass. (TODO delete passes.) |
| 400 | /// This implies that all passes MUST be allocated with 'new'. |
Devang Patel | 31217af | 2006-12-07 21:32:57 +0000 | [diff] [blame] | 401 | void add(Pass *P) { |
Devang Patel | df6c9ae | 2006-12-08 22:34:02 +0000 | [diff] [blame] | 402 | schedulePass(P); |
Devang Patel | 31217af | 2006-12-07 21:32:57 +0000 | [diff] [blame] | 403 | } |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 404 | |
| 405 | /// Add pass into the pass manager queue. |
| 406 | bool addPass(Pass *P); |
| 407 | |
| 408 | /// Execute all of the passes scheduled for execution. Keep |
| 409 | /// track of whether any of the passes modifies the function, and if |
| 410 | /// so, return true. |
| 411 | bool runOnModule(Module &M); |
Devang Patel | 9f3083e | 2006-11-15 19:39:54 +0000 | [diff] [blame] | 412 | bool runOnFunction(Function &F); |
Devang Patel | 272908d | 2006-12-08 22:57:48 +0000 | [diff] [blame] | 413 | bool run(Function &F); |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 414 | |
Devang Patel | ff631ae | 2006-11-15 01:27:05 +0000 | [diff] [blame] | 415 | /// doInitialization - Run all of the initializers for the function passes. |
| 416 | /// |
| 417 | bool doInitialization(Module &M); |
| 418 | |
| 419 | /// doFinalization - Run all of the initializers for the function passes. |
| 420 | /// |
| 421 | bool doFinalization(Module &M); |
Devang Patel | f9d96b9 | 2006-12-07 19:57:52 +0000 | [diff] [blame] | 422 | |
| 423 | /// Pass Manager itself does not invalidate any analysis info. |
| 424 | void getAnalysisUsage(AnalysisUsage &Info) const { |
| 425 | Info.setPreservesAll(); |
| 426 | } |
| 427 | |
Devang Patel | eda5617 | 2006-12-12 23:34:33 +0000 | [diff] [blame] | 428 | // Print passes managed by this manager |
| 429 | void dumpPassStructure(unsigned Offset) { |
| 430 | llvm::cerr << std::string(Offset*2, ' ') << "FunctionPass Manager\n"; |
| 431 | for (std::vector<Pass *>::iterator I = passVectorBegin(), |
| 432 | E = passVectorEnd(); I != E; ++I) { |
| 433 | (*I)->dumpPassStructure(Offset + 1); |
| 434 | dumpLastUses(*I, Offset+1); |
| 435 | } |
| 436 | } |
| 437 | |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 438 | private: |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 439 | // Active Pass Managers |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 440 | BasicBlockPassManager *activeBBPassManager; |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 441 | }; |
| 442 | |
Devang Patel | 10c2ca6 | 2006-12-12 22:47:13 +0000 | [diff] [blame] | 443 | //===----------------------------------------------------------------------===// |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 444 | // ModulePassManager |
Devang Patel | 10c2ca6 | 2006-12-12 22:47:13 +0000 | [diff] [blame] | 445 | // |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 446 | /// ModulePassManager manages ModulePasses and function pass managers. |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 447 | /// It batches all Module passes passes and function pass managers together and |
| 448 | /// sequence them to process one module. |
Chris Lattner | ce22ca3 | 2006-12-14 18:22:14 +0000 | [diff] [blame] | 449 | class ModulePassManager : public Pass, public PMDataManager { |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 450 | |
| 451 | public: |
Devang Patel | 56d48ec | 2006-12-15 22:57:49 +0000 | [diff] [blame^] | 452 | ModulePassManager(int Depth) : PMDataManager(Depth) { |
Devang Patel | 4c36e6b | 2006-12-07 23:24:58 +0000 | [diff] [blame] | 453 | activeFunctionPassManager = NULL; |
| 454 | } |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 455 | |
| 456 | /// Add a pass into a passmanager queue. |
| 457 | bool addPass(Pass *p); |
| 458 | |
| 459 | /// run - Execute all of the passes scheduled for execution. Keep track of |
| 460 | /// whether any of the passes modifies the module, and if so, return true. |
| 461 | bool runOnModule(Module &M); |
Devang Patel | ebba970 | 2006-11-13 22:40:09 +0000 | [diff] [blame] | 462 | |
Devang Patel | f9d96b9 | 2006-12-07 19:57:52 +0000 | [diff] [blame] | 463 | /// Pass Manager itself does not invalidate any analysis info. |
| 464 | void getAnalysisUsage(AnalysisUsage &Info) const { |
| 465 | Info.setPreservesAll(); |
| 466 | } |
| 467 | |
Devang Patel | eda5617 | 2006-12-12 23:34:33 +0000 | [diff] [blame] | 468 | // Print passes managed by this manager |
| 469 | void dumpPassStructure(unsigned Offset) { |
| 470 | llvm::cerr << std::string(Offset*2, ' ') << "ModulePass Manager\n"; |
| 471 | for (std::vector<Pass *>::iterator I = passVectorBegin(), |
| 472 | E = passVectorEnd(); I != E; ++I) { |
| 473 | (*I)->dumpPassStructure(Offset + 1); |
| 474 | dumpLastUses(*I, Offset+1); |
| 475 | } |
| 476 | } |
| 477 | |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 478 | private: |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 479 | // Active Pass Manager |
Devang Patel | 4e12f86 | 2006-11-08 10:44:40 +0000 | [diff] [blame] | 480 | FunctionPassManagerImpl_New *activeFunctionPassManager; |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 481 | }; |
| 482 | |
Devang Patel | 10c2ca6 | 2006-12-12 22:47:13 +0000 | [diff] [blame] | 483 | //===----------------------------------------------------------------------===// |
| 484 | // PassManagerImpl_New |
| 485 | // |
| 486 | /// PassManagerImpl_New manages ModulePassManagers |
Devang Patel | 31217af | 2006-12-07 21:32:57 +0000 | [diff] [blame] | 487 | class PassManagerImpl_New : public Pass, |
| 488 | public PMDataManager, |
Devang Patel | abcd1d3 | 2006-12-07 21:27:23 +0000 | [diff] [blame] | 489 | public PMTopLevelManager { |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 490 | |
| 491 | public: |
| 492 | |
Devang Patel | 56d48ec | 2006-12-15 22:57:49 +0000 | [diff] [blame^] | 493 | PassManagerImpl_New(int Depth) : PMDataManager(Depth) { |
Devang Patel | ad6b7fe | 2006-12-12 22:57:43 +0000 | [diff] [blame] | 494 | activeManager = NULL; |
| 495 | } |
Devang Patel | 4c36e6b | 2006-12-07 23:24:58 +0000 | [diff] [blame] | 496 | |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 497 | /// add - Add a pass to the queue of passes to run. This passes ownership of |
| 498 | /// the Pass to the PassManager. When the PassManager is destroyed, the pass |
| 499 | /// will be destroyed as well, so there is no need to delete the pass. This |
| 500 | /// implies that all passes MUST be allocated with 'new'. |
Devang Patel | 31217af | 2006-12-07 21:32:57 +0000 | [diff] [blame] | 501 | void add(Pass *P) { |
Devang Patel | df6c9ae | 2006-12-08 22:34:02 +0000 | [diff] [blame] | 502 | schedulePass(P); |
Devang Patel | 31217af | 2006-12-07 21:32:57 +0000 | [diff] [blame] | 503 | } |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 504 | |
| 505 | /// run - Execute all of the passes scheduled for execution. Keep track of |
| 506 | /// whether any of the passes modifies the module, and if so, return true. |
| 507 | bool run(Module &M); |
| 508 | |
Devang Patel | f9d96b9 | 2006-12-07 19:57:52 +0000 | [diff] [blame] | 509 | /// Pass Manager itself does not invalidate any analysis info. |
| 510 | void getAnalysisUsage(AnalysisUsage &Info) const { |
| 511 | Info.setPreservesAll(); |
| 512 | } |
| 513 | |
Devang Patel | abcd1d3 | 2006-12-07 21:27:23 +0000 | [diff] [blame] | 514 | inline void addTopLevelPass(Pass *P) { |
Devang Patel | d440cd9 | 2006-12-08 23:53:00 +0000 | [diff] [blame] | 515 | |
Devang Patel | fa971cd | 2006-12-08 23:57:43 +0000 | [diff] [blame] | 516 | if (ImmutablePass *IP = dynamic_cast<ImmutablePass *> (P)) { |
Devang Patel | d440cd9 | 2006-12-08 23:53:00 +0000 | [diff] [blame] | 517 | |
| 518 | // P is a immutable pass and it will be managed by this |
| 519 | // top level manager. Set up analysis resolver to connect them. |
| 520 | AnalysisResolver_New *AR = new AnalysisResolver_New(*this); |
| 521 | P->setResolver(AR); |
Devang Patel | 9525754 | 2006-12-12 22:21:37 +0000 | [diff] [blame] | 522 | initializeAnalysisImpl(P); |
Devang Patel | fa971cd | 2006-12-08 23:57:43 +0000 | [diff] [blame] | 523 | addImmutablePass(IP); |
Devang Patel | 9525754 | 2006-12-12 22:21:37 +0000 | [diff] [blame] | 524 | recordAvailableAnalysis(IP); |
Devang Patel | d440cd9 | 2006-12-08 23:53:00 +0000 | [diff] [blame] | 525 | } |
Devang Patel | fa971cd | 2006-12-08 23:57:43 +0000 | [diff] [blame] | 526 | else |
| 527 | addPass(P); |
Devang Patel | abcd1d3 | 2006-12-07 21:27:23 +0000 | [diff] [blame] | 528 | } |
| 529 | |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 530 | private: |
| 531 | |
Devang Patel | de12418 | 2006-12-07 21:10:57 +0000 | [diff] [blame] | 532 | /// Add a pass into a passmanager queue. |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 533 | bool addPass(Pass *p); |
| 534 | |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 535 | // Active Pass Manager |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 536 | ModulePassManager *activeManager; |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 537 | }; |
| 538 | |
Devang Patel | ffca910 | 2006-12-15 19:39:30 +0000 | [diff] [blame] | 539 | } // End of llvm namespace |
| 540 | |
| 541 | namespace { |
| 542 | |
Devang Patel | b8817b9 | 2006-12-14 00:59:42 +0000 | [diff] [blame] | 543 | //===----------------------------------------------------------------------===// |
| 544 | // TimingInfo Class - This class is used to calculate information about the |
| 545 | // amount of time each pass takes to execute. This only happens when |
| 546 | // -time-passes is enabled on the command line. |
| 547 | // |
| 548 | |
Devang Patel | ffca910 | 2006-12-15 19:39:30 +0000 | [diff] [blame] | 549 | class VISIBILITY_HIDDEN TimingInfo { |
Devang Patel | b8817b9 | 2006-12-14 00:59:42 +0000 | [diff] [blame] | 550 | std::map<Pass*, Timer> TimingData; |
| 551 | TimerGroup TG; |
| 552 | |
| 553 | public: |
| 554 | // Use 'create' member to get this. |
| 555 | TimingInfo() : TG("... Pass execution timing report ...") {} |
| 556 | |
| 557 | // TimingDtor - Print out information about timing information |
| 558 | ~TimingInfo() { |
| 559 | // Delete all of the timers... |
| 560 | TimingData.clear(); |
| 561 | // TimerGroup is deleted next, printing the report. |
| 562 | } |
| 563 | |
| 564 | // createTheTimeInfo - This method either initializes the TheTimeInfo pointer |
| 565 | // to a non null value (if the -time-passes option is enabled) or it leaves it |
| 566 | // null. It may be called multiple times. |
| 567 | static void createTheTimeInfo(); |
| 568 | |
| 569 | void passStarted(Pass *P) { |
| 570 | |
| 571 | if (dynamic_cast<PMDataManager *>(P)) |
| 572 | return; |
| 573 | |
| 574 | std::map<Pass*, Timer>::iterator I = TimingData.find(P); |
| 575 | if (I == TimingData.end()) |
| 576 | I=TimingData.insert(std::make_pair(P, Timer(P->getPassName(), TG))).first; |
| 577 | I->second.startTimer(); |
| 578 | } |
| 579 | void passEnded(Pass *P) { |
| 580 | |
| 581 | if (dynamic_cast<PMDataManager *>(P)) |
| 582 | return; |
| 583 | |
| 584 | std::map<Pass*, Timer>::iterator I = TimingData.find(P); |
| 585 | assert (I != TimingData.end() && "passStarted/passEnded not nested right!"); |
| 586 | I->second.stopTimer(); |
| 587 | } |
| 588 | }; |
| 589 | |
| 590 | static TimingInfo *TheTimeInfo; |
| 591 | |
Devang Patel | ffca910 | 2006-12-15 19:39:30 +0000 | [diff] [blame] | 592 | } // End of anon namespace |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 593 | |
Devang Patel | a1514cb | 2006-12-07 19:39:39 +0000 | [diff] [blame] | 594 | //===----------------------------------------------------------------------===// |
Devang Patel | afb1f362 | 2006-12-12 22:35:25 +0000 | [diff] [blame] | 595 | // PMTopLevelManager implementation |
| 596 | |
| 597 | /// Set pass P as the last user of the given analysis passes. |
| 598 | void PMTopLevelManager::setLastUser(std::vector<Pass *> &AnalysisPasses, |
| 599 | Pass *P) { |
| 600 | |
| 601 | for (std::vector<Pass *>::iterator I = AnalysisPasses.begin(), |
| 602 | E = AnalysisPasses.end(); I != E; ++I) { |
| 603 | Pass *AP = *I; |
| 604 | LastUser[AP] = P; |
| 605 | // If AP is the last user of other passes then make P last user of |
| 606 | // such passes. |
| 607 | for (std::map<Pass *, Pass *>::iterator LUI = LastUser.begin(), |
| 608 | LUE = LastUser.end(); LUI != LUE; ++LUI) { |
| 609 | if (LUI->second == AP) |
| 610 | LastUser[LUI->first] = P; |
| 611 | } |
| 612 | } |
Devang Patel | afb1f362 | 2006-12-12 22:35:25 +0000 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | /// Collect passes whose last user is P |
| 616 | void PMTopLevelManager::collectLastUses(std::vector<Pass *> &LastUses, |
| 617 | Pass *P) { |
| 618 | for (std::map<Pass *, Pass *>::iterator LUI = LastUser.begin(), |
| 619 | LUE = LastUser.end(); LUI != LUE; ++LUI) |
| 620 | if (LUI->second == P) |
| 621 | LastUses.push_back(LUI->first); |
| 622 | } |
| 623 | |
| 624 | /// Schedule pass P for execution. Make sure that passes required by |
| 625 | /// P are run before P is run. Update analysis info maintained by |
| 626 | /// the manager. Remove dead passes. This is a recursive function. |
| 627 | void PMTopLevelManager::schedulePass(Pass *P) { |
| 628 | |
| 629 | // TODO : Allocate function manager for this pass, other wise required set |
| 630 | // may be inserted into previous function manager |
| 631 | |
| 632 | AnalysisUsage AnUsage; |
| 633 | P->getAnalysisUsage(AnUsage); |
| 634 | const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet(); |
| 635 | for (std::vector<AnalysisID>::const_iterator I = RequiredSet.begin(), |
| 636 | E = RequiredSet.end(); I != E; ++I) { |
| 637 | |
| 638 | Pass *AnalysisPass = findAnalysisPass(*I); |
| 639 | if (!AnalysisPass) { |
| 640 | // Schedule this analysis run first. |
| 641 | AnalysisPass = (*I)->createPass(); |
| 642 | schedulePass(AnalysisPass); |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | // Now all required passes are available. |
| 647 | addTopLevelPass(P); |
| 648 | } |
| 649 | |
| 650 | /// Find the pass that implements Analysis AID. Search immutable |
| 651 | /// passes and all pass managers. If desired pass is not found |
| 652 | /// then return NULL. |
| 653 | Pass *PMTopLevelManager::findAnalysisPass(AnalysisID AID) { |
| 654 | |
| 655 | Pass *P = NULL; |
Devang Patel | cd6ba15 | 2006-12-12 22:50:05 +0000 | [diff] [blame] | 656 | // Check pass managers |
| 657 | for (std::vector<Pass *>::iterator I = PassManagers.begin(), |
| 658 | E = PassManagers.end(); P == NULL && I != E; ++I) { |
| 659 | PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I); |
| 660 | assert(PMD && "This is not a PassManager"); |
| 661 | P = PMD->findAnalysisPass(AID, false); |
| 662 | } |
| 663 | |
| 664 | // Check other pass managers |
| 665 | for (std::vector<PMDataManager *>::iterator I = IndirectPassManagers.begin(), |
| 666 | E = IndirectPassManagers.end(); P == NULL && I != E; ++I) |
| 667 | P = (*I)->findAnalysisPass(AID, false); |
| 668 | |
Devang Patel | afb1f362 | 2006-12-12 22:35:25 +0000 | [diff] [blame] | 669 | for (std::vector<ImmutablePass *>::iterator I = ImmutablePasses.begin(), |
| 670 | E = ImmutablePasses.end(); P == NULL && I != E; ++I) { |
| 671 | const PassInfo *PI = (*I)->getPassInfo(); |
| 672 | if (PI == AID) |
| 673 | P = *I; |
| 674 | |
| 675 | // If Pass not found then check the interfaces implemented by Immutable Pass |
| 676 | if (!P) { |
Devang Patel | 56d48ec | 2006-12-15 22:57:49 +0000 | [diff] [blame^] | 677 | const std::vector<const PassInfo*> &ImmPI = PI->getInterfacesImplemented(); |
| 678 | if (std::find(ImmPI.begin(), ImmPI.end(), AID) != ImmPI.end()) |
| 679 | P = *I; |
Devang Patel | afb1f362 | 2006-12-12 22:35:25 +0000 | [diff] [blame] | 680 | } |
| 681 | } |
| 682 | |
Devang Patel | afb1f362 | 2006-12-12 22:35:25 +0000 | [diff] [blame] | 683 | return P; |
| 684 | } |
| 685 | |
Devang Patel | eda5617 | 2006-12-12 23:34:33 +0000 | [diff] [blame] | 686 | // Print passes managed by this top level manager. |
Devang Patel | 991aeba | 2006-12-15 20:13:01 +0000 | [diff] [blame] | 687 | void PMTopLevelManager::dumpPasses() const { |
Devang Patel | eda5617 | 2006-12-12 23:34:33 +0000 | [diff] [blame] | 688 | |
| 689 | // Print out the immutable passes |
| 690 | for (unsigned i = 0, e = ImmutablePasses.size(); i != e; ++i) { |
| 691 | ImmutablePasses[i]->dumpPassStructure(0); |
| 692 | } |
| 693 | |
Devang Patel | 991aeba | 2006-12-15 20:13:01 +0000 | [diff] [blame] | 694 | for (std::vector<Pass *>::const_iterator I = PassManagers.begin(), |
Devang Patel | eda5617 | 2006-12-12 23:34:33 +0000 | [diff] [blame] | 695 | E = PassManagers.end(); I != E; ++I) |
| 696 | (*I)->dumpPassStructure(1); |
Devang Patel | eda5617 | 2006-12-12 23:34:33 +0000 | [diff] [blame] | 697 | } |
| 698 | |
Devang Patel | 991aeba | 2006-12-15 20:13:01 +0000 | [diff] [blame] | 699 | void PMTopLevelManager::dumpArguments() const { |
Devang Patel | cfd70c4 | 2006-12-13 22:10:00 +0000 | [diff] [blame] | 700 | |
| 701 | if (PassDebugging_New < Arguments) |
| 702 | return; |
| 703 | |
| 704 | cerr << "Pass Arguments: "; |
Devang Patel | 991aeba | 2006-12-15 20:13:01 +0000 | [diff] [blame] | 705 | for (std::vector<Pass *>::const_iterator I = PassManagers.begin(), |
Devang Patel | cfd70c4 | 2006-12-13 22:10:00 +0000 | [diff] [blame] | 706 | E = PassManagers.end(); I != E; ++I) { |
| 707 | PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I); |
| 708 | assert(PMD && "This is not a PassManager"); |
| 709 | PMD->dumpPassArguments(); |
| 710 | } |
| 711 | cerr << "\n"; |
| 712 | } |
| 713 | |
Devang Patel | afb1f362 | 2006-12-12 22:35:25 +0000 | [diff] [blame] | 714 | //===----------------------------------------------------------------------===// |
Devang Patel | dbe4a1e | 2006-12-07 18:36:24 +0000 | [diff] [blame] | 715 | // PMDataManager implementation |
Devang Patel | f68a349 | 2006-11-07 22:35:17 +0000 | [diff] [blame] | 716 | |
Devang Patel | d65e9e9 | 2006-11-08 01:31:28 +0000 | [diff] [blame] | 717 | /// 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] | 718 | /// manager. |
Devang Patel | dbe4a1e | 2006-12-07 18:36:24 +0000 | [diff] [blame] | 719 | bool PMDataManager::manageablePass(Pass *P) { |
Devang Patel | f68a349 | 2006-11-07 22:35:17 +0000 | [diff] [blame] | 720 | |
Devang Patel | 8f677ce | 2006-12-07 18:47:25 +0000 | [diff] [blame] | 721 | // TODO |
| 722 | // If this pass is not preserving information that is required by a |
| 723 | // pass maintained by higher level pass manager then do not insert |
| 724 | // this pass into current manager. Use new manager. For example, |
| 725 | // For example, If FunctionPass F is not preserving ModulePass Info M1 |
| 726 | // that is used by another ModulePass M2 then do not insert F in |
| 727 | // current function pass manager. |
Devang Patel | f68a349 | 2006-11-07 22:35:17 +0000 | [diff] [blame] | 728 | return true; |
| 729 | } |
| 730 | |
Devang Patel | 643676c | 2006-11-11 01:10:19 +0000 | [diff] [blame] | 731 | /// Augement AvailableAnalysis by adding analysis made available by pass P. |
Devang Patel | e9976aa | 2006-12-07 19:33:53 +0000 | [diff] [blame] | 732 | void PMDataManager::recordAvailableAnalysis(Pass *P) { |
Devang Patel | f60b5d9 | 2006-11-14 01:59:59 +0000 | [diff] [blame] | 733 | |
Devang Patel | 643676c | 2006-11-11 01:10:19 +0000 | [diff] [blame] | 734 | if (const PassInfo *PI = P->getPassInfo()) { |
Devang Patel | f60b5d9 | 2006-11-14 01:59:59 +0000 | [diff] [blame] | 735 | AvailableAnalysis[PI] = P; |
Devang Patel | 643676c | 2006-11-11 01:10:19 +0000 | [diff] [blame] | 736 | |
Devang Patel | e9976aa | 2006-12-07 19:33:53 +0000 | [diff] [blame] | 737 | //This pass is the current implementation of all of the interfaces it |
| 738 | //implements as well. |
| 739 | const std::vector<const PassInfo*> &II = PI->getInterfacesImplemented(); |
| 740 | for (unsigned i = 0, e = II.size(); i != e; ++i) |
| 741 | AvailableAnalysis[II[i]] = P; |
Devang Patel | 643676c | 2006-11-11 01:10:19 +0000 | [diff] [blame] | 742 | } |
| 743 | } |
| 744 | |
Devang Patel | f68a349 | 2006-11-07 22:35:17 +0000 | [diff] [blame] | 745 | /// Remove Analyss not preserved by Pass P |
Devang Patel | dbe4a1e | 2006-12-07 18:36:24 +0000 | [diff] [blame] | 746 | void PMDataManager::removeNotPreservedAnalysis(Pass *P) { |
Devang Patel | 349170f | 2006-11-11 01:24:55 +0000 | [diff] [blame] | 747 | AnalysisUsage AnUsage; |
| 748 | P->getAnalysisUsage(AnUsage); |
Devang Patel | f68a349 | 2006-11-07 22:35:17 +0000 | [diff] [blame] | 749 | |
Devang Patel | 2e169c3 | 2006-12-07 20:03:49 +0000 | [diff] [blame] | 750 | if (AnUsage.getPreservesAll()) |
| 751 | return; |
| 752 | |
| 753 | const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet(); |
Devang Patel | f60b5d9 | 2006-11-14 01:59:59 +0000 | [diff] [blame] | 754 | for (std::map<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(), |
Devang Patel | be6bd55e | 2006-12-12 23:07:44 +0000 | [diff] [blame] | 755 | E = AvailableAnalysis.end(); I != E; ) { |
Devang Patel | 56d48ec | 2006-12-15 22:57:49 +0000 | [diff] [blame^] | 756 | std::map<AnalysisID, Pass*>::iterator Info = I++; |
| 757 | if (std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) == |
Devang Patel | 349170f | 2006-11-11 01:24:55 +0000 | [diff] [blame] | 758 | PreservedSet.end()) { |
| 759 | // Remove this analysis |
Devang Patel | 56d48ec | 2006-12-15 22:57:49 +0000 | [diff] [blame^] | 760 | if (!dynamic_cast<ImmutablePass*>(Info->second)) |
| 761 | AvailableAnalysis.erase(Info); |
| 762 | } |
Devang Patel | 349170f | 2006-11-11 01:24:55 +0000 | [diff] [blame] | 763 | } |
Devang Patel | f68a349 | 2006-11-07 22:35:17 +0000 | [diff] [blame] | 764 | } |
| 765 | |
Devang Patel | ca18926 | 2006-11-14 03:05:08 +0000 | [diff] [blame] | 766 | /// Remove analysis passes that are not used any longer |
Devang Patel | 200d305 | 2006-12-13 23:50:44 +0000 | [diff] [blame] | 767 | void PMDataManager::removeDeadPasses(Pass *P, std::string &Msg) { |
Devang Patel | 17ad096 | 2006-12-08 00:37:52 +0000 | [diff] [blame] | 768 | |
| 769 | std::vector<Pass *> DeadPasses; |
| 770 | TPM->collectLastUses(DeadPasses, P); |
| 771 | |
| 772 | for (std::vector<Pass *>::iterator I = DeadPasses.begin(), |
| 773 | E = DeadPasses.end(); I != E; ++I) { |
Devang Patel | 200d305 | 2006-12-13 23:50:44 +0000 | [diff] [blame] | 774 | |
| 775 | std::string Msg1 = " Freeing Pass '"; |
| 776 | dumpPassInfo(*I, Msg1, Msg); |
| 777 | |
Devang Patel | b8817b9 | 2006-12-14 00:59:42 +0000 | [diff] [blame] | 778 | if (TheTimeInfo) TheTimeInfo->passStarted(P); |
Devang Patel | 17ad096 | 2006-12-08 00:37:52 +0000 | [diff] [blame] | 779 | (*I)->releaseMemory(); |
Devang Patel | b8817b9 | 2006-12-14 00:59:42 +0000 | [diff] [blame] | 780 | if (TheTimeInfo) TheTimeInfo->passEnded(P); |
| 781 | |
Devang Patel | 17ad096 | 2006-12-08 00:37:52 +0000 | [diff] [blame] | 782 | std::map<AnalysisID, Pass*>::iterator Pos = |
| 783 | AvailableAnalysis.find((*I)->getPassInfo()); |
| 784 | |
Devang Patel | 475c453 | 2006-12-08 00:59:05 +0000 | [diff] [blame] | 785 | // It is possible that pass is already removed from the AvailableAnalysis |
Devang Patel | 17ad096 | 2006-12-08 00:37:52 +0000 | [diff] [blame] | 786 | if (Pos != AvailableAnalysis.end()) |
| 787 | AvailableAnalysis.erase(Pos); |
| 788 | } |
Devang Patel | ca18926 | 2006-11-14 03:05:08 +0000 | [diff] [blame] | 789 | } |
| 790 | |
Devang Patel | 8f677ce | 2006-12-07 18:47:25 +0000 | [diff] [blame] | 791 | /// Add pass P into the PassVector. Update |
Devang Patel | 90b05e0 | 2006-11-11 02:04:19 +0000 | [diff] [blame] | 792 | /// AvailableAnalysis appropriately if ProcessAnalysis is true. |
Devang Patel | 2e169c3 | 2006-12-07 20:03:49 +0000 | [diff] [blame] | 793 | void PMDataManager::addPassToManager(Pass *P, |
| 794 | bool ProcessAnalysis) { |
Devang Patel | 8cad70d | 2006-11-11 01:51:02 +0000 | [diff] [blame] | 795 | |
Devang Patel | d440cd9 | 2006-12-08 23:53:00 +0000 | [diff] [blame] | 796 | // This manager is going to manage pass P. Set up analysis resolver |
| 797 | // to connect them. |
| 798 | AnalysisResolver_New *AR = new AnalysisResolver_New(*this); |
| 799 | P->setResolver(AR); |
| 800 | |
Devang Patel | 90b05e0 | 2006-11-11 02:04:19 +0000 | [diff] [blame] | 801 | if (ProcessAnalysis) { |
Devang Patel | bc03f13 | 2006-12-07 23:55:10 +0000 | [diff] [blame] | 802 | |
| 803 | // At the moment, this pass is the last user of all required passes. |
| 804 | std::vector<Pass *> LastUses; |
| 805 | std::vector<Pass *> RequiredPasses; |
| 806 | unsigned PDepth = this->getDepth(); |
| 807 | |
| 808 | collectRequiredAnalysisPasses(RequiredPasses, P); |
| 809 | for (std::vector<Pass *>::iterator I = RequiredPasses.begin(), |
| 810 | E = RequiredPasses.end(); I != E; ++I) { |
| 811 | Pass *PRequired = *I; |
| 812 | unsigned RDepth = 0; |
Devang Patel | 64619be | 2006-12-09 00:07:38 +0000 | [diff] [blame] | 813 | |
| 814 | PMDataManager &DM = PRequired->getResolver()->getPMDataManager(); |
| 815 | RDepth = DM.getDepth(); |
| 816 | |
Devang Patel | bc03f13 | 2006-12-07 23:55:10 +0000 | [diff] [blame] | 817 | if (PDepth == RDepth) |
| 818 | LastUses.push_back(PRequired); |
| 819 | else if (PDepth > RDepth) { |
| 820 | // Let the parent claim responsibility of last use |
Devang Patel | 832bc07 | 2006-12-15 00:08:26 +0000 | [diff] [blame] | 821 | TransferLastUses.push_back(PRequired); |
Devang Patel | bc03f13 | 2006-12-07 23:55:10 +0000 | [diff] [blame] | 822 | } else { |
| 823 | // Note : This feature is not yet implemented |
| 824 | assert (0 && |
| 825 | "Unable to handle Pass that requires lower level Analysis pass"); |
| 826 | } |
| 827 | } |
| 828 | |
Devang Patel | 832bc07 | 2006-12-15 00:08:26 +0000 | [diff] [blame] | 829 | LastUses.push_back(P); |
| 830 | TPM->setLastUser(LastUses, P); |
Devang Patel | bc03f13 | 2006-12-07 23:55:10 +0000 | [diff] [blame] | 831 | |
Devang Patel | 17bff0d | 2006-12-07 22:09:36 +0000 | [diff] [blame] | 832 | // Take a note of analysis required and made available by this pass. |
Devang Patel | 90b05e0 | 2006-11-11 02:04:19 +0000 | [diff] [blame] | 833 | // Remove the analysis not preserved by this pass |
| 834 | removeNotPreservedAnalysis(P); |
Devang Patel | 17bff0d | 2006-12-07 22:09:36 +0000 | [diff] [blame] | 835 | recordAvailableAnalysis(P); |
Devang Patel | 90b05e0 | 2006-11-11 02:04:19 +0000 | [diff] [blame] | 836 | } |
Devang Patel | 8cad70d | 2006-11-11 01:51:02 +0000 | [diff] [blame] | 837 | |
| 838 | // Add pass |
| 839 | PassVector.push_back(P); |
Devang Patel | 8cad70d | 2006-11-11 01:51:02 +0000 | [diff] [blame] | 840 | } |
| 841 | |
Devang Patel | 1d6267c | 2006-12-07 23:05:44 +0000 | [diff] [blame] | 842 | /// Populate RequiredPasses with the analysis pass that are required by |
| 843 | /// pass P. |
| 844 | void PMDataManager::collectRequiredAnalysisPasses(std::vector<Pass *> &RP, |
| 845 | Pass *P) { |
| 846 | AnalysisUsage AnUsage; |
| 847 | P->getAnalysisUsage(AnUsage); |
| 848 | const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet(); |
| 849 | for (std::vector<AnalysisID>::const_iterator |
| 850 | I = RequiredSet.begin(), E = RequiredSet.end(); |
| 851 | I != E; ++I) { |
Devang Patel | 640c5bb | 2006-12-08 22:30:11 +0000 | [diff] [blame] | 852 | Pass *AnalysisPass = findAnalysisPass(*I, true); |
Devang Patel | 1d6267c | 2006-12-07 23:05:44 +0000 | [diff] [blame] | 853 | assert (AnalysisPass && "Analysis pass is not available"); |
| 854 | RP.push_back(AnalysisPass); |
| 855 | } |
Devang Patel | f58183d | 2006-12-12 23:09:32 +0000 | [diff] [blame] | 856 | |
| 857 | const std::vector<AnalysisID> &IDs = AnUsage.getRequiredTransitiveSet(); |
| 858 | for (std::vector<AnalysisID>::const_iterator I = IDs.begin(), |
| 859 | E = IDs.end(); I != E; ++I) { |
| 860 | Pass *AnalysisPass = findAnalysisPass(*I, true); |
| 861 | assert (AnalysisPass && "Analysis pass is not available"); |
| 862 | RP.push_back(AnalysisPass); |
| 863 | } |
Devang Patel | 1d6267c | 2006-12-07 23:05:44 +0000 | [diff] [blame] | 864 | } |
| 865 | |
Devang Patel | 07f4f58 | 2006-11-14 21:49:36 +0000 | [diff] [blame] | 866 | // All Required analyses should be available to the pass as it runs! Here |
| 867 | // we fill in the AnalysisImpls member of the pass so that it can |
| 868 | // successfully use the getAnalysis() method to retrieve the |
| 869 | // implementations it needs. |
| 870 | // |
Devang Patel | dbe4a1e | 2006-12-07 18:36:24 +0000 | [diff] [blame] | 871 | void PMDataManager::initializeAnalysisImpl(Pass *P) { |
Devang Patel | ff631ae | 2006-11-15 01:27:05 +0000 | [diff] [blame] | 872 | AnalysisUsage AnUsage; |
| 873 | P->getAnalysisUsage(AnUsage); |
Devang Patel | 07f4f58 | 2006-11-14 21:49:36 +0000 | [diff] [blame] | 874 | |
| 875 | for (std::vector<const PassInfo *>::const_iterator |
| 876 | I = AnUsage.getRequiredSet().begin(), |
| 877 | E = AnUsage.getRequiredSet().end(); I != E; ++I) { |
Devang Patel | 640c5bb | 2006-12-08 22:30:11 +0000 | [diff] [blame] | 878 | Pass *Impl = findAnalysisPass(*I, true); |
Devang Patel | 07f4f58 | 2006-11-14 21:49:36 +0000 | [diff] [blame] | 879 | if (Impl == 0) |
| 880 | assert(0 && "Analysis used but not available!"); |
Devang Patel | 984698a | 2006-12-09 01:11:34 +0000 | [diff] [blame] | 881 | AnalysisResolver_New *AR = P->getResolver(); |
| 882 | AR->addAnalysisImplsPair(*I, Impl); |
Devang Patel | 07f4f58 | 2006-11-14 21:49:36 +0000 | [diff] [blame] | 883 | } |
| 884 | } |
| 885 | |
Devang Patel | 640c5bb | 2006-12-08 22:30:11 +0000 | [diff] [blame] | 886 | /// Find the pass that implements Analysis AID. If desired pass is not found |
| 887 | /// then return NULL. |
| 888 | Pass *PMDataManager::findAnalysisPass(AnalysisID AID, bool SearchParent) { |
| 889 | |
| 890 | // Check if AvailableAnalysis map has one entry. |
| 891 | std::map<AnalysisID, Pass*>::const_iterator I = AvailableAnalysis.find(AID); |
| 892 | |
| 893 | if (I != AvailableAnalysis.end()) |
| 894 | return I->second; |
| 895 | |
| 896 | // Search Parents through TopLevelManager |
| 897 | if (SearchParent) |
| 898 | return TPM->findAnalysisPass(AID); |
| 899 | |
Devang Patel | 9d759b8 | 2006-12-09 00:09:12 +0000 | [diff] [blame] | 900 | return NULL; |
Devang Patel | 640c5bb | 2006-12-08 22:30:11 +0000 | [diff] [blame] | 901 | } |
| 902 | |
Devang Patel | 991aeba | 2006-12-15 20:13:01 +0000 | [diff] [blame] | 903 | // Print list of passes that are last used by P. |
| 904 | void PMDataManager::dumpLastUses(Pass *P, unsigned Offset) const{ |
| 905 | |
| 906 | std::vector<Pass *> LUses; |
| 907 | |
| 908 | assert (TPM && "Top Level Manager is missing"); |
| 909 | TPM->collectLastUses(LUses, P); |
| 910 | |
| 911 | for (std::vector<Pass *>::iterator I = LUses.begin(), |
| 912 | E = LUses.end(); I != E; ++I) { |
| 913 | llvm::cerr << "--" << std::string(Offset*2, ' '); |
| 914 | (*I)->dumpPassStructure(0); |
| 915 | } |
| 916 | } |
| 917 | |
| 918 | void PMDataManager::dumpPassArguments() const { |
| 919 | for(std::vector<Pass *>::const_iterator I = PassVector.begin(), |
| 920 | E = PassVector.end(); I != E; ++I) { |
| 921 | if (PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I)) |
| 922 | PMD->dumpPassArguments(); |
| 923 | else |
| 924 | if (const PassInfo *PI = (*I)->getPassInfo()) |
| 925 | if (!PI->isAnalysisGroup()) |
| 926 | cerr << " -" << PI->getPassArgument(); |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | void PMDataManager:: dumpPassInfo(Pass *P, std::string &Msg1, |
| 931 | std::string &Msg2) const { |
| 932 | if (PassDebugging_New < Executions) |
| 933 | return; |
| 934 | cerr << (void*)this << std::string(getDepth()*2+1, ' '); |
| 935 | cerr << Msg1; |
| 936 | cerr << P->getPassName(); |
| 937 | cerr << Msg2; |
| 938 | } |
| 939 | |
| 940 | void PMDataManager::dumpAnalysisSetInfo(const char *Msg, Pass *P, |
| 941 | const std::vector<AnalysisID> &Set) |
| 942 | const { |
| 943 | if (PassDebugging_New >= Details && !Set.empty()) { |
| 944 | cerr << (void*)P << std::string(getDepth()*2+3, ' ') << Msg << " Analyses:"; |
| 945 | for (unsigned i = 0; i != Set.size(); ++i) { |
| 946 | if (i) cerr << ","; |
| 947 | cerr << " " << Set[i]->getPassName(); |
| 948 | } |
| 949 | cerr << "\n"; |
| 950 | } |
| 951 | } |
Devang Patel | 9bdf7d4 | 2006-12-08 23:28:54 +0000 | [diff] [blame] | 952 | |
| 953 | //===----------------------------------------------------------------------===// |
| 954 | // NOTE: Is this the right place to define this method ? |
| 955 | // getAnalysisToUpdate - Return an analysis result or null if it doesn't exist |
| 956 | Pass *AnalysisResolver_New::getAnalysisToUpdate(AnalysisID ID, bool dir) const { |
| 957 | return PM.findAnalysisPass(ID, dir); |
| 958 | } |
| 959 | |
Devang Patel | a1514cb | 2006-12-07 19:39:39 +0000 | [diff] [blame] | 960 | //===----------------------------------------------------------------------===// |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 961 | // BasicBlockPassManager implementation |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 962 | |
Devang Patel | d65e9e9 | 2006-11-08 01:31:28 +0000 | [diff] [blame] | 963 | /// Add pass P into PassVector and return true. If this pass is not |
| 964 | /// manageable by this manager then return false. |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 965 | bool |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 966 | BasicBlockPassManager::addPass(Pass *P) { |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 967 | |
| 968 | BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P); |
| 969 | if (!BP) |
| 970 | return false; |
| 971 | |
Devang Patel | 56d48ec | 2006-12-15 22:57:49 +0000 | [diff] [blame^] | 972 | // If this pass does not preserve analysis that is used by other passes |
| 973 | // managed by this manager than it is not a suitable pass for this manager. |
Devang Patel | d65e9e9 | 2006-11-08 01:31:28 +0000 | [diff] [blame] | 974 | if (!manageablePass(P)) |
Devang Patel | 3c8eb62 | 2006-11-07 22:56:50 +0000 | [diff] [blame] | 975 | return false; |
| 976 | |
Chris Lattner | ce22ca3 | 2006-12-14 18:22:14 +0000 | [diff] [blame] | 977 | addPassToManager(BP); |
Devang Patel | 349170f | 2006-11-11 01:24:55 +0000 | [diff] [blame] | 978 | |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 979 | return true; |
| 980 | } |
| 981 | |
| 982 | /// Execute all of the passes scheduled for execution by invoking |
| 983 | /// runOnBasicBlock method. Keep track of whether any of the passes modifies |
| 984 | /// the function, and if so, return true. |
| 985 | bool |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 986 | BasicBlockPassManager::runOnFunction(Function &F) { |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 987 | |
Devang Patel | 745a696 | 2006-12-12 23:15:28 +0000 | [diff] [blame] | 988 | if (F.isExternal()) |
| 989 | return false; |
| 990 | |
Devang Patel | e958559 | 2006-12-08 01:38:28 +0000 | [diff] [blame] | 991 | bool Changed = doInitialization(F); |
Devang Patel | a6b6dcb | 2006-12-07 18:41:09 +0000 | [diff] [blame] | 992 | initializeAnalysisInfo(); |
Devang Patel | 050ec72 | 2006-11-14 01:23:29 +0000 | [diff] [blame] | 993 | |
Devang Patel | 93a197c | 2006-12-14 00:08:04 +0000 | [diff] [blame] | 994 | std::string Msg1 = "Executing Pass '"; |
| 995 | std::string Msg3 = "' Made Modification '"; |
| 996 | |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 997 | for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) |
Devang Patel | 8cad70d | 2006-11-11 01:51:02 +0000 | [diff] [blame] | 998 | for (std::vector<Pass *>::iterator itr = passVectorBegin(), |
| 999 | e = passVectorEnd(); itr != e; ++itr) { |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 1000 | Pass *P = *itr; |
Devang Patel | f6d1d21 | 2006-12-14 00:25:06 +0000 | [diff] [blame] | 1001 | AnalysisUsage AnUsage; |
| 1002 | P->getAnalysisUsage(AnUsage); |
| 1003 | |
Devang Patel | 200d305 | 2006-12-13 23:50:44 +0000 | [diff] [blame] | 1004 | std::string Msg2 = "' on BasicBlock '" + (*I).getName() + "'...\n"; |
| 1005 | dumpPassInfo(P, Msg1, Msg2); |
Devang Patel | f6d1d21 | 2006-12-14 00:25:06 +0000 | [diff] [blame] | 1006 | dumpAnalysisSetInfo("Required", P, AnUsage.getRequiredSet()); |
| 1007 | |
Devang Patel | 47d7df7 | 2006-12-12 23:13:09 +0000 | [diff] [blame] | 1008 | initializeAnalysisImpl(P); |
Devang Patel | 93a197c | 2006-12-14 00:08:04 +0000 | [diff] [blame] | 1009 | |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 1010 | BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P); |
Devang Patel | b8817b9 | 2006-12-14 00:59:42 +0000 | [diff] [blame] | 1011 | if (TheTimeInfo) TheTimeInfo->passStarted(P); |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 1012 | Changed |= BP->runOnBasicBlock(*I); |
Devang Patel | b8817b9 | 2006-12-14 00:59:42 +0000 | [diff] [blame] | 1013 | if (TheTimeInfo) TheTimeInfo->passEnded(P); |
Devang Patel | 93a197c | 2006-12-14 00:08:04 +0000 | [diff] [blame] | 1014 | |
| 1015 | if (Changed) |
| 1016 | dumpPassInfo(P, Msg3, Msg2); |
Devang Patel | f6d1d21 | 2006-12-14 00:25:06 +0000 | [diff] [blame] | 1017 | dumpAnalysisSetInfo("Preserved", P, AnUsage.getPreservedSet()); |
Devang Patel | 93a197c | 2006-12-14 00:08:04 +0000 | [diff] [blame] | 1018 | |
Devang Patel | 050ec72 | 2006-11-14 01:23:29 +0000 | [diff] [blame] | 1019 | removeNotPreservedAnalysis(P); |
Devang Patel | 17bff0d | 2006-12-07 22:09:36 +0000 | [diff] [blame] | 1020 | recordAvailableAnalysis(P); |
Devang Patel | 200d305 | 2006-12-13 23:50:44 +0000 | [diff] [blame] | 1021 | removeDeadPasses(P, Msg2); |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 1022 | } |
Devang Patel | 56d48ec | 2006-12-15 22:57:49 +0000 | [diff] [blame^] | 1023 | return Changed |= doFinalization(F); |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 1024 | } |
| 1025 | |
Devang Patel | 475c453 | 2006-12-08 00:59:05 +0000 | [diff] [blame] | 1026 | // Implement doInitialization and doFinalization |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 1027 | inline bool BasicBlockPassManager::doInitialization(Module &M) { |
Devang Patel | 475c453 | 2006-12-08 00:59:05 +0000 | [diff] [blame] | 1028 | bool Changed = false; |
| 1029 | |
| 1030 | for (std::vector<Pass *>::iterator itr = passVectorBegin(), |
| 1031 | e = passVectorEnd(); itr != e; ++itr) { |
| 1032 | Pass *P = *itr; |
| 1033 | BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P); |
| 1034 | Changed |= BP->doInitialization(M); |
| 1035 | } |
| 1036 | |
| 1037 | return Changed; |
| 1038 | } |
| 1039 | |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 1040 | inline bool BasicBlockPassManager::doFinalization(Module &M) { |
Devang Patel | 475c453 | 2006-12-08 00:59:05 +0000 | [diff] [blame] | 1041 | bool Changed = false; |
| 1042 | |
| 1043 | for (std::vector<Pass *>::iterator itr = passVectorBegin(), |
| 1044 | e = passVectorEnd(); itr != e; ++itr) { |
| 1045 | Pass *P = *itr; |
| 1046 | BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P); |
| 1047 | Changed |= BP->doFinalization(M); |
| 1048 | } |
| 1049 | |
| 1050 | return Changed; |
| 1051 | } |
| 1052 | |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 1053 | inline bool BasicBlockPassManager::doInitialization(Function &F) { |
Devang Patel | 475c453 | 2006-12-08 00:59:05 +0000 | [diff] [blame] | 1054 | bool Changed = false; |
| 1055 | |
| 1056 | for (std::vector<Pass *>::iterator itr = passVectorBegin(), |
| 1057 | e = passVectorEnd(); itr != e; ++itr) { |
| 1058 | Pass *P = *itr; |
| 1059 | BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P); |
| 1060 | Changed |= BP->doInitialization(F); |
| 1061 | } |
| 1062 | |
| 1063 | return Changed; |
| 1064 | } |
| 1065 | |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 1066 | inline bool BasicBlockPassManager::doFinalization(Function &F) { |
Devang Patel | 475c453 | 2006-12-08 00:59:05 +0000 | [diff] [blame] | 1067 | bool Changed = false; |
| 1068 | |
| 1069 | for (std::vector<Pass *>::iterator itr = passVectorBegin(), |
| 1070 | e = passVectorEnd(); itr != e; ++itr) { |
| 1071 | Pass *P = *itr; |
| 1072 | BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P); |
| 1073 | Changed |= BP->doFinalization(F); |
| 1074 | } |
| 1075 | |
| 1076 | return Changed; |
| 1077 | } |
| 1078 | |
| 1079 | |
Devang Patel | a1514cb | 2006-12-07 19:39:39 +0000 | [diff] [blame] | 1080 | //===----------------------------------------------------------------------===// |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 1081 | // FunctionPassManager implementation |
Devang Patel | a1514cb | 2006-12-07 19:39:39 +0000 | [diff] [blame] | 1082 | |
Devang Patel | 4e12f86 | 2006-11-08 10:44:40 +0000 | [diff] [blame] | 1083 | /// Create new Function pass manager |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 1084 | FunctionPassManager::FunctionPassManager(ModuleProvider *P) { |
Devang Patel | 1f65368 | 2006-12-08 18:57:16 +0000 | [diff] [blame] | 1085 | FPM = new FunctionPassManagerImpl_New(0); |
Devang Patel | 9c6290c | 2006-12-12 22:02:16 +0000 | [diff] [blame] | 1086 | // FPM is the top level manager. |
| 1087 | FPM->setTopLevelManager(FPM); |
Devang Patel | 1036b65 | 2006-12-12 23:27:37 +0000 | [diff] [blame] | 1088 | |
| 1089 | PMDataManager *PMD = dynamic_cast<PMDataManager *>(FPM); |
| 1090 | AnalysisResolver_New *AR = new AnalysisResolver_New(*PMD); |
| 1091 | FPM->setResolver(AR); |
| 1092 | |
| 1093 | FPM->addPassManager(FPM); |
Devang Patel | 1f65368 | 2006-12-08 18:57:16 +0000 | [diff] [blame] | 1094 | MP = P; |
| 1095 | } |
| 1096 | |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 1097 | FunctionPassManager::~FunctionPassManager() { |
| 1098 | // Note : FPM maintains one entry in PassManagers vector. |
| 1099 | // This one entry is FPM itself. This is not ideal. One |
| 1100 | // alternative is have one additional layer between |
| 1101 | // FunctionPassManager and FunctionPassManagerImpl. |
| 1102 | // Meanwhile, to avoid going into infinte loop, first |
| 1103 | // remove FPM from its PassMangers vector. |
| 1104 | FPM->clearManagers(); |
Devang Patel | ab97cf4 | 2006-12-13 00:09:23 +0000 | [diff] [blame] | 1105 | delete FPM; |
| 1106 | } |
| 1107 | |
Devang Patel | 4e12f86 | 2006-11-08 10:44:40 +0000 | [diff] [blame] | 1108 | /// add - Add a pass to the queue of passes to run. This passes |
| 1109 | /// ownership of the Pass to the PassManager. When the |
| 1110 | /// PassManager_X is destroyed, the pass will be destroyed as well, so |
| 1111 | /// there is no need to delete the pass. (TODO delete passes.) |
| 1112 | /// This implies that all passes MUST be allocated with 'new'. |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 1113 | void FunctionPassManager::add(Pass *P) { |
Devang Patel | 4e12f86 | 2006-11-08 10:44:40 +0000 | [diff] [blame] | 1114 | FPM->add(P); |
| 1115 | } |
| 1116 | |
Devang Patel | 9f3083e | 2006-11-15 19:39:54 +0000 | [diff] [blame] | 1117 | /// run - Execute all of the passes scheduled for execution. Keep |
| 1118 | /// track of whether any of the passes modifies the function, and if |
| 1119 | /// so, return true. |
| 1120 | /// |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 1121 | bool FunctionPassManager::run(Function &F) { |
Devang Patel | 9f3083e | 2006-11-15 19:39:54 +0000 | [diff] [blame] | 1122 | std::string errstr; |
| 1123 | if (MP->materializeFunction(&F, &errstr)) { |
Bill Wendling | f3baad3 | 2006-12-07 01:30:32 +0000 | [diff] [blame] | 1124 | cerr << "Error reading bytecode file: " << errstr << "\n"; |
Devang Patel | 9f3083e | 2006-11-15 19:39:54 +0000 | [diff] [blame] | 1125 | abort(); |
| 1126 | } |
Devang Patel | 272908d | 2006-12-08 22:57:48 +0000 | [diff] [blame] | 1127 | return FPM->run(F); |
Devang Patel | 9f3083e | 2006-11-15 19:39:54 +0000 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | |
Devang Patel | ff631ae | 2006-11-15 01:27:05 +0000 | [diff] [blame] | 1131 | /// doInitialization - Run all of the initializers for the function passes. |
| 1132 | /// |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 1133 | bool FunctionPassManager::doInitialization() { |
Devang Patel | ff631ae | 2006-11-15 01:27:05 +0000 | [diff] [blame] | 1134 | return FPM->doInitialization(*MP->getModule()); |
| 1135 | } |
| 1136 | |
| 1137 | /// doFinalization - Run all of the initializers for the function passes. |
| 1138 | /// |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 1139 | bool FunctionPassManager::doFinalization() { |
Devang Patel | ff631ae | 2006-11-15 01:27:05 +0000 | [diff] [blame] | 1140 | return FPM->doFinalization(*MP->getModule()); |
| 1141 | } |
| 1142 | |
Devang Patel | a1514cb | 2006-12-07 19:39:39 +0000 | [diff] [blame] | 1143 | //===----------------------------------------------------------------------===// |
Devang Patel | 4e12f86 | 2006-11-08 10:44:40 +0000 | [diff] [blame] | 1144 | // FunctionPassManagerImpl_New implementation |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 1145 | |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 1146 | /// Add pass P into the pass manager queue. If P is a BasicBlockPass then |
| 1147 | /// either use it into active basic block pass manager or create new basic |
| 1148 | /// block pass manager to handle pass P. |
| 1149 | bool |
Devang Patel | 4e12f86 | 2006-11-08 10:44:40 +0000 | [diff] [blame] | 1150 | FunctionPassManagerImpl_New::addPass(Pass *P) { |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 1151 | |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 1152 | // If P is a BasicBlockPass then use BasicBlockPassManager. |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 1153 | if (BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P)) { |
| 1154 | |
Devang Patel | 4949fe0 | 2006-12-07 22:34:21 +0000 | [diff] [blame] | 1155 | if (!activeBBPassManager || !activeBBPassManager->addPass(BP)) { |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 1156 | |
Devang Patel | 4949fe0 | 2006-12-07 22:34:21 +0000 | [diff] [blame] | 1157 | // If active manager exists then clear its analysis info. |
| 1158 | if (activeBBPassManager) |
| 1159 | activeBBPassManager->initializeAnalysisInfo(); |
Devang Patel | 642c143 | 2006-12-07 21:58:50 +0000 | [diff] [blame] | 1160 | |
Devang Patel | 4949fe0 | 2006-12-07 22:34:21 +0000 | [diff] [blame] | 1161 | // Create and add new manager |
Devang Patel | 4c36e6b | 2006-12-07 23:24:58 +0000 | [diff] [blame] | 1162 | activeBBPassManager = |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 1163 | new BasicBlockPassManager(getDepth() + 1); |
Devang Patel | 9c6290c | 2006-12-12 22:02:16 +0000 | [diff] [blame] | 1164 | // Inherit top level manager |
| 1165 | activeBBPassManager->setTopLevelManager(this->getTopLevelManager()); |
Devang Patel | afb1f362 | 2006-12-12 22:35:25 +0000 | [diff] [blame] | 1166 | |
| 1167 | // Add new manager into current manager's list. |
Devang Patel | 90b05e0 | 2006-11-11 02:04:19 +0000 | [diff] [blame] | 1168 | addPassToManager(activeBBPassManager, false); |
Devang Patel | afb1f362 | 2006-12-12 22:35:25 +0000 | [diff] [blame] | 1169 | |
| 1170 | // Add new manager into top level manager's indirect passes list |
| 1171 | PMDataManager *PMD = dynamic_cast<PMDataManager *>(activeBBPassManager); |
| 1172 | assert (PMD && "Manager is not Pass Manager"); |
| 1173 | TPM->addIndirectPassManager(PMD); |
Devang Patel | 4949fe0 | 2006-12-07 22:34:21 +0000 | [diff] [blame] | 1174 | |
| 1175 | // Add pass into new manager. This time it must succeed. |
Devang Patel | d65e9e9 | 2006-11-08 01:31:28 +0000 | [diff] [blame] | 1176 | if (!activeBBPassManager->addPass(BP)) |
| 1177 | assert(0 && "Unable to add Pass"); |
Devang Patel | 832bc07 | 2006-12-15 00:08:26 +0000 | [diff] [blame] | 1178 | |
| 1179 | // If activeBBPassManager transfered any Last Uses then handle them here. |
| 1180 | std::vector<Pass *> &TLU = activeBBPassManager->getTransferredLastUses(); |
| 1181 | if (!TLU.empty()) |
| 1182 | TPM->setLastUser(TLU, this); |
| 1183 | |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 1184 | } |
Devang Patel | bc03f13 | 2006-12-07 23:55:10 +0000 | [diff] [blame] | 1185 | |
Devang Patel | bc03f13 | 2006-12-07 23:55:10 +0000 | [diff] [blame] | 1186 | |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 1187 | return true; |
| 1188 | } |
| 1189 | |
| 1190 | FunctionPass *FP = dynamic_cast<FunctionPass *>(P); |
| 1191 | if (!FP) |
| 1192 | return false; |
| 1193 | |
Devang Patel | 56d48ec | 2006-12-15 22:57:49 +0000 | [diff] [blame^] | 1194 | // If this pass does not preserve analysis that is used by other passes |
| 1195 | // managed by this manager than it is not a suitable pass for this manager. |
Devang Patel | d65e9e9 | 2006-11-08 01:31:28 +0000 | [diff] [blame] | 1196 | if (!manageablePass(P)) |
Devang Patel | 3c8eb62 | 2006-11-07 22:56:50 +0000 | [diff] [blame] | 1197 | return false; |
| 1198 | |
Devang Patel | 8cad70d | 2006-11-11 01:51:02 +0000 | [diff] [blame] | 1199 | addPassToManager (FP); |
Devang Patel | 4949fe0 | 2006-12-07 22:34:21 +0000 | [diff] [blame] | 1200 | |
| 1201 | // If active manager exists then clear its analysis info. |
| 1202 | if (activeBBPassManager) { |
| 1203 | activeBBPassManager->initializeAnalysisInfo(); |
| 1204 | activeBBPassManager = NULL; |
| 1205 | } |
| 1206 | |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 1207 | return true; |
| 1208 | } |
| 1209 | |
| 1210 | /// Execute all of the passes scheduled for execution by invoking |
| 1211 | /// runOnFunction method. Keep track of whether any of the passes modifies |
| 1212 | /// the function, and if so, return true. |
Devang Patel | 9f3083e | 2006-11-15 19:39:54 +0000 | [diff] [blame] | 1213 | bool FunctionPassManagerImpl_New::runOnModule(Module &M) { |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 1214 | |
Devang Patel | 0e29e29 | 2006-12-08 19:04:09 +0000 | [diff] [blame] | 1215 | bool Changed = doInitialization(M); |
Devang Patel | a6b6dcb | 2006-12-07 18:41:09 +0000 | [diff] [blame] | 1216 | initializeAnalysisInfo(); |
Devang Patel | 050ec72 | 2006-11-14 01:23:29 +0000 | [diff] [blame] | 1217 | |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 1218 | for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) |
Devang Patel | 1929089 | 2006-12-08 19:03:05 +0000 | [diff] [blame] | 1219 | this->runOnFunction(*I); |
| 1220 | |
Devang Patel | 56d48ec | 2006-12-15 22:57:49 +0000 | [diff] [blame^] | 1221 | return Changed |= doFinalization(M); |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 1222 | } |
| 1223 | |
Devang Patel | 9f3083e | 2006-11-15 19:39:54 +0000 | [diff] [blame] | 1224 | /// Execute all of the passes scheduled for execution by invoking |
| 1225 | /// runOnFunction method. Keep track of whether any of the passes modifies |
| 1226 | /// the function, and if so, return true. |
| 1227 | bool FunctionPassManagerImpl_New::runOnFunction(Function &F) { |
| 1228 | |
| 1229 | bool Changed = false; |
Devang Patel | 745a696 | 2006-12-12 23:15:28 +0000 | [diff] [blame] | 1230 | |
| 1231 | if (F.isExternal()) |
| 1232 | return false; |
| 1233 | |
Devang Patel | a6b6dcb | 2006-12-07 18:41:09 +0000 | [diff] [blame] | 1234 | initializeAnalysisInfo(); |
Devang Patel | 9f3083e | 2006-11-15 19:39:54 +0000 | [diff] [blame] | 1235 | |
Devang Patel | 93a197c | 2006-12-14 00:08:04 +0000 | [diff] [blame] | 1236 | std::string Msg1 = "Executing Pass '"; |
| 1237 | std::string Msg3 = "' Made Modification '"; |
| 1238 | |
Devang Patel | 9f3083e | 2006-11-15 19:39:54 +0000 | [diff] [blame] | 1239 | for (std::vector<Pass *>::iterator itr = passVectorBegin(), |
| 1240 | e = passVectorEnd(); itr != e; ++itr) { |
| 1241 | Pass *P = *itr; |
Devang Patel | f6d1d21 | 2006-12-14 00:25:06 +0000 | [diff] [blame] | 1242 | AnalysisUsage AnUsage; |
| 1243 | P->getAnalysisUsage(AnUsage); |
Devang Patel | 93a197c | 2006-12-14 00:08:04 +0000 | [diff] [blame] | 1244 | |
Devang Patel | 200d305 | 2006-12-13 23:50:44 +0000 | [diff] [blame] | 1245 | std::string Msg2 = "' on Function '" + F.getName() + "'...\n"; |
| 1246 | dumpPassInfo(P, Msg1, Msg2); |
Devang Patel | f6d1d21 | 2006-12-14 00:25:06 +0000 | [diff] [blame] | 1247 | dumpAnalysisSetInfo("Required", P, AnUsage.getRequiredSet()); |
Devang Patel | 93a197c | 2006-12-14 00:08:04 +0000 | [diff] [blame] | 1248 | |
Devang Patel | 47d7df7 | 2006-12-12 23:13:09 +0000 | [diff] [blame] | 1249 | initializeAnalysisImpl(P); |
Devang Patel | 9f3083e | 2006-11-15 19:39:54 +0000 | [diff] [blame] | 1250 | FunctionPass *FP = dynamic_cast<FunctionPass*>(P); |
Devang Patel | b8817b9 | 2006-12-14 00:59:42 +0000 | [diff] [blame] | 1251 | |
| 1252 | if (TheTimeInfo) TheTimeInfo->passStarted(P); |
Devang Patel | 9f3083e | 2006-11-15 19:39:54 +0000 | [diff] [blame] | 1253 | Changed |= FP->runOnFunction(F); |
Devang Patel | b8817b9 | 2006-12-14 00:59:42 +0000 | [diff] [blame] | 1254 | if (TheTimeInfo) TheTimeInfo->passEnded(P); |
Devang Patel | 93a197c | 2006-12-14 00:08:04 +0000 | [diff] [blame] | 1255 | |
| 1256 | if (Changed) |
| 1257 | dumpPassInfo(P, Msg3, Msg2); |
Devang Patel | f6d1d21 | 2006-12-14 00:25:06 +0000 | [diff] [blame] | 1258 | dumpAnalysisSetInfo("Preserved", P, AnUsage.getPreservedSet()); |
Devang Patel | 93a197c | 2006-12-14 00:08:04 +0000 | [diff] [blame] | 1259 | |
Devang Patel | 9f3083e | 2006-11-15 19:39:54 +0000 | [diff] [blame] | 1260 | removeNotPreservedAnalysis(P); |
Devang Patel | 17bff0d | 2006-12-07 22:09:36 +0000 | [diff] [blame] | 1261 | recordAvailableAnalysis(P); |
Devang Patel | 200d305 | 2006-12-13 23:50:44 +0000 | [diff] [blame] | 1262 | removeDeadPasses(P, Msg2); |
Devang Patel | 9f3083e | 2006-11-15 19:39:54 +0000 | [diff] [blame] | 1263 | } |
| 1264 | return Changed; |
| 1265 | } |
| 1266 | |
| 1267 | |
Devang Patel | ff631ae | 2006-11-15 01:27:05 +0000 | [diff] [blame] | 1268 | inline bool FunctionPassManagerImpl_New::doInitialization(Module &M) { |
| 1269 | bool Changed = false; |
| 1270 | |
| 1271 | for (std::vector<Pass *>::iterator itr = passVectorBegin(), |
| 1272 | e = passVectorEnd(); itr != e; ++itr) { |
| 1273 | Pass *P = *itr; |
| 1274 | |
| 1275 | FunctionPass *FP = dynamic_cast<FunctionPass*>(P); |
| 1276 | Changed |= FP->doInitialization(M); |
| 1277 | } |
| 1278 | |
| 1279 | return Changed; |
| 1280 | } |
| 1281 | |
| 1282 | inline bool FunctionPassManagerImpl_New::doFinalization(Module &M) { |
| 1283 | bool Changed = false; |
| 1284 | |
| 1285 | for (std::vector<Pass *>::iterator itr = passVectorBegin(), |
| 1286 | e = passVectorEnd(); itr != e; ++itr) { |
| 1287 | Pass *P = *itr; |
| 1288 | |
| 1289 | FunctionPass *FP = dynamic_cast<FunctionPass*>(P); |
| 1290 | Changed |= FP->doFinalization(M); |
| 1291 | } |
| 1292 | |
Devang Patel | ff631ae | 2006-11-15 01:27:05 +0000 | [diff] [blame] | 1293 | return Changed; |
| 1294 | } |
| 1295 | |
Devang Patel | 272908d | 2006-12-08 22:57:48 +0000 | [diff] [blame] | 1296 | // Execute all the passes managed by this top level manager. |
| 1297 | // Return true if any function is modified by a pass. |
| 1298 | bool FunctionPassManagerImpl_New::run(Function &F) { |
| 1299 | |
| 1300 | bool Changed = false; |
| 1301 | for (std::vector<Pass *>::iterator I = passManagersBegin(), |
| 1302 | E = passManagersEnd(); I != E; ++I) { |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 1303 | FunctionPassManagerImpl_New *FP = |
| 1304 | dynamic_cast<FunctionPassManagerImpl_New *>(*I); |
Devang Patel | 272908d | 2006-12-08 22:57:48 +0000 | [diff] [blame] | 1305 | Changed |= FP->runOnFunction(F); |
| 1306 | } |
| 1307 | return Changed; |
| 1308 | } |
| 1309 | |
Devang Patel | a1514cb | 2006-12-07 19:39:39 +0000 | [diff] [blame] | 1310 | //===----------------------------------------------------------------------===// |
Devang Patel | 05e1a97 | 2006-11-07 22:03:15 +0000 | [diff] [blame] | 1311 | // ModulePassManager implementation |
| 1312 | |
| 1313 | /// 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] | 1314 | /// then use FunctionPassManagerImpl_New to manage it. Return false if P |
Devang Patel | 05e1a97 | 2006-11-07 22:03:15 +0000 | [diff] [blame] | 1315 | /// is not manageable by this manager. |
| 1316 | bool |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 1317 | ModulePassManager::addPass(Pass *P) { |
Devang Patel | 05e1a97 | 2006-11-07 22:03:15 +0000 | [diff] [blame] | 1318 | |
| 1319 | // If P is FunctionPass then use function pass maanager. |
| 1320 | if (FunctionPass *FP = dynamic_cast<FunctionPass*>(P)) { |
| 1321 | |
Devang Patel | 640c5bb | 2006-12-08 22:30:11 +0000 | [diff] [blame] | 1322 | if (!activeFunctionPassManager || !activeFunctionPassManager->addPass(P)) { |
Devang Patel | 05e1a97 | 2006-11-07 22:03:15 +0000 | [diff] [blame] | 1323 | |
Devang Patel | 4949fe0 | 2006-12-07 22:34:21 +0000 | [diff] [blame] | 1324 | // If active manager exists then clear its analysis info. |
| 1325 | if (activeFunctionPassManager) |
| 1326 | activeFunctionPassManager->initializeAnalysisInfo(); |
Devang Patel | 642c143 | 2006-12-07 21:58:50 +0000 | [diff] [blame] | 1327 | |
Devang Patel | 4949fe0 | 2006-12-07 22:34:21 +0000 | [diff] [blame] | 1328 | // Create and add new manager |
Devang Patel | 4c36e6b | 2006-12-07 23:24:58 +0000 | [diff] [blame] | 1329 | activeFunctionPassManager = |
| 1330 | new FunctionPassManagerImpl_New(getDepth() + 1); |
Devang Patel | afb1f362 | 2006-12-12 22:35:25 +0000 | [diff] [blame] | 1331 | |
| 1332 | // Add new manager into current manager's list |
Devang Patel | 90b05e0 | 2006-11-11 02:04:19 +0000 | [diff] [blame] | 1333 | addPassToManager(activeFunctionPassManager, false); |
Devang Patel | afb1f362 | 2006-12-12 22:35:25 +0000 | [diff] [blame] | 1334 | |
Devang Patel | 9c6290c | 2006-12-12 22:02:16 +0000 | [diff] [blame] | 1335 | // Inherit top level manager |
| 1336 | activeFunctionPassManager->setTopLevelManager(this->getTopLevelManager()); |
Devang Patel | afb1f362 | 2006-12-12 22:35:25 +0000 | [diff] [blame] | 1337 | |
| 1338 | // Add new manager into top level manager's indirect passes list |
Chris Lattner | f0f611a | 2006-12-13 21:56:10 +0000 | [diff] [blame] | 1339 | PMDataManager *PMD = |
| 1340 | dynamic_cast<PMDataManager *>(activeFunctionPassManager); |
| 1341 | assert(PMD && "Manager is not Pass Manager"); |
Devang Patel | afb1f362 | 2006-12-12 22:35:25 +0000 | [diff] [blame] | 1342 | TPM->addIndirectPassManager(PMD); |
Devang Patel | af1fca5 | 2006-12-08 23:11:43 +0000 | [diff] [blame] | 1343 | |
Devang Patel | 4949fe0 | 2006-12-07 22:34:21 +0000 | [diff] [blame] | 1344 | // Add pass into new manager. This time it must succeed. |
Devang Patel | d65e9e9 | 2006-11-08 01:31:28 +0000 | [diff] [blame] | 1345 | if (!activeFunctionPassManager->addPass(FP)) |
| 1346 | assert(0 && "Unable to add pass"); |
Devang Patel | bc03f13 | 2006-12-07 23:55:10 +0000 | [diff] [blame] | 1347 | |
Devang Patel | 832bc07 | 2006-12-15 00:08:26 +0000 | [diff] [blame] | 1348 | // If activeFunctionPassManager transfered any Last Uses then |
| 1349 | // handle them here. |
| 1350 | std::vector<Pass *> &TLU = |
| 1351 | activeFunctionPassManager->getTransferredLastUses(); |
| 1352 | if (!TLU.empty()) |
| 1353 | TPM->setLastUser(TLU, this); |
| 1354 | } |
Devang Patel | bc03f13 | 2006-12-07 23:55:10 +0000 | [diff] [blame] | 1355 | |
Devang Patel | 05e1a97 | 2006-11-07 22:03:15 +0000 | [diff] [blame] | 1356 | return true; |
| 1357 | } |
| 1358 | |
| 1359 | ModulePass *MP = dynamic_cast<ModulePass *>(P); |
| 1360 | if (!MP) |
| 1361 | return false; |
| 1362 | |
Devang Patel | 56d48ec | 2006-12-15 22:57:49 +0000 | [diff] [blame^] | 1363 | // If this pass does not preserve analysis that is used by other passes |
| 1364 | // managed by this manager than it is not a suitable pass for this manager. |
Devang Patel | d65e9e9 | 2006-11-08 01:31:28 +0000 | [diff] [blame] | 1365 | if (!manageablePass(P)) |
Devang Patel | 3c8eb62 | 2006-11-07 22:56:50 +0000 | [diff] [blame] | 1366 | return false; |
| 1367 | |
Devang Patel | 8cad70d | 2006-11-11 01:51:02 +0000 | [diff] [blame] | 1368 | addPassToManager(MP); |
Devang Patel | 4949fe0 | 2006-12-07 22:34:21 +0000 | [diff] [blame] | 1369 | // If active manager exists then clear its analysis info. |
| 1370 | if (activeFunctionPassManager) { |
| 1371 | activeFunctionPassManager->initializeAnalysisInfo(); |
| 1372 | activeFunctionPassManager = NULL; |
| 1373 | } |
| 1374 | |
Devang Patel | 05e1a97 | 2006-11-07 22:03:15 +0000 | [diff] [blame] | 1375 | return true; |
| 1376 | } |
| 1377 | |
| 1378 | |
| 1379 | /// Execute all of the passes scheduled for execution by invoking |
| 1380 | /// runOnModule method. Keep track of whether any of the passes modifies |
| 1381 | /// the module, and if so, return true. |
| 1382 | bool |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 1383 | ModulePassManager::runOnModule(Module &M) { |
Devang Patel | 05e1a97 | 2006-11-07 22:03:15 +0000 | [diff] [blame] | 1384 | bool Changed = false; |
Devang Patel | a6b6dcb | 2006-12-07 18:41:09 +0000 | [diff] [blame] | 1385 | initializeAnalysisInfo(); |
Devang Patel | 050ec72 | 2006-11-14 01:23:29 +0000 | [diff] [blame] | 1386 | |
Devang Patel | 93a197c | 2006-12-14 00:08:04 +0000 | [diff] [blame] | 1387 | std::string Msg1 = "Executing Pass '"; |
| 1388 | std::string Msg3 = "' Made Modification '"; |
| 1389 | |
Devang Patel | 8cad70d | 2006-11-11 01:51:02 +0000 | [diff] [blame] | 1390 | for (std::vector<Pass *>::iterator itr = passVectorBegin(), |
| 1391 | e = passVectorEnd(); itr != e; ++itr) { |
Devang Patel | 05e1a97 | 2006-11-07 22:03:15 +0000 | [diff] [blame] | 1392 | Pass *P = *itr; |
Devang Patel | f6d1d21 | 2006-12-14 00:25:06 +0000 | [diff] [blame] | 1393 | AnalysisUsage AnUsage; |
| 1394 | P->getAnalysisUsage(AnUsage); |
Devang Patel | 93a197c | 2006-12-14 00:08:04 +0000 | [diff] [blame] | 1395 | |
Devang Patel | 200d305 | 2006-12-13 23:50:44 +0000 | [diff] [blame] | 1396 | std::string Msg2 = "' on Module '" + M.getModuleIdentifier() + "'...\n"; |
| 1397 | dumpPassInfo(P, Msg1, Msg2); |
Devang Patel | f6d1d21 | 2006-12-14 00:25:06 +0000 | [diff] [blame] | 1398 | dumpAnalysisSetInfo("Required", P, AnUsage.getRequiredSet()); |
Devang Patel | 93a197c | 2006-12-14 00:08:04 +0000 | [diff] [blame] | 1399 | |
Devang Patel | 47d7df7 | 2006-12-12 23:13:09 +0000 | [diff] [blame] | 1400 | initializeAnalysisImpl(P); |
Devang Patel | 05e1a97 | 2006-11-07 22:03:15 +0000 | [diff] [blame] | 1401 | ModulePass *MP = dynamic_cast<ModulePass*>(P); |
Devang Patel | b8817b9 | 2006-12-14 00:59:42 +0000 | [diff] [blame] | 1402 | |
| 1403 | if (TheTimeInfo) TheTimeInfo->passStarted(P); |
Devang Patel | 05e1a97 | 2006-11-07 22:03:15 +0000 | [diff] [blame] | 1404 | Changed |= MP->runOnModule(M); |
Devang Patel | b8817b9 | 2006-12-14 00:59:42 +0000 | [diff] [blame] | 1405 | if (TheTimeInfo) TheTimeInfo->passEnded(P); |
Devang Patel | 93a197c | 2006-12-14 00:08:04 +0000 | [diff] [blame] | 1406 | |
| 1407 | if (Changed) |
| 1408 | dumpPassInfo(P, Msg3, Msg2); |
Devang Patel | f6d1d21 | 2006-12-14 00:25:06 +0000 | [diff] [blame] | 1409 | dumpAnalysisSetInfo("Preserved", P, AnUsage.getPreservedSet()); |
| 1410 | |
Devang Patel | 050ec72 | 2006-11-14 01:23:29 +0000 | [diff] [blame] | 1411 | removeNotPreservedAnalysis(P); |
Devang Patel | 17bff0d | 2006-12-07 22:09:36 +0000 | [diff] [blame] | 1412 | recordAvailableAnalysis(P); |
Devang Patel | 200d305 | 2006-12-13 23:50:44 +0000 | [diff] [blame] | 1413 | removeDeadPasses(P, Msg2); |
Devang Patel | 05e1a97 | 2006-11-07 22:03:15 +0000 | [diff] [blame] | 1414 | } |
| 1415 | return Changed; |
| 1416 | } |
| 1417 | |
Devang Patel | a1514cb | 2006-12-07 19:39:39 +0000 | [diff] [blame] | 1418 | //===----------------------------------------------------------------------===// |
| 1419 | // PassManagerImpl implementation |
Devang Patel | ab97cf4 | 2006-12-13 00:09:23 +0000 | [diff] [blame] | 1420 | // |
Devang Patel | c290c8a | 2006-11-07 22:23:34 +0000 | [diff] [blame] | 1421 | /// Add P into active pass manager or use new module pass manager to |
| 1422 | /// manage it. |
Devang Patel | 1a6eaa4 | 2006-11-11 02:22:31 +0000 | [diff] [blame] | 1423 | bool PassManagerImpl_New::addPass(Pass *P) { |
Devang Patel | c290c8a | 2006-11-07 22:23:34 +0000 | [diff] [blame] | 1424 | |
Devang Patel | 6c9f548 | 2006-11-11 00:42:16 +0000 | [diff] [blame] | 1425 | if (!activeManager || !activeManager->addPass(P)) { |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 1426 | activeManager = new ModulePassManager(getDepth() + 1); |
Devang Patel | 9c6290c | 2006-12-12 22:02:16 +0000 | [diff] [blame] | 1427 | // Inherit top level manager |
| 1428 | activeManager->setTopLevelManager(this->getTopLevelManager()); |
Devang Patel | d440cd9 | 2006-12-08 23:53:00 +0000 | [diff] [blame] | 1429 | |
| 1430 | // This top level manager is going to manage activeManager. |
| 1431 | // Set up analysis resolver to connect them. |
| 1432 | AnalysisResolver_New *AR = new AnalysisResolver_New(*this); |
| 1433 | activeManager->setResolver(AR); |
| 1434 | |
Devang Patel | 5bbeb49 | 2006-12-08 22:47:25 +0000 | [diff] [blame] | 1435 | addPassManager(activeManager); |
Devang Patel | 28bbcbe | 2006-12-07 21:44:12 +0000 | [diff] [blame] | 1436 | return activeManager->addPass(P); |
Devang Patel | c290c8a | 2006-11-07 22:23:34 +0000 | [diff] [blame] | 1437 | } |
Devang Patel | 28bbcbe | 2006-12-07 21:44:12 +0000 | [diff] [blame] | 1438 | return true; |
Devang Patel | c290c8a | 2006-11-07 22:23:34 +0000 | [diff] [blame] | 1439 | } |
| 1440 | |
| 1441 | /// run - Execute all of the passes scheduled for execution. Keep track of |
| 1442 | /// 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] | 1443 | bool PassManagerImpl_New::run(Module &M) { |
Devang Patel | c290c8a | 2006-11-07 22:23:34 +0000 | [diff] [blame] | 1444 | |
Devang Patel | c290c8a | 2006-11-07 22:23:34 +0000 | [diff] [blame] | 1445 | bool Changed = false; |
Devang Patel | f1567a5 | 2006-12-13 20:03:48 +0000 | [diff] [blame] | 1446 | |
Devang Patel | b8817b9 | 2006-12-14 00:59:42 +0000 | [diff] [blame] | 1447 | TimingInfo::createTheTimeInfo(); |
| 1448 | |
Devang Patel | cfd70c4 | 2006-12-13 22:10:00 +0000 | [diff] [blame] | 1449 | dumpArguments(); |
Devang Patel | 03fb587 | 2006-12-13 21:13:31 +0000 | [diff] [blame] | 1450 | if (PassDebugging_New >= Structure) |
Devang Patel | f1567a5 | 2006-12-13 20:03:48 +0000 | [diff] [blame] | 1451 | dumpPasses(); |
| 1452 | |
Devang Patel | 5bbeb49 | 2006-12-08 22:47:25 +0000 | [diff] [blame] | 1453 | for (std::vector<Pass *>::iterator I = passManagersBegin(), |
| 1454 | E = passManagersEnd(); I != E; ++I) { |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 1455 | ModulePassManager *MP = dynamic_cast<ModulePassManager *>(*I); |
Devang Patel | 5bbeb49 | 2006-12-08 22:47:25 +0000 | [diff] [blame] | 1456 | Changed |= MP->runOnModule(M); |
Devang Patel | c290c8a | 2006-11-07 22:23:34 +0000 | [diff] [blame] | 1457 | } |
| 1458 | return Changed; |
| 1459 | } |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 1460 | |
Devang Patel | a1514cb | 2006-12-07 19:39:39 +0000 | [diff] [blame] | 1461 | //===----------------------------------------------------------------------===// |
| 1462 | // PassManager implementation |
| 1463 | |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 1464 | /// Create new pass manager |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 1465 | PassManager::PassManager() { |
Devang Patel | 4c36e6b | 2006-12-07 23:24:58 +0000 | [diff] [blame] | 1466 | PM = new PassManagerImpl_New(0); |
Devang Patel | 9c6290c | 2006-12-12 22:02:16 +0000 | [diff] [blame] | 1467 | // PM is the top level manager |
| 1468 | PM->setTopLevelManager(PM); |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 1469 | } |
| 1470 | |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 1471 | PassManager::~PassManager() { |
Devang Patel | ab97cf4 | 2006-12-13 00:09:23 +0000 | [diff] [blame] | 1472 | delete PM; |
| 1473 | } |
| 1474 | |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 1475 | /// add - Add a pass to the queue of passes to run. This passes ownership of |
| 1476 | /// the Pass to the PassManager. When the PassManager is destroyed, the pass |
| 1477 | /// will be destroyed as well, so there is no need to delete the pass. This |
| 1478 | /// implies that all passes MUST be allocated with 'new'. |
| 1479 | void |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 1480 | PassManager::add(Pass *P) { |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 1481 | PM->add(P); |
| 1482 | } |
| 1483 | |
| 1484 | /// run - Execute all of the passes scheduled for execution. Keep track of |
| 1485 | /// whether any of the passes modifies the module, and if so, return true. |
| 1486 | bool |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 1487 | PassManager::run(Module &M) { |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 1488 | return PM->run(M); |
| 1489 | } |
| 1490 | |
Devang Patel | b8817b9 | 2006-12-14 00:59:42 +0000 | [diff] [blame] | 1491 | //===----------------------------------------------------------------------===// |
| 1492 | // TimingInfo Class - This class is used to calculate information about the |
| 1493 | // amount of time each pass takes to execute. This only happens with |
| 1494 | // -time-passes is enabled on the command line. |
| 1495 | // |
| 1496 | bool llvm::TimePassesIsEnabled = false; |
| 1497 | static cl::opt<bool,true> |
| 1498 | EnableTiming("time-passes", cl::location(TimePassesIsEnabled), |
| 1499 | cl::desc("Time each pass, printing elapsed time for each on exit")); |
| 1500 | |
| 1501 | // createTheTimeInfo - This method either initializes the TheTimeInfo pointer to |
| 1502 | // a non null value (if the -time-passes option is enabled) or it leaves it |
| 1503 | // null. It may be called multiple times. |
| 1504 | void TimingInfo::createTheTimeInfo() { |
| 1505 | if (!TimePassesIsEnabled || TheTimeInfo) return; |
| 1506 | |
| 1507 | // Constructed the first time this is called, iff -time-passes is enabled. |
| 1508 | // This guarantees that the object will be constructed before static globals, |
| 1509 | // thus it will be destroyed before them. |
| 1510 | static ManagedStatic<TimingInfo> TTI; |
| 1511 | TheTimeInfo = &*TTI; |
| 1512 | } |
| 1513 | |
Devang Patel | b67904d | 2006-12-13 02:36:01 +0000 | [diff] [blame] | 1514 | #endif |