LLVM API Documentation

PassManagerBuilder.cpp
Go to the documentation of this file.
00001 //===- PassManagerBuilder.cpp - Build Standard Pass -----------------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines the PassManagerBuilder class, which is used to set up a
00011 // "standard" optimization sequence suitable for languages like C and C++.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 
00016 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
00017 #include "llvm-c/Transforms/PassManagerBuilder.h"
00018 #include "llvm/ADT/SmallVector.h"
00019 #include "llvm/Analysis/Passes.h"
00020 #include "llvm/IR/DataLayout.h"
00021 #include "llvm/IR/Verifier.h"
00022 #include "llvm/PassManager.h"
00023 #include "llvm/Support/CommandLine.h"
00024 #include "llvm/Support/ManagedStatic.h"
00025 #include "llvm/Analysis/TargetLibraryInfo.h"
00026 #include "llvm/Target/TargetMachine.h"
00027 #include "llvm/Transforms/IPO.h"
00028 #include "llvm/Transforms/Scalar.h"
00029 #include "llvm/Transforms/Vectorize.h"
00030 
00031 using namespace llvm;
00032 
00033 static cl::opt<bool>
00034 RunLoopVectorization("vectorize-loops", cl::Hidden,
00035                      cl::desc("Run the Loop vectorization passes"));
00036 
00037 static cl::opt<bool>
00038 RunSLPVectorization("vectorize-slp", cl::Hidden,
00039                     cl::desc("Run the SLP vectorization passes"));
00040 
00041 static cl::opt<bool>
00042 RunBBVectorization("vectorize-slp-aggressive", cl::Hidden,
00043                     cl::desc("Run the BB vectorization passes"));
00044 
00045 static cl::opt<bool>
00046 UseGVNAfterVectorization("use-gvn-after-vectorization",
00047   cl::init(false), cl::Hidden,
00048   cl::desc("Run GVN instead of Early CSE after vectorization passes"));
00049 
00050 static cl::opt<bool> ExtraVectorizerPasses(
00051     "extra-vectorizer-passes", cl::init(false), cl::Hidden,
00052     cl::desc("Run cleanup optimization passes after vectorization."));
00053 
00054 static cl::opt<bool> UseNewSROA("use-new-sroa",
00055   cl::init(true), cl::Hidden,
00056   cl::desc("Enable the new, experimental SROA pass"));
00057 
00058 static cl::opt<bool>
00059 RunLoopRerolling("reroll-loops", cl::Hidden,
00060                  cl::desc("Run the loop rerolling pass"));
00061 
00062 static cl::opt<bool> RunLoadCombine("combine-loads", cl::init(false),
00063                                     cl::Hidden,
00064                                     cl::desc("Run the load combining pass"));
00065 
00066 static cl::opt<bool>
00067 RunSLPAfterLoopVectorization("run-slp-after-loop-vectorization",
00068   cl::init(true), cl::Hidden,
00069   cl::desc("Run the SLP vectorizer (and BB vectorizer) after the Loop "
00070            "vectorizer instead of before"));
00071 
00072 static cl::opt<bool> UseCFLAA("use-cfl-aa",
00073   cl::init(false), cl::Hidden,
00074   cl::desc("Enable the new, experimental CFL alias analysis"));
00075 
00076 static cl::opt<bool>
00077 EnableMLSM("mlsm", cl::init(true), cl::Hidden,
00078            cl::desc("Enable motion of merged load and store"));
00079 
00080 PassManagerBuilder::PassManagerBuilder() {
00081     OptLevel = 2;
00082     SizeLevel = 0;
00083     LibraryInfo = nullptr;
00084     Inliner = nullptr;
00085     DisableTailCalls = false;
00086     DisableUnitAtATime = false;
00087     DisableUnrollLoops = false;
00088     BBVectorize = RunBBVectorization;
00089     SLPVectorize = RunSLPVectorization;
00090     LoopVectorize = RunLoopVectorization;
00091     RerollLoops = RunLoopRerolling;
00092     LoadCombine = RunLoadCombine;
00093     DisableGVNLoadPRE = false;
00094     VerifyInput = false;
00095     VerifyOutput = false;
00096     StripDebug = false;
00097     MergeFunctions = false;
00098 }
00099 
00100 PassManagerBuilder::~PassManagerBuilder() {
00101   delete LibraryInfo;
00102   delete Inliner;
00103 }
00104 
00105 /// Set of global extensions, automatically added as part of the standard set.
00106 static ManagedStatic<SmallVector<std::pair<PassManagerBuilder::ExtensionPointTy,
00107    PassManagerBuilder::ExtensionFn>, 8> > GlobalExtensions;
00108 
00109 void PassManagerBuilder::addGlobalExtension(
00110     PassManagerBuilder::ExtensionPointTy Ty,
00111     PassManagerBuilder::ExtensionFn Fn) {
00112   GlobalExtensions->push_back(std::make_pair(Ty, Fn));
00113 }
00114 
00115 void PassManagerBuilder::addExtension(ExtensionPointTy Ty, ExtensionFn Fn) {
00116   Extensions.push_back(std::make_pair(Ty, Fn));
00117 }
00118 
00119 void PassManagerBuilder::addExtensionsToPM(ExtensionPointTy ETy,
00120                                            PassManagerBase &PM) const {
00121   for (unsigned i = 0, e = GlobalExtensions->size(); i != e; ++i)
00122     if ((*GlobalExtensions)[i].first == ETy)
00123       (*GlobalExtensions)[i].second(*this, PM);
00124   for (unsigned i = 0, e = Extensions.size(); i != e; ++i)
00125     if (Extensions[i].first == ETy)
00126       Extensions[i].second(*this, PM);
00127 }
00128 
00129 void
00130 PassManagerBuilder::addInitialAliasAnalysisPasses(PassManagerBase &PM) const {
00131   // Add TypeBasedAliasAnalysis before BasicAliasAnalysis so that
00132   // BasicAliasAnalysis wins if they disagree. This is intended to help
00133   // support "obvious" type-punning idioms.
00134   if (UseCFLAA)
00135     PM.add(createCFLAliasAnalysisPass());
00136   PM.add(createTypeBasedAliasAnalysisPass());
00137   PM.add(createScopedNoAliasAAPass());
00138   PM.add(createBasicAliasAnalysisPass());
00139 }
00140 
00141 void PassManagerBuilder::populateFunctionPassManager(FunctionPassManager &FPM) {
00142   addExtensionsToPM(EP_EarlyAsPossible, FPM);
00143 
00144   // Add LibraryInfo if we have some.
00145   if (LibraryInfo)
00146     FPM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
00147 
00148   if (OptLevel == 0) return;
00149 
00150   addInitialAliasAnalysisPasses(FPM);
00151 
00152   FPM.add(createCFGSimplificationPass());
00153   if (UseNewSROA)
00154     FPM.add(createSROAPass());
00155   else
00156     FPM.add(createScalarReplAggregatesPass());
00157   FPM.add(createEarlyCSEPass());
00158   FPM.add(createLowerExpectIntrinsicPass());
00159 }
00160 
00161 void PassManagerBuilder::populateModulePassManager(PassManagerBase &MPM) {
00162   // If all optimizations are disabled, just run the always-inline pass and,
00163   // if enabled, the function merging pass.
00164   if (OptLevel == 0) {
00165     if (Inliner) {
00166       MPM.add(Inliner);
00167       Inliner = nullptr;
00168     }
00169 
00170     // FIXME: The BarrierNoopPass is a HACK! The inliner pass above implicitly
00171     // creates a CGSCC pass manager, but we don't want to add extensions into
00172     // that pass manager. To prevent this we insert a no-op module pass to reset
00173     // the pass manager to get the same behavior as EP_OptimizerLast in non-O0
00174     // builds. The function merging pass is 
00175     if (MergeFunctions)
00176       MPM.add(createMergeFunctionsPass());
00177     else if (!GlobalExtensions->empty() || !Extensions.empty())
00178       MPM.add(createBarrierNoopPass());
00179 
00180     addExtensionsToPM(EP_EnabledOnOptLevel0, MPM);
00181     return;
00182   }
00183 
00184   // Add LibraryInfo if we have some.
00185   if (LibraryInfo)
00186     MPM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
00187 
00188   addInitialAliasAnalysisPasses(MPM);
00189 
00190   if (!DisableUnitAtATime) {
00191     addExtensionsToPM(EP_ModuleOptimizerEarly, MPM);
00192 
00193     MPM.add(createIPSCCPPass());              // IP SCCP
00194     MPM.add(createGlobalOptimizerPass());     // Optimize out global vars
00195 
00196     MPM.add(createDeadArgEliminationPass());  // Dead argument elimination
00197 
00198     MPM.add(createInstructionCombiningPass());// Clean up after IPCP & DAE
00199     addExtensionsToPM(EP_Peephole, MPM);
00200     MPM.add(createCFGSimplificationPass());   // Clean up after IPCP & DAE
00201   }
00202 
00203   // Start of CallGraph SCC passes.
00204   if (!DisableUnitAtATime)
00205     MPM.add(createPruneEHPass());             // Remove dead EH info
00206   if (Inliner) {
00207     MPM.add(Inliner);
00208     Inliner = nullptr;
00209   }
00210   if (!DisableUnitAtATime)
00211     MPM.add(createFunctionAttrsPass());       // Set readonly/readnone attrs
00212   if (OptLevel > 2)
00213     MPM.add(createArgumentPromotionPass());   // Scalarize uninlined fn args
00214 
00215   // Start of function pass.
00216   // Break up aggregate allocas, using SSAUpdater.
00217   if (UseNewSROA)
00218     MPM.add(createSROAPass(/*RequiresDomTree*/ false));
00219   else
00220     MPM.add(createScalarReplAggregatesPass(-1, false));
00221   MPM.add(createEarlyCSEPass());              // Catch trivial redundancies
00222   MPM.add(createJumpThreadingPass());         // Thread jumps.
00223   MPM.add(createCorrelatedValuePropagationPass()); // Propagate conditionals
00224   MPM.add(createCFGSimplificationPass());     // Merge & remove BBs
00225   MPM.add(createInstructionCombiningPass());  // Combine silly seq's
00226   addExtensionsToPM(EP_Peephole, MPM);
00227 
00228   if (!DisableTailCalls)
00229     MPM.add(createTailCallEliminationPass()); // Eliminate tail calls
00230   MPM.add(createCFGSimplificationPass());     // Merge & remove BBs
00231   MPM.add(createReassociatePass());           // Reassociate expressions
00232   // Rotate Loop - disable header duplication at -Oz
00233   MPM.add(createLoopRotatePass(SizeLevel == 2 ? 0 : -1));
00234   MPM.add(createLICMPass());                  // Hoist loop invariants
00235   MPM.add(createLoopUnswitchPass(SizeLevel || OptLevel < 3));
00236   MPM.add(createInstructionCombiningPass());
00237   MPM.add(createIndVarSimplifyPass());        // Canonicalize indvars
00238   MPM.add(createLoopIdiomPass());             // Recognize idioms like memset.
00239   MPM.add(createLoopDeletionPass());          // Delete dead loops
00240 
00241   if (!DisableUnrollLoops)
00242     MPM.add(createSimpleLoopUnrollPass());    // Unroll small loops
00243   addExtensionsToPM(EP_LoopOptimizerEnd, MPM);
00244 
00245   if (OptLevel > 1) {
00246     if (EnableMLSM)
00247       MPM.add(createMergedLoadStoreMotionPass()); // Merge ld/st in diamonds
00248     MPM.add(createGVNPass(DisableGVNLoadPRE));  // Remove redundancies
00249   }
00250   MPM.add(createMemCpyOptPass());             // Remove memcpy / form memset
00251   MPM.add(createSCCPPass());                  // Constant prop with SCCP
00252 
00253   // Run instcombine after redundancy elimination to exploit opportunities
00254   // opened up by them.
00255   MPM.add(createInstructionCombiningPass());
00256   addExtensionsToPM(EP_Peephole, MPM);
00257   MPM.add(createJumpThreadingPass());         // Thread jumps
00258   MPM.add(createCorrelatedValuePropagationPass());
00259   MPM.add(createDeadStoreEliminationPass());  // Delete dead stores
00260 
00261   addExtensionsToPM(EP_ScalarOptimizerLate, MPM);
00262 
00263   if (RerollLoops)
00264     MPM.add(createLoopRerollPass());
00265   if (!RunSLPAfterLoopVectorization) {
00266     if (SLPVectorize)
00267       MPM.add(createSLPVectorizerPass());   // Vectorize parallel scalar chains.
00268 
00269     if (BBVectorize) {
00270       MPM.add(createBBVectorizePass());
00271       MPM.add(createInstructionCombiningPass());
00272       addExtensionsToPM(EP_Peephole, MPM);
00273       if (OptLevel > 1 && UseGVNAfterVectorization)
00274         MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
00275       else
00276         MPM.add(createEarlyCSEPass());      // Catch trivial redundancies
00277 
00278       // BBVectorize may have significantly shortened a loop body; unroll again.
00279       if (!DisableUnrollLoops)
00280         MPM.add(createLoopUnrollPass());
00281     }
00282   }
00283 
00284   if (LoadCombine)
00285     MPM.add(createLoadCombinePass());
00286 
00287   MPM.add(createAggressiveDCEPass());         // Delete dead instructions
00288   MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
00289   MPM.add(createInstructionCombiningPass());  // Clean up after everything.
00290   addExtensionsToPM(EP_Peephole, MPM);
00291 
00292   // FIXME: This is a HACK! The inliner pass above implicitly creates a CGSCC
00293   // pass manager that we are specifically trying to avoid. To prevent this
00294   // we must insert a no-op module pass to reset the pass manager.
00295   MPM.add(createBarrierNoopPass());
00296 
00297   // Re-rotate loops in all our loop nests. These may have fallout out of
00298   // rotated form due to GVN or other transformations, and the vectorizer relies
00299   // on the rotated form.
00300   if (ExtraVectorizerPasses)
00301     MPM.add(createLoopRotatePass());
00302 
00303   MPM.add(createLoopVectorizePass(DisableUnrollLoops, LoopVectorize));
00304   // FIXME: Because of #pragma vectorize enable, the passes below are always
00305   // inserted in the pipeline, even when the vectorizer doesn't run (ex. when
00306   // on -O1 and no #pragma is found). Would be good to have these two passes
00307   // as function calls, so that we can only pass them when the vectorizer
00308   // changed the code.
00309   MPM.add(createInstructionCombiningPass());
00310   if (OptLevel > 1 && ExtraVectorizerPasses) {
00311     // At higher optimization levels, try to clean up any runtime overlap and
00312     // alignment checks inserted by the vectorizer. We want to track correllated
00313     // runtime checks for two inner loops in the same outer loop, fold any
00314     // common computations, hoist loop-invariant aspects out of any outer loop,
00315     // and unswitch the runtime checks if possible. Once hoisted, we may have
00316     // dead (or speculatable) control flows or more combining opportunities.
00317     MPM.add(createEarlyCSEPass());
00318     MPM.add(createCorrelatedValuePropagationPass());
00319     MPM.add(createInstructionCombiningPass());
00320     MPM.add(createLICMPass());
00321     MPM.add(createLoopUnswitchPass(SizeLevel || OptLevel < 3));
00322     MPM.add(createCFGSimplificationPass());
00323     MPM.add(createInstructionCombiningPass());
00324   }
00325 
00326   if (RunSLPAfterLoopVectorization) {
00327     if (SLPVectorize) {
00328       MPM.add(createSLPVectorizerPass());   // Vectorize parallel scalar chains.
00329       if (OptLevel > 1 && ExtraVectorizerPasses) {
00330         MPM.add(createEarlyCSEPass());
00331       }
00332     }
00333 
00334     if (BBVectorize) {
00335       MPM.add(createBBVectorizePass());
00336       MPM.add(createInstructionCombiningPass());
00337       addExtensionsToPM(EP_Peephole, MPM);
00338       if (OptLevel > 1 && UseGVNAfterVectorization)
00339         MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
00340       else
00341         MPM.add(createEarlyCSEPass());      // Catch trivial redundancies
00342 
00343       // BBVectorize may have significantly shortened a loop body; unroll again.
00344       if (!DisableUnrollLoops)
00345         MPM.add(createLoopUnrollPass());
00346     }
00347   }
00348 
00349   addExtensionsToPM(EP_Peephole, MPM);
00350   MPM.add(createCFGSimplificationPass());
00351   MPM.add(createInstructionCombiningPass());
00352 
00353   if (!DisableUnrollLoops)
00354     MPM.add(createLoopUnrollPass());    // Unroll small loops
00355 
00356   // After vectorization and unrolling, assume intrinsics may tell us more
00357   // about pointer alignments.
00358   MPM.add(createAlignmentFromAssumptionsPass());
00359 
00360   if (!DisableUnitAtATime) {
00361     // FIXME: We shouldn't bother with this anymore.
00362     MPM.add(createStripDeadPrototypesPass()); // Get rid of dead prototypes
00363 
00364     // GlobalOpt already deletes dead functions and globals, at -O2 try a
00365     // late pass of GlobalDCE.  It is capable of deleting dead cycles.
00366     if (OptLevel > 1) {
00367       MPM.add(createGlobalDCEPass());         // Remove dead fns and globals.
00368       MPM.add(createConstantMergePass());     // Merge dup global constants
00369     }
00370   }
00371 
00372   if (MergeFunctions)
00373     MPM.add(createMergeFunctionsPass());
00374 
00375   addExtensionsToPM(EP_OptimizerLast, MPM);
00376 }
00377 
00378 void PassManagerBuilder::addLTOOptimizationPasses(PassManagerBase &PM) {
00379   // Provide AliasAnalysis services for optimizations.
00380   addInitialAliasAnalysisPasses(PM);
00381 
00382   // Propagate constants at call sites into the functions they call.  This
00383   // opens opportunities for globalopt (and inlining) by substituting function
00384   // pointers passed as arguments to direct uses of functions.
00385   PM.add(createIPSCCPPass());
00386 
00387   // Now that we internalized some globals, see if we can hack on them!
00388   PM.add(createGlobalOptimizerPass());
00389 
00390   // Linking modules together can lead to duplicated global constants, only
00391   // keep one copy of each constant.
00392   PM.add(createConstantMergePass());
00393 
00394   // Remove unused arguments from functions.
00395   PM.add(createDeadArgEliminationPass());
00396 
00397   // Reduce the code after globalopt and ipsccp.  Both can open up significant
00398   // simplification opportunities, and both can propagate functions through
00399   // function pointers.  When this happens, we often have to resolve varargs
00400   // calls, etc, so let instcombine do this.
00401   PM.add(createInstructionCombiningPass());
00402   addExtensionsToPM(EP_Peephole, PM);
00403 
00404   // Inline small functions
00405   bool RunInliner = Inliner;
00406   if (RunInliner) {
00407     PM.add(Inliner);
00408     Inliner = nullptr;
00409   }
00410 
00411   PM.add(createPruneEHPass());   // Remove dead EH info.
00412 
00413   // Optimize globals again if we ran the inliner.
00414   if (RunInliner)
00415     PM.add(createGlobalOptimizerPass());
00416   PM.add(createGlobalDCEPass()); // Remove dead functions.
00417 
00418   // If we didn't decide to inline a function, check to see if we can
00419   // transform it to pass arguments by value instead of by reference.
00420   PM.add(createArgumentPromotionPass());
00421 
00422   // The IPO passes may leave cruft around.  Clean up after them.
00423   PM.add(createInstructionCombiningPass());
00424   addExtensionsToPM(EP_Peephole, PM);
00425   PM.add(createJumpThreadingPass());
00426 
00427   // Break up allocas
00428   if (UseNewSROA)
00429     PM.add(createSROAPass());
00430   else
00431     PM.add(createScalarReplAggregatesPass());
00432 
00433   // Run a few AA driven optimizations here and now, to cleanup the code.
00434   PM.add(createFunctionAttrsPass()); // Add nocapture.
00435   PM.add(createGlobalsModRefPass()); // IP alias analysis.
00436 
00437   PM.add(createLICMPass());                 // Hoist loop invariants.
00438   if (EnableMLSM)
00439     PM.add(createMergedLoadStoreMotionPass()); // Merge ld/st in diamonds.
00440   PM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies.
00441   PM.add(createMemCpyOptPass());            // Remove dead memcpys.
00442 
00443   // Nuke dead stores.
00444   PM.add(createDeadStoreEliminationPass());
00445 
00446   // More loops are countable; try to optimize them.
00447   PM.add(createIndVarSimplifyPass());
00448   PM.add(createLoopDeletionPass());
00449   PM.add(createLoopVectorizePass(true, LoopVectorize));
00450 
00451   // More scalar chains could be vectorized due to more alias information
00452   if (RunSLPAfterLoopVectorization)
00453     if (SLPVectorize)
00454       PM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.
00455 
00456   // After vectorization, assume intrinsics may tell us more about pointer
00457   // alignments.
00458   PM.add(createAlignmentFromAssumptionsPass());
00459 
00460   if (LoadCombine)
00461     PM.add(createLoadCombinePass());
00462 
00463   // Cleanup and simplify the code after the scalar optimizations.
00464   PM.add(createInstructionCombiningPass());
00465   addExtensionsToPM(EP_Peephole, PM);
00466 
00467   PM.add(createJumpThreadingPass());
00468 
00469   // Delete basic blocks, which optimization passes may have killed.
00470   PM.add(createCFGSimplificationPass());
00471 
00472   // Now that we have optimized the program, discard unreachable functions.
00473   PM.add(createGlobalDCEPass());
00474 
00475   // FIXME: this is profitable (for compiler time) to do at -O0 too, but
00476   // currently it damages debug info.
00477   if (MergeFunctions)
00478     PM.add(createMergeFunctionsPass());
00479 }
00480 
00481 void PassManagerBuilder::populateLTOPassManager(PassManagerBase &PM) {
00482   if (LibraryInfo)
00483     PM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
00484 
00485   if (VerifyInput)
00486     PM.add(createVerifierPass());
00487 
00488   if (StripDebug)
00489     PM.add(createStripSymbolsPass(true));
00490 
00491   if (VerifyInput)
00492     PM.add(createDebugInfoVerifierPass());
00493 
00494   if (OptLevel != 0)
00495     addLTOOptimizationPasses(PM);
00496 
00497   if (VerifyOutput) {
00498     PM.add(createVerifierPass());
00499     PM.add(createDebugInfoVerifierPass());
00500   }
00501 }
00502 
00503 inline PassManagerBuilder *unwrap(LLVMPassManagerBuilderRef P) {
00504     return reinterpret_cast<PassManagerBuilder*>(P);
00505 }
00506 
00507 inline LLVMPassManagerBuilderRef wrap(PassManagerBuilder *P) {
00508   return reinterpret_cast<LLVMPassManagerBuilderRef>(P);
00509 }
00510 
00511 LLVMPassManagerBuilderRef LLVMPassManagerBuilderCreate() {
00512   PassManagerBuilder *PMB = new PassManagerBuilder();
00513   return wrap(PMB);
00514 }
00515 
00516 void LLVMPassManagerBuilderDispose(LLVMPassManagerBuilderRef PMB) {
00517   PassManagerBuilder *Builder = unwrap(PMB);
00518   delete Builder;
00519 }
00520 
00521 void
00522 LLVMPassManagerBuilderSetOptLevel(LLVMPassManagerBuilderRef PMB,
00523                                   unsigned OptLevel) {
00524   PassManagerBuilder *Builder = unwrap(PMB);
00525   Builder->OptLevel = OptLevel;
00526 }
00527 
00528 void
00529 LLVMPassManagerBuilderSetSizeLevel(LLVMPassManagerBuilderRef PMB,
00530                                    unsigned SizeLevel) {
00531   PassManagerBuilder *Builder = unwrap(PMB);
00532   Builder->SizeLevel = SizeLevel;
00533 }
00534 
00535 void
00536 LLVMPassManagerBuilderSetDisableUnitAtATime(LLVMPassManagerBuilderRef PMB,
00537                                             LLVMBool Value) {
00538   PassManagerBuilder *Builder = unwrap(PMB);
00539   Builder->DisableUnitAtATime = Value;
00540 }
00541 
00542 void
00543 LLVMPassManagerBuilderSetDisableUnrollLoops(LLVMPassManagerBuilderRef PMB,
00544                                             LLVMBool Value) {
00545   PassManagerBuilder *Builder = unwrap(PMB);
00546   Builder->DisableUnrollLoops = Value;
00547 }
00548 
00549 void
00550 LLVMPassManagerBuilderSetDisableSimplifyLibCalls(LLVMPassManagerBuilderRef PMB,
00551                                                  LLVMBool Value) {
00552   // NOTE: The simplify-libcalls pass has been removed.
00553 }
00554 
00555 void
00556 LLVMPassManagerBuilderUseInlinerWithThreshold(LLVMPassManagerBuilderRef PMB,
00557                                               unsigned Threshold) {
00558   PassManagerBuilder *Builder = unwrap(PMB);
00559   Builder->Inliner = createFunctionInliningPass(Threshold);
00560 }
00561 
00562 void
00563 LLVMPassManagerBuilderPopulateFunctionPassManager(LLVMPassManagerBuilderRef PMB,
00564                                                   LLVMPassManagerRef PM) {
00565   PassManagerBuilder *Builder = unwrap(PMB);
00566   FunctionPassManager *FPM = unwrap<FunctionPassManager>(PM);
00567   Builder->populateFunctionPassManager(*FPM);
00568 }
00569 
00570 void
00571 LLVMPassManagerBuilderPopulateModulePassManager(LLVMPassManagerBuilderRef PMB,
00572                                                 LLVMPassManagerRef PM) {
00573   PassManagerBuilder *Builder = unwrap(PMB);
00574   PassManagerBase *MPM = unwrap(PM);
00575   Builder->populateModulePassManager(*MPM);
00576 }
00577 
00578 void LLVMPassManagerBuilderPopulateLTOPassManager(LLVMPassManagerBuilderRef PMB,
00579                                                   LLVMPassManagerRef PM,
00580                                                   LLVMBool Internalize,
00581                                                   LLVMBool RunInliner) {
00582   PassManagerBuilder *Builder = unwrap(PMB);
00583   PassManagerBase *LPM = unwrap(PM);
00584 
00585   // A small backwards compatibility hack. populateLTOPassManager used to take
00586   // an RunInliner option.
00587   if (RunInliner && !Builder->Inliner)
00588     Builder->Inliner = createFunctionInliningPass();
00589 
00590   Builder->populateLTOPassManager(*LPM);
00591 }