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