LCOV - code coverage report
Current view: top level - lib/Passes - PassBuilder.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 472 492 95.9 %
Date: 2018-06-17 00:07:59 Functions: 44 44 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- Parsing, selection, and construction of pass pipelines -------------===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : /// \file
      10             : ///
      11             : /// This file provides the implementation of the PassBuilder based on our
      12             : /// static pass registry as well as related functionality. It also provides
      13             : /// helpers to aid in analyzing, debugging, and testing passes and pass
      14             : /// pipelines.
      15             : ///
      16             : //===----------------------------------------------------------------------===//
      17             : 
      18             : #include "llvm/Passes/PassBuilder.h"
      19             : #include "llvm/ADT/StringSwitch.h"
      20             : #include "llvm/Analysis/AliasAnalysis.h"
      21             : #include "llvm/Analysis/AliasAnalysisEvaluator.h"
      22             : #include "llvm/Analysis/AssumptionCache.h"
      23             : #include "llvm/Analysis/BasicAliasAnalysis.h"
      24             : #include "llvm/Analysis/BlockFrequencyInfo.h"
      25             : #include "llvm/Analysis/BranchProbabilityInfo.h"
      26             : #include "llvm/Analysis/CFGPrinter.h"
      27             : #include "llvm/Analysis/CFLAndersAliasAnalysis.h"
      28             : #include "llvm/Analysis/CFLSteensAliasAnalysis.h"
      29             : #include "llvm/Analysis/CGSCCPassManager.h"
      30             : #include "llvm/Analysis/CallGraph.h"
      31             : #include "llvm/Analysis/DemandedBits.h"
      32             : #include "llvm/Analysis/DependenceAnalysis.h"
      33             : #include "llvm/Analysis/DominanceFrontier.h"
      34             : #include "llvm/Analysis/GlobalsModRef.h"
      35             : #include "llvm/Analysis/IVUsers.h"
      36             : #include "llvm/Analysis/LazyCallGraph.h"
      37             : #include "llvm/Analysis/LazyValueInfo.h"
      38             : #include "llvm/Analysis/LoopAccessAnalysis.h"
      39             : #include "llvm/Analysis/LoopInfo.h"
      40             : #include "llvm/Analysis/MemoryDependenceAnalysis.h"
      41             : #include "llvm/Analysis/MemorySSA.h"
      42             : #include "llvm/Analysis/ModuleSummaryAnalysis.h"
      43             : #include "llvm/Analysis/OptimizationRemarkEmitter.h"
      44             : #include "llvm/Analysis/PostDominators.h"
      45             : #include "llvm/Analysis/ProfileSummaryInfo.h"
      46             : #include "llvm/Analysis/RegionInfo.h"
      47             : #include "llvm/Analysis/ScalarEvolution.h"
      48             : #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
      49             : #include "llvm/Analysis/ScopedNoAliasAA.h"
      50             : #include "llvm/Analysis/TargetLibraryInfo.h"
      51             : #include "llvm/Analysis/TargetTransformInfo.h"
      52             : #include "llvm/Analysis/TypeBasedAliasAnalysis.h"
      53             : #include "llvm/CodeGen/PreISelIntrinsicLowering.h"
      54             : #include "llvm/CodeGen/UnreachableBlockElim.h"
      55             : #include "llvm/IR/Dominators.h"
      56             : #include "llvm/IR/IRPrintingPasses.h"
      57             : #include "llvm/IR/PassManager.h"
      58             : #include "llvm/IR/Verifier.h"
      59             : #include "llvm/Support/Debug.h"
      60             : #include "llvm/Support/Regex.h"
      61             : #include "llvm/Target/TargetMachine.h"
      62             : #include "llvm/Transforms/AggressiveInstCombine/AggressiveInstCombine.h"
      63             : #include "llvm/Transforms/Instrumentation/GCOVProfiler.h"
      64             : #include "llvm/Transforms/IPO/AlwaysInliner.h"
      65             : #include "llvm/Transforms/IPO/ArgumentPromotion.h"
      66             : #include "llvm/Transforms/IPO/CalledValuePropagation.h"
      67             : #include "llvm/Transforms/IPO/ConstantMerge.h"
      68             : #include "llvm/Transforms/IPO/CrossDSOCFI.h"
      69             : #include "llvm/Transforms/IPO/DeadArgumentElimination.h"
      70             : #include "llvm/Transforms/IPO/ElimAvailExtern.h"
      71             : #include "llvm/Transforms/IPO/ForceFunctionAttrs.h"
      72             : #include "llvm/Transforms/IPO/FunctionAttrs.h"
      73             : #include "llvm/Transforms/IPO/FunctionImport.h"
      74             : #include "llvm/Transforms/IPO/GlobalDCE.h"
      75             : #include "llvm/Transforms/IPO/GlobalOpt.h"
      76             : #include "llvm/Transforms/IPO/GlobalSplit.h"
      77             : #include "llvm/Transforms/IPO/InferFunctionAttrs.h"
      78             : #include "llvm/Transforms/IPO/Inliner.h"
      79             : #include "llvm/Transforms/IPO/Internalize.h"
      80             : #include "llvm/Transforms/IPO/LowerTypeTests.h"
      81             : #include "llvm/Transforms/IPO/PartialInlining.h"
      82             : #include "llvm/Transforms/IPO/SCCP.h"
      83             : #include "llvm/Transforms/IPO/SampleProfile.h"
      84             : #include "llvm/Transforms/IPO/StripDeadPrototypes.h"
      85             : #include "llvm/Transforms/IPO/SyntheticCountsPropagation.h"
      86             : #include "llvm/Transforms/IPO/WholeProgramDevirt.h"
      87             : #include "llvm/Transforms/InstCombine/InstCombine.h"
      88             : #include "llvm/Transforms/Instrumentation/InstrProfiling.h"
      89             : #include "llvm/Transforms/Instrumentation/BoundsChecking.h"
      90             : #include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
      91             : #include "llvm/Transforms/Scalar/ADCE.h"
      92             : #include "llvm/Transforms/Scalar/AlignmentFromAssumptions.h"
      93             : #include "llvm/Transforms/Scalar/BDCE.h"
      94             : #include "llvm/Transforms/Scalar/CallSiteSplitting.h"
      95             : #include "llvm/Transforms/Scalar/ConstantHoisting.h"
      96             : #include "llvm/Transforms/Scalar/CorrelatedValuePropagation.h"
      97             : #include "llvm/Transforms/Scalar/DCE.h"
      98             : #include "llvm/Transforms/Scalar/DeadStoreElimination.h"
      99             : #include "llvm/Transforms/Scalar/DivRemPairs.h"
     100             : #include "llvm/Transforms/Scalar/EarlyCSE.h"
     101             : #include "llvm/Transforms/Scalar/Float2Int.h"
     102             : #include "llvm/Transforms/Scalar/GVN.h"
     103             : #include "llvm/Transforms/Scalar/GuardWidening.h"
     104             : #include "llvm/Transforms/Scalar/IVUsersPrinter.h"
     105             : #include "llvm/Transforms/Scalar/IndVarSimplify.h"
     106             : #include "llvm/Transforms/Scalar/InductiveRangeCheckElimination.h"
     107             : #include "llvm/Transforms/Scalar/JumpThreading.h"
     108             : #include "llvm/Transforms/Scalar/LICM.h"
     109             : #include "llvm/Transforms/Scalar/LoopAccessAnalysisPrinter.h"
     110             : #include "llvm/Transforms/Scalar/LoopDataPrefetch.h"
     111             : #include "llvm/Transforms/Scalar/LoopDeletion.h"
     112             : #include "llvm/Transforms/Scalar/LoopDistribute.h"
     113             : #include "llvm/Transforms/Scalar/LoopIdiomRecognize.h"
     114             : #include "llvm/Transforms/Scalar/LoopInstSimplify.h"
     115             : #include "llvm/Transforms/Scalar/LoopLoadElimination.h"
     116             : #include "llvm/Transforms/Scalar/LoopPassManager.h"
     117             : #include "llvm/Transforms/Scalar/LoopPredication.h"
     118             : #include "llvm/Transforms/Scalar/LoopRotation.h"
     119             : #include "llvm/Transforms/Scalar/LoopSimplifyCFG.h"
     120             : #include "llvm/Transforms/Scalar/LoopSink.h"
     121             : #include "llvm/Transforms/Scalar/LoopStrengthReduce.h"
     122             : #include "llvm/Transforms/Scalar/LoopUnrollPass.h"
     123             : #include "llvm/Transforms/Scalar/LowerAtomic.h"
     124             : #include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
     125             : #include "llvm/Transforms/Scalar/LowerGuardIntrinsic.h"
     126             : #include "llvm/Transforms/Scalar/MemCpyOptimizer.h"
     127             : #include "llvm/Transforms/Scalar/MergedLoadStoreMotion.h"
     128             : #include "llvm/Transforms/Scalar/NaryReassociate.h"
     129             : #include "llvm/Transforms/Scalar/NewGVN.h"
     130             : #include "llvm/Transforms/Scalar/PartiallyInlineLibCalls.h"
     131             : #include "llvm/Transforms/Scalar/Reassociate.h"
     132             : #include "llvm/Transforms/Scalar/RewriteStatepointsForGC.h"
     133             : #include "llvm/Transforms/Scalar/SCCP.h"
     134             : #include "llvm/Transforms/Scalar/SROA.h"
     135             : #include "llvm/Transforms/Scalar/SimpleLoopUnswitch.h"
     136             : #include "llvm/Transforms/Scalar/SimplifyCFG.h"
     137             : #include "llvm/Transforms/Scalar/Sink.h"
     138             : #include "llvm/Transforms/Scalar/SpeculateAroundPHIs.h"
     139             : #include "llvm/Transforms/Scalar/SpeculativeExecution.h"
     140             : #include "llvm/Transforms/Scalar/TailRecursionElimination.h"
     141             : #include "llvm/Transforms/Utils/AddDiscriminators.h"
     142             : #include "llvm/Transforms/Utils/BreakCriticalEdges.h"
     143             : #include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
     144             : #include "llvm/Transforms/Utils/LCSSA.h"
     145             : #include "llvm/Transforms/Utils/LibCallsShrinkWrap.h"
     146             : #include "llvm/Transforms/Utils/LoopSimplify.h"
     147             : #include "llvm/Transforms/Utils/LowerInvoke.h"
     148             : #include "llvm/Transforms/Utils/Mem2Reg.h"
     149             : #include "llvm/Transforms/Utils/NameAnonGlobals.h"
     150             : #include "llvm/Transforms/Utils/SimplifyInstructions.h"
     151             : #include "llvm/Transforms/Utils/SymbolRewriter.h"
     152             : #include "llvm/Transforms/Vectorize/LoopVectorize.h"
     153             : #include "llvm/Transforms/Vectorize/SLPVectorizer.h"
     154             : 
     155             : using namespace llvm;
     156             : 
     157      101169 : static cl::opt<unsigned> MaxDevirtIterations("pm-max-devirt-iterations",
     158      101169 :                                              cl::ReallyHidden, cl::init(4));
     159             : static cl::opt<bool>
     160      303507 :     RunPartialInlining("enable-npm-partial-inlining", cl::init(false),
     161             :                        cl::Hidden, cl::ZeroOrMore,
     162      303507 :                        cl::desc("Run Partial inlinining pass"));
     163             : 
     164             : static cl::opt<bool>
     165      303507 :     RunNewGVN("enable-npm-newgvn", cl::init(false),
     166             :               cl::Hidden, cl::ZeroOrMore,
     167      303507 :               cl::desc("Run NewGVN instead of GVN"));
     168             : 
     169      101169 : static cl::opt<bool> EnableEarlyCSEMemSSA(
     170      202338 :     "enable-npm-earlycse-memssa", cl::init(true), cl::Hidden,
     171      303507 :     cl::desc("Enable the EarlyCSE w/ MemorySSA pass for the new PM (default = on)"));
     172             : 
     173      101169 : static cl::opt<bool> EnableGVNHoist(
     174      202338 :     "enable-npm-gvn-hoist", cl::init(false), cl::Hidden,
     175      303507 :     cl::desc("Enable the GVN hoisting pass for the new PM (default = off)"));
     176             : 
     177      101169 : static cl::opt<bool> EnableGVNSink(
     178      202338 :     "enable-npm-gvn-sink", cl::init(false), cl::Hidden,
     179      303507 :     cl::desc("Enable the GVN hoisting pass for the new PM (default = off)"));
     180             : 
     181      101169 : static cl::opt<bool> EnableSyntheticCounts(
     182      202338 :     "enable-npm-synthetic-counts", cl::init(false), cl::Hidden, cl::ZeroOrMore,
     183      101169 :     cl::desc("Run synthetic function entry count generation "
     184      303507 :              "pass"));
     185             : 
     186      101169 : static Regex DefaultAliasRegex(
     187      101169 :     "^(default|thinlto-pre-link|thinlto|lto-pre-link|lto)<(O[0123sz])>$");
     188             : 
     189             : static bool isOptimizingForSize(PassBuilder::OptimizationLevel Level) {
     190          69 :   switch (Level) {
     191             :   case PassBuilder::O0:
     192             :   case PassBuilder::O1:
     193             :   case PassBuilder::O2:
     194             :   case PassBuilder::O3:
     195             :     return false;
     196             : 
     197             :   case PassBuilder::Os:
     198             :   case PassBuilder::Oz:
     199             :     return true;
     200             :   }
     201           0 :   llvm_unreachable("Invalid optimization level!");
     202             : }
     203             : 
     204             : namespace {
     205             : 
     206             : /// No-op module pass which does nothing.
     207             : struct NoOpModulePass {
     208             :   PreservedAnalyses run(Module &M, ModuleAnalysisManager &) {
     209             :     return PreservedAnalyses::all();
     210             :   }
     211             :   static StringRef name() { return "NoOpModulePass"; }
     212             : };
     213             : 
     214             : /// No-op module analysis.
     215             : class NoOpModuleAnalysis : public AnalysisInfoMixin<NoOpModuleAnalysis> {
     216             :   friend AnalysisInfoMixin<NoOpModuleAnalysis>;
     217             :   static AnalysisKey Key;
     218             : 
     219             : public:
     220             :   struct Result {};
     221             :   Result run(Module &, ModuleAnalysisManager &) { return Result(); }
     222             :   static StringRef name() { return "NoOpModuleAnalysis"; }
     223             : };
     224             : 
     225             : /// No-op CGSCC pass which does nothing.
     226             : struct NoOpCGSCCPass {
     227             :   PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &,
     228             :                         LazyCallGraph &, CGSCCUpdateResult &UR) {
     229             :     return PreservedAnalyses::all();
     230             :   }
     231             :   static StringRef name() { return "NoOpCGSCCPass"; }
     232             : };
     233             : 
     234             : /// No-op CGSCC analysis.
     235             : class NoOpCGSCCAnalysis : public AnalysisInfoMixin<NoOpCGSCCAnalysis> {
     236             :   friend AnalysisInfoMixin<NoOpCGSCCAnalysis>;
     237             :   static AnalysisKey Key;
     238             : 
     239             : public:
     240             :   struct Result {};
     241             :   Result run(LazyCallGraph::SCC &, CGSCCAnalysisManager &, LazyCallGraph &G) {
     242             :     return Result();
     243             :   }
     244             :   static StringRef name() { return "NoOpCGSCCAnalysis"; }
     245             : };
     246             : 
     247             : /// No-op function pass which does nothing.
     248             : struct NoOpFunctionPass {
     249             :   PreservedAnalyses run(Function &F, FunctionAnalysisManager &) {
     250             :     return PreservedAnalyses::all();
     251             :   }
     252             :   static StringRef name() { return "NoOpFunctionPass"; }
     253             : };
     254             : 
     255             : /// No-op function analysis.
     256             : class NoOpFunctionAnalysis : public AnalysisInfoMixin<NoOpFunctionAnalysis> {
     257             :   friend AnalysisInfoMixin<NoOpFunctionAnalysis>;
     258             :   static AnalysisKey Key;
     259             : 
     260             : public:
     261             :   struct Result {};
     262             :   Result run(Function &, FunctionAnalysisManager &) { return Result(); }
     263             :   static StringRef name() { return "NoOpFunctionAnalysis"; }
     264             : };
     265             : 
     266             : /// No-op loop pass which does nothing.
     267             : struct NoOpLoopPass {
     268             :   PreservedAnalyses run(Loop &L, LoopAnalysisManager &,
     269             :                         LoopStandardAnalysisResults &, LPMUpdater &) {
     270             :     return PreservedAnalyses::all();
     271             :   }
     272             :   static StringRef name() { return "NoOpLoopPass"; }
     273             : };
     274             : 
     275             : /// No-op loop analysis.
     276             : class NoOpLoopAnalysis : public AnalysisInfoMixin<NoOpLoopAnalysis> {
     277             :   friend AnalysisInfoMixin<NoOpLoopAnalysis>;
     278             :   static AnalysisKey Key;
     279             : 
     280             : public:
     281             :   struct Result {};
     282             :   Result run(Loop &, LoopAnalysisManager &, LoopStandardAnalysisResults &) {
     283             :     return Result();
     284             :   }
     285             :   static StringRef name() { return "NoOpLoopAnalysis"; }
     286             : };
     287             : 
     288             : AnalysisKey NoOpModuleAnalysis::Key;
     289             : AnalysisKey NoOpCGSCCAnalysis::Key;
     290             : AnalysisKey NoOpFunctionAnalysis::Key;
     291             : AnalysisKey NoOpLoopAnalysis::Key;
     292             : 
     293             : } // End anonymous namespace.
     294             : 
     295         308 : void PassBuilder::invokePeepholeEPCallbacks(
     296             :     FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) {
     297         322 :   for (auto &C : PeepholeEPCallbacks)
     298             :     C(FPM, Level);
     299         308 : }
     300             : 
     301         954 : void PassBuilder::registerModuleAnalyses(ModuleAnalysisManager &MAM) {
     302             : #define MODULE_ANALYSIS(NAME, CREATE_PASS)                                     \
     303             :   MAM.registerPass([&] { return CREATE_PASS; });
     304             : #include "PassRegistry.def"
     305             : 
     306         960 :   for (auto &C : ModuleAnalysisRegistrationCallbacks)
     307             :     C(MAM);
     308         954 : }
     309             : 
     310         950 : void PassBuilder::registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM) {
     311             : #define CGSCC_ANALYSIS(NAME, CREATE_PASS)                                      \
     312             :   CGAM.registerPass([&] { return CREATE_PASS; });
     313             : #include "PassRegistry.def"
     314             : 
     315         954 :   for (auto &C : CGSCCAnalysisRegistrationCallbacks)
     316             :     C(CGAM);
     317         950 : }
     318             : 
     319         954 : void PassBuilder::registerFunctionAnalyses(FunctionAnalysisManager &FAM) {
     320             : #define FUNCTION_ANALYSIS(NAME, CREATE_PASS)                                   \
     321             :   FAM.registerPass([&] { return CREATE_PASS; });
     322             : #include "PassRegistry.def"
     323             : 
     324        2712 :   for (auto &C : FunctionAnalysisRegistrationCallbacks)
     325             :     C(FAM);
     326         954 : }
     327             : 
     328         950 : void PassBuilder::registerLoopAnalyses(LoopAnalysisManager &LAM) {
     329             : #define LOOP_ANALYSIS(NAME, CREATE_PASS)                                       \
     330             :   LAM.registerPass([&] { return CREATE_PASS; });
     331             : #include "PassRegistry.def"
     332             : 
     333         954 :   for (auto &C : LoopAnalysisRegistrationCallbacks)
     334             :     C(LAM);
     335         950 : }
     336             : 
     337             : FunctionPassManager
     338          66 : PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
     339             :                                                  ThinLTOPhase Phase,
     340             :                                                  bool DebugLogging) {
     341             :   assert(Level != O0 && "Must request optimizations!");
     342          66 :   FunctionPassManager FPM(DebugLogging);
     343             : 
     344             :   // Form SSA out of local memory accesses after breaking apart aggregates into
     345             :   // scalars.
     346          66 :   FPM.addPass(SROA());
     347             : 
     348             :   // Catch trivial redundancies
     349          66 :   FPM.addPass(EarlyCSEPass(EnableEarlyCSEMemSSA));
     350             : 
     351             :   // Hoisting of scalars and load expressions.
     352          66 :   if (EnableGVNHoist)
     353           0 :     FPM.addPass(GVNHoistPass());
     354             : 
     355             :   // Global value numbering based sinking.
     356          66 :   if (EnableGVNSink) {
     357           0 :     FPM.addPass(GVNSinkPass());
     358           0 :     FPM.addPass(SimplifyCFGPass());
     359             :   }
     360             : 
     361             :   // Speculative execution if the target has divergent branches; otherwise nop.
     362          66 :   FPM.addPass(SpeculativeExecutionPass());
     363             : 
     364             :   // Optimize based on known information about branches, and cleanup afterward.
     365          66 :   FPM.addPass(JumpThreadingPass());
     366          66 :   FPM.addPass(CorrelatedValuePropagationPass());
     367          66 :   FPM.addPass(SimplifyCFGPass());
     368          66 :   if (Level == O3)
     369          18 :     FPM.addPass(AggressiveInstCombinePass());
     370         132 :   FPM.addPass(InstCombinePass());
     371             : 
     372             :   if (!isOptimizingForSize(Level))
     373          55 :     FPM.addPass(LibCallsShrinkWrapPass());
     374             : 
     375          66 :   invokePeepholeEPCallbacks(FPM, Level);
     376             : 
     377             :   // For PGO use pipeline, try to optimize memory intrinsics such as memcpy
     378             :   // using the size value profile. Don't perform this when optimizing for size.
     379          78 :   if (PGOOpt && !PGOOpt->ProfileUseFile.empty() &&
     380             :       !isOptimizingForSize(Level))
     381           1 :     FPM.addPass(PGOMemOPSizeOpt());
     382             : 
     383          66 :   FPM.addPass(TailCallElimPass());
     384          66 :   FPM.addPass(SimplifyCFGPass());
     385             : 
     386             :   // Form canonically associated expression trees, and simplify the trees using
     387             :   // basic mathematical properties. For example, this will form (nearly)
     388             :   // minimal multiplication trees.
     389          66 :   FPM.addPass(ReassociatePass());
     390             : 
     391             :   // Add the primary loop simplification pipeline.
     392             :   // FIXME: Currently this is split into two loop pass pipelines because we run
     393             :   // some function passes in between them. These can and should be removed
     394             :   // and/or replaced by scheduling the loop pass equivalents in the correct
     395             :   // positions. But those equivalent passes aren't powerful enough yet.
     396             :   // Specifically, `SimplifyCFGPass` and `InstCombinePass` are currently still
     397             :   // used. We have `LoopSimplifyCFGPass` which isn't yet powerful enough yet to
     398             :   // fully replace `SimplifyCFGPass`, and the closest to the other we have is
     399             :   // `LoopInstSimplify`.
     400             :   LoopPassManager LPM1(DebugLogging), LPM2(DebugLogging);
     401             : 
     402             :   // Simplify the loop body. We do this initially to clean up after other loop
     403             :   // passes run, either when iterating on a loop or on inner loops with
     404             :   // implications on the outer loop.
     405          66 :   LPM1.addPass(LoopInstSimplifyPass());
     406          66 :   LPM1.addPass(LoopSimplifyCFGPass());
     407             : 
     408             :   // Rotate Loop - disable header duplication at -Oz
     409          66 :   LPM1.addPass(LoopRotatePass(Level != Oz));
     410          66 :   LPM1.addPass(LICMPass());
     411          66 :   LPM1.addPass(SimpleLoopUnswitchPass());
     412          66 :   LPM2.addPass(IndVarSimplifyPass());
     413          66 :   LPM2.addPass(LoopIdiomRecognizePass());
     414             : 
     415          68 :   for (auto &C : LateLoopOptimizationsEPCallbacks)
     416             :     C(LPM2, Level);
     417             : 
     418          66 :   LPM2.addPass(LoopDeletionPass());
     419             :   // Do not enable unrolling in PreLinkThinLTO phase during sample PGO
     420             :   // because it changes IR to makes profile annotation in back compile
     421             :   // inaccurate.
     422          14 :   if (Phase != ThinLTOPhase::PreLink ||
     423          70 :       !PGOOpt || PGOOpt->SampleProfileFile.empty())
     424         126 :     LPM2.addPass(LoopFullUnrollPass(Level));
     425             : 
     426          68 :   for (auto &C : LoopOptimizerEndEPCallbacks)
     427             :     C(LPM2, Level);
     428             : 
     429             :   // We provide the opt remark emitter pass for LICM to use. We only need to do
     430             :   // this once as it is immutable.
     431          66 :   FPM.addPass(RequireAnalysisPass<OptimizationRemarkEmitterAnalysis, Function>());
     432         198 :   FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM1), DebugLogging));
     433          66 :   FPM.addPass(SimplifyCFGPass());
     434         132 :   FPM.addPass(InstCombinePass());
     435         198 :   FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM2), DebugLogging));
     436             : 
     437             :   // Eliminate redundancies.
     438          66 :   if (Level != O1) {
     439             :     // These passes add substantial compile time so skip them at O1.
     440          57 :     FPM.addPass(MergedLoadStoreMotionPass());
     441          57 :     if (RunNewGVN)
     442           0 :       FPM.addPass(NewGVNPass());
     443             :     else
     444          57 :       FPM.addPass(GVN());
     445             :   }
     446             : 
     447             :   // Specially optimize memory movement as it doesn't look like dataflow in SSA.
     448         132 :   FPM.addPass(MemCpyOptPass());
     449             : 
     450             :   // Sparse conditional constant propagation.
     451             :   // FIXME: It isn't clear why we do this *after* loop passes rather than
     452             :   // before...
     453          66 :   FPM.addPass(SCCPPass());
     454             : 
     455             :   // Delete dead bit computations (instcombine runs after to fold away the dead
     456             :   // computations, and then ADCE will run later to exploit any new DCE
     457             :   // opportunities that creates).
     458          66 :   FPM.addPass(BDCEPass());
     459             : 
     460             :   // Run instcombine after redundancy and dead bit elimination to exploit
     461             :   // opportunities opened up by them.
     462         132 :   FPM.addPass(InstCombinePass());
     463          66 :   invokePeepholeEPCallbacks(FPM, Level);
     464             : 
     465             :   // Re-consider control flow based optimizations after redundancy elimination,
     466             :   // redo DCE, etc.
     467          66 :   FPM.addPass(JumpThreadingPass());
     468          66 :   FPM.addPass(CorrelatedValuePropagationPass());
     469          66 :   FPM.addPass(DSEPass());
     470         132 :   FPM.addPass(createFunctionToLoopPassAdaptor(LICMPass(), DebugLogging));
     471             : 
     472          68 :   for (auto &C : ScalarOptimizerLateEPCallbacks)
     473             :     C(FPM, Level);
     474             : 
     475             :   // Finally, do an expensive DCE pass to catch all the dead code exposed by
     476             :   // the simplifications and basic cleanup after all the simplifications.
     477          66 :   FPM.addPass(ADCEPass());
     478          66 :   FPM.addPass(SimplifyCFGPass());
     479         132 :   FPM.addPass(InstCombinePass());
     480          66 :   invokePeepholeEPCallbacks(FPM, Level);
     481             : 
     482          66 :   return FPM;
     483             : }
     484             : 
     485           2 : void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM, bool DebugLogging,
     486             :                                     PassBuilder::OptimizationLevel Level,
     487             :                                     bool RunProfileGen,
     488             :                                     std::string ProfileGenFile,
     489             :                                     std::string ProfileUseFile) {
     490             :   // Generally running simplification passes and the inliner with an high
     491             :   // threshold results in smaller executables, but there may be cases where
     492             :   // the size grows, so let's be conservative here and skip this simplification
     493             :   // at -Os/Oz.
     494             :   if (!isOptimizingForSize(Level)) {
     495             :     InlineParams IP;
     496             : 
     497             :     // In the old pass manager, this is a cl::opt. Should still this be one?
     498           2 :     IP.DefaultThreshold = 75;
     499             : 
     500             :     // FIXME: The hint threshold has the same value used by the regular inliner.
     501             :     // This should probably be lowered after performance testing.
     502             :     // FIXME: this comment is cargo culted from the old pass manager, revisit).
     503             :     IP.HintThreshold = 325;
     504             : 
     505             :     CGSCCPassManager CGPipeline(DebugLogging);
     506             : 
     507           4 :     CGPipeline.addPass(InlinerPass(IP));
     508             : 
     509             :     FunctionPassManager FPM;
     510           2 :     FPM.addPass(SROA());
     511           2 :     FPM.addPass(EarlyCSEPass());    // Catch trivial redundancies.
     512           2 :     FPM.addPass(SimplifyCFGPass()); // Merge & remove basic blocks.
     513           4 :     FPM.addPass(InstCombinePass()); // Combine silly sequences.
     514           2 :     invokePeepholeEPCallbacks(FPM, Level);
     515             : 
     516           6 :     CGPipeline.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM)));
     517             : 
     518           6 :     MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPipeline)));
     519             :   }
     520             : 
     521             :   // Delete anything that is now dead to make sure that we don't instrument
     522             :   // dead code. Instrumentation can end up keeping dead code around and
     523             :   // dramatically increase code size.
     524           2 :   MPM.addPass(GlobalDCEPass());
     525             : 
     526           2 :   if (RunProfileGen) {
     527           1 :     MPM.addPass(PGOInstrumentationGen());
     528             : 
     529             :     FunctionPassManager FPM;
     530           1 :     FPM.addPass(
     531           2 :         createFunctionToLoopPassAdaptor(LoopRotatePass(), DebugLogging));
     532           3 :     MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
     533             : 
     534             :     // Add the profile lowering pass.
     535             :     InstrProfOptions Options;
     536           1 :     if (!ProfileGenFile.empty())
     537             :       Options.InstrProfileOutput = ProfileGenFile;
     538           1 :     Options.DoCounterPromotion = true;
     539           1 :     MPM.addPass(InstrProfiling(Options));
     540             :   }
     541             : 
     542           2 :   if (!ProfileUseFile.empty())
     543           3 :     MPM.addPass(PGOInstrumentationUse(ProfileUseFile));
     544           2 : }
     545             : 
     546             : static InlineParams
     547             : getInlineParamsFromOptLevel(PassBuilder::OptimizationLevel Level) {
     548             :   auto O3 = PassBuilder::O3;
     549          80 :   unsigned OptLevel = Level > O3 ? 2 : Level;
     550          80 :   unsigned SizeLevel = Level > O3 ? Level - O3 : 0;
     551          80 :   return getInlineParams(OptLevel, SizeLevel);
     552             : }
     553             : 
     554             : ModulePassManager
     555          66 : PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
     556             :                                                ThinLTOPhase Phase,
     557             :                                                bool DebugLogging) {
     558          66 :   ModulePassManager MPM(DebugLogging);
     559             : 
     560             :   // Do basic inference of function attributes from known properties of system
     561             :   // libraries and other oracles.
     562          66 :   MPM.addPass(InferFunctionAttrsPass());
     563             : 
     564             :   // Create an early function pass manager to cleanup the output of the
     565             :   // frontend.
     566             :   FunctionPassManager EarlyFPM(DebugLogging);
     567          66 :   EarlyFPM.addPass(SimplifyCFGPass());
     568          66 :   EarlyFPM.addPass(SROA());
     569          66 :   EarlyFPM.addPass(EarlyCSEPass());
     570          66 :   EarlyFPM.addPass(LowerExpectIntrinsicPass());
     571          66 :   if (Level == O3)
     572          18 :     EarlyFPM.addPass(CallSiteSplittingPass());
     573             : 
     574             :   // In SamplePGO ThinLTO backend, we need instcombine before profile annotation
     575             :   // to convert bitcast to direct calls so that they can be inlined during the
     576             :   // profile annotation prepration step.
     577             :   // More details about SamplePGO design can be found in:
     578             :   // https://research.google.com/pubs/pub45290.html
     579             :   // FIXME: revisit how SampleProfileLoad/Inliner/ICP is structured.
     580          78 :   if (PGOOpt && !PGOOpt->SampleProfileFile.empty() &&
     581             :       Phase == ThinLTOPhase::PostLink)
     582           4 :     EarlyFPM.addPass(InstCombinePass());
     583         198 :   MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM)));
     584             : 
     585          78 :   if (PGOOpt && !PGOOpt->SampleProfileFile.empty()) {
     586             :     // Annotate sample profile right after early FPM to ensure freshness of
     587             :     // the debug info.
     588          28 :     MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile,
     589             :                                         Phase == ThinLTOPhase::PreLink));
     590             :     // Do not invoke ICP in the ThinLTOPrelink phase as it makes it hard
     591             :     // for the profile annotation to be accurate in the ThinLTO backend.
     592           7 :     if (Phase != ThinLTOPhase::PreLink)
     593             :       // We perform early indirect call promotion here, before globalopt.
     594             :       // This is important for the ThinLTO backend phase because otherwise
     595             :       // imported available_externally functions look unreferenced and are
     596             :       // removed.
     597           8 :       MPM.addPass(PGOIndirectCallPromotion(Phase == ThinLTOPhase::PostLink,
     598             :                                            true));
     599             :   }
     600             : 
     601             :   // Interprocedural constant propagation now that basic cleanup has occurred
     602             :   // and prior to optimizing globals.
     603             :   // FIXME: This position in the pipeline hasn't been carefully considered in
     604             :   // years, it should be re-analyzed.
     605          66 :   MPM.addPass(IPSCCPPass());
     606             : 
     607             :   // Attach metadata to indirect call sites indicating the set of functions
     608             :   // they may target at run-time. This should follow IPSCCP.
     609          66 :   MPM.addPass(CalledValuePropagationPass());
     610             : 
     611             :   // Optimize globals to try and fold them into constants.
     612          66 :   MPM.addPass(GlobalOptPass());
     613             : 
     614             :   // Promote any localized globals to SSA registers.
     615             :   // FIXME: Should this instead by a run of SROA?
     616             :   // FIXME: We should probably run instcombine and simplify-cfg afterward to
     617             :   // delete control flows that are dead once globals have been folded to
     618             :   // constants.
     619          66 :   MPM.addPass(createModuleToFunctionPassAdaptor(PromotePass()));
     620             : 
     621             :   // Remove any dead arguments exposed by cleanups and constand folding
     622             :   // globals.
     623          66 :   MPM.addPass(DeadArgumentEliminationPass());
     624             : 
     625             :   // Create a small function pass pipeline to cleanup after all the global
     626             :   // optimizations.
     627             :   FunctionPassManager GlobalCleanupPM(DebugLogging);
     628         132 :   GlobalCleanupPM.addPass(InstCombinePass());
     629          66 :   invokePeepholeEPCallbacks(GlobalCleanupPM, Level);
     630             : 
     631          66 :   GlobalCleanupPM.addPass(SimplifyCFGPass());
     632         198 :   MPM.addPass(createModuleToFunctionPassAdaptor(std::move(GlobalCleanupPM)));
     633             : 
     634             :   // Add all the requested passes for instrumentation PGO, if requested.
     635          75 :   if (PGOOpt && Phase != ThinLTOPhase::PostLink &&
     636           8 :       (!PGOOpt->ProfileGenFile.empty() || !PGOOpt->ProfileUseFile.empty())) {
     637           6 :     addPGOInstrPasses(MPM, DebugLogging, Level, PGOOpt->RunProfileGen,
     638             :                       PGOOpt->ProfileGenFile, PGOOpt->ProfileUseFile);
     639           2 :     MPM.addPass(PGOIndirectCallPromotion(false, false));
     640             :   }
     641             : 
     642             :   // Synthesize function entry counts for non-PGO compilation.
     643          66 :   if (EnableSyntheticCounts && !PGOOpt)
     644           0 :     MPM.addPass(SyntheticCountsPropagation());
     645             : 
     646             :   // Require the GlobalsAA analysis for the module so we can query it within
     647             :   // the CGSCC pipeline.
     648          66 :   MPM.addPass(RequireAnalysisPass<GlobalsAA, Module>());
     649             : 
     650             :   // Require the ProfileSummaryAnalysis for the module so we can query it within
     651             :   // the inliner pass.
     652          66 :   MPM.addPass(RequireAnalysisPass<ProfileSummaryAnalysis, Module>());
     653             : 
     654             :   // Now begin the main postorder CGSCC pipeline.
     655             :   // FIXME: The current CGSCC pipeline has its origins in the legacy pass
     656             :   // manager and trying to emulate its precise behavior. Much of this doesn't
     657             :   // make a lot of sense and we should revisit the core CGSCC structure.
     658             :   CGSCCPassManager MainCGPipeline(DebugLogging);
     659             : 
     660             :   // Note: historically, the PruneEH pass was run first to deduce nounwind and
     661             :   // generally clean up exception handling overhead. It isn't clear this is
     662             :   // valuable as the inliner doesn't currently care whether it is inlining an
     663             :   // invoke or a call.
     664             : 
     665             :   // Run the inliner first. The theory is that we are walking bottom-up and so
     666             :   // the callees have already been fully optimized, and we want to inline them
     667             :   // into the callers so that our optimizations can reflect that.
     668             :   // For PreLinkThinLTO pass, we disable hot-caller heuristic for sample PGO
     669             :   // because it makes profile annotation in the backend inaccurate.
     670             :   InlineParams IP = getInlineParamsFromOptLevel(Level);
     671          14 :   if (Phase == ThinLTOPhase::PreLink &&
     672          70 :       PGOOpt && !PGOOpt->SampleProfileFile.empty())
     673             :     IP.HotCallSiteThreshold = 0;
     674         132 :   MainCGPipeline.addPass(InlinerPass(IP));
     675             : 
     676             :   // Now deduce any function attributes based in the current code.
     677          66 :   MainCGPipeline.addPass(PostOrderFunctionAttrsPass());
     678             : 
     679             :   // When at O3 add argument promotion to the pass pipeline.
     680             :   // FIXME: It isn't at all clear why this should be limited to O3.
     681          66 :   if (Level == O3)
     682          18 :     MainCGPipeline.addPass(ArgumentPromotionPass());
     683             : 
     684             :   // Lastly, add the core function simplification pipeline nested inside the
     685             :   // CGSCC walk.
     686         132 :   MainCGPipeline.addPass(createCGSCCToFunctionPassAdaptor(
     687         132 :       buildFunctionSimplificationPipeline(Level, Phase, DebugLogging)));
     688             : 
     689          68 :   for (auto &C : CGSCCOptimizerLateEPCallbacks)
     690             :     C(MainCGPipeline, Level);
     691             : 
     692             :   // We wrap the CGSCC pipeline in a devirtualization repeater. This will try
     693             :   // to detect when we devirtualize indirect calls and iterate the SCC passes
     694             :   // in that case to try and catch knock-on inlining or function attrs
     695             :   // opportunities. Then we add it to the module pipeline by walking the SCCs
     696             :   // in postorder (or bottom-up).
     697          66 :   MPM.addPass(
     698         330 :       createModuleToPostOrderCGSCCPassAdaptor(createDevirtSCCRepeatedPass(
     699             :           std::move(MainCGPipeline), MaxDevirtIterations)));
     700             : 
     701          66 :   return MPM;
     702             : }
     703             : 
     704             : ModulePassManager
     705          52 : PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
     706             :                                              bool DebugLogging) {
     707             :   ModulePassManager MPM(DebugLogging);
     708             : 
     709             :   // Optimize globals now that the module is fully simplified.
     710          52 :   MPM.addPass(GlobalOptPass());
     711          52 :   MPM.addPass(GlobalDCEPass());
     712             : 
     713             :   // Run partial inlining pass to partially inline functions that have
     714             :   // large bodies.
     715          52 :   if (RunPartialInlining)
     716           0 :     MPM.addPass(PartialInlinerPass());
     717             : 
     718             :   // Remove avail extern fns and globals definitions since we aren't compiling
     719             :   // an object file for later LTO. For LTO we want to preserve these so they
     720             :   // are eligible for inlining at link-time. Note if they are unreferenced they
     721             :   // will be removed by GlobalDCE later, so this only impacts referenced
     722             :   // available externally globals. Eventually they will be suppressed during
     723             :   // codegen, but eliminating here enables more opportunity for GlobalDCE as it
     724             :   // may make globals referenced by available external functions dead and saves
     725             :   // running remaining passes on the eliminated functions.
     726          52 :   MPM.addPass(EliminateAvailableExternallyPass());
     727             : 
     728             :   // Do RPO function attribute inference across the module to forward-propagate
     729             :   // attributes where applicable.
     730             :   // FIXME: Is this really an optimization rather than a canonicalization?
     731          52 :   MPM.addPass(ReversePostOrderFunctionAttrsPass());
     732             : 
     733             :   // Re-require GloblasAA here prior to function passes. This is particularly
     734             :   // useful as the above will have inlined, DCE'ed, and function-attr
     735             :   // propagated everything. We should at this point have a reasonably minimal
     736             :   // and richly annotated call graph. By computing aliasing and mod/ref
     737             :   // information for all local globals here, the late loop passes and notably
     738             :   // the vectorizer will be able to use them to help recognize vectorizable
     739             :   // memory operations.
     740          52 :   MPM.addPass(RequireAnalysisPass<GlobalsAA, Module>());
     741             : 
     742             :   FunctionPassManager OptimizePM(DebugLogging);
     743          52 :   OptimizePM.addPass(Float2IntPass());
     744             :   // FIXME: We need to run some loop optimizations to re-rotate loops after
     745             :   // simplify-cfg and others undo their rotation.
     746             : 
     747             :   // Optimize the loop execution. These passes operate on entire loop nests
     748             :   // rather than on each loop in an inside-out manner, and so they are actually
     749             :   // function passes.
     750             : 
     751         112 :   for (auto &C : VectorizerStartEPCallbacks)
     752             :     C(OptimizePM, Level);
     753             : 
     754             :   // First rotate loops that may have been un-rotated by prior passes.
     755          52 :   OptimizePM.addPass(
     756         104 :       createFunctionToLoopPassAdaptor(LoopRotatePass(), DebugLogging));
     757             : 
     758             :   // Distribute loops to allow partial vectorization.  I.e. isolate dependences
     759             :   // into separate loop that would otherwise inhibit vectorization.  This is
     760             :   // currently only performed for loops marked with the metadata
     761             :   // llvm.loop.distribute=true or when -enable-loop-distribute is specified.
     762          52 :   OptimizePM.addPass(LoopDistributePass());
     763             : 
     764             :   // Now run the core loop vectorizer.
     765          52 :   OptimizePM.addPass(LoopVectorizePass());
     766             : 
     767             :   // Eliminate loads by forwarding stores from the previous iteration to loads
     768             :   // of the current iteration.
     769          52 :   OptimizePM.addPass(LoopLoadEliminationPass());
     770             : 
     771             :   // Cleanup after the loop optimization passes.
     772         104 :   OptimizePM.addPass(InstCombinePass());
     773             : 
     774             :   // Now that we've formed fast to execute loop structures, we do further
     775             :   // optimizations. These are run afterward as they might block doing complex
     776             :   // analyses and transforms such as what are needed for loop vectorization.
     777             : 
     778             :   // Cleanup after loop vectorization, etc. Simplification passes like CVP and
     779             :   // GVN, loop transforms, and others have already run, so it's now better to
     780             :   // convert to more optimized IR using more aggressive simplify CFG options.
     781             :   // The extra sinking transform can create larger basic blocks, so do this
     782             :   // before SLP vectorization.
     783          52 :   OptimizePM.addPass(SimplifyCFGPass(SimplifyCFGOptions().
     784             :                                      forwardSwitchCondToPhi(true).
     785             :                                      convertSwitchToLookupTable(true).
     786             :                                      needCanonicalLoops(false).
     787             :                                      sinkCommonInsts(true)));
     788             : 
     789             :   // Optimize parallel scalar instruction chains into SIMD instructions.
     790          52 :   OptimizePM.addPass(SLPVectorizerPass());
     791             : 
     792         104 :   OptimizePM.addPass(InstCombinePass());
     793             : 
     794             :   // Unroll small loops to hide loop backedge latency and saturate any parallel
     795             :   // execution resources of an out-of-order processor. We also then need to
     796             :   // clean up redundancies and loop invariant code.
     797             :   // FIXME: It would be really good to use a loop-integrated instruction
     798             :   // combiner for cleanup here so that the unrolling and LICM can be pipelined
     799             :   // across the loop nests.
     800         104 :   OptimizePM.addPass(LoopUnrollPass(Level));
     801         104 :   OptimizePM.addPass(InstCombinePass());
     802          52 :   OptimizePM.addPass(RequireAnalysisPass<OptimizationRemarkEmitterAnalysis, Function>());
     803         104 :   OptimizePM.addPass(createFunctionToLoopPassAdaptor(LICMPass(), DebugLogging));
     804             : 
     805             :   // Now that we've vectorized and unrolled loops, we may have more refined
     806             :   // alignment information, try to re-derive it here.
     807          52 :   OptimizePM.addPass(AlignmentFromAssumptionsPass());
     808             : 
     809             :   // LoopSink pass sinks instructions hoisted by LICM, which serves as a
     810             :   // canonicalization pass that enables other optimizations. As a result,
     811             :   // LoopSink pass needs to be a very late IR pass to avoid undoing LICM
     812             :   // result too early.
     813          52 :   OptimizePM.addPass(LoopSinkPass());
     814             : 
     815             :   // And finally clean up LCSSA form before generating code.
     816          52 :   OptimizePM.addPass(InstSimplifierPass());
     817             : 
     818             :   // This hoists/decomposes div/rem ops. It should run after other sink/hoist
     819             :   // passes to avoid re-sinking, but before SimplifyCFG because it can allow
     820             :   // flattening of blocks.
     821          52 :   OptimizePM.addPass(DivRemPairsPass());
     822             : 
     823             :   // LoopSink (and other loop passes since the last simplifyCFG) might have
     824             :   // resulted in single-entry-single-exit or empty blocks. Clean up the CFG.
     825          52 :   OptimizePM.addPass(SimplifyCFGPass());
     826             : 
     827             :   // Optimize PHIs by speculating around them when profitable. Note that this
     828             :   // pass needs to be run after any PRE or similar pass as it is essentially
     829             :   // inserting redudnancies into the progrem. This even includes SimplifyCFG.
     830          52 :   OptimizePM.addPass(SpeculateAroundPHIsPass());
     831             : 
     832             :   // Add the core optimizing pipeline.
     833         156 :   MPM.addPass(createModuleToFunctionPassAdaptor(std::move(OptimizePM)));
     834             : 
     835             :   // Now we need to do some global optimization transforms.
     836             :   // FIXME: It would seem like these should come first in the optimization
     837             :   // pipeline and maybe be the bottom of the canonicalization pipeline? Weird
     838             :   // ordering here.
     839          52 :   MPM.addPass(GlobalDCEPass());
     840          52 :   MPM.addPass(ConstantMergePass());
     841             : 
     842          52 :   return MPM;
     843             : }
     844             : 
     845             : ModulePassManager
     846          37 : PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
     847             :                                            bool DebugLogging) {
     848             :   assert(Level != O0 && "Must request optimizations for the default pipeline!");
     849             : 
     850          37 :   ModulePassManager MPM(DebugLogging);
     851             : 
     852             :   // Force any function attributes we want the rest of the pipeline to observe.
     853          37 :   MPM.addPass(ForceFunctionAttrsPass());
     854             : 
     855             :   // Apply module pipeline start EP callback.
     856          43 :   for (auto &C : PipelineStartEPCallbacks)
     857             :     C(MPM);
     858             : 
     859          37 :   if (PGOOpt && PGOOpt->SamplePGOSupport)
     860           3 :     MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
     861             : 
     862             :   // Add the core simplification pipeline.
     863          74 :   MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::None,
     864             :                                                 DebugLogging));
     865             : 
     866             :   // Now add the optimization pipeline.
     867          74 :   MPM.addPass(buildModuleOptimizationPipeline(Level, DebugLogging));
     868             : 
     869          37 :   return MPM;
     870             : }
     871             : 
     872             : ModulePassManager
     873          14 : PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level,
     874             :                                                 bool DebugLogging) {
     875             :   assert(Level != O0 && "Must request optimizations for the default pipeline!");
     876             : 
     877          14 :   ModulePassManager MPM(DebugLogging);
     878             : 
     879             :   // Force any function attributes we want the rest of the pipeline to observe.
     880          14 :   MPM.addPass(ForceFunctionAttrsPass());
     881             : 
     882          14 :   if (PGOOpt && PGOOpt->SamplePGOSupport)
     883           4 :     MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
     884             : 
     885             :   // Apply module pipeline start EP callback.
     886          16 :   for (auto &C : PipelineStartEPCallbacks)
     887             :     C(MPM);
     888             : 
     889             :   // If we are planning to perform ThinLTO later, we don't bloat the code with
     890             :   // unrolling/vectorization/... now. Just simplify the module as much as we
     891             :   // can.
     892          28 :   MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::PreLink,
     893             :                                                 DebugLogging));
     894             : 
     895             :   // Run partial inlining pass to partially inline functions that have
     896             :   // large bodies.
     897             :   // FIXME: It isn't clear whether this is really the right place to run this
     898             :   // in ThinLTO. Because there is another canonicalization and simplification
     899             :   // phase that will run after the thin link, running this here ends up with
     900             :   // less information than will be available later and it may grow functions in
     901             :   // ways that aren't beneficial.
     902          14 :   if (RunPartialInlining)
     903           0 :     MPM.addPass(PartialInlinerPass());
     904             : 
     905             :   // Reduce the size of the IR as much as possible.
     906          14 :   MPM.addPass(GlobalOptPass());
     907             : 
     908          14 :   return MPM;
     909             : }
     910             : 
     911             : ModulePassManager
     912          15 : PassBuilder::buildThinLTODefaultPipeline(OptimizationLevel Level,
     913             :                                          bool DebugLogging) {
     914             :   // FIXME: The summary index is not hooked in the new pass manager yet.
     915             :   // When it's going to be hooked, enable WholeProgramDevirt and LowerTypeTest
     916             :   // here.
     917             : 
     918          15 :   ModulePassManager MPM(DebugLogging);
     919             : 
     920             :   // Force any function attributes we want the rest of the pipeline to observe.
     921          15 :   MPM.addPass(ForceFunctionAttrsPass());
     922             : 
     923             :   // During the ThinLTO backend phase we perform early indirect call promotion
     924             :   // here, before globalopt. Otherwise imported available_externally functions
     925             :   // look unreferenced and are removed.
     926             :   // FIXME: move this into buildModuleSimplificationPipeline to merge the logic
     927             :   //        with SamplePGO.
     928          18 :   if (!PGOOpt || PGOOpt->SampleProfileFile.empty())
     929          13 :     MPM.addPass(PGOIndirectCallPromotion(true /* InLTO */,
     930             :                                          false /* SamplePGO */));
     931             : 
     932             :   // Add the core simplification pipeline.
     933          30 :   MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::PostLink,
     934             :                                                 DebugLogging));
     935             : 
     936             :   // Now add the optimization pipeline.
     937          30 :   MPM.addPass(buildModuleOptimizationPipeline(Level, DebugLogging));
     938             : 
     939          15 :   return MPM;
     940             : }
     941             : 
     942             : ModulePassManager
     943           7 : PassBuilder::buildLTOPreLinkDefaultPipeline(OptimizationLevel Level,
     944             :                                             bool DebugLogging) {
     945             :   assert(Level != O0 && "Must request optimizations for the default pipeline!");
     946             :   // FIXME: We should use a customized pre-link pipeline!
     947           7 :   return buildPerModuleDefaultPipeline(Level, DebugLogging);
     948             : }
     949             : 
     950          15 : ModulePassManager PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
     951             :                                                        bool DebugLogging) {
     952             :   assert(Level != O0 && "Must request optimizations for the default pipeline!");
     953             :   ModulePassManager MPM(DebugLogging);
     954             : 
     955             :   // Remove unused virtual tables to improve the quality of code generated by
     956             :   // whole-program devirtualization and bitset lowering.
     957          15 :   MPM.addPass(GlobalDCEPass());
     958             : 
     959             :   // Force any function attributes we want the rest of the pipeline to observe.
     960          15 :   MPM.addPass(ForceFunctionAttrsPass());
     961             : 
     962             :   // Do basic inference of function attributes from known properties of system
     963             :   // libraries and other oracles.
     964          15 :   MPM.addPass(InferFunctionAttrsPass());
     965             : 
     966          15 :   if (Level > 1) {
     967             :     FunctionPassManager EarlyFPM(DebugLogging);
     968          14 :     EarlyFPM.addPass(CallSiteSplittingPass());
     969          42 :     MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM)));
     970             : 
     971             :     // Indirect call promotion. This should promote all the targets that are
     972             :     // left by the earlier promotion pass that promotes intra-module targets.
     973             :     // This two-step promotion is to save the compile time. For LTO, it should
     974             :     // produce the same result as if we only do promotion here.
     975          14 :     MPM.addPass(PGOIndirectCallPromotion(
     976          15 :         true /* InLTO */, PGOOpt && !PGOOpt->SampleProfileFile.empty()));
     977             :     // Propagate constants at call sites into the functions they call.  This
     978             :     // opens opportunities for globalopt (and inlining) by substituting function
     979             :     // pointers passed as arguments to direct uses of functions.
     980          14 :    MPM.addPass(IPSCCPPass());
     981             : 
     982             :    // Attach metadata to indirect call sites indicating the set of functions
     983             :    // they may target at run-time. This should follow IPSCCP.
     984          14 :    MPM.addPass(CalledValuePropagationPass());
     985             :   }
     986             : 
     987             :   // Now deduce any function attributes based in the current code.
     988          15 :   MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(
     989             :               PostOrderFunctionAttrsPass()));
     990             : 
     991             :   // Do RPO function attribute inference across the module to forward-propagate
     992             :   // attributes where applicable.
     993             :   // FIXME: Is this really an optimization rather than a canonicalization?
     994          15 :   MPM.addPass(ReversePostOrderFunctionAttrsPass());
     995             : 
     996             :   // Use inragne annotations on GEP indices to split globals where beneficial.
     997          15 :   MPM.addPass(GlobalSplitPass());
     998             : 
     999             :   // Run whole program optimization of virtual call when the list of callees
    1000             :   // is fixed.
    1001          15 :   MPM.addPass(WholeProgramDevirtPass());
    1002             : 
    1003             :   // Stop here at -O1.
    1004          15 :   if (Level == 1)
    1005             :     return MPM;
    1006             : 
    1007             :   // Optimize globals to try and fold them into constants.
    1008          14 :   MPM.addPass(GlobalOptPass());
    1009             : 
    1010             :   // Promote any localized globals to SSA registers.
    1011          14 :   MPM.addPass(createModuleToFunctionPassAdaptor(PromotePass()));
    1012             : 
    1013             :   // Linking modules together can lead to duplicate global constant, only
    1014             :   // keep one copy of each constant.
    1015          14 :   MPM.addPass(ConstantMergePass());
    1016             : 
    1017             :   // Remove unused arguments from functions.
    1018          14 :   MPM.addPass(DeadArgumentEliminationPass());
    1019             : 
    1020             :   // Reduce the code after globalopt and ipsccp.  Both can open up significant
    1021             :   // simplification opportunities, and both can propagate functions through
    1022             :   // function pointers.  When this happens, we often have to resolve varargs
    1023             :   // calls, etc, so let instcombine do this.
    1024             :   FunctionPassManager PeepholeFPM(DebugLogging);
    1025          14 :   if (Level == O3)
    1026           2 :     PeepholeFPM.addPass(AggressiveInstCombinePass());
    1027          28 :   PeepholeFPM.addPass(InstCombinePass());
    1028          14 :   invokePeepholeEPCallbacks(PeepholeFPM, Level);
    1029             : 
    1030          42 :   MPM.addPass(createModuleToFunctionPassAdaptor(std::move(PeepholeFPM)));
    1031             : 
    1032             :   // Note: historically, the PruneEH pass was run first to deduce nounwind and
    1033             :   // generally clean up exception handling overhead. It isn't clear this is
    1034             :   // valuable as the inliner doesn't currently care whether it is inlining an
    1035             :   // invoke or a call.
    1036             :   // Run the inliner now.
    1037          14 :   MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(
    1038          14 :       InlinerPass(getInlineParamsFromOptLevel(Level))));
    1039             : 
    1040             :   // Optimize globals again after we ran the inliner.
    1041          14 :   MPM.addPass(GlobalOptPass());
    1042             : 
    1043             :   // Garbage collect dead functions.
    1044             :   // FIXME: Add ArgumentPromotion pass after once it's ported.
    1045          14 :   MPM.addPass(GlobalDCEPass());
    1046             : 
    1047             :   FunctionPassManager FPM(DebugLogging);
    1048             :   // The IPO Passes may leave cruft around. Clean up after them.
    1049          28 :   FPM.addPass(InstCombinePass());
    1050          14 :   invokePeepholeEPCallbacks(FPM, Level);
    1051             : 
    1052          14 :   FPM.addPass(JumpThreadingPass());
    1053             : 
    1054             :   // Break up allocas
    1055          14 :   FPM.addPass(SROA());
    1056             : 
    1057             :   // Run a few AA driver optimizations here and now to cleanup the code.
    1058          42 :   MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
    1059             : 
    1060          14 :   MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(
    1061             :               PostOrderFunctionAttrsPass()));
    1062             :   // FIXME: here we run IP alias analysis in the legacy PM.
    1063             : 
    1064             :   FunctionPassManager MainFPM;
    1065             : 
    1066             :   // FIXME: once we fix LoopPass Manager, add LICM here.
    1067             :   // FIXME: once we provide support for enabling MLSM, add it here.
    1068             :   // FIXME: once we provide support for enabling NewGVN, add it here.
    1069          14 :   if (RunNewGVN)
    1070           0 :     MainFPM.addPass(NewGVNPass());
    1071             :   else
    1072          14 :     MainFPM.addPass(GVN());
    1073             : 
    1074             :   // Remove dead memcpy()'s.
    1075          28 :   MainFPM.addPass(MemCpyOptPass());
    1076             : 
    1077             :   // Nuke dead stores.
    1078          14 :   MainFPM.addPass(DSEPass());
    1079             : 
    1080             :   // FIXME: at this point, we run a bunch of loop passes:
    1081             :   // indVarSimplify, loopDeletion, loopInterchange, loopUnrool,
    1082             :   // loopVectorize. Enable them once the remaining issue with LPM
    1083             :   // are sorted out.
    1084             : 
    1085          28 :   MainFPM.addPass(InstCombinePass());
    1086          14 :   MainFPM.addPass(SimplifyCFGPass());
    1087          14 :   MainFPM.addPass(SCCPPass());
    1088          28 :   MainFPM.addPass(InstCombinePass());
    1089          14 :   MainFPM.addPass(BDCEPass());
    1090             : 
    1091             :   // FIXME: We may want to run SLPVectorizer here.
    1092             :   // After vectorization, assume intrinsics may tell us more
    1093             :   // about pointer alignments.
    1094             : #if 0
    1095             :   MainFPM.add(AlignmentFromAssumptionsPass());
    1096             : #endif
    1097             : 
    1098             :   // FIXME: Conditionally run LoadCombine here, after it's ported
    1099             :   // (in case we still have this pass, given its questionable usefulness).
    1100             : 
    1101          28 :   MainFPM.addPass(InstCombinePass());
    1102          14 :   invokePeepholeEPCallbacks(MainFPM, Level);
    1103          14 :   MainFPM.addPass(JumpThreadingPass());
    1104          42 :   MPM.addPass(createModuleToFunctionPassAdaptor(std::move(MainFPM)));
    1105             : 
    1106             :   // Create a function that performs CFI checks for cross-DSO calls with
    1107             :   // targets in the current module.
    1108          14 :   MPM.addPass(CrossDSOCFIPass());
    1109             : 
    1110             :   // Lower type metadata and the type.test intrinsic. This pass supports
    1111             :   // clang's control flow integrity mechanisms (-fsanitize=cfi*) and needs
    1112             :   // to be run at link time if CFI is enabled. This pass does nothing if
    1113             :   // CFI is disabled.
    1114             :   // Enable once we add support for the summary in the new PM.
    1115             : #if 0
    1116             :   MPM.addPass(LowerTypeTestsPass(Summary ? PassSummaryAction::Export :
    1117             :                                            PassSummaryAction::None,
    1118             :                                 Summary));
    1119             : #endif
    1120             : 
    1121             :   // Add late LTO optimization passes.
    1122             :   // Delete basic blocks, which optimization passes may have killed.
    1123          14 :   MPM.addPass(createModuleToFunctionPassAdaptor(SimplifyCFGPass()));
    1124             : 
    1125             :   // Drop bodies of available eternally objects to improve GlobalDCE.
    1126          14 :   MPM.addPass(EliminateAvailableExternallyPass());
    1127             : 
    1128             :   // Now that we have optimized the program, discard unreachable functions.
    1129          14 :   MPM.addPass(GlobalDCEPass());
    1130             : 
    1131             :   // FIXME: Enable MergeFuncs, conditionally, after ported, maybe.
    1132             :   return MPM;
    1133             : }
    1134             : 
    1135          59 : AAManager PassBuilder::buildDefaultAAPipeline() {
    1136             :   AAManager AA;
    1137             : 
    1138             :   // The order in which these are registered determines their priority when
    1139             :   // being queried.
    1140             : 
    1141             :   // First we register the basic alias analysis that provides the majority of
    1142             :   // per-function local AA logic. This is a stateless, on-demand local set of
    1143             :   // AA techniques.
    1144             :   AA.registerFunctionAnalysis<BasicAA>();
    1145             : 
    1146             :   // Next we query fast, specialized alias analyses that wrap IR-embedded
    1147             :   // information about aliasing.
    1148             :   AA.registerFunctionAnalysis<ScopedNoAliasAA>();
    1149             :   AA.registerFunctionAnalysis<TypeBasedAA>();
    1150             : 
    1151             :   // Add support for querying global aliasing information when available.
    1152             :   // Because the `AAManager` is a function analysis and `GlobalsAA` is a module
    1153             :   // analysis, all that the `AAManager` can do is query for any *cached*
    1154             :   // results from `GlobalsAA` through a readonly proxy.
    1155             :   AA.registerModuleAnalysis<GlobalsAA>();
    1156             : 
    1157          59 :   return AA;
    1158             : }
    1159             : 
    1160        1629 : static Optional<int> parseRepeatPassName(StringRef Name) {
    1161             :   if (!Name.consume_front("repeat<") || !Name.consume_back(">"))
    1162             :     return None;
    1163             :   int Count;
    1164           5 :   if (Name.getAsInteger(0, Count) || Count <= 0)
    1165             :     return None;
    1166             :   return Count;
    1167             : }
    1168             : 
    1169         467 : static Optional<int> parseDevirtPassName(StringRef Name) {
    1170             :   if (!Name.consume_front("devirt<") || !Name.consume_back(">"))
    1171             :     return None;
    1172             :   int Count;
    1173           3 :   if (Name.getAsInteger(0, Count) || Count <= 0)
    1174             :     return None;
    1175             :   return Count;
    1176             : }
    1177             : 
    1178             : /// Tests whether a pass name starts with a valid prefix for a default pipeline
    1179             : /// alias.
    1180        1261 : static bool startsWithDefaultPipelineAliasPrefix(StringRef Name) {
    1181             :   return Name.startswith("default") || Name.startswith("thinlto") ||
    1182        1261 :          Name.startswith("lto");
    1183             : }
    1184             : 
    1185             : /// Tests whether registered callbacks will accept a given pass name.
    1186             : ///
    1187             : /// When parsing a pipeline text, the type of the outermost pipeline may be
    1188             : /// omitted, in which case the type is automatically determined from the first
    1189             : /// pass name in the text. This may be a name that is handled through one of the
    1190             : /// callbacks. We check this through the oridinary parsing callbacks by setting
    1191             : /// up a dummy PassManager in order to not force the client to also handle this
    1192             : /// type of query.
    1193             : template <typename PassManagerT, typename CallbacksT>
    1194         902 : static bool callbacksAcceptPassName(StringRef Name, CallbacksT &Callbacks) {
    1195         902 :   if (!Callbacks.empty()) {
    1196             :     PassManagerT DummyPM;
    1197        1405 :     for (auto &CB : Callbacks)
    1198         482 :       if (CB(Name, DummyPM, {}))
    1199             :         return true;
    1200             :   }
    1201             :   return false;
    1202             : }
    1203             : 
    1204             : template <typename CallbacksT>
    1205         898 : static bool isModulePassName(StringRef Name, CallbacksT &Callbacks) {
    1206             :   // Manually handle aliases for pre-configured pipeline fragments.
    1207         898 :   if (startsWithDefaultPipelineAliasPrefix(Name))
    1208          44 :     return DefaultAliasRegex.match(Name);
    1209             : 
    1210             :   // Explicitly handle pass manager names.
    1211             :   if (Name == "module")
    1212             :     return true;
    1213             :   if (Name == "cgscc")
    1214             :     return true;
    1215             :   if (Name == "function")
    1216             :     return true;
    1217             : 
    1218             :   // Explicitly handle custom-parsed pass names.
    1219         731 :   if (parseRepeatPassName(Name))
    1220             :     return true;
    1221             : 
    1222             : #define MODULE_PASS(NAME, CREATE_PASS)                                         \
    1223             :   if (Name == NAME)                                                            \
    1224             :     return true;
    1225             : #define MODULE_ANALYSIS(NAME, CREATE_PASS)                                     \
    1226             :   if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">")           \
    1227             :     return true;
    1228             : #include "PassRegistry.def"
    1229             : 
    1230         467 :   return callbacksAcceptPassName<ModulePassManager>(Name, Callbacks);
    1231             : }
    1232             : 
    1233             : template <typename CallbacksT>
    1234         463 : static bool isCGSCCPassName(StringRef Name, CallbacksT &Callbacks) {
    1235             :   // Explicitly handle pass manager names.
    1236             :   if (Name == "cgscc")
    1237             :     return true;
    1238             :   if (Name == "function")
    1239             :     return true;
    1240             : 
    1241             :   // Explicitly handle custom-parsed pass names.
    1242         463 :   if (parseRepeatPassName(Name))
    1243             :     return true;
    1244         463 :   if (parseDevirtPassName(Name))
    1245             :     return true;
    1246             : 
    1247             : #define CGSCC_PASS(NAME, CREATE_PASS)                                          \
    1248             :   if (Name == NAME)                                                            \
    1249             :     return true;
    1250             : #define CGSCC_ANALYSIS(NAME, CREATE_PASS)                                      \
    1251             :   if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">")           \
    1252             :     return true;
    1253             : #include "PassRegistry.def"
    1254             : 
    1255         402 :   return callbacksAcceptPassName<CGSCCPassManager>(Name, Callbacks);
    1256             : }
    1257             : 
    1258             : template <typename CallbacksT>
    1259         413 : static bool isFunctionPassName(StringRef Name, CallbacksT &Callbacks) {
    1260             :   // Explicitly handle pass manager names.
    1261             :   if (Name == "function")
    1262             :     return true;
    1263             :   if (Name == "loop")
    1264             :     return true;
    1265             : 
    1266             :   // Explicitly handle custom-parsed pass names.
    1267         400 :   if (parseRepeatPassName(Name))
    1268             :     return true;
    1269             : 
    1270             : #define FUNCTION_PASS(NAME, CREATE_PASS)                                       \
    1271             :   if (Name == NAME)                                                            \
    1272             :     return true;
    1273             : #define FUNCTION_ANALYSIS(NAME, CREATE_PASS)                                   \
    1274             :   if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">")           \
    1275             :     return true;
    1276             : #include "PassRegistry.def"
    1277             : 
    1278          25 :   return callbacksAcceptPassName<FunctionPassManager>(Name, Callbacks);
    1279             : }
    1280             : 
    1281             : template <typename CallbacksT>
    1282          21 : static bool isLoopPassName(StringRef Name, CallbacksT &Callbacks) {
    1283             :   // Explicitly handle pass manager names.
    1284             :   if (Name == "loop")
    1285             :     return true;
    1286             : 
    1287             :   // Explicitly handle custom-parsed pass names.
    1288          21 :   if (parseRepeatPassName(Name))
    1289             :     return true;
    1290             : 
    1291             : #define LOOP_PASS(NAME, CREATE_PASS)                                           \
    1292             :   if (Name == NAME)                                                            \
    1293             :     return true;
    1294             : #define LOOP_ANALYSIS(NAME, CREATE_PASS)                                       \
    1295             :   if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">")           \
    1296             :     return true;
    1297             : #include "PassRegistry.def"
    1298             : 
    1299           8 :   return callbacksAcceptPassName<LoopPassManager>(Name, Callbacks);
    1300             : }
    1301             : 
    1302             : Optional<std::vector<PassBuilder::PipelineElement>>
    1303         928 : PassBuilder::parsePipelineText(StringRef Text) {
    1304         928 :   std::vector<PipelineElement> ResultPipeline;
    1305             : 
    1306             :   SmallVector<std::vector<PipelineElement> *, 4> PipelineStack = {
    1307        1856 :       &ResultPipeline};
    1308             :   for (;;) {
    1309        1763 :     std::vector<PipelineElement> &Pipeline = *PipelineStack.back();
    1310        1763 :     size_t Pos = Text.find_first_of(",()");
    1311        3526 :     Pipeline.push_back({Text.substr(0, Pos), {}});
    1312             : 
    1313             :     // If we have a single terminating name, we're done.
    1314        1763 :     if (Pos == Text.npos)
    1315             :       break;
    1316             : 
    1317        1113 :     char Sep = Text[Pos];
    1318        2226 :     Text = Text.substr(Pos + 1);
    1319        1113 :     if (Sep == ',')
    1320             :       // Just a name ending in a comma, continue.
    1321         434 :       continue;
    1322             : 
    1323        1032 :     if (Sep == '(') {
    1324             :       // Push the inner pipeline onto the stack to continue processing.
    1325         353 :       PipelineStack.push_back(&Pipeline.back().InnerPipeline);
    1326         353 :       continue;
    1327             :     }
    1328             : 
    1329             :     assert(Sep == ')' && "Bogus separator!");
    1330             :     // When handling the close parenthesis, we greedily consume them to avoid
    1331             :     // empty strings in the pipeline.
    1332             :     do {
    1333             :       // If we try to pop the outer pipeline we have unbalanced parentheses.
    1334         357 :       if (PipelineStack.size() == 1)
    1335             :         return None;
    1336             : 
    1337             :       PipelineStack.pop_back();
    1338             :     } while (Text.consume_front(")"));
    1339             : 
    1340             :     // Check if we've finished parsing.
    1341         319 :     if (Text.empty())
    1342             :       break;
    1343             : 
    1344             :     // Otherwise, the end of an inner pipeline always has to be followed by
    1345             :     // a comma, and then we can continue.
    1346             :     if (!Text.consume_front(","))
    1347             :       return None;
    1348             :   }
    1349             : 
    1350         920 :   if (PipelineStack.size() > 1)
    1351             :     // Unbalanced paretheses.
    1352             :     return None;
    1353             : 
    1354             :   assert(PipelineStack.back() == &ResultPipeline &&
    1355             :          "Wrong pipeline at the bottom of the stack!");
    1356             :   return {std::move(ResultPipeline)};
    1357             : }
    1358             : 
    1359         987 : bool PassBuilder::parseModulePass(ModulePassManager &MPM,
    1360             :                                   const PipelineElement &E, bool VerifyEachPass,
    1361             :                                   bool DebugLogging) {
    1362         987 :   auto &Name = E.Name;
    1363             :   auto &InnerPipeline = E.InnerPipeline;
    1364             : 
    1365             :   // First handle complex passes like the pass managers which carry pipelines.
    1366         987 :   if (!InnerPipeline.empty()) {
    1367             :     if (Name == "module") {
    1368           8 :       ModulePassManager NestedMPM(DebugLogging);
    1369          16 :       if (!parseModulePassPipeline(NestedMPM, InnerPipeline, VerifyEachPass,
    1370             :                                    DebugLogging))
    1371             :         return false;
    1372          16 :       MPM.addPass(std::move(NestedMPM));
    1373           8 :       return true;
    1374             :     }
    1375             :     if (Name == "cgscc") {
    1376         169 :       CGSCCPassManager CGPM(DebugLogging);
    1377         338 :       if (!parseCGSCCPassPipeline(CGPM, InnerPipeline, VerifyEachPass,
    1378             :                                   DebugLogging))
    1379             :         return false;
    1380         504 :       MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM)));
    1381         168 :       return true;
    1382             :     }
    1383             :     if (Name == "function") {
    1384         445 :       FunctionPassManager FPM(DebugLogging);
    1385         890 :       if (!parseFunctionPassPipeline(FPM, InnerPipeline, VerifyEachPass,
    1386             :                                      DebugLogging))
    1387             :         return false;
    1388        1323 :       MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
    1389         441 :       return true;
    1390             :     }
    1391           2 :     if (auto Count = parseRepeatPassName(Name)) {
    1392           1 :       ModulePassManager NestedMPM(DebugLogging);
    1393           2 :       if (!parseModulePassPipeline(NestedMPM, InnerPipeline, VerifyEachPass,
    1394             :                                    DebugLogging))
    1395             :         return false;
    1396           4 :       MPM.addPass(createRepeatedPass(*Count, std::move(NestedMPM)));
    1397           1 :       return true;
    1398             :     }
    1399             : 
    1400           3 :     for (auto &C : ModulePipelineParsingCallbacks)
    1401           1 :       if (C(Name, MPM, InnerPipeline))
    1402             :         return true;
    1403             : 
    1404             :     // Normal passes can't have pipelines.
    1405             :     return false;
    1406             :   }
    1407             : 
    1408             :   // Manually handle aliases for pre-configured pipeline fragments.
    1409         363 :   if (startsWithDefaultPipelineAliasPrefix(Name)) {
    1410             :     SmallVector<StringRef, 3> Matches;
    1411          44 :     if (!DefaultAliasRegex.match(Name, &Matches))
    1412             :       return false;
    1413             :     assert(Matches.size() == 3 && "Must capture two matched strings!");
    1414             : 
    1415          44 :     OptimizationLevel L = StringSwitch<OptimizationLevel>(Matches[2])
    1416             :                               .Case("O0", O0)
    1417             :                               .Case("O1", O1)
    1418             :                               .Case("O2", O2)
    1419             :                               .Case("O3", O3)
    1420             :                               .Case("Os", Os)
    1421             :                               .Case("Oz", Oz);
    1422          44 :     if (L == O0)
    1423             :       // At O0 we do nothing at all!
    1424             :       return true;
    1425             : 
    1426             :     if (Matches[1] == "default") {
    1427          40 :       MPM.addPass(buildPerModuleDefaultPipeline(L, DebugLogging));
    1428             :     } else if (Matches[1] == "thinlto-pre-link") {
    1429          16 :       MPM.addPass(buildThinLTOPreLinkDefaultPipeline(L, DebugLogging));
    1430             :     } else if (Matches[1] == "thinlto") {
    1431          14 :       MPM.addPass(buildThinLTODefaultPipeline(L, DebugLogging));
    1432             :     } else if (Matches[1] == "lto-pre-link") {
    1433           4 :       MPM.addPass(buildLTOPreLinkDefaultPipeline(L, DebugLogging));
    1434             :     } else {
    1435             :       assert(Matches[1] == "lto" && "Not one of the matched options!");
    1436          12 :       MPM.addPass(buildLTODefaultPipeline(L, DebugLogging));
    1437             :     }
    1438             :     return true;
    1439             :   }
    1440             : 
    1441             :   // Finally expand the basic registered passes from the .inc file.
    1442             : #define MODULE_PASS(NAME, CREATE_PASS)                                         \
    1443             :   if (Name == NAME) {                                                          \
    1444             :     MPM.addPass(CREATE_PASS);                                                  \
    1445             :     return true;                                                               \
    1446             :   }
    1447             : #define MODULE_ANALYSIS(NAME, CREATE_PASS)                                     \
    1448             :   if (Name == "require<" NAME ">") {                                           \
    1449             :     MPM.addPass(                                                               \
    1450             :         RequireAnalysisPass<                                                   \
    1451             :             std::remove_reference<decltype(CREATE_PASS)>::type, Module>());    \
    1452             :     return true;                                                               \
    1453             :   }                                                                            \
    1454             :   if (Name == "invalidate<" NAME ">") {                                        \
    1455             :     MPM.addPass(InvalidateAnalysisPass<                                        \
    1456             :                 std::remove_reference<decltype(CREATE_PASS)>::type>());        \
    1457             :     return true;                                                               \
    1458             :   }
    1459             : #include "PassRegistry.def"
    1460             : 
    1461          10 :   for (auto &C : ModulePipelineParsingCallbacks)
    1462          10 :     if (C(Name, MPM, InnerPipeline))
    1463             :       return true;
    1464             :   return false;
    1465             : }
    1466             : 
    1467         216 : bool PassBuilder::parseCGSCCPass(CGSCCPassManager &CGPM,
    1468             :                                  const PipelineElement &E, bool VerifyEachPass,
    1469             :                                  bool DebugLogging) {
    1470         216 :   auto &Name = E.Name;
    1471             :   auto &InnerPipeline = E.InnerPipeline;
    1472             : 
    1473             :   // First handle complex passes like the pass managers which carry pipelines.
    1474         216 :   if (!InnerPipeline.empty()) {
    1475             :     if (Name == "cgscc") {
    1476           0 :       CGSCCPassManager NestedCGPM(DebugLogging);
    1477           0 :       if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass,
    1478             :                                   DebugLogging))
    1479             :         return false;
    1480             :       // Add the nested pass manager with the appropriate adaptor.
    1481           0 :       CGPM.addPass(std::move(NestedCGPM));
    1482           0 :       return true;
    1483             :     }
    1484             :     if (Name == "function") {
    1485          30 :       FunctionPassManager FPM(DebugLogging);
    1486          60 :       if (!parseFunctionPassPipeline(FPM, InnerPipeline, VerifyEachPass,
    1487             :                                      DebugLogging))
    1488             :         return false;
    1489             :       // Add the nested pass manager with the appropriate adaptor.
    1490          90 :       CGPM.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM)));
    1491          30 :       return true;
    1492             :     }
    1493           5 :     if (auto Count = parseRepeatPassName(Name)) {
    1494           1 :       CGSCCPassManager NestedCGPM(DebugLogging);
    1495           2 :       if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass,
    1496             :                                   DebugLogging))
    1497             :         return false;
    1498           4 :       CGPM.addPass(createRepeatedPass(*Count, std::move(NestedCGPM)));
    1499           1 :       return true;
    1500             :     }
    1501           4 :     if (auto MaxRepetitions = parseDevirtPassName(Name)) {
    1502           3 :       CGSCCPassManager NestedCGPM(DebugLogging);
    1503           6 :       if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass,
    1504             :                                   DebugLogging))
    1505             :         return false;
    1506           3 :       CGPM.addPass(
    1507           9 :           createDevirtSCCRepeatedPass(std::move(NestedCGPM), *MaxRepetitions));
    1508           3 :       return true;
    1509             :     }
    1510             : 
    1511           1 :     for (auto &C : CGSCCPipelineParsingCallbacks)
    1512           0 :       if (C(Name, CGPM, InnerPipeline))
    1513             :         return true;
    1514             : 
    1515             :     // Normal passes can't have pipelines.
    1516             :     return false;
    1517             :   }
    1518             : 
    1519             : // Now expand the basic registered passes from the .inc file.
    1520             : #define CGSCC_PASS(NAME, CREATE_PASS)                                          \
    1521             :   if (Name == NAME) {                                                          \
    1522             :     CGPM.addPass(CREATE_PASS);                                                 \
    1523             :     return true;                                                               \
    1524             :   }
    1525             : #define CGSCC_ANALYSIS(NAME, CREATE_PASS)                                      \
    1526             :   if (Name == "require<" NAME ">") {                                           \
    1527             :     CGPM.addPass(RequireAnalysisPass<                                          \
    1528             :                  std::remove_reference<decltype(CREATE_PASS)>::type,           \
    1529             :                  LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &,    \
    1530             :                  CGSCCUpdateResult &>());                                      \
    1531             :     return true;                                                               \
    1532             :   }                                                                            \
    1533             :   if (Name == "invalidate<" NAME ">") {                                        \
    1534             :     CGPM.addPass(InvalidateAnalysisPass<                                       \
    1535             :                  std::remove_reference<decltype(CREATE_PASS)>::type>());       \
    1536             :     return true;                                                               \
    1537             :   }
    1538             : #include "PassRegistry.def"
    1539             : 
    1540           3 :   for (auto &C : CGSCCPipelineParsingCallbacks)
    1541           3 :     if (C(Name, CGPM, InnerPipeline))
    1542             :       return true;
    1543             :   return false;
    1544             : }
    1545             : 
    1546         827 : bool PassBuilder::parseFunctionPass(FunctionPassManager &FPM,
    1547             :                                     const PipelineElement &E,
    1548             :                                     bool VerifyEachPass, bool DebugLogging) {
    1549         827 :   auto &Name = E.Name;
    1550             :   auto &InnerPipeline = E.InnerPipeline;
    1551             : 
    1552             :   // First handle complex passes like the pass managers which carry pipelines.
    1553         827 :   if (!InnerPipeline.empty()) {
    1554             :     if (Name == "function") {
    1555           1 :       FunctionPassManager NestedFPM(DebugLogging);
    1556           2 :       if (!parseFunctionPassPipeline(NestedFPM, InnerPipeline, VerifyEachPass,
    1557             :                                      DebugLogging))
    1558             :         return false;
    1559             :       // Add the nested pass manager with the appropriate adaptor.
    1560           2 :       FPM.addPass(std::move(NestedFPM));
    1561           1 :       return true;
    1562             :     }
    1563             :     if (Name == "loop") {
    1564         145 :       LoopPassManager LPM(DebugLogging);
    1565         290 :       if (!parseLoopPassPipeline(LPM, InnerPipeline, VerifyEachPass,
    1566             :                                  DebugLogging))
    1567             :         return false;
    1568             :       // Add the nested pass manager with the appropriate adaptor.
    1569         144 :       FPM.addPass(
    1570         432 :           createFunctionToLoopPassAdaptor(std::move(LPM), DebugLogging));
    1571         144 :       return true;
    1572             :     }
    1573           5 :     if (auto Count = parseRepeatPassName(Name)) {
    1574           1 :       FunctionPassManager NestedFPM(DebugLogging);
    1575           2 :       if (!parseFunctionPassPipeline(NestedFPM, InnerPipeline, VerifyEachPass,
    1576             :                                      DebugLogging))
    1577             :         return false;
    1578           4 :       FPM.addPass(createRepeatedPass(*Count, std::move(NestedFPM)));
    1579           1 :       return true;
    1580             :     }
    1581             : 
    1582          16 :     for (auto &C : FunctionPipelineParsingCallbacks)
    1583           8 :       if (C(Name, FPM, InnerPipeline))
    1584             :         return true;
    1585             : 
    1586             :     // Normal passes can't have pipelines.
    1587             :     return false;
    1588             :   }
    1589             : 
    1590             : // Now expand the basic registered passes from the .inc file.
    1591             : #define FUNCTION_PASS(NAME, CREATE_PASS)                                       \
    1592             :   if (Name == NAME) {                                                          \
    1593             :     FPM.addPass(CREATE_PASS);                                                  \
    1594             :     return true;                                                               \
    1595             :   }
    1596             : #define FUNCTION_ANALYSIS(NAME, CREATE_PASS)                                   \
    1597             :   if (Name == "require<" NAME ">") {                                           \
    1598             :     FPM.addPass(                                                               \
    1599             :         RequireAnalysisPass<                                                   \
    1600             :             std::remove_reference<decltype(CREATE_PASS)>::type, Function>());  \
    1601             :     return true;                                                               \
    1602             :   }                                                                            \
    1603             :   if (Name == "invalidate<" NAME ">") {                                        \
    1604             :     FPM.addPass(InvalidateAnalysisPass<                                        \
    1605             :                 std::remove_reference<decltype(CREATE_PASS)>::type>());        \
    1606             :     return true;                                                               \
    1607             :   }
    1608             : #include "PassRegistry.def"
    1609             : 
    1610          10 :   for (auto &C : FunctionPipelineParsingCallbacks)
    1611           7 :     if (C(Name, FPM, InnerPipeline))
    1612             :       return true;
    1613             :   return false;
    1614             : }
    1615             : 
    1616         161 : bool PassBuilder::parseLoopPass(LoopPassManager &LPM, const PipelineElement &E,
    1617             :                                 bool VerifyEachPass, bool DebugLogging) {
    1618         161 :   StringRef Name = E.Name;
    1619             :   auto &InnerPipeline = E.InnerPipeline;
    1620             : 
    1621             :   // First handle complex passes like the pass managers which carry pipelines.
    1622         161 :   if (!InnerPipeline.empty()) {
    1623             :     if (Name == "loop") {
    1624           0 :       LoopPassManager NestedLPM(DebugLogging);
    1625           0 :       if (!parseLoopPassPipeline(NestedLPM, InnerPipeline, VerifyEachPass,
    1626             :                                  DebugLogging))
    1627             :         return false;
    1628             :       // Add the nested pass manager with the appropriate adaptor.
    1629           0 :       LPM.addPass(std::move(NestedLPM));
    1630           0 :       return true;
    1631             :     }
    1632           2 :     if (auto Count = parseRepeatPassName(Name)) {
    1633           1 :       LoopPassManager NestedLPM(DebugLogging);
    1634           2 :       if (!parseLoopPassPipeline(NestedLPM, InnerPipeline, VerifyEachPass,
    1635             :                                  DebugLogging))
    1636             :         return false;
    1637           4 :       LPM.addPass(createRepeatedPass(*Count, std::move(NestedLPM)));
    1638           1 :       return true;
    1639             :     }
    1640             : 
    1641           1 :     for (auto &C : LoopPipelineParsingCallbacks)
    1642           0 :       if (C(Name, LPM, InnerPipeline))
    1643             :         return true;
    1644             : 
    1645             :     // Normal passes can't have pipelines.
    1646             :     return false;
    1647             :   }
    1648             : 
    1649             : // Now expand the basic registered passes from the .inc file.
    1650             : #define LOOP_PASS(NAME, CREATE_PASS)                                           \
    1651             :   if (Name == NAME) {                                                          \
    1652             :     LPM.addPass(CREATE_PASS);                                                  \
    1653             :     return true;                                                               \
    1654             :   }
    1655             : #define LOOP_ANALYSIS(NAME, CREATE_PASS)                                       \
    1656             :   if (Name == "require<" NAME ">") {                                           \
    1657             :     LPM.addPass(RequireAnalysisPass<                                           \
    1658             :                 std::remove_reference<decltype(CREATE_PASS)>::type, Loop,      \
    1659             :                 LoopAnalysisManager, LoopStandardAnalysisResults &,            \
    1660             :                 LPMUpdater &>());                                              \
    1661             :     return true;                                                               \
    1662             :   }                                                                            \
    1663             :   if (Name == "invalidate<" NAME ">") {                                        \
    1664             :     LPM.addPass(InvalidateAnalysisPass<                                        \
    1665             :                 std::remove_reference<decltype(CREATE_PASS)>::type>());        \
    1666             :     return true;                                                               \
    1667             :   }
    1668             : #include "PassRegistry.def"
    1669             : 
    1670           3 :   for (auto &C : LoopPipelineParsingCallbacks)
    1671           3 :     if (C(Name, LPM, InnerPipeline))
    1672             :       return true;
    1673             :   return false;
    1674             : }
    1675             : 
    1676         145 : bool PassBuilder::parseAAPassName(AAManager &AA, StringRef Name) {
    1677             : #define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS)                               \
    1678             :   if (Name == NAME) {                                                          \
    1679             :     AA.registerModuleAnalysis<                                                 \
    1680             :         std::remove_reference<decltype(CREATE_PASS)>::type>();                 \
    1681             :     return true;                                                               \
    1682             :   }
    1683             : #define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS)                             \
    1684             :   if (Name == NAME) {                                                          \
    1685             :     AA.registerFunctionAnalysis<                                               \
    1686             :         std::remove_reference<decltype(CREATE_PASS)>::type>();                 \
    1687             :     return true;                                                               \
    1688             :   }
    1689             : #include "PassRegistry.def"
    1690             : 
    1691           2 :   for (auto &C : AAParsingCallbacks)
    1692           0 :     if (C(Name, AA))
    1693             :       return true;
    1694             :   return false;
    1695             : }
    1696             : 
    1697         150 : bool PassBuilder::parseLoopPassPipeline(LoopPassManager &LPM,
    1698             :                                         ArrayRef<PipelineElement> Pipeline,
    1699             :                                         bool VerifyEachPass,
    1700             :                                         bool DebugLogging) {
    1701         470 :   for (const auto &Element : Pipeline) {
    1702         161 :     if (!parseLoopPass(LPM, Element, VerifyEachPass, DebugLogging))
    1703             :       return false;
    1704             :     // FIXME: No verifier support for Loop passes!
    1705             :   }
    1706             :   return true;
    1707             : }
    1708             : 
    1709         490 : bool PassBuilder::parseFunctionPassPipeline(FunctionPassManager &FPM,
    1710             :                                             ArrayRef<PipelineElement> Pipeline,
    1711             :                                             bool VerifyEachPass,
    1712             :                                             bool DebugLogging) {
    1713        2136 :   for (const auto &Element : Pipeline) {
    1714         827 :     if (!parseFunctionPass(FPM, Element, VerifyEachPass, DebugLogging))
    1715             :       return false;
    1716         823 :     if (VerifyEachPass)
    1717          14 :       FPM.addPass(VerifierPass());
    1718             :   }
    1719             :   return true;
    1720             : }
    1721             : 
    1722         175 : bool PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
    1723             :                                          ArrayRef<PipelineElement> Pipeline,
    1724             :                                          bool VerifyEachPass,
    1725             :                                          bool DebugLogging) {
    1726         605 :   for (const auto &Element : Pipeline) {
    1727         216 :     if (!parseCGSCCPass(CGPM, Element, VerifyEachPass, DebugLogging))
    1728             :       return false;
    1729             :     // FIXME: No verifier support for CGSCC passes!
    1730             :   }
    1731             :   return true;
    1732             : }
    1733             : 
    1734         950 : void PassBuilder::crossRegisterProxies(LoopAnalysisManager &LAM,
    1735             :                                        FunctionAnalysisManager &FAM,
    1736             :                                        CGSCCAnalysisManager &CGAM,
    1737             :                                        ModuleAnalysisManager &MAM) {
    1738        1900 :   MAM.registerPass([&] { return FunctionAnalysisManagerModuleProxy(FAM); });
    1739        1900 :   MAM.registerPass([&] { return CGSCCAnalysisManagerModuleProxy(CGAM); });
    1740        1900 :   CGAM.registerPass([&] { return ModuleAnalysisManagerCGSCCProxy(MAM); });
    1741        1900 :   FAM.registerPass([&] { return CGSCCAnalysisManagerFunctionProxy(CGAM); });
    1742        1900 :   FAM.registerPass([&] { return ModuleAnalysisManagerFunctionProxy(MAM); });
    1743        1900 :   FAM.registerPass([&] { return LoopAnalysisManagerFunctionProxy(LAM); });
    1744        1900 :   LAM.registerPass([&] { return FunctionAnalysisManagerLoopProxy(FAM); });
    1745         950 : }
    1746             : 
    1747         901 : bool PassBuilder::parseModulePassPipeline(ModulePassManager &MPM,
    1748             :                                           ArrayRef<PipelineElement> Pipeline,
    1749             :                                           bool VerifyEachPass,
    1750             :                                           bool DebugLogging) {
    1751        2861 :   for (const auto &Element : Pipeline) {
    1752         987 :     if (!parseModulePass(MPM, Element, VerifyEachPass, DebugLogging))
    1753             :       return false;
    1754         980 :     if (VerifyEachPass)
    1755          21 :       MPM.addPass(VerifierPass());
    1756             :   }
    1757             :   return true;
    1758             : }
    1759             : 
    1760             : // Primary pass pipeline description parsing routine for a \c ModulePassManager
    1761             : // FIXME: Should this routine accept a TargetMachine or require the caller to
    1762             : // pre-populate the analysis managers with target-specific stuff?
    1763         909 : bool PassBuilder::parsePassPipeline(ModulePassManager &MPM,
    1764             :                                     StringRef PipelineText, bool VerifyEachPass,
    1765             :                                     bool DebugLogging) {
    1766         909 :   auto Pipeline = parsePipelineText(PipelineText);
    1767        1807 :   if (!Pipeline || Pipeline->empty())
    1768             :     return false;
    1769             : 
    1770             :   // If the first name isn't at the module layer, wrap the pipeline up
    1771             :   // automatically.
    1772         898 :   StringRef FirstName = Pipeline->front().Name;
    1773             : 
    1774         898 :   if (!isModulePassName(FirstName, ModulePipelineParsingCallbacks)) {
    1775         461 :     if (isCGSCCPassName(FirstName, CGSCCPipelineParsingCallbacks)) {
    1776         122 :       Pipeline = {{"cgscc", std::move(*Pipeline)}};
    1777         400 :     } else if (isFunctionPassName(FirstName,
    1778             :                                   FunctionPipelineParsingCallbacks)) {
    1779         758 :       Pipeline = {{"function", std::move(*Pipeline)}};
    1780          21 :     } else if (isLoopPassName(FirstName, LoopPipelineParsingCallbacks)) {
    1781          45 :       Pipeline = {{"function", {{"loop", std::move(*Pipeline)}}}};
    1782             :     } else {
    1783           8 :       for (auto &C : TopLevelPipelineParsingCallbacks)
    1784           2 :         if (C(MPM, *Pipeline, VerifyEachPass, DebugLogging))
    1785             :           return true;
    1786             : 
    1787             :       // Unknown pass name!
    1788             :       return false;
    1789             :     }
    1790             :   }
    1791             : 
    1792        1784 :   return parseModulePassPipeline(MPM, *Pipeline, VerifyEachPass, DebugLogging);
    1793             : }
    1794             : 
    1795             : // Primary pass pipeline description parsing routine for a \c CGSCCPassManager
    1796           2 : bool PassBuilder::parsePassPipeline(CGSCCPassManager &CGPM,
    1797             :                                     StringRef PipelineText, bool VerifyEachPass,
    1798             :                                     bool DebugLogging) {
    1799           2 :   auto Pipeline = parsePipelineText(PipelineText);
    1800           4 :   if (!Pipeline || Pipeline->empty())
    1801             :     return false;
    1802             : 
    1803           2 :   StringRef FirstName = Pipeline->front().Name;
    1804           2 :   if (!isCGSCCPassName(FirstName, CGSCCPipelineParsingCallbacks))
    1805             :     return false;
    1806             : 
    1807           4 :   return parseCGSCCPassPipeline(CGPM, *Pipeline, VerifyEachPass, DebugLogging);
    1808             : }
    1809             : 
    1810             : // Primary pass pipeline description parsing routine for a \c
    1811             : // FunctionPassManager
    1812          13 : bool PassBuilder::parsePassPipeline(FunctionPassManager &FPM,
    1813             :                                     StringRef PipelineText, bool VerifyEachPass,
    1814             :                                     bool DebugLogging) {
    1815          13 :   auto Pipeline = parsePipelineText(PipelineText);
    1816          26 :   if (!Pipeline || Pipeline->empty())
    1817             :     return false;
    1818             : 
    1819          13 :   StringRef FirstName = Pipeline->front().Name;
    1820          13 :   if (!isFunctionPassName(FirstName, FunctionPipelineParsingCallbacks))
    1821             :     return false;
    1822             : 
    1823          26 :   return parseFunctionPassPipeline(FPM, *Pipeline, VerifyEachPass,
    1824          13 :                                    DebugLogging);
    1825             : }
    1826             : 
    1827             : // Primary pass pipeline description parsing routine for a \c LoopPassManager
    1828           4 : bool PassBuilder::parsePassPipeline(LoopPassManager &CGPM,
    1829             :                                     StringRef PipelineText, bool VerifyEachPass,
    1830             :                                     bool DebugLogging) {
    1831           4 :   auto Pipeline = parsePipelineText(PipelineText);
    1832           8 :   if (!Pipeline || Pipeline->empty())
    1833             :     return false;
    1834             : 
    1835           8 :   return parseLoopPassPipeline(CGPM, *Pipeline, VerifyEachPass, DebugLogging);
    1836             : }
    1837             : 
    1838         898 : bool PassBuilder::parseAAPipeline(AAManager &AA, StringRef PipelineText) {
    1839             :   // If the pipeline just consists of the word 'default' just replace the AA
    1840             :   // manager with our default one.
    1841             :   if (PipelineText == "default") {
    1842          38 :     AA = buildDefaultAAPipeline();
    1843          19 :     return true;
    1844             :   }
    1845             : 
    1846        1165 :   while (!PipelineText.empty()) {
    1847             :     StringRef Name;
    1848         145 :     std::tie(Name, PipelineText) = PipelineText.split(',');
    1849         145 :     if (!parseAAPassName(AA, Name))
    1850           2 :       return false;
    1851             :   }
    1852             : 
    1853             :   return true;
    1854      303507 : }

Generated by: LCOV version 1.13