blob: 38e1b8e166677be5d1d3b0c78b92732ad8feff87 [file] [log] [blame]
Rafael Espindolac684e832011-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
15
16#include "llvm/Transforms/IPO/PassManagerBuilder.h"
Rafael Espindola69cb2162011-08-09 22:17:34 +000017#include "llvm-c/Transforms/PassManagerBuilder.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000018#include "llvm/ADT/SmallVector.h"
Rafael Espindolac684e832011-08-02 21:50:27 +000019#include "llvm/Analysis/Passes.h"
Stephen Hines36b56882014-04-23 16:57:46 -070020#include "llvm/IR/Verifier.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000021#include "llvm/PassManager.h"
Hal Finkelde5e5ec2012-02-01 03:51:43 +000022#include "llvm/Support/CommandLine.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000023#include "llvm/Support/ManagedStatic.h"
Rafael Espindolac684e832011-08-02 21:50:27 +000024#include "llvm/Target/TargetLibraryInfo.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000025#include "llvm/Transforms/IPO.h"
Rafael Espindolac684e832011-08-02 21:50:27 +000026#include "llvm/Transforms/Scalar.h"
Hal Finkelde5e5ec2012-02-01 03:51:43 +000027#include "llvm/Transforms/Vectorize.h"
Rafael Espindolac684e832011-08-02 21:50:27 +000028
29using namespace llvm;
30
Hal Finkelde5e5ec2012-02-01 03:51:43 +000031static cl::opt<bool>
Nadav Rotemfe168482013-10-18 23:38:13 +000032RunLoopVectorization("vectorize-loops", cl::Hidden,
Nadav Rotem9210cc32012-10-30 18:37:43 +000033 cl::desc("Run the Loop vectorization passes"));
Nadav Rotemd233b782012-10-29 16:36:25 +000034
35static cl::opt<bool>
Nadav Rotemfe168482013-10-18 23:38:13 +000036RunSLPVectorization("vectorize-slp", cl::Hidden,
Nadav Rotem1129a832013-04-15 05:39:58 +000037 cl::desc("Run the SLP vectorization passes"));
38
39static cl::opt<bool>
Nadav Rotemfe168482013-10-18 23:38:13 +000040RunBBVectorization("vectorize-slp-aggressive", cl::Hidden,
Nadav Rotem1129a832013-04-15 05:39:58 +000041 cl::desc("Run the BB vectorization passes"));
Hal Finkelde5e5ec2012-02-01 03:51:43 +000042
Hal Finkel064551e2012-04-13 17:15:33 +000043static cl::opt<bool>
44UseGVNAfterVectorization("use-gvn-after-vectorization",
45 cl::init(false), cl::Hidden,
46 cl::desc("Run GVN instead of Early CSE after vectorization passes"));
47
Chandler Carruth713aa942012-09-14 09:22:59 +000048static cl::opt<bool> UseNewSROA("use-new-sroa",
Chandler Carruth1fe4fae2012-10-02 04:24:01 +000049 cl::init(true), cl::Hidden,
Chandler Carruth713aa942012-09-14 09:22:59 +000050 cl::desc("Enable the new, experimental SROA pass"));
51
Hal Finkelbebe48d2013-11-16 23:59:05 +000052static cl::opt<bool>
53RunLoopRerolling("reroll-loops", cl::Hidden,
54 cl::desc("Run the loop rerolling pass"));
55
Rafael Espindolac684e832011-08-02 21:50:27 +000056PassManagerBuilder::PassManagerBuilder() {
57 OptLevel = 2;
58 SizeLevel = 0;
Stephen Hinesdce4a402014-05-29 02:49:00 -070059 LibraryInfo = nullptr;
60 Inliner = nullptr;
61 DisableTailCalls = false;
Rafael Espindolac684e832011-08-02 21:50:27 +000062 DisableUnitAtATime = false;
63 DisableUnrollLoops = false;
Nadav Rotem1129a832013-04-15 05:39:58 +000064 BBVectorize = RunBBVectorization;
Nadav Rotem88498382013-04-15 04:54:42 +000065 SLPVectorize = RunSLPVectorization;
Nadav Rotemd233b782012-10-29 16:36:25 +000066 LoopVectorize = RunLoopVectorization;
Hal Finkelc8dc96b2013-11-17 16:02:50 +000067 RerollLoops = RunLoopRerolling;
Rafael Espindolac684e832011-08-02 21:50:27 +000068}
69
70PassManagerBuilder::~PassManagerBuilder() {
71 delete LibraryInfo;
72 delete Inliner;
73}
74
David Chisnall7a817ea2011-08-16 13:58:41 +000075/// Set of global extensions, automatically added as part of the standard set.
76static ManagedStatic<SmallVector<std::pair<PassManagerBuilder::ExtensionPointTy,
77 PassManagerBuilder::ExtensionFn>, 8> > GlobalExtensions;
78
79void PassManagerBuilder::addGlobalExtension(
80 PassManagerBuilder::ExtensionPointTy Ty,
81 PassManagerBuilder::ExtensionFn Fn) {
82 GlobalExtensions->push_back(std::make_pair(Ty, Fn));
83}
84
Rafael Espindolac684e832011-08-02 21:50:27 +000085void PassManagerBuilder::addExtension(ExtensionPointTy Ty, ExtensionFn Fn) {
86 Extensions.push_back(std::make_pair(Ty, Fn));
87}
88
89void PassManagerBuilder::addExtensionsToPM(ExtensionPointTy ETy,
90 PassManagerBase &PM) const {
David Chisnall7a817ea2011-08-16 13:58:41 +000091 for (unsigned i = 0, e = GlobalExtensions->size(); i != e; ++i)
92 if ((*GlobalExtensions)[i].first == ETy)
93 (*GlobalExtensions)[i].second(*this, PM);
Rafael Espindolac684e832011-08-02 21:50:27 +000094 for (unsigned i = 0, e = Extensions.size(); i != e; ++i)
95 if (Extensions[i].first == ETy)
96 Extensions[i].second(*this, PM);
97}
98
99void
100PassManagerBuilder::addInitialAliasAnalysisPasses(PassManagerBase &PM) const {
101 // Add TypeBasedAliasAnalysis before BasicAliasAnalysis so that
102 // BasicAliasAnalysis wins if they disagree. This is intended to help
103 // support "obvious" type-punning idioms.
104 PM.add(createTypeBasedAliasAnalysisPass());
105 PM.add(createBasicAliasAnalysisPass());
106}
107
108void PassManagerBuilder::populateFunctionPassManager(FunctionPassManager &FPM) {
109 addExtensionsToPM(EP_EarlyAsPossible, FPM);
110
111 // Add LibraryInfo if we have some.
112 if (LibraryInfo) FPM.add(new TargetLibraryInfo(*LibraryInfo));
113
114 if (OptLevel == 0) return;
115
116 addInitialAliasAnalysisPasses(FPM);
117
118 FPM.add(createCFGSimplificationPass());
Chandler Carruth713aa942012-09-14 09:22:59 +0000119 if (UseNewSROA)
120 FPM.add(createSROAPass());
121 else
122 FPM.add(createScalarReplAggregatesPass());
Rafael Espindolac684e832011-08-02 21:50:27 +0000123 FPM.add(createEarlyCSEPass());
124 FPM.add(createLowerExpectIntrinsicPass());
125}
126
127void PassManagerBuilder::populateModulePassManager(PassManagerBase &MPM) {
128 // If all optimizations are disabled, just run the always-inline pass.
129 if (OptLevel == 0) {
130 if (Inliner) {
131 MPM.add(Inliner);
Stephen Hinesdce4a402014-05-29 02:49:00 -0700132 Inliner = nullptr;
Rafael Espindolac684e832011-08-02 21:50:27 +0000133 }
Chandler Carruth63a1eb62012-10-18 08:05:46 +0000134
135 // FIXME: This is a HACK! The inliner pass above implicitly creates a CGSCC
136 // pass manager, but we don't want to add extensions into that pass manager.
137 // To prevent this we must insert a no-op module pass to reset the pass
138 // manager to get the same behavior as EP_OptimizerLast in non-O0 builds.
139 if (!GlobalExtensions->empty() || !Extensions.empty())
140 MPM.add(createBarrierNoopPass());
141
Kostya Serebryanyaf65a8c2011-11-30 22:19:26 +0000142 addExtensionsToPM(EP_EnabledOnOptLevel0, MPM);
Rafael Espindolac684e832011-08-02 21:50:27 +0000143 return;
144 }
145
146 // Add LibraryInfo if we have some.
147 if (LibraryInfo) MPM.add(new TargetLibraryInfo(*LibraryInfo));
148
149 addInitialAliasAnalysisPasses(MPM);
150
151 if (!DisableUnitAtATime) {
Dan Gohman7d4c87e2012-01-17 20:51:32 +0000152 addExtensionsToPM(EP_ModuleOptimizerEarly, MPM);
153
Rafael Espindolac684e832011-08-02 21:50:27 +0000154 MPM.add(createGlobalOptimizerPass()); // Optimize out global vars
155
156 MPM.add(createIPSCCPPass()); // IP SCCP
157 MPM.add(createDeadArgEliminationPass()); // Dead argument elimination
158
159 MPM.add(createInstructionCombiningPass());// Clean up after IPCP & DAE
Stephen Hinesdce4a402014-05-29 02:49:00 -0700160 addExtensionsToPM(EP_Peephole, MPM);
Rafael Espindolac684e832011-08-02 21:50:27 +0000161 MPM.add(createCFGSimplificationPass()); // Clean up after IPCP & DAE
162 }
163
164 // Start of CallGraph SCC passes.
165 if (!DisableUnitAtATime)
166 MPM.add(createPruneEHPass()); // Remove dead EH info
167 if (Inliner) {
168 MPM.add(Inliner);
Stephen Hinesdce4a402014-05-29 02:49:00 -0700169 Inliner = nullptr;
Rafael Espindolac684e832011-08-02 21:50:27 +0000170 }
171 if (!DisableUnitAtATime)
172 MPM.add(createFunctionAttrsPass()); // Set readonly/readnone attrs
173 if (OptLevel > 2)
174 MPM.add(createArgumentPromotionPass()); // Scalarize uninlined fn args
175
176 // Start of function pass.
177 // Break up aggregate allocas, using SSAUpdater.
Chandler Carruth1c8db502012-09-15 11:43:14 +0000178 if (UseNewSROA)
179 MPM.add(createSROAPass(/*RequiresDomTree*/ false));
180 else
181 MPM.add(createScalarReplAggregatesPass(-1, false));
Rafael Espindolac684e832011-08-02 21:50:27 +0000182 MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
Rafael Espindolac684e832011-08-02 21:50:27 +0000183 MPM.add(createJumpThreadingPass()); // Thread jumps.
184 MPM.add(createCorrelatedValuePropagationPass()); // Propagate conditionals
185 MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
186 MPM.add(createInstructionCombiningPass()); // Combine silly seq's
Stephen Hinesdce4a402014-05-29 02:49:00 -0700187 addExtensionsToPM(EP_Peephole, MPM);
Rafael Espindolac684e832011-08-02 21:50:27 +0000188
Stephen Hinesdce4a402014-05-29 02:49:00 -0700189 if (!DisableTailCalls)
190 MPM.add(createTailCallEliminationPass()); // Eliminate tail calls
Rafael Espindolac684e832011-08-02 21:50:27 +0000191 MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
192 MPM.add(createReassociatePass()); // Reassociate expressions
193 MPM.add(createLoopRotatePass()); // Rotate Loop
194 MPM.add(createLICMPass()); // Hoist loop invariants
195 MPM.add(createLoopUnswitchPass(SizeLevel || OptLevel < 3));
196 MPM.add(createInstructionCombiningPass());
197 MPM.add(createIndVarSimplifyPass()); // Canonicalize indvars
198 MPM.add(createLoopIdiomPass()); // Recognize idioms like memset.
199 MPM.add(createLoopDeletionPass()); // Delete dead loops
Nadav Rotemd15c0c72012-10-17 18:25:06 +0000200
Rafael Espindolac684e832011-08-02 21:50:27 +0000201 if (!DisableUnrollLoops)
Stephen Hines36b56882014-04-23 16:57:46 -0700202 MPM.add(createSimpleLoopUnrollPass()); // Unroll small loops
Rafael Espindolac684e832011-08-02 21:50:27 +0000203 addExtensionsToPM(EP_LoopOptimizerEnd, MPM);
204
205 if (OptLevel > 1)
206 MPM.add(createGVNPass()); // Remove redundancies
207 MPM.add(createMemCpyOptPass()); // Remove memcpy / form memset
208 MPM.add(createSCCPPass()); // Constant prop with SCCP
209
210 // Run instcombine after redundancy elimination to exploit opportunities
211 // opened up by them.
212 MPM.add(createInstructionCombiningPass());
Stephen Hinesdce4a402014-05-29 02:49:00 -0700213 addExtensionsToPM(EP_Peephole, MPM);
Rafael Espindolac684e832011-08-02 21:50:27 +0000214 MPM.add(createJumpThreadingPass()); // Thread jumps
215 MPM.add(createCorrelatedValuePropagationPass());
216 MPM.add(createDeadStoreEliminationPass()); // Delete dead stores
217
218 addExtensionsToPM(EP_ScalarOptimizerLate, MPM);
219
Hal Finkelc8dc96b2013-11-17 16:02:50 +0000220 if (RerollLoops)
Hal Finkelbebe48d2013-11-16 23:59:05 +0000221 MPM.add(createLoopRerollPass());
Nadav Rotemf1cd7982013-08-28 23:40:29 +0000222 if (SLPVectorize)
223 MPM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.
Nadav Rotem1129a832013-04-15 05:39:58 +0000224
Nadav Rotemf1cd7982013-08-28 23:40:29 +0000225 if (BBVectorize) {
226 MPM.add(createBBVectorizePass());
227 MPM.add(createInstructionCombiningPass());
Stephen Hinesdce4a402014-05-29 02:49:00 -0700228 addExtensionsToPM(EP_Peephole, MPM);
Nadav Rotemf1cd7982013-08-28 23:40:29 +0000229 if (OptLevel > 1 && UseGVNAfterVectorization)
230 MPM.add(createGVNPass()); // Remove redundancies
231 else
232 MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
Hal Finkelc0b3d4c2013-01-29 00:22:49 +0000233
Nadav Rotemf1cd7982013-08-28 23:40:29 +0000234 // BBVectorize may have significantly shortened a loop body; unroll again.
235 if (!DisableUnrollLoops)
236 MPM.add(createLoopUnrollPass());
Hal Finkelde5e5ec2012-02-01 03:51:43 +0000237 }
238
Rafael Espindolac684e832011-08-02 21:50:27 +0000239 MPM.add(createAggressiveDCEPass()); // Delete dead instructions
Tom Stellard01d72032013-08-06 02:43:45 +0000240 MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
Rafael Espindolac684e832011-08-02 21:50:27 +0000241 MPM.add(createInstructionCombiningPass()); // Clean up after everything.
Stephen Hinesdce4a402014-05-29 02:49:00 -0700242 addExtensionsToPM(EP_Peephole, MPM);
Rafael Espindolac684e832011-08-02 21:50:27 +0000243
Stephen Hines36b56882014-04-23 16:57:46 -0700244 // FIXME: This is a HACK! The inliner pass above implicitly creates a CGSCC
245 // pass manager that we are specifically trying to avoid. To prevent this
246 // we must insert a no-op module pass to reset the pass manager.
247 MPM.add(createBarrierNoopPass());
248 MPM.add(createLoopVectorizePass(DisableUnrollLoops, LoopVectorize));
249 // FIXME: Because of #pragma vectorize enable, the passes below are always
250 // inserted in the pipeline, even when the vectorizer doesn't run (ex. when
251 // on -O1 and no #pragma is found). Would be good to have these two passes
252 // as function calls, so that we can only pass them when the vectorizer
253 // changed the code.
254 MPM.add(createInstructionCombiningPass());
Stephen Hinesdce4a402014-05-29 02:49:00 -0700255 addExtensionsToPM(EP_Peephole, MPM);
Stephen Hines36b56882014-04-23 16:57:46 -0700256 MPM.add(createCFGSimplificationPass());
Chandler Carruth6bf3a052013-06-24 07:21:47 +0000257
Stephen Hines36b56882014-04-23 16:57:46 -0700258 if (!DisableUnrollLoops)
259 MPM.add(createLoopUnrollPass()); // Unroll small loops
Chandler Carruth6bf3a052013-06-24 07:21:47 +0000260
Rafael Espindolac684e832011-08-02 21:50:27 +0000261 if (!DisableUnitAtATime) {
262 // FIXME: We shouldn't bother with this anymore.
263 MPM.add(createStripDeadPrototypesPass()); // Get rid of dead prototypes
264
Evan Chengf5fdc142012-09-28 21:23:26 +0000265 // GlobalOpt already deletes dead functions and globals, at -O2 try a
Rafael Espindolac684e832011-08-02 21:50:27 +0000266 // late pass of GlobalDCE. It is capable of deleting dead cycles.
Evan Chengf5fdc142012-09-28 21:23:26 +0000267 if (OptLevel > 1) {
Rafael Espindolac684e832011-08-02 21:50:27 +0000268 MPM.add(createGlobalDCEPass()); // Remove dead fns and globals.
Rafael Espindolac684e832011-08-02 21:50:27 +0000269 MPM.add(createConstantMergePass()); // Merge dup global constants
Evan Chengf5fdc142012-09-28 21:23:26 +0000270 }
Rafael Espindolac684e832011-08-02 21:50:27 +0000271 }
Kostya Serebryany1db39492012-03-23 23:22:59 +0000272 addExtensionsToPM(EP_OptimizerLast, MPM);
Rafael Espindolac684e832011-08-02 21:50:27 +0000273}
274
275void PassManagerBuilder::populateLTOPassManager(PassManagerBase &PM,
276 bool Internalize,
Bill Wendling3197b442012-04-02 22:16:50 +0000277 bool RunInliner,
278 bool DisableGVNLoadPRE) {
Rafael Espindolac684e832011-08-02 21:50:27 +0000279 // Provide AliasAnalysis services for optimizations.
280 addInitialAliasAnalysisPasses(PM);
281
282 // Now that composite has been compiled, scan through the module, looking
283 // for a main function. If main is defined, mark all other functions
284 // internal.
Bill Wendling6e4d93b2013-08-30 00:48:37 +0000285 if (Internalize)
Rafael Espindola7e667c52013-10-31 20:51:58 +0000286 PM.add(createInternalizePass("main"));
Rafael Espindolac684e832011-08-02 21:50:27 +0000287
288 // Propagate constants at call sites into the functions they call. This
289 // opens opportunities for globalopt (and inlining) by substituting function
290 // pointers passed as arguments to direct uses of functions.
291 PM.add(createIPSCCPPass());
292
293 // Now that we internalized some globals, see if we can hack on them!
294 PM.add(createGlobalOptimizerPass());
295
296 // Linking modules together can lead to duplicated global constants, only
297 // keep one copy of each constant.
298 PM.add(createConstantMergePass());
299
300 // Remove unused arguments from functions.
301 PM.add(createDeadArgEliminationPass());
302
303 // Reduce the code after globalopt and ipsccp. Both can open up significant
304 // simplification opportunities, and both can propagate functions through
305 // function pointers. When this happens, we often have to resolve varargs
306 // calls, etc, so let instcombine do this.
307 PM.add(createInstructionCombiningPass());
Stephen Hinesdce4a402014-05-29 02:49:00 -0700308 addExtensionsToPM(EP_Peephole, PM);
Rafael Espindolac684e832011-08-02 21:50:27 +0000309
310 // Inline small functions
311 if (RunInliner)
312 PM.add(createFunctionInliningPass());
313
314 PM.add(createPruneEHPass()); // Remove dead EH info.
315
316 // Optimize globals again if we ran the inliner.
317 if (RunInliner)
318 PM.add(createGlobalOptimizerPass());
319 PM.add(createGlobalDCEPass()); // Remove dead functions.
320
321 // If we didn't decide to inline a function, check to see if we can
322 // transform it to pass arguments by value instead of by reference.
323 PM.add(createArgumentPromotionPass());
324
325 // The IPO passes may leave cruft around. Clean up after them.
326 PM.add(createInstructionCombiningPass());
Stephen Hinesdce4a402014-05-29 02:49:00 -0700327 addExtensionsToPM(EP_Peephole, PM);
Rafael Espindolac684e832011-08-02 21:50:27 +0000328 PM.add(createJumpThreadingPass());
Bill Wendling6e4d93b2013-08-30 00:48:37 +0000329
Rafael Espindolac684e832011-08-02 21:50:27 +0000330 // Break up allocas
Chandler Carruth713aa942012-09-14 09:22:59 +0000331 if (UseNewSROA)
332 PM.add(createSROAPass());
333 else
334 PM.add(createScalarReplAggregatesPass());
Rafael Espindolac684e832011-08-02 21:50:27 +0000335
336 // Run a few AA driven optimizations here and now, to cleanup the code.
337 PM.add(createFunctionAttrsPass()); // Add nocapture.
338 PM.add(createGlobalsModRefPass()); // IP alias analysis.
339
Bill Wendling3197b442012-04-02 22:16:50 +0000340 PM.add(createLICMPass()); // Hoist loop invariants.
341 PM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies.
342 PM.add(createMemCpyOptPass()); // Remove dead memcpys.
Bill Wendling6e4d93b2013-08-30 00:48:37 +0000343
Rafael Espindolac684e832011-08-02 21:50:27 +0000344 // Nuke dead stores.
345 PM.add(createDeadStoreEliminationPass());
346
Stephen Hinesdce4a402014-05-29 02:49:00 -0700347 // More loops are countable; try to optimize them.
348 PM.add(createIndVarSimplifyPass());
349 PM.add(createLoopDeletionPass());
Stephen Hines36b56882014-04-23 16:57:46 -0700350 PM.add(createLoopVectorizePass(true, true));
351
Stephen Hinesdce4a402014-05-29 02:49:00 -0700352 // More scalar chains could be vectorized due to more alias information
353 PM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.
354
Rafael Espindolac684e832011-08-02 21:50:27 +0000355 // Cleanup and simplify the code after the scalar optimizations.
356 PM.add(createInstructionCombiningPass());
Stephen Hinesdce4a402014-05-29 02:49:00 -0700357 addExtensionsToPM(EP_Peephole, PM);
Rafael Espindolac684e832011-08-02 21:50:27 +0000358
359 PM.add(createJumpThreadingPass());
360
361 // Delete basic blocks, which optimization passes may have killed.
Tom Stellard01d72032013-08-06 02:43:45 +0000362 PM.add(createCFGSimplificationPass());
Rafael Espindolac684e832011-08-02 21:50:27 +0000363
364 // Now that we have optimized the program, discard unreachable functions.
365 PM.add(createGlobalDCEPass());
366}
Rafael Espindola69cb2162011-08-09 22:17:34 +0000367
Eric Christopher3e397312013-04-22 22:47:22 +0000368inline PassManagerBuilder *unwrap(LLVMPassManagerBuilderRef P) {
369 return reinterpret_cast<PassManagerBuilder*>(P);
370}
371
372inline LLVMPassManagerBuilderRef wrap(PassManagerBuilder *P) {
373 return reinterpret_cast<LLVMPassManagerBuilderRef>(P);
374}
375
Dmitri Gribenko79c07d22012-11-15 16:51:49 +0000376LLVMPassManagerBuilderRef LLVMPassManagerBuilderCreate() {
Rafael Espindola69cb2162011-08-09 22:17:34 +0000377 PassManagerBuilder *PMB = new PassManagerBuilder();
378 return wrap(PMB);
379}
380
381void LLVMPassManagerBuilderDispose(LLVMPassManagerBuilderRef PMB) {
382 PassManagerBuilder *Builder = unwrap(PMB);
383 delete Builder;
384}
385
386void
387LLVMPassManagerBuilderSetOptLevel(LLVMPassManagerBuilderRef PMB,
388 unsigned OptLevel) {
389 PassManagerBuilder *Builder = unwrap(PMB);
390 Builder->OptLevel = OptLevel;
391}
392
393void
394LLVMPassManagerBuilderSetSizeLevel(LLVMPassManagerBuilderRef PMB,
395 unsigned SizeLevel) {
396 PassManagerBuilder *Builder = unwrap(PMB);
397 Builder->SizeLevel = SizeLevel;
398}
399
400void
401LLVMPassManagerBuilderSetDisableUnitAtATime(LLVMPassManagerBuilderRef PMB,
402 LLVMBool Value) {
403 PassManagerBuilder *Builder = unwrap(PMB);
404 Builder->DisableUnitAtATime = Value;
405}
406
407void
408LLVMPassManagerBuilderSetDisableUnrollLoops(LLVMPassManagerBuilderRef PMB,
409 LLVMBool Value) {
410 PassManagerBuilder *Builder = unwrap(PMB);
411 Builder->DisableUnrollLoops = Value;
412}
413
414void
415LLVMPassManagerBuilderSetDisableSimplifyLibCalls(LLVMPassManagerBuilderRef PMB,
416 LLVMBool Value) {
Meador Ingebe87bce2013-06-20 19:48:07 +0000417 // NOTE: The simplify-libcalls pass has been removed.
Rafael Espindola69cb2162011-08-09 22:17:34 +0000418}
419
420void
421LLVMPassManagerBuilderUseInlinerWithThreshold(LLVMPassManagerBuilderRef PMB,
422 unsigned Threshold) {
423 PassManagerBuilder *Builder = unwrap(PMB);
424 Builder->Inliner = createFunctionInliningPass(Threshold);
425}
426
427void
428LLVMPassManagerBuilderPopulateFunctionPassManager(LLVMPassManagerBuilderRef PMB,
429 LLVMPassManagerRef PM) {
430 PassManagerBuilder *Builder = unwrap(PMB);
431 FunctionPassManager *FPM = unwrap<FunctionPassManager>(PM);
432 Builder->populateFunctionPassManager(*FPM);
433}
434
435void
436LLVMPassManagerBuilderPopulateModulePassManager(LLVMPassManagerBuilderRef PMB,
437 LLVMPassManagerRef PM) {
438 PassManagerBuilder *Builder = unwrap(PMB);
439 PassManagerBase *MPM = unwrap(PM);
440 Builder->populateModulePassManager(*MPM);
441}
442
443void LLVMPassManagerBuilderPopulateLTOPassManager(LLVMPassManagerBuilderRef PMB,
444 LLVMPassManagerRef PM,
Nick Lewycky0ebc0842013-03-10 21:58:22 +0000445 LLVMBool Internalize,
446 LLVMBool RunInliner) {
Rafael Espindola69cb2162011-08-09 22:17:34 +0000447 PassManagerBuilder *Builder = unwrap(PMB);
448 PassManagerBase *LPM = unwrap(PM);
Nick Lewycky0ebc0842013-03-10 21:58:22 +0000449 Builder->populateLTOPassManager(*LPM, Internalize != 0, RunInliner != 0);
Rafael Espindola69cb2162011-08-09 22:17:34 +0000450}