1 //===-- Scalar.h - Scalar Transformations -----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This header file defines prototypes for accessor functions that expose passes
11 // in the Scalar transformations library.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_TRANSFORMS_SCALAR_H
16 #define LLVM_TRANSFORMS_SCALAR_H
24 class GetElementPtrInst;
29 //===----------------------------------------------------------------------===//
31 // RaisePointerReferences - Try to eliminate as many pointer arithmetic
32 // expressions as possible, by converting expressions to use getelementptr and
35 FunctionPass *createRaisePointerReferencesPass();
37 //===----------------------------------------------------------------------===//
39 // Constant Propagation Pass - A worklist driven constant propagation pass
41 FunctionPass *createConstantPropagationPass();
44 //===----------------------------------------------------------------------===//
46 // Sparse Conditional Constant Propagation Pass
48 FunctionPass *createSCCPPass();
51 //===----------------------------------------------------------------------===//
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.
57 FunctionPass *createDeadInstEliminationPass();
60 //===----------------------------------------------------------------------===//
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
67 FunctionPass *createDeadCodeEliminationPass();
69 //===----------------------------------------------------------------------===//
71 // DeadStoreElimination - This pass deletes stores that are post-dominated by
72 // must-aliased stores and are not loaded used between the stores.
74 FunctionPass *createDeadStoreEliminationPass();
76 //===----------------------------------------------------------------------===//
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.
82 FunctionPass *createAggressiveDCEPass();
85 //===----------------------------------------------------------------------===//
87 // Scalar Replacement of Aggregates - Break up alloca's of aggregates into
88 // multiple allocas if possible.
90 FunctionPass *createScalarReplAggregatesPass();
93 //===----------------------------------------------------------------------===//
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.
100 FunctionPass *createGCSEPass();
103 //===----------------------------------------------------------------------===//
105 // InductionVariableSimplify - Transform induction variables in a program to all
106 // use a single canonical induction variable per loop.
108 FunctionPass *createIndVarSimplifyPass();
111 //===----------------------------------------------------------------------===//
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.
117 // This pass combines things like:
118 // %Y = add int 1, %X
119 // %Z = add int 1, %Y
121 // %Z = add int 2, %X
123 FunctionPass *createInstructionCombiningPass();
126 //===----------------------------------------------------------------------===//
128 // LICM - This pass is a loop invariant code motion and memory promotion pass.
130 FunctionPass *createLICMPass();
132 //===----------------------------------------------------------------------===//
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.
139 FunctionPass *createLoopStrengthReducePass(const TargetLowering *TLI = NULL);
141 //===----------------------------------------------------------------------===//
143 // LoopUnswitch - This pass is a simple loop unswitching pass.
145 FunctionPass *createLoopUnswitchPass();
148 //===----------------------------------------------------------------------===//
150 // LoopUnroll - This pass is a simple loop unrolling pass.
152 FunctionPass *createLoopUnrollPass();
154 //===----------------------------------------------------------------------===//
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:
160 // %X = alloca int, uint 1 ret int 42
161 // store int 42, int *%X
165 FunctionPass *createPromoteMemoryToRegisterPass();
166 extern const PassInfo *PromoteMemoryToRegisterID;
168 //===----------------------------------------------------------------------===//
170 // This pass is used to demote registers to memory references .
171 // In basically undoes the PromoteMemoryToRegister pass to
172 // make cfg hacking easier.
173 FunctionPass *createDemoteRegisterToMemoryPass();
174 extern const PassInfo *DemoteRegisterToMemoryID;
176 //===----------------------------------------------------------------------===//
178 // This pass reassociates commutative expressions in an order that is designed
179 // to promote better constant propagation, GCSE, LICM, PRE...
181 // For example: 4 + (x + 5) -> x + (4 + 5)
183 FunctionPass *createReassociatePass();
185 //===----------------------------------------------------------------------===//
187 // This pass eliminates correlated conditions, such as these:
189 // if (X > 2) ; // Known false
193 FunctionPass *createCorrelatedExpressionEliminationPass();
196 // createCondPropagationPass - This pass propagates information about
197 // conditional expressions through the program, allowing it to eliminate
198 // conditional branches in some cases.
200 FunctionPass *createCondPropagationPass();
202 //===----------------------------------------------------------------------===//
204 // TailDuplication - Eliminate unconditional branches through controlled code
205 // duplication, creating simpler CFG structures.
207 FunctionPass *createTailDuplicationPass();
210 //===----------------------------------------------------------------------===//
212 // CFG Simplification - Merge basic blocks, eliminate unreachable blocks,
213 // simplify terminator instructions, etc...
215 FunctionPass *createCFGSimplificationPass();
218 //===----------------------------------------------------------------------===//
220 // BreakCriticalEdges pass - Break all of the critical edges in the CFG by
221 // inserting a dummy basic block. This pass may be "required" by passes that
222 // cannot deal with critical edges. For this usage, a pass must call:
224 // AU.addRequiredID(BreakCriticalEdgesID);
226 // This pass obviously invalidates the CFG, but can update forward dominator
227 // (set, immediate dominators, tree, and frontier) information.
229 FunctionPass *createBreakCriticalEdgesPass();
230 extern const PassInfo *BreakCriticalEdgesID;
232 //===----------------------------------------------------------------------===//
234 // LoopSimplify pass - Insert Pre-header blocks into the CFG for every function
235 // in the module. This pass updates dominator information, loop information,
236 // and does not add critical edges to the CFG.
238 // AU.addRequiredID(LoopSimplifyID);
240 FunctionPass *createLoopSimplifyPass();
241 extern const PassInfo *LoopSimplifyID;
243 //===----------------------------------------------------------------------===//
244 // This pass converts SelectInst instructions into conditional branch and PHI
245 // instructions. If the OnlyFP flag is set to true, then only floating point
246 // select instructions are lowered.
248 FunctionPass *createLowerSelectPass(bool OnlyFP = false);
249 extern const PassInfo *LowerSelectID;
251 //===----------------------------------------------------------------------===//
253 // LowerAllocations Pass - Turn malloc and free instructions into %malloc and
256 // AU.addRequiredID(LowerAllocationsID);
258 FunctionPass *createLowerAllocationsPass(bool LowerMallocArgToInteger = false);
259 extern const PassInfo *LowerAllocationsID;
261 //===----------------------------------------------------------------------===//
263 // This pass eliminates call instructions to the current function which occur
264 // immediately before return instructions.
266 FunctionPass *createTailCallEliminationPass();
268 //===----------------------------------------------------------------------===//
269 // This pass converts SwitchInst instructions into a sequence of chained binary
270 // branch instructions.
272 FunctionPass *createLowerSwitchPass();
273 extern const PassInfo *LowerSwitchID;
275 //===----------------------------------------------------------------------===//
276 // This pass converts PackedType operations into low-level scalar operations.
278 FunctionPass *createLowerPackedPass();
280 //===----------------------------------------------------------------------===//
281 // This pass converts invoke and unwind instructions to use sjlj exception
282 // handling mechanisms. Note that after this pass runs the CFG is not entirely
283 // accurate (exceptional control flow edges are not correct anymore) so only
284 // very simple things should be done after the lowerinvoke pass has run (like
285 // generation of native code). This should *NOT* be used as a general purpose
286 // "my LLVM-to-LLVM pass doesn't support the invoke instruction yet" lowering
289 FunctionPass *createLowerInvokePass(unsigned JumBufSize = 200,
290 unsigned JumpBufAlign = 0);
291 extern const PassInfo *LowerInvokePassID;
294 //===----------------------------------------------------------------------===//
295 /// createLowerGCPass - This function returns an instance of the "lowergc"
296 /// pass, which lowers garbage collection intrinsics to normal LLVM code.
298 FunctionPass *createLowerGCPass();
300 //===----------------------------------------------------------------------===//
301 // This pass reorders basic blocks in order to increase the number of fall-
302 // through conditional branches.
303 FunctionPass *createBlockPlacementPass();
305 //===----------------------------------------------------------------------===//
306 // This pass inserts phi nodes at loop boundaries to simplify other loop
308 FunctionPass *createLCSSAPass();
309 extern const PassInfo *LCSSAID;
311 } // End llvm namespace