| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 1 | //===- PassManagerBuilder.cpp - Build Standard Pass -----------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the PassManagerBuilder class, which is used to set up a |
| 11 | // "standard" optimization sequence suitable for languages like C and C++. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 15 | #include "llvm/Transforms/IPO/PassManagerBuilder.h" |
| Rafael Espindola | 07f60915 | 2011-08-09 22:17:34 +0000 | [diff] [blame] | 16 | #include "llvm-c/Transforms/PassManagerBuilder.h" |
| Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/SmallVector.h" |
| Chandler Carruth | 17e0bc3 | 2015-08-06 07:33:15 +0000 | [diff] [blame] | 18 | #include "llvm/Analysis/BasicAliasAnalysis.h" |
| Chandler Carruth | 8b046a4 | 2015-08-14 02:42:20 +0000 | [diff] [blame] | 19 | #include "llvm/Analysis/CFLAliasAnalysis.h" |
| Chandler Carruth | 21dcff7 | 2015-08-14 03:48:20 +0000 | [diff] [blame] | 20 | #include "llvm/Analysis/GlobalsModRef.h" |
| Chandler Carruth | 3a040e6 | 2015-12-27 08:41:34 +0000 | [diff] [blame] | 21 | #include "llvm/Analysis/Passes.h" |
| Chandler Carruth | 42ff448 | 2015-08-14 02:55:50 +0000 | [diff] [blame] | 22 | #include "llvm/Analysis/ScopedNoAliasAA.h" |
| Chandler Carruth | 62d4215 | 2015-01-15 02:16:27 +0000 | [diff] [blame] | 23 | #include "llvm/Analysis/TargetLibraryInfo.h" |
| Chandler Carruth | 1db2282 | 2015-08-14 03:33:48 +0000 | [diff] [blame] | 24 | #include "llvm/Analysis/TypeBasedAliasAnalysis.h" |
| Chandler Carruth | 3a040e6 | 2015-12-27 08:41:34 +0000 | [diff] [blame] | 25 | #include "llvm/IR/DataLayout.h" |
| 26 | #include "llvm/IR/FunctionInfo.h" |
| 27 | #include "llvm/IR/LegacyPassManager.h" |
| 28 | #include "llvm/IR/Verifier.h" |
| 29 | #include "llvm/Support/CommandLine.h" |
| 30 | #include "llvm/Support/ManagedStatic.h" |
| Rafael Espindola | 7cebf36 | 2014-08-21 20:03:44 +0000 | [diff] [blame] | 31 | #include "llvm/Target/TargetMachine.h" |
| Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 32 | #include "llvm/Transforms/IPO.h" |
| Chandler Carruth | f49f1a87 | 2015-12-27 08:13:45 +0000 | [diff] [blame] | 33 | #include "llvm/Transforms/IPO/ForceFunctionAttrs.h" |
| Chandler Carruth | 9c4ed17 | 2016-02-18 11:03:11 +0000 | [diff] [blame] | 34 | #include "llvm/Transforms/IPO/FunctionAttrs.h" |
| Chandler Carruth | 3a040e6 | 2015-12-27 08:41:34 +0000 | [diff] [blame] | 35 | #include "llvm/Transforms/IPO/InferFunctionAttrs.h" |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 36 | #include "llvm/Transforms/Scalar.h" |
| Hal Finkel | c34e511 | 2012-02-01 03:51:43 +0000 | [diff] [blame] | 37 | #include "llvm/Transforms/Vectorize.h" |
| Rong Xu | 34abbfb | 2016-01-21 18:28:59 +0000 | [diff] [blame] | 38 | #include "llvm/Transforms/Instrumentation.h" |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 39 | |
| 40 | using namespace llvm; |
| 41 | |
| Hal Finkel | c34e511 | 2012-02-01 03:51:43 +0000 | [diff] [blame] | 42 | static cl::opt<bool> |
| Nadav Rotem | 7f27e0b | 2013-10-18 23:38:13 +0000 | [diff] [blame] | 43 | RunLoopVectorization("vectorize-loops", cl::Hidden, |
| Nadav Rotem | d3df665 | 2012-10-30 18:37:43 +0000 | [diff] [blame] | 44 | cl::desc("Run the Loop vectorization passes")); |
| Nadav Rotem | c59ae20 | 2012-10-29 16:36:25 +0000 | [diff] [blame] | 45 | |
| 46 | static cl::opt<bool> |
| Nadav Rotem | 7f27e0b | 2013-10-18 23:38:13 +0000 | [diff] [blame] | 47 | RunSLPVectorization("vectorize-slp", cl::Hidden, |
| Nadav Rotem | d4dcc00 | 2013-04-15 05:39:58 +0000 | [diff] [blame] | 48 | cl::desc("Run the SLP vectorization passes")); |
| 49 | |
| 50 | static cl::opt<bool> |
| Nadav Rotem | 7f27e0b | 2013-10-18 23:38:13 +0000 | [diff] [blame] | 51 | RunBBVectorization("vectorize-slp-aggressive", cl::Hidden, |
| Nadav Rotem | d4dcc00 | 2013-04-15 05:39:58 +0000 | [diff] [blame] | 52 | cl::desc("Run the BB vectorization passes")); |
| Hal Finkel | c34e511 | 2012-02-01 03:51:43 +0000 | [diff] [blame] | 53 | |
| Hal Finkel | 204bf53 | 2012-04-13 17:15:33 +0000 | [diff] [blame] | 54 | static cl::opt<bool> |
| 55 | UseGVNAfterVectorization("use-gvn-after-vectorization", |
| 56 | cl::init(false), cl::Hidden, |
| 57 | cl::desc("Run GVN instead of Early CSE after vectorization passes")); |
| 58 | |
| Chandler Carruth | 7b8297a | 2014-10-14 00:31:29 +0000 | [diff] [blame] | 59 | static cl::opt<bool> ExtraVectorizerPasses( |
| 60 | "extra-vectorizer-passes", cl::init(false), cl::Hidden, |
| 61 | cl::desc("Run cleanup optimization passes after vectorization.")); |
| 62 | |
| Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 63 | static cl::opt<bool> UseNewSROA("use-new-sroa", |
| Chandler Carruth | 4e43599 | 2012-10-02 04:24:01 +0000 | [diff] [blame] | 64 | cl::init(true), cl::Hidden, |
| Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 65 | cl::desc("Enable the new, experimental SROA pass")); |
| 66 | |
| Hal Finkel | bf45efd | 2013-11-16 23:59:05 +0000 | [diff] [blame] | 67 | static cl::opt<bool> |
| 68 | RunLoopRerolling("reroll-loops", cl::Hidden, |
| 69 | cl::desc("Run the loop rerolling pass")); |
| 70 | |
| James Molloy | 0cbb2a86 | 2015-03-27 10:36:57 +0000 | [diff] [blame] | 71 | static cl::opt<bool> |
| 72 | RunFloat2Int("float-to-int", cl::Hidden, cl::init(true), |
| 73 | cl::desc("Run the float2int (float demotion) pass")); |
| 74 | |
| Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 75 | static cl::opt<bool> RunLoadCombine("combine-loads", cl::init(false), |
| 76 | cl::Hidden, |
| 77 | cl::desc("Run the load combining pass")); |
| 78 | |
| James Molloy | 568da09 | 2014-08-06 12:56:19 +0000 | [diff] [blame] | 79 | static cl::opt<bool> |
| 80 | RunSLPAfterLoopVectorization("run-slp-after-loop-vectorization", |
| James Molloy | 6b95d8e | 2014-09-04 13:23:08 +0000 | [diff] [blame] | 81 | cl::init(true), cl::Hidden, |
| James Molloy | 568da09 | 2014-08-06 12:56:19 +0000 | [diff] [blame] | 82 | cl::desc("Run the SLP vectorizer (and BB vectorizer) after the Loop " |
| 83 | "vectorizer instead of before")); |
| 84 | |
| Hal Finkel | 445dda5 | 2014-09-02 22:12:54 +0000 | [diff] [blame] | 85 | static cl::opt<bool> UseCFLAA("use-cfl-aa", |
| 86 | cl::init(false), cl::Hidden, |
| 87 | cl::desc("Enable the new, experimental CFL alias analysis")); |
| James Molloy | 568da09 | 2014-08-06 12:56:19 +0000 | [diff] [blame] | 88 | |
| Gerolf Hoflehner | 24815d9 | 2014-09-10 19:55:29 +0000 | [diff] [blame] | 89 | static cl::opt<bool> |
| Gerolf Hoflehner | 008e5cd | 2014-09-10 20:24:03 +0000 | [diff] [blame] | 90 | EnableMLSM("mlsm", cl::init(true), cl::Hidden, |
| 91 | cl::desc("Enable motion of merged load and store")); |
| Gerolf Hoflehner | 24815d9 | 2014-09-10 19:55:29 +0000 | [diff] [blame] | 92 | |
| Karthik Bhat | 88db86d | 2015-03-06 10:11:25 +0000 | [diff] [blame] | 93 | static cl::opt<bool> EnableLoopInterchange( |
| 94 | "enable-loopinterchange", cl::init(false), cl::Hidden, |
| 95 | cl::desc("Enable the new, experimental LoopInterchange Pass")); |
| 96 | |
| Adam Nemet | 938d3d6 | 2015-05-14 12:05:18 +0000 | [diff] [blame] | 97 | static cl::opt<bool> EnableLoopDistribute( |
| 98 | "enable-loop-distribute", cl::init(false), cl::Hidden, |
| 99 | cl::desc("Enable the new, experimental LoopDistribution Pass")); |
| 100 | |
| Chandler Carruth | e9ea5a6 | 2015-07-22 11:57:28 +0000 | [diff] [blame] | 101 | static cl::opt<bool> EnableNonLTOGlobalsModRef( |
| James Molloy | 4015925 | 2015-10-13 10:43:57 +0000 | [diff] [blame] | 102 | "enable-non-lto-gmr", cl::init(true), cl::Hidden, |
| Chandler Carruth | e9ea5a6 | 2015-07-22 11:57:28 +0000 | [diff] [blame] | 103 | cl::desc( |
| 104 | "Enable the GlobalsModRef AliasAnalysis outside of the LTO pipeline.")); |
| 105 | |
| Adam Nemet | e54a4fa | 2015-11-03 23:50:08 +0000 | [diff] [blame] | 106 | static cl::opt<bool> EnableLoopLoadElim( |
| 107 | "enable-loop-load-elim", cl::init(false), cl::Hidden, |
| 108 | cl::desc("Enable the new, experimental LoopLoadElimination Pass")); |
| 109 | |
| Rong Xu | 34abbfb | 2016-01-21 18:28:59 +0000 | [diff] [blame] | 110 | static cl::opt<std::string> RunPGOInstrGen( |
| 111 | "profile-generate", cl::init(""), cl::Hidden, |
| 112 | cl::desc("Enable generation phase of PGO instrumentation and specify the " |
| 113 | "path of profile data file")); |
| 114 | |
| 115 | static cl::opt<std::string> RunPGOInstrUse( |
| 116 | "profile-use", cl::init(""), cl::Hidden, cl::value_desc("filename"), |
| 117 | cl::desc("Enable use phase of PGO instrumentation and specify the path " |
| 118 | "of profile data file")); |
| 119 | |
| Ashutosh Nema | df6763a | 2016-02-06 07:47:48 +0000 | [diff] [blame] | 120 | static cl::opt<bool> UseLoopVersioningLICM( |
| 121 | "enable-loop-versioning-licm", cl::init(false), cl::Hidden, |
| 122 | cl::desc("Enable the experimental Loop Versioning LICM pass")); |
| 123 | |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 124 | PassManagerBuilder::PassManagerBuilder() { |
| 125 | OptLevel = 2; |
| 126 | SizeLevel = 0; |
| Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 127 | LibraryInfo = nullptr; |
| 128 | Inliner = nullptr; |
| Teresa Johnson | 5fcbdb7 | 2015-12-07 19:21:11 +0000 | [diff] [blame] | 129 | FunctionIndex = nullptr; |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 130 | DisableUnitAtATime = false; |
| 131 | DisableUnrollLoops = false; |
| Nadav Rotem | d4dcc00 | 2013-04-15 05:39:58 +0000 | [diff] [blame] | 132 | BBVectorize = RunBBVectorization; |
| Nadav Rotem | a1e5e44 | 2013-04-15 04:54:42 +0000 | [diff] [blame] | 133 | SLPVectorize = RunSLPVectorization; |
| Nadav Rotem | c59ae20 | 2012-10-29 16:36:25 +0000 | [diff] [blame] | 134 | LoopVectorize = RunLoopVectorization; |
| Hal Finkel | 29aeb20 | 2013-11-17 16:02:50 +0000 | [diff] [blame] | 135 | RerollLoops = RunLoopRerolling; |
| Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 136 | LoadCombine = RunLoadCombine; |
| Rafael Espindola | 208bc53 | 2014-08-21 13:13:17 +0000 | [diff] [blame] | 137 | DisableGVNLoadPRE = false; |
| Rafael Espindola | 7cebf36 | 2014-08-21 20:03:44 +0000 | [diff] [blame] | 138 | VerifyInput = false; |
| 139 | VerifyOutput = false; |
| Nick Lewycky | 9e6d184 | 2014-09-13 21:46:00 +0000 | [diff] [blame] | 140 | MergeFunctions = false; |
| Teresa Johnson | d3a33a1 | 2015-07-06 16:22:42 +0000 | [diff] [blame] | 141 | PrepareForLTO = false; |
| Rong Xu | 34abbfb | 2016-01-21 18:28:59 +0000 | [diff] [blame] | 142 | PGOInstrGen = RunPGOInstrGen; |
| 143 | PGOInstrUse = RunPGOInstrUse; |
| Mehdi Amini | 1db10ac | 2016-02-16 23:02:29 +0000 | [diff] [blame] | 144 | PrepareForThinLTO = false; |
| 145 | PerformThinLTO = false; |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | PassManagerBuilder::~PassManagerBuilder() { |
| 149 | delete LibraryInfo; |
| 150 | delete Inliner; |
| 151 | } |
| 152 | |
| David Chisnall | 719a72f | 2011-08-16 13:58:41 +0000 | [diff] [blame] | 153 | /// Set of global extensions, automatically added as part of the standard set. |
| 154 | static ManagedStatic<SmallVector<std::pair<PassManagerBuilder::ExtensionPointTy, |
| 155 | PassManagerBuilder::ExtensionFn>, 8> > GlobalExtensions; |
| 156 | |
| 157 | void PassManagerBuilder::addGlobalExtension( |
| 158 | PassManagerBuilder::ExtensionPointTy Ty, |
| 159 | PassManagerBuilder::ExtensionFn Fn) { |
| 160 | GlobalExtensions->push_back(std::make_pair(Ty, Fn)); |
| 161 | } |
| 162 | |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 163 | void PassManagerBuilder::addExtension(ExtensionPointTy Ty, ExtensionFn Fn) { |
| 164 | Extensions.push_back(std::make_pair(Ty, Fn)); |
| 165 | } |
| 166 | |
| 167 | void PassManagerBuilder::addExtensionsToPM(ExtensionPointTy ETy, |
| Chandler Carruth | 30d69c2 | 2015-02-13 10:01:29 +0000 | [diff] [blame] | 168 | legacy::PassManagerBase &PM) const { |
| David Chisnall | 719a72f | 2011-08-16 13:58:41 +0000 | [diff] [blame] | 169 | for (unsigned i = 0, e = GlobalExtensions->size(); i != e; ++i) |
| 170 | if ((*GlobalExtensions)[i].first == ETy) |
| 171 | (*GlobalExtensions)[i].second(*this, PM); |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 172 | for (unsigned i = 0, e = Extensions.size(); i != e; ++i) |
| 173 | if (Extensions[i].first == ETy) |
| 174 | Extensions[i].second(*this, PM); |
| 175 | } |
| 176 | |
| Chandler Carruth | 30d69c2 | 2015-02-13 10:01:29 +0000 | [diff] [blame] | 177 | void PassManagerBuilder::addInitialAliasAnalysisPasses( |
| 178 | legacy::PassManagerBase &PM) const { |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 179 | // Add TypeBasedAliasAnalysis before BasicAliasAnalysis so that |
| 180 | // BasicAliasAnalysis wins if they disagree. This is intended to help |
| 181 | // support "obvious" type-punning idioms. |
| Hal Finkel | 445dda5 | 2014-09-02 22:12:54 +0000 | [diff] [blame] | 182 | if (UseCFLAA) |
| Chandler Carruth | 7b560d4 | 2015-09-09 17:55:00 +0000 | [diff] [blame] | 183 | PM.add(createCFLAAWrapperPass()); |
| 184 | PM.add(createTypeBasedAAWrapperPass()); |
| 185 | PM.add(createScopedNoAliasAAWrapperPass()); |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 186 | } |
| 187 | |
| Chandler Carruth | 30d69c2 | 2015-02-13 10:01:29 +0000 | [diff] [blame] | 188 | void PassManagerBuilder::populateFunctionPassManager( |
| 189 | legacy::FunctionPassManager &FPM) { |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 190 | addExtensionsToPM(EP_EarlyAsPossible, FPM); |
| 191 | |
| 192 | // Add LibraryInfo if we have some. |
| Chandler Carruth | b98f63d | 2015-01-15 10:41:28 +0000 | [diff] [blame] | 193 | if (LibraryInfo) |
| 194 | FPM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo)); |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 195 | |
| 196 | if (OptLevel == 0) return; |
| 197 | |
| 198 | addInitialAliasAnalysisPasses(FPM); |
| 199 | |
| 200 | FPM.add(createCFGSimplificationPass()); |
| Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 201 | if (UseNewSROA) |
| 202 | FPM.add(createSROAPass()); |
| 203 | else |
| 204 | FPM.add(createScalarReplAggregatesPass()); |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 205 | FPM.add(createEarlyCSEPass()); |
| 206 | FPM.add(createLowerExpectIntrinsicPass()); |
| 207 | } |
| 208 | |
| Rong Xu | 34abbfb | 2016-01-21 18:28:59 +0000 | [diff] [blame] | 209 | // Do PGO instrumentation generation or use pass as the option specified. |
| 210 | void PassManagerBuilder::addPGOInstrPasses(legacy::PassManagerBase &MPM) { |
| 211 | if (!PGOInstrGen.empty()) { |
| 212 | MPM.add(createPGOInstrumentationGenPass()); |
| 213 | // Add the profile lowering pass. |
| 214 | InstrProfOptions Options; |
| 215 | Options.InstrProfileOutput = PGOInstrGen; |
| 216 | MPM.add(createInstrProfilingPass(Options)); |
| 217 | } |
| 218 | if (!PGOInstrUse.empty()) |
| 219 | MPM.add(createPGOInstrumentationUsePass(PGOInstrUse)); |
| 220 | } |
| Mehdi Amini | ec8bee1 | 2016-02-16 22:54:27 +0000 | [diff] [blame] | 221 | void PassManagerBuilder::addFunctionSimplificationPasses( |
| Mehdi Amini | 9c1c3ac | 2016-02-11 22:09:11 +0000 | [diff] [blame] | 222 | legacy::PassManagerBase &MPM) { |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 223 | // Start of function pass. |
| 224 | // Break up aggregate allocas, using SSAUpdater. |
| Chandler Carruth | 70b44c5 | 2012-09-15 11:43:14 +0000 | [diff] [blame] | 225 | if (UseNewSROA) |
| Mehdi Amini | d134a67 | 2015-08-23 22:15:49 +0000 | [diff] [blame] | 226 | MPM.add(createSROAPass()); |
| Chandler Carruth | 70b44c5 | 2012-09-15 11:43:14 +0000 | [diff] [blame] | 227 | else |
| 228 | MPM.add(createScalarReplAggregatesPass(-1, false)); |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 229 | MPM.add(createEarlyCSEPass()); // Catch trivial redundancies |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 230 | MPM.add(createJumpThreadingPass()); // Thread jumps. |
| 231 | MPM.add(createCorrelatedValuePropagationPass()); // Propagate conditionals |
| 232 | MPM.add(createCFGSimplificationPass()); // Merge & remove BBs |
| 233 | MPM.add(createInstructionCombiningPass()); // Combine silly seq's |
| Peter Collingbourne | 0a43761 | 2014-05-25 10:27:02 +0000 | [diff] [blame] | 234 | addExtensionsToPM(EP_Peephole, MPM); |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 235 | |
| Akira Hatanaka | d9699bc | 2015-06-09 19:07:19 +0000 | [diff] [blame] | 236 | MPM.add(createTailCallEliminationPass()); // Eliminate tail calls |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 237 | MPM.add(createCFGSimplificationPass()); // Merge & remove BBs |
| 238 | MPM.add(createReassociatePass()); // Reassociate expressions |
| Mehdi Amini | 1db10ac | 2016-02-16 23:02:29 +0000 | [diff] [blame] | 239 | if (PrepareForThinLTO) { |
| 240 | MPM.add(createAggressiveDCEPass()); // Delete dead instructions |
| 241 | MPM.add(createInstructionCombiningPass()); // Combine silly seq's |
| 242 | return; |
| 243 | } |
| Roman Divacky | d2b9a1b | 2014-11-21 19:53:24 +0000 | [diff] [blame] | 244 | // Rotate Loop - disable header duplication at -Oz |
| 245 | MPM.add(createLoopRotatePass(SizeLevel == 2 ? 0 : -1)); |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 246 | MPM.add(createLICMPass()); // Hoist loop invariants |
| 247 | MPM.add(createLoopUnswitchPass(SizeLevel || OptLevel < 3)); |
| Michael Zolotukhin | 74621cc | 2015-09-24 03:50:17 +0000 | [diff] [blame] | 248 | MPM.add(createCFGSimplificationPass()); |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 249 | MPM.add(createInstructionCombiningPass()); |
| 250 | MPM.add(createIndVarSimplifyPass()); // Canonicalize indvars |
| 251 | MPM.add(createLoopIdiomPass()); // Recognize idioms like memset. |
| 252 | MPM.add(createLoopDeletionPass()); // Delete dead loops |
| Karthik Bhat | 8210fdf | 2015-04-23 04:51:44 +0000 | [diff] [blame] | 253 | if (EnableLoopInterchange) { |
| Karthik Bhat | 88db86d | 2015-03-06 10:11:25 +0000 | [diff] [blame] | 254 | MPM.add(createLoopInterchangePass()); // Interchange loops |
| Karthik Bhat | 8210fdf | 2015-04-23 04:51:44 +0000 | [diff] [blame] | 255 | MPM.add(createCFGSimplificationPass()); |
| 256 | } |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 257 | if (!DisableUnrollLoops) |
| Hal Finkel | 86b3064 | 2014-03-31 23:23:51 +0000 | [diff] [blame] | 258 | MPM.add(createSimpleLoopUnrollPass()); // Unroll small loops |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 259 | addExtensionsToPM(EP_LoopOptimizerEnd, MPM); |
| 260 | |
| Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 261 | if (OptLevel > 1) { |
| Gerolf Hoflehner | 24815d9 | 2014-09-10 19:55:29 +0000 | [diff] [blame] | 262 | if (EnableMLSM) |
| 263 | MPM.add(createMergedLoadStoreMotionPass()); // Merge ld/st in diamonds |
| Rafael Espindola | 208bc53 | 2014-08-21 13:13:17 +0000 | [diff] [blame] | 264 | MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies |
| Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 265 | } |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 266 | MPM.add(createMemCpyOptPass()); // Remove memcpy / form memset |
| 267 | MPM.add(createSCCPPass()); // Constant prop with SCCP |
| 268 | |
| Hal Finkel | 2bb61ba | 2015-02-17 01:36:59 +0000 | [diff] [blame] | 269 | // Delete dead bit computations (instcombine runs after to fold away the dead |
| 270 | // computations, and then ADCE will run later to exploit any new DCE |
| 271 | // opportunities that creates). |
| 272 | MPM.add(createBitTrackingDCEPass()); // Delete dead bit computations |
| 273 | |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 274 | // Run instcombine after redundancy elimination to exploit opportunities |
| 275 | // opened up by them. |
| 276 | MPM.add(createInstructionCombiningPass()); |
| Peter Collingbourne | 0a43761 | 2014-05-25 10:27:02 +0000 | [diff] [blame] | 277 | addExtensionsToPM(EP_Peephole, MPM); |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 278 | MPM.add(createJumpThreadingPass()); // Thread jumps |
| 279 | MPM.add(createCorrelatedValuePropagationPass()); |
| 280 | MPM.add(createDeadStoreEliminationPass()); // Delete dead stores |
| James Molloy | 8357024 | 2015-02-16 18:59:54 +0000 | [diff] [blame] | 281 | MPM.add(createLICMPass()); |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 282 | |
| 283 | addExtensionsToPM(EP_ScalarOptimizerLate, MPM); |
| 284 | |
| Hal Finkel | 29aeb20 | 2013-11-17 16:02:50 +0000 | [diff] [blame] | 285 | if (RerollLoops) |
| Hal Finkel | bf45efd | 2013-11-16 23:59:05 +0000 | [diff] [blame] | 286 | MPM.add(createLoopRerollPass()); |
| James Molloy | 568da09 | 2014-08-06 12:56:19 +0000 | [diff] [blame] | 287 | if (!RunSLPAfterLoopVectorization) { |
| 288 | if (SLPVectorize) |
| 289 | MPM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains. |
| Nadav Rotem | d4dcc00 | 2013-04-15 05:39:58 +0000 | [diff] [blame] | 290 | |
| James Molloy | 568da09 | 2014-08-06 12:56:19 +0000 | [diff] [blame] | 291 | if (BBVectorize) { |
| 292 | MPM.add(createBBVectorizePass()); |
| 293 | MPM.add(createInstructionCombiningPass()); |
| 294 | addExtensionsToPM(EP_Peephole, MPM); |
| 295 | if (OptLevel > 1 && UseGVNAfterVectorization) |
| Rafael Espindola | 208bc53 | 2014-08-21 13:13:17 +0000 | [diff] [blame] | 296 | MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies |
| James Molloy | 568da09 | 2014-08-06 12:56:19 +0000 | [diff] [blame] | 297 | else |
| 298 | MPM.add(createEarlyCSEPass()); // Catch trivial redundancies |
| Hal Finkel | bf4db4f | 2013-01-29 00:22:49 +0000 | [diff] [blame] | 299 | |
| James Molloy | 568da09 | 2014-08-06 12:56:19 +0000 | [diff] [blame] | 300 | // BBVectorize may have significantly shortened a loop body; unroll again. |
| 301 | if (!DisableUnrollLoops) |
| 302 | MPM.add(createLoopUnrollPass()); |
| 303 | } |
| Hal Finkel | c34e511 | 2012-02-01 03:51:43 +0000 | [diff] [blame] | 304 | } |
| 305 | |
| Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 306 | if (LoadCombine) |
| 307 | MPM.add(createLoadCombinePass()); |
| 308 | |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 309 | MPM.add(createAggressiveDCEPass()); // Delete dead instructions |
| Tom Stellard | aa664d9 | 2013-08-06 02:43:45 +0000 | [diff] [blame] | 310 | MPM.add(createCFGSimplificationPass()); // Merge & remove BBs |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 311 | MPM.add(createInstructionCombiningPass()); // Clean up after everything. |
| Peter Collingbourne | 0a43761 | 2014-05-25 10:27:02 +0000 | [diff] [blame] | 312 | addExtensionsToPM(EP_Peephole, MPM); |
| Mehdi Amini | ec8bee1 | 2016-02-16 22:54:27 +0000 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | void PassManagerBuilder::populateModulePassManager( |
| 316 | legacy::PassManagerBase &MPM) { |
| 317 | // Allow forcing function attributes as a debugging and tuning aid. |
| 318 | MPM.add(createForceFunctionAttrsLegacyPass()); |
| 319 | |
| 320 | // If all optimizations are disabled, just run the always-inline pass and, |
| 321 | // if enabled, the function merging pass. |
| 322 | if (OptLevel == 0) { |
| 323 | addPGOInstrPasses(MPM); |
| 324 | if (Inliner) { |
| 325 | MPM.add(Inliner); |
| 326 | Inliner = nullptr; |
| 327 | } |
| 328 | |
| 329 | // FIXME: The BarrierNoopPass is a HACK! The inliner pass above implicitly |
| 330 | // creates a CGSCC pass manager, but we don't want to add extensions into |
| 331 | // that pass manager. To prevent this we insert a no-op module pass to reset |
| 332 | // the pass manager to get the same behavior as EP_OptimizerLast in non-O0 |
| 333 | // builds. The function merging pass is |
| 334 | if (MergeFunctions) |
| 335 | MPM.add(createMergeFunctionsPass()); |
| 336 | else if (!GlobalExtensions->empty() || !Extensions.empty()) |
| 337 | MPM.add(createBarrierNoopPass()); |
| 338 | |
| 339 | addExtensionsToPM(EP_EnabledOnOptLevel0, MPM); |
| 340 | return; |
| 341 | } |
| 342 | |
| 343 | // Add LibraryInfo if we have some. |
| 344 | if (LibraryInfo) |
| 345 | MPM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo)); |
| 346 | |
| 347 | addInitialAliasAnalysisPasses(MPM); |
| 348 | |
| 349 | if (!DisableUnitAtATime) { |
| 350 | // Infer attributes about declarations if possible. |
| 351 | MPM.add(createInferFunctionAttrsLegacyPass()); |
| 352 | |
| 353 | addExtensionsToPM(EP_ModuleOptimizerEarly, MPM); |
| 354 | |
| 355 | MPM.add(createIPSCCPPass()); // IP SCCP |
| 356 | MPM.add(createGlobalOptimizerPass()); // Optimize out global vars |
| 357 | // Promote any localized global vars. |
| 358 | MPM.add(createPromoteMemoryToRegisterPass()); |
| 359 | |
| 360 | MPM.add(createDeadArgEliminationPass()); // Dead argument elimination |
| 361 | |
| 362 | MPM.add(createInstructionCombiningPass()); // Clean up after IPCP & DAE |
| 363 | addExtensionsToPM(EP_Peephole, MPM); |
| 364 | MPM.add(createCFGSimplificationPass()); // Clean up after IPCP & DAE |
| 365 | } |
| 366 | |
| Mehdi Amini | 1db10ac | 2016-02-16 23:02:29 +0000 | [diff] [blame] | 367 | if (!PerformThinLTO) |
| 368 | /// PGO instrumentation is added during the compile phase for ThinLTO, do |
| 369 | /// not run it a second time |
| 370 | addPGOInstrPasses(MPM); |
| Mehdi Amini | ec8bee1 | 2016-02-16 22:54:27 +0000 | [diff] [blame] | 371 | |
| 372 | if (EnableNonLTOGlobalsModRef) |
| 373 | // We add a module alias analysis pass here. In part due to bugs in the |
| 374 | // analysis infrastructure this "works" in that the analysis stays alive |
| 375 | // for the entire SCC pass run below. |
| 376 | MPM.add(createGlobalsAAWrapperPass()); |
| 377 | |
| 378 | // Start of CallGraph SCC passes. |
| 379 | if (!DisableUnitAtATime) |
| 380 | MPM.add(createPruneEHPass()); // Remove dead EH info |
| 381 | if (Inliner) { |
| 382 | MPM.add(Inliner); |
| 383 | Inliner = nullptr; |
| 384 | } |
| 385 | if (!DisableUnitAtATime) |
| Chandler Carruth | 9c4ed17 | 2016-02-18 11:03:11 +0000 | [diff] [blame] | 386 | MPM.add(createPostOrderFunctionAttrsLegacyPass()); |
| Mehdi Amini | ec8bee1 | 2016-02-16 22:54:27 +0000 | [diff] [blame] | 387 | if (OptLevel > 2) |
| 388 | MPM.add(createArgumentPromotionPass()); // Scalarize uninlined fn args |
| 389 | |
| 390 | addFunctionSimplificationPasses(MPM); |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 391 | |
| Mehdi Amini | 1db10ac | 2016-02-16 23:02:29 +0000 | [diff] [blame] | 392 | // If we are planning to perform ThinLTO later, let's not bloat the code with |
| 393 | // unrolling/vectorization/... now. We'll first run the inliner + CGSCC passes |
| 394 | // during ThinLTO and perform the rest of the optimizations afterward. |
| 395 | if (PrepareForThinLTO) |
| 396 | return; |
| 397 | |
| Renato Golin | 729a3ae | 2013-12-05 21:20:02 +0000 | [diff] [blame] | 398 | // FIXME: This is a HACK! The inliner pass above implicitly creates a CGSCC |
| 399 | // pass manager that we are specifically trying to avoid. To prevent this |
| 400 | // we must insert a no-op module pass to reset the pass manager. |
| 401 | MPM.add(createBarrierNoopPass()); |
| Chandler Carruth | 7b8297a | 2014-10-14 00:31:29 +0000 | [diff] [blame] | 402 | |
| Ashutosh Nema | 2260a3a | 2016-02-11 09:23:53 +0000 | [diff] [blame] | 403 | // Scheduling LoopVersioningLICM when inlining is over, because after that |
| Ashutosh Nema | df6763a | 2016-02-06 07:47:48 +0000 | [diff] [blame] | 404 | // we may see more accurate aliasing. Reason to run this late is that too |
| 405 | // early versioning may prevent further inlining due to increase of code |
| 406 | // size. By placing it just after inlining other optimizations which runs |
| 407 | // later might get benefit of no-alias assumption in clone loop. |
| 408 | if (UseLoopVersioningLICM) { |
| 409 | MPM.add(createLoopVersioningLICMPass()); // Do LoopVersioningLICM |
| 410 | MPM.add(createLICMPass()); // Hoist loop invariants |
| 411 | } |
| 412 | |
| Chandler Carruth | 1926b70 | 2016-01-08 10:55:52 +0000 | [diff] [blame] | 413 | if (!DisableUnitAtATime) |
| 414 | MPM.add(createReversePostOrderFunctionAttrsPass()); |
| 415 | |
| Mehdi Amini | 1db10ac | 2016-02-16 23:02:29 +0000 | [diff] [blame] | 416 | if (!DisableUnitAtATime && OptLevel > 1 && !PrepareForLTO) |
| Yaron Keren | 611c7cf | 2015-09-02 06:34:11 +0000 | [diff] [blame] | 417 | // Remove avail extern fns and globals definitions if we aren't |
| 418 | // compiling an object file for later LTO. For LTO we want to preserve |
| 419 | // these so they are eligible for inlining at link-time. Note if they |
| 420 | // are unreferenced they will be removed by GlobalDCE later, so |
| 421 | // this only impacts referenced available externally globals. |
| 422 | // Eventually they will be suppressed during codegen, but eliminating |
| 423 | // here enables more opportunity for GlobalDCE as it may make |
| 424 | // globals referenced by available external functions dead |
| 425 | // and saves running remaining passes on the eliminated functions. |
| 426 | MPM.add(createEliminateAvailableExternallyPass()); |
| Mehdi Amini | 1db10ac | 2016-02-16 23:02:29 +0000 | [diff] [blame] | 427 | |
| 428 | if (PerformThinLTO) { |
| 429 | // Remove dead fns and globals. Removing unreferenced functions could lead |
| 430 | // to more opportunities for globalopt. |
| 431 | MPM.add(createGlobalDCEPass()); |
| 432 | MPM.add(createGlobalOptimizerPass()); |
| 433 | // Remove dead fns and globals after globalopt. |
| 434 | MPM.add(createGlobalDCEPass()); |
| 435 | addFunctionSimplificationPasses(MPM); |
| Yaron Keren | 611c7cf | 2015-09-02 06:34:11 +0000 | [diff] [blame] | 436 | } |
| 437 | |
| Chandler Carruth | 08eebe2 | 2015-07-23 09:34:01 +0000 | [diff] [blame] | 438 | if (EnableNonLTOGlobalsModRef) |
| 439 | // We add a fresh GlobalsModRef run at this point. This is particularly |
| 440 | // useful as the above will have inlined, DCE'ed, and function-attr |
| 441 | // propagated everything. We should at this point have a reasonably minimal |
| 442 | // and richly annotated call graph. By computing aliasing and mod/ref |
| 443 | // information for all local globals here, the late loop passes and notably |
| 444 | // the vectorizer will be able to use them to help recognize vectorizable |
| 445 | // memory operations. |
| 446 | // |
| 447 | // Note that this relies on a bug in the pass manager which preserves |
| 448 | // a module analysis into a function pass pipeline (and throughout it) so |
| 449 | // long as the first function pass doesn't invalidate the module analysis. |
| 450 | // Thus both Float2Int and LoopRotate have to preserve AliasAnalysis for |
| 451 | // this to work. Fortunately, it is trivial to preserve AliasAnalysis |
| 452 | // (doing nothing preserves it as it is required to be conservatively |
| 453 | // correct in the face of IR changes). |
| Chandler Carruth | 7b560d4 | 2015-09-09 17:55:00 +0000 | [diff] [blame] | 454 | MPM.add(createGlobalsAAWrapperPass()); |
| Chandler Carruth | 08eebe2 | 2015-07-23 09:34:01 +0000 | [diff] [blame] | 455 | |
| James Molloy | 0cbb2a86 | 2015-03-27 10:36:57 +0000 | [diff] [blame] | 456 | if (RunFloat2Int) |
| 457 | MPM.add(createFloat2IntPass()); |
| 458 | |
| Tobias Grosser | 39a7bd1 | 2015-07-16 08:20:37 +0000 | [diff] [blame] | 459 | addExtensionsToPM(EP_VectorizerStart, MPM); |
| 460 | |
| Chandler Carruth | 7b8297a | 2014-10-14 00:31:29 +0000 | [diff] [blame] | 461 | // Re-rotate loops in all our loop nests. These may have fallout out of |
| 462 | // rotated form due to GVN or other transformations, and the vectorizer relies |
| Alexey Bataev | da33d80 | 2015-07-10 10:37:09 +0000 | [diff] [blame] | 463 | // on the rotated form. Disable header duplication at -Oz. |
| 464 | MPM.add(createLoopRotatePass(SizeLevel == 2 ? 0 : -1)); |
| Chandler Carruth | 7b8297a | 2014-10-14 00:31:29 +0000 | [diff] [blame] | 465 | |
| Adam Nemet | 938d3d6 | 2015-05-14 12:05:18 +0000 | [diff] [blame] | 466 | // Distribute loops to allow partial vectorization. I.e. isolate dependences |
| 467 | // into separate loop that would otherwise inhibit vectorization. |
| 468 | if (EnableLoopDistribute) |
| 469 | MPM.add(createLoopDistributePass()); |
| 470 | |
| Renato Golin | 729a3ae | 2013-12-05 21:20:02 +0000 | [diff] [blame] | 471 | MPM.add(createLoopVectorizePass(DisableUnrollLoops, LoopVectorize)); |
| Adam Nemet | e54a4fa | 2015-11-03 23:50:08 +0000 | [diff] [blame] | 472 | |
| 473 | // Eliminate loads by forwarding stores from the previous iteration to loads |
| 474 | // of the current iteration. |
| 475 | if (EnableLoopLoadElim) |
| 476 | MPM.add(createLoopLoadEliminationPass()); |
| 477 | |
| Renato Golin | 729a3ae | 2013-12-05 21:20:02 +0000 | [diff] [blame] | 478 | // FIXME: Because of #pragma vectorize enable, the passes below are always |
| 479 | // inserted in the pipeline, even when the vectorizer doesn't run (ex. when |
| 480 | // on -O1 and no #pragma is found). Would be good to have these two passes |
| 481 | // as function calls, so that we can only pass them when the vectorizer |
| 482 | // changed the code. |
| 483 | MPM.add(createInstructionCombiningPass()); |
| Chandler Carruth | 7b8297a | 2014-10-14 00:31:29 +0000 | [diff] [blame] | 484 | if (OptLevel > 1 && ExtraVectorizerPasses) { |
| 485 | // At higher optimization levels, try to clean up any runtime overlap and |
| 486 | // alignment checks inserted by the vectorizer. We want to track correllated |
| 487 | // runtime checks for two inner loops in the same outer loop, fold any |
| 488 | // common computations, hoist loop-invariant aspects out of any outer loop, |
| 489 | // and unswitch the runtime checks if possible. Once hoisted, we may have |
| 490 | // dead (or speculatable) control flows or more combining opportunities. |
| 491 | MPM.add(createEarlyCSEPass()); |
| 492 | MPM.add(createCorrelatedValuePropagationPass()); |
| 493 | MPM.add(createInstructionCombiningPass()); |
| 494 | MPM.add(createLICMPass()); |
| 495 | MPM.add(createLoopUnswitchPass(SizeLevel || OptLevel < 3)); |
| 496 | MPM.add(createCFGSimplificationPass()); |
| 497 | MPM.add(createInstructionCombiningPass()); |
| 498 | } |
| James Molloy | 568da09 | 2014-08-06 12:56:19 +0000 | [diff] [blame] | 499 | |
| 500 | if (RunSLPAfterLoopVectorization) { |
| Chandler Carruth | 7b8297a | 2014-10-14 00:31:29 +0000 | [diff] [blame] | 501 | if (SLPVectorize) { |
| James Molloy | 568da09 | 2014-08-06 12:56:19 +0000 | [diff] [blame] | 502 | MPM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains. |
| Chandler Carruth | 7b8297a | 2014-10-14 00:31:29 +0000 | [diff] [blame] | 503 | if (OptLevel > 1 && ExtraVectorizerPasses) { |
| 504 | MPM.add(createEarlyCSEPass()); |
| 505 | } |
| 506 | } |
| James Molloy | 568da09 | 2014-08-06 12:56:19 +0000 | [diff] [blame] | 507 | |
| 508 | if (BBVectorize) { |
| 509 | MPM.add(createBBVectorizePass()); |
| 510 | MPM.add(createInstructionCombiningPass()); |
| 511 | addExtensionsToPM(EP_Peephole, MPM); |
| 512 | if (OptLevel > 1 && UseGVNAfterVectorization) |
| Rafael Espindola | 208bc53 | 2014-08-21 13:13:17 +0000 | [diff] [blame] | 513 | MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies |
| James Molloy | 568da09 | 2014-08-06 12:56:19 +0000 | [diff] [blame] | 514 | else |
| 515 | MPM.add(createEarlyCSEPass()); // Catch trivial redundancies |
| 516 | |
| 517 | // BBVectorize may have significantly shortened a loop body; unroll again. |
| 518 | if (!DisableUnrollLoops) |
| 519 | MPM.add(createLoopUnrollPass()); |
| 520 | } |
| 521 | } |
| 522 | |
| Peter Collingbourne | 0a43761 | 2014-05-25 10:27:02 +0000 | [diff] [blame] | 523 | addExtensionsToPM(EP_Peephole, MPM); |
| Renato Golin | 729a3ae | 2013-12-05 21:20:02 +0000 | [diff] [blame] | 524 | MPM.add(createCFGSimplificationPass()); |
| Chandler Carruth | 7b8297a | 2014-10-14 00:31:29 +0000 | [diff] [blame] | 525 | MPM.add(createInstructionCombiningPass()); |
| Chandler Carruth | 08e1b87 | 2013-06-24 07:21:47 +0000 | [diff] [blame] | 526 | |
| Kevin Qin | 49bc764 | 2015-03-12 05:36:01 +0000 | [diff] [blame] | 527 | if (!DisableUnrollLoops) { |
| Hal Finkel | 86b3064 | 2014-03-31 23:23:51 +0000 | [diff] [blame] | 528 | MPM.add(createLoopUnrollPass()); // Unroll small loops |
| 529 | |
| Wei Mi | bf727ba | 2015-05-14 22:02:54 +0000 | [diff] [blame] | 530 | // LoopUnroll may generate some redundency to cleanup. |
| 531 | MPM.add(createInstructionCombiningPass()); |
| 532 | |
| Kevin Qin | 49bc764 | 2015-03-12 05:36:01 +0000 | [diff] [blame] | 533 | // Runtime unrolling will introduce runtime check in loop prologue. If the |
| 534 | // unrolled loop is a inner loop, then the prologue will be inside the |
| 535 | // outer loop. LICM pass can help to promote the runtime check out if the |
| 536 | // checked value is loop invariant. |
| 537 | MPM.add(createLICMPass()); |
| 538 | } |
| 539 | |
| Hal Finkel | d67e463 | 2014-09-07 20:05:11 +0000 | [diff] [blame] | 540 | // After vectorization and unrolling, assume intrinsics may tell us more |
| 541 | // about pointer alignments. |
| 542 | MPM.add(createAlignmentFromAssumptionsPass()); |
| 543 | |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 544 | if (!DisableUnitAtATime) { |
| 545 | // FIXME: We shouldn't bother with this anymore. |
| 546 | MPM.add(createStripDeadPrototypesPass()); // Get rid of dead prototypes |
| 547 | |
| Evan Cheng | 8c6b06d | 2012-09-28 21:23:26 +0000 | [diff] [blame] | 548 | // GlobalOpt already deletes dead functions and globals, at -O2 try a |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 549 | // late pass of GlobalDCE. It is capable of deleting dead cycles. |
| Evan Cheng | 8c6b06d | 2012-09-28 21:23:26 +0000 | [diff] [blame] | 550 | if (OptLevel > 1) { |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 551 | MPM.add(createGlobalDCEPass()); // Remove dead fns and globals. |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 552 | MPM.add(createConstantMergePass()); // Merge dup global constants |
| Evan Cheng | 8c6b06d | 2012-09-28 21:23:26 +0000 | [diff] [blame] | 553 | } |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 554 | } |
| Nick Lewycky | 9e6d184 | 2014-09-13 21:46:00 +0000 | [diff] [blame] | 555 | |
| 556 | if (MergeFunctions) |
| 557 | MPM.add(createMergeFunctionsPass()); |
| 558 | |
| Kostya Serebryany | e505a5a | 2012-03-23 23:22:59 +0000 | [diff] [blame] | 559 | addExtensionsToPM(EP_OptimizerLast, MPM); |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 560 | } |
| 561 | |
| Chandler Carruth | 30d69c2 | 2015-02-13 10:01:29 +0000 | [diff] [blame] | 562 | void PassManagerBuilder::addLTOOptimizationPasses(legacy::PassManagerBase &PM) { |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 563 | // Provide AliasAnalysis services for optimizations. |
| 564 | addInitialAliasAnalysisPasses(PM); |
| 565 | |
| Teresa Johnson | 5fcbdb7 | 2015-12-07 19:21:11 +0000 | [diff] [blame] | 566 | if (FunctionIndex) |
| 567 | PM.add(createFunctionImportPass(FunctionIndex)); |
| 568 | |
| Chandler Carruth | f49f1a87 | 2015-12-27 08:13:45 +0000 | [diff] [blame] | 569 | // Allow forcing function attributes as a debugging and tuning aid. |
| 570 | PM.add(createForceFunctionAttrsLegacyPass()); |
| 571 | |
| Chandler Carruth | 3a040e6 | 2015-12-27 08:41:34 +0000 | [diff] [blame] | 572 | // Infer attributes about declarations if possible. |
| 573 | PM.add(createInferFunctionAttrsLegacyPass()); |
| 574 | |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 575 | // Propagate constants at call sites into the functions they call. This |
| 576 | // opens opportunities for globalopt (and inlining) by substituting function |
| 577 | // pointers passed as arguments to direct uses of functions. |
| 578 | PM.add(createIPSCCPPass()); |
| 579 | |
| 580 | // Now that we internalized some globals, see if we can hack on them! |
| Chandler Carruth | 9c4ed17 | 2016-02-18 11:03:11 +0000 | [diff] [blame] | 581 | PM.add(createPostOrderFunctionAttrsLegacyPass()); |
| Chandler Carruth | 1926b70 | 2016-01-08 10:55:52 +0000 | [diff] [blame] | 582 | PM.add(createReversePostOrderFunctionAttrsPass()); |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 583 | PM.add(createGlobalOptimizerPass()); |
| James Molloy | 6045cc8 | 2015-12-15 09:24:01 +0000 | [diff] [blame] | 584 | // Promote any localized global vars. |
| 585 | PM.add(createPromoteMemoryToRegisterPass()); |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 586 | |
| 587 | // Linking modules together can lead to duplicated global constants, only |
| 588 | // keep one copy of each constant. |
| 589 | PM.add(createConstantMergePass()); |
| 590 | |
| 591 | // Remove unused arguments from functions. |
| 592 | PM.add(createDeadArgEliminationPass()); |
| 593 | |
| 594 | // Reduce the code after globalopt and ipsccp. Both can open up significant |
| 595 | // simplification opportunities, and both can propagate functions through |
| 596 | // function pointers. When this happens, we often have to resolve varargs |
| 597 | // calls, etc, so let instcombine do this. |
| 598 | PM.add(createInstructionCombiningPass()); |
| Peter Collingbourne | 0a43761 | 2014-05-25 10:27:02 +0000 | [diff] [blame] | 599 | addExtensionsToPM(EP_Peephole, PM); |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 600 | |
| 601 | // Inline small functions |
| Rafael Espindola | e07caad | 2014-08-21 13:35:30 +0000 | [diff] [blame] | 602 | bool RunInliner = Inliner; |
| 603 | if (RunInliner) { |
| 604 | PM.add(Inliner); |
| 605 | Inliner = nullptr; |
| 606 | } |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 607 | |
| 608 | PM.add(createPruneEHPass()); // Remove dead EH info. |
| 609 | |
| 610 | // Optimize globals again if we ran the inliner. |
| 611 | if (RunInliner) |
| 612 | PM.add(createGlobalOptimizerPass()); |
| 613 | PM.add(createGlobalDCEPass()); // Remove dead functions. |
| 614 | |
| 615 | // If we didn't decide to inline a function, check to see if we can |
| 616 | // transform it to pass arguments by value instead of by reference. |
| 617 | PM.add(createArgumentPromotionPass()); |
| 618 | |
| 619 | // The IPO passes may leave cruft around. Clean up after them. |
| 620 | PM.add(createInstructionCombiningPass()); |
| Peter Collingbourne | 0a43761 | 2014-05-25 10:27:02 +0000 | [diff] [blame] | 621 | addExtensionsToPM(EP_Peephole, PM); |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 622 | PM.add(createJumpThreadingPass()); |
| Bill Wendling | 4c0d9ad | 2013-08-30 00:48:37 +0000 | [diff] [blame] | 623 | |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 624 | // Break up allocas |
| Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 625 | if (UseNewSROA) |
| 626 | PM.add(createSROAPass()); |
| 627 | else |
| 628 | PM.add(createScalarReplAggregatesPass()); |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 629 | |
| 630 | // Run a few AA driven optimizations here and now, to cleanup the code. |
| Chandler Carruth | 9c4ed17 | 2016-02-18 11:03:11 +0000 | [diff] [blame] | 631 | PM.add(createPostOrderFunctionAttrsLegacyPass()); // Add nocapture. |
| Chandler Carruth | 7b560d4 | 2015-09-09 17:55:00 +0000 | [diff] [blame] | 632 | PM.add(createGlobalsAAWrapperPass()); // IP alias analysis. |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 633 | |
| Bill Wendling | 932b992 | 2012-04-02 22:16:50 +0000 | [diff] [blame] | 634 | PM.add(createLICMPass()); // Hoist loop invariants. |
| Gerolf Hoflehner | 24815d9 | 2014-09-10 19:55:29 +0000 | [diff] [blame] | 635 | if (EnableMLSM) |
| 636 | PM.add(createMergedLoadStoreMotionPass()); // Merge ld/st in diamonds. |
| Bill Wendling | 932b992 | 2012-04-02 22:16:50 +0000 | [diff] [blame] | 637 | PM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies. |
| 638 | PM.add(createMemCpyOptPass()); // Remove dead memcpys. |
| Bill Wendling | 4c0d9ad | 2013-08-30 00:48:37 +0000 | [diff] [blame] | 639 | |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 640 | // Nuke dead stores. |
| 641 | PM.add(createDeadStoreEliminationPass()); |
| 642 | |
| Duncan P. N. Exon Smith | 2b69189 | 2014-04-15 17:48:15 +0000 | [diff] [blame] | 643 | // More loops are countable; try to optimize them. |
| 644 | PM.add(createIndVarSimplifyPass()); |
| 645 | PM.add(createLoopDeletionPass()); |
| Karthik Bhat | 88db86d | 2015-03-06 10:11:25 +0000 | [diff] [blame] | 646 | if (EnableLoopInterchange) |
| 647 | PM.add(createLoopInterchangePass()); |
| 648 | |
| James Molloy | 31f3ddd | 2016-01-14 15:00:09 +0000 | [diff] [blame] | 649 | if (!DisableUnrollLoops) |
| 650 | PM.add(createSimpleLoopUnrollPass()); // Unroll small loops |
| Arnold Schwaighofer | eb1a38f | 2014-10-26 21:50:58 +0000 | [diff] [blame] | 651 | PM.add(createLoopVectorizePass(true, LoopVectorize)); |
| James Molloy | 31f3ddd | 2016-01-14 15:00:09 +0000 | [diff] [blame] | 652 | // The vectorizer may have significantly shortened a loop body; unroll again. |
| 653 | if (!DisableUnrollLoops) |
| 654 | PM.add(createLoopUnrollPass()); |
| Arnold Schwaighofer | 6ccda92 | 2014-02-24 18:19:31 +0000 | [diff] [blame] | 655 | |
| James Molloy | 6045cc8 | 2015-12-15 09:24:01 +0000 | [diff] [blame] | 656 | // Now that we've optimized loops (in particular loop induction variables), |
| 657 | // we may have exposed more scalar opportunities. Run parts of the scalar |
| 658 | // optimizer again at this point. |
| 659 | PM.add(createInstructionCombiningPass()); // Initial cleanup |
| 660 | PM.add(createCFGSimplificationPass()); // if-convert |
| 661 | PM.add(createSCCPPass()); // Propagate exposed constants |
| 662 | PM.add(createInstructionCombiningPass()); // Clean up again |
| 663 | PM.add(createBitTrackingDCEPass()); |
| 664 | |
| Yi Jiang | 79eb0aa | 2014-05-05 23:14:46 +0000 | [diff] [blame] | 665 | // More scalar chains could be vectorized due to more alias information |
| JF Bastien | f42a6ea | 2014-10-21 23:18:21 +0000 | [diff] [blame] | 666 | if (RunSLPAfterLoopVectorization) |
| 667 | if (SLPVectorize) |
| 668 | PM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains. |
| Yi Jiang | 79eb0aa | 2014-05-05 23:14:46 +0000 | [diff] [blame] | 669 | |
| Hal Finkel | d67e463 | 2014-09-07 20:05:11 +0000 | [diff] [blame] | 670 | // After vectorization, assume intrinsics may tell us more about pointer |
| 671 | // alignments. |
| 672 | PM.add(createAlignmentFromAssumptionsPass()); |
| 673 | |
| Michael J. Spencer | 289067c | 2014-05-29 01:55:07 +0000 | [diff] [blame] | 674 | if (LoadCombine) |
| 675 | PM.add(createLoadCombinePass()); |
| 676 | |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 677 | // Cleanup and simplify the code after the scalar optimizations. |
| 678 | PM.add(createInstructionCombiningPass()); |
| Peter Collingbourne | 0a43761 | 2014-05-25 10:27:02 +0000 | [diff] [blame] | 679 | addExtensionsToPM(EP_Peephole, PM); |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 680 | |
| 681 | PM.add(createJumpThreadingPass()); |
| Peter Collingbourne | 070843d | 2015-03-19 22:01:00 +0000 | [diff] [blame] | 682 | } |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 683 | |
| Peter Collingbourne | df49d1b | 2016-02-09 22:50:34 +0000 | [diff] [blame] | 684 | void PassManagerBuilder::addEarlyLTOOptimizationPasses( |
| 685 | legacy::PassManagerBase &PM) { |
| 686 | // Remove unused virtual tables to improve the quality of code generated by |
| 687 | // whole-program devirtualization and bitset lowering. |
| 688 | PM.add(createGlobalDCEPass()); |
| 689 | |
| 690 | // Apply whole-program devirtualization and virtual constant propagation. |
| 691 | PM.add(createWholeProgramDevirtPass()); |
| 692 | } |
| 693 | |
| Peter Collingbourne | 070843d | 2015-03-19 22:01:00 +0000 | [diff] [blame] | 694 | void PassManagerBuilder::addLateLTOOptimizationPasses( |
| 695 | legacy::PassManagerBase &PM) { |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 696 | // Delete basic blocks, which optimization passes may have killed. |
| Tom Stellard | aa664d9 | 2013-08-06 02:43:45 +0000 | [diff] [blame] | 697 | PM.add(createCFGSimplificationPass()); |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 698 | |
| Teresa Johnson | c4279a7 | 2015-08-11 16:26:41 +0000 | [diff] [blame] | 699 | // Drop bodies of available externally objects to improve GlobalDCE. |
| 700 | PM.add(createEliminateAvailableExternallyPass()); |
| 701 | |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 702 | // Now that we have optimized the program, discard unreachable functions. |
| 703 | PM.add(createGlobalDCEPass()); |
| Nick Lewycky | 9e6d184 | 2014-09-13 21:46:00 +0000 | [diff] [blame] | 704 | |
| 705 | // FIXME: this is profitable (for compiler time) to do at -O0 too, but |
| 706 | // currently it damages debug info. |
| 707 | if (MergeFunctions) |
| 708 | PM.add(createMergeFunctionsPass()); |
| Rafael Espindola | 3ea478b | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 709 | } |
| Rafael Espindola | 07f60915 | 2011-08-09 22:17:34 +0000 | [diff] [blame] | 710 | |
| Mehdi Amini | 1db10ac | 2016-02-16 23:02:29 +0000 | [diff] [blame] | 711 | void PassManagerBuilder::populateThinLTOPassManager( |
| 712 | legacy::PassManagerBase &PM) { |
| 713 | PerformThinLTO = true; |
| 714 | |
| 715 | if (VerifyInput) |
| 716 | PM.add(createVerifierPass()); |
| 717 | |
| 718 | if (FunctionIndex) |
| 719 | PM.add(createFunctionImportPass(FunctionIndex)); |
| 720 | |
| 721 | populateModulePassManager(PM); |
| 722 | |
| 723 | if (VerifyOutput) |
| 724 | PM.add(createVerifierPass()); |
| 725 | PerformThinLTO = false; |
| 726 | } |
| 727 | |
| Chandler Carruth | 30d69c2 | 2015-02-13 10:01:29 +0000 | [diff] [blame] | 728 | void PassManagerBuilder::populateLTOPassManager(legacy::PassManagerBase &PM) { |
| Rafael Espindola | 7cebf36 | 2014-08-21 20:03:44 +0000 | [diff] [blame] | 729 | if (LibraryInfo) |
| Chandler Carruth | b98f63d | 2015-01-15 10:41:28 +0000 | [diff] [blame] | 730 | PM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo)); |
| Rafael Espindola | 7cebf36 | 2014-08-21 20:03:44 +0000 | [diff] [blame] | 731 | |
| Duncan P. N. Exon Smith | ab58a56 | 2015-03-19 22:24:17 +0000 | [diff] [blame] | 732 | if (VerifyInput) |
| Rafael Espindola | 7cebf36 | 2014-08-21 20:03:44 +0000 | [diff] [blame] | 733 | PM.add(createVerifierPass()); |
| Rafael Espindola | 7cebf36 | 2014-08-21 20:03:44 +0000 | [diff] [blame] | 734 | |
| Peter Collingbourne | df49d1b | 2016-02-09 22:50:34 +0000 | [diff] [blame] | 735 | if (OptLevel != 0) |
| 736 | addEarlyLTOOptimizationPasses(PM); |
| 737 | |
| Peter Collingbourne | 070843d | 2015-03-19 22:01:00 +0000 | [diff] [blame] | 738 | if (OptLevel > 1) |
| Rafael Espindola | 7cebf36 | 2014-08-21 20:03:44 +0000 | [diff] [blame] | 739 | addLTOOptimizationPasses(PM); |
| 740 | |
| Evgeniy Stepanov | 67849d5 | 2015-12-15 23:00:08 +0000 | [diff] [blame] | 741 | // Create a function that performs CFI checks for cross-DSO calls with targets |
| 742 | // in the current module. |
| 743 | PM.add(createCrossDSOCFIPass()); |
| 744 | |
| Peter Collingbourne | 070843d | 2015-03-19 22:01:00 +0000 | [diff] [blame] | 745 | // Lower bit sets to globals. This pass supports Clang's control flow |
| 746 | // integrity mechanisms (-fsanitize=cfi*) and needs to run at link time if CFI |
| 747 | // is enabled. The pass does nothing if CFI is disabled. |
| 748 | PM.add(createLowerBitSetsPass()); |
| 749 | |
| 750 | if (OptLevel != 0) |
| 751 | addLateLTOOptimizationPasses(PM); |
| 752 | |
| Duncan P. N. Exon Smith | ab58a56 | 2015-03-19 22:24:17 +0000 | [diff] [blame] | 753 | if (VerifyOutput) |
| Rafael Espindola | 7cebf36 | 2014-08-21 20:03:44 +0000 | [diff] [blame] | 754 | PM.add(createVerifierPass()); |
| Rafael Espindola | 7cebf36 | 2014-08-21 20:03:44 +0000 | [diff] [blame] | 755 | } |
| 756 | |
| Eric Christopher | 04d4e93 | 2013-04-22 22:47:22 +0000 | [diff] [blame] | 757 | inline PassManagerBuilder *unwrap(LLVMPassManagerBuilderRef P) { |
| 758 | return reinterpret_cast<PassManagerBuilder*>(P); |
| 759 | } |
| 760 | |
| 761 | inline LLVMPassManagerBuilderRef wrap(PassManagerBuilder *P) { |
| 762 | return reinterpret_cast<LLVMPassManagerBuilderRef>(P); |
| 763 | } |
| 764 | |
| Dmitri Gribenko | 0011bbf | 2012-11-15 16:51:49 +0000 | [diff] [blame] | 765 | LLVMPassManagerBuilderRef LLVMPassManagerBuilderCreate() { |
| Rafael Espindola | 07f60915 | 2011-08-09 22:17:34 +0000 | [diff] [blame] | 766 | PassManagerBuilder *PMB = new PassManagerBuilder(); |
| 767 | return wrap(PMB); |
| 768 | } |
| 769 | |
| 770 | void LLVMPassManagerBuilderDispose(LLVMPassManagerBuilderRef PMB) { |
| 771 | PassManagerBuilder *Builder = unwrap(PMB); |
| 772 | delete Builder; |
| 773 | } |
| 774 | |
| 775 | void |
| 776 | LLVMPassManagerBuilderSetOptLevel(LLVMPassManagerBuilderRef PMB, |
| 777 | unsigned OptLevel) { |
| 778 | PassManagerBuilder *Builder = unwrap(PMB); |
| 779 | Builder->OptLevel = OptLevel; |
| 780 | } |
| 781 | |
| 782 | void |
| 783 | LLVMPassManagerBuilderSetSizeLevel(LLVMPassManagerBuilderRef PMB, |
| 784 | unsigned SizeLevel) { |
| 785 | PassManagerBuilder *Builder = unwrap(PMB); |
| 786 | Builder->SizeLevel = SizeLevel; |
| 787 | } |
| 788 | |
| 789 | void |
| 790 | LLVMPassManagerBuilderSetDisableUnitAtATime(LLVMPassManagerBuilderRef PMB, |
| 791 | LLVMBool Value) { |
| 792 | PassManagerBuilder *Builder = unwrap(PMB); |
| 793 | Builder->DisableUnitAtATime = Value; |
| 794 | } |
| 795 | |
| 796 | void |
| 797 | LLVMPassManagerBuilderSetDisableUnrollLoops(LLVMPassManagerBuilderRef PMB, |
| 798 | LLVMBool Value) { |
| 799 | PassManagerBuilder *Builder = unwrap(PMB); |
| 800 | Builder->DisableUnrollLoops = Value; |
| 801 | } |
| 802 | |
| 803 | void |
| 804 | LLVMPassManagerBuilderSetDisableSimplifyLibCalls(LLVMPassManagerBuilderRef PMB, |
| 805 | LLVMBool Value) { |
| Meador Inge | dfb08a2 | 2013-06-20 19:48:07 +0000 | [diff] [blame] | 806 | // NOTE: The simplify-libcalls pass has been removed. |
| Rafael Espindola | 07f60915 | 2011-08-09 22:17:34 +0000 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | void |
| 810 | LLVMPassManagerBuilderUseInlinerWithThreshold(LLVMPassManagerBuilderRef PMB, |
| 811 | unsigned Threshold) { |
| 812 | PassManagerBuilder *Builder = unwrap(PMB); |
| 813 | Builder->Inliner = createFunctionInliningPass(Threshold); |
| 814 | } |
| 815 | |
| 816 | void |
| 817 | LLVMPassManagerBuilderPopulateFunctionPassManager(LLVMPassManagerBuilderRef PMB, |
| 818 | LLVMPassManagerRef PM) { |
| 819 | PassManagerBuilder *Builder = unwrap(PMB); |
| Chandler Carruth | 30d69c2 | 2015-02-13 10:01:29 +0000 | [diff] [blame] | 820 | legacy::FunctionPassManager *FPM = unwrap<legacy::FunctionPassManager>(PM); |
| Rafael Espindola | 07f60915 | 2011-08-09 22:17:34 +0000 | [diff] [blame] | 821 | Builder->populateFunctionPassManager(*FPM); |
| 822 | } |
| 823 | |
| 824 | void |
| 825 | LLVMPassManagerBuilderPopulateModulePassManager(LLVMPassManagerBuilderRef PMB, |
| 826 | LLVMPassManagerRef PM) { |
| 827 | PassManagerBuilder *Builder = unwrap(PMB); |
| Chandler Carruth | 30d69c2 | 2015-02-13 10:01:29 +0000 | [diff] [blame] | 828 | legacy::PassManagerBase *MPM = unwrap(PM); |
| Rafael Espindola | 07f60915 | 2011-08-09 22:17:34 +0000 | [diff] [blame] | 829 | Builder->populateModulePassManager(*MPM); |
| 830 | } |
| 831 | |
| 832 | void LLVMPassManagerBuilderPopulateLTOPassManager(LLVMPassManagerBuilderRef PMB, |
| 833 | LLVMPassManagerRef PM, |
| Nick Lewycky | 5f50854 | 2013-03-10 21:58:22 +0000 | [diff] [blame] | 834 | LLVMBool Internalize, |
| 835 | LLVMBool RunInliner) { |
| Rafael Espindola | 07f60915 | 2011-08-09 22:17:34 +0000 | [diff] [blame] | 836 | PassManagerBuilder *Builder = unwrap(PMB); |
| Chandler Carruth | 30d69c2 | 2015-02-13 10:01:29 +0000 | [diff] [blame] | 837 | legacy::PassManagerBase *LPM = unwrap(PM); |
| Rafael Espindola | e07caad | 2014-08-21 13:35:30 +0000 | [diff] [blame] | 838 | |
| 839 | // A small backwards compatibility hack. populateLTOPassManager used to take |
| 840 | // an RunInliner option. |
| 841 | if (RunInliner && !Builder->Inliner) |
| 842 | Builder->Inliner = createFunctionInliningPass(); |
| 843 | |
| 844 | Builder->populateLTOPassManager(*LPM); |
| Rafael Espindola | 07f60915 | 2011-08-09 22:17:34 +0000 | [diff] [blame] | 845 | } |