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