LLVM's Analysis and Transform Passes
  1. Introduction
  2. Analysis Passes
  3. Transform Passes
  4. Utility Passes

Written by Reid Spencer and Gordon Henriksen

Introduction

This document serves as a high level summary of the optimization features that LLVM provides. Optimizations are implemented as Passes that traverse some portion of a program to either collect information or transform the program. The table below divides the passes that LLVM provides into three categories. Analysis passes compute information that other passes can use or for debugging or program visualization purposes. Transform passes can use (or invalidate) the analysis passes. Transform passes all mutate the program in some way. Utility passes provides some utility but don't otherwise fit categorization. For example passes to extract functions to bitcode or write a module to bitcode are neither analysis nor transform passes.

The table below provides a quick summary of each pass and links to the more complete pass description later in the document.

ANALYSIS PASSES
OptionName
-aa-evalExhaustive Alias Analysis Precision Evaluator
-anders-aaAndersen's Interprocedural Alias Analysis
-basicaaBasic Alias Analysis (default AA impl)
-basiccgBasic CallGraph Construction
-basicvnBasic Value Numbering (default GVN impl)
-callgraphPrint a call graph
-callsccPrint SCCs of the Call Graph
-cfgsccPrint SCCs of each function CFG
-codegenprepareOptimize for code generation
-count-aaCount Alias Analysis Query Responses
-debug-aaAA use debugger
-domfrontierDominance Frontier Construction
-domtreeDominator Tree Construction
-externalfnconstantsPrint external fn callsites passed constants
-globalsmodref-aaSimple mod/ref analysis for globals
-instcountCounts the various types of Instructions
-intervalsInterval Partition Construction
-load-vnLoad Value Numbering
-loopsNatural Loop Construction
-memdepMemory Dependence Analysis
-no-aaNo Alias Analysis (always returns 'may' alias)
-no-profileNo Profile Information
-postdomfrontierPost-Dominance Frontier Construction
-postdomtreePost-Dominator Tree Construction
-printPrint function to stderr
-print-alias-setsAlias Set Printer
-print-callgraphPrint Call Graph to 'dot' file
-print-cfgPrint CFG of function to 'dot' file
-print-cfg-onlyPrint CFG of function to 'dot' file (with no function bodies)
-printmPrint module to stderr
-printusedtypesFind Used Types
-profile-loaderLoad profile information from llvmprof.out
-scalar-evolutionScalar Evolution Analysis
-targetdataTarget Data Layout
TRANSFORM PASSES
OptionName
-adceAggressive Dead Code Elimination
-argpromotionPromote 'by reference' arguments to scalars
-block-placementProfile Guided Basic Block Placement
-break-crit-edgesBreak critical edges in CFG
-ceeCorrelated Expression Elimination
-condpropConditional Propagation
-constmergeMerge Duplicate Global Constants
-constpropSimple constant propagation
-dceDead Code Elimination
-deadargelimDead Argument Elimination
-deadtypeelimDead Type Elimination
-dieDead Instruction Elimination
-dseDead Store Elimination
-gcseGlobal Common Subexpression Elimination
-globaldceDead Global Elimination
-globaloptGlobal Variable Optimizer
-gvnGlobal Value Numbering
-gvnpreGlobal Value Numbering/Partial Redundancy Elimination
-indmemremIndirect Malloc and Free Removal
-indvarsCanonicalize Induction Variables
-inlineFunction Integration/Inlining
-insert-block-profilingInsert instrumentation for block profiling
-insert-edge-profilingInsert instrumentation for edge profiling
-insert-function-profilingInsert instrumentation for function profiling
-insert-null-profiling-rsMeasure profiling framework overhead
-insert-rs-profiling-frameworkInsert random sampling instrumentation framework
-instcombineCombine redundant instructions
-internalizeInternalize Global Symbols
-ipconstpropInterprocedural constant propagation
-ipsccpInterprocedural Sparse Conditional Constant Propagation
-lcssaLoop-Closed SSA Form Pass
-licmLoop Invariant Code Motion
-loop-extractExtract loops into new functions
-loop-extract-singleExtract at most one loop into a new function
-loop-index-splitIndex Split Loops
-loop-reduceLoop Strength Reduction
-loop-rotateRotate Loops
-loop-unrollUnroll loops
-loop-unswitchUnswitch loops
-loopsimplifyCanonicalize natural loops
-lower-packedlowers packed operations to operations on smaller packed datatypes
-lowerallocsLower allocations from instructions to calls
-lowergcLower GC intrinsics, for GCless code generators
-lowerinvokeLower invoke and unwind, for unwindless code generators
-lowerselectLower select instructions to branches
-lowersetjmpLower Set Jump
-lowerswitchLower SwitchInst's to branches
-mem2regPromote Memory to Register
-mergereturnUnify function exit nodes
-predsimplifyPredicate Simplifier
-prune-ehRemove unused exception handling info
-raiseallocsRaise allocations from calls to instructions
-reassociateReassociate expressions
-reg2memDemote all values to stack slots
-scalarreplScalar Replacement of Aggregates
-sccpSparse Conditional Constant Propagation
-simplify-libcallsSimplify well-known library calls
-simplifycfgSimplify the CFG
-stripStrip all symbols from a module
-tailcallelimTail Call Elimination
-tailduplicateTail Duplication
UTILITY PASSES
OptionName
-deadarghaX0rDead Argument Hacking (BUGPOINT USE ONLY; DO NOT USE)
-extract-blocksExtract Basic Blocks From Module (for bugpoint use)
-emitbitcodeBitcode Writer
-verifyModule Verifier
-view-cfgView CFG of function
-view-cfg-onlyView CFG of function (with no function bodies)
Analysis Passes

This section describes the LLVM Analysis Passes.

Exhaustive Alias Analysis Precision Evaluator

This is a simple N^2 alias analysis accuracy evaluator. Basically, for each function in the program, it simply queries to see how the alias analysis implementation answers alias queries between each pair of pointers in the function.

This is inspired and adapted from code by: Naveen Neelakantam, Francesco Spadini, and Wojciech Stryjewski.

Andersen's Interprocedural Alias Analysis

This is an implementation of Andersen's interprocedural alias analysis

In pointer analysis terms, this is a subset-based, flow-insensitive, field-sensitive, and context-insensitive algorithm pointer algorithm.

This algorithm is implemented as three stages:

  1. Object identification.
  2. Inclusion constraint identification.
  3. Offline constraint graph optimization.
  4. Inclusion constraint solving.

The object identification stage identifies all of the memory objects in the program, which includes globals, heap allocated objects, and stack allocated objects.

The inclusion constraint identification stage finds all inclusion constraints in the program by scanning the program, looking for pointer assignments and other statements that effect the points-to graph. For a statement like A = B, this statement is processed to indicate that A can point to anything that B can point to. Constraints can handle copies, loads, and stores, and address taking.

The offline constraint graph optimization portion includes offline variable substitution algorithms intended to computer pointer and location equivalences. Pointer equivalences are those pointers that will have the same points-to sets, and location equivalences are those variables that always appear together in points-to sets.

The inclusion constraint solving phase iteratively propagates the inclusion constraints until a fixed point is reached. This is an O(n³) algorithm.

Function constraints are handled as if they were structs with X fields. Thus, an access to argument X of function Y is an access to node index getNode(Y) + X. This representation allows handling of indirect calls without any issues. To wit, an indirect call Y(a,b) is equivalent to *(Y + 1) = a, *(Y + 2) = b. The return node for a function F is always located at getNode(F) + CallReturnPos. The arguments start at getNode(F) + CallArgPos.

Basic Alias Analysis (default AA impl)

This is the default implementation of the Alias Analysis interface that simply implements a few identities (two different globals cannot alias, etc), but otherwise does no analysis.

Basic CallGraph Construction

Yet to be written.

Basic Value Numbering (default GVN impl)

This is the default implementation of the ValueNumbering interface. It walks the SSA def-use chains to trivially identify lexically identical expressions. This does not require any ahead of time analysis, so it is a very fast default implementation.

Print a call graph

This pass, only available in opt, prints the call graph into a .dot graph. This graph can then be processed with the "dot" tool to convert it to postscript or some other suitable format.

Print SCCs of the Call Graph

This pass, only available in opt, prints the SCCs of the call graph to standard output in a human-readable form.

Print SCCs of each function CFG

This pass, only available in opt, prints the SCCs of each function CFG to standard output in a human-readable form.

Optimize for code generation

This pass munges the code in the input function to better prepare it for SelectionDAG-based code generation. This works around limitations in it's basic-block-at-a-time approach. It should eventually be removed.

Count Alias Analysis Query Responses

A pass which can be used to count how many alias queries are being made and how the alias analysis implementation being used responds.

AA use debugger

This simple pass checks alias analysis users to ensure that if they create a new value, they do not query AA without informing it of the value. It acts as a shim over any other AA pass you want.

Yes keeping track of every value in the program is expensive, but this is a debugging pass.

Dominance Frontier Construction

This pass is a simple dominator construction algorithm for finding forward dominator frontiers.

Dominator Tree Construction

This pass is a simple dominator construction algorithm for finding forward dominators.

Print external fn callsites passed constants

This pass, only available in opt, prints out call sites to external functions that are called with constant arguments. This can be useful when looking for standard library functions we should constant fold or handle in alias analyses.

Simple mod/ref analysis for globals

This simple pass provides alias and mod/ref information for global values that do not have their address taken, and keeps track of whether functions read or write memory (are "pure"). For this simple (but very common) case, we can provide pretty accurate and useful information.

Counts the various types of Instructions

This pass collects the count of all instructions and reports them

Interval Partition Construction

This analysis calculates and represents the interval partition of a function, or a preexisting interval partition.

In this way, the interval partition may be used to reduce a flow graph down to its degenerate single node interval partition (unless it is irreducible).

Load Value Numbering

This pass value numbers load and call instructions. To do this, it finds lexically identical load instructions, and uses alias analysis to determine which loads are guaranteed to produce the same value. To value number call instructions, it looks for calls to functions that do not write to memory which do not have intervening instructions that clobber the memory that is read from.

This pass builds off of another value numbering pass to implement value numbering for non-load and non-call instructions. It uses Alias Analysis so that it can disambiguate the load instructions. The more powerful these base analyses are, the more powerful the resultant value numbering will be.

Natural Loop Construction

This analysis is used to identify natural loops and determine the loop depth of various nodes of the CFG. Note that the loops identified may actually be several natural loops that share the same header node... not just a single natural loop.

Memory Dependence Analysis

Yet to be written.

No Alias Analysis (always returns 'may' alias)

Yet to be written.

No Profile Information

Yet to be written.

Post-Dominance Frontier Construction

Yet to be written.

Post-Dominator Tree Construction

Yet to be written.

Print function to stderr

Yet to be written.

Alias Set Printer

Yet to be written.

Print Call Graph to 'dot' file

Yet to be written.

Print CFG of function to 'dot' file

Yet to be written.

Print CFG of function to 'dot' file (with no function bodies)

Yet to be written.

Print module to stderr

Yet to be written.

Find Used Types

Yet to be written.

Load profile information from llvmprof.out

Yet to be written.

Scalar Evolution Analysis

Yet to be written.

Target Data Layout

Yet to be written.

Transform Passes

This section describes the LLVM Transform Passes.

Aggressive Dead Code Elimination

ADCE aggressively tries to eliminate code. This pass is similar to DCE but it assumes that values are dead until proven otherwise. This is similar to SCCP, except applied to the liveness of values.

Promote 'by reference' arguments to scalars

Yet to be written.

Profile Guided Basic Block Placement

This pass implements a very simple profile guided basic block placement algorithm. The idea is to put frequently executed blocks together at the start of the function, and hopefully increase the number of fall-through conditional branches. If there is no profile information for a particular function, this pass basically orders blocks in depth-first order.

The algorithm implemented here is basically "Algo1" from "Profile Guided Code Positioning" by Pettis and Hansen, except that it uses basic block counts instead of edge counts. This could be improved in many ways, but is very simple for now.

Basically we "place" the entry block, then loop over all successors in a DFO, placing the most frequently executed successor until we run out of blocks. Did we mention that this was extremely simplistic? This is also much slower than it could be. When it becomes important, this pass will be rewritten to use a better algorithm, and then we can worry about efficiency.

Break critical edges in CFG

Yet to be written.

Correlated Expression Elimination

Correlated Expression Elimination propagates information from conditional branches to blocks dominated by destinations of the branch. It propagates information from the condition check itself into the body of the branch, allowing transformations like these for example:

if (i == 7)
  ... 4*i;  // constant propagation

M = i+1; N = j+1;
if (i == j)
  X = M-N;  // = M-M == 0;

This is called Correlated Expression Elimination because we eliminate or simplify expressions that are correlated with the direction of a branch. In this way we use static information to give us some information about the dynamic value of a variable.

Conditional Propagation

This pass propagates information about conditional expressions through the program, allowing it to eliminate conditional branches in some cases.

Merge Duplicate Global Constants

Yet to be written.

Simple constant propagation

This file implements constant propagation and merging. It looks for instructions involving only constant operands and replaces them with a constant value instead of an instruction. For example:

add i32 1, 2

becomes

i32 3

NOTE: this pass has a habit of making definitions be dead. It is a good idea to to run a DIE (Dead Instruction Elimination) pass sometime after running this pass.

Dead Code Elimination

Yet to be written.

Dead Argument Elimination

Yet to be written.

Dead Type Elimination

Yet to be written.

Dead Instruction Elimination

Yet to be written.

Dead Store Elimination

Yet to be written.

Global Common Subexpression Elimination

Yet to be written.

Dead Global Elimination

Yet to be written.

Global Variable Optimizer

Yet to be written.

Global Value Numbering

This pass performs global value numbering to eliminate fully redundant instructions. It also performs simple dead load elimination.

Global Value Numbering/Partial Redundancy Elimination

This pass performs a hybrid of global value numbering and partial redundancy elimination, known as GVN-PRE. It performs partial redundancy elimination on values, rather than lexical expressions, allowing a more comprehensive view the optimization. It replaces redundant values with uses of earlier occurences of the same value. While this is beneficial in that it eliminates unneeded computation, it also increases register pressure by creating large live ranges, and should be used with caution on platforms that are very sensitive to register pressure.

Indirect Malloc and Free Removal

Yet to be written.

Canonicalize Induction Variables

Yet to be written.

Function Integration/Inlining

Yet to be written.

Insert instrumentation for block profiling

Yet to be written.

Insert instrumentation for edge profiling

Yet to be written.

Insert instrumentation for function profiling

Yet to be written.

Measure profiling framework overhead

Yet to be written.

Insert random sampling instrumentation framework

Yet to be written.

Combine redundant instructions

Yet to be written.

Internalize Global Symbols

Yet to be written.

Interprocedural constant propagation

Yet to be written.

Interprocedural Sparse Conditional Constant Propagation

Yet to be written.

Loop-Closed SSA Form Pass

Yet to be written.

Loop Invariant Code Motion

Yet to be written.

Extract loops into new functions

Yet to be written.

Extract at most one loop into a new function

Yet to be written.

Index Split Loops

Yet to be written.

Loop Strength Reduction

Yet to be written.

Rotate Loops

Yet to be written.

Unroll loops

Yet to be written.

Unswitch loops

Yet to be written.

Canonicalize natural loops

Yet to be written.

lowers packed operations to operations on smaller packed datatypes

Yet to be written.

Lower allocations from instructions to calls

Yet to be written.

Lower GC intrinsics, for GCless code generators

Yet to be written.

Lower invoke and unwind, for unwindless code generators

Yet to be written.

Lower select instructions to branches

Yet to be written.

Lower Set Jump

Yet to be written.

Lower SwitchInst's to branches

Yet to be written.

Promote Memory to Register

Yet to be written.

Unify function exit nodes

Yet to be written.

Predicate Simplifier

Yet to be written.

Remove unused exception handling info

Yet to be written.

Raise allocations from calls to instructions

Yet to be written.

Reassociate expressions

Yet to be written.

Demote all values to stack slots

Yet to be written.

Scalar Replacement of Aggregates

Yet to be written.

Sparse Conditional Constant Propagation

Yet to be written.

Simplify well-known library calls

Yet to be written.

Simplify the CFG

Yet to be written.

Strip all symbols from a module

Yet to be written.

Tail Call Elimination

Yet to be written.

Tail Duplication

Yet to be written.

Utility Passes

This section describes the LLVM Utility Passes.

Dead Argument Hacking (BUGPOINT USE ONLY; DO NOT USE)

Yet to be written.

Extract Basic Blocks From Module (for bugpoint use)

Yet to be written.

Bitcode Writer

Yet to be written.

Module Verifier

Yet to be written.

View CFG of function

Yet to be written.

View CFG of function (with no function bodies)

Yet to be written.


Valid CSS! Valid HTML 4.01! Reid Spencer
LLVM Compiler Infrastructure
Last modified: $Date$