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