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/IR/LegacyPassManager.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                                            legacy::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 PassManagerBuilder::addInitialAliasAnalysisPasses(
00130     legacy::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(
00142     legacy::FunctionPassManager &FPM) {
00143   addExtensionsToPM(EP_EarlyAsPossible, FPM);
00144 
00145   // Add LibraryInfo if we have some.
00146   if (LibraryInfo)
00147     FPM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
00148 
00149   if (OptLevel == 0) return;
00150 
00151   addInitialAliasAnalysisPasses(FPM);
00152 
00153   FPM.add(createCFGSimplificationPass());
00154   if (UseNewSROA)
00155     FPM.add(createSROAPass());
00156   else
00157     FPM.add(createScalarReplAggregatesPass());
00158   FPM.add(createEarlyCSEPass());
00159   FPM.add(createLowerExpectIntrinsicPass());
00160 }
00161 
00162 void PassManagerBuilder::populateModulePassManager(
00163     legacy::PassManagerBase &MPM) {
00164   // If all optimizations are disabled, just run the always-inline pass and,
00165   // if enabled, the function merging pass.
00166   if (OptLevel == 0) {
00167     if (Inliner) {
00168       MPM.add(Inliner);
00169       Inliner = nullptr;
00170     }
00171 
00172     // FIXME: The BarrierNoopPass is a HACK! The inliner pass above implicitly
00173     // creates a CGSCC pass manager, but we don't want to add extensions into
00174     // that pass manager. To prevent this we insert a no-op module pass to reset
00175     // the pass manager to get the same behavior as EP_OptimizerLast in non-O0
00176     // builds. The function merging pass is 
00177     if (MergeFunctions)
00178       MPM.add(createMergeFunctionsPass());
00179     else if (!GlobalExtensions->empty() || !Extensions.empty())
00180       MPM.add(createBarrierNoopPass());
00181 
00182     addExtensionsToPM(EP_EnabledOnOptLevel0, MPM);
00183     return;
00184   }
00185 
00186   // Add LibraryInfo if we have some.
00187   if (LibraryInfo)
00188     MPM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
00189 
00190   addInitialAliasAnalysisPasses(MPM);
00191 
00192   if (!DisableUnitAtATime) {
00193     addExtensionsToPM(EP_ModuleOptimizerEarly, MPM);
00194 
00195     MPM.add(createIPSCCPPass());              // IP SCCP
00196     MPM.add(createGlobalOptimizerPass());     // Optimize out global vars
00197 
00198     MPM.add(createDeadArgEliminationPass());  // Dead argument elimination
00199 
00200     MPM.add(createInstructionCombiningPass());// Clean up after IPCP & DAE
00201     addExtensionsToPM(EP_Peephole, MPM);
00202     MPM.add(createCFGSimplificationPass());   // Clean up after IPCP & DAE
00203   }
00204 
00205   // Start of CallGraph SCC passes.
00206   if (!DisableUnitAtATime)
00207     MPM.add(createPruneEHPass());             // Remove dead EH info
00208   if (Inliner) {
00209     MPM.add(Inliner);
00210     Inliner = nullptr;
00211   }
00212   if (!DisableUnitAtATime)
00213     MPM.add(createFunctionAttrsPass());       // Set readonly/readnone attrs
00214   if (OptLevel > 2)
00215     MPM.add(createArgumentPromotionPass());   // Scalarize uninlined fn args
00216 
00217   // Start of function pass.
00218   // Break up aggregate allocas, using SSAUpdater.
00219   if (UseNewSROA)
00220     MPM.add(createSROAPass(/*RequiresDomTree*/ false));
00221   else
00222     MPM.add(createScalarReplAggregatesPass(-1, false));
00223   MPM.add(createEarlyCSEPass());              // Catch trivial redundancies
00224   MPM.add(createJumpThreadingPass());         // Thread jumps.
00225   MPM.add(createCorrelatedValuePropagationPass()); // Propagate conditionals
00226   MPM.add(createCFGSimplificationPass());     // Merge & remove BBs
00227   MPM.add(createInstructionCombiningPass());  // Combine silly seq's
00228   addExtensionsToPM(EP_Peephole, MPM);
00229 
00230   if (!DisableTailCalls)
00231     MPM.add(createTailCallEliminationPass()); // Eliminate tail calls
00232   MPM.add(createCFGSimplificationPass());     // Merge & remove BBs
00233   MPM.add(createReassociatePass());           // Reassociate expressions
00234   // Rotate Loop - disable header duplication at -Oz
00235   MPM.add(createLoopRotatePass(SizeLevel == 2 ? 0 : -1));
00236   MPM.add(createLICMPass());                  // Hoist loop invariants
00237   MPM.add(createLoopUnswitchPass(SizeLevel || OptLevel < 3));
00238   MPM.add(createInstructionCombiningPass());
00239   MPM.add(createIndVarSimplifyPass());        // Canonicalize indvars
00240   MPM.add(createLoopIdiomPass());             // Recognize idioms like memset.
00241   MPM.add(createLoopDeletionPass());          // Delete dead loops
00242 
00243   if (!DisableUnrollLoops)
00244     MPM.add(createSimpleLoopUnrollPass());    // Unroll small loops
00245   addExtensionsToPM(EP_LoopOptimizerEnd, MPM);
00246 
00247   if (OptLevel > 1) {
00248     if (EnableMLSM)
00249       MPM.add(createMergedLoadStoreMotionPass()); // Merge ld/st in diamonds
00250     MPM.add(createGVNPass(DisableGVNLoadPRE));  // Remove redundancies
00251   }
00252   MPM.add(createMemCpyOptPass());             // Remove memcpy / form memset
00253   MPM.add(createSCCPPass());                  // Constant prop with SCCP
00254 
00255   // Delete dead bit computations (instcombine runs after to fold away the dead
00256   // computations, and then ADCE will run later to exploit any new DCE
00257   // opportunities that creates).
00258   MPM.add(createBitTrackingDCEPass());        // Delete dead bit computations
00259 
00260   // Run instcombine after redundancy elimination to exploit opportunities
00261   // opened up by them.
00262   MPM.add(createInstructionCombiningPass());
00263   addExtensionsToPM(EP_Peephole, MPM);
00264   MPM.add(createJumpThreadingPass());         // Thread jumps
00265   MPM.add(createCorrelatedValuePropagationPass());
00266   MPM.add(createDeadStoreEliminationPass());  // Delete dead stores
00267   MPM.add(createLICMPass());
00268 
00269   addExtensionsToPM(EP_ScalarOptimizerLate, MPM);
00270 
00271   if (RerollLoops)
00272     MPM.add(createLoopRerollPass());
00273   if (!RunSLPAfterLoopVectorization) {
00274     if (SLPVectorize)
00275       MPM.add(createSLPVectorizerPass());   // Vectorize parallel scalar chains.
00276 
00277     if (BBVectorize) {
00278       MPM.add(createBBVectorizePass());
00279       MPM.add(createInstructionCombiningPass());
00280       addExtensionsToPM(EP_Peephole, MPM);
00281       if (OptLevel > 1 && UseGVNAfterVectorization)
00282         MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
00283       else
00284         MPM.add(createEarlyCSEPass());      // Catch trivial redundancies
00285 
00286       // BBVectorize may have significantly shortened a loop body; unroll again.
00287       if (!DisableUnrollLoops)
00288         MPM.add(createLoopUnrollPass());
00289     }
00290   }
00291 
00292   if (LoadCombine)
00293     MPM.add(createLoadCombinePass());
00294 
00295   MPM.add(createAggressiveDCEPass());         // Delete dead instructions
00296   MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
00297   MPM.add(createInstructionCombiningPass());  // Clean up after everything.
00298   addExtensionsToPM(EP_Peephole, MPM);
00299 
00300   // FIXME: This is a HACK! The inliner pass above implicitly creates a CGSCC
00301   // pass manager that we are specifically trying to avoid. To prevent this
00302   // we must insert a no-op module pass to reset the pass manager.
00303   MPM.add(createBarrierNoopPass());
00304 
00305   // Re-rotate loops in all our loop nests. These may have fallout out of
00306   // rotated form due to GVN or other transformations, and the vectorizer relies
00307   // on the rotated form.
00308   if (ExtraVectorizerPasses)
00309     MPM.add(createLoopRotatePass());
00310 
00311   MPM.add(createLoopVectorizePass(DisableUnrollLoops, LoopVectorize));
00312   // FIXME: Because of #pragma vectorize enable, the passes below are always
00313   // inserted in the pipeline, even when the vectorizer doesn't run (ex. when
00314   // on -O1 and no #pragma is found). Would be good to have these two passes
00315   // as function calls, so that we can only pass them when the vectorizer
00316   // changed the code.
00317   MPM.add(createInstructionCombiningPass());
00318   if (OptLevel > 1 && ExtraVectorizerPasses) {
00319     // At higher optimization levels, try to clean up any runtime overlap and
00320     // alignment checks inserted by the vectorizer. We want to track correllated
00321     // runtime checks for two inner loops in the same outer loop, fold any
00322     // common computations, hoist loop-invariant aspects out of any outer loop,
00323     // and unswitch the runtime checks if possible. Once hoisted, we may have
00324     // dead (or speculatable) control flows or more combining opportunities.
00325     MPM.add(createEarlyCSEPass());
00326     MPM.add(createCorrelatedValuePropagationPass());
00327     MPM.add(createInstructionCombiningPass());
00328     MPM.add(createLICMPass());
00329     MPM.add(createLoopUnswitchPass(SizeLevel || OptLevel < 3));
00330     MPM.add(createCFGSimplificationPass());
00331     MPM.add(createInstructionCombiningPass());
00332   }
00333 
00334   if (RunSLPAfterLoopVectorization) {
00335     if (SLPVectorize) {
00336       MPM.add(createSLPVectorizerPass());   // Vectorize parallel scalar chains.
00337       if (OptLevel > 1 && ExtraVectorizerPasses) {
00338         MPM.add(createEarlyCSEPass());
00339       }
00340     }
00341 
00342     if (BBVectorize) {
00343       MPM.add(createBBVectorizePass());
00344       MPM.add(createInstructionCombiningPass());
00345       addExtensionsToPM(EP_Peephole, MPM);
00346       if (OptLevel > 1 && UseGVNAfterVectorization)
00347         MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
00348       else
00349         MPM.add(createEarlyCSEPass());      // Catch trivial redundancies
00350 
00351       // BBVectorize may have significantly shortened a loop body; unroll again.
00352       if (!DisableUnrollLoops)
00353         MPM.add(createLoopUnrollPass());
00354     }
00355   }
00356 
00357   addExtensionsToPM(EP_Peephole, MPM);
00358   MPM.add(createCFGSimplificationPass());
00359   MPM.add(createInstructionCombiningPass());
00360 
00361   if (!DisableUnrollLoops)
00362     MPM.add(createLoopUnrollPass());    // Unroll small loops
00363 
00364   // After vectorization and unrolling, assume intrinsics may tell us more
00365   // about pointer alignments.
00366   MPM.add(createAlignmentFromAssumptionsPass());
00367 
00368   if (!DisableUnitAtATime) {
00369     // FIXME: We shouldn't bother with this anymore.
00370     MPM.add(createStripDeadPrototypesPass()); // Get rid of dead prototypes
00371 
00372     // GlobalOpt already deletes dead functions and globals, at -O2 try a
00373     // late pass of GlobalDCE.  It is capable of deleting dead cycles.
00374     if (OptLevel > 1) {
00375       MPM.add(createGlobalDCEPass());         // Remove dead fns and globals.
00376       MPM.add(createConstantMergePass());     // Merge dup global constants
00377     }
00378   }
00379 
00380   if (MergeFunctions)
00381     MPM.add(createMergeFunctionsPass());
00382 
00383   addExtensionsToPM(EP_OptimizerLast, MPM);
00384 }
00385 
00386 void PassManagerBuilder::addLTOOptimizationPasses(legacy::PassManagerBase &PM) {
00387   // Provide AliasAnalysis services for optimizations.
00388   addInitialAliasAnalysisPasses(PM);
00389 
00390   // Propagate constants at call sites into the functions they call.  This
00391   // opens opportunities for globalopt (and inlining) by substituting function
00392   // pointers passed as arguments to direct uses of functions.
00393   PM.add(createIPSCCPPass());
00394 
00395   // Now that we internalized some globals, see if we can hack on them!
00396   PM.add(createGlobalOptimizerPass());
00397 
00398   // Linking modules together can lead to duplicated global constants, only
00399   // keep one copy of each constant.
00400   PM.add(createConstantMergePass());
00401 
00402   // Remove unused arguments from functions.
00403   PM.add(createDeadArgEliminationPass());
00404 
00405   // Reduce the code after globalopt and ipsccp.  Both can open up significant
00406   // simplification opportunities, and both can propagate functions through
00407   // function pointers.  When this happens, we often have to resolve varargs
00408   // calls, etc, so let instcombine do this.
00409   PM.add(createInstructionCombiningPass());
00410   addExtensionsToPM(EP_Peephole, PM);
00411 
00412   // Inline small functions
00413   bool RunInliner = Inliner;
00414   if (RunInliner) {
00415     PM.add(Inliner);
00416     Inliner = nullptr;
00417   }
00418 
00419   PM.add(createPruneEHPass());   // Remove dead EH info.
00420 
00421   // Optimize globals again if we ran the inliner.
00422   if (RunInliner)
00423     PM.add(createGlobalOptimizerPass());
00424   PM.add(createGlobalDCEPass()); // Remove dead functions.
00425 
00426   // If we didn't decide to inline a function, check to see if we can
00427   // transform it to pass arguments by value instead of by reference.
00428   PM.add(createArgumentPromotionPass());
00429 
00430   // The IPO passes may leave cruft around.  Clean up after them.
00431   PM.add(createInstructionCombiningPass());
00432   addExtensionsToPM(EP_Peephole, PM);
00433   PM.add(createJumpThreadingPass());
00434 
00435   // Break up allocas
00436   if (UseNewSROA)
00437     PM.add(createSROAPass());
00438   else
00439     PM.add(createScalarReplAggregatesPass());
00440 
00441   // Run a few AA driven optimizations here and now, to cleanup the code.
00442   PM.add(createFunctionAttrsPass()); // Add nocapture.
00443   PM.add(createGlobalsModRefPass()); // IP alias analysis.
00444 
00445   PM.add(createLICMPass());                 // Hoist loop invariants.
00446   if (EnableMLSM)
00447     PM.add(createMergedLoadStoreMotionPass()); // Merge ld/st in diamonds.
00448   PM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies.
00449   PM.add(createMemCpyOptPass());            // Remove dead memcpys.
00450 
00451   // Nuke dead stores.
00452   PM.add(createDeadStoreEliminationPass());
00453 
00454   // More loops are countable; try to optimize them.
00455   PM.add(createIndVarSimplifyPass());
00456   PM.add(createLoopDeletionPass());
00457   PM.add(createLoopVectorizePass(true, LoopVectorize));
00458 
00459   // More scalar chains could be vectorized due to more alias information
00460   if (RunSLPAfterLoopVectorization)
00461     if (SLPVectorize)
00462       PM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.
00463 
00464   // After vectorization, assume intrinsics may tell us more about pointer
00465   // alignments.
00466   PM.add(createAlignmentFromAssumptionsPass());
00467 
00468   if (LoadCombine)
00469     PM.add(createLoadCombinePass());
00470 
00471   // Cleanup and simplify the code after the scalar optimizations.
00472   PM.add(createInstructionCombiningPass());
00473   addExtensionsToPM(EP_Peephole, PM);
00474 
00475   PM.add(createJumpThreadingPass());
00476 
00477   // Lower bitset metadata to bitsets.
00478   PM.add(createLowerBitSetsPass());
00479 
00480   // Delete basic blocks, which optimization passes may have killed.
00481   PM.add(createCFGSimplificationPass());
00482 
00483   // Now that we have optimized the program, discard unreachable functions.
00484   PM.add(createGlobalDCEPass());
00485 
00486   // FIXME: this is profitable (for compiler time) to do at -O0 too, but
00487   // currently it damages debug info.
00488   if (MergeFunctions)
00489     PM.add(createMergeFunctionsPass());
00490 }
00491 
00492 void PassManagerBuilder::populateLTOPassManager(legacy::PassManagerBase &PM) {
00493   if (LibraryInfo)
00494     PM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
00495 
00496   if (VerifyInput)
00497     PM.add(createVerifierPass());
00498 
00499   if (StripDebug)
00500     PM.add(createStripSymbolsPass(true));
00501 
00502   if (VerifyInput)
00503     PM.add(createDebugInfoVerifierPass());
00504 
00505   if (OptLevel != 0)
00506     addLTOOptimizationPasses(PM);
00507 
00508   if (VerifyOutput) {
00509     PM.add(createVerifierPass());
00510     PM.add(createDebugInfoVerifierPass());
00511   }
00512 }
00513 
00514 inline PassManagerBuilder *unwrap(LLVMPassManagerBuilderRef P) {
00515     return reinterpret_cast<PassManagerBuilder*>(P);
00516 }
00517 
00518 inline LLVMPassManagerBuilderRef wrap(PassManagerBuilder *P) {
00519   return reinterpret_cast<LLVMPassManagerBuilderRef>(P);
00520 }
00521 
00522 LLVMPassManagerBuilderRef LLVMPassManagerBuilderCreate() {
00523   PassManagerBuilder *PMB = new PassManagerBuilder();
00524   return wrap(PMB);
00525 }
00526 
00527 void LLVMPassManagerBuilderDispose(LLVMPassManagerBuilderRef PMB) {
00528   PassManagerBuilder *Builder = unwrap(PMB);
00529   delete Builder;
00530 }
00531 
00532 void
00533 LLVMPassManagerBuilderSetOptLevel(LLVMPassManagerBuilderRef PMB,
00534                                   unsigned OptLevel) {
00535   PassManagerBuilder *Builder = unwrap(PMB);
00536   Builder->OptLevel = OptLevel;
00537 }
00538 
00539 void
00540 LLVMPassManagerBuilderSetSizeLevel(LLVMPassManagerBuilderRef PMB,
00541                                    unsigned SizeLevel) {
00542   PassManagerBuilder *Builder = unwrap(PMB);
00543   Builder->SizeLevel = SizeLevel;
00544 }
00545 
00546 void
00547 LLVMPassManagerBuilderSetDisableUnitAtATime(LLVMPassManagerBuilderRef PMB,
00548                                             LLVMBool Value) {
00549   PassManagerBuilder *Builder = unwrap(PMB);
00550   Builder->DisableUnitAtATime = Value;
00551 }
00552 
00553 void
00554 LLVMPassManagerBuilderSetDisableUnrollLoops(LLVMPassManagerBuilderRef PMB,
00555                                             LLVMBool Value) {
00556   PassManagerBuilder *Builder = unwrap(PMB);
00557   Builder->DisableUnrollLoops = Value;
00558 }
00559 
00560 void
00561 LLVMPassManagerBuilderSetDisableSimplifyLibCalls(LLVMPassManagerBuilderRef PMB,
00562                                                  LLVMBool Value) {
00563   // NOTE: The simplify-libcalls pass has been removed.
00564 }
00565 
00566 void
00567 LLVMPassManagerBuilderUseInlinerWithThreshold(LLVMPassManagerBuilderRef PMB,
00568                                               unsigned Threshold) {
00569   PassManagerBuilder *Builder = unwrap(PMB);
00570   Builder->Inliner = createFunctionInliningPass(Threshold);
00571 }
00572 
00573 void
00574 LLVMPassManagerBuilderPopulateFunctionPassManager(LLVMPassManagerBuilderRef PMB,
00575                                                   LLVMPassManagerRef PM) {
00576   PassManagerBuilder *Builder = unwrap(PMB);
00577   legacy::FunctionPassManager *FPM = unwrap<legacy::FunctionPassManager>(PM);
00578   Builder->populateFunctionPassManager(*FPM);
00579 }
00580 
00581 void
00582 LLVMPassManagerBuilderPopulateModulePassManager(LLVMPassManagerBuilderRef PMB,
00583                                                 LLVMPassManagerRef PM) {
00584   PassManagerBuilder *Builder = unwrap(PMB);
00585   legacy::PassManagerBase *MPM = unwrap(PM);
00586   Builder->populateModulePassManager(*MPM);
00587 }
00588 
00589 void LLVMPassManagerBuilderPopulateLTOPassManager(LLVMPassManagerBuilderRef PMB,
00590                                                   LLVMPassManagerRef PM,
00591                                                   LLVMBool Internalize,
00592                                                   LLVMBool RunInliner) {
00593   PassManagerBuilder *Builder = unwrap(PMB);
00594   legacy::PassManagerBase *LPM = unwrap(PM);
00595 
00596   // A small backwards compatibility hack. populateLTOPassManager used to take
00597   // an RunInliner option.
00598   if (RunInliner && !Builder->Inliner)
00599     Builder->Inliner = createFunctionInliningPass();
00600 
00601   Builder->populateLTOPassManager(*LPM);
00602 }