class PassBuilder

Declaration

class PassBuilder { /* full declaration omitted */ };

Description

This class provides access to building LLVM's passes. Its members provide the baseline state available to passes during their construction. The \c PassRegistry.def file specifies how to construct all of the built-in passes, and those may reference these members during construction.

Declared at: llvm/include/llvm/Passes/PassBuilder.h:110

Method Overview

Methods

PassBuilder(
    llvm::TargetMachine* TM = nullptr,
    llvm::PipelineTuningOptions PTO =
        llvm::PipelineTuningOptions(),
    Optional<llvm::PGOOptions> PGOOpt = None,
    llvm::PassInstrumentationCallbacks* PIC =
        nullptr)

Declared at: llvm/include/llvm/Passes/PassBuilder.h:224

Parameters

llvm::TargetMachine* TM = nullptr
llvm::PipelineTuningOptions PTO = llvm::PipelineTuningOptions()
Optional<llvm::PGOOptions> PGOOpt = None
llvm::PassInstrumentationCallbacks* PIC = nullptr

void addPGOInstrPassesForO0(
    llvm::ModulePassManager& MPM,
    bool DebugLogging,
    bool RunProfileGen,
    bool IsCS,
    std::string ProfileFile,
    std::string ProfileRemappingFile)

Description

Add PGOInstrumenation passes for O0 only.

Declared at: llvm/include/llvm/Passes/PassBuilder.h:629

Parameters

llvm::ModulePassManager& MPM
bool DebugLogging
bool RunProfileGen
bool IsCS
std::string ProfileFile
std::string ProfileRemappingFile

llvm::AAManager buildDefaultAAPipeline()

Description

Build the default `AAManager` with the default alias analysis pipeline registered.

Declared at: llvm/include/llvm/Passes/PassBuilder.h:404

llvm::FunctionPassManager
buildFunctionSimplificationPipeline(
    llvm::PassBuilder::OptimizationLevel Level,
    llvm::PassBuilder::ThinLTOPhase Phase,
    bool DebugLogging = false)

Description

Construct the core LLVM function canonicalization and simplification pipeline. This is a long pipeline and uses most of the per-function optimization passes in LLVM to canonicalize and simplify the IR. It is suitable to run repeatedly over the IR and is not expected to destroy important information about the semantics of the IR. Note that \p Level cannot be `O0` here. The pipelines produced are only intended for use when attempting to optimize code. If frontends require some transformations for semantic reasons, they should explicitly build them. \p Phase indicates the current ThinLTO phase.

Declared at: llvm/include/llvm/Passes/PassBuilder.h:285

Parameters

llvm::PassBuilder::OptimizationLevel Level
llvm::PassBuilder::ThinLTOPhase Phase
bool DebugLogging = false

llvm::ModulePassManager buildLTODefaultPipeline(
    llvm::PassBuilder::OptimizationLevel Level,
    bool DebugLogging,
    llvm::ModuleSummaryIndex* ExportSummary)

Description

Build an LTO default optimization pipeline to a pass manager. This provides a good default optimization pipeline for link-time optimization and code generation. It is particularly tuned to fit well when IR coming into the LTO phase was first run through \c addPreLinkLTODefaultPipeline, and the two coordinate closely. Note that \p Level cannot be `O0` here. The pipelines produced are only intended for use when attempting to optimize code. If frontends require some transformations for semantic reasons, they should explicitly build them.

Declared at: llvm/include/llvm/Passes/PassBuilder.h:398

Parameters

llvm::PassBuilder::OptimizationLevel Level
bool DebugLogging
llvm::ModuleSummaryIndex* ExportSummary

llvm::ModulePassManager
buildLTOPreLinkDefaultPipeline(
    llvm::PassBuilder::OptimizationLevel Level,
    bool DebugLogging = false)

Description

Build a pre-link, LTO-targeting default optimization pipeline to a pass manager. This adds the pre-link optimizations tuned to work well with a later LTO run. It works to minimize the IR which needs to be analyzed without making irreversible decisions which could be made better during the LTO run. Note that \p Level cannot be `O0` here. The pipelines produced are only intended for use when attempting to optimize code. If frontends require some transformations for semantic reasons, they should explicitly build them.

Declared at: llvm/include/llvm/Passes/PassBuilder.h:384

Parameters

llvm::PassBuilder::OptimizationLevel Level
bool DebugLogging = false

llvm::ModulePassManager
buildModuleOptimizationPipeline(
    llvm::PassBuilder::OptimizationLevel Level,
    bool DebugLogging = false,
    bool LTOPreLink = false)

Description

Construct the core LLVM module optimization pipeline. This pipeline focuses on optimizing the execution speed of the IR. It uses cost modeling and thresholds to balance code growth against runtime improvements. It includes vectorization and other information destroying transformations. It also cannot generally be run repeatedly on a module without potentially seriously regressing either runtime performance of the code or serious code size growth. Note that \p Level cannot be `O0` here. The pipelines produced are only intended for use when attempting to optimize code. If frontends require some transformations for semantic reasons, they should explicitly build them.

Declared at: llvm/include/llvm/Passes/PassBuilder.h:322

Parameters

llvm::PassBuilder::OptimizationLevel Level
bool DebugLogging = false
bool LTOPreLink = false

llvm::ModulePassManager
buildModuleSimplificationPipeline(
    llvm::PassBuilder::OptimizationLevel Level,
    llvm::PassBuilder::ThinLTOPhase Phase,
    bool DebugLogging = false)

Description

Construct the core LLVM module canonicalization and simplification pipeline. This pipeline focuses on canonicalizing and simplifying the entire module of IR. Much like the function simplification pipeline above, it is suitable to run repeatedly over the IR and is not expected to destroy important information. It does, however, perform inlining and other heuristic based simplifications that are not strictly reversible. Note that \p Level cannot be `O0` here. The pipelines produced are only intended for use when attempting to optimize code. If frontends require some transformations for semantic reasons, they should explicitly build them. \p Phase indicates the current ThinLTO phase.

Declared at: llvm/include/llvm/Passes/PassBuilder.h:305

Parameters

llvm::PassBuilder::OptimizationLevel Level
llvm::PassBuilder::ThinLTOPhase Phase
bool DebugLogging = false

llvm::ModulePassManager
buildPerModuleDefaultPipeline(
    llvm::PassBuilder::OptimizationLevel Level,
    bool DebugLogging = false,
    bool LTOPreLink = false)

Description

Build a per-module default optimization pipeline. This provides a good default optimization pipeline for per-module optimization and code generation without any link-time optimization. It typically correspond to frontend "-O[123]" options for optimization levels \c O1, \c O2 and \c O3 resp. Note that \p Level cannot be `O0` here. The pipelines produced are only intended for use when attempting to optimize code. If frontends require some transformations for semantic reasons, they should explicitly build them.

Declared at: llvm/include/llvm/Passes/PassBuilder.h:337

Parameters

llvm::PassBuilder::OptimizationLevel Level
bool DebugLogging = false
bool LTOPreLink = false

llvm::ModulePassManager
buildThinLTODefaultPipeline(
    llvm::PassBuilder::OptimizationLevel Level,
    bool DebugLogging,
    const llvm::ModuleSummaryIndex* ImportSummary)

Description

Build an ThinLTO default optimization pipeline to a pass manager. This provides a good default optimization pipeline for link-time optimization and code generation. It is particularly tuned to fit well when IR coming into the LTO phase was first run through \c addPreLinkLTODefaultPipeline, and the two coordinate closely. Note that \p Level cannot be `O0` here. The pipelines produced are only intended for use when attempting to optimize code. If frontends require some transformations for semantic reasons, they should explicitly build them.

Declared at: llvm/include/llvm/Passes/PassBuilder.h:369

Parameters

llvm::PassBuilder::OptimizationLevel Level
bool DebugLogging
const llvm::ModuleSummaryIndex* ImportSummary

llvm::ModulePassManager
buildThinLTOPreLinkDefaultPipeline(
    llvm::PassBuilder::OptimizationLevel Level,
    bool DebugLogging = false)

Description

Build a pre-link, ThinLTO-targeting default optimization pipeline to a pass manager. This adds the pre-link optimizations tuned to prepare a module for a ThinLTO run. It works to minimize the IR which needs to be analyzed without making irreversible decisions which could be made better during the LTO run. Note that \p Level cannot be `O0` here. The pipelines produced are only intended for use when attempting to optimize code. If frontends require some transformations for semantic reasons, they should explicitly build them.

Declared at: llvm/include/llvm/Passes/PassBuilder.h:354

Parameters

llvm::PassBuilder::OptimizationLevel Level
bool DebugLogging = false

void crossRegisterProxies(
    llvm::LoopAnalysisManager& LAM,
    llvm::FunctionAnalysisManager& FAM,
    llvm::CGSCCAnalysisManager& CGAM,
    llvm::ModuleAnalysisManager& MAM)

Description

Cross register the analysis managers through their proxies. This is an interface that can be used to cross register each AnalysisManager with all the others analysis managers.

Declared at: llvm/include/llvm/Passes/PassBuilder.h:234

Parameters

llvm::LoopAnalysisManager& LAM
llvm::FunctionAnalysisManager& FAM
llvm::CGSCCAnalysisManager& CGAM
llvm::ModuleAnalysisManager& MAM

llvm::PassInstrumentationCallbacks*
getPassInstrumentationCallbacks() const

Description

Returns PIC. External libraries can use this to register pass instrumentation callbacks.

Declared at: llvm/include/llvm/Passes/PassBuilder.h:637

llvm::Error parseAAPipeline(
    llvm::AAManager& AA,
    llvm::StringRef PipelineText)

Description

Parse a textual alias analysis pipeline into the provided AA manager. The format of the textual AA pipeline is a comma separated list of AA pass names: basic-aa,globals-aa,... The AA manager is set up such that the provided alias analyses are tried in the order specified. See the \c AAManaager documentation for details about the logic used. This routine just provides the textual mapping between AA names and the analyses to register with the manager. Returns false if the text cannot be parsed cleanly. The specific state of the \p AA manager is unspecified if such an error is encountered and this returns false.

Declared at: llvm/include/llvm/Passes/PassBuilder.h:472

Parameters

llvm::AAManager& AA
llvm::StringRef PipelineText

llvm::Error parsePassPipeline(
    llvm::ModulePassManager& MPM,
    llvm::StringRef PipelineText,
    bool VerifyEachPass = true,
    bool DebugLogging = false)

Description

Parse a textual pass pipeline description into a \c ModulePassManager. The format of the textual pass pipeline description looks something like: module(function(instcombine,sroa),dce,cgscc(inliner,function(...)),...) Pass managers have ()s describing the nest structure of passes. All passes are comma separated. As a special shortcut, if the very first pass is not a module pass (as a module pass manager is), this will automatically form the shortest stack of pass managers that allow inserting that first pass. So, assuming function passes 'fpassN', CGSCC passes 'cgpassN', and loop passes 'lpassN', all of these are valid: fpass1,fpass2,fpass3 cgpass1,cgpass2,cgpass3 lpass1,lpass2,lpass3 And they are equivalent to the following (resp.): module(function(fpass1,fpass2,fpass3)) module(cgscc(cgpass1,cgpass2,cgpass3)) module(function(loop(lpass1,lpass2,lpass3))) This shortcut is especially useful for debugging and testing small pass combinations. Note that these shortcuts don't introduce any other magic. If the sequence of passes aren't all the exact same kind of pass, it will be an error. You cannot mix different levels implicitly, you must explicitly form a pass manager in which to nest passes.

Declared at: llvm/include/llvm/Passes/PassBuilder.h:435

Parameters

llvm::ModulePassManager& MPM
llvm::StringRef PipelineText
bool VerifyEachPass = true
bool DebugLogging = false

llvm::Error parsePassPipeline(
    llvm::CGSCCPassManager& CGPM,
    llvm::StringRef PipelineText,
    bool VerifyEachPass = true,
    bool DebugLogging = false)

Description

{{ @ Parse a textual pass pipeline description into a specific PassManager Automatic deduction of an appropriate pass manager stack is not supported. For example, to insert a loop pass 'lpass' into a FunctionPassManager, this is the valid pipeline text: function(lpass)

Declared at: llvm/include/llvm/Passes/PassBuilder.h:446

Parameters

llvm::CGSCCPassManager& CGPM
llvm::StringRef PipelineText
bool VerifyEachPass = true
bool DebugLogging = false

llvm::Error parsePassPipeline(
    llvm::FunctionPassManager& FPM,
    llvm::StringRef PipelineText,
    bool VerifyEachPass = true,
    bool DebugLogging = false)

Declared at: llvm/include/llvm/Passes/PassBuilder.h:449

Parameters

llvm::FunctionPassManager& FPM
llvm::StringRef PipelineText
bool VerifyEachPass = true
bool DebugLogging = false

llvm::Error parsePassPipeline(
    llvm::LoopPassManager& LPM,
    llvm::StringRef PipelineText,
    bool VerifyEachPass = true,
    bool DebugLogging = false)

Declared at: llvm/include/llvm/Passes/PassBuilder.h:452

Parameters

llvm::LoopPassManager& LPM
llvm::StringRef PipelineText
bool VerifyEachPass = true
bool DebugLogging = false

void registerAnalysisRegistrationCallback(
    const std::function<
        void(ModuleAnalysisManager&)>& C)

Declared at: llvm/include/llvm/Passes/PassBuilder.h:585

Parameters

const std::function<void(ModuleAnalysisManager&)>& C

void registerAnalysisRegistrationCallback(
    const std::function<
        void(LoopAnalysisManager&)>& C)

Declared at: llvm/include/llvm/Passes/PassBuilder.h:581

Parameters

const std::function<void(LoopAnalysisManager&)>& C

void registerAnalysisRegistrationCallback(
    const std::function<
        void(FunctionAnalysisManager&)>& C)

Declared at: llvm/include/llvm/Passes/PassBuilder.h:577

Parameters

const std::function<void( FunctionAnalysisManager&)>& C

void registerAnalysisRegistrationCallback(
    const std::function<
        void(CGSCCAnalysisManager&)>& C)

Description

{{ @ Register callbacks for analysis registration with this PassBuilder instance. Callees register their analyses with the given AnalysisManager objects.

Declared at: llvm/include/llvm/Passes/PassBuilder.h:573

Parameters

const std::function<void(CGSCCAnalysisManager&)>& C

void registerCGSCCAnalyses(
    llvm::CGSCCAnalysisManager& CGAM)

Description

Registers all available CGSCC analysis passes. This is an interface that can be used to populate a \c CGSCCAnalysisManager with all registered CGSCC analyses. Callers can still manually register any additional analyses. Callers can also pre-register analyses and this will not override those.

Declared at: llvm/include/llvm/Passes/PassBuilder.h:253

Parameters

llvm::CGSCCAnalysisManager& CGAM

void registerCGSCCOptimizerLateEPCallback(
    const std::function<void(CGSCCPassManager&,
                             OptimizationLevel)>&
        C)

Description

Register a callback for a default optimizer pipeline extension point This extension point allows adding CallGraphSCC passes at the end of the main CallGraphSCC passes and before any function simplification passes run by CGPassManager.

Declared at: llvm/include/llvm/Passes/PassBuilder.h:525

Parameters

const std::function<void(CGSCCPassManager&, OptimizationLevel)>& C

void registerFunctionAnalyses(
    llvm::FunctionAnalysisManager& FAM)

Description

Registers all available function analysis passes. This is an interface that can be used to populate a \c FunctionAnalysisManager with all registered function analyses. Callers can still manually register any additional analyses. Callers can also pre-register analyses and this will not override those.

Declared at: llvm/include/llvm/Passes/PassBuilder.h:261

Parameters

llvm::FunctionAnalysisManager& FAM

void registerLateLoopOptimizationsEPCallback(
    const std::function<void(LoopPassManager&,
                             OptimizationLevel)>&
        C)

Description

Register a callback for a default optimizer pipeline extension point This extension point allows adding late loop canonicalization and simplification passes. This is the last point in the loop optimization pipeline before loop deletion. Each pass added here must be an instance of LoopPass. This is the place to add passes that can remove loops, such as target- specific loop idiom recognition.

Declared at: llvm/include/llvm/Passes/PassBuilder.h:494

Parameters

const std::function<void(LoopPassManager&, OptimizationLevel)>& C

void registerLoopAnalyses(
    llvm::LoopAnalysisManager& LAM)

Description

Registers all available loop analysis passes. This is an interface that can be used to populate a \c LoopAnalysisManager with all registered loop analyses. Callers can still manually register any additional analyses.

Declared at: llvm/include/llvm/Passes/PassBuilder.h:268

Parameters

llvm::LoopAnalysisManager& LAM

void registerLoopOptimizerEndEPCallback(
    const std::function<void(LoopPassManager&,
                             OptimizationLevel)>&
        C)

Description

Register a callback for a default optimizer pipeline extension point This extension point allows adding loop passes to the end of the loop optimizer.

Declared at: llvm/include/llvm/Passes/PassBuilder.h:504

Parameters

const std::function<void(LoopPassManager&, OptimizationLevel)>& C

void registerModuleAnalyses(
    llvm::ModuleAnalysisManager& MAM)

Description

Registers all available module analysis passes. This is an interface that can be used to populate a \c ModuleAnalysisManager with all registered module analyses. Callers can still manually register any additional analyses. Callers can also pre-register analyses and this will not override those.

Declared at: llvm/include/llvm/Passes/PassBuilder.h:245

Parameters

llvm::ModuleAnalysisManager& MAM

void registerOptimizerLastEPCallback(
    const std::function<void(FunctionPassManager&,
                             OptimizationLevel)>&
        C)

Description

Register a callback for a default optimizer pipeline extension point This extension point allows adding optimizations at the very end of the function optimization pipeline. A key difference between this and the legacy PassManager's OptimizerLast callback is that this extension point is not triggered at O0. Extensions to the O0 pipeline should append their passes to the end of the overall pipeline.

Declared at: llvm/include/llvm/Passes/PassBuilder.h:558

Parameters

const std::function<void(FunctionPassManager&, OptimizationLevel)>& C

void registerParseAACallback(
    const std::function<bool(StringRef,
                             AAManager&)>& C)

Description

Register a callback for parsing an AliasAnalysis Name to populate the given AAManager \p AA

Declared at: llvm/include/llvm/Passes/PassBuilder.h:565

Parameters

const std::function<bool(StringRef, AAManager&)>& C

void registerParseTopLevelPipelineCallback(
    const std::function<
        bool(ModulePassManager&,
             ArrayRef<PipelineElement>,
             bool,
             bool)>& C)

Description

Register a callback for a top-level pipeline entry. If the PassManager type is not given at the top level of the pipeline text, this Callback should be used to determine the appropriate stack of PassManagers and populate the passed ModulePassManager.

Declared at: llvm/include/llvm/Passes/PassBuilder.h:622

Parameters

const std::function<bool( ModulePassManager&, ArrayRef<PipelineElement>, bool, bool)>& C

void registerPeepholeEPCallback(
    const std::function<void(FunctionPassManager&,
                             OptimizationLevel)>&
        C)

Description

Register a callback for a default optimizer pipeline extension point This extension point allows adding passes that perform peephole optimizations similar to the instruction combiner. These passes will be inserted after each instance of the instruction combiner pass.

Declared at: llvm/include/llvm/Passes/PassBuilder.h:480

Parameters

const std::function<void(FunctionPassManager&, OptimizationLevel)>& C

void registerPipelineParsingCallback(
    const std::function<
        bool(StringRef,
             CGSCCPassManager&,
             ArrayRef<PipelineElement>)>& C)

Description

{{ @ Register pipeline parsing callbacks with this pass builder instance. Using these callbacks, callers can parse both a single pass name, as well as entire sub-pipelines, and populate the PassManager instance accordingly.

Declared at: llvm/include/llvm/Passes/PassBuilder.h:595

Parameters

const std::function<bool( StringRef, CGSCCPassManager&, ArrayRef<PipelineElement>)>& C

void registerPipelineParsingCallback(
    const std::function<
        bool(StringRef,
             FunctionPassManager&,
             ArrayRef<PipelineElement>)>& C)

Declared at: llvm/include/llvm/Passes/PassBuilder.h:600

Parameters

const std::function<bool( StringRef, FunctionPassManager&, ArrayRef<PipelineElement>)>& C

void registerPipelineParsingCallback(
    const std::function<
        bool(StringRef,
             LoopPassManager&,
             ArrayRef<PipelineElement>)>& C)

Declared at: llvm/include/llvm/Passes/PassBuilder.h:605

Parameters

const std::function<bool( StringRef, LoopPassManager&, ArrayRef<PipelineElement>)>& C

void registerPipelineParsingCallback(
    const std::function<
        bool(StringRef,
             ModulePassManager&,
             ArrayRef<PipelineElement>)>& C)

Declared at: llvm/include/llvm/Passes/PassBuilder.h:610

Parameters

const std::function<bool( StringRef, ModulePassManager&, ArrayRef<PipelineElement>)>& C

void registerPipelineStartEPCallback(
    const std::function<void(ModulePassManager&)>&
        C)

Description

Register a callback for a default optimizer pipeline extension point. This extension point allows adding optimization once at the start of the pipeline. This does not apply to 'backend' compiles (LTO and ThinLTO link-time pipelines).

Declared at: llvm/include/llvm/Passes/PassBuilder.h:546

Parameters

const std::function<void(ModulePassManager&)>& C

void registerScalarOptimizerLateEPCallback(
    const std::function<void(FunctionPassManager&,
                             OptimizationLevel)>&
        C)

Description

Register a callback for a default optimizer pipeline extension point This extension point allows adding optimization passes after most of the main optimizations, but before the last cleanup-ish optimizations.

Declared at: llvm/include/llvm/Passes/PassBuilder.h:514

Parameters

const std::function<void(FunctionPassManager&, OptimizationLevel)>& C

void registerVectorizerStartEPCallback(
    const std::function<void(FunctionPassManager&,
                             OptimizationLevel)>&
        C)

Description

Register a callback for a default optimizer pipeline extension point This extension point allows adding optimization passes before the vectorizer and other highly target specific optimization passes are executed.

Declared at: llvm/include/llvm/Passes/PassBuilder.h:536

Parameters

const std::function<void(FunctionPassManager&, OptimizationLevel)>& C