blob: 9876efa7b235510423006a9834b0bf2d2767b917 [file] [log] [blame]
Rafael Espindola3ea478b2011-08-02 21:50:27 +00001//===- 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 Espindola3ea478b2011-08-02 21:50:27 +000015#include "llvm/Transforms/IPO/PassManagerBuilder.h"
Rafael Espindola07f609152011-08-09 22:17:34 +000016#include "llvm-c/Transforms/PassManagerBuilder.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000017#include "llvm/ADT/SmallVector.h"
Chandler Carruth17e0bc32015-08-06 07:33:15 +000018#include "llvm/Analysis/BasicAliasAnalysis.h"
Chandler Carruth8b046a42015-08-14 02:42:20 +000019#include "llvm/Analysis/CFLAliasAnalysis.h"
Chandler Carruth21dcff72015-08-14 03:48:20 +000020#include "llvm/Analysis/GlobalsModRef.h"
Chandler Carruth3a040e62015-12-27 08:41:34 +000021#include "llvm/Analysis/Passes.h"
Chandler Carruth42ff4482015-08-14 02:55:50 +000022#include "llvm/Analysis/ScopedNoAliasAA.h"
Chandler Carruth62d42152015-01-15 02:16:27 +000023#include "llvm/Analysis/TargetLibraryInfo.h"
Chandler Carruth1db22822015-08-14 03:33:48 +000024#include "llvm/Analysis/TypeBasedAliasAnalysis.h"
Chandler Carruth3a040e62015-12-27 08:41:34 +000025#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 Espindola7cebf362014-08-21 20:03:44 +000031#include "llvm/Target/TargetMachine.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000032#include "llvm/Transforms/IPO.h"
Chandler Carruthf49f1a872015-12-27 08:13:45 +000033#include "llvm/Transforms/IPO/ForceFunctionAttrs.h"
Chandler Carruth3a040e62015-12-27 08:41:34 +000034#include "llvm/Transforms/IPO/InferFunctionAttrs.h"
Rafael Espindola3ea478b2011-08-02 21:50:27 +000035#include "llvm/Transforms/Scalar.h"
Hal Finkelc34e5112012-02-01 03:51:43 +000036#include "llvm/Transforms/Vectorize.h"
Rafael Espindola3ea478b2011-08-02 21:50:27 +000037
38using namespace llvm;
39
Hal Finkelc34e5112012-02-01 03:51:43 +000040static cl::opt<bool>
Nadav Rotem7f27e0b2013-10-18 23:38:13 +000041RunLoopVectorization("vectorize-loops", cl::Hidden,
Nadav Rotemd3df6652012-10-30 18:37:43 +000042 cl::desc("Run the Loop vectorization passes"));
Nadav Rotemc59ae202012-10-29 16:36:25 +000043
44static cl::opt<bool>
Nadav Rotem7f27e0b2013-10-18 23:38:13 +000045RunSLPVectorization("vectorize-slp", cl::Hidden,
Nadav Rotemd4dcc002013-04-15 05:39:58 +000046 cl::desc("Run the SLP vectorization passes"));
47
48static cl::opt<bool>
Nadav Rotem7f27e0b2013-10-18 23:38:13 +000049RunBBVectorization("vectorize-slp-aggressive", cl::Hidden,
Nadav Rotemd4dcc002013-04-15 05:39:58 +000050 cl::desc("Run the BB vectorization passes"));
Hal Finkelc34e5112012-02-01 03:51:43 +000051
Hal Finkel204bf532012-04-13 17:15:33 +000052static cl::opt<bool>
53UseGVNAfterVectorization("use-gvn-after-vectorization",
54 cl::init(false), cl::Hidden,
55 cl::desc("Run GVN instead of Early CSE after vectorization passes"));
56
Chandler Carruth7b8297a2014-10-14 00:31:29 +000057static cl::opt<bool> ExtraVectorizerPasses(
58 "extra-vectorizer-passes", cl::init(false), cl::Hidden,
59 cl::desc("Run cleanup optimization passes after vectorization."));
60
Chandler Carruth1b398ae2012-09-14 09:22:59 +000061static cl::opt<bool> UseNewSROA("use-new-sroa",
Chandler Carruth4e435992012-10-02 04:24:01 +000062 cl::init(true), cl::Hidden,
Chandler Carruth1b398ae2012-09-14 09:22:59 +000063 cl::desc("Enable the new, experimental SROA pass"));
64
Hal Finkelbf45efd2013-11-16 23:59:05 +000065static cl::opt<bool>
66RunLoopRerolling("reroll-loops", cl::Hidden,
67 cl::desc("Run the loop rerolling pass"));
68
James Molloy0cbb2a862015-03-27 10:36:57 +000069static cl::opt<bool>
70RunFloat2Int("float-to-int", cl::Hidden, cl::init(true),
71 cl::desc("Run the float2int (float demotion) pass"));
72
Michael J. Spencer289067c2014-05-29 01:55:07 +000073static cl::opt<bool> RunLoadCombine("combine-loads", cl::init(false),
74 cl::Hidden,
75 cl::desc("Run the load combining pass"));
76
James Molloy568da092014-08-06 12:56:19 +000077static cl::opt<bool>
78RunSLPAfterLoopVectorization("run-slp-after-loop-vectorization",
James Molloy6b95d8e2014-09-04 13:23:08 +000079 cl::init(true), cl::Hidden,
James Molloy568da092014-08-06 12:56:19 +000080 cl::desc("Run the SLP vectorizer (and BB vectorizer) after the Loop "
81 "vectorizer instead of before"));
82
Hal Finkel445dda52014-09-02 22:12:54 +000083static cl::opt<bool> UseCFLAA("use-cfl-aa",
84 cl::init(false), cl::Hidden,
85 cl::desc("Enable the new, experimental CFL alias analysis"));
James Molloy568da092014-08-06 12:56:19 +000086
Gerolf Hoflehner24815d92014-09-10 19:55:29 +000087static cl::opt<bool>
Gerolf Hoflehner008e5cd2014-09-10 20:24:03 +000088EnableMLSM("mlsm", cl::init(true), cl::Hidden,
89 cl::desc("Enable motion of merged load and store"));
Gerolf Hoflehner24815d92014-09-10 19:55:29 +000090
Karthik Bhat88db86d2015-03-06 10:11:25 +000091static cl::opt<bool> EnableLoopInterchange(
92 "enable-loopinterchange", cl::init(false), cl::Hidden,
93 cl::desc("Enable the new, experimental LoopInterchange Pass"));
94
Adam Nemet938d3d62015-05-14 12:05:18 +000095static cl::opt<bool> EnableLoopDistribute(
96 "enable-loop-distribute", cl::init(false), cl::Hidden,
97 cl::desc("Enable the new, experimental LoopDistribution Pass"));
98
Chandler Carruthe9ea5a62015-07-22 11:57:28 +000099static cl::opt<bool> EnableNonLTOGlobalsModRef(
James Molloy40159252015-10-13 10:43:57 +0000100 "enable-non-lto-gmr", cl::init(true), cl::Hidden,
Chandler Carruthe9ea5a62015-07-22 11:57:28 +0000101 cl::desc(
102 "Enable the GlobalsModRef AliasAnalysis outside of the LTO pipeline."));
103
Adam Nemete54a4fa2015-11-03 23:50:08 +0000104static cl::opt<bool> EnableLoopLoadElim(
105 "enable-loop-load-elim", cl::init(false), cl::Hidden,
106 cl::desc("Enable the new, experimental LoopLoadElimination Pass"));
107
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000108PassManagerBuilder::PassManagerBuilder() {
109 OptLevel = 2;
110 SizeLevel = 0;
Craig Topperf40110f2014-04-25 05:29:35 +0000111 LibraryInfo = nullptr;
112 Inliner = nullptr;
Teresa Johnson5fcbdb72015-12-07 19:21:11 +0000113 FunctionIndex = nullptr;
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000114 DisableUnitAtATime = false;
115 DisableUnrollLoops = false;
Nadav Rotemd4dcc002013-04-15 05:39:58 +0000116 BBVectorize = RunBBVectorization;
Nadav Rotema1e5e442013-04-15 04:54:42 +0000117 SLPVectorize = RunSLPVectorization;
Nadav Rotemc59ae202012-10-29 16:36:25 +0000118 LoopVectorize = RunLoopVectorization;
Hal Finkel29aeb202013-11-17 16:02:50 +0000119 RerollLoops = RunLoopRerolling;
Michael J. Spencer289067c2014-05-29 01:55:07 +0000120 LoadCombine = RunLoadCombine;
Rafael Espindola208bc532014-08-21 13:13:17 +0000121 DisableGVNLoadPRE = false;
Rafael Espindola7cebf362014-08-21 20:03:44 +0000122 VerifyInput = false;
123 VerifyOutput = false;
Nick Lewycky9e6d1842014-09-13 21:46:00 +0000124 MergeFunctions = false;
Teresa Johnsond3a33a12015-07-06 16:22:42 +0000125 PrepareForLTO = false;
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000126}
127
128PassManagerBuilder::~PassManagerBuilder() {
129 delete LibraryInfo;
130 delete Inliner;
131}
132
David Chisnall719a72f2011-08-16 13:58:41 +0000133/// Set of global extensions, automatically added as part of the standard set.
134static ManagedStatic<SmallVector<std::pair<PassManagerBuilder::ExtensionPointTy,
135 PassManagerBuilder::ExtensionFn>, 8> > GlobalExtensions;
136
137void PassManagerBuilder::addGlobalExtension(
138 PassManagerBuilder::ExtensionPointTy Ty,
139 PassManagerBuilder::ExtensionFn Fn) {
140 GlobalExtensions->push_back(std::make_pair(Ty, Fn));
141}
142
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000143void PassManagerBuilder::addExtension(ExtensionPointTy Ty, ExtensionFn Fn) {
144 Extensions.push_back(std::make_pair(Ty, Fn));
145}
146
147void PassManagerBuilder::addExtensionsToPM(ExtensionPointTy ETy,
Chandler Carruth30d69c22015-02-13 10:01:29 +0000148 legacy::PassManagerBase &PM) const {
David Chisnall719a72f2011-08-16 13:58:41 +0000149 for (unsigned i = 0, e = GlobalExtensions->size(); i != e; ++i)
150 if ((*GlobalExtensions)[i].first == ETy)
151 (*GlobalExtensions)[i].second(*this, PM);
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000152 for (unsigned i = 0, e = Extensions.size(); i != e; ++i)
153 if (Extensions[i].first == ETy)
154 Extensions[i].second(*this, PM);
155}
156
Chandler Carruth30d69c22015-02-13 10:01:29 +0000157void PassManagerBuilder::addInitialAliasAnalysisPasses(
158 legacy::PassManagerBase &PM) const {
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000159 // Add TypeBasedAliasAnalysis before BasicAliasAnalysis so that
160 // BasicAliasAnalysis wins if they disagree. This is intended to help
161 // support "obvious" type-punning idioms.
Hal Finkel445dda52014-09-02 22:12:54 +0000162 if (UseCFLAA)
Chandler Carruth7b560d42015-09-09 17:55:00 +0000163 PM.add(createCFLAAWrapperPass());
164 PM.add(createTypeBasedAAWrapperPass());
165 PM.add(createScopedNoAliasAAWrapperPass());
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000166}
167
Chandler Carruth30d69c22015-02-13 10:01:29 +0000168void PassManagerBuilder::populateFunctionPassManager(
169 legacy::FunctionPassManager &FPM) {
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000170 addExtensionsToPM(EP_EarlyAsPossible, FPM);
171
172 // Add LibraryInfo if we have some.
Chandler Carruthb98f63d2015-01-15 10:41:28 +0000173 if (LibraryInfo)
174 FPM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000175
176 if (OptLevel == 0) return;
177
178 addInitialAliasAnalysisPasses(FPM);
179
180 FPM.add(createCFGSimplificationPass());
Chandler Carruth1b398ae2012-09-14 09:22:59 +0000181 if (UseNewSROA)
182 FPM.add(createSROAPass());
183 else
184 FPM.add(createScalarReplAggregatesPass());
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000185 FPM.add(createEarlyCSEPass());
186 FPM.add(createLowerExpectIntrinsicPass());
187}
188
Chandler Carruth30d69c22015-02-13 10:01:29 +0000189void PassManagerBuilder::populateModulePassManager(
190 legacy::PassManagerBase &MPM) {
Chandler Carruthf49f1a872015-12-27 08:13:45 +0000191 // Allow forcing function attributes as a debugging and tuning aid.
192 MPM.add(createForceFunctionAttrsLegacyPass());
193
Nick Lewycky592d8492014-10-23 23:49:31 +0000194 // If all optimizations are disabled, just run the always-inline pass and,
195 // if enabled, the function merging pass.
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000196 if (OptLevel == 0) {
197 if (Inliner) {
198 MPM.add(Inliner);
Craig Topperf40110f2014-04-25 05:29:35 +0000199 Inliner = nullptr;
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000200 }
Chandler Carruthe8479e12012-10-18 08:05:46 +0000201
Nick Lewycky592d8492014-10-23 23:49:31 +0000202 // FIXME: The BarrierNoopPass is a HACK! The inliner pass above implicitly
203 // creates a CGSCC pass manager, but we don't want to add extensions into
204 // that pass manager. To prevent this we insert a no-op module pass to reset
205 // the pass manager to get the same behavior as EP_OptimizerLast in non-O0
206 // builds. The function merging pass is
207 if (MergeFunctions)
208 MPM.add(createMergeFunctionsPass());
209 else if (!GlobalExtensions->empty() || !Extensions.empty())
Chandler Carruthe8479e12012-10-18 08:05:46 +0000210 MPM.add(createBarrierNoopPass());
211
Kostya Serebryanydc436f92011-11-30 22:19:26 +0000212 addExtensionsToPM(EP_EnabledOnOptLevel0, MPM);
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000213 return;
214 }
215
216 // Add LibraryInfo if we have some.
Chandler Carruthb98f63d2015-01-15 10:41:28 +0000217 if (LibraryInfo)
218 MPM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000219
220 addInitialAliasAnalysisPasses(MPM);
221
222 if (!DisableUnitAtATime) {
Chandler Carruth3a040e62015-12-27 08:41:34 +0000223 // Infer attributes about declarations if possible.
224 MPM.add(createInferFunctionAttrsLegacyPass());
225
Dan Gohmanb9936292012-01-17 20:51:32 +0000226 addExtensionsToPM(EP_ModuleOptimizerEarly, MPM);
227
Gerolf Hoflehner65b13322014-07-03 19:28:15 +0000228 MPM.add(createIPSCCPPass()); // IP SCCP
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000229 MPM.add(createGlobalOptimizerPass()); // Optimize out global vars
James Molloy6045cc82015-12-15 09:24:01 +0000230 // Promote any localized global vars
231 MPM.add(createPromoteMemoryToRegisterPass());
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000232
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000233 MPM.add(createDeadArgEliminationPass()); // Dead argument elimination
234
235 MPM.add(createInstructionCombiningPass());// Clean up after IPCP & DAE
Peter Collingbourne0a437612014-05-25 10:27:02 +0000236 addExtensionsToPM(EP_Peephole, MPM);
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000237 MPM.add(createCFGSimplificationPass()); // Clean up after IPCP & DAE
238 }
239
Chandler Carruthe9ea5a62015-07-22 11:57:28 +0000240 if (EnableNonLTOGlobalsModRef)
241 // We add a module alias analysis pass here. In part due to bugs in the
242 // analysis infrastructure this "works" in that the analysis stays alive
243 // for the entire SCC pass run below.
Chandler Carruth7b560d42015-09-09 17:55:00 +0000244 MPM.add(createGlobalsAAWrapperPass());
Chandler Carruthe9ea5a62015-07-22 11:57:28 +0000245
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000246 // Start of CallGraph SCC passes.
247 if (!DisableUnitAtATime)
248 MPM.add(createPruneEHPass()); // Remove dead EH info
249 if (Inliner) {
250 MPM.add(Inliner);
Craig Topperf40110f2014-04-25 05:29:35 +0000251 Inliner = nullptr;
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000252 }
253 if (!DisableUnitAtATime)
254 MPM.add(createFunctionAttrsPass()); // Set readonly/readnone attrs
255 if (OptLevel > 2)
256 MPM.add(createArgumentPromotionPass()); // Scalarize uninlined fn args
257
258 // Start of function pass.
259 // Break up aggregate allocas, using SSAUpdater.
Chandler Carruth70b44c52012-09-15 11:43:14 +0000260 if (UseNewSROA)
Mehdi Aminid134a672015-08-23 22:15:49 +0000261 MPM.add(createSROAPass());
Chandler Carruth70b44c52012-09-15 11:43:14 +0000262 else
263 MPM.add(createScalarReplAggregatesPass(-1, false));
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000264 MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000265 MPM.add(createJumpThreadingPass()); // Thread jumps.
266 MPM.add(createCorrelatedValuePropagationPass()); // Propagate conditionals
267 MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
268 MPM.add(createInstructionCombiningPass()); // Combine silly seq's
Peter Collingbourne0a437612014-05-25 10:27:02 +0000269 addExtensionsToPM(EP_Peephole, MPM);
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000270
Akira Hatanakad9699bc2015-06-09 19:07:19 +0000271 MPM.add(createTailCallEliminationPass()); // Eliminate tail calls
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000272 MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
273 MPM.add(createReassociatePass()); // Reassociate expressions
Roman Divackyd2b9a1b2014-11-21 19:53:24 +0000274 // Rotate Loop - disable header duplication at -Oz
275 MPM.add(createLoopRotatePass(SizeLevel == 2 ? 0 : -1));
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000276 MPM.add(createLICMPass()); // Hoist loop invariants
277 MPM.add(createLoopUnswitchPass(SizeLevel || OptLevel < 3));
Michael Zolotukhin74621cc2015-09-24 03:50:17 +0000278 MPM.add(createCFGSimplificationPass());
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000279 MPM.add(createInstructionCombiningPass());
280 MPM.add(createIndVarSimplifyPass()); // Canonicalize indvars
281 MPM.add(createLoopIdiomPass()); // Recognize idioms like memset.
282 MPM.add(createLoopDeletionPass()); // Delete dead loops
Karthik Bhat8210fdf2015-04-23 04:51:44 +0000283 if (EnableLoopInterchange) {
Karthik Bhat88db86d2015-03-06 10:11:25 +0000284 MPM.add(createLoopInterchangePass()); // Interchange loops
Karthik Bhat8210fdf2015-04-23 04:51:44 +0000285 MPM.add(createCFGSimplificationPass());
286 }
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000287 if (!DisableUnrollLoops)
Hal Finkel86b30642014-03-31 23:23:51 +0000288 MPM.add(createSimpleLoopUnrollPass()); // Unroll small loops
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000289 addExtensionsToPM(EP_LoopOptimizerEnd, MPM);
290
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000291 if (OptLevel > 1) {
Gerolf Hoflehner24815d92014-09-10 19:55:29 +0000292 if (EnableMLSM)
293 MPM.add(createMergedLoadStoreMotionPass()); // Merge ld/st in diamonds
Rafael Espindola208bc532014-08-21 13:13:17 +0000294 MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000295 }
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000296 MPM.add(createMemCpyOptPass()); // Remove memcpy / form memset
297 MPM.add(createSCCPPass()); // Constant prop with SCCP
298
Hal Finkel2bb61ba2015-02-17 01:36:59 +0000299 // Delete dead bit computations (instcombine runs after to fold away the dead
300 // computations, and then ADCE will run later to exploit any new DCE
301 // opportunities that creates).
302 MPM.add(createBitTrackingDCEPass()); // Delete dead bit computations
303
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000304 // Run instcombine after redundancy elimination to exploit opportunities
305 // opened up by them.
306 MPM.add(createInstructionCombiningPass());
Peter Collingbourne0a437612014-05-25 10:27:02 +0000307 addExtensionsToPM(EP_Peephole, MPM);
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000308 MPM.add(createJumpThreadingPass()); // Thread jumps
309 MPM.add(createCorrelatedValuePropagationPass());
310 MPM.add(createDeadStoreEliminationPass()); // Delete dead stores
James Molloy83570242015-02-16 18:59:54 +0000311 MPM.add(createLICMPass());
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000312
313 addExtensionsToPM(EP_ScalarOptimizerLate, MPM);
314
Hal Finkel29aeb202013-11-17 16:02:50 +0000315 if (RerollLoops)
Hal Finkelbf45efd2013-11-16 23:59:05 +0000316 MPM.add(createLoopRerollPass());
James Molloy568da092014-08-06 12:56:19 +0000317 if (!RunSLPAfterLoopVectorization) {
318 if (SLPVectorize)
319 MPM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.
Nadav Rotemd4dcc002013-04-15 05:39:58 +0000320
James Molloy568da092014-08-06 12:56:19 +0000321 if (BBVectorize) {
322 MPM.add(createBBVectorizePass());
323 MPM.add(createInstructionCombiningPass());
324 addExtensionsToPM(EP_Peephole, MPM);
325 if (OptLevel > 1 && UseGVNAfterVectorization)
Rafael Espindola208bc532014-08-21 13:13:17 +0000326 MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
James Molloy568da092014-08-06 12:56:19 +0000327 else
328 MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
Hal Finkelbf4db4f2013-01-29 00:22:49 +0000329
James Molloy568da092014-08-06 12:56:19 +0000330 // BBVectorize may have significantly shortened a loop body; unroll again.
331 if (!DisableUnrollLoops)
332 MPM.add(createLoopUnrollPass());
333 }
Hal Finkelc34e5112012-02-01 03:51:43 +0000334 }
335
Michael J. Spencer289067c2014-05-29 01:55:07 +0000336 if (LoadCombine)
337 MPM.add(createLoadCombinePass());
338
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000339 MPM.add(createAggressiveDCEPass()); // Delete dead instructions
Tom Stellardaa664d92013-08-06 02:43:45 +0000340 MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000341 MPM.add(createInstructionCombiningPass()); // Clean up after everything.
Peter Collingbourne0a437612014-05-25 10:27:02 +0000342 addExtensionsToPM(EP_Peephole, MPM);
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000343
Renato Golin729a3ae2013-12-05 21:20:02 +0000344 // FIXME: This is a HACK! The inliner pass above implicitly creates a CGSCC
345 // pass manager that we are specifically trying to avoid. To prevent this
346 // we must insert a no-op module pass to reset the pass manager.
347 MPM.add(createBarrierNoopPass());
Chandler Carruth7b8297a2014-10-14 00:31:29 +0000348
Yaron Keren611c7cf2015-09-02 06:34:11 +0000349 if (!DisableUnitAtATime && OptLevel > 1 && !PrepareForLTO) {
350 // Remove avail extern fns and globals definitions if we aren't
351 // compiling an object file for later LTO. For LTO we want to preserve
352 // these so they are eligible for inlining at link-time. Note if they
353 // are unreferenced they will be removed by GlobalDCE later, so
354 // this only impacts referenced available externally globals.
355 // Eventually they will be suppressed during codegen, but eliminating
356 // here enables more opportunity for GlobalDCE as it may make
357 // globals referenced by available external functions dead
358 // and saves running remaining passes on the eliminated functions.
359 MPM.add(createEliminateAvailableExternallyPass());
360 }
361
Chandler Carruth08eebe22015-07-23 09:34:01 +0000362 if (EnableNonLTOGlobalsModRef)
363 // We add a fresh GlobalsModRef run at this point. This is particularly
364 // useful as the above will have inlined, DCE'ed, and function-attr
365 // propagated everything. We should at this point have a reasonably minimal
366 // and richly annotated call graph. By computing aliasing and mod/ref
367 // information for all local globals here, the late loop passes and notably
368 // the vectorizer will be able to use them to help recognize vectorizable
369 // memory operations.
370 //
371 // Note that this relies on a bug in the pass manager which preserves
372 // a module analysis into a function pass pipeline (and throughout it) so
373 // long as the first function pass doesn't invalidate the module analysis.
374 // Thus both Float2Int and LoopRotate have to preserve AliasAnalysis for
375 // this to work. Fortunately, it is trivial to preserve AliasAnalysis
376 // (doing nothing preserves it as it is required to be conservatively
377 // correct in the face of IR changes).
Chandler Carruth7b560d42015-09-09 17:55:00 +0000378 MPM.add(createGlobalsAAWrapperPass());
Chandler Carruth08eebe22015-07-23 09:34:01 +0000379
James Molloy0cbb2a862015-03-27 10:36:57 +0000380 if (RunFloat2Int)
381 MPM.add(createFloat2IntPass());
382
Tobias Grosser39a7bd12015-07-16 08:20:37 +0000383 addExtensionsToPM(EP_VectorizerStart, MPM);
384
Chandler Carruth7b8297a2014-10-14 00:31:29 +0000385 // Re-rotate loops in all our loop nests. These may have fallout out of
386 // rotated form due to GVN or other transformations, and the vectorizer relies
Alexey Bataevda33d802015-07-10 10:37:09 +0000387 // on the rotated form. Disable header duplication at -Oz.
388 MPM.add(createLoopRotatePass(SizeLevel == 2 ? 0 : -1));
Chandler Carruth7b8297a2014-10-14 00:31:29 +0000389
Adam Nemet938d3d62015-05-14 12:05:18 +0000390 // Distribute loops to allow partial vectorization. I.e. isolate dependences
391 // into separate loop that would otherwise inhibit vectorization.
392 if (EnableLoopDistribute)
393 MPM.add(createLoopDistributePass());
394
Renato Golin729a3ae2013-12-05 21:20:02 +0000395 MPM.add(createLoopVectorizePass(DisableUnrollLoops, LoopVectorize));
Adam Nemete54a4fa2015-11-03 23:50:08 +0000396
397 // Eliminate loads by forwarding stores from the previous iteration to loads
398 // of the current iteration.
399 if (EnableLoopLoadElim)
400 MPM.add(createLoopLoadEliminationPass());
401
Renato Golin729a3ae2013-12-05 21:20:02 +0000402 // FIXME: Because of #pragma vectorize enable, the passes below are always
403 // inserted in the pipeline, even when the vectorizer doesn't run (ex. when
404 // on -O1 and no #pragma is found). Would be good to have these two passes
405 // as function calls, so that we can only pass them when the vectorizer
406 // changed the code.
407 MPM.add(createInstructionCombiningPass());
Chandler Carruth7b8297a2014-10-14 00:31:29 +0000408 if (OptLevel > 1 && ExtraVectorizerPasses) {
409 // At higher optimization levels, try to clean up any runtime overlap and
410 // alignment checks inserted by the vectorizer. We want to track correllated
411 // runtime checks for two inner loops in the same outer loop, fold any
412 // common computations, hoist loop-invariant aspects out of any outer loop,
413 // and unswitch the runtime checks if possible. Once hoisted, we may have
414 // dead (or speculatable) control flows or more combining opportunities.
415 MPM.add(createEarlyCSEPass());
416 MPM.add(createCorrelatedValuePropagationPass());
417 MPM.add(createInstructionCombiningPass());
418 MPM.add(createLICMPass());
419 MPM.add(createLoopUnswitchPass(SizeLevel || OptLevel < 3));
420 MPM.add(createCFGSimplificationPass());
421 MPM.add(createInstructionCombiningPass());
422 }
James Molloy568da092014-08-06 12:56:19 +0000423
424 if (RunSLPAfterLoopVectorization) {
Chandler Carruth7b8297a2014-10-14 00:31:29 +0000425 if (SLPVectorize) {
James Molloy568da092014-08-06 12:56:19 +0000426 MPM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.
Chandler Carruth7b8297a2014-10-14 00:31:29 +0000427 if (OptLevel > 1 && ExtraVectorizerPasses) {
428 MPM.add(createEarlyCSEPass());
429 }
430 }
James Molloy568da092014-08-06 12:56:19 +0000431
432 if (BBVectorize) {
433 MPM.add(createBBVectorizePass());
434 MPM.add(createInstructionCombiningPass());
435 addExtensionsToPM(EP_Peephole, MPM);
436 if (OptLevel > 1 && UseGVNAfterVectorization)
Rafael Espindola208bc532014-08-21 13:13:17 +0000437 MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
James Molloy568da092014-08-06 12:56:19 +0000438 else
439 MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
440
441 // BBVectorize may have significantly shortened a loop body; unroll again.
442 if (!DisableUnrollLoops)
443 MPM.add(createLoopUnrollPass());
444 }
445 }
446
Peter Collingbourne0a437612014-05-25 10:27:02 +0000447 addExtensionsToPM(EP_Peephole, MPM);
Renato Golin729a3ae2013-12-05 21:20:02 +0000448 MPM.add(createCFGSimplificationPass());
Chandler Carruth7b8297a2014-10-14 00:31:29 +0000449 MPM.add(createInstructionCombiningPass());
Chandler Carruth08e1b872013-06-24 07:21:47 +0000450
Kevin Qin49bc7642015-03-12 05:36:01 +0000451 if (!DisableUnrollLoops) {
Hal Finkel86b30642014-03-31 23:23:51 +0000452 MPM.add(createLoopUnrollPass()); // Unroll small loops
453
Wei Mibf727ba2015-05-14 22:02:54 +0000454 // LoopUnroll may generate some redundency to cleanup.
455 MPM.add(createInstructionCombiningPass());
456
Kevin Qin49bc7642015-03-12 05:36:01 +0000457 // Runtime unrolling will introduce runtime check in loop prologue. If the
458 // unrolled loop is a inner loop, then the prologue will be inside the
459 // outer loop. LICM pass can help to promote the runtime check out if the
460 // checked value is loop invariant.
461 MPM.add(createLICMPass());
462 }
463
Hal Finkeld67e4632014-09-07 20:05:11 +0000464 // After vectorization and unrolling, assume intrinsics may tell us more
465 // about pointer alignments.
466 MPM.add(createAlignmentFromAssumptionsPass());
467
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000468 if (!DisableUnitAtATime) {
469 // FIXME: We shouldn't bother with this anymore.
470 MPM.add(createStripDeadPrototypesPass()); // Get rid of dead prototypes
471
Evan Cheng8c6b06d2012-09-28 21:23:26 +0000472 // GlobalOpt already deletes dead functions and globals, at -O2 try a
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000473 // late pass of GlobalDCE. It is capable of deleting dead cycles.
Evan Cheng8c6b06d2012-09-28 21:23:26 +0000474 if (OptLevel > 1) {
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000475 MPM.add(createGlobalDCEPass()); // Remove dead fns and globals.
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000476 MPM.add(createConstantMergePass()); // Merge dup global constants
Evan Cheng8c6b06d2012-09-28 21:23:26 +0000477 }
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000478 }
Nick Lewycky9e6d1842014-09-13 21:46:00 +0000479
480 if (MergeFunctions)
481 MPM.add(createMergeFunctionsPass());
482
Kostya Serebryanye505a5a2012-03-23 23:22:59 +0000483 addExtensionsToPM(EP_OptimizerLast, MPM);
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000484}
485
Chandler Carruth30d69c22015-02-13 10:01:29 +0000486void PassManagerBuilder::addLTOOptimizationPasses(legacy::PassManagerBase &PM) {
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000487 // Provide AliasAnalysis services for optimizations.
488 addInitialAliasAnalysisPasses(PM);
489
Teresa Johnson5fcbdb72015-12-07 19:21:11 +0000490 if (FunctionIndex)
491 PM.add(createFunctionImportPass(FunctionIndex));
492
Chandler Carruthf49f1a872015-12-27 08:13:45 +0000493 // Allow forcing function attributes as a debugging and tuning aid.
494 PM.add(createForceFunctionAttrsLegacyPass());
495
Chandler Carruth3a040e62015-12-27 08:41:34 +0000496 // Infer attributes about declarations if possible.
497 PM.add(createInferFunctionAttrsLegacyPass());
498
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000499 // Propagate constants at call sites into the functions they call. This
500 // opens opportunities for globalopt (and inlining) by substituting function
501 // pointers passed as arguments to direct uses of functions.
502 PM.add(createIPSCCPPass());
503
504 // Now that we internalized some globals, see if we can hack on them!
James Molloy9ad4f222015-11-18 11:24:42 +0000505 PM.add(createFunctionAttrsPass()); // Add norecurse if possible.
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000506 PM.add(createGlobalOptimizerPass());
James Molloy6045cc82015-12-15 09:24:01 +0000507 // Promote any localized global vars.
508 PM.add(createPromoteMemoryToRegisterPass());
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000509
510 // Linking modules together can lead to duplicated global constants, only
511 // keep one copy of each constant.
512 PM.add(createConstantMergePass());
513
514 // Remove unused arguments from functions.
515 PM.add(createDeadArgEliminationPass());
516
517 // Reduce the code after globalopt and ipsccp. Both can open up significant
518 // simplification opportunities, and both can propagate functions through
519 // function pointers. When this happens, we often have to resolve varargs
520 // calls, etc, so let instcombine do this.
521 PM.add(createInstructionCombiningPass());
Peter Collingbourne0a437612014-05-25 10:27:02 +0000522 addExtensionsToPM(EP_Peephole, PM);
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000523
524 // Inline small functions
Rafael Espindolae07caad2014-08-21 13:35:30 +0000525 bool RunInliner = Inliner;
526 if (RunInliner) {
527 PM.add(Inliner);
528 Inliner = nullptr;
529 }
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000530
531 PM.add(createPruneEHPass()); // Remove dead EH info.
532
533 // Optimize globals again if we ran the inliner.
534 if (RunInliner)
535 PM.add(createGlobalOptimizerPass());
536 PM.add(createGlobalDCEPass()); // Remove dead functions.
537
538 // If we didn't decide to inline a function, check to see if we can
539 // transform it to pass arguments by value instead of by reference.
540 PM.add(createArgumentPromotionPass());
541
542 // The IPO passes may leave cruft around. Clean up after them.
543 PM.add(createInstructionCombiningPass());
Peter Collingbourne0a437612014-05-25 10:27:02 +0000544 addExtensionsToPM(EP_Peephole, PM);
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000545 PM.add(createJumpThreadingPass());
Bill Wendling4c0d9ad2013-08-30 00:48:37 +0000546
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000547 // Break up allocas
Chandler Carruth1b398ae2012-09-14 09:22:59 +0000548 if (UseNewSROA)
549 PM.add(createSROAPass());
550 else
551 PM.add(createScalarReplAggregatesPass());
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000552
553 // Run a few AA driven optimizations here and now, to cleanup the code.
554 PM.add(createFunctionAttrsPass()); // Add nocapture.
Chandler Carruth7b560d42015-09-09 17:55:00 +0000555 PM.add(createGlobalsAAWrapperPass()); // IP alias analysis.
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000556
Bill Wendling932b9922012-04-02 22:16:50 +0000557 PM.add(createLICMPass()); // Hoist loop invariants.
Gerolf Hoflehner24815d92014-09-10 19:55:29 +0000558 if (EnableMLSM)
559 PM.add(createMergedLoadStoreMotionPass()); // Merge ld/st in diamonds.
Bill Wendling932b9922012-04-02 22:16:50 +0000560 PM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies.
561 PM.add(createMemCpyOptPass()); // Remove dead memcpys.
Bill Wendling4c0d9ad2013-08-30 00:48:37 +0000562
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000563 // Nuke dead stores.
564 PM.add(createDeadStoreEliminationPass());
565
Duncan P. N. Exon Smith2b691892014-04-15 17:48:15 +0000566 // More loops are countable; try to optimize them.
567 PM.add(createIndVarSimplifyPass());
568 PM.add(createLoopDeletionPass());
Karthik Bhat88db86d2015-03-06 10:11:25 +0000569 if (EnableLoopInterchange)
570 PM.add(createLoopInterchangePass());
571
Arnold Schwaighofereb1a38f2014-10-26 21:50:58 +0000572 PM.add(createLoopVectorizePass(true, LoopVectorize));
Arnold Schwaighofer6ccda922014-02-24 18:19:31 +0000573
James Molloy6045cc82015-12-15 09:24:01 +0000574 // Now that we've optimized loops (in particular loop induction variables),
575 // we may have exposed more scalar opportunities. Run parts of the scalar
576 // optimizer again at this point.
577 PM.add(createInstructionCombiningPass()); // Initial cleanup
578 PM.add(createCFGSimplificationPass()); // if-convert
579 PM.add(createSCCPPass()); // Propagate exposed constants
580 PM.add(createInstructionCombiningPass()); // Clean up again
581 PM.add(createBitTrackingDCEPass());
582
Yi Jiang79eb0aa2014-05-05 23:14:46 +0000583 // More scalar chains could be vectorized due to more alias information
JF Bastienf42a6ea2014-10-21 23:18:21 +0000584 if (RunSLPAfterLoopVectorization)
585 if (SLPVectorize)
586 PM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.
Yi Jiang79eb0aa2014-05-05 23:14:46 +0000587
Hal Finkeld67e4632014-09-07 20:05:11 +0000588 // After vectorization, assume intrinsics may tell us more about pointer
589 // alignments.
590 PM.add(createAlignmentFromAssumptionsPass());
591
Michael J. Spencer289067c2014-05-29 01:55:07 +0000592 if (LoadCombine)
593 PM.add(createLoadCombinePass());
594
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000595 // Cleanup and simplify the code after the scalar optimizations.
596 PM.add(createInstructionCombiningPass());
Peter Collingbourne0a437612014-05-25 10:27:02 +0000597 addExtensionsToPM(EP_Peephole, PM);
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000598
599 PM.add(createJumpThreadingPass());
Peter Collingbourne070843d2015-03-19 22:01:00 +0000600}
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000601
Peter Collingbourne070843d2015-03-19 22:01:00 +0000602void PassManagerBuilder::addLateLTOOptimizationPasses(
603 legacy::PassManagerBase &PM) {
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000604 // Delete basic blocks, which optimization passes may have killed.
Tom Stellardaa664d92013-08-06 02:43:45 +0000605 PM.add(createCFGSimplificationPass());
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000606
Teresa Johnsonc4279a72015-08-11 16:26:41 +0000607 // Drop bodies of available externally objects to improve GlobalDCE.
608 PM.add(createEliminateAvailableExternallyPass());
609
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000610 // Now that we have optimized the program, discard unreachable functions.
611 PM.add(createGlobalDCEPass());
Nick Lewycky9e6d1842014-09-13 21:46:00 +0000612
613 // FIXME: this is profitable (for compiler time) to do at -O0 too, but
614 // currently it damages debug info.
615 if (MergeFunctions)
616 PM.add(createMergeFunctionsPass());
Rafael Espindola3ea478b2011-08-02 21:50:27 +0000617}
Rafael Espindola07f609152011-08-09 22:17:34 +0000618
Chandler Carruth30d69c22015-02-13 10:01:29 +0000619void PassManagerBuilder::populateLTOPassManager(legacy::PassManagerBase &PM) {
Rafael Espindola7cebf362014-08-21 20:03:44 +0000620 if (LibraryInfo)
Chandler Carruthb98f63d2015-01-15 10:41:28 +0000621 PM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
Rafael Espindola7cebf362014-08-21 20:03:44 +0000622
Duncan P. N. Exon Smithab58a562015-03-19 22:24:17 +0000623 if (VerifyInput)
Rafael Espindola7cebf362014-08-21 20:03:44 +0000624 PM.add(createVerifierPass());
Rafael Espindola7cebf362014-08-21 20:03:44 +0000625
Peter Collingbourne070843d2015-03-19 22:01:00 +0000626 if (OptLevel > 1)
Rafael Espindola7cebf362014-08-21 20:03:44 +0000627 addLTOOptimizationPasses(PM);
628
Evgeniy Stepanov67849d52015-12-15 23:00:08 +0000629 // Create a function that performs CFI checks for cross-DSO calls with targets
630 // in the current module.
631 PM.add(createCrossDSOCFIPass());
632
Peter Collingbourne070843d2015-03-19 22:01:00 +0000633 // Lower bit sets to globals. This pass supports Clang's control flow
634 // integrity mechanisms (-fsanitize=cfi*) and needs to run at link time if CFI
635 // is enabled. The pass does nothing if CFI is disabled.
636 PM.add(createLowerBitSetsPass());
637
638 if (OptLevel != 0)
639 addLateLTOOptimizationPasses(PM);
640
Duncan P. N. Exon Smithab58a562015-03-19 22:24:17 +0000641 if (VerifyOutput)
Rafael Espindola7cebf362014-08-21 20:03:44 +0000642 PM.add(createVerifierPass());
Rafael Espindola7cebf362014-08-21 20:03:44 +0000643}
644
Eric Christopher04d4e932013-04-22 22:47:22 +0000645inline PassManagerBuilder *unwrap(LLVMPassManagerBuilderRef P) {
646 return reinterpret_cast<PassManagerBuilder*>(P);
647}
648
649inline LLVMPassManagerBuilderRef wrap(PassManagerBuilder *P) {
650 return reinterpret_cast<LLVMPassManagerBuilderRef>(P);
651}
652
Dmitri Gribenko0011bbf2012-11-15 16:51:49 +0000653LLVMPassManagerBuilderRef LLVMPassManagerBuilderCreate() {
Rafael Espindola07f609152011-08-09 22:17:34 +0000654 PassManagerBuilder *PMB = new PassManagerBuilder();
655 return wrap(PMB);
656}
657
658void LLVMPassManagerBuilderDispose(LLVMPassManagerBuilderRef PMB) {
659 PassManagerBuilder *Builder = unwrap(PMB);
660 delete Builder;
661}
662
663void
664LLVMPassManagerBuilderSetOptLevel(LLVMPassManagerBuilderRef PMB,
665 unsigned OptLevel) {
666 PassManagerBuilder *Builder = unwrap(PMB);
667 Builder->OptLevel = OptLevel;
668}
669
670void
671LLVMPassManagerBuilderSetSizeLevel(LLVMPassManagerBuilderRef PMB,
672 unsigned SizeLevel) {
673 PassManagerBuilder *Builder = unwrap(PMB);
674 Builder->SizeLevel = SizeLevel;
675}
676
677void
678LLVMPassManagerBuilderSetDisableUnitAtATime(LLVMPassManagerBuilderRef PMB,
679 LLVMBool Value) {
680 PassManagerBuilder *Builder = unwrap(PMB);
681 Builder->DisableUnitAtATime = Value;
682}
683
684void
685LLVMPassManagerBuilderSetDisableUnrollLoops(LLVMPassManagerBuilderRef PMB,
686 LLVMBool Value) {
687 PassManagerBuilder *Builder = unwrap(PMB);
688 Builder->DisableUnrollLoops = Value;
689}
690
691void
692LLVMPassManagerBuilderSetDisableSimplifyLibCalls(LLVMPassManagerBuilderRef PMB,
693 LLVMBool Value) {
Meador Ingedfb08a22013-06-20 19:48:07 +0000694 // NOTE: The simplify-libcalls pass has been removed.
Rafael Espindola07f609152011-08-09 22:17:34 +0000695}
696
697void
698LLVMPassManagerBuilderUseInlinerWithThreshold(LLVMPassManagerBuilderRef PMB,
699 unsigned Threshold) {
700 PassManagerBuilder *Builder = unwrap(PMB);
701 Builder->Inliner = createFunctionInliningPass(Threshold);
702}
703
704void
705LLVMPassManagerBuilderPopulateFunctionPassManager(LLVMPassManagerBuilderRef PMB,
706 LLVMPassManagerRef PM) {
707 PassManagerBuilder *Builder = unwrap(PMB);
Chandler Carruth30d69c22015-02-13 10:01:29 +0000708 legacy::FunctionPassManager *FPM = unwrap<legacy::FunctionPassManager>(PM);
Rafael Espindola07f609152011-08-09 22:17:34 +0000709 Builder->populateFunctionPassManager(*FPM);
710}
711
712void
713LLVMPassManagerBuilderPopulateModulePassManager(LLVMPassManagerBuilderRef PMB,
714 LLVMPassManagerRef PM) {
715 PassManagerBuilder *Builder = unwrap(PMB);
Chandler Carruth30d69c22015-02-13 10:01:29 +0000716 legacy::PassManagerBase *MPM = unwrap(PM);
Rafael Espindola07f609152011-08-09 22:17:34 +0000717 Builder->populateModulePassManager(*MPM);
718}
719
720void LLVMPassManagerBuilderPopulateLTOPassManager(LLVMPassManagerBuilderRef PMB,
721 LLVMPassManagerRef PM,
Nick Lewycky5f508542013-03-10 21:58:22 +0000722 LLVMBool Internalize,
723 LLVMBool RunInliner) {
Rafael Espindola07f609152011-08-09 22:17:34 +0000724 PassManagerBuilder *Builder = unwrap(PMB);
Chandler Carruth30d69c22015-02-13 10:01:29 +0000725 legacy::PassManagerBase *LPM = unwrap(PM);
Rafael Espindolae07caad2014-08-21 13:35:30 +0000726
727 // A small backwards compatibility hack. populateLTOPassManager used to take
728 // an RunInliner option.
729 if (RunInliner && !Builder->Inliner)
730 Builder->Inliner = createFunctionInliningPass();
731
732 Builder->populateLTOPassManager(*LPM);
Rafael Espindola07f609152011-08-09 22:17:34 +0000733}