Factor out debugging code into the common base class.
[oota-llvm.git] / include / llvm / Transforms / Scalar.h
1 //===-- Scalar.h - Scalar Transformations -----------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // 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 FunctionPass;
21 class LoopPass;
22 class Pass;
23 class GetElementPtrInst;
24 class PassInfo;
25 class TerminatorInst;
26 class TargetLowering;
27
28 //===----------------------------------------------------------------------===//
29 //
30 // ConstantPropagation - A worklist driven constant propagation pass
31 //
32 FunctionPass *createConstantPropagationPass();
33
34 //===----------------------------------------------------------------------===//
35 //
36 // SCCP - Sparse conditional constant propagation.
37 //
38 FunctionPass *createSCCPPass();
39
40 //===----------------------------------------------------------------------===//
41 //
42 // DeadInstElimination - This pass quickly removes trivially dead instructions
43 // without modifying the CFG of the function.  It is a BasicBlockPass, so it
44 // runs efficiently when queued next to other BasicBlockPass's.
45 //
46 Pass *createDeadInstEliminationPass();
47
48 //===----------------------------------------------------------------------===//
49 //
50 // DeadCodeElimination - This pass is more powerful than DeadInstElimination,
51 // because it is worklist driven that can potentially revisit instructions when
52 // their other instructions become dead, to eliminate chains of dead
53 // computations.
54 //
55 FunctionPass *createDeadCodeEliminationPass();
56
57 //===----------------------------------------------------------------------===//
58 //
59 // DeadStoreElimination - This pass deletes stores that are post-dominated by
60 // must-aliased stores and are not loaded used between the stores.
61 //
62 FunctionPass *createDeadStoreEliminationPass();
63
64 //===----------------------------------------------------------------------===//
65 //
66 // AggressiveDCE - This pass uses the SSA based Aggressive DCE algorithm.  This
67 // algorithm assumes instructions are dead until proven otherwise, which makes
68 // it more successful are removing non-obviously dead instructions.
69 //
70 FunctionPass *createAggressiveDCEPass();
71
72 //===----------------------------------------------------------------------===//
73 //
74 // ScalarReplAggregates - Break up alloca's of aggregates into multiple allocas
75 // if possible.
76 //
77 FunctionPass *createScalarReplAggregatesPass(signed Threshold = -1);
78
79 //===----------------------------------------------------------------------===//
80 //
81 // GCSE - This pass is designed to be a very quick global transformation that
82 // eliminates global common subexpressions from a function.  It does this by
83 // examining the SSA value graph of the function, instead of doing slow
84 // bit-vector computations.
85 //
86 FunctionPass *createGCSEPass();
87
88 //===----------------------------------------------------------------------===//
89 //
90 // InductionVariableSimplify - Transform induction variables in a program to all
91 // use a single canonical induction variable per loop.
92 //
93 LoopPass *createIndVarSimplifyPass();
94
95 //===----------------------------------------------------------------------===//
96 //
97 // InstructionCombining - Combine instructions to form fewer, simple
98 // instructions. This pass does not modify the CFG, and has a tendency to make
99 // instructions dead, so a subsequent DCE pass is useful.
100 //
101 // This pass combines things like:
102 //    %Y = add int 1, %X
103 //    %Z = add int 1, %Y
104 // into:
105 //    %Z = add int 2, %X
106 //
107 FunctionPass *createInstructionCombiningPass();
108
109 //===----------------------------------------------------------------------===//
110 //
111 // LICM - This pass is a loop invariant code motion and memory promotion pass.
112 //
113 LoopPass *createLICMPass();
114
115 //===----------------------------------------------------------------------===//
116 //
117 // LoopStrengthReduce - This pass is strength reduces GEP instructions that use
118 // a loop's canonical induction variable as one of their indices.  It takes an
119 // optional parameter used to consult the target machine whether certain
120 // transformations are profitable.
121 //
122 LoopPass *createLoopStrengthReducePass(const TargetLowering *TLI = 0);
123
124 //===----------------------------------------------------------------------===//
125 //
126 // LoopUnswitch - This pass is a simple loop unswitching pass.
127 //
128 LoopPass *createLoopUnswitchPass(bool OptimizeForSize = false);
129
130 //===----------------------------------------------------------------------===//
131 //
132 // LoopUnroll - This pass is a simple loop unrolling pass.
133 //
134 LoopPass *createLoopUnrollPass();
135
136 //===----------------------------------------------------------------------===//
137 //
138 // LoopRotate - This pass is a simple loop rotating pass.
139 //
140 LoopPass *createLoopRotatePass();
141
142 //===----------------------------------------------------------------------===//
143 //
144 // LoopIndexSplit - This pass divides loop's iteration range by spliting loop
145 // such that each individual loop is executed efficiently.
146 //
147 LoopPass *createLoopIndexSplitPass();
148
149
150 //===----------------------------------------------------------------------===//
151 //
152 // PromoteMemoryToRegister - This pass is used to promote memory references to
153 // be register references. A simple example of the transformation performed by
154 // this pass is:
155 //
156 //        FROM CODE                           TO CODE
157 //   %X = alloca int, uint 1                 ret int 42
158 //   store int 42, int *%X
159 //   %Y = load int* %X
160 //   ret int %Y
161 //
162 FunctionPass *createPromoteMemoryToRegisterPass();
163 extern const PassInfo *const PromoteMemoryToRegisterID;
164
165 //===----------------------------------------------------------------------===//
166 //
167 // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
168 // references. In basically undoes the PromoteMemoryToRegister pass to make cfg
169 // hacking easier.
170 //
171 FunctionPass *createDemoteRegisterToMemoryPass();
172 extern const PassInfo *const DemoteRegisterToMemoryID;
173
174 //===----------------------------------------------------------------------===//
175 //
176 // Reassociate - This pass reassociates commutative expressions in an order that
177 // is designed to promote better constant propagation, GCSE, LICM, PRE...
178 //
179 // For example:  4 + (x + 5)  ->  x + (4 + 5)
180 //
181 FunctionPass *createReassociatePass();
182
183 //===----------------------------------------------------------------------===//
184 //
185 // CondPropagationPass - This pass propagates information about conditional
186 // expressions through the program, allowing it to eliminate conditional
187 // branches in some cases.
188 //
189 FunctionPass *createCondPropagationPass();
190
191 //===----------------------------------------------------------------------===//
192 //
193 // TailDuplication - Eliminate unconditional branches through controlled code
194 // duplication, creating simpler CFG structures.
195 //
196 FunctionPass *createTailDuplicationPass();
197
198 //===----------------------------------------------------------------------===//
199 //
200 // JumpThreading - Thread control through mult-pred/multi-succ blocks where some
201 // preds always go to some succ.
202 //
203 FunctionPass *createJumpThreadingPass();
204   
205 //===----------------------------------------------------------------------===//
206 //
207 // CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
208 // simplify terminator instructions, etc...
209 //
210 FunctionPass *createCFGSimplificationPass();
211
212 //===----------------------------------------------------------------------===//
213 //
214 // BreakCriticalEdges - Break all of the critical edges in the CFG by inserting
215 // a dummy basic block. This pass may be "required" by passes that cannot deal
216 // 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 FunctionPass *createBreakCriticalEdgesPass();
224 extern const PassInfo *const BreakCriticalEdgesID;
225
226 //===----------------------------------------------------------------------===//
227 //
228 // LoopSimplify - Insert Pre-header blocks into the CFG for every function in
229 // the module.  This pass updates dominator information, loop information, and
230 // does not add critical edges to the CFG.
231 //
232 //   AU.addRequiredID(LoopSimplifyID);
233 //
234 FunctionPass *createLoopSimplifyPass();
235 extern const PassInfo *const LoopSimplifyID;
236
237 //===----------------------------------------------------------------------===//
238 //
239 // LowerAllocations - Turn malloc and free instructions into %malloc and %free
240 // calls.
241 //
242 //   AU.addRequiredID(LowerAllocationsID);
243 //
244 Pass *createLowerAllocationsPass(bool LowerMallocArgToInteger = false);
245 extern const PassInfo *const LowerAllocationsID;
246
247 //===----------------------------------------------------------------------===//
248 //
249 // TailCallElimination - This pass eliminates call instructions to the current
250 // function which occur immediately before return instructions.
251 //
252 FunctionPass *createTailCallEliminationPass();
253
254 //===----------------------------------------------------------------------===//
255 //
256 // LowerSwitch - This pass converts SwitchInst instructions into a sequence of
257 // chained binary branch instructions.
258 //
259 FunctionPass *createLowerSwitchPass();
260 extern const PassInfo *const LowerSwitchID;
261
262 //===----------------------------------------------------------------------===//
263 //
264 // LowerInvoke - This pass converts invoke and unwind instructions to use sjlj
265 // exception handling mechanisms.  Note that after this pass runs the CFG is not
266 // entirely accurate (exceptional control flow edges are not correct anymore) so
267 // only very simple things should be done after the lowerinvoke pass has run
268 // (like generation of native code).  This should *NOT* be used as a general
269 // purpose "my LLVM-to-LLVM pass doesn't support the invoke instruction yet"
270 // lowering pass.
271 //
272 FunctionPass *createLowerInvokePass(const TargetLowering *TLI = 0);
273 extern const PassInfo *const LowerInvokePassID;
274
275 //===----------------------------------------------------------------------===//
276 //
277 // BlockPlacement - This pass reorders basic blocks in order to increase the
278 // number of fall-through conditional branches.
279 //
280 FunctionPass *createBlockPlacementPass();
281
282 //===----------------------------------------------------------------------===//
283 //
284 // LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop
285 // optimizations.
286 //
287 LoopPass *createLCSSAPass();
288 extern const PassInfo *const LCSSAID;
289
290 //===----------------------------------------------------------------------===//
291 //
292 // PredicateSimplifier - This pass collapses duplicate variables into one
293 // canonical form, and tries to simplify expressions along the way.
294 //
295 FunctionPass *createPredicateSimplifierPass();
296
297 //===----------------------------------------------------------------------===//
298 //
299 // GVN-PRE - This pass performs global value numbering and partial redundancy
300 // elimination.
301 //
302 FunctionPass *createGVNPREPass();
303
304 //===----------------------------------------------------------------------===//
305 //
306 // GVN - This pass performs global value numbering and redundant load 
307 // elimination cotemporaneously.
308 //
309 FunctionPass *createGVNPass();
310
311 //===----------------------------------------------------------------------===//
312 //
313 // MemCpyOpt - This pass performs optimizations related to eliminating memcpy
314 // calls and/or combining multiple stores into memset's.
315 //
316 FunctionPass *createMemCpyOptPass();
317
318 //===----------------------------------------------------------------------===//
319 //
320 // LoopDeletion - This pass performs DCE of non-infinite loops that it
321 // can prove are dead.
322 //
323 LoopPass *createLoopDeletionPass();
324   
325 //===----------------------------------------------------------------------===//
326 //
327 /// createSimplifyLibCallsPass - This pass optimizes specific calls to
328 /// specific well-known (library) functions.
329 FunctionPass *createSimplifyLibCallsPass();
330
331 //===----------------------------------------------------------------------===//
332 //
333 // CodeGenPrepare - This pass prepares a function for instruction selection.
334 //
335 FunctionPass *createCodeGenPreparePass(const TargetLowering *TLI = 0);
336
337 } // End llvm namespace
338
339 #endif