1 //===-- Scalar.h - Scalar Transformations -----------------------*- C++ -*-===//
3 // This header file defines prototypes for accessor functions that expose passes
4 // in the Scalar transformations library.
6 //===----------------------------------------------------------------------===//
8 #ifndef LLVM_TRANSFORMS_SCALAR_H
9 #define LLVM_TRANSFORMS_SCALAR_H
13 class GetElementPtrInst;
17 //===----------------------------------------------------------------------===//
19 // RaisePointerReferences - Try to eliminate as many pointer arithmetic
20 // expressions as possible, by converting expressions to use getelementptr and
23 Pass *createRaisePointerReferencesPass();
25 //===----------------------------------------------------------------------===//
27 // Constant Propagation Pass - A worklist driven constant propagation pass
29 Pass *createConstantPropagationPass();
32 //===----------------------------------------------------------------------===//
34 // Sparse Conditional Constant Propagation Pass
36 Pass *createSCCPPass();
39 //===----------------------------------------------------------------------===//
41 // DeadInstElimination - This pass quickly removes trivially dead instructions
42 // without modifying the CFG of the function. It is a BasicBlockPass, so it
43 // runs efficiently when queued next to other BasicBlockPass's.
45 Pass *createDeadInstEliminationPass();
48 //===----------------------------------------------------------------------===//
50 // DeadCodeElimination - This pass is more powerful than DeadInstElimination,
51 // because it is worklist driven that can potentially revisit instructions when
52 // their other instructions become dead, to eliminate chains of dead
55 Pass *createDeadCodeEliminationPass();
58 //===----------------------------------------------------------------------===//
60 // AggressiveDCE - This pass uses the SSA based Aggressive DCE algorithm. This
61 // algorithm assumes instructions are dead until proven otherwise, which makes
62 // it more successful are removing non-obviously dead instructions.
64 Pass *createAggressiveDCEPass();
67 //===----------------------------------------------------------------------===//
69 // Scalar Replacement of Aggregates - Break up alloca's of aggregates into
70 // multiple allocas if possible.
72 Pass *createScalarReplAggregatesPass();
74 //===----------------------------------------------------------------------===//
76 // DecomposeMultiDimRefs - Convert multi-dimensional references consisting of
77 // any combination of 2 or more array and structure indices into a sequence of
78 // instructions (using getelementpr and cast) so that each instruction has at
79 // most one index (except structure references, which need an extra leading
82 // This pass decomposes all multi-dimensional references in a function.
83 FunctionPass *createDecomposeMultiDimRefsPass();
85 // This function decomposes a single instance of such a reference.
86 // Return value: true if the instruction was replaced; false otherwise.
88 bool DecomposeArrayRef(GetElementPtrInst* GEP);
90 //===----------------------------------------------------------------------===//
92 // GCSE - This pass is designed to be a very quick global transformation that
93 // eliminates global common subexpressions from a function. It does this by
94 // examining the SSA value graph of the function, instead of doing slow
95 // bit-vector computations.
97 Pass *createGCSEPass();
100 //===----------------------------------------------------------------------===//
102 // InductionVariableSimplify - Transform induction variables in a program to all
103 // use a single canonical induction variable per loop.
105 Pass *createIndVarSimplifyPass();
108 //===----------------------------------------------------------------------===//
110 // InstructionCombining - Combine instructions to form fewer, simple
111 // instructions. This pass does not modify the CFG, and has a tendancy to
112 // make instructions dead, so a subsequent DCE pass is useful.
114 // This pass combines things like:
115 // %Y = add int 1, %X
116 // %Z = add int 1, %Y
118 // %Z = add int 2, %X
120 Pass *createInstructionCombiningPass();
123 //===----------------------------------------------------------------------===//
125 // LICM - This pass is a simple natural loop based loop invariant code motion
128 Pass *createLICMPass();
131 //===----------------------------------------------------------------------===//
133 // PiNodeInsertion - This pass inserts single entry Phi nodes into basic blocks
134 // that are preceeded by a conditional branch, where the branch gives
135 // information about the operands of the condition. For example, this C code:
136 // if (x == 0) { ... = x + 4;
139 // x2 = phi(x); // Node that can hold data flow information about X
142 // Since the direction of the condition branch gives information about X itself
143 // (whether or not it is zero), some passes (like value numbering or ABCD) can
144 // use the inserted Phi/Pi nodes as a place to attach information, in this case
145 // saying that X has a value of 0 in this scope. The power of this analysis
146 // information is that "in the scope" translates to "for all uses of x2".
148 // This special form of Phi node is refered to as a Pi node, following the
149 // terminology defined in the "Array Bounds Checks on Demand" paper.
151 Pass *createPiNodeInsertionPass();
154 //===----------------------------------------------------------------------===//
156 // This pass is used to promote memory references to be register references. A
157 // simple example of the transformation performed by this pass is:
160 // %X = alloca int, uint 1 ret int 42
161 // store int 42, int *%X
165 Pass *createPromoteMemoryToRegister();
168 //===----------------------------------------------------------------------===//
170 // This pass reassociates commutative expressions in an order that is designed
171 // to promote better constant propagation, GCSE, LICM, PRE...
173 // For example: 4 + (x + 5) -> x + (4 + 5)
175 Pass *createReassociatePass();
177 //===----------------------------------------------------------------------===//
179 // This pass eliminates correlated conditions, such as these:
181 // if (X > 2) ; // Known false
185 Pass *createCorrelatedExpressionEliminationPass();
187 //===----------------------------------------------------------------------===//
189 // TailDuplication - Eliminate unconditional branches through controlled code
190 // duplication, creating simpler CFG structures.
192 Pass *createTailDuplicationPass();
195 //===----------------------------------------------------------------------===//
197 // CFG Simplification - Merge basic blocks, eliminate unreachable blocks,
198 // simplify terminator instructions, etc...
200 FunctionPass *createCFGSimplificationPass();
203 //===----------------------------------------------------------------------===//
205 // BreakCriticalEdges pass - Break all of the critical edges in the CFG by
206 // inserting a dummy basic block. This pass may be "required" by passes that
207 // cannot deal with critical edges. For this usage, a pass must call:
209 // AU.addRequiredID(BreakCriticalEdgesID);
211 // This pass obviously invalidates the CFG, but can update forward dominator
212 // (set, immediate dominators, and tree) information.
214 Pass *createBreakCriticalEdgesPass();
215 extern const PassInfo *BreakCriticalEdgesID;
217 // The BreakCriticalEdges pass also exposes some low-level functionality that
218 // may be used by other passes.
220 /// isCriticalEdge - Return true if the specified edge is a critical edge.
221 /// Critical edges are edges from a block with multiple successors to a block
222 /// with multiple predecessors.
224 bool isCriticalEdge(const TerminatorInst *TI, unsigned SuccNum);
226 /// SplitCriticalEdge - Insert a new node node to split the critical edge. This
227 /// will update DominatorSet, ImmediateDominator and DominatorTree information
228 /// if a pass is specified, thus calling this pass will not invalidate these
231 void SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, Pass *P = 0);
233 //===----------------------------------------------------------------------===//
235 // LoopSimplify pass - Insert Pre-header blocks into the CFG for every function
236 // in the module. This pass updates dominator information, loop information,
237 // and does not add critical edges to the CFG.
239 // AU.addRequiredID(LoopSimplifyID);
241 Pass *createLoopSimplifyPass();
242 extern const PassInfo *LoopSimplifyID;
244 //===----------------------------------------------------------------------===//
246 // This pass eliminates call instructions to the current function which occur
247 // immediately before return instructions.
249 FunctionPass *createTailCallEliminationPass();
252 //===----------------------------------------------------------------------===//
253 // This pass convert malloc and free instructions to %malloc & %free function
256 FunctionPass *createLowerAllocationsPass();
258 //===----------------------------------------------------------------------===//
259 // This pass converts SwitchInst instructions into a sequence of chained binary
260 // branch instructions.
262 FunctionPass *createLowerSwitchPass();
265 //===----------------------------------------------------------------------===//
266 // This pass converts 'invoke' instructions calls, and 'unwind' instructions
267 // into calls to abort().
269 FunctionPass *createLowerInvokePass();
273 //===----------------------------------------------------------------------===//
275 // These functions removes symbols from functions and modules.
277 Pass *createSymbolStrippingPass();
278 Pass *createFullSymbolStrippingPass();