1 //===- PassManagerBuilder.cpp - Build Standard Pass -----------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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++.
13 //===----------------------------------------------------------------------===//
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/IR/LegacyPassManager.h"
23 #include "llvm/Support/CommandLine.h"
24 #include "llvm/Support/ManagedStatic.h"
25 #include "llvm/Analysis/BasicAliasAnalysis.h"
26 #include "llvm/Analysis/CFLAliasAnalysis.h"
27 #include "llvm/Analysis/GlobalsModRef.h"
28 #include "llvm/Analysis/ScopedNoAliasAA.h"
29 #include "llvm/Analysis/TargetLibraryInfo.h"
30 #include "llvm/Analysis/TypeBasedAliasAnalysis.h"
31 #include "llvm/Target/TargetMachine.h"
32 #include "llvm/Transforms/IPO.h"
33 #include "llvm/Transforms/Scalar.h"
34 #include "llvm/Transforms/Vectorize.h"
39 RunLoopVectorization("vectorize-loops", cl::Hidden,
40 cl::desc("Run the Loop vectorization passes"));
43 RunSLPVectorization("vectorize-slp", cl::Hidden,
44 cl::desc("Run the SLP vectorization passes"));
47 RunBBVectorization("vectorize-slp-aggressive", cl::Hidden,
48 cl::desc("Run the BB vectorization passes"));
51 UseGVNAfterVectorization("use-gvn-after-vectorization",
52 cl::init(false), cl::Hidden,
53 cl::desc("Run GVN instead of Early CSE after vectorization passes"));
55 static cl::opt<bool> ExtraVectorizerPasses(
56 "extra-vectorizer-passes", cl::init(false), cl::Hidden,
57 cl::desc("Run cleanup optimization passes after vectorization."));
59 static cl::opt<bool> UseNewSROA("use-new-sroa",
60 cl::init(true), cl::Hidden,
61 cl::desc("Enable the new, experimental SROA pass"));
64 RunLoopRerolling("reroll-loops", cl::Hidden,
65 cl::desc("Run the loop rerolling pass"));
68 RunFloat2Int("float-to-int", cl::Hidden, cl::init(true),
69 cl::desc("Run the float2int (float demotion) pass"));
71 static cl::opt<bool> RunLoadCombine("combine-loads", cl::init(false),
73 cl::desc("Run the load combining pass"));
76 RunSLPAfterLoopVectorization("run-slp-after-loop-vectorization",
77 cl::init(true), cl::Hidden,
78 cl::desc("Run the SLP vectorizer (and BB vectorizer) after the Loop "
79 "vectorizer instead of before"));
81 static cl::opt<bool> UseCFLAA("use-cfl-aa",
82 cl::init(false), cl::Hidden,
83 cl::desc("Enable the new, experimental CFL alias analysis"));
86 EnableMLSM("mlsm", cl::init(true), cl::Hidden,
87 cl::desc("Enable motion of merged load and store"));
89 static cl::opt<bool> EnableLoopInterchange(
90 "enable-loopinterchange", cl::init(false), cl::Hidden,
91 cl::desc("Enable the new, experimental LoopInterchange Pass"));
93 static cl::opt<bool> EnableLoopDistribute(
94 "enable-loop-distribute", cl::init(false), cl::Hidden,
95 cl::desc("Enable the new, experimental LoopDistribution Pass"));
97 static cl::opt<bool> EnableNonLTOGlobalsModRef(
98 "enable-non-lto-gmr", cl::init(true), cl::Hidden,
100 "Enable the GlobalsModRef AliasAnalysis outside of the LTO pipeline."));
102 static cl::opt<bool> EnableLoopLoadElim(
103 "enable-loop-load-elim", cl::init(false), cl::Hidden,
104 cl::desc("Enable the new, experimental LoopLoadElimination Pass"));
106 PassManagerBuilder::PassManagerBuilder() {
109 LibraryInfo = nullptr;
111 DisableUnitAtATime = false;
112 DisableUnrollLoops = false;
113 BBVectorize = RunBBVectorization;
114 SLPVectorize = RunSLPVectorization;
115 LoopVectorize = RunLoopVectorization;
116 RerollLoops = RunLoopRerolling;
117 LoadCombine = RunLoadCombine;
118 DisableGVNLoadPRE = false;
120 VerifyOutput = false;
121 MergeFunctions = false;
122 PrepareForLTO = false;
125 PassManagerBuilder::~PassManagerBuilder() {
130 /// Set of global extensions, automatically added as part of the standard set.
131 static ManagedStatic<SmallVector<std::pair<PassManagerBuilder::ExtensionPointTy,
132 PassManagerBuilder::ExtensionFn>, 8> > GlobalExtensions;
134 void PassManagerBuilder::addGlobalExtension(
135 PassManagerBuilder::ExtensionPointTy Ty,
136 PassManagerBuilder::ExtensionFn Fn) {
137 GlobalExtensions->push_back(std::make_pair(Ty, Fn));
140 void PassManagerBuilder::addExtension(ExtensionPointTy Ty, ExtensionFn Fn) {
141 Extensions.push_back(std::make_pair(Ty, Fn));
144 void PassManagerBuilder::addExtensionsToPM(ExtensionPointTy ETy,
145 legacy::PassManagerBase &PM) const {
146 for (unsigned i = 0, e = GlobalExtensions->size(); i != e; ++i)
147 if ((*GlobalExtensions)[i].first == ETy)
148 (*GlobalExtensions)[i].second(*this, PM);
149 for (unsigned i = 0, e = Extensions.size(); i != e; ++i)
150 if (Extensions[i].first == ETy)
151 Extensions[i].second(*this, PM);
154 void PassManagerBuilder::addInitialAliasAnalysisPasses(
155 legacy::PassManagerBase &PM) const {
156 // Add TypeBasedAliasAnalysis before BasicAliasAnalysis so that
157 // BasicAliasAnalysis wins if they disagree. This is intended to help
158 // support "obvious" type-punning idioms.
160 PM.add(createCFLAAWrapperPass());
161 PM.add(createTypeBasedAAWrapperPass());
162 PM.add(createScopedNoAliasAAWrapperPass());
165 void PassManagerBuilder::populateFunctionPassManager(
166 legacy::FunctionPassManager &FPM) {
167 addExtensionsToPM(EP_EarlyAsPossible, FPM);
169 // Add LibraryInfo if we have some.
171 FPM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
173 if (OptLevel == 0) return;
175 addInitialAliasAnalysisPasses(FPM);
177 FPM.add(createCFGSimplificationPass());
179 FPM.add(createSROAPass());
181 FPM.add(createScalarReplAggregatesPass());
182 FPM.add(createEarlyCSEPass());
183 FPM.add(createLowerExpectIntrinsicPass());
186 void PassManagerBuilder::populateModulePassManager(
187 legacy::PassManagerBase &MPM) {
188 // If all optimizations are disabled, just run the always-inline pass and,
189 // if enabled, the function merging pass.
196 // FIXME: The BarrierNoopPass is a HACK! The inliner pass above implicitly
197 // creates a CGSCC pass manager, but we don't want to add extensions into
198 // that pass manager. To prevent this we insert a no-op module pass to reset
199 // the pass manager to get the same behavior as EP_OptimizerLast in non-O0
200 // builds. The function merging pass is
202 MPM.add(createMergeFunctionsPass());
203 else if (!GlobalExtensions->empty() || !Extensions.empty())
204 MPM.add(createBarrierNoopPass());
206 addExtensionsToPM(EP_EnabledOnOptLevel0, MPM);
210 // Add LibraryInfo if we have some.
212 MPM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
214 addInitialAliasAnalysisPasses(MPM);
216 if (!DisableUnitAtATime) {
217 addExtensionsToPM(EP_ModuleOptimizerEarly, MPM);
219 MPM.add(createIPSCCPPass()); // IP SCCP
220 MPM.add(createGlobalOptimizerPass()); // Optimize out global vars
222 MPM.add(createDeadArgEliminationPass()); // Dead argument elimination
224 MPM.add(createInstructionCombiningPass());// Clean up after IPCP & DAE
225 addExtensionsToPM(EP_Peephole, MPM);
226 MPM.add(createCFGSimplificationPass()); // Clean up after IPCP & DAE
229 if (EnableNonLTOGlobalsModRef)
230 // We add a module alias analysis pass here. In part due to bugs in the
231 // analysis infrastructure this "works" in that the analysis stays alive
232 // for the entire SCC pass run below.
233 MPM.add(createGlobalsAAWrapperPass());
235 // Start of CallGraph SCC passes.
236 if (!DisableUnitAtATime)
237 MPM.add(createPruneEHPass()); // Remove dead EH info
242 if (!DisableUnitAtATime)
243 MPM.add(createFunctionAttrsPass()); // Set readonly/readnone attrs
245 MPM.add(createArgumentPromotionPass()); // Scalarize uninlined fn args
247 // Start of function pass.
248 // Break up aggregate allocas, using SSAUpdater.
250 MPM.add(createSROAPass());
252 MPM.add(createScalarReplAggregatesPass(-1, false));
253 MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
254 MPM.add(createJumpThreadingPass()); // Thread jumps.
255 MPM.add(createCorrelatedValuePropagationPass()); // Propagate conditionals
256 MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
257 MPM.add(createInstructionCombiningPass()); // Combine silly seq's
258 addExtensionsToPM(EP_Peephole, MPM);
260 MPM.add(createTailCallEliminationPass()); // Eliminate tail calls
261 MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
262 MPM.add(createReassociatePass()); // Reassociate expressions
263 // Rotate Loop - disable header duplication at -Oz
264 MPM.add(createLoopRotatePass(SizeLevel == 2 ? 0 : -1));
265 MPM.add(createLICMPass()); // Hoist loop invariants
266 MPM.add(createLoopUnswitchPass(SizeLevel || OptLevel < 3));
267 MPM.add(createCFGSimplificationPass());
268 MPM.add(createInstructionCombiningPass());
269 MPM.add(createIndVarSimplifyPass()); // Canonicalize indvars
270 MPM.add(createLoopIdiomPass()); // Recognize idioms like memset.
271 MPM.add(createLoopDeletionPass()); // Delete dead loops
272 if (EnableLoopInterchange) {
273 MPM.add(createLoopInterchangePass()); // Interchange loops
274 MPM.add(createCFGSimplificationPass());
276 if (!DisableUnrollLoops)
277 MPM.add(createSimpleLoopUnrollPass()); // Unroll small loops
278 addExtensionsToPM(EP_LoopOptimizerEnd, MPM);
282 MPM.add(createMergedLoadStoreMotionPass()); // Merge ld/st in diamonds
283 MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
285 MPM.add(createMemCpyOptPass()); // Remove memcpy / form memset
286 MPM.add(createSCCPPass()); // Constant prop with SCCP
288 // Delete dead bit computations (instcombine runs after to fold away the dead
289 // computations, and then ADCE will run later to exploit any new DCE
290 // opportunities that creates).
291 MPM.add(createBitTrackingDCEPass()); // Delete dead bit computations
293 // Run instcombine after redundancy elimination to exploit opportunities
294 // opened up by them.
295 MPM.add(createInstructionCombiningPass());
296 addExtensionsToPM(EP_Peephole, MPM);
297 MPM.add(createJumpThreadingPass()); // Thread jumps
298 MPM.add(createCorrelatedValuePropagationPass());
299 MPM.add(createDeadStoreEliminationPass()); // Delete dead stores
300 MPM.add(createLICMPass());
302 addExtensionsToPM(EP_ScalarOptimizerLate, MPM);
305 MPM.add(createLoopRerollPass());
306 if (!RunSLPAfterLoopVectorization) {
308 MPM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.
311 MPM.add(createBBVectorizePass());
312 MPM.add(createInstructionCombiningPass());
313 addExtensionsToPM(EP_Peephole, MPM);
314 if (OptLevel > 1 && UseGVNAfterVectorization)
315 MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
317 MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
319 // BBVectorize may have significantly shortened a loop body; unroll again.
320 if (!DisableUnrollLoops)
321 MPM.add(createLoopUnrollPass());
326 MPM.add(createLoadCombinePass());
328 MPM.add(createAggressiveDCEPass()); // Delete dead instructions
329 MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
330 MPM.add(createInstructionCombiningPass()); // Clean up after everything.
331 addExtensionsToPM(EP_Peephole, MPM);
333 // FIXME: This is a HACK! The inliner pass above implicitly creates a CGSCC
334 // pass manager that we are specifically trying to avoid. To prevent this
335 // we must insert a no-op module pass to reset the pass manager.
336 MPM.add(createBarrierNoopPass());
338 if (!DisableUnitAtATime && OptLevel > 1 && !PrepareForLTO) {
339 // Remove avail extern fns and globals definitions if we aren't
340 // compiling an object file for later LTO. For LTO we want to preserve
341 // these so they are eligible for inlining at link-time. Note if they
342 // are unreferenced they will be removed by GlobalDCE later, so
343 // this only impacts referenced available externally globals.
344 // Eventually they will be suppressed during codegen, but eliminating
345 // here enables more opportunity for GlobalDCE as it may make
346 // globals referenced by available external functions dead
347 // and saves running remaining passes on the eliminated functions.
348 MPM.add(createEliminateAvailableExternallyPass());
351 if (EnableNonLTOGlobalsModRef)
352 // We add a fresh GlobalsModRef run at this point. This is particularly
353 // useful as the above will have inlined, DCE'ed, and function-attr
354 // propagated everything. We should at this point have a reasonably minimal
355 // and richly annotated call graph. By computing aliasing and mod/ref
356 // information for all local globals here, the late loop passes and notably
357 // the vectorizer will be able to use them to help recognize vectorizable
358 // memory operations.
360 // Note that this relies on a bug in the pass manager which preserves
361 // a module analysis into a function pass pipeline (and throughout it) so
362 // long as the first function pass doesn't invalidate the module analysis.
363 // Thus both Float2Int and LoopRotate have to preserve AliasAnalysis for
364 // this to work. Fortunately, it is trivial to preserve AliasAnalysis
365 // (doing nothing preserves it as it is required to be conservatively
366 // correct in the face of IR changes).
367 MPM.add(createGlobalsAAWrapperPass());
370 MPM.add(createFloat2IntPass());
372 addExtensionsToPM(EP_VectorizerStart, MPM);
374 // Re-rotate loops in all our loop nests. These may have fallout out of
375 // rotated form due to GVN or other transformations, and the vectorizer relies
376 // on the rotated form. Disable header duplication at -Oz.
377 MPM.add(createLoopRotatePass(SizeLevel == 2 ? 0 : -1));
379 // Distribute loops to allow partial vectorization. I.e. isolate dependences
380 // into separate loop that would otherwise inhibit vectorization.
381 if (EnableLoopDistribute)
382 MPM.add(createLoopDistributePass());
384 MPM.add(createLoopVectorizePass(DisableUnrollLoops, LoopVectorize));
386 // Eliminate loads by forwarding stores from the previous iteration to loads
387 // of the current iteration.
388 if (EnableLoopLoadElim)
389 MPM.add(createLoopLoadEliminationPass());
391 // FIXME: Because of #pragma vectorize enable, the passes below are always
392 // inserted in the pipeline, even when the vectorizer doesn't run (ex. when
393 // on -O1 and no #pragma is found). Would be good to have these two passes
394 // as function calls, so that we can only pass them when the vectorizer
396 MPM.add(createInstructionCombiningPass());
397 if (OptLevel > 1 && ExtraVectorizerPasses) {
398 // At higher optimization levels, try to clean up any runtime overlap and
399 // alignment checks inserted by the vectorizer. We want to track correllated
400 // runtime checks for two inner loops in the same outer loop, fold any
401 // common computations, hoist loop-invariant aspects out of any outer loop,
402 // and unswitch the runtime checks if possible. Once hoisted, we may have
403 // dead (or speculatable) control flows or more combining opportunities.
404 MPM.add(createEarlyCSEPass());
405 MPM.add(createCorrelatedValuePropagationPass());
406 MPM.add(createInstructionCombiningPass());
407 MPM.add(createLICMPass());
408 MPM.add(createLoopUnswitchPass(SizeLevel || OptLevel < 3));
409 MPM.add(createCFGSimplificationPass());
410 MPM.add(createInstructionCombiningPass());
413 if (RunSLPAfterLoopVectorization) {
415 MPM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.
416 if (OptLevel > 1 && ExtraVectorizerPasses) {
417 MPM.add(createEarlyCSEPass());
422 MPM.add(createBBVectorizePass());
423 MPM.add(createInstructionCombiningPass());
424 addExtensionsToPM(EP_Peephole, MPM);
425 if (OptLevel > 1 && UseGVNAfterVectorization)
426 MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
428 MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
430 // BBVectorize may have significantly shortened a loop body; unroll again.
431 if (!DisableUnrollLoops)
432 MPM.add(createLoopUnrollPass());
436 addExtensionsToPM(EP_Peephole, MPM);
437 MPM.add(createCFGSimplificationPass());
438 MPM.add(createInstructionCombiningPass());
440 if (!DisableUnrollLoops) {
441 MPM.add(createLoopUnrollPass()); // Unroll small loops
443 // LoopUnroll may generate some redundency to cleanup.
444 MPM.add(createInstructionCombiningPass());
446 // Runtime unrolling will introduce runtime check in loop prologue. If the
447 // unrolled loop is a inner loop, then the prologue will be inside the
448 // outer loop. LICM pass can help to promote the runtime check out if the
449 // checked value is loop invariant.
450 MPM.add(createLICMPass());
453 // After vectorization and unrolling, assume intrinsics may tell us more
454 // about pointer alignments.
455 MPM.add(createAlignmentFromAssumptionsPass());
457 if (!DisableUnitAtATime) {
458 // FIXME: We shouldn't bother with this anymore.
459 MPM.add(createStripDeadPrototypesPass()); // Get rid of dead prototypes
461 // GlobalOpt already deletes dead functions and globals, at -O2 try a
462 // late pass of GlobalDCE. It is capable of deleting dead cycles.
464 MPM.add(createGlobalDCEPass()); // Remove dead fns and globals.
465 MPM.add(createConstantMergePass()); // Merge dup global constants
470 MPM.add(createMergeFunctionsPass());
472 addExtensionsToPM(EP_OptimizerLast, MPM);
475 void PassManagerBuilder::addLTOOptimizationPasses(legacy::PassManagerBase &PM) {
476 // Provide AliasAnalysis services for optimizations.
477 addInitialAliasAnalysisPasses(PM);
479 // Propagate constants at call sites into the functions they call. This
480 // opens opportunities for globalopt (and inlining) by substituting function
481 // pointers passed as arguments to direct uses of functions.
482 PM.add(createIPSCCPPass());
484 // Now that we internalized some globals, see if we can hack on them!
485 PM.add(createGlobalOptimizerPass());
487 // Linking modules together can lead to duplicated global constants, only
488 // keep one copy of each constant.
489 PM.add(createConstantMergePass());
491 // Remove unused arguments from functions.
492 PM.add(createDeadArgEliminationPass());
494 // Reduce the code after globalopt and ipsccp. Both can open up significant
495 // simplification opportunities, and both can propagate functions through
496 // function pointers. When this happens, we often have to resolve varargs
497 // calls, etc, so let instcombine do this.
498 PM.add(createInstructionCombiningPass());
499 addExtensionsToPM(EP_Peephole, PM);
501 // Inline small functions
502 bool RunInliner = Inliner;
508 PM.add(createPruneEHPass()); // Remove dead EH info.
510 // Optimize globals again if we ran the inliner.
512 PM.add(createGlobalOptimizerPass());
513 PM.add(createGlobalDCEPass()); // Remove dead functions.
515 // If we didn't decide to inline a function, check to see if we can
516 // transform it to pass arguments by value instead of by reference.
517 PM.add(createArgumentPromotionPass());
519 // The IPO passes may leave cruft around. Clean up after them.
520 PM.add(createInstructionCombiningPass());
521 addExtensionsToPM(EP_Peephole, PM);
522 PM.add(createJumpThreadingPass());
526 PM.add(createSROAPass());
528 PM.add(createScalarReplAggregatesPass());
530 // Run a few AA driven optimizations here and now, to cleanup the code.
531 PM.add(createFunctionAttrsPass()); // Add nocapture.
532 PM.add(createGlobalsAAWrapperPass()); // IP alias analysis.
534 PM.add(createLICMPass()); // Hoist loop invariants.
536 PM.add(createMergedLoadStoreMotionPass()); // Merge ld/st in diamonds.
537 PM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies.
538 PM.add(createMemCpyOptPass()); // Remove dead memcpys.
541 PM.add(createDeadStoreEliminationPass());
543 // More loops are countable; try to optimize them.
544 PM.add(createIndVarSimplifyPass());
545 PM.add(createLoopDeletionPass());
546 if (EnableLoopInterchange)
547 PM.add(createLoopInterchangePass());
549 PM.add(createLoopVectorizePass(true, LoopVectorize));
551 // More scalar chains could be vectorized due to more alias information
552 if (RunSLPAfterLoopVectorization)
554 PM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.
556 // After vectorization, assume intrinsics may tell us more about pointer
558 PM.add(createAlignmentFromAssumptionsPass());
561 PM.add(createLoadCombinePass());
563 // Cleanup and simplify the code after the scalar optimizations.
564 PM.add(createInstructionCombiningPass());
565 addExtensionsToPM(EP_Peephole, PM);
567 PM.add(createJumpThreadingPass());
570 void PassManagerBuilder::addLateLTOOptimizationPasses(
571 legacy::PassManagerBase &PM) {
572 // Delete basic blocks, which optimization passes may have killed.
573 PM.add(createCFGSimplificationPass());
575 // Drop bodies of available externally objects to improve GlobalDCE.
576 PM.add(createEliminateAvailableExternallyPass());
578 // Now that we have optimized the program, discard unreachable functions.
579 PM.add(createGlobalDCEPass());
581 // FIXME: this is profitable (for compiler time) to do at -O0 too, but
582 // currently it damages debug info.
584 PM.add(createMergeFunctionsPass());
587 void PassManagerBuilder::populateLTOPassManager(legacy::PassManagerBase &PM) {
589 PM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
592 PM.add(createVerifierPass());
595 addLTOOptimizationPasses(PM);
597 // Lower bit sets to globals. This pass supports Clang's control flow
598 // integrity mechanisms (-fsanitize=cfi*) and needs to run at link time if CFI
599 // is enabled. The pass does nothing if CFI is disabled.
600 PM.add(createLowerBitSetsPass());
603 addLateLTOOptimizationPasses(PM);
606 PM.add(createVerifierPass());
609 inline PassManagerBuilder *unwrap(LLVMPassManagerBuilderRef P) {
610 return reinterpret_cast<PassManagerBuilder*>(P);
613 inline LLVMPassManagerBuilderRef wrap(PassManagerBuilder *P) {
614 return reinterpret_cast<LLVMPassManagerBuilderRef>(P);
617 LLVMPassManagerBuilderRef LLVMPassManagerBuilderCreate() {
618 PassManagerBuilder *PMB = new PassManagerBuilder();
622 void LLVMPassManagerBuilderDispose(LLVMPassManagerBuilderRef PMB) {
623 PassManagerBuilder *Builder = unwrap(PMB);
628 LLVMPassManagerBuilderSetOptLevel(LLVMPassManagerBuilderRef PMB,
630 PassManagerBuilder *Builder = unwrap(PMB);
631 Builder->OptLevel = OptLevel;
635 LLVMPassManagerBuilderSetSizeLevel(LLVMPassManagerBuilderRef PMB,
636 unsigned SizeLevel) {
637 PassManagerBuilder *Builder = unwrap(PMB);
638 Builder->SizeLevel = SizeLevel;
642 LLVMPassManagerBuilderSetDisableUnitAtATime(LLVMPassManagerBuilderRef PMB,
644 PassManagerBuilder *Builder = unwrap(PMB);
645 Builder->DisableUnitAtATime = Value;
649 LLVMPassManagerBuilderSetDisableUnrollLoops(LLVMPassManagerBuilderRef PMB,
651 PassManagerBuilder *Builder = unwrap(PMB);
652 Builder->DisableUnrollLoops = Value;
656 LLVMPassManagerBuilderSetDisableSimplifyLibCalls(LLVMPassManagerBuilderRef PMB,
658 // NOTE: The simplify-libcalls pass has been removed.
662 LLVMPassManagerBuilderUseInlinerWithThreshold(LLVMPassManagerBuilderRef PMB,
663 unsigned Threshold) {
664 PassManagerBuilder *Builder = unwrap(PMB);
665 Builder->Inliner = createFunctionInliningPass(Threshold);
669 LLVMPassManagerBuilderPopulateFunctionPassManager(LLVMPassManagerBuilderRef PMB,
670 LLVMPassManagerRef PM) {
671 PassManagerBuilder *Builder = unwrap(PMB);
672 legacy::FunctionPassManager *FPM = unwrap<legacy::FunctionPassManager>(PM);
673 Builder->populateFunctionPassManager(*FPM);
677 LLVMPassManagerBuilderPopulateModulePassManager(LLVMPassManagerBuilderRef PMB,
678 LLVMPassManagerRef PM) {
679 PassManagerBuilder *Builder = unwrap(PMB);
680 legacy::PassManagerBase *MPM = unwrap(PM);
681 Builder->populateModulePassManager(*MPM);
684 void LLVMPassManagerBuilderPopulateLTOPassManager(LLVMPassManagerBuilderRef PMB,
685 LLVMPassManagerRef PM,
686 LLVMBool Internalize,
687 LLVMBool RunInliner) {
688 PassManagerBuilder *Builder = unwrap(PMB);
689 legacy::PassManagerBase *LPM = unwrap(PM);
691 // A small backwards compatibility hack. populateLTOPassManager used to take
692 // an RunInliner option.
693 if (RunInliner && !Builder->Inliner)
694 Builder->Inliner = createFunctionInliningPass();
696 Builder->populateLTOPassManager(*LPM);