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 // Constant Propagation Pass - A worklist driven constant propagation pass
21 Pass *createConstantPropagationPass();
24 //===----------------------------------------------------------------------===//
26 // Sparse Conditional Constant Propagation Pass
28 Pass *createSCCPPass();
31 //===----------------------------------------------------------------------===//
33 // DeadInstElimination - This pass quickly removes trivially dead instructions
34 // without modifying the CFG of the function. It is a BasicBlockPass, so it
35 // runs efficiently when queued next to other BasicBlockPass's.
37 Pass *createDeadInstEliminationPass();
40 //===----------------------------------------------------------------------===//
42 // DeadCodeElimination - This pass is more powerful than DeadInstElimination,
43 // because it is worklist driven that can potentially revisit instructions when
44 // their other instructions become dead, to eliminate chains of dead
47 Pass *createDeadCodeEliminationPass();
50 //===----------------------------------------------------------------------===//
52 // AggressiveDCE - This pass uses the SSA based Aggressive DCE algorithm. This
53 // algorithm assumes instructions are dead until proven otherwise, which makes
54 // it more successful are removing non-obviously dead instructions.
56 Pass *createAggressiveDCEPass();
59 //===----------------------------------------------------------------------===//
61 // Scalar Replacement of Aggregates - Break up alloca's of aggregates into
62 // multiple allocas if possible.
64 Pass *createScalarReplAggregatesPass();
66 //===----------------------------------------------------------------------===//
68 // DecomposeMultiDimRefs - Convert multi-dimensional references consisting of
69 // any combination of 2 or more array and structure indices into a sequence of
70 // instructions (using getelementpr and cast) so that each instruction has at
71 // most one index (except structure references, which need an extra leading
74 // This pass decomposes all multi-dimensional references in a function.
75 FunctionPass *createDecomposeMultiDimRefsPass();
77 // This function decomposes a single instance of such a reference.
78 // Return value: true if the instruction was replaced; false otherwise.
80 bool DecomposeArrayRef(GetElementPtrInst* GEP);
82 //===----------------------------------------------------------------------===//
84 // GCSE - This pass is designed to be a very quick global transformation that
85 // eliminates global common subexpressions from a function. It does this by
86 // examining the SSA value graph of the function, instead of doing slow
87 // bit-vector computations.
89 Pass *createGCSEPass();
92 //===----------------------------------------------------------------------===//
94 // InductionVariableSimplify - Transform induction variables in a program to all
95 // use a single cannonical induction variable per loop.
97 Pass *createIndVarSimplifyPass();
100 //===----------------------------------------------------------------------===//
102 // InstructionCombining - Combine instructions to form fewer, simple
103 // instructions. This pass does not modify the CFG, and has a tendancy to
104 // make instructions dead, so a subsequent DCE pass is useful.
106 // This pass combines things like:
107 // %Y = add int 1, %X
108 // %Z = add int 1, %Y
110 // %Z = add int 2, %X
112 Pass *createInstructionCombiningPass();
115 //===----------------------------------------------------------------------===//
117 // LICM - This pass is a simple natural loop based loop invariant code motion
120 Pass *createLICMPass();
123 //===----------------------------------------------------------------------===//
125 // PiNodeInsertion - This pass inserts single entry Phi nodes into basic blocks
126 // that are preceeded by a conditional branch, where the branch gives
127 // information about the operands of the condition. For example, this C code:
128 // if (x == 0) { ... = x + 4;
131 // x2 = phi(x); // Node that can hold data flow information about X
134 // Since the direction of the condition branch gives information about X itself
135 // (whether or not it is zero), some passes (like value numbering or ABCD) can
136 // use the inserted Phi/Pi nodes as a place to attach information, in this case
137 // saying that X has a value of 0 in this scope. The power of this analysis
138 // information is that "in the scope" translates to "for all uses of x2".
140 // This special form of Phi node is refered to as a Pi node, following the
141 // terminology defined in the "Array Bounds Checks on Demand" paper.
143 Pass *createPiNodeInsertionPass();
146 //===----------------------------------------------------------------------===//
148 // This pass is used to promote memory references to be register references. A
149 // simple example of the transformation performed by this pass is:
152 // %X = alloca int, uint 1 ret int 42
153 // store int 42, int *%X
157 Pass *createPromoteMemoryToRegister();
160 //===----------------------------------------------------------------------===//
162 // This pass reassociates commutative expressions in an order that is designed
163 // to promote better constant propagation, GCSE, LICM, PRE...
165 // For example: 4 + (x + 5) -> x + (4 + 5)
167 Pass *createReassociatePass();
169 //===----------------------------------------------------------------------===//
171 // This pass eliminates correlated conditions, such as these:
173 // if (X > 2) ; // Known false
177 Pass *createCorrelatedExpressionEliminationPass();
179 //===----------------------------------------------------------------------===//
181 // TailDuplication - Eliminate unconditional branches through controlled code
182 // duplication, creating simpler CFG structures.
184 Pass *createTailDuplicationPass();
187 //===----------------------------------------------------------------------===//
189 // CFG Simplification - Merge basic blocks, eliminate unreachable blocks,
190 // simplify terminator instructions, etc...
192 Pass *createCFGSimplificationPass();
195 //===----------------------------------------------------------------------===//
197 // BreakCriticalEdges pass - Break all of the critical edges in the CFG by
198 // inserting a dummy basic block. This pass may be "required" by passes that
199 // cannot deal with critical edges. For this usage, a pass must call:
201 // AU.addRequiredID(BreakCriticalEdgesID);
203 // This pass obviously invalidates the CFG, but can update forward dominator
204 // (set, immediate dominators, and tree) information.
206 Pass *createBreakCriticalEdgesPass();
207 extern const PassInfo *BreakCriticalEdgesID;
209 // The BreakCriticalEdges pass also exposes some low-level functionality that
210 // may be used by other passes.
212 /// isCriticalEdge - Return true if the specified edge is a critical edge.
213 /// Critical edges are edges from a block with multiple successors to a block
214 /// with multiple predecessors.
216 bool isCriticalEdge(const TerminatorInst *TI, unsigned SuccNum);
218 /// SplitCriticalEdge - Insert a new node node to split the critical edge. This
219 /// will update DominatorSet, ImmediateDominator and DominatorTree information
220 /// if a pass is specified, thus calling this pass will not invalidate these
223 void SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, Pass *P = 0);
225 //===----------------------------------------------------------------------===//
227 // LoopPreheaders pass - Insert Pre-header blocks into the CFG for every
228 // function in the module. This pass updates dominator information, loop
229 // information, and does not add critical edges to the CFG.
231 // AU.addRequiredID(LoopPreheadersID);
233 Pass *createLoopPreheaderInsertionPass();
234 extern const PassInfo *LoopPreheadersID;
237 //===----------------------------------------------------------------------===//
238 // This pass convert malloc and free instructions to %malloc & %free function
241 FunctionPass *createLowerAllocationsPass();
243 //===----------------------------------------------------------------------===//
244 // This pass converts SwitchInst instructions into a sequence of chained binary
245 // branch instructions.
247 FunctionPass *createLowerSwitchPass();
249 //===----------------------------------------------------------------------===//
251 // These functions removes symbols from functions and modules.
253 Pass *createSymbolStrippingPass();
254 Pass *createFullSymbolStrippingPass();