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
22 class GetElementPtrInst;
27 //===----------------------------------------------------------------------===//
29 // ConstantPropagation - A worklist driven constant propagation pass
31 FunctionPass *createConstantPropagationPass();
33 //===----------------------------------------------------------------------===//
35 // SCCP - Sparse conditional constant propagation.
37 FunctionPass *createSCCPPass();
39 //===----------------------------------------------------------------------===//
41 // DeadInstElimination - This pass quickly removes trivially dead instructions
42 // without modifying the CFG of the function. It is a BasicBlockPass, so it
43 // runs efficiently when queued next to other BasicBlockPass's.
45 Pass *createDeadInstEliminationPass();
47 //===----------------------------------------------------------------------===//
49 // DeadCodeElimination - This pass is more powerful than DeadInstElimination,
50 // because it is worklist driven that can potentially revisit instructions when
51 // their other instructions become dead, to eliminate chains of dead
54 FunctionPass *createDeadCodeEliminationPass();
56 //===----------------------------------------------------------------------===//
58 // DeadStoreElimination - This pass deletes stores that are post-dominated by
59 // must-aliased stores and are not loaded used between the stores.
61 FunctionPass *createDeadStoreEliminationPass();
63 //===----------------------------------------------------------------------===//
65 // AggressiveDCE - This pass uses the SSA based Aggressive DCE algorithm. This
66 // algorithm assumes instructions are dead until proven otherwise, which makes
67 // it more successful are removing non-obviously dead instructions.
69 FunctionPass *createAggressiveDCEPass();
71 //===----------------------------------------------------------------------===//
73 // ScalarReplAggregates - Break up alloca's of aggregates into multiple allocas
76 FunctionPass *createScalarReplAggregatesPass(signed Threshold = -1,
77 bool UseDomTree = true,
78 signed StructMemberThreshold = -1,
79 signed ArrayElementThreshold = -1,
80 signed ScalarLoadThreshold = -1);
82 //===----------------------------------------------------------------------===//
84 // InductionVariableSimplify - Transform induction variables in a program to all
85 // use a single canonical induction variable per loop.
87 Pass *createIndVarSimplifyPass();
89 //===----------------------------------------------------------------------===//
91 // InstructionCombining - Combine instructions to form fewer, simple
92 // instructions. This pass does not modify the CFG, and has a tendency to make
93 // instructions dead, so a subsequent DCE pass is useful.
95 // This pass combines things like:
101 FunctionPass *createInstructionCombiningPass();
103 //===----------------------------------------------------------------------===//
105 // LICM - This pass is a loop invariant code motion and memory promotion pass.
107 Pass *createLICMPass();
109 //===----------------------------------------------------------------------===//
111 // LoopStrengthReduce - This pass is strength reduces GEP instructions that use
112 // a loop's canonical induction variable as one of their indices. It takes an
113 // optional parameter used to consult the target machine whether certain
114 // transformations are profitable.
116 Pass *createLoopStrengthReducePass(const TargetLowering *TLI = 0);
118 Pass *createGlobalMergePass(const TargetLowering *TLI = 0);
120 //===----------------------------------------------------------------------===//
122 // LoopUnswitch - This pass is a simple loop unswitching pass.
124 Pass *createLoopUnswitchPass(bool OptimizeForSize = false);
126 //===----------------------------------------------------------------------===//
128 // LoopInstSimplify - This pass simplifies instructions in a loop's body.
130 Pass *createLoopInstSimplifyPass();
132 //===----------------------------------------------------------------------===//
134 // LoopUnroll - This pass is a simple loop unrolling pass.
136 Pass *createLoopUnrollPass(int Threshold = -1, int Count = -1, int AllowPartial = -1);
138 //===----------------------------------------------------------------------===//
140 // LoopRotate - This pass is a simple loop rotating pass.
142 Pass *createLoopRotatePass();
144 //===----------------------------------------------------------------------===//
146 // LoopIdiom - This pass recognizes and replaces idioms in loops.
148 Pass *createLoopIdiomPass();
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 i32, i32 1 ret i32 42
158 // store i32 42, i32 *%X
162 FunctionPass *createPromoteMemoryToRegisterPass();
164 //===----------------------------------------------------------------------===//
166 // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
167 // references. In basically undoes the PromoteMemoryToRegister pass to make cfg
170 FunctionPass *createDemoteRegisterToMemoryPass();
171 extern char &DemoteRegisterToMemoryID;
173 //===----------------------------------------------------------------------===//
175 // Reassociate - This pass reassociates commutative expressions in an order that
176 // is designed to promote better constant propagation, GCSE, LICM, PRE...
178 // For example: 4 + (x + 5) -> x + (4 + 5)
180 FunctionPass *createReassociatePass();
182 //===----------------------------------------------------------------------===//
184 // JumpThreading - Thread control through mult-pred/multi-succ blocks where some
185 // preds always go to some succ.
187 FunctionPass *createJumpThreadingPass();
189 //===----------------------------------------------------------------------===//
191 // CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
192 // simplify terminator instructions, etc...
194 FunctionPass *createCFGSimplificationPass();
196 //===----------------------------------------------------------------------===//
198 // BreakCriticalEdges - Break all of the critical edges in the CFG by inserting
199 // a dummy basic block. This pass may be "required" by passes that cannot deal
200 // with critical edges. For this usage, a pass must call:
202 // AU.addRequiredID(BreakCriticalEdgesID);
204 // This pass obviously invalidates the CFG, but can update forward dominator
205 // (set, immediate dominators, tree, and frontier) information.
207 FunctionPass *createBreakCriticalEdgesPass();
208 extern char &BreakCriticalEdgesID;
210 //===----------------------------------------------------------------------===//
212 // LoopSimplify - Insert Pre-header blocks into the CFG for every function in
213 // the module. This pass updates dominator information, loop information, and
214 // does not add critical edges to the CFG.
216 // AU.addRequiredID(LoopSimplifyID);
218 Pass *createLoopSimplifyPass();
219 extern char &LoopSimplifyID;
221 //===----------------------------------------------------------------------===//
223 // TailCallElimination - This pass eliminates call instructions to the current
224 // function which occur immediately before return instructions.
226 FunctionPass *createTailCallEliminationPass();
228 //===----------------------------------------------------------------------===//
230 // LowerSwitch - This pass converts SwitchInst instructions into a sequence of
231 // chained binary branch instructions.
233 FunctionPass *createLowerSwitchPass();
234 extern char &LowerSwitchID;
236 //===----------------------------------------------------------------------===//
238 // LowerInvoke - This pass converts invoke and unwind instructions to use sjlj
239 // exception handling mechanisms. Note that after this pass runs the CFG is not
240 // entirely accurate (exceptional control flow edges are not correct anymore) so
241 // only very simple things should be done after the lowerinvoke pass has run
242 // (like generation of native code). This should *NOT* be used as a general
243 // purpose "my LLVM-to-LLVM pass doesn't support the invoke instruction yet"
246 FunctionPass *createLowerInvokePass(const TargetLowering *TLI = 0);
247 FunctionPass *createLowerInvokePass(const TargetLowering *TLI,
248 bool useExpensiveEHSupport);
249 extern char &LowerInvokePassID;
251 //===----------------------------------------------------------------------===//
253 // BlockPlacement - This pass reorders basic blocks in order to increase the
254 // number of fall-through conditional branches.
256 FunctionPass *createBlockPlacementPass();
258 //===----------------------------------------------------------------------===//
260 // LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop
263 Pass *createLCSSAPass();
264 extern char &LCSSAID;
266 //===----------------------------------------------------------------------===//
268 // EarlyCSE - This pass performs a simple and fast CSE pass over the dominator
271 FunctionPass *createEarlyCSEPass();
273 //===----------------------------------------------------------------------===//
275 // GVN - This pass performs global value numbering and redundant load
276 // elimination cotemporaneously.
278 FunctionPass *createGVNPass(bool NoLoads = false);
280 //===----------------------------------------------------------------------===//
282 // MemCpyOpt - This pass performs optimizations related to eliminating memcpy
283 // calls and/or combining multiple stores into memset's.
285 FunctionPass *createMemCpyOptPass();
287 //===----------------------------------------------------------------------===//
289 // LoopDeletion - This pass performs DCE of non-infinite loops that it
290 // can prove are dead.
292 Pass *createLoopDeletionPass();
294 //===----------------------------------------------------------------------===//
296 /// createSimplifyLibCallsPass - This pass optimizes specific calls to
297 /// specific well-known (library) functions.
298 FunctionPass *createSimplifyLibCallsPass();
300 //===----------------------------------------------------------------------===//
302 // CodeGenPrepare - This pass prepares a function for instruction selection.
304 FunctionPass *createCodeGenPreparePass(const TargetLowering *TLI = 0);
306 //===----------------------------------------------------------------------===//
308 // InstructionNamer - Give any unnamed non-void instructions "tmp" names.
310 FunctionPass *createInstructionNamerPass();
311 extern char &InstructionNamerID;
313 //===----------------------------------------------------------------------===//
315 // Sink - Code Sinking
317 FunctionPass *createSinkingPass();
319 //===----------------------------------------------------------------------===//
321 // LowerAtomic - Lower atomic intrinsics to non-atomic form
323 Pass *createLowerAtomicPass();
325 //===----------------------------------------------------------------------===//
327 // ValuePropagation - Propagate CFG-derived value information
329 Pass *createCorrelatedValuePropagationPass();
331 //===----------------------------------------------------------------------===//
333 // ObjCARCAPElim - ObjC ARC autorelease pool elimination.
335 Pass *createObjCARCAPElimPass();
337 //===----------------------------------------------------------------------===//
339 // ObjCARCExpand - ObjC ARC preliminary simplifications.
341 Pass *createObjCARCExpandPass();
343 //===----------------------------------------------------------------------===//
345 // ObjCARCContract - Late ObjC ARC cleanups.
347 Pass *createObjCARCContractPass();
349 //===----------------------------------------------------------------------===//
351 // ObjCARCOpt - ObjC ARC optimization.
353 Pass *createObjCARCOptPass();
355 //===----------------------------------------------------------------------===//
357 // InstructionSimplifier - Remove redundant instructions.
359 FunctionPass *createInstructionSimplifierPass();
360 extern char &InstructionSimplifierID;
363 //===----------------------------------------------------------------------===//
365 // LowerExpectIntriniscs - Removes llvm.expect intrinsics and creates
366 // "block_weights" metadata.
367 FunctionPass *createLowerExpectIntrinsicPass();
370 } // End llvm namespace