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/FunctionInfo.h"
22 #include "llvm/IR/Verifier.h"
23 #include "llvm/IR/LegacyPassManager.h"
24 #include "llvm/Support/CommandLine.h"
25 #include "llvm/Support/ManagedStatic.h"
26 #include "llvm/Analysis/BasicAliasAnalysis.h"
27 #include "llvm/Analysis/CFLAliasAnalysis.h"
28 #include "llvm/Analysis/GlobalsModRef.h"
29 #include "llvm/Analysis/ScopedNoAliasAA.h"
30 #include "llvm/Analysis/TargetLibraryInfo.h"
31 #include "llvm/Analysis/TypeBasedAliasAnalysis.h"
32 #include "llvm/Target/TargetMachine.h"
33 #include "llvm/Transforms/IPO.h"
34 #include "llvm/Transforms/Scalar.h"
35 #include "llvm/Transforms/Vectorize.h"
40 RunLoopVectorization("vectorize-loops", cl::Hidden,
41 cl::desc("Run the Loop vectorization passes"));
44 RunSLPVectorization("vectorize-slp", cl::Hidden,
45 cl::desc("Run the SLP vectorization passes"));
48 RunBBVectorization("vectorize-slp-aggressive", cl::Hidden,
49 cl::desc("Run the BB vectorization passes"));
52 UseGVNAfterVectorization("use-gvn-after-vectorization",
53 cl::init(false), cl::Hidden,
54 cl::desc("Run GVN instead of Early CSE after vectorization passes"));
56 static cl::opt<bool> ExtraVectorizerPasses(
57 "extra-vectorizer-passes", cl::init(false), cl::Hidden,
58 cl::desc("Run cleanup optimization passes after vectorization."));
60 static cl::opt<bool> UseNewSROA("use-new-sroa",
61 cl::init(true), cl::Hidden,
62 cl::desc("Enable the new, experimental SROA pass"));
65 RunLoopRerolling("reroll-loops", cl::Hidden,
66 cl::desc("Run the loop rerolling pass"));
69 RunFloat2Int("float-to-int", cl::Hidden, cl::init(true),
70 cl::desc("Run the float2int (float demotion) pass"));
72 static cl::opt<bool> RunLoadCombine("combine-loads", cl::init(false),
74 cl::desc("Run the load combining pass"));
77 RunSLPAfterLoopVectorization("run-slp-after-loop-vectorization",
78 cl::init(true), cl::Hidden,
79 cl::desc("Run the SLP vectorizer (and BB vectorizer) after the Loop "
80 "vectorizer instead of before"));
82 static cl::opt<bool> UseCFLAA("use-cfl-aa",
83 cl::init(false), cl::Hidden,
84 cl::desc("Enable the new, experimental CFL alias analysis"));
87 EnableMLSM("mlsm", cl::init(true), cl::Hidden,
88 cl::desc("Enable motion of merged load and store"));
90 static cl::opt<bool> EnableLoopInterchange(
91 "enable-loopinterchange", cl::init(false), cl::Hidden,
92 cl::desc("Enable the new, experimental LoopInterchange Pass"));
94 static cl::opt<bool> EnableLoopDistribute(
95 "enable-loop-distribute", cl::init(false), cl::Hidden,
96 cl::desc("Enable the new, experimental LoopDistribution Pass"));
98 static cl::opt<bool> EnableNonLTOGlobalsModRef(
99 "enable-non-lto-gmr", cl::init(true), cl::Hidden,
101 "Enable the GlobalsModRef AliasAnalysis outside of the LTO pipeline."));
103 static cl::opt<bool> EnableLoopLoadElim(
104 "enable-loop-load-elim", cl::init(false), cl::Hidden,
105 cl::desc("Enable the new, experimental LoopLoadElimination Pass"));
107 PassManagerBuilder::PassManagerBuilder() {
110 LibraryInfo = nullptr;
112 FunctionIndex = nullptr;
113 DisableUnitAtATime = false;
114 DisableUnrollLoops = false;
115 BBVectorize = RunBBVectorization;
116 SLPVectorize = RunSLPVectorization;
117 LoopVectorize = RunLoopVectorization;
118 RerollLoops = RunLoopRerolling;
119 LoadCombine = RunLoadCombine;
120 DisableGVNLoadPRE = false;
122 VerifyOutput = false;
123 MergeFunctions = false;
124 PrepareForLTO = false;
127 PassManagerBuilder::~PassManagerBuilder() {
132 /// Set of global extensions, automatically added as part of the standard set.
133 static ManagedStatic<SmallVector<std::pair<PassManagerBuilder::ExtensionPointTy,
134 PassManagerBuilder::ExtensionFn>, 8> > GlobalExtensions;
136 void PassManagerBuilder::addGlobalExtension(
137 PassManagerBuilder::ExtensionPointTy Ty,
138 PassManagerBuilder::ExtensionFn Fn) {
139 GlobalExtensions->push_back(std::make_pair(Ty, Fn));
142 void PassManagerBuilder::addExtension(ExtensionPointTy Ty, ExtensionFn Fn) {
143 Extensions.push_back(std::make_pair(Ty, Fn));
146 void PassManagerBuilder::addExtensionsToPM(ExtensionPointTy ETy,
147 legacy::PassManagerBase &PM) const {
148 for (unsigned i = 0, e = GlobalExtensions->size(); i != e; ++i)
149 if ((*GlobalExtensions)[i].first == ETy)
150 (*GlobalExtensions)[i].second(*this, PM);
151 for (unsigned i = 0, e = Extensions.size(); i != e; ++i)
152 if (Extensions[i].first == ETy)
153 Extensions[i].second(*this, PM);
156 void PassManagerBuilder::addInitialAliasAnalysisPasses(
157 legacy::PassManagerBase &PM) const {
158 // Add TypeBasedAliasAnalysis before BasicAliasAnalysis so that
159 // BasicAliasAnalysis wins if they disagree. This is intended to help
160 // support "obvious" type-punning idioms.
162 PM.add(createCFLAAWrapperPass());
163 PM.add(createTypeBasedAAWrapperPass());
164 PM.add(createScopedNoAliasAAWrapperPass());
167 void PassManagerBuilder::populateFunctionPassManager(
168 legacy::FunctionPassManager &FPM) {
169 addExtensionsToPM(EP_EarlyAsPossible, FPM);
171 // Add LibraryInfo if we have some.
173 FPM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
175 if (OptLevel == 0) return;
177 addInitialAliasAnalysisPasses(FPM);
179 FPM.add(createCFGSimplificationPass());
181 FPM.add(createSROAPass());
183 FPM.add(createScalarReplAggregatesPass());
184 FPM.add(createEarlyCSEPass());
185 FPM.add(createLowerExpectIntrinsicPass());
188 void PassManagerBuilder::populateModulePassManager(
189 legacy::PassManagerBase &MPM) {
190 // If all optimizations are disabled, just run the always-inline pass and,
191 // if enabled, the function merging pass.
198 // FIXME: The BarrierNoopPass is a HACK! The inliner pass above implicitly
199 // creates a CGSCC pass manager, but we don't want to add extensions into
200 // that pass manager. To prevent this we insert a no-op module pass to reset
201 // the pass manager to get the same behavior as EP_OptimizerLast in non-O0
202 // builds. The function merging pass is
204 MPM.add(createMergeFunctionsPass());
205 else if (!GlobalExtensions->empty() || !Extensions.empty())
206 MPM.add(createBarrierNoopPass());
208 addExtensionsToPM(EP_EnabledOnOptLevel0, MPM);
212 // Add LibraryInfo if we have some.
214 MPM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
216 addInitialAliasAnalysisPasses(MPM);
218 if (!DisableUnitAtATime) {
219 addExtensionsToPM(EP_ModuleOptimizerEarly, MPM);
221 MPM.add(createIPSCCPPass()); // IP SCCP
222 MPM.add(createGlobalOptimizerPass()); // Optimize out global vars
223 // Promote any localized global vars
224 MPM.add(createPromoteMemoryToRegisterPass());
226 MPM.add(createDeadArgEliminationPass()); // Dead argument elimination
228 MPM.add(createInstructionCombiningPass());// Clean up after IPCP & DAE
229 addExtensionsToPM(EP_Peephole, MPM);
230 MPM.add(createCFGSimplificationPass()); // Clean up after IPCP & DAE
233 if (EnableNonLTOGlobalsModRef)
234 // We add a module alias analysis pass here. In part due to bugs in the
235 // analysis infrastructure this "works" in that the analysis stays alive
236 // for the entire SCC pass run below.
237 MPM.add(createGlobalsAAWrapperPass());
239 // Start of CallGraph SCC passes.
240 if (!DisableUnitAtATime)
241 MPM.add(createPruneEHPass()); // Remove dead EH info
246 if (!DisableUnitAtATime)
247 MPM.add(createFunctionAttrsPass()); // Set readonly/readnone attrs
249 MPM.add(createArgumentPromotionPass()); // Scalarize uninlined fn args
251 // Start of function pass.
252 // Break up aggregate allocas, using SSAUpdater.
254 MPM.add(createSROAPass());
256 MPM.add(createScalarReplAggregatesPass(-1, false));
257 MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
258 MPM.add(createJumpThreadingPass()); // Thread jumps.
259 MPM.add(createCorrelatedValuePropagationPass()); // Propagate conditionals
260 MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
261 MPM.add(createInstructionCombiningPass()); // Combine silly seq's
262 addExtensionsToPM(EP_Peephole, MPM);
264 MPM.add(createTailCallEliminationPass()); // Eliminate tail calls
265 MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
266 MPM.add(createReassociatePass()); // Reassociate expressions
267 // Rotate Loop - disable header duplication at -Oz
268 MPM.add(createLoopRotatePass(SizeLevel == 2 ? 0 : -1));
269 MPM.add(createLICMPass()); // Hoist loop invariants
270 MPM.add(createLoopUnswitchPass(SizeLevel || OptLevel < 3));
271 MPM.add(createCFGSimplificationPass());
272 MPM.add(createInstructionCombiningPass());
273 MPM.add(createIndVarSimplifyPass()); // Canonicalize indvars
274 MPM.add(createLoopIdiomPass()); // Recognize idioms like memset.
275 MPM.add(createLoopDeletionPass()); // Delete dead loops
276 if (EnableLoopInterchange) {
277 MPM.add(createLoopInterchangePass()); // Interchange loops
278 MPM.add(createCFGSimplificationPass());
280 if (!DisableUnrollLoops)
281 MPM.add(createSimpleLoopUnrollPass()); // Unroll small loops
282 addExtensionsToPM(EP_LoopOptimizerEnd, MPM);
286 MPM.add(createMergedLoadStoreMotionPass()); // Merge ld/st in diamonds
287 MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
289 MPM.add(createMemCpyOptPass()); // Remove memcpy / form memset
290 MPM.add(createSCCPPass()); // Constant prop with SCCP
292 // Delete dead bit computations (instcombine runs after to fold away the dead
293 // computations, and then ADCE will run later to exploit any new DCE
294 // opportunities that creates).
295 MPM.add(createBitTrackingDCEPass()); // Delete dead bit computations
297 // Run instcombine after redundancy elimination to exploit opportunities
298 // opened up by them.
299 MPM.add(createInstructionCombiningPass());
300 addExtensionsToPM(EP_Peephole, MPM);
301 MPM.add(createJumpThreadingPass()); // Thread jumps
302 MPM.add(createCorrelatedValuePropagationPass());
303 MPM.add(createDeadStoreEliminationPass()); // Delete dead stores
304 MPM.add(createLICMPass());
306 addExtensionsToPM(EP_ScalarOptimizerLate, MPM);
309 MPM.add(createLoopRerollPass());
310 if (!RunSLPAfterLoopVectorization) {
312 MPM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.
315 MPM.add(createBBVectorizePass());
316 MPM.add(createInstructionCombiningPass());
317 addExtensionsToPM(EP_Peephole, MPM);
318 if (OptLevel > 1 && UseGVNAfterVectorization)
319 MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
321 MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
323 // BBVectorize may have significantly shortened a loop body; unroll again.
324 if (!DisableUnrollLoops)
325 MPM.add(createLoopUnrollPass());
330 MPM.add(createLoadCombinePass());
332 MPM.add(createAggressiveDCEPass()); // Delete dead instructions
333 MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
334 MPM.add(createInstructionCombiningPass()); // Clean up after everything.
335 addExtensionsToPM(EP_Peephole, MPM);
337 // FIXME: This is a HACK! The inliner pass above implicitly creates a CGSCC
338 // pass manager that we are specifically trying to avoid. To prevent this
339 // we must insert a no-op module pass to reset the pass manager.
340 MPM.add(createBarrierNoopPass());
342 if (!DisableUnitAtATime && OptLevel > 1 && !PrepareForLTO) {
343 // Remove avail extern fns and globals definitions if we aren't
344 // compiling an object file for later LTO. For LTO we want to preserve
345 // these so they are eligible for inlining at link-time. Note if they
346 // are unreferenced they will be removed by GlobalDCE later, so
347 // this only impacts referenced available externally globals.
348 // Eventually they will be suppressed during codegen, but eliminating
349 // here enables more opportunity for GlobalDCE as it may make
350 // globals referenced by available external functions dead
351 // and saves running remaining passes on the eliminated functions.
352 MPM.add(createEliminateAvailableExternallyPass());
355 if (EnableNonLTOGlobalsModRef)
356 // We add a fresh GlobalsModRef run at this point. This is particularly
357 // useful as the above will have inlined, DCE'ed, and function-attr
358 // propagated everything. We should at this point have a reasonably minimal
359 // and richly annotated call graph. By computing aliasing and mod/ref
360 // information for all local globals here, the late loop passes and notably
361 // the vectorizer will be able to use them to help recognize vectorizable
362 // memory operations.
364 // Note that this relies on a bug in the pass manager which preserves
365 // a module analysis into a function pass pipeline (and throughout it) so
366 // long as the first function pass doesn't invalidate the module analysis.
367 // Thus both Float2Int and LoopRotate have to preserve AliasAnalysis for
368 // this to work. Fortunately, it is trivial to preserve AliasAnalysis
369 // (doing nothing preserves it as it is required to be conservatively
370 // correct in the face of IR changes).
371 MPM.add(createGlobalsAAWrapperPass());
374 MPM.add(createFloat2IntPass());
376 addExtensionsToPM(EP_VectorizerStart, MPM);
378 // Re-rotate loops in all our loop nests. These may have fallout out of
379 // rotated form due to GVN or other transformations, and the vectorizer relies
380 // on the rotated form. Disable header duplication at -Oz.
381 MPM.add(createLoopRotatePass(SizeLevel == 2 ? 0 : -1));
383 // Distribute loops to allow partial vectorization. I.e. isolate dependences
384 // into separate loop that would otherwise inhibit vectorization.
385 if (EnableLoopDistribute)
386 MPM.add(createLoopDistributePass());
388 MPM.add(createLoopVectorizePass(DisableUnrollLoops, LoopVectorize));
390 // Eliminate loads by forwarding stores from the previous iteration to loads
391 // of the current iteration.
392 if (EnableLoopLoadElim)
393 MPM.add(createLoopLoadEliminationPass());
395 // FIXME: Because of #pragma vectorize enable, the passes below are always
396 // inserted in the pipeline, even when the vectorizer doesn't run (ex. when
397 // on -O1 and no #pragma is found). Would be good to have these two passes
398 // as function calls, so that we can only pass them when the vectorizer
400 MPM.add(createInstructionCombiningPass());
401 if (OptLevel > 1 && ExtraVectorizerPasses) {
402 // At higher optimization levels, try to clean up any runtime overlap and
403 // alignment checks inserted by the vectorizer. We want to track correllated
404 // runtime checks for two inner loops in the same outer loop, fold any
405 // common computations, hoist loop-invariant aspects out of any outer loop,
406 // and unswitch the runtime checks if possible. Once hoisted, we may have
407 // dead (or speculatable) control flows or more combining opportunities.
408 MPM.add(createEarlyCSEPass());
409 MPM.add(createCorrelatedValuePropagationPass());
410 MPM.add(createInstructionCombiningPass());
411 MPM.add(createLICMPass());
412 MPM.add(createLoopUnswitchPass(SizeLevel || OptLevel < 3));
413 MPM.add(createCFGSimplificationPass());
414 MPM.add(createInstructionCombiningPass());
417 if (RunSLPAfterLoopVectorization) {
419 MPM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.
420 if (OptLevel > 1 && ExtraVectorizerPasses) {
421 MPM.add(createEarlyCSEPass());
426 MPM.add(createBBVectorizePass());
427 MPM.add(createInstructionCombiningPass());
428 addExtensionsToPM(EP_Peephole, MPM);
429 if (OptLevel > 1 && UseGVNAfterVectorization)
430 MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
432 MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
434 // BBVectorize may have significantly shortened a loop body; unroll again.
435 if (!DisableUnrollLoops)
436 MPM.add(createLoopUnrollPass());
440 addExtensionsToPM(EP_Peephole, MPM);
441 MPM.add(createCFGSimplificationPass());
442 MPM.add(createInstructionCombiningPass());
444 if (!DisableUnrollLoops) {
445 MPM.add(createLoopUnrollPass()); // Unroll small loops
447 // LoopUnroll may generate some redundency to cleanup.
448 MPM.add(createInstructionCombiningPass());
450 // Runtime unrolling will introduce runtime check in loop prologue. If the
451 // unrolled loop is a inner loop, then the prologue will be inside the
452 // outer loop. LICM pass can help to promote the runtime check out if the
453 // checked value is loop invariant.
454 MPM.add(createLICMPass());
457 // After vectorization and unrolling, assume intrinsics may tell us more
458 // about pointer alignments.
459 MPM.add(createAlignmentFromAssumptionsPass());
461 if (!DisableUnitAtATime) {
462 // FIXME: We shouldn't bother with this anymore.
463 MPM.add(createStripDeadPrototypesPass()); // Get rid of dead prototypes
465 // GlobalOpt already deletes dead functions and globals, at -O2 try a
466 // late pass of GlobalDCE. It is capable of deleting dead cycles.
468 MPM.add(createGlobalDCEPass()); // Remove dead fns and globals.
469 MPM.add(createConstantMergePass()); // Merge dup global constants
474 MPM.add(createMergeFunctionsPass());
476 addExtensionsToPM(EP_OptimizerLast, MPM);
479 void PassManagerBuilder::addLTOOptimizationPasses(legacy::PassManagerBase &PM) {
480 // Provide AliasAnalysis services for optimizations.
481 addInitialAliasAnalysisPasses(PM);
484 PM.add(createFunctionImportPass(FunctionIndex));
486 // Propagate constants at call sites into the functions they call. This
487 // opens opportunities for globalopt (and inlining) by substituting function
488 // pointers passed as arguments to direct uses of functions.
489 PM.add(createIPSCCPPass());
491 // Now that we internalized some globals, see if we can hack on them!
492 PM.add(createFunctionAttrsPass()); // Add norecurse if possible.
493 PM.add(createGlobalOptimizerPass());
494 // Promote any localized global vars.
495 PM.add(createPromoteMemoryToRegisterPass());
497 // Linking modules together can lead to duplicated global constants, only
498 // keep one copy of each constant.
499 PM.add(createConstantMergePass());
501 // Remove unused arguments from functions.
502 PM.add(createDeadArgEliminationPass());
504 // Reduce the code after globalopt and ipsccp. Both can open up significant
505 // simplification opportunities, and both can propagate functions through
506 // function pointers. When this happens, we often have to resolve varargs
507 // calls, etc, so let instcombine do this.
508 PM.add(createInstructionCombiningPass());
509 addExtensionsToPM(EP_Peephole, PM);
511 // Inline small functions
512 bool RunInliner = Inliner;
518 PM.add(createPruneEHPass()); // Remove dead EH info.
520 // Optimize globals again if we ran the inliner.
522 PM.add(createGlobalOptimizerPass());
523 PM.add(createGlobalDCEPass()); // Remove dead functions.
525 // If we didn't decide to inline a function, check to see if we can
526 // transform it to pass arguments by value instead of by reference.
527 PM.add(createArgumentPromotionPass());
529 // The IPO passes may leave cruft around. Clean up after them.
530 PM.add(createInstructionCombiningPass());
531 addExtensionsToPM(EP_Peephole, PM);
532 PM.add(createJumpThreadingPass());
536 PM.add(createSROAPass());
538 PM.add(createScalarReplAggregatesPass());
540 // Run a few AA driven optimizations here and now, to cleanup the code.
541 PM.add(createFunctionAttrsPass()); // Add nocapture.
542 PM.add(createGlobalsAAWrapperPass()); // IP alias analysis.
544 PM.add(createLICMPass()); // Hoist loop invariants.
546 PM.add(createMergedLoadStoreMotionPass()); // Merge ld/st in diamonds.
547 PM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies.
548 PM.add(createMemCpyOptPass()); // Remove dead memcpys.
551 PM.add(createDeadStoreEliminationPass());
553 // More loops are countable; try to optimize them.
554 PM.add(createIndVarSimplifyPass());
555 PM.add(createLoopDeletionPass());
556 if (EnableLoopInterchange)
557 PM.add(createLoopInterchangePass());
559 PM.add(createLoopVectorizePass(true, LoopVectorize));
561 // Now that we've optimized loops (in particular loop induction variables),
562 // we may have exposed more scalar opportunities. Run parts of the scalar
563 // optimizer again at this point.
564 PM.add(createInstructionCombiningPass()); // Initial cleanup
565 PM.add(createCFGSimplificationPass()); // if-convert
566 PM.add(createSCCPPass()); // Propagate exposed constants
567 PM.add(createInstructionCombiningPass()); // Clean up again
568 PM.add(createBitTrackingDCEPass());
570 // More scalar chains could be vectorized due to more alias information
571 if (RunSLPAfterLoopVectorization)
573 PM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.
575 // After vectorization, assume intrinsics may tell us more about pointer
577 PM.add(createAlignmentFromAssumptionsPass());
580 PM.add(createLoadCombinePass());
582 // Cleanup and simplify the code after the scalar optimizations.
583 PM.add(createInstructionCombiningPass());
584 addExtensionsToPM(EP_Peephole, PM);
586 PM.add(createJumpThreadingPass());
589 void PassManagerBuilder::addLateLTOOptimizationPasses(
590 legacy::PassManagerBase &PM) {
591 // Delete basic blocks, which optimization passes may have killed.
592 PM.add(createCFGSimplificationPass());
594 // Drop bodies of available externally objects to improve GlobalDCE.
595 PM.add(createEliminateAvailableExternallyPass());
597 // Now that we have optimized the program, discard unreachable functions.
598 PM.add(createGlobalDCEPass());
600 // FIXME: this is profitable (for compiler time) to do at -O0 too, but
601 // currently it damages debug info.
603 PM.add(createMergeFunctionsPass());
606 void PassManagerBuilder::populateLTOPassManager(legacy::PassManagerBase &PM) {
608 PM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
611 PM.add(createVerifierPass());
614 addLTOOptimizationPasses(PM);
616 // Create a function that performs CFI checks for cross-DSO calls with targets
617 // in the current module.
618 PM.add(createCrossDSOCFIPass());
620 // Lower bit sets to globals. This pass supports Clang's control flow
621 // integrity mechanisms (-fsanitize=cfi*) and needs to run at link time if CFI
622 // is enabled. The pass does nothing if CFI is disabled.
623 PM.add(createLowerBitSetsPass());
626 addLateLTOOptimizationPasses(PM);
629 PM.add(createVerifierPass());
632 inline PassManagerBuilder *unwrap(LLVMPassManagerBuilderRef P) {
633 return reinterpret_cast<PassManagerBuilder*>(P);
636 inline LLVMPassManagerBuilderRef wrap(PassManagerBuilder *P) {
637 return reinterpret_cast<LLVMPassManagerBuilderRef>(P);
640 LLVMPassManagerBuilderRef LLVMPassManagerBuilderCreate() {
641 PassManagerBuilder *PMB = new PassManagerBuilder();
645 void LLVMPassManagerBuilderDispose(LLVMPassManagerBuilderRef PMB) {
646 PassManagerBuilder *Builder = unwrap(PMB);
651 LLVMPassManagerBuilderSetOptLevel(LLVMPassManagerBuilderRef PMB,
653 PassManagerBuilder *Builder = unwrap(PMB);
654 Builder->OptLevel = OptLevel;
658 LLVMPassManagerBuilderSetSizeLevel(LLVMPassManagerBuilderRef PMB,
659 unsigned SizeLevel) {
660 PassManagerBuilder *Builder = unwrap(PMB);
661 Builder->SizeLevel = SizeLevel;
665 LLVMPassManagerBuilderSetDisableUnitAtATime(LLVMPassManagerBuilderRef PMB,
667 PassManagerBuilder *Builder = unwrap(PMB);
668 Builder->DisableUnitAtATime = Value;
672 LLVMPassManagerBuilderSetDisableUnrollLoops(LLVMPassManagerBuilderRef PMB,
674 PassManagerBuilder *Builder = unwrap(PMB);
675 Builder->DisableUnrollLoops = Value;
679 LLVMPassManagerBuilderSetDisableSimplifyLibCalls(LLVMPassManagerBuilderRef PMB,
681 // NOTE: The simplify-libcalls pass has been removed.
685 LLVMPassManagerBuilderUseInlinerWithThreshold(LLVMPassManagerBuilderRef PMB,
686 unsigned Threshold) {
687 PassManagerBuilder *Builder = unwrap(PMB);
688 Builder->Inliner = createFunctionInliningPass(Threshold);
692 LLVMPassManagerBuilderPopulateFunctionPassManager(LLVMPassManagerBuilderRef PMB,
693 LLVMPassManagerRef PM) {
694 PassManagerBuilder *Builder = unwrap(PMB);
695 legacy::FunctionPassManager *FPM = unwrap<legacy::FunctionPassManager>(PM);
696 Builder->populateFunctionPassManager(*FPM);
700 LLVMPassManagerBuilderPopulateModulePassManager(LLVMPassManagerBuilderRef PMB,
701 LLVMPassManagerRef PM) {
702 PassManagerBuilder *Builder = unwrap(PMB);
703 legacy::PassManagerBase *MPM = unwrap(PM);
704 Builder->populateModulePassManager(*MPM);
707 void LLVMPassManagerBuilderPopulateLTOPassManager(LLVMPassManagerBuilderRef PMB,
708 LLVMPassManagerRef PM,
709 LLVMBool Internalize,
710 LLVMBool RunInliner) {
711 PassManagerBuilder *Builder = unwrap(PMB);
712 legacy::PassManagerBase *LPM = unwrap(PM);
714 // A small backwards compatibility hack. populateLTOPassManager used to take
715 // an RunInliner option.
716 if (RunInliner && !Builder->Inliner)
717 Builder->Inliner = createFunctionInliningPass();
719 Builder->populateLTOPassManager(*LPM);