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