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