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