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();
167 //===----------------------------------------------------------------------===//
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;
175 //===----------------------------------------------------------------------===//
177 // This pass reassociates commutative expressions in an order that is designed
178 // to promote better constant propagation, GCSE, LICM, PRE...
180 // For example: 4 + (x + 5) -> x + (4 + 5)
182 FunctionPass *createReassociatePass();
184 //===----------------------------------------------------------------------===//
186 // This pass eliminates correlated conditions, such as these:
188 // if (X > 2) ; // Known false
192 FunctionPass *createCorrelatedExpressionEliminationPass();
195 // createCondPropagationPass - This pass propagates information about
196 // conditional expressions through the program, allowing it to eliminate
197 // conditional branches in some cases.
199 FunctionPass *createCondPropagationPass();
201 //===----------------------------------------------------------------------===//
203 // TailDuplication - Eliminate unconditional branches through controlled code
204 // duplication, creating simpler CFG structures.
206 FunctionPass *createTailDuplicationPass();
209 //===----------------------------------------------------------------------===//
211 // CFG Simplification - Merge basic blocks, eliminate unreachable blocks,
212 // simplify terminator instructions, etc...
214 FunctionPass *createCFGSimplificationPass();
217 //===----------------------------------------------------------------------===//
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:
223 // AU.addRequiredID(BreakCriticalEdgesID);
225 // This pass obviously invalidates the CFG, but can update forward dominator
226 // (set, immediate dominators, tree, and frontier) information.
228 FunctionPass *createBreakCriticalEdgesPass();
229 extern const PassInfo *BreakCriticalEdgesID;
231 //===----------------------------------------------------------------------===//
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.
237 // AU.addRequiredID(LoopSimplifyID);
239 FunctionPass *createLoopSimplifyPass();
240 extern const PassInfo *LoopSimplifyID;
242 //===----------------------------------------------------------------------===//
244 // This pass eliminates call instructions to the current function which occur
245 // immediately before return instructions.
247 FunctionPass *createTailCallEliminationPass();
250 //===----------------------------------------------------------------------===//
251 // This pass convert malloc and free instructions to %malloc & %free function
254 FunctionPass *createLowerAllocationsPass(bool LowerMallocArgToInteger = false);
256 //===----------------------------------------------------------------------===//
257 // This pass converts SwitchInst instructions into a sequence of chained binary
258 // branch instructions.
260 FunctionPass *createLowerSwitchPass();
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.
267 FunctionPass *createLowerSelectPass(bool OnlyFP = false);
269 //===----------------------------------------------------------------------===//
270 // This pass converts PackedType operations into low-level scalar operations.
272 FunctionPass *createLowerPackedPass();
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
283 FunctionPass *createLowerInvokePass(unsigned JumBufSize = 200,
284 unsigned JumpBufAlign = 0);
285 extern const PassInfo *LowerInvokePassID;
288 //===----------------------------------------------------------------------===//
289 /// createLowerGCPass - This function returns an instance of the "lowergc"
290 /// pass, which lowers garbage collection intrinsics to normal LLVM code.
292 FunctionPass *createLowerGCPass();
294 //===----------------------------------------------------------------------===//
295 // This pass reorders basic blocks in order to increase the number of fall-
296 // through conditional branches.
297 FunctionPass *createBlockPlacementPass();
299 } // End llvm namespace