58dcd428acc0798b271b1dff1507b73beb0991bd
[oota-llvm.git] / include / llvm / Transforms / Scalar.h
1 //===-- Scalar.h - Scalar Transformations ------------------------*- C++ -*-==//
2 //
3 // This header file defines prototypes for accessor functions that expose passes
4 // in the Scalar transformations library.
5 //
6 //===----------------------------------------------------------------------===//
7
8 #ifndef LLVM_TRANSFORMS_SCALAR_H
9 #define LLVM_TRANSFORMS_SCALAR_H
10
11 class Pass;
12 class FunctionPass;
13 class GetElementPtrInst;
14 class PassInfo;
15 class TerminatorInst;
16
17 //===----------------------------------------------------------------------===//
18 //
19 // Constant Propagation Pass - A worklist driven constant propagation pass
20 //
21 Pass *createConstantPropagationPass();
22
23
24 //===----------------------------------------------------------------------===//
25 //
26 // Sparse Conditional Constant Propagation Pass
27 //
28 Pass *createSCCPPass();
29
30
31 //===----------------------------------------------------------------------===//
32 //
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.
36 //
37 Pass *createDeadInstEliminationPass();
38
39
40 //===----------------------------------------------------------------------===//
41 //
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
45 // computations.
46 //
47 Pass *createDeadCodeEliminationPass();
48
49
50 //===----------------------------------------------------------------------===//
51 //
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.
55 //
56 Pass *createAggressiveDCEPass();
57
58
59 //===----------------------------------------------------------------------===//
60 //
61 // Scalar Replacement of Aggregates - Break up alloca's of aggregates into
62 // multiple allocas if possible.
63 //
64 Pass *createScalarReplAggregatesPass();
65
66 //===----------------------------------------------------------------------===//
67 // 
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
72 // index of [0]).
73
74 // This pass decomposes all multi-dimensional references in a function.
75 FunctionPass *createDecomposeMultiDimRefsPass();
76
77 // This function decomposes a single instance of such a reference.
78 // Return value: true if the instruction was replaced; false otherwise.
79 // 
80 bool DecomposeArrayRef(GetElementPtrInst* GEP);
81
82 //===----------------------------------------------------------------------===//
83 //
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.
88 //
89 Pass *createGCSEPass();
90
91
92 //===----------------------------------------------------------------------===//
93 //
94 // InductionVariableSimplify - Transform induction variables in a program to all
95 // use a single cannonical induction variable per loop.
96 //
97 Pass *createIndVarSimplifyPass();
98
99
100 //===----------------------------------------------------------------------===//
101 //
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.
105 //
106 // This pass combines things like:
107 //    %Y = add int 1, %X
108 //    %Z = add int 1, %Y
109 // into:
110 //    %Z = add int 2, %X
111 //
112 Pass *createInstructionCombiningPass();
113
114
115 //===----------------------------------------------------------------------===//
116 //
117 // LICM - This pass is a simple natural loop based loop invariant code motion
118 // pass.
119 //
120 Pass *createLICMPass();
121
122
123 //===----------------------------------------------------------------------===//
124 //
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;
129 // becomes:
130 //   if (x == 0) {
131 //     x2 = phi(x);    // Node that can hold data flow information about X
132 //     ... = x2 + 4;
133 //
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".
139 //
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.
142 //
143 Pass *createPiNodeInsertionPass();
144
145
146 //===----------------------------------------------------------------------===//
147 //
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:
150 //
151 //        FROM CODE                           TO CODE
152 //   %X = alloca int, uint 1                 ret int 42
153 //   store int 42, int *%X
154 //   %Y = load int* %X
155 //   ret int %Y
156 //
157 Pass *createPromoteMemoryToRegister();
158
159
160 //===----------------------------------------------------------------------===//
161 //
162 // This pass reassociates commutative expressions in an order that is designed
163 // to promote better constant propagation, GCSE, LICM, PRE...
164 //
165 // For example:  4 + (x + 5)  ->  x + (4 + 5)
166 //
167 Pass *createReassociatePass();
168
169 //===----------------------------------------------------------------------===//
170 //
171 // This pass eliminates correlated conditions, such as these:
172 //  if (X == 0)
173 //    if (X > 2) ;   // Known false
174 //    else
175 //      Y = X * Z;   // = 0
176 //
177 Pass *createCorrelatedExpressionEliminationPass();
178
179 //===----------------------------------------------------------------------===//
180 //
181 // TailDuplication - Eliminate unconditional branches through controlled code
182 // duplication, creating simpler CFG structures.
183 //
184 Pass *createTailDuplicationPass();
185
186
187 //===----------------------------------------------------------------------===//
188 //
189 // CFG Simplification - Merge basic blocks, eliminate unreachable blocks,
190 // simplify terminator instructions, etc...
191 //
192 Pass *createCFGSimplificationPass();
193
194
195 //===----------------------------------------------------------------------===//
196 //
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:
200 //
201 //   AU.addRequiredID(BreakCriticalEdgesID);
202 //
203 // This pass obviously invalidates the CFG, but can update forward dominator
204 // (set, immediate dominators, and tree) information.
205 //
206 Pass *createBreakCriticalEdgesPass();
207 extern const PassInfo *BreakCriticalEdgesID;
208
209 // The BreakCriticalEdges pass also exposes some low-level functionality that
210 // may be used by other passes.
211
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.
215 ///
216 bool isCriticalEdge(const TerminatorInst *TI, unsigned SuccNum);
217
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
221 /// analyses.
222 ///
223 void SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, Pass *P = 0);
224
225 //===----------------------------------------------------------------------===//
226 //
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.
230 //
231 //   AU.addRequiredID(LoopPreheadersID);
232 //
233 Pass *createLoopPreheaderInsertionPass();
234 extern const PassInfo *LoopPreheadersID;
235
236
237 //===----------------------------------------------------------------------===//
238 // These two passes convert malloc and free instructions to and from %malloc &
239 // %free function calls.
240 //
241 FunctionPass *createLowerAllocationsPass();
242 Pass *createRaiseAllocationsPass();
243
244 //===----------------------------------------------------------------------===//
245 // This pass converts SwitchInst instructions into a sequence of chained binary
246 // branch instructions.
247 //
248 FunctionPass *createLowerSwitchPass();
249
250 //===----------------------------------------------------------------------===//
251 //
252 // These functions removes symbols from functions and modules.
253 //
254 Pass *createSymbolStrippingPass();
255 Pass *createFullSymbolStrippingPass();
256
257 #endif