LCOV - code coverage report
Current view: top level - include/llvm/Passes - PassBuilder.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 30 30 100.0 %
Date: 2018-10-17 09:37:48 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- Parsing, selection, and construction of pass pipelines --*- C++ -*--===//
       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             : /// Interfaces for registering analysis passes, producing common pass manager
      12             : /// configurations, and parsing of pass pipelines.
      13             : ///
      14             : //===----------------------------------------------------------------------===//
      15             : 
      16             : #ifndef LLVM_PASSES_PASSBUILDER_H
      17             : #define LLVM_PASSES_PASSBUILDER_H
      18             : 
      19             : #include "llvm/ADT/Optional.h"
      20             : #include "llvm/Analysis/CGSCCPassManager.h"
      21             : #include "llvm/IR/PassManager.h"
      22             : #include "llvm/Transforms/Instrumentation.h"
      23             : #include "llvm/Transforms/Scalar/LoopPassManager.h"
      24             : #include <vector>
      25             : 
      26             : namespace llvm {
      27             : class StringRef;
      28             : class AAManager;
      29             : class TargetMachine;
      30             : class ModuleSummaryIndex;
      31             : 
      32             : /// A struct capturing PGO tunables.
      33             : struct PGOOptions {
      34          16 :   PGOOptions(std::string ProfileGenFile = "", std::string ProfileUseFile = "",
      35             :              std::string SampleProfileFile = "",
      36             :              std::string ProfileRemappingFile = "",
      37             :              bool RunProfileGen = false, bool SamplePGOSupport = false)
      38          16 :       : ProfileGenFile(ProfileGenFile), ProfileUseFile(ProfileUseFile),
      39             :         SampleProfileFile(SampleProfileFile),
      40             :         ProfileRemappingFile(ProfileRemappingFile),
      41             :         RunProfileGen(RunProfileGen),
      42          16 :         SamplePGOSupport(SamplePGOSupport || !SampleProfileFile.empty()) {
      43             :     assert((RunProfileGen ||
      44             :             !SampleProfileFile.empty() ||
      45             :             !ProfileUseFile.empty() ||
      46             :             SamplePGOSupport) && "Illegal PGOOptions.");
      47          16 :   }
      48             :   std::string ProfileGenFile;
      49             :   std::string ProfileUseFile;
      50             :   std::string SampleProfileFile;
      51             :   std::string ProfileRemappingFile;
      52             :   bool RunProfileGen;
      53             :   bool SamplePGOSupport;
      54             : };
      55             : 
      56             : /// This class provides access to building LLVM's passes.
      57             : ///
      58             : /// It's members provide the baseline state available to passes during their
      59             : /// construction. The \c PassRegistry.def file specifies how to construct all
      60             : /// of the built-in passes, and those may reference these members during
      61             : /// construction.
      62             : class PassBuilder {
      63             :   TargetMachine *TM;
      64             :   Optional<PGOOptions> PGOOpt;
      65             :   PassInstrumentationCallbacks *PIC;
      66             : 
      67             : public:
      68             :   /// A struct to capture parsed pass pipeline names.
      69             :   ///
      70             :   /// A pipeline is defined as a series of names, each of which may in itself
      71             :   /// recursively contain a nested pipeline. A name is either the name of a pass
      72             :   /// (e.g. "instcombine") or the name of a pipeline type (e.g. "cgscc"). If the
      73             :   /// name is the name of a pass, the InnerPipeline is empty, since passes
      74             :   /// cannot contain inner pipelines. See parsePassPipeline() for a more
      75             :   /// detailed description of the textual pipeline format.
      76        6090 :   struct PipelineElement {
      77             :     StringRef Name;
      78             :     std::vector<PipelineElement> InnerPipeline;
      79             :   };
      80             : 
      81             :   /// ThinLTO phase.
      82             :   ///
      83             :   /// This enumerates the LLVM ThinLTO optimization phases.
      84             :   enum class ThinLTOPhase {
      85             :     /// No ThinLTO behavior needed.
      86             :     None,
      87             :     // ThinLTO prelink (summary) phase.
      88             :     PreLink,
      89             :     // ThinLTO postlink (backend compile) phase.
      90             :     PostLink
      91             :   };
      92             : 
      93             :   /// LLVM-provided high-level optimization levels.
      94             :   ///
      95             :   /// This enumerates the LLVM-provided high-level optimization levels. Each
      96             :   /// level has a specific goal and rationale.
      97             :   enum OptimizationLevel {
      98             :     /// Disable as many optimizations as possible. This doesn't completely
      99             :     /// disable the optimizer in all cases, for example always_inline functions
     100             :     /// can be required to be inlined for correctness.
     101             :     O0,
     102             : 
     103             :     /// Optimize quickly without destroying debuggability.
     104             :     ///
     105             :     /// FIXME: The current and historical behavior of this level does *not*
     106             :     /// agree with this goal, but we would like to move toward this goal in the
     107             :     /// future.
     108             :     ///
     109             :     /// This level is tuned to produce a result from the optimizer as quickly
     110             :     /// as possible and to avoid destroying debuggability. This tends to result
     111             :     /// in a very good development mode where the compiled code will be
     112             :     /// immediately executed as part of testing. As a consequence, where
     113             :     /// possible, we would like to produce efficient-to-execute code, but not
     114             :     /// if it significantly slows down compilation or would prevent even basic
     115             :     /// debugging of the resulting binary.
     116             :     ///
     117             :     /// As an example, complex loop transformations such as versioning,
     118             :     /// vectorization, or fusion might not make sense here due to the degree to
     119             :     /// which the executed code would differ from the source code, and the
     120             :     /// potential compile time cost.
     121             :     O1,
     122             : 
     123             :     /// Optimize for fast execution as much as possible without triggering
     124             :     /// significant incremental compile time or code size growth.
     125             :     ///
     126             :     /// The key idea is that optimizations at this level should "pay for
     127             :     /// themselves". So if an optimization increases compile time by 5% or
     128             :     /// increases code size by 5% for a particular benchmark, that benchmark
     129             :     /// should also be one which sees a 5% runtime improvement. If the compile
     130             :     /// time or code size penalties happen on average across a diverse range of
     131             :     /// LLVM users' benchmarks, then the improvements should as well.
     132             :     ///
     133             :     /// And no matter what, the compile time needs to not grow superlinearly
     134             :     /// with the size of input to LLVM so that users can control the runtime of
     135             :     /// the optimizer in this mode.
     136             :     ///
     137             :     /// This is expected to be a good default optimization level for the vast
     138             :     /// majority of users.
     139             :     O2,
     140             : 
     141             :     /// Optimize for fast execution as much as possible.
     142             :     ///
     143             :     /// This mode is significantly more aggressive in trading off compile time
     144             :     /// and code size to get execution time improvements. The core idea is that
     145             :     /// this mode should include any optimization that helps execution time on
     146             :     /// balance across a diverse collection of benchmarks, even if it increases
     147             :     /// code size or compile time for some benchmarks without corresponding
     148             :     /// improvements to execution time.
     149             :     ///
     150             :     /// Despite being willing to trade more compile time off to get improved
     151             :     /// execution time, this mode still tries to avoid superlinear growth in
     152             :     /// order to make even significantly slower compile times at least scale
     153             :     /// reasonably. This does not preclude very substantial constant factor
     154             :     /// costs though.
     155             :     O3,
     156             : 
     157             :     /// Similar to \c O2 but tries to optimize for small code size instead of
     158             :     /// fast execution without triggering significant incremental execution
     159             :     /// time slowdowns.
     160             :     ///
     161             :     /// The logic here is exactly the same as \c O2, but with code size and
     162             :     /// execution time metrics swapped.
     163             :     ///
     164             :     /// A consequence of the different core goal is that this should in general
     165             :     /// produce substantially smaller executables that still run in
     166             :     /// a reasonable amount of time.
     167             :     Os,
     168             : 
     169             :     /// A very specialized mode that will optimize for code size at any and all
     170             :     /// costs.
     171             :     ///
     172             :     /// This is useful primarily when there are absolute size limitations and
     173             :     /// any effort taken to reduce the size is worth it regardless of the
     174             :     /// execution time impact. You should expect this level to produce rather
     175             :     /// slow, but very small, code.
     176             :     Oz
     177             :   };
     178             : 
     179        1022 :   explicit PassBuilder(TargetMachine *TM = nullptr,
     180             :                        Optional<PGOOptions> PGOOpt = None,
     181             :                        PassInstrumentationCallbacks *PIC = nullptr)
     182        1022 :       : TM(TM), PGOOpt(PGOOpt), PIC(PIC) {}
     183             : 
     184             :   /// Cross register the analysis managers through their proxies.
     185             :   ///
     186             :   /// This is an interface that can be used to cross register each
     187             :   // AnalysisManager with all the others analysis managers.
     188             :   void crossRegisterProxies(LoopAnalysisManager &LAM,
     189             :                             FunctionAnalysisManager &FAM,
     190             :                             CGSCCAnalysisManager &CGAM,
     191             :                             ModuleAnalysisManager &MAM);
     192             : 
     193             :   /// Registers all available module analysis passes.
     194             :   ///
     195             :   /// This is an interface that can be used to populate a \c
     196             :   /// ModuleAnalysisManager with all registered module analyses. Callers can
     197             :   /// still manually register any additional analyses. Callers can also
     198             :   /// pre-register analyses and this will not override those.
     199             :   void registerModuleAnalyses(ModuleAnalysisManager &MAM);
     200             : 
     201             :   /// Registers all available CGSCC analysis passes.
     202             :   ///
     203             :   /// This is an interface that can be used to populate a \c CGSCCAnalysisManager
     204             :   /// with all registered CGSCC analyses. Callers can still manually register any
     205             :   /// additional analyses. Callers can also pre-register analyses and this will
     206             :   /// not override those.
     207             :   void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM);
     208             : 
     209             :   /// Registers all available function analysis passes.
     210             :   ///
     211             :   /// This is an interface that can be used to populate a \c
     212             :   /// FunctionAnalysisManager with all registered function analyses. Callers can
     213             :   /// still manually register any additional analyses. Callers can also
     214             :   /// pre-register analyses and this will not override those.
     215             :   void registerFunctionAnalyses(FunctionAnalysisManager &FAM);
     216             : 
     217             :   /// Registers all available loop analysis passes.
     218             :   ///
     219             :   /// This is an interface that can be used to populate a \c LoopAnalysisManager
     220             :   /// with all registered loop analyses. Callers can still manually register any
     221             :   /// additional analyses.
     222             :   void registerLoopAnalyses(LoopAnalysisManager &LAM);
     223             : 
     224             :   /// Construct the core LLVM function canonicalization and simplification
     225             :   /// pipeline.
     226             :   ///
     227             :   /// This is a long pipeline and uses most of the per-function optimization
     228             :   /// passes in LLVM to canonicalize and simplify the IR. It is suitable to run
     229             :   /// repeatedly over the IR and is not expected to destroy important
     230             :   /// information about the semantics of the IR.
     231             :   ///
     232             :   /// Note that \p Level cannot be `O0` here. The pipelines produced are
     233             :   /// only intended for use when attempting to optimize code. If frontends
     234             :   /// require some transformations for semantic reasons, they should explicitly
     235             :   /// build them.
     236             :   ///
     237             :   /// \p Phase indicates the current ThinLTO phase.
     238             :   FunctionPassManager
     239             :   buildFunctionSimplificationPipeline(OptimizationLevel Level,
     240             :                                       ThinLTOPhase Phase,
     241             :                                       bool DebugLogging = false);
     242             : 
     243             :   /// Construct the core LLVM module canonicalization and simplification
     244             :   /// pipeline.
     245             :   ///
     246             :   /// This pipeline focuses on canonicalizing and simplifying the entire module
     247             :   /// of IR. Much like the function simplification pipeline above, it is
     248             :   /// suitable to run repeatedly over the IR and is not expected to destroy
     249             :   /// important information. It does, however, perform inlining and other
     250             :   /// heuristic based simplifications that are not strictly reversible.
     251             :   ///
     252             :   /// Note that \p Level cannot be `O0` here. The pipelines produced are
     253             :   /// only intended for use when attempting to optimize code. If frontends
     254             :   /// require some transformations for semantic reasons, they should explicitly
     255             :   /// build them.
     256             :   ///
     257             :   /// \p Phase indicates the current ThinLTO phase.
     258             :   ModulePassManager
     259             :   buildModuleSimplificationPipeline(OptimizationLevel Level,
     260             :                                     ThinLTOPhase Phase,
     261             :                                     bool DebugLogging = false);
     262             : 
     263             :   /// Construct the core LLVM module optimization pipeline.
     264             :   ///
     265             :   /// This pipeline focuses on optimizing the execution speed of the IR. It
     266             :   /// uses cost modeling and thresholds to balance code growth against runtime
     267             :   /// improvements. It includes vectorization and other information destroying
     268             :   /// transformations. It also cannot generally be run repeatedly on a module
     269             :   /// without potentially seriously regressing either runtime performance of
     270             :   /// the code or serious code size growth.
     271             :   ///
     272             :   /// Note that \p Level cannot be `O0` here. The pipelines produced are
     273             :   /// only intended for use when attempting to optimize code. If frontends
     274             :   /// require some transformations for semantic reasons, they should explicitly
     275             :   /// build them.
     276             :   ModulePassManager buildModuleOptimizationPipeline(OptimizationLevel Level,
     277             :                                                     bool DebugLogging = false);
     278             : 
     279             :   /// Build a per-module default optimization pipeline.
     280             :   ///
     281             :   /// This provides a good default optimization pipeline for per-module
     282             :   /// optimization and code generation without any link-time optimization. It
     283             :   /// typically correspond to frontend "-O[123]" options for optimization
     284             :   /// levels \c O1, \c O2 and \c O3 resp.
     285             :   ///
     286             :   /// Note that \p Level cannot be `O0` here. The pipelines produced are
     287             :   /// only intended for use when attempting to optimize code. If frontends
     288             :   /// require some transformations for semantic reasons, they should explicitly
     289             :   /// build them.
     290             :   ModulePassManager buildPerModuleDefaultPipeline(OptimizationLevel Level,
     291             :                                                   bool DebugLogging = false);
     292             : 
     293             :   /// Build a pre-link, ThinLTO-targeting default optimization pipeline to
     294             :   /// a pass manager.
     295             :   ///
     296             :   /// This adds the pre-link optimizations tuned to prepare a module for
     297             :   /// a ThinLTO run. It works to minimize the IR which needs to be analyzed
     298             :   /// without making irreversible decisions which could be made better during
     299             :   /// the LTO run.
     300             :   ///
     301             :   /// Note that \p Level cannot be `O0` here. The pipelines produced are
     302             :   /// only intended for use when attempting to optimize code. If frontends
     303             :   /// require some transformations for semantic reasons, they should explicitly
     304             :   /// build them.
     305             :   ModulePassManager
     306             :   buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level,
     307             :                                      bool DebugLogging = false);
     308             : 
     309             :   /// Build an ThinLTO default optimization pipeline to a pass manager.
     310             :   ///
     311             :   /// This provides a good default optimization pipeline for link-time
     312             :   /// optimization and code generation. It is particularly tuned to fit well
     313             :   /// when IR coming into the LTO phase was first run through \c
     314             :   /// addPreLinkLTODefaultPipeline, and the two coordinate closely.
     315             :   ///
     316             :   /// Note that \p Level cannot be `O0` here. The pipelines produced are
     317             :   /// only intended for use when attempting to optimize code. If frontends
     318             :   /// require some transformations for semantic reasons, they should explicitly
     319             :   /// build them.
     320             :   ModulePassManager
     321             :   buildThinLTODefaultPipeline(OptimizationLevel Level, bool DebugLogging,
     322             :                               const ModuleSummaryIndex *ImportSummary);
     323             : 
     324             :   /// Build a pre-link, LTO-targeting default optimization pipeline to a pass
     325             :   /// manager.
     326             :   ///
     327             :   /// This adds the pre-link optimizations tuned to work well with a later LTO
     328             :   /// run. It works to minimize the IR which needs to be analyzed without
     329             :   /// making irreversible decisions which could be made better during the LTO
     330             :   /// run.
     331             :   ///
     332             :   /// Note that \p Level cannot be `O0` here. The pipelines produced are
     333             :   /// only intended for use when attempting to optimize code. If frontends
     334             :   /// require some transformations for semantic reasons, they should explicitly
     335             :   /// build them.
     336             :   ModulePassManager buildLTOPreLinkDefaultPipeline(OptimizationLevel Level,
     337             :                                                    bool DebugLogging = false);
     338             : 
     339             :   /// Build an LTO default optimization pipeline to a pass manager.
     340             :   ///
     341             :   /// This provides a good default optimization pipeline for link-time
     342             :   /// optimization and code generation. It is particularly tuned to fit well
     343             :   /// when IR coming into the LTO phase was first run through \c
     344             :   /// addPreLinkLTODefaultPipeline, and the two coordinate closely.
     345             :   ///
     346             :   /// Note that \p Level cannot be `O0` here. The pipelines produced are
     347             :   /// only intended for use when attempting to optimize code. If frontends
     348             :   /// require some transformations for semantic reasons, they should explicitly
     349             :   /// build them.
     350             :   ModulePassManager buildLTODefaultPipeline(OptimizationLevel Level,
     351             :                                             bool DebugLogging,
     352             :                                             ModuleSummaryIndex *ExportSummary);
     353             : 
     354             :   /// Build the default `AAManager` with the default alias analysis pipeline
     355             :   /// registered.
     356             :   AAManager buildDefaultAAPipeline();
     357             : 
     358             :   /// Parse a textual pass pipeline description into a \c
     359             :   /// ModulePassManager.
     360             :   ///
     361             :   /// The format of the textual pass pipeline description looks something like:
     362             :   ///
     363             :   ///   module(function(instcombine,sroa),dce,cgscc(inliner,function(...)),...)
     364             :   ///
     365             :   /// Pass managers have ()s describing the nest structure of passes. All passes
     366             :   /// are comma separated. As a special shortcut, if the very first pass is not
     367             :   /// a module pass (as a module pass manager is), this will automatically form
     368             :   /// the shortest stack of pass managers that allow inserting that first pass.
     369             :   /// So, assuming function passes 'fpassN', CGSCC passes 'cgpassN', and loop
     370             :   /// passes 'lpassN', all of these are valid:
     371             :   ///
     372             :   ///   fpass1,fpass2,fpass3
     373             :   ///   cgpass1,cgpass2,cgpass3
     374             :   ///   lpass1,lpass2,lpass3
     375             :   ///
     376             :   /// And they are equivalent to the following (resp.):
     377             :   ///
     378             :   ///   module(function(fpass1,fpass2,fpass3))
     379             :   ///   module(cgscc(cgpass1,cgpass2,cgpass3))
     380             :   ///   module(function(loop(lpass1,lpass2,lpass3)))
     381             :   ///
     382             :   /// This shortcut is especially useful for debugging and testing small pass
     383             :   /// combinations. Note that these shortcuts don't introduce any other magic.
     384             :   /// If the sequence of passes aren't all the exact same kind of pass, it will
     385             :   /// be an error. You cannot mix different levels implicitly, you must
     386             :   /// explicitly form a pass manager in which to nest passes.
     387             :   bool parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText,
     388             :                          bool VerifyEachPass = true, bool DebugLogging = false);
     389             : 
     390             :   /// {{@ Parse a textual pass pipeline description into a specific PassManager
     391             :   ///
     392             :   /// Automatic deduction of an appropriate pass manager stack is not supported.
     393             :   /// For example, to insert a loop pass 'lpass' into a FunctinoPassManager,
     394             :   /// this is the valid pipeline text:
     395             :   ///
     396             :   ///   function(lpass)
     397             :   bool parsePassPipeline(CGSCCPassManager &CGPM, StringRef PipelineText,
     398             :                          bool VerifyEachPass = true, bool DebugLogging = false);
     399             :   bool parsePassPipeline(FunctionPassManager &FPM, StringRef PipelineText,
     400             :                          bool VerifyEachPass = true, bool DebugLogging = false);
     401             :   bool parsePassPipeline(LoopPassManager &LPM, StringRef PipelineText,
     402             :                          bool VerifyEachPass = true, bool DebugLogging = false);
     403             :   /// @}}
     404             : 
     405             :   /// Parse a textual alias analysis pipeline into the provided AA manager.
     406             :   ///
     407             :   /// The format of the textual AA pipeline is a comma separated list of AA
     408             :   /// pass names:
     409             :   ///
     410             :   ///   basic-aa,globals-aa,...
     411             :   ///
     412             :   /// The AA manager is set up such that the provided alias analyses are tried
     413             :   /// in the order specified. See the \c AAManaager documentation for details
     414             :   /// about the logic used. This routine just provides the textual mapping
     415             :   /// between AA names and the analyses to register with the manager.
     416             :   ///
     417             :   /// Returns false if the text cannot be parsed cleanly. The specific state of
     418             :   /// the \p AA manager is unspecified if such an error is encountered and this
     419             :   /// returns false.
     420             :   bool parseAAPipeline(AAManager &AA, StringRef PipelineText);
     421             : 
     422             :   /// Register a callback for a default optimizer pipeline extension
     423             :   /// point
     424             :   ///
     425             :   /// This extension point allows adding passes that perform peephole
     426             :   /// optimizations similar to the instruction combiner. These passes will be
     427             :   /// inserted after each instance of the instruction combiner pass.
     428             :   void registerPeepholeEPCallback(
     429             :       const std::function<void(FunctionPassManager &, OptimizationLevel)> &C) {
     430           2 :     PeepholeEPCallbacks.push_back(C);
     431             :   }
     432             : 
     433             :   /// Register a callback for a default optimizer pipeline extension
     434             :   /// point
     435             :   ///
     436             :   /// This extension point allows adding late loop canonicalization and
     437             :   /// simplification passes. This is the last point in the loop optimization
     438             :   /// pipeline before loop deletion. Each pass added
     439             :   /// here must be an instance of LoopPass.
     440             :   /// This is the place to add passes that can remove loops, such as target-
     441             :   /// specific loop idiom recognition.
     442             :   void registerLateLoopOptimizationsEPCallback(
     443             :       const std::function<void(LoopPassManager &, OptimizationLevel)> &C) {
     444           1 :     LateLoopOptimizationsEPCallbacks.push_back(C);
     445             :   }
     446             : 
     447             :   /// Register a callback for a default optimizer pipeline extension
     448             :   /// point
     449             :   ///
     450             :   /// This extension point allows adding loop passes to the end of the loop
     451             :   /// optimizer.
     452             :   void registerLoopOptimizerEndEPCallback(
     453             :       const std::function<void(LoopPassManager &, OptimizationLevel)> &C) {
     454           1 :     LoopOptimizerEndEPCallbacks.push_back(C);
     455             :   }
     456             : 
     457             :   /// Register a callback for a default optimizer pipeline extension
     458             :   /// point
     459             :   ///
     460             :   /// This extension point allows adding optimization passes after most of the
     461             :   /// main optimizations, but before the last cleanup-ish optimizations.
     462             :   void registerScalarOptimizerLateEPCallback(
     463             :       const std::function<void(FunctionPassManager &, OptimizationLevel)> &C) {
     464           1 :     ScalarOptimizerLateEPCallbacks.push_back(C);
     465             :   }
     466             : 
     467             :   /// Register a callback for a default optimizer pipeline extension
     468             :   /// point
     469             :   ///
     470             :   /// This extension point allows adding CallGraphSCC passes at the end of the
     471             :   /// main CallGraphSCC passes and before any function simplification passes run
     472             :   /// by CGPassManager.
     473             :   void registerCGSCCOptimizerLateEPCallback(
     474             :       const std::function<void(CGSCCPassManager &, OptimizationLevel)> &C) {
     475           1 :     CGSCCOptimizerLateEPCallbacks.push_back(C);
     476             :   }
     477             : 
     478             :   /// Register a callback for a default optimizer pipeline extension
     479             :   /// point
     480             :   ///
     481             :   /// This extension point allows adding optimization passes before the
     482             :   /// vectorizer and other highly target specific optimization passes are
     483             :   /// executed.
     484             :   void registerVectorizerStartEPCallback(
     485             :       const std::function<void(FunctionPassManager &, OptimizationLevel)> &C) {
     486         921 :     VectorizerStartEPCallbacks.push_back(C);
     487             :   }
     488             : 
     489             :   /// Register a callback for a default optimizer pipeline extension point.
     490             :   ///
     491             :   /// This extension point allows adding optimization once at the start of the
     492             :   /// pipeline. This does not apply to 'backend' compiles (LTO and ThinLTO
     493             :   /// link-time pipelines).
     494             :   void registerPipelineStartEPCallback(
     495             :       const std::function<void(ModulePassManager &)> &C) {
     496           5 :     PipelineStartEPCallbacks.push_back(C);
     497             :   }
     498             : 
     499             :   /// Register a callback for parsing an AliasAnalysis Name to populate
     500             :   /// the given AAManager \p AA
     501             :   void registerParseAACallback(
     502             :       const std::function<bool(StringRef Name, AAManager &AA)> &C) {
     503             :     AAParsingCallbacks.push_back(C);
     504             :   }
     505             : 
     506             :   /// {{@ Register callbacks for analysis registration with this PassBuilder
     507             :   /// instance.
     508             :   /// Callees register their analyses with the given AnalysisManager objects.
     509             :   void registerAnalysisRegistrationCallback(
     510             :       const std::function<void(CGSCCAnalysisManager &)> &C) {
     511           4 :     CGSCCAnalysisRegistrationCallbacks.push_back(C);
     512             :   }
     513             :   void registerAnalysisRegistrationCallback(
     514             :       const std::function<void(FunctionAnalysisManager &)> &C) {
     515         924 :     FunctionAnalysisRegistrationCallbacks.push_back(C);
     516             :   }
     517             :   void registerAnalysisRegistrationCallback(
     518             :       const std::function<void(LoopAnalysisManager &)> &C) {
     519           4 :     LoopAnalysisRegistrationCallbacks.push_back(C);
     520             :   }
     521             :   void registerAnalysisRegistrationCallback(
     522             :       const std::function<void(ModuleAnalysisManager &)> &C) {
     523           5 :     ModuleAnalysisRegistrationCallbacks.push_back(C);
     524             :   }
     525             :   /// @}}
     526             : 
     527             :   /// {{@ Register pipeline parsing callbacks with this pass builder instance.
     528             :   /// Using these callbacks, callers can parse both a single pass name, as well
     529             :   /// as entire sub-pipelines, and populate the PassManager instance
     530             :   /// accordingly.
     531             :   void registerPipelineParsingCallback(
     532             :       const std::function<bool(StringRef Name, CGSCCPassManager &,
     533             :                                ArrayRef<PipelineElement>)> &C) {
     534           4 :     CGSCCPipelineParsingCallbacks.push_back(C);
     535             :   }
     536             :   void registerPipelineParsingCallback(
     537             :       const std::function<bool(StringRef Name, FunctionPassManager &,
     538             :                                ArrayRef<PipelineElement>)> &C) {
     539        1844 :     FunctionPipelineParsingCallbacks.push_back(C);
     540             :   }
     541             :   void registerPipelineParsingCallback(
     542             :       const std::function<bool(StringRef Name, LoopPassManager &,
     543             :                                ArrayRef<PipelineElement>)> &C) {
     544           4 :     LoopPipelineParsingCallbacks.push_back(C);
     545             :   }
     546             :   void registerPipelineParsingCallback(
     547             :       const std::function<bool(StringRef Name, ModulePassManager &,
     548             :                                ArrayRef<PipelineElement>)> &C) {
     549         926 :     ModulePipelineParsingCallbacks.push_back(C);
     550             :   }
     551             :   /// @}}
     552             : 
     553             :   /// Register a callback for a top-level pipeline entry.
     554             :   ///
     555             :   /// If the PassManager type is not given at the top level of the pipeline
     556             :   /// text, this Callback should be used to determine the appropriate stack of
     557             :   /// PassManagers and populate the passed ModulePassManager.
     558             :   void registerParseTopLevelPipelineCallback(
     559             :       const std::function<bool(ModulePassManager &, ArrayRef<PipelineElement>,
     560             :                                bool VerifyEachPass, bool DebugLogging)> &C) {
     561         921 :     TopLevelPipelineParsingCallbacks.push_back(C);
     562             :   }
     563             : 
     564             : private:
     565             :   static Optional<std::vector<PipelineElement>>
     566             :   parsePipelineText(StringRef Text);
     567             : 
     568             :   bool parseModulePass(ModulePassManager &MPM, const PipelineElement &E,
     569             :                        bool VerifyEachPass, bool DebugLogging);
     570             :   bool parseCGSCCPass(CGSCCPassManager &CGPM, const PipelineElement &E,
     571             :                       bool VerifyEachPass, bool DebugLogging);
     572             :   bool parseFunctionPass(FunctionPassManager &FPM, const PipelineElement &E,
     573             :                      bool VerifyEachPass, bool DebugLogging);
     574             :   bool parseLoopPass(LoopPassManager &LPM, const PipelineElement &E,
     575             :                      bool VerifyEachPass, bool DebugLogging);
     576             :   bool parseAAPassName(AAManager &AA, StringRef Name);
     577             : 
     578             :   bool parseLoopPassPipeline(LoopPassManager &LPM,
     579             :                              ArrayRef<PipelineElement> Pipeline,
     580             :                              bool VerifyEachPass, bool DebugLogging);
     581             :   bool parseFunctionPassPipeline(FunctionPassManager &FPM,
     582             :                                  ArrayRef<PipelineElement> Pipeline,
     583             :                                  bool VerifyEachPass, bool DebugLogging);
     584             :   bool parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
     585             :                               ArrayRef<PipelineElement> Pipeline,
     586             :                               bool VerifyEachPass, bool DebugLogging);
     587             :   bool parseModulePassPipeline(ModulePassManager &MPM,
     588             :                                ArrayRef<PipelineElement> Pipeline,
     589             :                                bool VerifyEachPass, bool DebugLogging);
     590             : 
     591             :   void addPGOInstrPasses(ModulePassManager &MPM, bool DebugLogging,
     592             :                          OptimizationLevel Level, bool RunProfileGen,
     593             :                          std::string ProfileGenFile,
     594             :                          std::string ProfileUseFile,
     595             :                          std::string ProfileRemappingFile);
     596             : 
     597             :   void invokePeepholeEPCallbacks(FunctionPassManager &, OptimizationLevel);
     598             : 
     599             :   // Extension Point callbacks
     600             :   SmallVector<std::function<void(FunctionPassManager &, OptimizationLevel)>, 2>
     601             :       PeepholeEPCallbacks;
     602             :   SmallVector<std::function<void(LoopPassManager &, OptimizationLevel)>, 2>
     603             :       LateLoopOptimizationsEPCallbacks;
     604             :   SmallVector<std::function<void(LoopPassManager &, OptimizationLevel)>, 2>
     605             :       LoopOptimizerEndEPCallbacks;
     606             :   SmallVector<std::function<void(FunctionPassManager &, OptimizationLevel)>, 2>
     607             :       ScalarOptimizerLateEPCallbacks;
     608             :   SmallVector<std::function<void(CGSCCPassManager &, OptimizationLevel)>, 2>
     609             :       CGSCCOptimizerLateEPCallbacks;
     610             :   SmallVector<std::function<void(FunctionPassManager &, OptimizationLevel)>, 2>
     611             :       VectorizerStartEPCallbacks;
     612             :   // Module callbacks
     613             :   SmallVector<std::function<void(ModulePassManager &)>, 2>
     614             :       PipelineStartEPCallbacks;
     615             :   SmallVector<std::function<void(ModuleAnalysisManager &)>, 2>
     616             :       ModuleAnalysisRegistrationCallbacks;
     617             :   SmallVector<std::function<bool(StringRef, ModulePassManager &,
     618             :                                  ArrayRef<PipelineElement>)>,
     619             :               2>
     620             :       ModulePipelineParsingCallbacks;
     621             :   SmallVector<std::function<bool(ModulePassManager &, ArrayRef<PipelineElement>,
     622             :                                  bool VerifyEachPass, bool DebugLogging)>,
     623             :               2>
     624             :       TopLevelPipelineParsingCallbacks;
     625             :   // CGSCC callbacks
     626             :   SmallVector<std::function<void(CGSCCAnalysisManager &)>, 2>
     627             :       CGSCCAnalysisRegistrationCallbacks;
     628             :   SmallVector<std::function<bool(StringRef, CGSCCPassManager &,
     629             :                                  ArrayRef<PipelineElement>)>,
     630             :               2>
     631             :       CGSCCPipelineParsingCallbacks;
     632             :   // Function callbacks
     633             :   SmallVector<std::function<void(FunctionAnalysisManager &)>, 2>
     634             :       FunctionAnalysisRegistrationCallbacks;
     635             :   SmallVector<std::function<bool(StringRef, FunctionPassManager &,
     636             :                                  ArrayRef<PipelineElement>)>,
     637             :               2>
     638             :       FunctionPipelineParsingCallbacks;
     639             :   // Loop callbacks
     640             :   SmallVector<std::function<void(LoopAnalysisManager &)>, 2>
     641             :       LoopAnalysisRegistrationCallbacks;
     642             :   SmallVector<std::function<bool(StringRef, LoopPassManager &,
     643             :                                  ArrayRef<PipelineElement>)>,
     644             :               2>
     645             :       LoopPipelineParsingCallbacks;
     646             :   // AA callbacks
     647             :   SmallVector<std::function<bool(StringRef Name, AAManager &AA)>, 2>
     648             :       AAParsingCallbacks;
     649             : };
     650             : 
     651             : /// This utility template takes care of adding require<> and invalidate<>
     652             : /// passes for an analysis to a given \c PassManager. It is intended to be used
     653             : /// during parsing of a pass pipeline when parsing a single PipelineName.
     654             : /// When registering a new function analysis FancyAnalysis with the pass
     655             : /// pipeline name "fancy-analysis", a matching ParsePipelineCallback could look
     656             : /// like this:
     657             : ///
     658             : /// static bool parseFunctionPipeline(StringRef Name, FunctionPassManager &FPM,
     659             : ///                                   ArrayRef<PipelineElement> P) {
     660             : ///   if (parseAnalysisUtilityPasses<FancyAnalysis>("fancy-analysis", Name,
     661             : ///                                                 FPM))
     662             : ///     return true;
     663             : ///   return false;
     664             : /// }
     665             : template <typename AnalysisT, typename IRUnitT, typename AnalysisManagerT,
     666             :           typename... ExtraArgTs>
     667         117 : bool parseAnalysisUtilityPasses(
     668             :     StringRef AnalysisName, StringRef PipelineName,
     669             :     PassManager<IRUnitT, AnalysisManagerT, ExtraArgTs...> &PM) {
     670             :   if (!PipelineName.endswith(">"))
     671             :     return false;
     672             :   // See if this is an invalidate<> pass name
     673             :   if (PipelineName.startswith("invalidate<")) {
     674           5 :     PipelineName = PipelineName.substr(11, PipelineName.size() - 12);
     675             :     if (PipelineName != AnalysisName)
     676             :       return false;
     677           5 :     PM.addPass(InvalidateAnalysisPass<AnalysisT>());
     678           5 :     return true;
     679             :   }
     680             : 
     681             :   // See if this is a require<> pass name
     682             :   if (PipelineName.startswith("require<")) {
     683          20 :     PipelineName = PipelineName.substr(8, PipelineName.size() - 9);
     684             :     if (PipelineName != AnalysisName)
     685             :       return false;
     686           8 :     PM.addPass(RequireAnalysisPass<AnalysisT, IRUnitT, AnalysisManagerT,
     687             :                                    ExtraArgTs...>());
     688           8 :     return true;
     689             :   }
     690             : 
     691             :   return false;
     692             : }
     693             : }
     694             : 
     695             : #endif

Generated by: LCOV version 1.13