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 Pass *createRaisePointerReferencesPass();
34 //===----------------------------------------------------------------------===//
36 // Constant Propagation Pass - A worklist driven constant propagation pass
38 Pass *createConstantPropagationPass();
41 //===----------------------------------------------------------------------===//
43 // Sparse Conditional Constant Propagation Pass
45 Pass *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 Pass *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 Pass *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 Pass *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 Pass *createAggressiveDCEPass();
82 //===----------------------------------------------------------------------===//
84 // Scalar Replacement of Aggregates - Break up alloca's of aggregates into
85 // multiple allocas if possible.
87 Pass *createScalarReplAggregatesPass();
89 //===----------------------------------------------------------------------===//
91 // DecomposeMultiDimRefs - Convert multi-dimensional references consisting of
92 // any combination of 2 or more array and structure indices into a sequence of
93 // instructions (using getelementpr and cast) so that each instruction has at
94 // most one index (except structure references, which need an extra leading
97 // This pass decomposes all multi-dimensional references in a function.
98 FunctionPass *createDecomposeMultiDimRefsPass();
100 // This function decomposes a single instance of such a reference.
101 // Return value: true if the instruction was replaced; false otherwise.
103 bool DecomposeArrayRef(GetElementPtrInst* GEP);
105 //===----------------------------------------------------------------------===//
107 // GCSE - This pass is designed to be a very quick global transformation that
108 // eliminates global common subexpressions from a function. It does this by
109 // examining the SSA value graph of the function, instead of doing slow
110 // bit-vector computations.
112 FunctionPass *createGCSEPass();
115 //===----------------------------------------------------------------------===//
117 // InductionVariableSimplify - Transform induction variables in a program to all
118 // use a single canonical induction variable per loop.
120 Pass *createIndVarSimplifyPass();
123 //===----------------------------------------------------------------------===//
125 // InstructionCombining - Combine instructions to form fewer, simple
126 // instructions. This pass does not modify the CFG, and has a tendency to
127 // make instructions dead, so a subsequent DCE pass is useful.
129 // This pass combines things like:
130 // %Y = add int 1, %X
131 // %Z = add int 1, %Y
133 // %Z = add int 2, %X
135 Pass *createInstructionCombiningPass();
138 //===----------------------------------------------------------------------===//
140 // LICM - This pass is a loop invariant code motion and memory promotion pass.
142 FunctionPass *createLICMPass();
145 //===----------------------------------------------------------------------===//
147 // LoopUnswitch - This pass is a simple loop unswitching pass.
149 FunctionPass *createLoopUnswitchPass();
152 //===----------------------------------------------------------------------===//
154 // LoopUnroll - This pass is a simple loop unrolling pass.
156 FunctionPass *createLoopUnrollPass();
159 //===----------------------------------------------------------------------===//
161 // PiNodeInsertion - This pass inserts single entry Phi nodes into basic blocks
162 // that are preceeded by a conditional branch, where the branch gives
163 // information about the operands of the condition. For example, this C code:
164 // if (x == 0) { ... = x + 4;
167 // x2 = phi(x); // Node that can hold data flow information about X
170 // Since the direction of the condition branch gives information about X itself
171 // (whether or not it is zero), some passes (like value numbering or ABCD) can
172 // use the inserted Phi/Pi nodes as a place to attach information, in this case
173 // saying that X has a value of 0 in this scope. The power of this analysis
174 // information is that "in the scope" translates to "for all uses of x2".
176 // This special form of Phi node is refered to as a Pi node, following the
177 // terminology defined in the "Array Bounds Checks on Demand" paper.
179 Pass *createPiNodeInsertionPass();
182 //===----------------------------------------------------------------------===//
184 // This pass is used to promote memory references to be register references. A
185 // simple example of the transformation performed by this pass is:
188 // %X = alloca int, uint 1 ret int 42
189 // store int 42, int *%X
193 Pass *createPromoteMemoryToRegister();
196 //===----------------------------------------------------------------------===//
198 // This pass reassociates commutative expressions in an order that is designed
199 // to promote better constant propagation, GCSE, LICM, PRE...
201 // For example: 4 + (x + 5) -> x + (4 + 5)
203 FunctionPass *createReassociatePass();
205 //===----------------------------------------------------------------------===//
207 // This pass eliminates correlated conditions, such as these:
209 // if (X > 2) ; // Known false
213 Pass *createCorrelatedExpressionEliminationPass();
215 //===----------------------------------------------------------------------===//
217 // TailDuplication - Eliminate unconditional branches through controlled code
218 // duplication, creating simpler CFG structures.
220 Pass *createTailDuplicationPass();
223 //===----------------------------------------------------------------------===//
225 // CFG Simplification - Merge basic blocks, eliminate unreachable blocks,
226 // simplify terminator instructions, etc...
228 FunctionPass *createCFGSimplificationPass();
231 //===----------------------------------------------------------------------===//
233 // BreakCriticalEdges pass - Break all of the critical edges in the CFG by
234 // inserting a dummy basic block. This pass may be "required" by passes that
235 // cannot deal with critical edges. For this usage, a pass must call:
237 // AU.addRequiredID(BreakCriticalEdgesID);
239 // This pass obviously invalidates the CFG, but can update forward dominator
240 // (set, immediate dominators, tree, and frontier) information.
242 Pass *createBreakCriticalEdgesPass();
243 extern const PassInfo *BreakCriticalEdgesID;
245 //===----------------------------------------------------------------------===//
247 // LoopSimplify pass - Insert Pre-header blocks into the CFG for every function
248 // in the module. This pass updates dominator information, loop information,
249 // and does not add critical edges to the CFG.
251 // AU.addRequiredID(LoopSimplifyID);
253 Pass *createLoopSimplifyPass();
254 extern const PassInfo *LoopSimplifyID;
256 //===----------------------------------------------------------------------===//
258 // This pass eliminates call instructions to the current function which occur
259 // immediately before return instructions.
261 FunctionPass *createTailCallEliminationPass();
264 //===----------------------------------------------------------------------===//
265 // This pass convert malloc and free instructions to %malloc & %free function
268 FunctionPass *createLowerAllocationsPass();
270 //===----------------------------------------------------------------------===//
271 // This pass converts SwitchInst instructions into a sequence of chained binary
272 // branch instructions.
274 FunctionPass *createLowerSwitchPass();
276 //===----------------------------------------------------------------------===//
277 // This pass converts SelectInst instructions into conditional branch and PHI
278 // instructions. If the OnlyFP flag is set to true, then only floating point
279 // select instructions are lowered.
281 FunctionPass *createLowerSelectPass(bool OnlyFP = false);
283 //===----------------------------------------------------------------------===//
284 // This pass converts invoke and unwind instructions to use sjlj exception
285 // handling mechanisms. Note that after this pass runs the CFG is not entirely
286 // accurate (exceptional control flow edges are not correct anymore) so only
287 // very simple things should be done after the lowerinvoke pass has run (like
288 // generation of native code). This should *NOT* be used as a general purpose
289 // "my LLVM-to-LLVM pass doesn't support the invoke instruction yet" lowering
292 FunctionPass *createLowerInvokePass();
293 extern const PassInfo *LowerInvokePassID;
296 //===----------------------------------------------------------------------===//
297 /// createLowerGCPass - This function returns an instance of the "lowergc"
298 /// pass, which lowers garbage collection intrinsics to normal LLVM code.
300 FunctionPass *createLowerGCPass();
302 //===----------------------------------------------------------------------===//
303 // Returns a pass which converts all instances of ConstantExpression
304 // into regular LLVM instructions.
305 FunctionPass* createLowerConstantExpressionsPass();
308 //===----------------------------------------------------------------------===//
310 // These functions removes symbols from functions and modules.
312 Pass *createSymbolStrippingPass();
313 Pass *createFullSymbolStrippingPass();
315 } // End llvm namespace