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