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