502c5d34fa8989b808911ff38419f1c174e18f5b
[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 #include <cstdlib>
19
20 namespace llvm {
21
22 class ModulePass;
23 class FunctionPass;
24 class GetElementPtrInst;
25 class PassInfo;
26 class TerminatorInst;
27 class TargetLowering;
28
29 //===----------------------------------------------------------------------===//
30 //
31 // RaisePointerReferences - Try to eliminate as many pointer arithmetic
32 // expressions as possible, by converting expressions to use getelementptr and
33 // friends.
34 //
35 FunctionPass *createRaisePointerReferencesPass();
36
37 //===----------------------------------------------------------------------===//
38 //
39 // Constant Propagation Pass - A worklist driven constant propagation pass
40 //
41 FunctionPass *createConstantPropagationPass();
42
43
44 //===----------------------------------------------------------------------===//
45 //
46 // Sparse Conditional Constant Propagation Pass
47 //
48 FunctionPass *createSCCPPass();
49
50
51 //===----------------------------------------------------------------------===//
52 //
53 // DeadInstElimination - This pass quickly removes trivially dead instructions
54 // without modifying the CFG of the function.  It is a BasicBlockPass, so it
55 // runs efficiently when queued next to other BasicBlockPass's.
56 //
57 FunctionPass *createDeadInstEliminationPass();
58
59
60 //===----------------------------------------------------------------------===//
61 //
62 // DeadCodeElimination - This pass is more powerful than DeadInstElimination,
63 // because it is worklist driven that can potentially revisit instructions when
64 // their other instructions become dead, to eliminate chains of dead
65 // computations.
66 //
67 FunctionPass *createDeadCodeEliminationPass();
68
69 //===----------------------------------------------------------------------===//
70 //
71 // DeadStoreElimination - This pass deletes stores that are post-dominated by
72 // must-aliased stores and are not loaded used between the stores.
73 //
74 FunctionPass *createDeadStoreEliminationPass();
75
76 //===----------------------------------------------------------------------===//
77 //
78 // AggressiveDCE - This pass uses the SSA based Aggressive DCE algorithm.  This
79 // algorithm assumes instructions are dead until proven otherwise, which makes
80 // it more successful are removing non-obviously dead instructions.
81 //
82 FunctionPass *createAggressiveDCEPass();
83
84
85 //===----------------------------------------------------------------------===//
86 //
87 // Scalar Replacement of Aggregates - Break up alloca's of aggregates into
88 // multiple allocas if possible.
89 //
90 FunctionPass *createScalarReplAggregatesPass();
91
92
93 //===----------------------------------------------------------------------===//
94 //
95 // GCSE - This pass is designed to be a very quick global transformation that
96 // eliminates global common subexpressions from a function.  It does this by
97 // examining the SSA value graph of the function, instead of doing slow
98 // bit-vector computations.
99 //
100 FunctionPass *createGCSEPass();
101
102
103 //===----------------------------------------------------------------------===//
104 //
105 // InductionVariableSimplify - Transform induction variables in a program to all
106 // use a single canonical induction variable per loop.
107 //
108 FunctionPass *createIndVarSimplifyPass();
109
110
111 //===----------------------------------------------------------------------===//
112 //
113 // InstructionCombining - Combine instructions to form fewer, simple
114 //   instructions.  This pass does not modify the CFG, and has a tendency to
115 //   make instructions dead, so a subsequent DCE pass is useful.
116 //
117 // This pass combines things like:
118 //    %Y = add int 1, %X
119 //    %Z = add int 1, %Y
120 // into:
121 //    %Z = add int 2, %X
122 //
123 FunctionPass *createInstructionCombiningPass();
124
125
126 //===----------------------------------------------------------------------===//
127 //
128 // LICM - This pass is a loop invariant code motion and memory promotion pass.
129 //
130 FunctionPass *createLICMPass();
131
132 //===----------------------------------------------------------------------===//
133 //
134 // LoopStrengthReduce - This pass is strength reduces GEP instructions that use
135 // a loop's canonical induction variable as one of their indices.  It takes an
136 // optional parameter used to consult the target machine whether certain
137 // transformations are profitable.
138 //
139 FunctionPass *createLoopStrengthReducePass(const TargetLowering *TLI = NULL);
140
141 //===----------------------------------------------------------------------===//
142 //
143 // LoopUnswitch - This pass is a simple loop unswitching pass.
144 //
145 FunctionPass *createLoopUnswitchPass();
146
147
148 //===----------------------------------------------------------------------===//
149 //
150 // LoopUnroll - This pass is a simple loop unrolling pass.
151 //
152 FunctionPass *createLoopUnrollPass();
153
154 //===----------------------------------------------------------------------===//
155 //
156 // This pass is used to promote memory references to be register references.  A
157 // simple example of the transformation performed by this pass is:
158 //
159 //        FROM CODE                           TO CODE
160 //   %X = alloca int, uint 1                 ret int 42
161 //   store int 42, int *%X
162 //   %Y = load int* %X
163 //   ret int %Y
164 //
165 FunctionPass *createPromoteMemoryToRegisterPass();
166
167 //===----------------------------------------------------------------------===//
168 //
169 // This pass is used to demote registers to memory references .
170 // In basically undoes the PromoteMemoryToRegister pass to
171 // make cfg hacking easier.
172 FunctionPass *createDemoteRegisterToMemoryPass();
173 extern const PassInfo *DemoteRegisterToMemoryID;
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 FunctionPass *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 FunctionPass *createCorrelatedExpressionEliminationPass();
193
194
195 // createCondPropagationPass - This pass propagates information about
196 // conditional expressions through the program, allowing it to eliminate
197 // conditional branches in some cases.
198 //
199 FunctionPass *createCondPropagationPass();
200
201 //===----------------------------------------------------------------------===//
202 //
203 // TailDuplication - Eliminate unconditional branches through controlled code
204 // duplication, creating simpler CFG structures.
205 //
206 FunctionPass *createTailDuplicationPass();
207
208
209 //===----------------------------------------------------------------------===//
210 //
211 // CFG Simplification - Merge basic blocks, eliminate unreachable blocks,
212 // simplify terminator instructions, etc...
213 //
214 FunctionPass *createCFGSimplificationPass();
215
216
217 //===----------------------------------------------------------------------===//
218 //
219 // BreakCriticalEdges pass - Break all of the critical edges in the CFG by
220 // inserting a dummy basic block.  This pass may be "required" by passes that
221 // cannot deal with critical edges.  For this usage, a pass must call:
222 //
223 //   AU.addRequiredID(BreakCriticalEdgesID);
224 //
225 // This pass obviously invalidates the CFG, but can update forward dominator
226 // (set, immediate dominators, tree, and frontier) information.
227 //
228 FunctionPass *createBreakCriticalEdgesPass();
229 extern const PassInfo *BreakCriticalEdgesID;
230
231 //===----------------------------------------------------------------------===//
232 //
233 // LoopSimplify pass - Insert Pre-header blocks into the CFG for every function
234 // in the module.  This pass updates dominator information, loop information,
235 // and does not add critical edges to the CFG.
236 //
237 //   AU.addRequiredID(LoopSimplifyID);
238 //
239 FunctionPass *createLoopSimplifyPass();
240 extern const PassInfo *LoopSimplifyID;
241
242 //===----------------------------------------------------------------------===//
243 //
244 // This pass eliminates call instructions to the current function which occur
245 // immediately before return instructions.
246 //
247 FunctionPass *createTailCallEliminationPass();
248
249
250 //===----------------------------------------------------------------------===//
251 // This pass convert malloc and free instructions to %malloc & %free function
252 // calls.
253 //
254 FunctionPass *createLowerAllocationsPass(bool LowerMallocArgToInteger = false);
255
256 //===----------------------------------------------------------------------===//
257 // This pass converts SwitchInst instructions into a sequence of chained binary
258 // branch instructions.
259 //
260 FunctionPass *createLowerSwitchPass();
261
262 //===----------------------------------------------------------------------===//
263 // This pass converts SelectInst instructions into conditional branch and PHI
264 // instructions.  If the OnlyFP flag is set to true, then only floating point
265 // select instructions are lowered.
266 //
267 FunctionPass *createLowerSelectPass(bool OnlyFP = false);
268
269 //===----------------------------------------------------------------------===//
270 // This pass converts PackedType operations into low-level scalar operations.
271 //
272 FunctionPass *createLowerPackedPass();
273
274 //===----------------------------------------------------------------------===//
275 // This pass converts invoke and unwind instructions to use sjlj exception
276 // handling mechanisms.  Note that after this pass runs the CFG is not entirely
277 // accurate (exceptional control flow edges are not correct anymore) so only
278 // very simple things should be done after the lowerinvoke pass has run (like
279 // generation of native code).  This should *NOT* be used as a general purpose
280 // "my LLVM-to-LLVM pass doesn't support the invoke instruction yet" lowering
281 // pass.
282 //
283 FunctionPass *createLowerInvokePass(unsigned JumBufSize = 200, 
284                                     unsigned JumpBufAlign = 0);
285 extern const PassInfo *LowerInvokePassID;
286
287
288 //===----------------------------------------------------------------------===//
289 /// createLowerGCPass - This function returns an instance of the "lowergc"
290 /// pass, which lowers garbage collection intrinsics to normal LLVM code.
291 ///
292 FunctionPass *createLowerGCPass();
293
294 //===----------------------------------------------------------------------===//
295 // This pass reorders basic blocks in order to increase the number of fall-
296 // through conditional branches.
297 FunctionPass *createBlockPlacementPass();
298
299 } // End llvm namespace
300
301 #endif