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     MPM.add(createCFGSimplificationPass());
00252   }
00253   if (!DisableUnrollLoops)
00254     MPM.add(createSimpleLoopUnrollPass());    // Unroll small loops
00255   addExtensionsToPM(EP_LoopOptimizerEnd, MPM);
00256 
00257   if (OptLevel > 1) {
00258     if (EnableMLSM)
00259       MPM.add(createMergedLoadStoreMotionPass()); // Merge ld/st in diamonds
00260     MPM.add(createGVNPass(DisableGVNLoadPRE));  // Remove redundancies
00261   }
00262   MPM.add(createMemCpyOptPass());             // Remove memcpy / form memset
00263   MPM.add(createSCCPPass());                  // Constant prop with SCCP
00264 
00265   // Delete dead bit computations (instcombine runs after to fold away the dead
00266   // computations, and then ADCE will run later to exploit any new DCE
00267   // opportunities that creates).
00268   MPM.add(createBitTrackingDCEPass());        // Delete dead bit computations
00269 
00270   // Run instcombine after redundancy elimination to exploit opportunities
00271   // opened up by them.
00272   MPM.add(createInstructionCombiningPass());
00273   addExtensionsToPM(EP_Peephole, MPM);
00274   MPM.add(createJumpThreadingPass());         // Thread jumps
00275   MPM.add(createCorrelatedValuePropagationPass());
00276   MPM.add(createDeadStoreEliminationPass());  // Delete dead stores
00277   MPM.add(createLICMPass());
00278 
00279   addExtensionsToPM(EP_ScalarOptimizerLate, MPM);
00280 
00281   if (RerollLoops)
00282     MPM.add(createLoopRerollPass());
00283   if (!RunSLPAfterLoopVectorization) {
00284     if (SLPVectorize)
00285       MPM.add(createSLPVectorizerPass());   // Vectorize parallel scalar chains.
00286 
00287     if (BBVectorize) {
00288       MPM.add(createBBVectorizePass());
00289       MPM.add(createInstructionCombiningPass());
00290       addExtensionsToPM(EP_Peephole, MPM);
00291       if (OptLevel > 1 && UseGVNAfterVectorization)
00292         MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
00293       else
00294         MPM.add(createEarlyCSEPass());      // Catch trivial redundancies
00295 
00296       // BBVectorize may have significantly shortened a loop body; unroll again.
00297       if (!DisableUnrollLoops)
00298         MPM.add(createLoopUnrollPass());
00299     }
00300   }
00301 
00302   if (LoadCombine)
00303     MPM.add(createLoadCombinePass());
00304 
00305   MPM.add(createAggressiveDCEPass());         // Delete dead instructions
00306   MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
00307   MPM.add(createInstructionCombiningPass());  // Clean up after everything.
00308   addExtensionsToPM(EP_Peephole, MPM);
00309 
00310   // FIXME: This is a HACK! The inliner pass above implicitly creates a CGSCC
00311   // pass manager that we are specifically trying to avoid. To prevent this
00312   // we must insert a no-op module pass to reset the pass manager.
00313   MPM.add(createBarrierNoopPass());
00314 
00315   if (RunFloat2Int)
00316     MPM.add(createFloat2IntPass());
00317 
00318   // Re-rotate loops in all our loop nests. These may have fallout out of
00319   // rotated form due to GVN or other transformations, and the vectorizer relies
00320   // on the rotated form.
00321   MPM.add(createLoopRotatePass());
00322 
00323   MPM.add(createLoopVectorizePass(DisableUnrollLoops, LoopVectorize));
00324   // FIXME: Because of #pragma vectorize enable, the passes below are always
00325   // inserted in the pipeline, even when the vectorizer doesn't run (ex. when
00326   // on -O1 and no #pragma is found). Would be good to have these two passes
00327   // as function calls, so that we can only pass them when the vectorizer
00328   // changed the code.
00329   MPM.add(createInstructionCombiningPass());
00330   if (OptLevel > 1 && ExtraVectorizerPasses) {
00331     // At higher optimization levels, try to clean up any runtime overlap and
00332     // alignment checks inserted by the vectorizer. We want to track correllated
00333     // runtime checks for two inner loops in the same outer loop, fold any
00334     // common computations, hoist loop-invariant aspects out of any outer loop,
00335     // and unswitch the runtime checks if possible. Once hoisted, we may have
00336     // dead (or speculatable) control flows or more combining opportunities.
00337     MPM.add(createEarlyCSEPass());
00338     MPM.add(createCorrelatedValuePropagationPass());
00339     MPM.add(createInstructionCombiningPass());
00340     MPM.add(createLICMPass());
00341     MPM.add(createLoopUnswitchPass(SizeLevel || OptLevel < 3));
00342     MPM.add(createCFGSimplificationPass());
00343     MPM.add(createInstructionCombiningPass());
00344   }
00345 
00346   if (RunSLPAfterLoopVectorization) {
00347     if (SLPVectorize) {
00348       MPM.add(createSLPVectorizerPass());   // Vectorize parallel scalar chains.
00349       if (OptLevel > 1 && ExtraVectorizerPasses) {
00350         MPM.add(createEarlyCSEPass());
00351       }
00352     }
00353 
00354     if (BBVectorize) {
00355       MPM.add(createBBVectorizePass());
00356       MPM.add(createInstructionCombiningPass());
00357       addExtensionsToPM(EP_Peephole, MPM);
00358       if (OptLevel > 1 && UseGVNAfterVectorization)
00359         MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
00360       else
00361         MPM.add(createEarlyCSEPass());      // Catch trivial redundancies
00362 
00363       // BBVectorize may have significantly shortened a loop body; unroll again.
00364       if (!DisableUnrollLoops)
00365         MPM.add(createLoopUnrollPass());
00366     }
00367   }
00368 
00369   addExtensionsToPM(EP_Peephole, MPM);
00370   MPM.add(createCFGSimplificationPass());
00371   MPM.add(createInstructionCombiningPass());
00372 
00373   if (!DisableUnrollLoops) {
00374     MPM.add(createLoopUnrollPass());    // Unroll small loops
00375 
00376     // This is a barrier pass to avoid combine LICM pass and loop unroll pass
00377     // within same loop pass manager.
00378     MPM.add(createInstructionSimplifierPass());
00379 
00380     // Runtime unrolling will introduce runtime check in loop prologue. If the
00381     // unrolled loop is a inner loop, then the prologue will be inside the
00382     // outer loop. LICM pass can help to promote the runtime check out if the
00383     // checked value is loop invariant.
00384     MPM.add(createLICMPass());
00385   }
00386 
00387   // After vectorization and unrolling, assume intrinsics may tell us more
00388   // about pointer alignments.
00389   MPM.add(createAlignmentFromAssumptionsPass());
00390 
00391   if (!DisableUnitAtATime) {
00392     // FIXME: We shouldn't bother with this anymore.
00393     MPM.add(createStripDeadPrototypesPass()); // Get rid of dead prototypes
00394 
00395     // GlobalOpt already deletes dead functions and globals, at -O2 try a
00396     // late pass of GlobalDCE.  It is capable of deleting dead cycles.
00397     if (OptLevel > 1) {
00398       MPM.add(createGlobalDCEPass());         // Remove dead fns and globals.
00399       MPM.add(createConstantMergePass());     // Merge dup global constants
00400     }
00401   }
00402 
00403   if (MergeFunctions)
00404     MPM.add(createMergeFunctionsPass());
00405 
00406   addExtensionsToPM(EP_OptimizerLast, MPM);
00407 }
00408 
00409 void PassManagerBuilder::addLTOOptimizationPasses(legacy::PassManagerBase &PM) {
00410   // Provide AliasAnalysis services for optimizations.
00411   addInitialAliasAnalysisPasses(PM);
00412 
00413   // Propagate constants at call sites into the functions they call.  This
00414   // opens opportunities for globalopt (and inlining) by substituting function
00415   // pointers passed as arguments to direct uses of functions.
00416   PM.add(createIPSCCPPass());
00417 
00418   // Now that we internalized some globals, see if we can hack on them!
00419   PM.add(createGlobalOptimizerPass());
00420 
00421   // Linking modules together can lead to duplicated global constants, only
00422   // keep one copy of each constant.
00423   PM.add(createConstantMergePass());
00424 
00425   // Remove unused arguments from functions.
00426   PM.add(createDeadArgEliminationPass());
00427 
00428   // Reduce the code after globalopt and ipsccp.  Both can open up significant
00429   // simplification opportunities, and both can propagate functions through
00430   // function pointers.  When this happens, we often have to resolve varargs
00431   // calls, etc, so let instcombine do this.
00432   PM.add(createInstructionCombiningPass());
00433   addExtensionsToPM(EP_Peephole, PM);
00434 
00435   // Inline small functions
00436   bool RunInliner = Inliner;
00437   if (RunInliner) {
00438     PM.add(Inliner);
00439     Inliner = nullptr;
00440   }
00441 
00442   PM.add(createPruneEHPass());   // Remove dead EH info.
00443 
00444   // Optimize globals again if we ran the inliner.
00445   if (RunInliner)
00446     PM.add(createGlobalOptimizerPass());
00447   PM.add(createGlobalDCEPass()); // Remove dead functions.
00448 
00449   // If we didn't decide to inline a function, check to see if we can
00450   // transform it to pass arguments by value instead of by reference.
00451   PM.add(createArgumentPromotionPass());
00452 
00453   // The IPO passes may leave cruft around.  Clean up after them.
00454   PM.add(createInstructionCombiningPass());
00455   addExtensionsToPM(EP_Peephole, PM);
00456   PM.add(createJumpThreadingPass());
00457 
00458   // Break up allocas
00459   if (UseNewSROA)
00460     PM.add(createSROAPass());
00461   else
00462     PM.add(createScalarReplAggregatesPass());
00463 
00464   // Run a few AA driven optimizations here and now, to cleanup the code.
00465   PM.add(createFunctionAttrsPass()); // Add nocapture.
00466   PM.add(createGlobalsModRefPass()); // IP alias analysis.
00467 
00468   PM.add(createLICMPass());                 // Hoist loop invariants.
00469   if (EnableMLSM)
00470     PM.add(createMergedLoadStoreMotionPass()); // Merge ld/st in diamonds.
00471   PM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies.
00472   PM.add(createMemCpyOptPass());            // Remove dead memcpys.
00473 
00474   // Nuke dead stores.
00475   PM.add(createDeadStoreEliminationPass());
00476 
00477   // More loops are countable; try to optimize them.
00478   PM.add(createIndVarSimplifyPass());
00479   PM.add(createLoopDeletionPass());
00480   if (EnableLoopInterchange)
00481     PM.add(createLoopInterchangePass());
00482 
00483   PM.add(createLoopVectorizePass(true, LoopVectorize));
00484 
00485   // More scalar chains could be vectorized due to more alias information
00486   if (RunSLPAfterLoopVectorization)
00487     if (SLPVectorize)
00488       PM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.
00489 
00490   // After vectorization, assume intrinsics may tell us more about pointer
00491   // alignments.
00492   PM.add(createAlignmentFromAssumptionsPass());
00493 
00494   if (LoadCombine)
00495     PM.add(createLoadCombinePass());
00496 
00497   // Cleanup and simplify the code after the scalar optimizations.
00498   PM.add(createInstructionCombiningPass());
00499   addExtensionsToPM(EP_Peephole, PM);
00500 
00501   PM.add(createJumpThreadingPass());
00502 }
00503 
00504 void PassManagerBuilder::addLateLTOOptimizationPasses(
00505     legacy::PassManagerBase &PM) {
00506   // Delete basic blocks, which optimization passes may have killed.
00507   PM.add(createCFGSimplificationPass());
00508 
00509   // Now that we have optimized the program, discard unreachable functions.
00510   PM.add(createGlobalDCEPass());
00511 
00512   // FIXME: this is profitable (for compiler time) to do at -O0 too, but
00513   // currently it damages debug info.
00514   if (MergeFunctions)
00515     PM.add(createMergeFunctionsPass());
00516 }
00517 
00518 void PassManagerBuilder::populateLTOPassManager(legacy::PassManagerBase &PM) {
00519   if (LibraryInfo)
00520     PM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
00521 
00522   if (VerifyInput)
00523     PM.add(createVerifierPass());
00524 
00525   if (OptLevel > 1)
00526     addLTOOptimizationPasses(PM);
00527 
00528   // Lower bit sets to globals. This pass supports Clang's control flow
00529   // integrity mechanisms (-fsanitize=cfi*) and needs to run at link time if CFI
00530   // is enabled. The pass does nothing if CFI is disabled.
00531   PM.add(createLowerBitSetsPass());
00532 
00533   if (OptLevel != 0)
00534     addLateLTOOptimizationPasses(PM);
00535 
00536   if (VerifyOutput)
00537     PM.add(createVerifierPass());
00538 }
00539 
00540 inline PassManagerBuilder *unwrap(LLVMPassManagerBuilderRef P) {
00541     return reinterpret_cast<PassManagerBuilder*>(P);
00542 }
00543 
00544 inline LLVMPassManagerBuilderRef wrap(PassManagerBuilder *P) {
00545   return reinterpret_cast<LLVMPassManagerBuilderRef>(P);
00546 }
00547 
00548 LLVMPassManagerBuilderRef LLVMPassManagerBuilderCreate() {
00549   PassManagerBuilder *PMB = new PassManagerBuilder();
00550   return wrap(PMB);
00551 }
00552 
00553 void LLVMPassManagerBuilderDispose(LLVMPassManagerBuilderRef PMB) {
00554   PassManagerBuilder *Builder = unwrap(PMB);
00555   delete Builder;
00556 }
00557 
00558 void
00559 LLVMPassManagerBuilderSetOptLevel(LLVMPassManagerBuilderRef PMB,
00560                                   unsigned OptLevel) {
00561   PassManagerBuilder *Builder = unwrap(PMB);
00562   Builder->OptLevel = OptLevel;
00563 }
00564 
00565 void
00566 LLVMPassManagerBuilderSetSizeLevel(LLVMPassManagerBuilderRef PMB,
00567                                    unsigned SizeLevel) {
00568   PassManagerBuilder *Builder = unwrap(PMB);
00569   Builder->SizeLevel = SizeLevel;
00570 }
00571 
00572 void
00573 LLVMPassManagerBuilderSetDisableUnitAtATime(LLVMPassManagerBuilderRef PMB,
00574                                             LLVMBool Value) {
00575   PassManagerBuilder *Builder = unwrap(PMB);
00576   Builder->DisableUnitAtATime = Value;
00577 }
00578 
00579 void
00580 LLVMPassManagerBuilderSetDisableUnrollLoops(LLVMPassManagerBuilderRef PMB,
00581                                             LLVMBool Value) {
00582   PassManagerBuilder *Builder = unwrap(PMB);
00583   Builder->DisableUnrollLoops = Value;
00584 }
00585 
00586 void
00587 LLVMPassManagerBuilderSetDisableSimplifyLibCalls(LLVMPassManagerBuilderRef PMB,
00588                                                  LLVMBool Value) {
00589   // NOTE: The simplify-libcalls pass has been removed.
00590 }
00591 
00592 void
00593 LLVMPassManagerBuilderUseInlinerWithThreshold(LLVMPassManagerBuilderRef PMB,
00594                                               unsigned Threshold) {
00595   PassManagerBuilder *Builder = unwrap(PMB);
00596   Builder->Inliner = createFunctionInliningPass(Threshold);
00597 }
00598 
00599 void
00600 LLVMPassManagerBuilderPopulateFunctionPassManager(LLVMPassManagerBuilderRef PMB,
00601                                                   LLVMPassManagerRef PM) {
00602   PassManagerBuilder *Builder = unwrap(PMB);
00603   legacy::FunctionPassManager *FPM = unwrap<legacy::FunctionPassManager>(PM);
00604   Builder->populateFunctionPassManager(*FPM);
00605 }
00606 
00607 void
00608 LLVMPassManagerBuilderPopulateModulePassManager(LLVMPassManagerBuilderRef PMB,
00609                                                 LLVMPassManagerRef PM) {
00610   PassManagerBuilder *Builder = unwrap(PMB);
00611   legacy::PassManagerBase *MPM = unwrap(PM);
00612   Builder->populateModulePassManager(*MPM);
00613 }
00614 
00615 void LLVMPassManagerBuilderPopulateLTOPassManager(LLVMPassManagerBuilderRef PMB,
00616                                                   LLVMPassManagerRef PM,
00617                                                   LLVMBool Internalize,
00618                                                   LLVMBool RunInliner) {
00619   PassManagerBuilder *Builder = unwrap(PMB);
00620   legacy::PassManagerBase *LPM = unwrap(PM);
00621 
00622   // A small backwards compatibility hack. populateLTOPassManager used to take
00623   // an RunInliner option.
00624   if (RunInliner && !Builder->Inliner)
00625     Builder->Inliner = createFunctionInliningPass();
00626 
00627   Builder->populateLTOPassManager(*LPM);
00628 }