Chris Lattner | 3e58d9b | 2003-10-13 05:33:01 +0000 | [diff] [blame] | 1 | //===- Pass.cpp - LLVM Pass Infrastructure Implementation -----------------===// |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 2 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 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 | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 7 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | d695328 | 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 | ee335e3 | 2008-05-23 20:40:06 +0000 | [diff] [blame] | 16 | #include "llvm/Pass.h" |
Nico Weber | 0f38c60 | 2018-04-30 14:59:11 +0000 | [diff] [blame] | 17 | #include "llvm/Config/llvm-config.h" |
Eugene Zelenko | 9797e4a | 2017-09-06 23:05:38 +0000 | [diff] [blame] | 18 | #include "llvm/IR/Attributes.h" |
| 19 | #include "llvm/IR/BasicBlock.h" |
Paul Robinson | 2684ddd | 2014-02-06 00:07:05 +0000 | [diff] [blame] | 20 | #include "llvm/IR/Function.h" |
Chandler Carruth | 8a5351f | 2014-01-12 11:10:32 +0000 | [diff] [blame] | 21 | #include "llvm/IR/IRPrintingPasses.h" |
Eugene Zelenko | 9797e4a | 2017-09-06 23:05:38 +0000 | [diff] [blame] | 22 | #include "llvm/IR/LLVMContext.h" |
Chandler Carruth | f7591dd | 2014-03-04 12:32:42 +0000 | [diff] [blame] | 23 | #include "llvm/IR/LegacyPassNameParser.h" |
Andrew Kaylor | 1e455c5 | 2016-04-22 22:06:11 +0000 | [diff] [blame] | 24 | #include "llvm/IR/Module.h" |
| 25 | #include "llvm/IR/OptBisect.h" |
Eugene Zelenko | 9797e4a | 2017-09-06 23:05:38 +0000 | [diff] [blame] | 26 | #include "llvm/PassInfo.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 27 | #include "llvm/PassRegistry.h" |
Eugene Zelenko | 9797e4a | 2017-09-06 23:05:38 +0000 | [diff] [blame] | 28 | #include "llvm/PassSupport.h" |
| 29 | #include "llvm/Support/Compiler.h" |
David Greene | 840d41e | 2010-01-05 01:30:04 +0000 | [diff] [blame] | 30 | #include "llvm/Support/Debug.h" |
Chris Lattner | 45cfe54 | 2009-08-23 06:03:38 +0000 | [diff] [blame] | 31 | #include "llvm/Support/raw_ostream.h" |
Eugene Zelenko | 9797e4a | 2017-09-06 23:05:38 +0000 | [diff] [blame] | 32 | #include <cassert> |
| 33 | |
Chris Lattner | 31f8499 | 2003-11-21 20:23:48 +0000 | [diff] [blame] | 34 | using namespace llvm; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 35 | |
Chandler Carruth | 283b399 | 2014-04-21 22:55:11 +0000 | [diff] [blame] | 36 | #define DEBUG_TYPE "ir" |
| 37 | |
Chris Lattner | 27ad137 | 2002-05-06 19:31:52 +0000 | [diff] [blame] | 38 | //===----------------------------------------------------------------------===// |
Chris Lattner | 4130086 | 2002-01-31 00:45:31 +0000 | [diff] [blame] | 39 | // Pass Implementation |
Chris Lattner | 35f07eb | 2002-01-22 00:17:48 +0000 | [diff] [blame] | 40 | // |
Chris Lattner | 4130086 | 2002-01-31 00:45:31 +0000 | [diff] [blame] | 41 | |
Devang Patel | c7d0f4b | 2006-12-22 22:49:00 +0000 | [diff] [blame] | 42 | // Force out-of-line virtual method. |
Andrew Trick | 8247e0d | 2012-02-03 05:12:30 +0000 | [diff] [blame] | 43 | Pass::~Pass() { |
| 44 | delete Resolver; |
Devang Patel | 6e21ff0 | 2007-04-26 21:33:42 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | // Force out-of-line virtual method. |
Eugene Zelenko | 9797e4a | 2017-09-06 23:05:38 +0000 | [diff] [blame] | 48 | ModulePass::~ModulePass() = default; |
Chris Lattner | d695328 | 2002-01-21 07:37:31 +0000 | [diff] [blame] | 49 | |
Eugene Zelenko | 9797e4a | 2017-09-06 23:05:38 +0000 | [diff] [blame] | 50 | Pass *ModulePass::createPrinterPass(raw_ostream &OS, |
David Greene | 5c8aa95 | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 51 | const std::string &Banner) const { |
Eugene Zelenko | 9797e4a | 2017-09-06 23:05:38 +0000 | [diff] [blame] | 52 | return createPrintModulePass(OS, Banner); |
David Greene | 5c8aa95 | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Dan Gohman | eda23fa | 2009-12-14 19:43:09 +0000 | [diff] [blame] | 55 | PassManagerType ModulePass::getPotentialPassManagerType() const { |
| 56 | return PMT_ModulePassManager; |
| 57 | } |
| 58 | |
Andrew Kaylor | 1e455c5 | 2016-04-22 22:06:11 +0000 | [diff] [blame] | 59 | bool ModulePass::skipModule(Module &M) const { |
Fedor Sergeev | 558f76f | 2018-03-27 16:57:20 +0000 | [diff] [blame] | 60 | return !M.getContext().getOptPassGate().shouldRunPass(this, M); |
Andrew Kaylor | 1e455c5 | 2016-04-22 22:06:11 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Owen Anderson | 90c579d | 2010-08-06 18:33:48 +0000 | [diff] [blame] | 63 | bool Pass::mustPreserveAnalysisID(char &AID) const { |
Craig Topper | ec0f0bc | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 64 | return Resolver->getAnalysisIfAvailable(&AID, true) != nullptr; |
Chris Lattner | f1ab454 | 2003-03-21 21:41:02 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Joe Abbey | 62faf77 | 2011-11-21 04:42:21 +0000 | [diff] [blame] | 67 | // dumpPassStructure - Implement the -debug-pass=Structure option |
Dan Gohman | 8a757ae | 2010-08-19 01:29:07 +0000 | [diff] [blame] | 68 | void Pass::dumpPassStructure(unsigned Offset) { |
David Greene | 840d41e | 2010-01-05 01:30:04 +0000 | [diff] [blame] | 69 | dbgs().indent(Offset*2) << getPassName() << "\n"; |
Chris Lattner | 37d66c4 | 2002-07-30 16:27:02 +0000 | [diff] [blame] | 70 | } |
Chris Lattner | 96c466b | 2002-04-29 14:57:45 +0000 | [diff] [blame] | 71 | |
Dan Gohman | b973d5f | 2008-03-14 18:27:04 +0000 | [diff] [blame] | 72 | /// getPassName - Return a nice clean name for a pass. This usually |
| 73 | /// implemented in terms of the name that is registered by one of the |
| 74 | /// Registration templates, but can be overloaded directly. |
Mehdi Amini | 67f335d | 2016-10-01 02:56:57 +0000 | [diff] [blame] | 75 | StringRef Pass::getPassName() const { |
Owen Anderson | 90c579d | 2010-08-06 18:33:48 +0000 | [diff] [blame] | 76 | AnalysisID AID = getPassID(); |
| 77 | const PassInfo *PI = PassRegistry::getPassRegistry()->getPassInfo(AID); |
| 78 | if (PI) |
Chris Lattner | 44050fb | 2002-07-29 21:02:31 +0000 | [diff] [blame] | 79 | return PI->getPassName(); |
Chris Lattner | fe3e3f4 | 2007-10-18 16:11:18 +0000 | [diff] [blame] | 80 | return "Unnamed pass: implement Pass::getPassName()"; |
Chris Lattner | 44050fb | 2002-07-29 21:02:31 +0000 | [diff] [blame] | 81 | } |
Chris Lattner | 96c466b | 2002-04-29 14:57:45 +0000 | [diff] [blame] | 82 | |
Dan Gohman | eda23fa | 2009-12-14 19:43:09 +0000 | [diff] [blame] | 83 | void Pass::preparePassManager(PMStack &) { |
| 84 | // By default, don't do anything. |
| 85 | } |
| 86 | |
| 87 | PassManagerType Pass::getPotentialPassManagerType() const { |
| 88 | // Default implementation. |
Andrew Trick | 8247e0d | 2012-02-03 05:12:30 +0000 | [diff] [blame] | 89 | return PMT_Unknown; |
Dan Gohman | eda23fa | 2009-12-14 19:43:09 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | void Pass::getAnalysisUsage(AnalysisUsage &) const { |
| 93 | // By default, no analysis results are used, all are invalidated. |
| 94 | } |
| 95 | |
| 96 | void Pass::releaseMemory() { |
| 97 | // By default, don't do anything. |
| 98 | } |
| 99 | |
| 100 | void Pass::verifyAnalysis() const { |
| 101 | // By default, don't do anything. |
| 102 | } |
| 103 | |
Owen Anderson | 90c579d | 2010-08-06 18:33:48 +0000 | [diff] [blame] | 104 | void *Pass::getAdjustedAnalysisPointer(AnalysisID AID) { |
Dan Gohman | e407c1d | 2010-06-21 18:46:45 +0000 | [diff] [blame] | 105 | return this; |
| 106 | } |
| 107 | |
| 108 | ImmutablePass *Pass::getAsImmutablePass() { |
Craig Topper | ec0f0bc | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 109 | return nullptr; |
Dan Gohman | e407c1d | 2010-06-21 18:46:45 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | PMDataManager *Pass::getAsPMDataManager() { |
Craig Topper | ec0f0bc | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 113 | return nullptr; |
Dan Gohman | e407c1d | 2010-06-21 18:46:45 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | void Pass::setResolver(AnalysisResolver *AR) { |
| 117 | assert(!Resolver && "Resolver is already set"); |
| 118 | Resolver = AR; |
| 119 | } |
| 120 | |
Misha Brukman | 69c856a | 2003-10-14 21:38:42 +0000 | [diff] [blame] | 121 | // print - Print out the internal state of the pass. This is called by Analyze |
Misha Brukman | 5560c9d | 2003-08-18 14:43:39 +0000 | [diff] [blame] | 122 | // to print out the contents of an analysis. Otherwise it is not necessary to |
Chris Lattner | a59cbb2 | 2002-07-27 01:12:17 +0000 | [diff] [blame] | 123 | // implement this method. |
Eugene Zelenko | 9797e4a | 2017-09-06 23:05:38 +0000 | [diff] [blame] | 124 | void Pass::print(raw_ostream &OS, const Module *) const { |
| 125 | OS << "Pass::print not implemented for pass: '" << getPassName() << "'!\n"; |
Chris Lattner | a59cbb2 | 2002-07-27 01:12:17 +0000 | [diff] [blame] | 126 | } |
| 127 | |
Aaron Ballman | 1d03d38 | 2017-10-15 14:32:27 +0000 | [diff] [blame] | 128 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
Bill Wendling | 832171c | 2006-12-07 20:04:42 +0000 | [diff] [blame] | 129 | // dump - call print(cerr); |
Yaron Keren | 5530798 | 2016-01-29 20:50:44 +0000 | [diff] [blame] | 130 | LLVM_DUMP_METHOD void Pass::dump() const { |
Craig Topper | ec0f0bc | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 131 | print(dbgs(), nullptr); |
Chris Lattner | a59cbb2 | 2002-07-27 01:12:17 +0000 | [diff] [blame] | 132 | } |
Matthias Braun | 88d2075 | 2017-01-28 02:02:38 +0000 | [diff] [blame] | 133 | #endif |
Chris Lattner | a59cbb2 | 2002-07-27 01:12:17 +0000 | [diff] [blame] | 134 | |
Chris Lattner | 4130086 | 2002-01-31 00:45:31 +0000 | [diff] [blame] | 135 | //===----------------------------------------------------------------------===// |
Chris Lattner | 70b4f3e | 2002-09-25 21:59:11 +0000 | [diff] [blame] | 136 | // ImmutablePass Implementation |
| 137 | // |
Devang Patel | c7d0f4b | 2006-12-22 22:49:00 +0000 | [diff] [blame] | 138 | // Force out-of-line virtual method. |
Eugene Zelenko | 9797e4a | 2017-09-06 23:05:38 +0000 | [diff] [blame] | 139 | ImmutablePass::~ImmutablePass() = default; |
Chris Lattner | 70b4f3e | 2002-09-25 21:59:11 +0000 | [diff] [blame] | 140 | |
Dan Gohman | eda23fa | 2009-12-14 19:43:09 +0000 | [diff] [blame] | 141 | void ImmutablePass::initializePass() { |
| 142 | // By default, don't do anything. |
| 143 | } |
| 144 | |
Chris Lattner | 70b4f3e | 2002-09-25 21:59:11 +0000 | [diff] [blame] | 145 | //===----------------------------------------------------------------------===// |
Chris Lattner | f57b845 | 2002-04-27 06:56:12 +0000 | [diff] [blame] | 146 | // FunctionPass Implementation |
Chris Lattner | d695328 | 2002-01-21 07:37:31 +0000 | [diff] [blame] | 147 | // |
Chris Lattner | 4130086 | 2002-01-31 00:45:31 +0000 | [diff] [blame] | 148 | |
Eugene Zelenko | 9797e4a | 2017-09-06 23:05:38 +0000 | [diff] [blame] | 149 | Pass *FunctionPass::createPrinterPass(raw_ostream &OS, |
David Greene | 5c8aa95 | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 150 | const std::string &Banner) const { |
Eugene Zelenko | 9797e4a | 2017-09-06 23:05:38 +0000 | [diff] [blame] | 151 | return createPrintFunctionPass(OS, Banner); |
David Greene | 5c8aa95 | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Dan Gohman | eda23fa | 2009-12-14 19:43:09 +0000 | [diff] [blame] | 154 | PassManagerType FunctionPass::getPotentialPassManagerType() const { |
| 155 | return PMT_FunctionPassManager; |
| 156 | } |
| 157 | |
Serge Pavlov | 69a1a20 | 2017-01-15 10:23:18 +0000 | [diff] [blame] | 158 | bool FunctionPass::skipFunction(const Function &F) const { |
Fedor Sergeev | 558f76f | 2018-03-27 16:57:20 +0000 | [diff] [blame] | 159 | if (!F.getContext().getOptPassGate().shouldRunPass(this, F)) |
Andrew Kaylor | 1e455c5 | 2016-04-22 22:06:11 +0000 | [diff] [blame] | 160 | return true; |
| 161 | |
Paul Robinson | 2684ddd | 2014-02-06 00:07:05 +0000 | [diff] [blame] | 162 | if (F.hasFnAttribute(Attribute::OptimizeNone)) { |
Nicola Zaghen | 0818e78 | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 163 | LLVM_DEBUG(dbgs() << "Skipping pass '" << getPassName() << "' on function " |
| 164 | << F.getName() << "\n"); |
Paul Robinson | 2684ddd | 2014-02-06 00:07:05 +0000 | [diff] [blame] | 165 | return true; |
| 166 | } |
| 167 | return false; |
| 168 | } |
| 169 | |
Chris Lattner | 4130086 | 2002-01-31 00:45:31 +0000 | [diff] [blame] | 170 | //===----------------------------------------------------------------------===// |
| 171 | // BasicBlockPass Implementation |
| 172 | // |
| 173 | |
Eugene Zelenko | 9797e4a | 2017-09-06 23:05:38 +0000 | [diff] [blame] | 174 | Pass *BasicBlockPass::createPrinterPass(raw_ostream &OS, |
David Greene | 5c8aa95 | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 175 | const std::string &Banner) const { |
Eugene Zelenko | 9797e4a | 2017-09-06 23:05:38 +0000 | [diff] [blame] | 176 | return createPrintBasicBlockPass(OS, Banner); |
David Greene | 5c8aa95 | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Dan Gohman | eda23fa | 2009-12-14 19:43:09 +0000 | [diff] [blame] | 179 | bool BasicBlockPass::doInitialization(Function &) { |
| 180 | // By default, don't do anything. |
| 181 | return false; |
| 182 | } |
| 183 | |
| 184 | bool BasicBlockPass::doFinalization(Function &) { |
| 185 | // By default, don't do anything. |
| 186 | return false; |
| 187 | } |
| 188 | |
Andrew Kaylor | 1e455c5 | 2016-04-22 22:06:11 +0000 | [diff] [blame] | 189 | bool BasicBlockPass::skipBasicBlock(const BasicBlock &BB) const { |
Paul Robinson | cf84b5b | 2014-02-26 01:23:26 +0000 | [diff] [blame] | 190 | const Function *F = BB.getParent(); |
Andrew Kaylor | 1e455c5 | 2016-04-22 22:06:11 +0000 | [diff] [blame] | 191 | if (!F) |
| 192 | return false; |
Fedor Sergeev | 558f76f | 2018-03-27 16:57:20 +0000 | [diff] [blame] | 193 | if (!F->getContext().getOptPassGate().shouldRunPass(this, BB)) |
Andrew Kaylor | 1e455c5 | 2016-04-22 22:06:11 +0000 | [diff] [blame] | 194 | return true; |
| 195 | if (F->hasFnAttribute(Attribute::OptimizeNone)) { |
Paul Robinson | 2684ddd | 2014-02-06 00:07:05 +0000 | [diff] [blame] | 196 | // Report this only once per function. |
| 197 | if (&BB == &F->getEntryBlock()) |
Nicola Zaghen | 0818e78 | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 198 | LLVM_DEBUG(dbgs() << "Skipping pass '" << getPassName() |
| 199 | << "' on function " << F->getName() << "\n"); |
Paul Robinson | 2684ddd | 2014-02-06 00:07:05 +0000 | [diff] [blame] | 200 | return true; |
| 201 | } |
| 202 | return false; |
| 203 | } |
| 204 | |
Dan Gohman | eda23fa | 2009-12-14 19:43:09 +0000 | [diff] [blame] | 205 | PassManagerType BasicBlockPass::getPotentialPassManagerType() const { |
Andrew Trick | 8247e0d | 2012-02-03 05:12:30 +0000 | [diff] [blame] | 206 | return PMT_BasicBlockPassManager; |
Dan Gohman | eda23fa | 2009-12-14 19:43:09 +0000 | [diff] [blame] | 207 | } |
| 208 | |
Owen Anderson | 90c579d | 2010-08-06 18:33:48 +0000 | [diff] [blame] | 209 | const PassInfo *Pass::lookupPassInfo(const void *TI) { |
Owen Anderson | aac07ea | 2010-07-20 21:22:24 +0000 | [diff] [blame] | 210 | return PassRegistry::getPassRegistry()->getPassInfo(TI); |
Chris Lattner | 54bbdb4 | 2002-07-23 18:08:00 +0000 | [diff] [blame] | 211 | } |
| 212 | |
Owen Anderson | 8be3291 | 2010-07-20 08:26:15 +0000 | [diff] [blame] | 213 | const PassInfo *Pass::lookupPassInfo(StringRef Arg) { |
Owen Anderson | aac07ea | 2010-07-20 21:22:24 +0000 | [diff] [blame] | 214 | return PassRegistry::getPassRegistry()->getPassInfo(Arg); |
Dan Gohman | 8a261e4 | 2009-10-08 17:00:02 +0000 | [diff] [blame] | 215 | } |
| 216 | |
Andrew Trick | 5e108ee | 2012-02-15 03:21:47 +0000 | [diff] [blame] | 217 | Pass *Pass::createPass(AnalysisID ID) { |
| 218 | const PassInfo *PI = PassRegistry::getPassRegistry()->getPassInfo(ID); |
Andrew Trick | ebe18ef | 2012-02-08 21:22:34 +0000 | [diff] [blame] | 219 | if (!PI) |
Craig Topper | ec0f0bc | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 220 | return nullptr; |
Andrew Trick | ebe18ef | 2012-02-08 21:22:34 +0000 | [diff] [blame] | 221 | return PI->createPass(); |
| 222 | } |
| 223 | |
Chris Lattner | 789bc84 | 2002-08-21 22:17:09 +0000 | [diff] [blame] | 224 | //===----------------------------------------------------------------------===// |
| 225 | // Analysis Group Implementation Code |
| 226 | //===----------------------------------------------------------------------===// |
| 227 | |
Chris Lattner | 789bc84 | 2002-08-21 22:17:09 +0000 | [diff] [blame] | 228 | // RegisterAGBase implementation |
Eugene Zelenko | 9797e4a | 2017-09-06 23:05:38 +0000 | [diff] [blame] | 229 | |
Mehdi Amini | 6bd185b | 2016-10-01 04:03:30 +0000 | [diff] [blame] | 230 | RegisterAGBase::RegisterAGBase(StringRef Name, const void *InterfaceID, |
Owen Anderson | 90c579d | 2010-08-06 18:33:48 +0000 | [diff] [blame] | 231 | const void *PassID, bool isDefault) |
Owen Anderson | 9650983 | 2010-07-21 17:52:45 +0000 | [diff] [blame] | 232 | : PassInfo(Name, InterfaceID) { |
| 233 | PassRegistry::getPassRegistry()->registerAnalysisGroup(InterfaceID, PassID, |
| 234 | *this, isDefault); |
Chris Lattner | 789bc84 | 2002-08-21 22:17:09 +0000 | [diff] [blame] | 235 | } |
| 236 | |
Chris Lattner | 54bbdb4 | 2002-07-23 18:08:00 +0000 | [diff] [blame] | 237 | //===----------------------------------------------------------------------===// |
| 238 | // PassRegistrationListener implementation |
| 239 | // |
| 240 | |
Chris Lattner | 54bbdb4 | 2002-07-23 18:08:00 +0000 | [diff] [blame] | 241 | // enumeratePasses - Iterate over the registered passes, calling the |
| 242 | // passEnumerate callback on each PassInfo object. |
Chris Lattner | 54bbdb4 | 2002-07-23 18:08:00 +0000 | [diff] [blame] | 243 | void PassRegistrationListener::enumeratePasses() { |
Owen Anderson | aac07ea | 2010-07-20 21:22:24 +0000 | [diff] [blame] | 244 | PassRegistry::getPassRegistry()->enumerateWith(this); |
Chris Lattner | 54bbdb4 | 2002-07-23 18:08:00 +0000 | [diff] [blame] | 245 | } |
Reid Spencer | e8f3848 | 2005-04-25 01:01:35 +0000 | [diff] [blame] | 246 | |
Chris Bieneman | 40a2186 | 2015-01-22 21:01:12 +0000 | [diff] [blame] | 247 | PassNameParser::PassNameParser(cl::Option &O) |
| 248 | : cl::parser<const PassInfo *>(O) { |
Zachary Turner | a4dc93e | 2014-06-12 00:16:36 +0000 | [diff] [blame] | 249 | PassRegistry::getPassRegistry()->addRegistrationListener(this); |
| 250 | } |
| 251 | |
Eugene Zelenko | 9797e4a | 2017-09-06 23:05:38 +0000 | [diff] [blame] | 252 | // This only gets called during static destruction, in which case the |
| 253 | // PassRegistry will have already been destroyed by llvm_shutdown(). So |
| 254 | // attempting to remove the registration listener is an error. |
| 255 | PassNameParser::~PassNameParser() = default; |
Chris Lattner | 6eeb734 | 2010-01-22 06:29:25 +0000 | [diff] [blame] | 256 | |
Chris Lattner | 947c768 | 2006-12-01 22:21:11 +0000 | [diff] [blame] | 257 | //===----------------------------------------------------------------------===// |
| 258 | // AnalysisUsage Class Implementation |
| 259 | // |
| 260 | |
Chris Lattner | baf2ecd | 2006-12-01 23:27:45 +0000 | [diff] [blame] | 261 | namespace { |
Andrew Trick | 8247e0d | 2012-02-03 05:12:30 +0000 | [diff] [blame] | 262 | |
Eugene Zelenko | 9797e4a | 2017-09-06 23:05:38 +0000 | [diff] [blame] | 263 | struct GetCFGOnlyPasses : public PassRegistrationListener { |
| 264 | using VectorType = AnalysisUsage::VectorType; |
| 265 | |
| 266 | VectorType &CFGOnlyList; |
| 267 | |
| 268 | GetCFGOnlyPasses(VectorType &L) : CFGOnlyList(L) {} |
| 269 | |
| 270 | void passEnumerate(const PassInfo *P) override { |
| 271 | if (P->isCFGOnlyPass()) |
| 272 | CFGOnlyList.push_back(P->getTypeInfo()); |
| 273 | } |
| 274 | }; |
| 275 | |
| 276 | } // end anonymous namespace |
Chris Lattner | baf2ecd | 2006-12-01 23:27:45 +0000 | [diff] [blame] | 277 | |
Sylvestre Ledru | 94c2271 | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 278 | // setPreservesCFG - This function should be called to by the pass, iff they do |
Chris Lattner | 947c768 | 2006-12-01 22:21:11 +0000 | [diff] [blame] | 279 | // not: |
| 280 | // |
| 281 | // 1. Add or remove basic blocks from the function |
| 282 | // 2. Modify terminator instructions in any way. |
| 283 | // |
| 284 | // This function annotates the AnalysisUsage info object to say that analyses |
| 285 | // that only depend on the CFG are preserved by this pass. |
Chris Lattner | 947c768 | 2006-12-01 22:21:11 +0000 | [diff] [blame] | 286 | void AnalysisUsage::setPreservesCFG() { |
| 287 | // Since this transformation doesn't modify the CFG, it preserves all analyses |
| 288 | // that only depend on the CFG (like dominators, loop info, etc...) |
Chris Lattner | baf2ecd | 2006-12-01 23:27:45 +0000 | [diff] [blame] | 289 | GetCFGOnlyPasses(Preserved).enumeratePasses(); |
Chris Lattner | 947c768 | 2006-12-01 22:21:11 +0000 | [diff] [blame] | 290 | } |
| 291 | |
Owen Anderson | 90c579d | 2010-08-06 18:33:48 +0000 | [diff] [blame] | 292 | AnalysisUsage &AnalysisUsage::addPreserved(StringRef Arg) { |
| 293 | const PassInfo *PI = Pass::lookupPassInfo(Arg); |
| 294 | // If the pass exists, preserve it. Otherwise silently do nothing. |
| 295 | if (PI) Preserved.push_back(PI->getTypeInfo()); |
| 296 | return *this; |
| 297 | } |
| 298 | |
| 299 | AnalysisUsage &AnalysisUsage::addRequiredID(const void *ID) { |
Dan Gohman | e407c1d | 2010-06-21 18:46:45 +0000 | [diff] [blame] | 300 | Required.push_back(ID); |
| 301 | return *this; |
| 302 | } |
Chris Lattner | 947c768 | 2006-12-01 22:21:11 +0000 | [diff] [blame] | 303 | |
Owen Anderson | 90c579d | 2010-08-06 18:33:48 +0000 | [diff] [blame] | 304 | AnalysisUsage &AnalysisUsage::addRequiredID(char &ID) { |
| 305 | Required.push_back(&ID); |
| 306 | return *this; |
| 307 | } |
| 308 | |
| 309 | AnalysisUsage &AnalysisUsage::addRequiredTransitiveID(char &ID) { |
| 310 | Required.push_back(&ID); |
| 311 | RequiredTransitive.push_back(&ID); |
Dan Gohman | e407c1d | 2010-06-21 18:46:45 +0000 | [diff] [blame] | 312 | return *this; |
| 313 | } |