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