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
22 class GetElementPtrInst;
26 //===----------------------------------------------------------------------===//
28 // RaisePointerReferences - Try to eliminate as many pointer arithmetic
29 // expressions as possible, by converting expressions to use getelementptr and
32 FunctionPass *createRaisePointerReferencesPass();
34 //===----------------------------------------------------------------------===//
36 // Constant Propagation Pass - A worklist driven constant propagation pass
38 FunctionPass *createConstantPropagationPass();
41 //===----------------------------------------------------------------------===//
43 // Sparse Conditional Constant Propagation Pass
45 FunctionPass *createSCCPPass();
48 //===----------------------------------------------------------------------===//
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.
54 FunctionPass *createDeadInstEliminationPass();
57 //===----------------------------------------------------------------------===//
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
64 FunctionPass *createDeadCodeEliminationPass();
66 //===----------------------------------------------------------------------===//
68 // DeadStoreElimination - This pass deletes stores that are post-dominated by
69 // must-aliased stores and are not loaded used between the stores.
71 FunctionPass *createDeadStoreEliminationPass();
73 //===----------------------------------------------------------------------===//
75 // AggressiveDCE - This pass uses the SSA based Aggressive DCE algorithm. This
76 // algorithm assumes instructions are dead until proven otherwise, which makes
77 // it more successful are removing non-obviously dead instructions.
79 FunctionPass *createAggressiveDCEPass();
82 //===----------------------------------------------------------------------===//
84 // Scalar Replacement of Aggregates - Break up alloca's of aggregates into
85 // multiple allocas if possible.
87 FunctionPass *createScalarReplAggregatesPass();
90 //===----------------------------------------------------------------------===//
92 // GCSE - This pass is designed to be a very quick global transformation that
93 // eliminates global common subexpressions from a function. It does this by
94 // examining the SSA value graph of the function, instead of doing slow
95 // bit-vector computations.
97 FunctionPass *createGCSEPass();
100 //===----------------------------------------------------------------------===//
102 // InductionVariableSimplify - Transform induction variables in a program to all
103 // use a single canonical induction variable per loop.
105 FunctionPass *createIndVarSimplifyPass();
108 //===----------------------------------------------------------------------===//
110 // InstructionCombining - Combine instructions to form fewer, simple
111 // instructions. This pass does not modify the CFG, and has a tendency to
112 // make instructions dead, so a subsequent DCE pass is useful.
114 // This pass combines things like:
115 // %Y = add int 1, %X
116 // %Z = add int 1, %Y
118 // %Z = add int 2, %X
120 FunctionPass *createInstructionCombiningPass();
123 //===----------------------------------------------------------------------===//
125 // LICM - This pass is a loop invariant code motion and memory promotion pass.
127 FunctionPass *createLICMPass();
129 //===----------------------------------------------------------------------===//
131 // LoopStrengthReduce - This pass is strength reduces GEP instructions that use
132 // a loop's canonical induction variable as one of their indices. The
133 // MaxTargetAMSize is the largest element size that the target architecture
134 // can handle in its addressing modes. Power of two multipliers less than or
135 // equal to this value are not reduced.
137 FunctionPass *createLoopStrengthReducePass(unsigned MaxTargetAMSize = 1);
139 //===----------------------------------------------------------------------===//
141 // LoopUnswitch - This pass is a simple loop unswitching pass.
143 FunctionPass *createLoopUnswitchPass();
146 //===----------------------------------------------------------------------===//
148 // LoopUnroll - This pass is a simple loop unrolling pass.
150 FunctionPass *createLoopUnrollPass();
152 //===----------------------------------------------------------------------===//
154 // This pass is used to promote memory references to be register references. A
155 // simple example of the transformation performed by this pass is:
158 // %X = alloca int, uint 1 ret int 42
159 // store int 42, int *%X
163 FunctionPass *createPromoteMemoryToRegisterPass();
165 //===----------------------------------------------------------------------===//
167 // This pass is used to demote registers to memory references .
168 // In basically undoes the PromoteMemoryToRegister pass to
169 // make cfg hacking easier.
170 FunctionPass *createDemoteRegisterToMemoryPass();
172 //===----------------------------------------------------------------------===//
174 // This pass reassociates commutative expressions in an order that is designed
175 // to promote better constant propagation, GCSE, LICM, PRE...
177 // For example: 4 + (x + 5) -> x + (4 + 5)
179 FunctionPass *createReassociatePass();
181 //===----------------------------------------------------------------------===//
183 // This pass eliminates correlated conditions, such as these:
185 // if (X > 2) ; // Known false
189 FunctionPass *createCorrelatedExpressionEliminationPass();
192 // createCondPropagationPass - This pass propagates information about
193 // conditional expressions through the program, allowing it to eliminate
194 // conditional branches in some cases.
196 FunctionPass *createCondPropagationPass();
198 //===----------------------------------------------------------------------===//
200 // TailDuplication - Eliminate unconditional branches through controlled code
201 // duplication, creating simpler CFG structures.
203 FunctionPass *createTailDuplicationPass();
206 //===----------------------------------------------------------------------===//
208 // CFG Simplification - Merge basic blocks, eliminate unreachable blocks,
209 // simplify terminator instructions, etc...
211 FunctionPass *createCFGSimplificationPass();
214 //===----------------------------------------------------------------------===//
216 // BreakCriticalEdges pass - Break all of the critical edges in the CFG by
217 // inserting a dummy basic block. This pass may be "required" by passes that
218 // cannot deal with critical edges. For this usage, a pass must call:
220 // AU.addRequiredID(BreakCriticalEdgesID);
222 // This pass obviously invalidates the CFG, but can update forward dominator
223 // (set, immediate dominators, tree, and frontier) information.
225 FunctionPass *createBreakCriticalEdgesPass();
226 extern const PassInfo *BreakCriticalEdgesID;
228 //===----------------------------------------------------------------------===//
230 // LoopSimplify pass - Insert Pre-header blocks into the CFG for every function
231 // in the module. This pass updates dominator information, loop information,
232 // and does not add critical edges to the CFG.
234 // AU.addRequiredID(LoopSimplifyID);
236 FunctionPass *createLoopSimplifyPass();
237 extern const PassInfo *LoopSimplifyID;
239 //===----------------------------------------------------------------------===//
241 // This pass eliminates call instructions to the current function which occur
242 // immediately before return instructions.
244 FunctionPass *createTailCallEliminationPass();
247 //===----------------------------------------------------------------------===//
248 // This pass convert malloc and free instructions to %malloc & %free function
251 FunctionPass *createLowerAllocationsPass(bool LowerMallocArgToInteger = false);
253 //===----------------------------------------------------------------------===//
254 // This pass converts SwitchInst instructions into a sequence of chained binary
255 // branch instructions.
257 FunctionPass *createLowerSwitchPass();
259 //===----------------------------------------------------------------------===//
260 // This pass converts SelectInst instructions into conditional branch and PHI
261 // instructions. If the OnlyFP flag is set to true, then only floating point
262 // select instructions are lowered.
264 FunctionPass *createLowerSelectPass(bool OnlyFP = false);
266 //===----------------------------------------------------------------------===//
267 // This pass converts PackedType operations into low-level scalar operations.
269 FunctionPass *createLowerPackedPass();
271 //===----------------------------------------------------------------------===//
272 // This pass converts invoke and unwind instructions to use sjlj exception
273 // handling mechanisms. Note that after this pass runs the CFG is not entirely
274 // accurate (exceptional control flow edges are not correct anymore) so only
275 // very simple things should be done after the lowerinvoke pass has run (like
276 // generation of native code). This should *NOT* be used as a general purpose
277 // "my LLVM-to-LLVM pass doesn't support the invoke instruction yet" lowering
280 FunctionPass *createLowerInvokePass(unsigned JumBufSize = 200,
281 unsigned JumpBufAlign = 0);
282 extern const PassInfo *LowerInvokePassID;
285 //===----------------------------------------------------------------------===//
286 /// createLowerGCPass - This function returns an instance of the "lowergc"
287 /// pass, which lowers garbage collection intrinsics to normal LLVM code.
289 FunctionPass *createLowerGCPass();
291 //===----------------------------------------------------------------------===//
292 // This pass reorders basic blocks in order to increase the number of fall-
293 // through conditional branches.
294 FunctionPass *createBlockPlacementPass();
296 //===----------------------------------------------------------------------===//
297 // This pass does partial redundancy elimination.
298 FunctionPass *createPREPass();
300 } // End llvm namespace