d408bee19fd86a438bdee6cf080d87cc61700540
[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 GetElementPtrInst;
13 class PassInfo;
14 class TerminatorInst;
15
16 //===----------------------------------------------------------------------===//
17 //
18 // Constant Propagation Pass - A worklist driven constant propagation pass
19 //
20 Pass *createConstantPropagationPass();
21
22
23 //===----------------------------------------------------------------------===//
24 //
25 // Sparse Conditional Constant Propagation Pass
26 //
27 Pass *createSCCPPass();
28
29
30 //===----------------------------------------------------------------------===//
31 //
32 // DeadInstElimination - This pass quickly removes trivially dead instructions
33 // without modifying the CFG of the function.  It is a BasicBlockPass, so it
34 // runs efficiently when queued next to other BasicBlockPass's.
35 //
36 Pass *createDeadInstEliminationPass();
37
38
39 //===----------------------------------------------------------------------===//
40 //
41 // DeadCodeElimination - This pass is more powerful than DeadInstElimination,
42 // because it is worklist driven that can potentially revisit instructions when
43 // their other instructions become dead, to eliminate chains of dead
44 // computations.
45 //
46 Pass *createDeadCodeEliminationPass();
47
48
49 //===----------------------------------------------------------------------===//
50 //
51 // AggressiveDCE - This pass uses the SSA based Aggressive DCE algorithm.  This
52 // algorithm assumes instructions are dead until proven otherwise, which makes
53 // it more successful are removing non-obviously dead instructions.
54 //
55 Pass *createAggressiveDCEPass();
56
57
58 //===----------------------------------------------------------------------===//
59 //
60 // Scalar Replacement of Aggregates - Break up alloca's of aggregates into
61 // multiple allocas if possible.
62 //
63 Pass *createScalarReplAggregatesPass();
64
65 //===----------------------------------------------------------------------===//
66 // 
67 // DecomposeMultiDimRefs - Convert multi-dimensional references consisting of
68 // any combination of 2 or more array and structure indices into a sequence of
69 // instructions (using getelementpr and cast) so that each instruction has at
70 // most one index (except structure references, which need an extra leading
71 // index of [0]).
72
73 // This pass decomposes all multi-dimensional references in a function.
74 Pass *createDecomposeMultiDimRefsPass();
75
76 // This function decomposes a single instance of such a reference.
77 // Return value: true if the instruction was replaced; false otherwise.
78 // 
79 bool DecomposeArrayRef(GetElementPtrInst* GEP);
80
81 //===----------------------------------------------------------------------===//
82 //
83 // GCSE - This pass is designed to be a very quick global transformation that
84 // eliminates global common subexpressions from a function.  It does this by
85 // examining the SSA value graph of the function, instead of doing slow
86 // bit-vector computations.
87 //
88 Pass *createGCSEPass();
89
90
91 //===----------------------------------------------------------------------===//
92 //
93 // InductionVariableSimplify - Transform induction variables in a program to all
94 // use a single cannonical induction variable per loop.
95 //
96 Pass *createIndVarSimplifyPass();
97
98
99 //===----------------------------------------------------------------------===//
100 //
101 // InstructionCombining - Combine instructions to form fewer, simple
102 //   instructions.  This pass does not modify the CFG, and has a tendancy to
103 //   make instructions dead, so a subsequent DCE pass is useful.
104 //
105 // This pass combines things like:
106 //    %Y = add int 1, %X
107 //    %Z = add int 1, %Y
108 // into:
109 //    %Z = add int 2, %X
110 //
111 Pass *createInstructionCombiningPass();
112
113
114 //===----------------------------------------------------------------------===//
115 //
116 // LICM - This pass is a simple natural loop based loop invariant code motion
117 // pass.
118 //
119 Pass *createLICMPass();
120
121
122 //===----------------------------------------------------------------------===//
123 //
124 // PiNodeInsertion - This pass inserts single entry Phi nodes into basic blocks
125 // that are preceeded by a conditional branch, where the branch gives
126 // information about the operands of the condition.  For example, this C code:
127 //   if (x == 0) { ... = x + 4;
128 // becomes:
129 //   if (x == 0) {
130 //     x2 = phi(x);    // Node that can hold data flow information about X
131 //     ... = x2 + 4;
132 //
133 // Since the direction of the condition branch gives information about X itself
134 // (whether or not it is zero), some passes (like value numbering or ABCD) can
135 // use the inserted Phi/Pi nodes as a place to attach information, in this case
136 // saying that X has a value of 0 in this scope.  The power of this analysis
137 // information is that "in the scope" translates to "for all uses of x2".
138 //
139 // This special form of Phi node is refered to as a Pi node, following the
140 // terminology defined in the "Array Bounds Checks on Demand" paper.
141 //
142 Pass *createPiNodeInsertionPass();
143
144
145 //===----------------------------------------------------------------------===//
146 //
147 // This pass is used to promote memory references to be register references.  A
148 // simple example of the transformation performed by this pass is:
149 //
150 //        FROM CODE                           TO CODE
151 //   %X = alloca int, uint 1                 ret int 42
152 //   store int 42, int *%X
153 //   %Y = load int* %X
154 //   ret int %Y
155 //
156 Pass *createPromoteMemoryToRegister();
157
158
159 //===----------------------------------------------------------------------===//
160 //
161 // This pass reassociates commutative expressions in an order that is designed
162 // to promote better constant propagation, GCSE, LICM, PRE...
163 //
164 // For example:  4 + (x + 5)  ->  x + (4 + 5)
165 //
166 Pass *createReassociatePass();
167
168 //===----------------------------------------------------------------------===//
169 //
170 // This pass eliminates correlated conditions, such as these:
171 //  if (X == 0)
172 //    if (X > 2) ;   // Known false
173 //    else
174 //      Y = X * Z;   // = 0
175 //
176 Pass *createCorrelatedExpressionEliminationPass();
177
178 //===----------------------------------------------------------------------===//
179 //
180 // CFG Simplification - Merge basic blocks, eliminate unreachable blocks,
181 // simplify terminator instructions, etc...
182 //
183 Pass *createCFGSimplificationPass();
184
185 //===----------------------------------------------------------------------===//
186 //
187 // BreakCriticalEdges pass - Break all of the critical edges in the CFG by
188 // inserting a dummy basic block.  This pass may be "required" by passes that
189 // cannot deal with critical edges.  For this usage, a pass must call:
190 //
191 //   AU.addRequiredID(BreakCriticalEdgesID);
192 //
193 // This pass obviously invalidates the CFG, but can update forward dominator
194 // (set, immediate dominators, and tree) information.
195 //
196 Pass *createBreakCriticalEdgesPass();
197 extern const PassInfo *BreakCriticalEdgesID;
198
199 // The BreakCriticalEdges pass also exposes some low-level functionality that
200 // may be used by other passes.
201
202 /// isCriticalEdge - Return true if the specified edge is a critical edge.
203 /// Critical edges are edges from a block with multiple successors to a block
204 /// with multiple predecessors.
205 ///
206 bool isCriticalEdge(const TerminatorInst *TI, unsigned SuccNum);
207
208 /// SplitCriticalEdge - Insert a new node node to split the critical edge.  This
209 /// will update DominatorSet, ImmediateDominator and DominatorTree information
210 /// if a pass is specified, thus calling this pass will not invalidate these
211 /// analyses.
212 ///
213 void SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, Pass *P = 0);
214
215 //===----------------------------------------------------------------------===//
216 //
217 // LoopPreheaders pass - Insert Pre-header blocks into the CFG for every
218 // function in the module.  This pass updates dominator information, loop
219 // information, and does not add critical edges to the CFG.
220 //
221 //   AU.addRequiredID(LoopPreheadersID);
222 //
223 Pass *createLoopPreheaderInsertionPass();
224 extern const PassInfo *LoopPreheadersID;
225
226
227 //===----------------------------------------------------------------------===//
228 // These two passes convert malloc and free instructions to and from %malloc &
229 // %free function calls.
230 //
231 Pass *createLowerAllocationsPass();
232 Pass *createRaiseAllocationsPass();
233
234 //===----------------------------------------------------------------------===//
235 // This pass converts SwitchInst instructions into a sequence of chained binary
236 // branch instructions.
237 //
238 Pass *createLowerSwitchPass();
239
240 //===----------------------------------------------------------------------===//
241 //
242 // These functions removes symbols from functions and modules.
243 //
244 Pass *createSymbolStrippingPass();
245 Pass *createFullSymbolStrippingPass();
246
247 #endif