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();
141 //===----------------------------------------------------------------------===//
143 // PromoteMemoryToRegister - This pass is used to promote memory references to
144 // be register references. A simple example of the transformation performed by
148 // %X = alloca int, uint 1 ret int 42
149 // store int 42, int *%X
153 FunctionPass *createPromoteMemoryToRegisterPass();
154 extern const PassInfo *const PromoteMemoryToRegisterID;
156 //===----------------------------------------------------------------------===//
158 // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
159 // references. In basically undoes the PromoteMemoryToRegister pass to make cfg
162 FunctionPass *createDemoteRegisterToMemoryPass();
163 extern const PassInfo *const DemoteRegisterToMemoryID;
165 //===----------------------------------------------------------------------===//
167 // Reassociate - This pass reassociates commutative expressions in an order that
168 // is designed to promote better constant propagation, GCSE, LICM, PRE...
170 // For example: 4 + (x + 5) -> x + (4 + 5)
172 FunctionPass *createReassociatePass();
174 //===----------------------------------------------------------------------===//
176 // CondPropagationPass - This pass propagates information about conditional
177 // expressions through the program, allowing it to eliminate conditional
178 // branches in some cases.
180 FunctionPass *createCondPropagationPass();
182 //===----------------------------------------------------------------------===//
184 // TailDuplication - Eliminate unconditional branches through controlled code
185 // duplication, creating simpler CFG structures.
187 FunctionPass *createTailDuplicationPass();
189 //===----------------------------------------------------------------------===//
191 // JumpThreading - Thread control through mult-pred/multi-succ blocks where some
192 // preds always go to some succ.
194 FunctionPass *createJumpThreadingPass();
196 //===----------------------------------------------------------------------===//
198 // CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
199 // simplify terminator instructions, etc...
201 FunctionPass *createCFGSimplificationPass();
203 //===----------------------------------------------------------------------===//
205 // BreakCriticalEdges - Break all of the critical edges in the CFG by inserting
206 // a dummy basic block. This pass may be "required" by passes that cannot deal
207 // with critical edges. For this usage, a pass must call:
209 // AU.addRequiredID(BreakCriticalEdgesID);
211 // This pass obviously invalidates the CFG, but can update forward dominator
212 // (set, immediate dominators, tree, and frontier) information.
214 FunctionPass *createBreakCriticalEdgesPass();
215 extern const PassInfo *const BreakCriticalEdgesID;
217 //===----------------------------------------------------------------------===//
219 // LoopSimplify - Insert Pre-header blocks into the CFG for every function in
220 // the module. This pass updates dominator information, loop information, and
221 // does not add critical edges to the CFG.
223 // AU.addRequiredID(LoopSimplifyID);
225 FunctionPass *createLoopSimplifyPass();
226 extern const PassInfo *const LoopSimplifyID;
228 //===----------------------------------------------------------------------===//
230 // LowerAllocations - Turn malloc and free instructions into %malloc and %free
233 // AU.addRequiredID(LowerAllocationsID);
235 Pass *createLowerAllocationsPass(bool LowerMallocArgToInteger = false);
236 extern const PassInfo *const LowerAllocationsID;
238 //===----------------------------------------------------------------------===//
240 // TailCallElimination - This pass eliminates call instructions to the current
241 // function which occur immediately before return instructions.
243 FunctionPass *createTailCallEliminationPass();
245 //===----------------------------------------------------------------------===//
247 // LowerSwitch - This pass converts SwitchInst instructions into a sequence of
248 // chained binary branch instructions.
250 FunctionPass *createLowerSwitchPass();
251 extern const PassInfo *const LowerSwitchID;
253 //===----------------------------------------------------------------------===//
255 // LowerInvoke - This pass converts invoke and unwind instructions to use sjlj
256 // exception handling mechanisms. Note that after this pass runs the CFG is not
257 // entirely accurate (exceptional control flow edges are not correct anymore) so
258 // only very simple things should be done after the lowerinvoke pass has run
259 // (like generation of native code). This should *NOT* be used as a general
260 // purpose "my LLVM-to-LLVM pass doesn't support the invoke instruction yet"
263 FunctionPass *createLowerInvokePass(const TargetLowering *TLI = 0);
264 extern const PassInfo *const LowerInvokePassID;
266 //===----------------------------------------------------------------------===//
268 // BlockPlacement - This pass reorders basic blocks in order to increase the
269 // number of fall-through conditional branches.
271 FunctionPass *createBlockPlacementPass();
273 //===----------------------------------------------------------------------===//
275 // LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop
278 LoopPass *createLCSSAPass();
279 extern const PassInfo *const LCSSAID;
281 //===----------------------------------------------------------------------===//
283 // PredicateSimplifier - This pass collapses duplicate variables into one
284 // canonical form, and tries to simplify expressions along the way.
286 FunctionPass *createPredicateSimplifierPass();
288 //===----------------------------------------------------------------------===//
290 // GVN-PRE - This pass performs global value numbering and partial redundancy
293 FunctionPass *createGVNPREPass();
295 //===----------------------------------------------------------------------===//
297 // GVN - This pass performs global value numbering and redundant load
298 // elimination cotemporaneously.
300 FunctionPass *createGVNPass();
302 //===----------------------------------------------------------------------===//
304 // MemCpyOpt - This pass performs optimizations related to eliminating memcpy
305 // calls and/or combining multiple stores into memset's.
307 FunctionPass *createMemCpyOptPass();
309 //===----------------------------------------------------------------------===//
311 // LoopDeletion - This pass performs DCE of non-infinite loops that it
312 // can prove are dead.
314 LoopPass *createLoopDeletionPass();
316 //===----------------------------------------------------------------------===//
318 /// createSimplifyLibCallsPass - This pass optimizes specific calls to
319 /// specific well-known (library) functions.
320 FunctionPass *createSimplifyLibCallsPass();
322 //===----------------------------------------------------------------------===//
324 // CodeGenPrepare - This pass prepares a function for instruction selection.
326 FunctionPass *createCodeGenPreparePass(const TargetLowering *TLI = 0);
328 } // End llvm namespace