Pass

public enum Pass

A subset of supported LLVM IR optimizer passes.

  • This pass uses the SSA based Aggressive DCE algorithm. This algorithm assumes instructions are dead until proven otherwise, which makes it more successful are removing non-obviously dead instructions.

    Declaration

    Swift

    case aggressiveDCE
  • This pass uses a bit-tracking DCE algorithm in order to remove computations of dead bits.

    Declaration

    Swift

    case bitTrackingDCE
  • Use assume intrinsics to set load/store alignments.

    Declaration

    Swift

    case alignmentFromAssumptions
  • Merge basic blocks, eliminate unreachable blocks, simplify terminator instructions, etc.

    Declaration

    Swift

    case cfgSimplification
  • This pass deletes stores that are post-dominated by must-aliased stores and are not loaded used between the stores.

    Declaration

    Swift

    case deadStoreElimination
  • Converts vector operations into scalar operations.

    Declaration

    Swift

    case scalarizer
  • This pass merges loads and stores in diamonds. Loads are hoisted into the header, while stores sink into the footer.

    Declaration

    Swift

    case mergedLoadStoreMotion
  • gvn

    This pass performs global value numbering and redundant load elimination cotemporaneously.

    Declaration

    Swift

    case gvn
  • Transform induction variables in a program to all use a single canonical induction variable per loop.

    Declaration

    Swift

    case indVarSimplify
  • Combine instructions to form fewer, simple instructions. This pass does not modify the CFG, and has a tendency to make instructions dead, so a subsequent DCE pass is useful.

    This pass combines things like:

    %Y = add int 1, %X
    %Z = add int 1, %Y
    

    into:

    %Z = add int 2, %X
    

    Declaration

    Swift

    case instructionCombining
  • Working in conjunction with the linker, iterate through all functions and global values in the module and attempt to change their linkage from external to internal.

    To preserve the linkage of a global value, return true from the given callback.

    Declaration

    Swift

    case internalize(mustPreserve: (IRGlobal) -> Bool)
  • Working in conjunction with the linker, iterate through all functions and global values in the module and attempt to change their linkage from external to internal.

    When a function with the name “main” is encountered, if the value of preserveMain is true, “main” will not be internalized.

    Declaration

    Swift

    case internalizeAll(preserveMain: Bool)
  • Thread control through mult-pred/multi-succ blocks where some preds always go to some succ. Thresholds other than minus one override the internal BB duplication default threshold.

    Declaration

    Swift

    case jumpThreading
  • This pass is a loop invariant code motion and memory promotion pass.

    Declaration

    Swift

    case licm
  • This pass performs DCE of non-infinite loops that it can prove are dead.

    Declaration

    Swift

    case loopDeletion
  • This pass recognizes and replaces idioms in loops.

    Declaration

    Swift

    case loopIdiom
  • This pass is a simple loop rotating pass.

    Declaration

    Swift

    case loopRotate
  • This pass is a simple loop rerolling pass.

    Declaration

    Swift

    case loopReroll
  • This pass is a simple loop unrolling pass.

    Declaration

    Swift

    case loopUnroll
  • This pass is a simple loop unroll-and-jam pass.

    Declaration

    Swift

    case loopUnrollAndJam
  • This pass is a simple loop unswitching pass.

    Declaration

    Swift

    case loopUnswitch
  • This pass lowers atomic intrinsics to non-atomic form for use in a known non-preemptible environment.

    Declaration

    Swift

    case lowerAtomic
  • This pass performs optimizations related to eliminating memcpy calls and/or combining multiple stores into memset’s.

    Declaration

    Swift

    case memCpyOpt
  • Tries to inline the fast path of library calls such as sqrt.

    Declaration

    Swift

    case partiallyInlineLibCalls
  • This pass converts SwitchInst instructions into a sequence of chained binary branch instructions.

    Declaration

    Swift

    case lowerSwitch
  • This pass is used to promote memory references to be register references. A simple example of the transformation performed by this pass is going from code like this:

    %X = alloca i32, i32 1
    store i32 42, i32 *%X
    %Y = load i32* %X
    ret i32 %Y
    

    To code like this:

    ret i32 42
    

    Declaration

    Swift

    case promoteMemoryToRegister
  • Adds DWARF discriminators to the IR. Discriminators are used to decide what CFG path was taken inside sub-graphs whose instructions share the same line and column number information.

    Declaration

    Swift

    case addDiscriminators
  • This pass reassociates commutative expressions in an order that is designed to promote better constant propagation, GCSE, LICM, PRE, etc.

    For example:

    4 + (x + 5)  ->  x + (4 + 5)
    

    Declaration

    Swift

    case reassociate
  • Sparse conditional constant propagation.

    Declaration

    Swift

    case sccp
  • This pass eliminates call instructions to the current function which occur immediately before return instructions.

    Declaration

    Swift

    case tailCallElimination
  • A worklist driven constant propagation pass.

    Declaration

    Swift

    case constantPropagation
  • This pass is used to demote registers to memory references. It basically undoes the .promoteMemoryToRegister pass to make CFG hacking easier.

    Declaration

    Swift

    case demoteMemoryToRegister
  • Propagate CFG-derived value information

    Declaration

    Swift

    case correlatedValuePropagation
  • This pass performs a simple and fast CSE pass over the dominator tree.

    Declaration

    Swift

    case earlyCSE
  • Removes llvm.expect intrinsics and creates “block_weights” metadata.

    Declaration

    Swift

    case lowerExpectIntrinsic
  • Adds metadata to LLVM IR types and performs metadata-based Type-Based Alias Analysis (TBAA).

    TBAA requires that two pointers to objects of different types must never alias. Because memory in LLVM is typeless, TBAA is performed using special metadata nodes describing aliasing relationships between types in the source language(s).

    To construct this metadata, see MDBuilder.

    Declaration

    Swift

    case typeBasedAliasAnalysis
  • Adds metadata to LLVM IR types and performs metadata-based scoped no-alias analysis.

    Declaration

    Swift

    case scopedNoAliasAA
  • LLVM’s primary stateless and local alias analysis.

    Given a pointer value, walk the use-def chain to find out how that pointer is used. The traversal terminates at global variables and aliases, stack allocations, and values of non-pointer types - referred to as “underlying objects”. Analysis may reach multiple underlying object values because of branching control flow. If the set of underlying objects for one pointer has a non-empty intersection with another, those two pointers are deemed mayalias. Else, an empty intersection deems those pointers noalias.

    Basic Alias Analysis should generally be scheduled ahead of other AA passes. This is because it is more conservative than other passes about declaring two pointers mustalias, and does so fairly efficiently. For example, loads through two members of a union with distinct types are declared by TBAA to be noalias, where BasicAA considers them mustalias.

    Declaration

    Swift

    case basicAliasAnalysis
  • Performs alias and mod/ref analysis for internal global values that do not have their address taken.

    Internal global variables that are only loaded from may be marked as constants.

    Declaration

    Swift

    case globalsAliasAnalysis
  • This pass is used to ensure that functions have at most one return instruction in them. Additionally, it keeps track of which node is the new exit node of the CFG.

    Declaration

    Swift

    case unifyFunctionExitNodes
  • Runs the LLVM IR Verifier to sanity check the results of passes.

    Declaration

    Swift

    case verifier
  • A pass to inline and remove functions marked as “always_inline”.

    Declaration

    Swift

    case alwaysInliner
  • This pass promotes “by reference” arguments to be passed by value if the number of elements passed is less than or equal to 3.

    Declaration

    Swift

    case argumentPromotion
  • This function returns a new pass that merges duplicate global constants together into a single constant that is shared. This is useful because some passes (ie TraceValues) insert a lot of string constants into the program, regardless of whether or not they duplicate an existing string.

    Declaration

    Swift

    case constantMerge
  • This pass removes arguments from functions which are not used by the body of the function.

    Declaration

    Swift

    case deadArgElimination
  • This pass walks SCCs of the call graph in RPO to deduce and propagate function attributes. Currently it only handles synthesizing norecurse attributes.

    Declaration

    Swift

    case functionAttrs
  • Uses a heuristic to inline direct function calls to small functions.

    Declaration

    Swift

    case functionInlining
  • This transform is designed to eliminate unreachable internal globals (functions or global variables)

    Declaration

    Swift

    case globalDCE
  • This function returns a new pass that optimizes non-address taken internal globals.

    Declaration

    Swift

    case globalOptimizer
  • This pass propagates constants from call sites into the bodies of functions.

    Declaration

    Swift

    case ipConstantPropagation
  • This pass propagates constants from call sites into the bodies of functions, and keeps track of whether basic blocks are executable in the process.

    Declaration

    Swift

    case ipscc
  • Return a new pass object which transforms invoke instructions into calls, if the callee can not unwind the stack.

    Declaration

    Swift

    case pruneEH
  • This transformation attempts to discovery alloca allocations of aggregates that can be broken down into component scalar values.

    Declaration

    Swift

    case scalarReplacementOfAggregates
  • This pass removes any function declarations (prototypes) that are not used.

    Declaration

    Swift

    case stripDeadPrototypes
  • These functions removes symbols from functions and modules without touching symbols for debugging information.

    Declaration

    Swift

    case stripSymbols
  • Performs a loop vectorization pass to widen instructions in loops to operate on multiple consecutive iterations.

    Declaration

    Swift

    case loopVectorize
  • This pass performs a superword-level parallelism pass to combine similar independent instructions into vector instructions.

    Declaration

    Swift

    case slpVectorize
  • An invalid pass that crashes when added to the pass manager.

    Declaration

    Swift

    case invalid(reason: String)