PassPipeliner

public final class PassPipeliner

Implements a pass manager, pipeliner, and executor for a set of user-provided optimization passes.

A PassPipeliner handles the creation of a related set of optimization passes called a “pipeline”. Grouping passes is done for multiple reasons, chief among them is that optimizer passes are extremely sensitive to their ordering relative to other passes. In addition, pass groupings allow for the clean segregation of otherwise unrelated passes. For example, a pipeline might consist of “mandatory” passes such as Jump Threading, LICM, and DCE in one pipeline and “diagnostic” passes in another.

  • The module for this pass pipeline.

    Declaration

    Swift

    public let module: Module
  • The pipeline stages registered with this pass pipeliner.

    Declaration

    Swift

    public private(set) var stages: [String] { get }
  • A helper object that can add passes to a pipeline.

    To add a new pass, call add(_:).

    See more

    Declaration

    Swift

    public final class Builder
  • Initializes a new, empty pipeliner.

    Declaration

    Swift

    public init(module: Module)

    Parameters

    module

    The module the pipeliner will run over.

  • Appends a stage to the pipeliner.

    The staging function provides a Builder object into which the types of passes for a given pipeline are inserted.

    Declaration

    Swift

    public func addStage(_ name: String, _ stager: (Builder) -> Void)

    Parameters

    name

    The name of the pipeline stage.

    stager

    A builder function.

  • Executes the entirety of the pass pipeline.

    Execution of passes is done in a loop that is divided into two phases. The first phase aggregates all local passes and stops aggregation when it encounters a module-level pass. This group of local passes is then run one at a time on the same scope. The second phase is entered and the module pass is run. The first phase is then re-entered until all local passes have run on all local scopes and all intervening module passes have been run.

    The same pipeline may be repeatedly re-executed, but pipeline execution is not re-entrancy safe.

    Declaration

    Swift

    public func execute(mask pipelineMask: Set<String> = [])

    Parameters

    pipelineMask

    Describes the subset of pipelines that should be executed. If the mask is empty, all pipelines will be executed.

Standard Pass Pipelines

  • Adds a pipeline stage populated with function passes that LLVM considers standard for languages like C and C++. Additional parameters are available to tune the overall behavior of the optimization pipeline at a macro level.

    Declaration

    Swift

    public func addStandardFunctionPipeline(
      _ name: String,
      optimization: CodeGenOptLevel = .`default`,
      size: CodeGenOptLevel = .none
    )

    Parameters

    name

    The name of the pipeline stage.

    optimization

    The level of optimization.

    size

    The level of size optimization.

  • Adds a pipeline stage populated with module passes that LLVM considers standard for languages like C and C++. Additional parameters are available to tune the overall behavior of the optimization pipeline at a macro level.

    Declaration

    Swift

    public func addStandardModulePipeline(
      _ name: String,
      optimization: CodeGenOptLevel = .`default`,
      size: CodeGenOptLevel = .none
    )

    Parameters

    name

    The name of the pipeline stage.

    optimization

    The level of optimization.

    size

    The level of size optimization.