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