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 // InductionVariableSimplify - Transform induction variables in a program to all
82 // use a single canonical induction variable per loop.
84 LoopPass *createIndVarSimplifyPass();
86 //===----------------------------------------------------------------------===//
88 // InstructionCombining - Combine instructions to form fewer, simple
89 // instructions. This pass does not modify the CFG, and has a tendency to make
90 // instructions dead, so a subsequent DCE pass is useful.
92 // This pass combines things like:
98 FunctionPass *createInstructionCombiningPass();
100 //===----------------------------------------------------------------------===//
102 // LICM - This pass is a loop invariant code motion and memory promotion pass.
104 LoopPass *createLICMPass();
106 //===----------------------------------------------------------------------===//
108 // LoopStrengthReduce - This pass is strength reduces GEP instructions that use
109 // a loop's canonical induction variable as one of their indices. It takes an
110 // optional parameter used to consult the target machine whether certain
111 // transformations are profitable.
113 LoopPass *createLoopStrengthReducePass(const TargetLowering *TLI = 0);
115 //===----------------------------------------------------------------------===//
117 // LoopUnswitch - This pass is a simple loop unswitching pass.
119 LoopPass *createLoopUnswitchPass(bool OptimizeForSize = false);
121 //===----------------------------------------------------------------------===//
123 // LoopUnroll - This pass is a simple loop unrolling pass.
125 LoopPass *createLoopUnrollPass();
127 //===----------------------------------------------------------------------===//
129 // LoopRotate - This pass is a simple loop rotating pass.
131 LoopPass *createLoopRotatePass();
133 //===----------------------------------------------------------------------===//
135 // LoopIndexSplit - This pass divides loop's iteration range by spliting loop
136 // such that each individual loop is executed efficiently.
138 LoopPass *createLoopIndexSplitPass();
140 //===----------------------------------------------------------------------===//
142 // PromoteMemoryToRegister - This pass is used to promote memory references to
143 // be register references. A simple example of the transformation performed by
147 // %X = alloca int, uint 1 ret int 42
148 // store int 42, int *%X
152 FunctionPass *createPromoteMemoryToRegisterPass();
153 extern const PassInfo *const PromoteMemoryToRegisterID;
155 //===----------------------------------------------------------------------===//
157 // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
158 // references. In basically undoes the PromoteMemoryToRegister pass to make cfg
161 FunctionPass *createDemoteRegisterToMemoryPass();
162 extern const PassInfo *const DemoteRegisterToMemoryID;
164 //===----------------------------------------------------------------------===//
166 // Reassociate - This pass reassociates commutative expressions in an order that
167 // is designed to promote better constant propagation, GCSE, LICM, PRE...
169 // For example: 4 + (x + 5) -> x + (4 + 5)
171 FunctionPass *createReassociatePass();
173 //===----------------------------------------------------------------------===//
175 // CondPropagationPass - This pass propagates information about conditional
176 // expressions through the program, allowing it to eliminate conditional
177 // branches in some cases.
179 FunctionPass *createCondPropagationPass();
181 //===----------------------------------------------------------------------===//
183 // TailDuplication - Eliminate unconditional branches through controlled code
184 // duplication, creating simpler CFG structures.
186 FunctionPass *createTailDuplicationPass();
188 //===----------------------------------------------------------------------===//
190 // JumpThreading - Thread control through mult-pred/multi-succ blocks where some
191 // preds always go to some succ.
193 FunctionPass *createJumpThreadingPass();
195 //===----------------------------------------------------------------------===//
197 // CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
198 // simplify terminator instructions, etc...
200 FunctionPass *createCFGSimplificationPass();
202 //===----------------------------------------------------------------------===//
204 // BreakCriticalEdges - Break all of the critical edges in the CFG by inserting
205 // a dummy basic block. This pass may be "required" by passes that cannot deal
206 // with critical edges. For this usage, a pass must call:
208 // AU.addRequiredID(BreakCriticalEdgesID);
210 // This pass obviously invalidates the CFG, but can update forward dominator
211 // (set, immediate dominators, tree, and frontier) information.
213 FunctionPass *createBreakCriticalEdgesPass();
214 extern const PassInfo *const BreakCriticalEdgesID;
216 //===----------------------------------------------------------------------===//
218 // LoopSimplify - Insert Pre-header blocks into the CFG for every function in
219 // the module. This pass updates dominator information, loop information, and
220 // does not add critical edges to the CFG.
222 // AU.addRequiredID(LoopSimplifyID);
224 FunctionPass *createLoopSimplifyPass();
225 extern const PassInfo *const LoopSimplifyID;
227 //===----------------------------------------------------------------------===//
229 // LowerAllocations - Turn malloc and free instructions into %malloc and %free
232 // AU.addRequiredID(LowerAllocationsID);
234 Pass *createLowerAllocationsPass(bool LowerMallocArgToInteger = false);
235 extern const PassInfo *const LowerAllocationsID;
237 //===----------------------------------------------------------------------===//
239 // TailCallElimination - This pass eliminates call instructions to the current
240 // function which occur immediately before return instructions.
242 FunctionPass *createTailCallEliminationPass();
244 //===----------------------------------------------------------------------===//
246 // LowerSwitch - This pass converts SwitchInst instructions into a sequence of
247 // chained binary branch instructions.
249 FunctionPass *createLowerSwitchPass();
250 extern const PassInfo *const LowerSwitchID;
252 //===----------------------------------------------------------------------===//
254 // LowerInvoke - This pass converts invoke and unwind instructions to use sjlj
255 // exception handling mechanisms. Note that after this pass runs the CFG is not
256 // entirely accurate (exceptional control flow edges are not correct anymore) so
257 // only very simple things should be done after the lowerinvoke pass has run
258 // (like generation of native code). This should *NOT* be used as a general
259 // purpose "my LLVM-to-LLVM pass doesn't support the invoke instruction yet"
262 FunctionPass *createLowerInvokePass(const TargetLowering *TLI = 0);
263 extern const PassInfo *const LowerInvokePassID;
265 //===----------------------------------------------------------------------===//
267 // BlockPlacement - This pass reorders basic blocks in order to increase the
268 // number of fall-through conditional branches.
270 FunctionPass *createBlockPlacementPass();
272 //===----------------------------------------------------------------------===//
274 // LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop
277 LoopPass *createLCSSAPass();
278 extern const PassInfo *const LCSSAID;
280 //===----------------------------------------------------------------------===//
282 // PredicateSimplifier - This pass collapses duplicate variables into one
283 // canonical form, and tries to simplify expressions along the way.
285 FunctionPass *createPredicateSimplifierPass();
287 //===----------------------------------------------------------------------===//
289 // GVN-PRE - This pass performs global value numbering and partial redundancy
292 FunctionPass *createGVNPREPass();
294 //===----------------------------------------------------------------------===//
296 // GVN - This pass performs global value numbering and redundant load
297 // elimination cotemporaneously.
299 FunctionPass *createGVNPass();
301 //===----------------------------------------------------------------------===//
303 // MemCpyOpt - This pass performs optimizations related to eliminating memcpy
304 // calls and/or combining multiple stores into memset's.
306 FunctionPass *createMemCpyOptPass();
308 //===----------------------------------------------------------------------===//
310 // LoopDeletion - This pass performs DCE of non-infinite loops that it
311 // can prove are dead.
313 LoopPass *createLoopDeletionPass();
315 //===----------------------------------------------------------------------===//
317 /// createSimplifyLibCallsPass - This pass optimizes specific calls to
318 /// specific well-known (library) functions.
319 FunctionPass *createSimplifyLibCallsPass();
321 //===----------------------------------------------------------------------===//
323 // CodeGenPrepare - This pass prepares a function for instruction selection.
325 FunctionPass *createCodeGenPreparePass(const TargetLowering *TLI = 0);
328 //===----------------------------------------------------------------------===//
330 // InstructionNamer - Give any unnamed non-void instructions "tmp" names.
332 FunctionPass *createInstructionNamerPass();
334 } // End llvm namespace