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
15
16 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
17 #include "llvm-c/Transforms/PassManagerBuilder.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/Analysis/Passes.h"
20 #include "llvm/IR/DataLayout.h"
21 #include "llvm/IR/Verifier.h"
22 #include "llvm/PassManager.h"
23 #include "llvm/Support/CommandLine.h"
24 #include "llvm/Support/ManagedStatic.h"
25 #include "llvm/Target/TargetLibraryInfo.h"
26 #include "llvm/Target/TargetMachine.h"
27 #include "llvm/Target/TargetSubtargetInfo.h"
28 #include "llvm/Transforms/IPO.h"
29 #include "llvm/Transforms/Scalar.h"
30 #include "llvm/Transforms/Vectorize.h"
31
32 using namespace llvm;
33
34 static cl::opt<bool>
35 RunLoopVectorization("vectorize-loops", cl::Hidden,
36 cl::desc("Run the Loop vectorization passes"));
37
38 static cl::opt<bool>
39 RunSLPVectorization("vectorize-slp", cl::Hidden,
40 cl::desc("Run the SLP vectorization passes"));
41
42 static cl::opt<bool>
43 RunBBVectorization("vectorize-slp-aggressive", cl::Hidden,
44 cl::desc("Run the BB vectorization passes"));
45
46 static cl::opt<bool>
47 UseGVNAfterVectorization("use-gvn-after-vectorization",
48 cl::init(false), cl::Hidden,
49 cl::desc("Run GVN instead of Early CSE after vectorization passes"));
50
51 static cl::opt<bool> ExtraVectorizerPasses(
52 "extra-vectorizer-passes", cl::init(false), cl::Hidden,
53 cl::desc("Run cleanup optimization passes after vectorization."));
54
55 static cl::opt<bool> UseNewSROA("use-new-sroa",
56 cl::init(true), cl::Hidden,
57 cl::desc("Enable the new, experimental SROA pass"));
58
59 static cl::opt<bool>
60 RunLoopRerolling("reroll-loops", cl::Hidden,
61 cl::desc("Run the loop rerolling pass"));
62
63 static cl::opt<bool> RunLoadCombine("combine-loads", cl::init(false),
64 cl::Hidden,
65 cl::desc("Run the load combining pass"));
66
67 static cl::opt<bool>
68 RunSLPAfterLoopVectorization("run-slp-after-loop-vectorization",
69 cl::init(true), cl::Hidden,
70 cl::desc("Run the SLP vectorizer (and BB vectorizer) after the Loop "
71 "vectorizer instead of before"));
72
73 static cl::opt<bool> UseCFLAA("use-cfl-aa",
74 cl::init(false), cl::Hidden,
75 cl::desc("Enable the new, experimental CFL alias analysis"));
76
77 static cl::opt<bool>
78 EnableMLSM("mlsm", cl::init(true), cl::Hidden,
79 cl::desc("Enable motion of merged load and store"));
80
PassManagerBuilder()81 PassManagerBuilder::PassManagerBuilder() {
82 OptLevel = 2;
83 SizeLevel = 0;
84 LibraryInfo = nullptr;
85 Inliner = nullptr;
86 DisableTailCalls = false;
87 DisableUnitAtATime = false;
88 DisableUnrollLoops = false;
89 BBVectorize = RunBBVectorization;
90 SLPVectorize = RunSLPVectorization;
91 LoopVectorize = RunLoopVectorization;
92 RerollLoops = RunLoopRerolling;
93 LoadCombine = RunLoadCombine;
94 DisableGVNLoadPRE = false;
95 VerifyInput = false;
96 VerifyOutput = false;
97 StripDebug = false;
98 MergeFunctions = false;
99 }
100
~PassManagerBuilder()101 PassManagerBuilder::~PassManagerBuilder() {
102 delete LibraryInfo;
103 delete Inliner;
104 }
105
106 /// Set of global extensions, automatically added as part of the standard set.
107 static ManagedStatic<SmallVector<std::pair<PassManagerBuilder::ExtensionPointTy,
108 PassManagerBuilder::ExtensionFn>, 8> > GlobalExtensions;
109
addGlobalExtension(PassManagerBuilder::ExtensionPointTy Ty,PassManagerBuilder::ExtensionFn Fn)110 void PassManagerBuilder::addGlobalExtension(
111 PassManagerBuilder::ExtensionPointTy Ty,
112 PassManagerBuilder::ExtensionFn Fn) {
113 GlobalExtensions->push_back(std::make_pair(Ty, Fn));
114 }
115
addExtension(ExtensionPointTy Ty,ExtensionFn Fn)116 void PassManagerBuilder::addExtension(ExtensionPointTy Ty, ExtensionFn Fn) {
117 Extensions.push_back(std::make_pair(Ty, Fn));
118 }
119
addExtensionsToPM(ExtensionPointTy ETy,PassManagerBase & PM) const120 void PassManagerBuilder::addExtensionsToPM(ExtensionPointTy ETy,
121 PassManagerBase &PM) const {
122 for (unsigned i = 0, e = GlobalExtensions->size(); i != e; ++i)
123 if ((*GlobalExtensions)[i].first == ETy)
124 (*GlobalExtensions)[i].second(*this, PM);
125 for (unsigned i = 0, e = Extensions.size(); i != e; ++i)
126 if (Extensions[i].first == ETy)
127 Extensions[i].second(*this, PM);
128 }
129
130 void
addInitialAliasAnalysisPasses(PassManagerBase & PM) const131 PassManagerBuilder::addInitialAliasAnalysisPasses(PassManagerBase &PM) const {
132 // Add TypeBasedAliasAnalysis before BasicAliasAnalysis so that
133 // BasicAliasAnalysis wins if they disagree. This is intended to help
134 // support "obvious" type-punning idioms.
135 if (UseCFLAA)
136 PM.add(createCFLAliasAnalysisPass());
137 PM.add(createTypeBasedAliasAnalysisPass());
138 PM.add(createScopedNoAliasAAPass());
139 PM.add(createBasicAliasAnalysisPass());
140 }
141
populateFunctionPassManager(FunctionPassManager & FPM)142 void PassManagerBuilder::populateFunctionPassManager(FunctionPassManager &FPM) {
143 addExtensionsToPM(EP_EarlyAsPossible, FPM);
144
145 // Add LibraryInfo if we have some.
146 if (LibraryInfo) FPM.add(new TargetLibraryInfo(*LibraryInfo));
147
148 if (OptLevel == 0) return;
149
150 addInitialAliasAnalysisPasses(FPM);
151
152 FPM.add(createCFGSimplificationPass());
153 if (UseNewSROA)
154 FPM.add(createSROAPass());
155 else
156 FPM.add(createScalarReplAggregatesPass());
157 FPM.add(createEarlyCSEPass());
158 FPM.add(createLowerExpectIntrinsicPass());
159 }
160
populateModulePassManager(PassManagerBase & MPM)161 void PassManagerBuilder::populateModulePassManager(PassManagerBase &MPM) {
162 // If all optimizations are disabled, just run the always-inline pass and,
163 // if enabled, the function merging pass.
164 if (OptLevel == 0) {
165 if (Inliner) {
166 MPM.add(Inliner);
167 Inliner = nullptr;
168 }
169
170 // FIXME: The BarrierNoopPass is a HACK! The inliner pass above implicitly
171 // creates a CGSCC pass manager, but we don't want to add extensions into
172 // that pass manager. To prevent this we insert a no-op module pass to reset
173 // the pass manager to get the same behavior as EP_OptimizerLast in non-O0
174 // builds. The function merging pass is
175 if (MergeFunctions)
176 MPM.add(createMergeFunctionsPass());
177 else if (!GlobalExtensions->empty() || !Extensions.empty())
178 MPM.add(createBarrierNoopPass());
179
180 addExtensionsToPM(EP_EnabledOnOptLevel0, MPM);
181 return;
182 }
183
184 // Add LibraryInfo if we have some.
185 if (LibraryInfo) MPM.add(new TargetLibraryInfo(*LibraryInfo));
186
187 addInitialAliasAnalysisPasses(MPM);
188
189 if (!DisableUnitAtATime) {
190 addExtensionsToPM(EP_ModuleOptimizerEarly, MPM);
191
192 MPM.add(createIPSCCPPass()); // IP SCCP
193 MPM.add(createGlobalOptimizerPass()); // Optimize out global vars
194
195 MPM.add(createDeadArgEliminationPass()); // Dead argument elimination
196
197 MPM.add(createInstructionCombiningPass());// Clean up after IPCP & DAE
198 addExtensionsToPM(EP_Peephole, MPM);
199 MPM.add(createCFGSimplificationPass()); // Clean up after IPCP & DAE
200 }
201
202 // Start of CallGraph SCC passes.
203 if (!DisableUnitAtATime)
204 MPM.add(createPruneEHPass()); // Remove dead EH info
205 if (Inliner) {
206 MPM.add(Inliner);
207 Inliner = nullptr;
208 }
209 if (!DisableUnitAtATime)
210 MPM.add(createFunctionAttrsPass()); // Set readonly/readnone attrs
211 if (OptLevel > 2)
212 MPM.add(createArgumentPromotionPass()); // Scalarize uninlined fn args
213
214 // Start of function pass.
215 // Break up aggregate allocas, using SSAUpdater.
216 if (UseNewSROA)
217 MPM.add(createSROAPass(/*RequiresDomTree*/ false));
218 else
219 MPM.add(createScalarReplAggregatesPass(-1, false));
220 MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
221 MPM.add(createJumpThreadingPass()); // Thread jumps.
222 MPM.add(createCorrelatedValuePropagationPass()); // Propagate conditionals
223 MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
224 MPM.add(createInstructionCombiningPass()); // Combine silly seq's
225 addExtensionsToPM(EP_Peephole, MPM);
226
227 if (!DisableTailCalls)
228 MPM.add(createTailCallEliminationPass()); // Eliminate tail calls
229 MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
230 MPM.add(createReassociatePass()); // Reassociate expressions
231 // Rotate Loop - disable header duplication at -Oz
232 MPM.add(createLoopRotatePass(SizeLevel == 2 ? 0 : -1));
233 MPM.add(createLICMPass()); // Hoist loop invariants
234 MPM.add(createLoopUnswitchPass(SizeLevel || OptLevel < 3));
235 MPM.add(createInstructionCombiningPass());
236 MPM.add(createIndVarSimplifyPass()); // Canonicalize indvars
237 MPM.add(createLoopIdiomPass()); // Recognize idioms like memset.
238 MPM.add(createLoopDeletionPass()); // Delete dead loops
239
240 if (!DisableUnrollLoops)
241 MPM.add(createSimpleLoopUnrollPass()); // Unroll small loops
242 addExtensionsToPM(EP_LoopOptimizerEnd, MPM);
243
244 if (OptLevel > 1) {
245 if (EnableMLSM)
246 MPM.add(createMergedLoadStoreMotionPass()); // Merge ld/st in diamonds
247 MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
248 }
249 MPM.add(createMemCpyOptPass()); // Remove memcpy / form memset
250 MPM.add(createSCCPPass()); // Constant prop with SCCP
251
252 // Run instcombine after redundancy elimination to exploit opportunities
253 // opened up by them.
254 MPM.add(createInstructionCombiningPass());
255 addExtensionsToPM(EP_Peephole, MPM);
256 MPM.add(createJumpThreadingPass()); // Thread jumps
257 MPM.add(createCorrelatedValuePropagationPass());
258 MPM.add(createDeadStoreEliminationPass()); // Delete dead stores
259
260 addExtensionsToPM(EP_ScalarOptimizerLate, MPM);
261
262 if (RerollLoops)
263 MPM.add(createLoopRerollPass());
264 if (!RunSLPAfterLoopVectorization) {
265 if (SLPVectorize)
266 MPM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.
267
268 if (BBVectorize) {
269 MPM.add(createBBVectorizePass());
270 MPM.add(createInstructionCombiningPass());
271 addExtensionsToPM(EP_Peephole, MPM);
272 if (OptLevel > 1 && UseGVNAfterVectorization)
273 MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
274 else
275 MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
276
277 // BBVectorize may have significantly shortened a loop body; unroll again.
278 if (!DisableUnrollLoops)
279 MPM.add(createLoopUnrollPass());
280 }
281 }
282
283 if (LoadCombine)
284 MPM.add(createLoadCombinePass());
285
286 MPM.add(createAggressiveDCEPass()); // Delete dead instructions
287 MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
288 MPM.add(createInstructionCombiningPass()); // Clean up after everything.
289 addExtensionsToPM(EP_Peephole, MPM);
290
291 // FIXME: This is a HACK! The inliner pass above implicitly creates a CGSCC
292 // pass manager that we are specifically trying to avoid. To prevent this
293 // we must insert a no-op module pass to reset the pass manager.
294 MPM.add(createBarrierNoopPass());
295
296 // Re-rotate loops in all our loop nests. These may have fallout out of
297 // rotated form due to GVN or other transformations, and the vectorizer relies
298 // on the rotated form.
299 if (ExtraVectorizerPasses)
300 MPM.add(createLoopRotatePass());
301
302 MPM.add(createLoopVectorizePass(DisableUnrollLoops, LoopVectorize));
303 // FIXME: Because of #pragma vectorize enable, the passes below are always
304 // inserted in the pipeline, even when the vectorizer doesn't run (ex. when
305 // on -O1 and no #pragma is found). Would be good to have these two passes
306 // as function calls, so that we can only pass them when the vectorizer
307 // changed the code.
308 MPM.add(createInstructionCombiningPass());
309 if (OptLevel > 1 && ExtraVectorizerPasses) {
310 // At higher optimization levels, try to clean up any runtime overlap and
311 // alignment checks inserted by the vectorizer. We want to track correllated
312 // runtime checks for two inner loops in the same outer loop, fold any
313 // common computations, hoist loop-invariant aspects out of any outer loop,
314 // and unswitch the runtime checks if possible. Once hoisted, we may have
315 // dead (or speculatable) control flows or more combining opportunities.
316 MPM.add(createEarlyCSEPass());
317 MPM.add(createCorrelatedValuePropagationPass());
318 MPM.add(createInstructionCombiningPass());
319 MPM.add(createLICMPass());
320 MPM.add(createLoopUnswitchPass(SizeLevel || OptLevel < 3));
321 MPM.add(createCFGSimplificationPass());
322 MPM.add(createInstructionCombiningPass());
323 }
324
325 if (RunSLPAfterLoopVectorization) {
326 if (SLPVectorize) {
327 MPM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.
328 if (OptLevel > 1 && ExtraVectorizerPasses) {
329 MPM.add(createEarlyCSEPass());
330 }
331 }
332
333 if (BBVectorize) {
334 MPM.add(createBBVectorizePass());
335 MPM.add(createInstructionCombiningPass());
336 addExtensionsToPM(EP_Peephole, MPM);
337 if (OptLevel > 1 && UseGVNAfterVectorization)
338 MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
339 else
340 MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
341
342 // BBVectorize may have significantly shortened a loop body; unroll again.
343 if (!DisableUnrollLoops)
344 MPM.add(createLoopUnrollPass());
345 }
346 }
347
348 addExtensionsToPM(EP_Peephole, MPM);
349 MPM.add(createCFGSimplificationPass());
350 MPM.add(createInstructionCombiningPass());
351
352 if (!DisableUnrollLoops)
353 MPM.add(createLoopUnrollPass()); // Unroll small loops
354
355 // After vectorization and unrolling, assume intrinsics may tell us more
356 // about pointer alignments.
357 MPM.add(createAlignmentFromAssumptionsPass());
358
359 if (!DisableUnitAtATime) {
360 // FIXME: We shouldn't bother with this anymore.
361 MPM.add(createStripDeadPrototypesPass()); // Get rid of dead prototypes
362
363 // GlobalOpt already deletes dead functions and globals, at -O2 try a
364 // late pass of GlobalDCE. It is capable of deleting dead cycles.
365 if (OptLevel > 1) {
366 MPM.add(createGlobalDCEPass()); // Remove dead fns and globals.
367 MPM.add(createConstantMergePass()); // Merge dup global constants
368 }
369 }
370
371 if (MergeFunctions)
372 MPM.add(createMergeFunctionsPass());
373
374 addExtensionsToPM(EP_OptimizerLast, MPM);
375 }
376
addLTOOptimizationPasses(PassManagerBase & PM)377 void PassManagerBuilder::addLTOOptimizationPasses(PassManagerBase &PM) {
378 // Provide AliasAnalysis services for optimizations.
379 addInitialAliasAnalysisPasses(PM);
380
381 // Propagate constants at call sites into the functions they call. This
382 // opens opportunities for globalopt (and inlining) by substituting function
383 // pointers passed as arguments to direct uses of functions.
384 PM.add(createIPSCCPPass());
385
386 // Now that we internalized some globals, see if we can hack on them!
387 PM.add(createGlobalOptimizerPass());
388
389 // Linking modules together can lead to duplicated global constants, only
390 // keep one copy of each constant.
391 PM.add(createConstantMergePass());
392
393 // Remove unused arguments from functions.
394 PM.add(createDeadArgEliminationPass());
395
396 // Reduce the code after globalopt and ipsccp. Both can open up significant
397 // simplification opportunities, and both can propagate functions through
398 // function pointers. When this happens, we often have to resolve varargs
399 // calls, etc, so let instcombine do this.
400 PM.add(createInstructionCombiningPass());
401 addExtensionsToPM(EP_Peephole, PM);
402
403 // Inline small functions
404 bool RunInliner = Inliner;
405 if (RunInliner) {
406 PM.add(Inliner);
407 Inliner = nullptr;
408 }
409
410 PM.add(createPruneEHPass()); // Remove dead EH info.
411
412 // Optimize globals again if we ran the inliner.
413 if (RunInliner)
414 PM.add(createGlobalOptimizerPass());
415 PM.add(createGlobalDCEPass()); // Remove dead functions.
416
417 // If we didn't decide to inline a function, check to see if we can
418 // transform it to pass arguments by value instead of by reference.
419 PM.add(createArgumentPromotionPass());
420
421 // The IPO passes may leave cruft around. Clean up after them.
422 PM.add(createInstructionCombiningPass());
423 addExtensionsToPM(EP_Peephole, PM);
424 PM.add(createJumpThreadingPass());
425
426 // Break up allocas
427 if (UseNewSROA)
428 PM.add(createSROAPass());
429 else
430 PM.add(createScalarReplAggregatesPass());
431
432 // Run a few AA driven optimizations here and now, to cleanup the code.
433 PM.add(createFunctionAttrsPass()); // Add nocapture.
434 PM.add(createGlobalsModRefPass()); // IP alias analysis.
435
436 PM.add(createLICMPass()); // Hoist loop invariants.
437 if (EnableMLSM)
438 PM.add(createMergedLoadStoreMotionPass()); // Merge ld/st in diamonds.
439 PM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies.
440 PM.add(createMemCpyOptPass()); // Remove dead memcpys.
441
442 // Nuke dead stores.
443 PM.add(createDeadStoreEliminationPass());
444
445 // More loops are countable; try to optimize them.
446 PM.add(createIndVarSimplifyPass());
447 PM.add(createLoopDeletionPass());
448 PM.add(createLoopVectorizePass(true, LoopVectorize));
449
450 // More scalar chains could be vectorized due to more alias information
451 if (RunSLPAfterLoopVectorization)
452 if (SLPVectorize)
453 PM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.
454
455 // After vectorization, assume intrinsics may tell us more about pointer
456 // alignments.
457 PM.add(createAlignmentFromAssumptionsPass());
458
459 if (LoadCombine)
460 PM.add(createLoadCombinePass());
461
462 // Cleanup and simplify the code after the scalar optimizations.
463 PM.add(createInstructionCombiningPass());
464 addExtensionsToPM(EP_Peephole, PM);
465
466 PM.add(createJumpThreadingPass());
467
468 // Delete basic blocks, which optimization passes may have killed.
469 PM.add(createCFGSimplificationPass());
470
471 // Now that we have optimized the program, discard unreachable functions.
472 PM.add(createGlobalDCEPass());
473
474 // FIXME: this is profitable (for compiler time) to do at -O0 too, but
475 // currently it damages debug info.
476 if (MergeFunctions)
477 PM.add(createMergeFunctionsPass());
478 }
479
populateLTOPassManager(PassManagerBase & PM,TargetMachine * TM)480 void PassManagerBuilder::populateLTOPassManager(PassManagerBase &PM,
481 TargetMachine *TM) {
482 if (TM) {
483 PM.add(new DataLayoutPass());
484 TM->addAnalysisPasses(PM);
485 }
486
487 if (LibraryInfo)
488 PM.add(new TargetLibraryInfo(*LibraryInfo));
489
490 if (VerifyInput)
491 PM.add(createVerifierPass());
492
493 if (StripDebug)
494 PM.add(createStripSymbolsPass(true));
495
496 if (VerifyInput)
497 PM.add(createDebugInfoVerifierPass());
498
499 if (OptLevel != 0)
500 addLTOOptimizationPasses(PM);
501
502 if (VerifyOutput) {
503 PM.add(createVerifierPass());
504 PM.add(createDebugInfoVerifierPass());
505 }
506 }
507
unwrap(LLVMPassManagerBuilderRef P)508 inline PassManagerBuilder *unwrap(LLVMPassManagerBuilderRef P) {
509 return reinterpret_cast<PassManagerBuilder*>(P);
510 }
511
wrap(PassManagerBuilder * P)512 inline LLVMPassManagerBuilderRef wrap(PassManagerBuilder *P) {
513 return reinterpret_cast<LLVMPassManagerBuilderRef>(P);
514 }
515
LLVMPassManagerBuilderCreate()516 LLVMPassManagerBuilderRef LLVMPassManagerBuilderCreate() {
517 PassManagerBuilder *PMB = new PassManagerBuilder();
518 return wrap(PMB);
519 }
520
LLVMPassManagerBuilderDispose(LLVMPassManagerBuilderRef PMB)521 void LLVMPassManagerBuilderDispose(LLVMPassManagerBuilderRef PMB) {
522 PassManagerBuilder *Builder = unwrap(PMB);
523 delete Builder;
524 }
525
526 void
LLVMPassManagerBuilderSetOptLevel(LLVMPassManagerBuilderRef PMB,unsigned OptLevel)527 LLVMPassManagerBuilderSetOptLevel(LLVMPassManagerBuilderRef PMB,
528 unsigned OptLevel) {
529 PassManagerBuilder *Builder = unwrap(PMB);
530 Builder->OptLevel = OptLevel;
531 }
532
533 void
LLVMPassManagerBuilderSetSizeLevel(LLVMPassManagerBuilderRef PMB,unsigned SizeLevel)534 LLVMPassManagerBuilderSetSizeLevel(LLVMPassManagerBuilderRef PMB,
535 unsigned SizeLevel) {
536 PassManagerBuilder *Builder = unwrap(PMB);
537 Builder->SizeLevel = SizeLevel;
538 }
539
540 void
LLVMPassManagerBuilderSetDisableUnitAtATime(LLVMPassManagerBuilderRef PMB,LLVMBool Value)541 LLVMPassManagerBuilderSetDisableUnitAtATime(LLVMPassManagerBuilderRef PMB,
542 LLVMBool Value) {
543 PassManagerBuilder *Builder = unwrap(PMB);
544 Builder->DisableUnitAtATime = Value;
545 }
546
547 void
LLVMPassManagerBuilderSetDisableUnrollLoops(LLVMPassManagerBuilderRef PMB,LLVMBool Value)548 LLVMPassManagerBuilderSetDisableUnrollLoops(LLVMPassManagerBuilderRef PMB,
549 LLVMBool Value) {
550 PassManagerBuilder *Builder = unwrap(PMB);
551 Builder->DisableUnrollLoops = Value;
552 }
553
554 void
LLVMPassManagerBuilderSetDisableSimplifyLibCalls(LLVMPassManagerBuilderRef PMB,LLVMBool Value)555 LLVMPassManagerBuilderSetDisableSimplifyLibCalls(LLVMPassManagerBuilderRef PMB,
556 LLVMBool Value) {
557 // NOTE: The simplify-libcalls pass has been removed.
558 }
559
560 void
LLVMPassManagerBuilderUseInlinerWithThreshold(LLVMPassManagerBuilderRef PMB,unsigned Threshold)561 LLVMPassManagerBuilderUseInlinerWithThreshold(LLVMPassManagerBuilderRef PMB,
562 unsigned Threshold) {
563 PassManagerBuilder *Builder = unwrap(PMB);
564 Builder->Inliner = createFunctionInliningPass(Threshold);
565 }
566
567 void
LLVMPassManagerBuilderPopulateFunctionPassManager(LLVMPassManagerBuilderRef PMB,LLVMPassManagerRef PM)568 LLVMPassManagerBuilderPopulateFunctionPassManager(LLVMPassManagerBuilderRef PMB,
569 LLVMPassManagerRef PM) {
570 PassManagerBuilder *Builder = unwrap(PMB);
571 FunctionPassManager *FPM = unwrap<FunctionPassManager>(PM);
572 Builder->populateFunctionPassManager(*FPM);
573 }
574
575 void
LLVMPassManagerBuilderPopulateModulePassManager(LLVMPassManagerBuilderRef PMB,LLVMPassManagerRef PM)576 LLVMPassManagerBuilderPopulateModulePassManager(LLVMPassManagerBuilderRef PMB,
577 LLVMPassManagerRef PM) {
578 PassManagerBuilder *Builder = unwrap(PMB);
579 PassManagerBase *MPM = unwrap(PM);
580 Builder->populateModulePassManager(*MPM);
581 }
582
LLVMPassManagerBuilderPopulateLTOPassManager(LLVMPassManagerBuilderRef PMB,LLVMPassManagerRef PM,LLVMBool Internalize,LLVMBool RunInliner)583 void LLVMPassManagerBuilderPopulateLTOPassManager(LLVMPassManagerBuilderRef PMB,
584 LLVMPassManagerRef PM,
585 LLVMBool Internalize,
586 LLVMBool RunInliner) {
587 PassManagerBuilder *Builder = unwrap(PMB);
588 PassManagerBase *LPM = unwrap(PM);
589
590 // A small backwards compatibility hack. populateLTOPassManager used to take
591 // an RunInliner option.
592 if (RunInliner && !Builder->Inliner)
593 Builder->Inliner = createFunctionInliningPass();
594
595 Builder->populateLTOPassManager(*LPM);
596 }
597