1 //===-- Scalar.h - Scalar Transformations -----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // 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
25 class GetElementPtrInst;
30 //===----------------------------------------------------------------------===//
32 // ConstantPropagation - A worklist driven constant propagation pass
34 FunctionPass *createConstantPropagationPass();
36 //===----------------------------------------------------------------------===//
38 // SCCP - Sparse conditional constant propagation.
40 FunctionPass *createSCCPPass();
42 //===----------------------------------------------------------------------===//
44 // DeadInstElimination - This pass quickly removes trivially dead instructions
45 // without modifying the CFG of the function. It is a BasicBlockPass, so it
46 // runs efficiently when queued next to other BasicBlockPass's.
48 Pass *createDeadInstEliminationPass();
50 //===----------------------------------------------------------------------===//
52 // DeadCodeElimination - This pass is more powerful than DeadInstElimination,
53 // because it is worklist driven that can potentially revisit instructions when
54 // their other instructions become dead, to eliminate chains of dead
57 FunctionPass *createDeadCodeEliminationPass();
59 //===----------------------------------------------------------------------===//
61 // DeadStoreElimination - This pass deletes stores that are post-dominated by
62 // must-aliased stores and are not loaded used between the stores.
64 FunctionPass *createDeadStoreEliminationPass();
66 //===----------------------------------------------------------------------===//
68 // AggressiveDCE - This pass uses the SSA based Aggressive DCE algorithm. This
69 // algorithm assumes instructions are dead until proven otherwise, which makes
70 // it more successful are removing non-obviously dead instructions.
72 FunctionPass *createAggressiveDCEPass();
74 //===----------------------------------------------------------------------===//
76 // ScalarReplAggregates - Break up alloca's of aggregates into multiple allocas
79 FunctionPass *createScalarReplAggregatesPass(signed Threshold = -1);
81 //===----------------------------------------------------------------------===//
83 // GCSE - This pass is designed to be a very quick global transformation that
84 // eliminates global common subexpressions from a function. It does this by
85 // examining the SSA value graph of the function, instead of doing slow
86 // bit-vector computations.
88 FunctionPass *createGCSEPass();
90 //===----------------------------------------------------------------------===//
92 // InductionVariableSimplify - Transform induction variables in a program to all
93 // use a single canonical induction variable per loop.
95 LoopPass *createIndVarSimplifyPass();
97 //===----------------------------------------------------------------------===//
99 // InstructionCombining - Combine instructions to form fewer, simple
100 // instructions. This pass does not modify the CFG, and has a tendency to make
101 // instructions dead, so a subsequent DCE pass is useful.
103 // This pass combines things like:
104 // %Y = add int 1, %X
105 // %Z = add int 1, %Y
107 // %Z = add int 2, %X
109 FunctionPass *createInstructionCombiningPass();
111 //===----------------------------------------------------------------------===//
113 // LICM - This pass is a loop invariant code motion and memory promotion pass.
115 LoopPass *createLICMPass();
117 //===----------------------------------------------------------------------===//
119 // LoopStrengthReduce - This pass is strength reduces GEP instructions that use
120 // a loop's canonical induction variable as one of their indices. It takes an
121 // optional parameter used to consult the target machine whether certain
122 // transformations are profitable.
124 LoopPass *createLoopStrengthReducePass(const TargetLowering *TLI = 0);
126 //===----------------------------------------------------------------------===//
128 // LoopUnswitch - This pass is a simple loop unswitching pass.
130 LoopPass *createLoopUnswitchPass(bool OptimizeForSize = false);
132 //===----------------------------------------------------------------------===//
134 // LoopUnroll - This pass is a simple loop unrolling pass.
136 LoopPass *createLoopUnrollPass();
138 //===----------------------------------------------------------------------===//
140 // LoopRotate - This pass is a simple loop rotating pass.
142 LoopPass *createLoopRotatePass();
144 //===----------------------------------------------------------------------===//
146 // LoopIndexSplit - This pass divides loop's iteration range by spliting loop
147 // such that each individual loop is executed efficiently.
149 LoopPass *createLoopIndexSplitPass();
152 //===----------------------------------------------------------------------===//
154 // PromoteMemoryToRegister - This pass is used to promote memory references to
155 // be register references. A simple example of the transformation performed by
159 // %X = alloca int, uint 1 ret int 42
160 // store int 42, int *%X
164 FunctionPass *createPromoteMemoryToRegisterPass();
165 extern const PassInfo *PromoteMemoryToRegisterID;
167 //===----------------------------------------------------------------------===//
169 // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
170 // references. In basically undoes the PromoteMemoryToRegister pass to make cfg
173 FunctionPass *createDemoteRegisterToMemoryPass();
174 extern const PassInfo *DemoteRegisterToMemoryID;
176 //===----------------------------------------------------------------------===//
178 // Reassociate - This pass reassociates commutative expressions in an order that
179 // is designed to promote better constant propagation, GCSE, LICM, PRE...
181 // For example: 4 + (x + 5) -> x + (4 + 5)
183 FunctionPass *createReassociatePass();
185 //===----------------------------------------------------------------------===//
187 // CondPropagationPass - This pass propagates information about conditional
188 // expressions through the program, allowing it to eliminate conditional
189 // branches in some cases.
191 FunctionPass *createCondPropagationPass();
193 //===----------------------------------------------------------------------===//
195 // TailDuplication - Eliminate unconditional branches through controlled code
196 // duplication, creating simpler CFG structures.
198 FunctionPass *createTailDuplicationPass();
200 //===----------------------------------------------------------------------===//
202 // JumpThreading - Thread control through mult-pred/multi-succ blocks where some
203 // preds always go to some succ.
205 FunctionPass *createJumpThreadingPass();
207 //===----------------------------------------------------------------------===//
209 // CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
210 // simplify terminator instructions, etc...
212 FunctionPass *createCFGSimplificationPass();
214 //===----------------------------------------------------------------------===//
216 // BreakCriticalEdges - Break all of the critical edges in the CFG by inserting
217 // a dummy basic block. This pass may be "required" by passes that cannot deal
218 // 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 - Insert Pre-header blocks into the CFG for every function in
231 // the module. This pass updates dominator information, loop information, and
232 // does not add critical edges to the CFG.
234 // AU.addRequiredID(LoopSimplifyID);
236 FunctionPass *createLoopSimplifyPass();
237 extern const PassInfo *LoopSimplifyID;
239 //===----------------------------------------------------------------------===//
241 // LowerAllocations - Turn malloc and free instructions into %malloc and %free
244 // AU.addRequiredID(LowerAllocationsID);
246 Pass *createLowerAllocationsPass(bool LowerMallocArgToInteger = false);
247 extern const PassInfo *LowerAllocationsID;
249 //===----------------------------------------------------------------------===//
251 // TailCallElimination - This pass eliminates call instructions to the current
252 // function which occur immediately before return instructions.
254 FunctionPass *createTailCallEliminationPass();
256 //===----------------------------------------------------------------------===//
258 // LowerSwitch - This pass converts SwitchInst instructions into a sequence of
259 // chained binary branch instructions.
261 FunctionPass *createLowerSwitchPass();
262 extern const PassInfo *LowerSwitchID;
264 //===----------------------------------------------------------------------===//
266 // LowerInvoke - This pass converts invoke and unwind instructions to use sjlj
267 // exception handling mechanisms. Note that after this pass runs the CFG is not
268 // entirely accurate (exceptional control flow edges are not correct anymore) so
269 // only very simple things should be done after the lowerinvoke pass has run
270 // (like generation of native code). This should *NOT* be used as a general
271 // purpose "my LLVM-to-LLVM pass doesn't support the invoke instruction yet"
274 FunctionPass *createLowerInvokePass(const TargetLowering *TLI = NULL);
275 extern const PassInfo *LowerInvokePassID;
277 //===----------------------------------------------------------------------===//
279 // BlockPlacement - This pass reorders basic blocks in order to increase the
280 // number of fall-through conditional branches.
282 FunctionPass *createBlockPlacementPass();
284 //===----------------------------------------------------------------------===//
286 // LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop
289 LoopPass *createLCSSAPass();
290 extern const PassInfo *LCSSAID;
292 //===----------------------------------------------------------------------===//
294 // PredicateSimplifier - This pass collapses duplicate variables into one
295 // canonical form, and tries to simplify expressions along the way.
297 FunctionPass *createPredicateSimplifierPass();
299 //===----------------------------------------------------------------------===//
301 // GVN-PRE - This pass performs global value numbering and partial redundancy
304 FunctionPass *createGVNPREPass();
306 //===----------------------------------------------------------------------===//
308 // GVN - This pass performs global value numbering and redundant load
309 // elimination cotemporaneously.
311 FunctionPass *createGVNPass();
313 //===----------------------------------------------------------------------===//
315 // MemCpyOpt - This pass performs optimizations related to eliminating memcpy
316 // calls and/or combining multiple stores into memset's.
318 FunctionPass *createMemCpyOptPass();
320 //===----------------------------------------------------------------------===//
322 // LoopDeletion - This pass performs DCE of non-infinite loops that it
323 // can prove are dead.
325 LoopPass *createLoopDeletionPass();
327 //===----------------------------------------------------------------------===//
329 /// createSimplifyLibCallsPass - This pass optimizes specific calls to
330 /// specific well-known (library) functions.
331 FunctionPass *createSimplifyLibCallsPass();
333 //===----------------------------------------------------------------------===//
335 // CodeGenPrepare - This pass prepares a function for instruction selection.
337 FunctionPass *createCodeGenPreparePass(const TargetLowering *TLI = 0);
339 } // End llvm namespace