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 // ConstantPropagation - A worklist driven constant propagation pass
41 FunctionPass *createConstantPropagationPass();
43 //===----------------------------------------------------------------------===//
45 // SCCP - Sparse conditional constant propagation.
47 FunctionPass *createSCCPPass();
49 //===----------------------------------------------------------------------===//
51 // DeadInstElimination - This pass quickly removes trivially dead instructions
52 // without modifying the CFG of the function. It is a BasicBlockPass, so it
53 // runs efficiently when queued next to other BasicBlockPass's.
55 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();
81 //===----------------------------------------------------------------------===//
83 // ScalarReplAggregates - Break up alloca's of aggregates into multiple allocas
86 FunctionPass *createScalarReplAggregatesPass();
88 //===----------------------------------------------------------------------===//
90 // GCSE - This pass is designed to be a very quick global transformation that
91 // eliminates global common subexpressions from a function. It does this by
92 // examining the SSA value graph of the function, instead of doing slow
93 // bit-vector computations.
95 FunctionPass *createGCSEPass();
97 //===----------------------------------------------------------------------===//
99 // InductionVariableSimplify - Transform induction variables in a program to all
100 // use a single canonical induction variable per loop.
102 FunctionPass *createIndVarSimplifyPass();
104 //===----------------------------------------------------------------------===//
106 // InstructionCombining - Combine instructions to form fewer, simple
107 // instructions. This pass does not modify the CFG, and has a tendency to make
108 // instructions dead, so a subsequent DCE pass is useful.
110 // This pass combines things like:
111 // %Y = add int 1, %X
112 // %Z = add int 1, %Y
114 // %Z = add int 2, %X
116 FunctionPass *createInstructionCombiningPass();
118 //===----------------------------------------------------------------------===//
120 // LICM - This pass is a loop invariant code motion and memory promotion pass.
122 FunctionPass *createLICMPass();
124 //===----------------------------------------------------------------------===//
126 // LoopStrengthReduce - This pass is strength reduces GEP instructions that use
127 // a loop's canonical induction variable as one of their indices. It takes an
128 // optional parameter used to consult the target machine whether certain
129 // transformations are profitable.
131 FunctionPass *createLoopStrengthReducePass(const TargetLowering *TLI = NULL);
133 //===----------------------------------------------------------------------===//
135 // LoopUnswitch - This pass is a simple loop unswitching pass.
137 FunctionPass *createLoopUnswitchPass();
139 //===----------------------------------------------------------------------===//
141 // LoopUnroll - This pass is a simple loop unrolling pass.
143 FunctionPass *createLoopUnrollPass();
145 //===----------------------------------------------------------------------===//
147 // PromoteMemoryToRegister - This pass is used to promote memory references to
148 // be register references. A simple example of the transformation performed by
152 // %X = alloca int, uint 1 ret int 42
153 // store int 42, int *%X
157 FunctionPass *createPromoteMemoryToRegisterPass();
158 extern const PassInfo *PromoteMemoryToRegisterID;
160 //===----------------------------------------------------------------------===//
162 // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
163 // references. In basically undoes the PromoteMemoryToRegister pass to make cfg
166 FunctionPass *createDemoteRegisterToMemoryPass();
167 extern const PassInfo *DemoteRegisterToMemoryID;
169 //===----------------------------------------------------------------------===//
171 // Reassociate - This pass reassociates commutative expressions in an order that
172 // is designed to promote better constant propagation, GCSE, LICM, PRE...
174 // For example: 4 + (x + 5) -> x + (4 + 5)
176 FunctionPass *createReassociatePass();
178 //===----------------------------------------------------------------------===//
180 // CorrelatedExpressionElimination - This pass eliminates correlated
181 // conditions, such as these:
183 // if (X > 2) ; // Known false
187 FunctionPass *createCorrelatedExpressionEliminationPass();
189 //===----------------------------------------------------------------------===//
191 // CondPropagationPass - This pass propagates information about conditional
192 // expressions through the program, allowing it to eliminate conditional
193 // branches in some cases.
195 FunctionPass *createCondPropagationPass();
197 //===----------------------------------------------------------------------===//
199 // TailDuplication - Eliminate unconditional branches through controlled code
200 // duplication, creating simpler CFG structures.
202 FunctionPass *createTailDuplicationPass();
204 //===----------------------------------------------------------------------===//
206 // CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
207 // simplify terminator instructions, etc...
209 FunctionPass *createCFGSimplificationPass();
211 //===----------------------------------------------------------------------===//
213 // BreakCriticalEdges - Break all of the critical edges in the CFG by inserting
214 // a dummy basic block. This pass may be "required" by passes that cannot deal
215 // with critical edges. For this usage, a pass must call:
217 // AU.addRequiredID(BreakCriticalEdgesID);
219 // This pass obviously invalidates the CFG, but can update forward dominator
220 // (set, immediate dominators, tree, and frontier) information.
222 FunctionPass *createBreakCriticalEdgesPass();
223 extern const PassInfo *BreakCriticalEdgesID;
225 //===----------------------------------------------------------------------===//
227 // LoopSimplify - Insert Pre-header blocks into the CFG for every function in
228 // the module. This pass updates dominator information, loop information, and
229 // does not add critical edges to the CFG.
231 // AU.addRequiredID(LoopSimplifyID);
233 FunctionPass *createLoopSimplifyPass();
234 extern const PassInfo *LoopSimplifyID;
236 //===----------------------------------------------------------------------===//
238 // LowerSelect - This pass converts SelectInst instructions into conditional
239 // branch and PHI instructions. If the OnlyFP flag is set to true, then only
240 // floating point select instructions are lowered.
242 FunctionPass *createLowerSelectPass(bool OnlyFP = false);
243 extern const PassInfo *LowerSelectID;
245 //===----------------------------------------------------------------------===//
247 // LowerAllocations - Turn malloc and free instructions into %malloc and %free
250 // AU.addRequiredID(LowerAllocationsID);
252 FunctionPass *createLowerAllocationsPass(bool LowerMallocArgToInteger = false);
253 extern const PassInfo *LowerAllocationsID;
255 //===----------------------------------------------------------------------===//
257 // TailCallElimination - This pass eliminates call instructions to the current
258 // function which occur immediately before return instructions.
260 FunctionPass *createTailCallEliminationPass();
262 //===----------------------------------------------------------------------===//
264 // LowerSwitch - This pass converts SwitchInst instructions into a sequence of
265 // chained binary branch instructions.
267 FunctionPass *createLowerSwitchPass();
268 extern const PassInfo *LowerSwitchID;
270 //===----------------------------------------------------------------------===//
272 // LowerPacked - This pass converts PackedType operations into low-level scalar
275 FunctionPass *createLowerPackedPass();
277 //===----------------------------------------------------------------------===//
279 // LowerInvoke - This pass converts invoke and unwind instructions to use sjlj
280 // exception handling mechanisms. Note that after this pass runs the CFG is not
281 // entirely accurate (exceptional control flow edges are not correct anymore) so
282 // only very simple things should be done after the lowerinvoke pass has run
283 // (like generation of native code). This should *NOT* be used as a general
284 // purpose "my LLVM-to-LLVM pass doesn't support the invoke instruction yet"
287 FunctionPass *createLowerInvokePass(const TargetLowering *TLI = NULL);
288 extern const PassInfo *LowerInvokePassID;
290 //===----------------------------------------------------------------------===//
292 // LowerGCPass - This function returns an instance of the "lowergc" pass, which
293 // lowers garbage collection intrinsics to normal LLVM code.
295 FunctionPass *createLowerGCPass();
297 //===----------------------------------------------------------------------===//
299 // BlockPlacement - This pass reorders basic blocks in order to increase the
300 // number of fall-through conditional branches.
302 FunctionPass *createBlockPlacementPass();
304 //===----------------------------------------------------------------------===//
306 // LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop
309 FunctionPass *createLCSSAPass();
310 extern const PassInfo *LCSSAID;
312 //===----------------------------------------------------------------------===//
314 // PredicateSimplifier - This pass collapses duplicate variables into one
315 // canonical form, and tries to simplify expressions along the way.
317 FunctionPass *createPredicateSimplifierPass();
319 } // End llvm namespace