Chris Lattner | ab16a65 | 2003-10-13 05:33:01 +0000 | [diff] [blame] | 1 | //===- Pass.cpp - LLVM Pass Infrastructure Implementation -----------------===// |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 2 | // |
John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 7 | // |
John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 26e4f89 | 2002-01-21 07:37:31 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file implements the LLVM Pass infrastructure. It is primarily |
| 11 | // responsible with ensuring that passes are executed and batched together |
| 12 | // optimally. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
Dan Gohman | 643b3a0 | 2008-05-23 20:40:06 +0000 | [diff] [blame] | 16 | #include "llvm/Pass.h" |
Paul Robinson | af4e64d | 2014-02-06 00:07:05 +0000 | [diff] [blame] | 17 | #include "llvm/IR/Function.h" |
Chandler Carruth | b8ddc70 | 2014-01-12 11:10:32 +0000 | [diff] [blame] | 18 | #include "llvm/IR/IRPrintingPasses.h" |
Chandler Carruth | 1b69ed8 | 2014-03-04 12:32:42 +0000 | [diff] [blame] | 19 | #include "llvm/IR/LegacyPassNameParser.h" |
Andrew Kaylor | aa641a5 | 2016-04-22 22:06:11 +0000 | [diff] [blame] | 20 | #include "llvm/IR/Module.h" |
| 21 | #include "llvm/IR/OptBisect.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 22 | #include "llvm/PassRegistry.h" |
David Greene | dfe4ad7 | 2010-01-05 01:30:04 +0000 | [diff] [blame] | 23 | #include "llvm/Support/Debug.h" |
Chris Lattner | 1362602 | 2009-08-23 06:03:38 +0000 | [diff] [blame] | 24 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | 189d19f | 2003-11-21 20:23:48 +0000 | [diff] [blame] | 25 | using namespace llvm; |
Brian Gaeke | 960707c | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 26 | |
Chandler Carruth | e96dd89 | 2014-04-21 22:55:11 +0000 | [diff] [blame] | 27 | #define DEBUG_TYPE "ir" |
| 28 | |
Chris Lattner | 7e0dbe6 | 2002-05-06 19:31:52 +0000 | [diff] [blame] | 29 | //===----------------------------------------------------------------------===// |
Chris Lattner | cdd09c2 | 2002-01-31 00:45:31 +0000 | [diff] [blame] | 30 | // Pass Implementation |
Chris Lattner | 654b5bc | 2002-01-22 00:17:48 +0000 | [diff] [blame] | 31 | // |
Chris Lattner | cdd09c2 | 2002-01-31 00:45:31 +0000 | [diff] [blame] | 32 | |
Devang Patel | f5a994e | 2006-12-22 22:49:00 +0000 | [diff] [blame] | 33 | // Force out-of-line virtual method. |
Andrew Trick | 808a7a6 | 2012-02-03 05:12:30 +0000 | [diff] [blame] | 34 | Pass::~Pass() { |
| 35 | delete Resolver; |
Devang Patel | 2c1bba0 | 2007-04-26 21:33:42 +0000 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | // Force out-of-line virtual method. |
Devang Patel | f5a994e | 2006-12-22 22:49:00 +0000 | [diff] [blame] | 39 | ModulePass::~ModulePass() { } |
Chris Lattner | 26e4f89 | 2002-01-21 07:37:31 +0000 | [diff] [blame] | 40 | |
David Greene | 9b063df | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 41 | Pass *ModulePass::createPrinterPass(raw_ostream &O, |
| 42 | const std::string &Banner) const { |
Chandler Carruth | 9d80513 | 2014-01-12 11:30:46 +0000 | [diff] [blame] | 43 | return createPrintModulePass(O, Banner); |
David Greene | 9b063df | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Dan Gohman | 1cfbfc8 | 2009-12-14 19:43:09 +0000 | [diff] [blame] | 46 | PassManagerType ModulePass::getPotentialPassManagerType() const { |
| 47 | return PMT_ModulePassManager; |
| 48 | } |
| 49 | |
Andrew Kaylor | aa641a5 | 2016-04-22 22:06:11 +0000 | [diff] [blame] | 50 | bool ModulePass::skipModule(Module &M) const { |
| 51 | return !M.getContext().getOptBisect().shouldRunPass(this, M); |
| 52 | } |
| 53 | |
Owen Anderson | a7aed18 | 2010-08-06 18:33:48 +0000 | [diff] [blame] | 54 | bool Pass::mustPreserveAnalysisID(char &AID) const { |
Craig Topper | c620761 | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 55 | return Resolver->getAnalysisIfAvailable(&AID, true) != nullptr; |
Chris Lattner | 9ad7757 | 2003-03-21 21:41:02 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Joe Abbey | 96e89f6 | 2011-11-21 04:42:21 +0000 | [diff] [blame] | 58 | // dumpPassStructure - Implement the -debug-pass=Structure option |
Dan Gohman | f71c521 | 2010-08-19 01:29:07 +0000 | [diff] [blame] | 59 | void Pass::dumpPassStructure(unsigned Offset) { |
David Greene | dfe4ad7 | 2010-01-05 01:30:04 +0000 | [diff] [blame] | 60 | dbgs().indent(Offset*2) << getPassName() << "\n"; |
Chris Lattner | 198cf42 | 2002-07-30 16:27:02 +0000 | [diff] [blame] | 61 | } |
Chris Lattner | 37104aa | 2002-04-29 14:57:45 +0000 | [diff] [blame] | 62 | |
Dan Gohman | 94f57c5 | 2008-03-14 18:27:04 +0000 | [diff] [blame] | 63 | /// getPassName - Return a nice clean name for a pass. This usually |
| 64 | /// implemented in terms of the name that is registered by one of the |
| 65 | /// Registration templates, but can be overloaded directly. |
| 66 | /// |
Mehdi Amini | 117296c | 2016-10-01 02:56:57 +0000 | [diff] [blame] | 67 | StringRef Pass::getPassName() const { |
Owen Anderson | a7aed18 | 2010-08-06 18:33:48 +0000 | [diff] [blame] | 68 | AnalysisID AID = getPassID(); |
| 69 | const PassInfo *PI = PassRegistry::getPassRegistry()->getPassInfo(AID); |
| 70 | if (PI) |
Chris Lattner | 071577d | 2002-07-29 21:02:31 +0000 | [diff] [blame] | 71 | return PI->getPassName(); |
Chris Lattner | 9afb8e4 | 2007-10-18 16:11:18 +0000 | [diff] [blame] | 72 | return "Unnamed pass: implement Pass::getPassName()"; |
Chris Lattner | 071577d | 2002-07-29 21:02:31 +0000 | [diff] [blame] | 73 | } |
Chris Lattner | 37104aa | 2002-04-29 14:57:45 +0000 | [diff] [blame] | 74 | |
Dan Gohman | 1cfbfc8 | 2009-12-14 19:43:09 +0000 | [diff] [blame] | 75 | void Pass::preparePassManager(PMStack &) { |
| 76 | // By default, don't do anything. |
| 77 | } |
| 78 | |
| 79 | PassManagerType Pass::getPotentialPassManagerType() const { |
| 80 | // Default implementation. |
Andrew Trick | 808a7a6 | 2012-02-03 05:12:30 +0000 | [diff] [blame] | 81 | return PMT_Unknown; |
Dan Gohman | 1cfbfc8 | 2009-12-14 19:43:09 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | void Pass::getAnalysisUsage(AnalysisUsage &) const { |
| 85 | // By default, no analysis results are used, all are invalidated. |
| 86 | } |
| 87 | |
| 88 | void Pass::releaseMemory() { |
| 89 | // By default, don't do anything. |
| 90 | } |
| 91 | |
| 92 | void Pass::verifyAnalysis() const { |
| 93 | // By default, don't do anything. |
| 94 | } |
| 95 | |
Owen Anderson | a7aed18 | 2010-08-06 18:33:48 +0000 | [diff] [blame] | 96 | void *Pass::getAdjustedAnalysisPointer(AnalysisID AID) { |
Dan Gohman | ffdee30 | 2010-06-21 18:46:45 +0000 | [diff] [blame] | 97 | return this; |
| 98 | } |
| 99 | |
| 100 | ImmutablePass *Pass::getAsImmutablePass() { |
Craig Topper | c620761 | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 101 | return nullptr; |
Dan Gohman | ffdee30 | 2010-06-21 18:46:45 +0000 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | PMDataManager *Pass::getAsPMDataManager() { |
Craig Topper | c620761 | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 105 | return nullptr; |
Dan Gohman | ffdee30 | 2010-06-21 18:46:45 +0000 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | void Pass::setResolver(AnalysisResolver *AR) { |
| 109 | assert(!Resolver && "Resolver is already set"); |
| 110 | Resolver = AR; |
| 111 | } |
| 112 | |
Misha Brukman | 56a8642 | 2003-10-14 21:38:42 +0000 | [diff] [blame] | 113 | // print - Print out the internal state of the pass. This is called by Analyze |
Misha Brukman | 7eb05a1 | 2003-08-18 14:43:39 +0000 | [diff] [blame] | 114 | // to print out the contents of an analysis. Otherwise it is not necessary to |
Chris Lattner | 2675007 | 2002-07-27 01:12:17 +0000 | [diff] [blame] | 115 | // implement this method. |
| 116 | // |
Chris Lattner | 1362602 | 2009-08-23 06:03:38 +0000 | [diff] [blame] | 117 | void Pass::print(raw_ostream &O,const Module*) const { |
Chris Lattner | 2675007 | 2002-07-27 01:12:17 +0000 | [diff] [blame] | 118 | O << "Pass::print not implemented for pass: '" << getPassName() << "'!\n"; |
| 119 | } |
| 120 | |
Matthias Braun | 8c209aa | 2017-01-28 02:02:38 +0000 | [diff] [blame] | 121 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
Bill Wendling | 22e978a | 2006-12-07 20:04:42 +0000 | [diff] [blame] | 122 | // dump - call print(cerr); |
Yaron Keren | eb2a254 | 2016-01-29 20:50:44 +0000 | [diff] [blame] | 123 | LLVM_DUMP_METHOD void Pass::dump() const { |
Craig Topper | c620761 | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 124 | print(dbgs(), nullptr); |
Chris Lattner | 2675007 | 2002-07-27 01:12:17 +0000 | [diff] [blame] | 125 | } |
Matthias Braun | 8c209aa | 2017-01-28 02:02:38 +0000 | [diff] [blame] | 126 | #endif |
Chris Lattner | 2675007 | 2002-07-27 01:12:17 +0000 | [diff] [blame] | 127 | |
Chris Lattner | cdd09c2 | 2002-01-31 00:45:31 +0000 | [diff] [blame] | 128 | //===----------------------------------------------------------------------===// |
Chris Lattner | ee0788d | 2002-09-25 21:59:11 +0000 | [diff] [blame] | 129 | // ImmutablePass Implementation |
| 130 | // |
Devang Patel | f5a994e | 2006-12-22 22:49:00 +0000 | [diff] [blame] | 131 | // Force out-of-line virtual method. |
| 132 | ImmutablePass::~ImmutablePass() { } |
Chris Lattner | ee0788d | 2002-09-25 21:59:11 +0000 | [diff] [blame] | 133 | |
Dan Gohman | 1cfbfc8 | 2009-12-14 19:43:09 +0000 | [diff] [blame] | 134 | void ImmutablePass::initializePass() { |
| 135 | // By default, don't do anything. |
| 136 | } |
| 137 | |
Chris Lattner | ee0788d | 2002-09-25 21:59:11 +0000 | [diff] [blame] | 138 | //===----------------------------------------------------------------------===// |
Chris Lattner | c8e6654 | 2002-04-27 06:56:12 +0000 | [diff] [blame] | 139 | // FunctionPass Implementation |
Chris Lattner | 26e4f89 | 2002-01-21 07:37:31 +0000 | [diff] [blame] | 140 | // |
Chris Lattner | cdd09c2 | 2002-01-31 00:45:31 +0000 | [diff] [blame] | 141 | |
David Greene | 9b063df | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 142 | Pass *FunctionPass::createPrinterPass(raw_ostream &O, |
| 143 | const std::string &Banner) const { |
Chandler Carruth | 9d80513 | 2014-01-12 11:30:46 +0000 | [diff] [blame] | 144 | return createPrintFunctionPass(O, Banner); |
David Greene | 9b063df | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Dan Gohman | 1cfbfc8 | 2009-12-14 19:43:09 +0000 | [diff] [blame] | 147 | PassManagerType FunctionPass::getPotentialPassManagerType() const { |
| 148 | return PMT_FunctionPassManager; |
| 149 | } |
| 150 | |
Serge Pavlov | ed5eb93 | 2017-01-15 10:23:18 +0000 | [diff] [blame] | 151 | bool FunctionPass::skipFunction(const Function &F) const { |
| 152 | if (!F.getContext().getOptBisect().shouldRunPass(this, F)) |
Andrew Kaylor | aa641a5 | 2016-04-22 22:06:11 +0000 | [diff] [blame] | 153 | return true; |
| 154 | |
Paul Robinson | af4e64d | 2014-02-06 00:07:05 +0000 | [diff] [blame] | 155 | if (F.hasFnAttribute(Attribute::OptimizeNone)) { |
Andrew Kaylor | aa641a5 | 2016-04-22 22:06:11 +0000 | [diff] [blame] | 156 | DEBUG(dbgs() << "Skipping pass '" << getPassName() << "' on function " |
| 157 | << F.getName() << "\n"); |
Paul Robinson | af4e64d | 2014-02-06 00:07:05 +0000 | [diff] [blame] | 158 | return true; |
| 159 | } |
| 160 | return false; |
| 161 | } |
| 162 | |
Chris Lattner | cdd09c2 | 2002-01-31 00:45:31 +0000 | [diff] [blame] | 163 | //===----------------------------------------------------------------------===// |
| 164 | // BasicBlockPass Implementation |
| 165 | // |
| 166 | |
David Greene | 9b063df | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 167 | Pass *BasicBlockPass::createPrinterPass(raw_ostream &O, |
| 168 | const std::string &Banner) const { |
Chandler Carruth | 9d80513 | 2014-01-12 11:30:46 +0000 | [diff] [blame] | 169 | return createPrintBasicBlockPass(O, Banner); |
David Greene | 9b063df | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Dan Gohman | 1cfbfc8 | 2009-12-14 19:43:09 +0000 | [diff] [blame] | 172 | bool BasicBlockPass::doInitialization(Function &) { |
| 173 | // By default, don't do anything. |
| 174 | return false; |
| 175 | } |
| 176 | |
| 177 | bool BasicBlockPass::doFinalization(Function &) { |
| 178 | // By default, don't do anything. |
| 179 | return false; |
| 180 | } |
| 181 | |
Andrew Kaylor | aa641a5 | 2016-04-22 22:06:11 +0000 | [diff] [blame] | 182 | bool BasicBlockPass::skipBasicBlock(const BasicBlock &BB) const { |
Paul Robinson | 0c12b1d2 | 2014-02-26 01:23:26 +0000 | [diff] [blame] | 183 | const Function *F = BB.getParent(); |
Andrew Kaylor | aa641a5 | 2016-04-22 22:06:11 +0000 | [diff] [blame] | 184 | if (!F) |
| 185 | return false; |
| 186 | if (!F->getContext().getOptBisect().shouldRunPass(this, BB)) |
| 187 | return true; |
| 188 | if (F->hasFnAttribute(Attribute::OptimizeNone)) { |
Paul Robinson | af4e64d | 2014-02-06 00:07:05 +0000 | [diff] [blame] | 189 | // Report this only once per function. |
| 190 | if (&BB == &F->getEntryBlock()) |
| 191 | DEBUG(dbgs() << "Skipping pass '" << getPassName() |
| 192 | << "' on function " << F->getName() << "\n"); |
| 193 | return true; |
| 194 | } |
| 195 | return false; |
| 196 | } |
| 197 | |
Dan Gohman | 1cfbfc8 | 2009-12-14 19:43:09 +0000 | [diff] [blame] | 198 | PassManagerType BasicBlockPass::getPotentialPassManagerType() const { |
Andrew Trick | 808a7a6 | 2012-02-03 05:12:30 +0000 | [diff] [blame] | 199 | return PMT_BasicBlockPassManager; |
Dan Gohman | 1cfbfc8 | 2009-12-14 19:43:09 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Owen Anderson | a7aed18 | 2010-08-06 18:33:48 +0000 | [diff] [blame] | 202 | const PassInfo *Pass::lookupPassInfo(const void *TI) { |
Owen Anderson | 4154061 | 2010-07-20 21:22:24 +0000 | [diff] [blame] | 203 | return PassRegistry::getPassRegistry()->getPassInfo(TI); |
Chris Lattner | 37d3c95 | 2002-07-23 18:08:00 +0000 | [diff] [blame] | 204 | } |
| 205 | |
Owen Anderson | 8178122 | 2010-07-20 08:26:15 +0000 | [diff] [blame] | 206 | const PassInfo *Pass::lookupPassInfo(StringRef Arg) { |
Owen Anderson | 4154061 | 2010-07-20 21:22:24 +0000 | [diff] [blame] | 207 | return PassRegistry::getPassRegistry()->getPassInfo(Arg); |
Dan Gohman | 0998427 | 2009-10-08 17:00:02 +0000 | [diff] [blame] | 208 | } |
| 209 | |
Andrew Trick | c9ce9d2 | 2012-02-15 03:21:47 +0000 | [diff] [blame] | 210 | Pass *Pass::createPass(AnalysisID ID) { |
| 211 | const PassInfo *PI = PassRegistry::getPassRegistry()->getPassInfo(ID); |
Andrew Trick | 3a61b78 | 2012-02-08 21:22:34 +0000 | [diff] [blame] | 212 | if (!PI) |
Craig Topper | c620761 | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 213 | return nullptr; |
Andrew Trick | 3a61b78 | 2012-02-08 21:22:34 +0000 | [diff] [blame] | 214 | return PI->createPass(); |
| 215 | } |
| 216 | |
Chris Lattner | 6e041bd | 2002-08-21 22:17:09 +0000 | [diff] [blame] | 217 | //===----------------------------------------------------------------------===// |
| 218 | // Analysis Group Implementation Code |
| 219 | //===----------------------------------------------------------------------===// |
| 220 | |
Chris Lattner | 6e041bd | 2002-08-21 22:17:09 +0000 | [diff] [blame] | 221 | // RegisterAGBase implementation |
| 222 | // |
Mehdi Amini | f20abe5 | 2016-10-01 04:03:30 +0000 | [diff] [blame] | 223 | RegisterAGBase::RegisterAGBase(StringRef Name, const void *InterfaceID, |
Owen Anderson | a7aed18 | 2010-08-06 18:33:48 +0000 | [diff] [blame] | 224 | const void *PassID, bool isDefault) |
Owen Anderson | 845b14e | 2010-07-21 17:52:45 +0000 | [diff] [blame] | 225 | : PassInfo(Name, InterfaceID) { |
| 226 | PassRegistry::getPassRegistry()->registerAnalysisGroup(InterfaceID, PassID, |
| 227 | *this, isDefault); |
Chris Lattner | 6e041bd | 2002-08-21 22:17:09 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Chris Lattner | 37d3c95 | 2002-07-23 18:08:00 +0000 | [diff] [blame] | 230 | //===----------------------------------------------------------------------===// |
| 231 | // PassRegistrationListener implementation |
| 232 | // |
| 233 | |
Chris Lattner | 37d3c95 | 2002-07-23 18:08:00 +0000 | [diff] [blame] | 234 | // enumeratePasses - Iterate over the registered passes, calling the |
| 235 | // passEnumerate callback on each PassInfo object. |
| 236 | // |
| 237 | void PassRegistrationListener::enumeratePasses() { |
Owen Anderson | 4154061 | 2010-07-20 21:22:24 +0000 | [diff] [blame] | 238 | PassRegistry::getPassRegistry()->enumerateWith(this); |
Chris Lattner | 37d3c95 | 2002-07-23 18:08:00 +0000 | [diff] [blame] | 239 | } |
Reid Spencer | 8edc8be | 2005-04-25 01:01:35 +0000 | [diff] [blame] | 240 | |
Chris Bieneman | 799ef37 | 2015-01-22 21:01:12 +0000 | [diff] [blame] | 241 | PassNameParser::PassNameParser(cl::Option &O) |
| 242 | : cl::parser<const PassInfo *>(O) { |
Zachary Turner | 39c422d | 2014-06-12 00:16:36 +0000 | [diff] [blame] | 243 | PassRegistry::getPassRegistry()->addRegistrationListener(this); |
| 244 | } |
| 245 | |
| 246 | PassNameParser::~PassNameParser() { |
| 247 | // This only gets called during static destruction, in which case the |
| 248 | // PassRegistry will have already been destroyed by llvm_shutdown(). So |
| 249 | // attempting to remove the registration listener is an error. |
| 250 | } |
Chris Lattner | 5264fce | 2010-01-22 06:29:25 +0000 | [diff] [blame] | 251 | |
Chris Lattner | 23d5405 | 2006-12-01 22:21:11 +0000 | [diff] [blame] | 252 | //===----------------------------------------------------------------------===// |
| 253 | // AnalysisUsage Class Implementation |
| 254 | // |
| 255 | |
Chris Lattner | 1b368a0 | 2006-12-01 23:27:45 +0000 | [diff] [blame] | 256 | namespace { |
| 257 | struct GetCFGOnlyPasses : public PassRegistrationListener { |
Chris Lattner | cbd160f | 2008-08-08 05:33:04 +0000 | [diff] [blame] | 258 | typedef AnalysisUsage::VectorType VectorType; |
| 259 | VectorType &CFGOnlyList; |
| 260 | GetCFGOnlyPasses(VectorType &L) : CFGOnlyList(L) {} |
Andrew Trick | 808a7a6 | 2012-02-03 05:12:30 +0000 | [diff] [blame] | 261 | |
Craig Topper | f398d7c | 2014-03-05 06:35:38 +0000 | [diff] [blame] | 262 | void passEnumerate(const PassInfo *P) override { |
Chris Lattner | 1b368a0 | 2006-12-01 23:27:45 +0000 | [diff] [blame] | 263 | if (P->isCFGOnlyPass()) |
Owen Anderson | a7aed18 | 2010-08-06 18:33:48 +0000 | [diff] [blame] | 264 | CFGOnlyList.push_back(P->getTypeInfo()); |
Chris Lattner | 1b368a0 | 2006-12-01 23:27:45 +0000 | [diff] [blame] | 265 | } |
| 266 | }; |
Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 267 | } |
Chris Lattner | 1b368a0 | 2006-12-01 23:27:45 +0000 | [diff] [blame] | 268 | |
Sylvestre Ledru | 91ce36c | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 269 | // setPreservesCFG - This function should be called to by the pass, iff they do |
Chris Lattner | 23d5405 | 2006-12-01 22:21:11 +0000 | [diff] [blame] | 270 | // not: |
| 271 | // |
| 272 | // 1. Add or remove basic blocks from the function |
| 273 | // 2. Modify terminator instructions in any way. |
| 274 | // |
| 275 | // This function annotates the AnalysisUsage info object to say that analyses |
| 276 | // that only depend on the CFG are preserved by this pass. |
| 277 | // |
| 278 | void AnalysisUsage::setPreservesCFG() { |
| 279 | // Since this transformation doesn't modify the CFG, it preserves all analyses |
| 280 | // that only depend on the CFG (like dominators, loop info, etc...) |
Chris Lattner | 1b368a0 | 2006-12-01 23:27:45 +0000 | [diff] [blame] | 281 | GetCFGOnlyPasses(Preserved).enumeratePasses(); |
Chris Lattner | 23d5405 | 2006-12-01 22:21:11 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Owen Anderson | a7aed18 | 2010-08-06 18:33:48 +0000 | [diff] [blame] | 284 | AnalysisUsage &AnalysisUsage::addPreserved(StringRef Arg) { |
| 285 | const PassInfo *PI = Pass::lookupPassInfo(Arg); |
| 286 | // If the pass exists, preserve it. Otherwise silently do nothing. |
| 287 | if (PI) Preserved.push_back(PI->getTypeInfo()); |
| 288 | return *this; |
| 289 | } |
| 290 | |
| 291 | AnalysisUsage &AnalysisUsage::addRequiredID(const void *ID) { |
Dan Gohman | ffdee30 | 2010-06-21 18:46:45 +0000 | [diff] [blame] | 292 | Required.push_back(ID); |
| 293 | return *this; |
| 294 | } |
Chris Lattner | 23d5405 | 2006-12-01 22:21:11 +0000 | [diff] [blame] | 295 | |
Owen Anderson | a7aed18 | 2010-08-06 18:33:48 +0000 | [diff] [blame] | 296 | AnalysisUsage &AnalysisUsage::addRequiredID(char &ID) { |
| 297 | Required.push_back(&ID); |
| 298 | return *this; |
| 299 | } |
| 300 | |
| 301 | AnalysisUsage &AnalysisUsage::addRequiredTransitiveID(char &ID) { |
| 302 | Required.push_back(&ID); |
| 303 | RequiredTransitive.push_back(&ID); |
Dan Gohman | ffdee30 | 2010-06-21 18:46:45 +0000 | [diff] [blame] | 304 | return *this; |
| 305 | } |