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