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 // SROA - Replace aggregates or pieces of aggregates with scalar SSA values.
75 FunctionPass *createSROAPass(bool RequiresDomTree = true);
77 //===----------------------------------------------------------------------===//
79 // ScalarReplAggregates - Break up alloca's of aggregates into multiple allocas
82 FunctionPass *createScalarReplAggregatesPass(signed Threshold = -1,
83 bool UseDomTree = true,
84 signed StructMemberThreshold = -1,
85 signed ArrayElementThreshold = -1,
86 signed ScalarLoadThreshold = -1);
88 //===----------------------------------------------------------------------===//
90 // InductionVariableSimplify - Transform induction variables in a program to all
91 // use a single canonical induction variable per loop.
93 Pass *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 Pass *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.
120 Pass *createLoopStrengthReducePass();
122 Pass *createGlobalMergePass(const TargetLowering *TLI = 0);
124 //===----------------------------------------------------------------------===//
126 // LoopUnswitch - This pass is a simple loop unswitching pass.
128 Pass *createLoopUnswitchPass(bool OptimizeForSize = false);
130 //===----------------------------------------------------------------------===//
132 // LoopInstSimplify - This pass simplifies instructions in a loop's body.
134 Pass *createLoopInstSimplifyPass();
136 //===----------------------------------------------------------------------===//
138 // LoopUnroll - This pass is a simple loop unrolling pass.
140 Pass *createLoopUnrollPass(int Threshold = -1, int Count = -1, int AllowPartial = -1);
142 //===----------------------------------------------------------------------===//
144 // LoopRotate - This pass is a simple loop rotating pass.
146 Pass *createLoopRotatePass();
148 //===----------------------------------------------------------------------===//
150 // LoopIdiom - This pass recognizes and replaces idioms in loops.
152 Pass *createLoopIdiomPass();
154 //===----------------------------------------------------------------------===//
156 // PromoteMemoryToRegister - This pass is used to promote memory references to
157 // be register references. A simple example of the transformation performed by
161 // %X = alloca i32, i32 1 ret i32 42
162 // store i32 42, i32 *%X
166 FunctionPass *createPromoteMemoryToRegisterPass();
168 //===----------------------------------------------------------------------===//
170 // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
171 // references. In basically undoes the PromoteMemoryToRegister pass to make cfg
174 FunctionPass *createDemoteRegisterToMemoryPass();
175 extern char &DemoteRegisterToMemoryID;
177 //===----------------------------------------------------------------------===//
179 // Reassociate - This pass reassociates commutative expressions in an order that
180 // is designed to promote better constant propagation, GCSE, LICM, PRE...
182 // For example: 4 + (x + 5) -> x + (4 + 5)
184 FunctionPass *createReassociatePass();
186 //===----------------------------------------------------------------------===//
188 // JumpThreading - Thread control through mult-pred/multi-succ blocks where some
189 // preds always go to some succ.
191 FunctionPass *createJumpThreadingPass();
193 //===----------------------------------------------------------------------===//
195 // CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
196 // simplify terminator instructions, etc...
198 FunctionPass *createCFGSimplificationPass();
200 //===----------------------------------------------------------------------===//
202 // CFG Structurization - Remove irreducible control flow
204 Pass *createStructurizeCFGPass();
206 //===----------------------------------------------------------------------===//
208 // BreakCriticalEdges - Break all of the critical edges in the CFG by inserting
209 // a dummy basic block. This pass may be "required" by passes that cannot deal
210 // with critical edges. For this usage, a pass must call:
212 // AU.addRequiredID(BreakCriticalEdgesID);
214 // This pass obviously invalidates the CFG, but can update forward dominator
215 // (set, immediate dominators, tree, and frontier) information.
217 FunctionPass *createBreakCriticalEdgesPass();
218 extern char &BreakCriticalEdgesID;
220 //===----------------------------------------------------------------------===//
222 // LoopSimplify - Insert Pre-header blocks into the CFG for every function in
223 // the module. This pass updates dominator information, loop information, and
224 // does not add critical edges to the CFG.
226 // AU.addRequiredID(LoopSimplifyID);
228 Pass *createLoopSimplifyPass();
229 extern char &LoopSimplifyID;
231 //===----------------------------------------------------------------------===//
233 // TailCallElimination - This pass eliminates call instructions to the current
234 // function which occur immediately before return instructions.
236 FunctionPass *createTailCallEliminationPass();
238 //===----------------------------------------------------------------------===//
240 // LowerSwitch - This pass converts SwitchInst instructions into a sequence of
241 // chained binary branch instructions.
243 FunctionPass *createLowerSwitchPass();
244 extern char &LowerSwitchID;
246 //===----------------------------------------------------------------------===//
248 // LowerInvoke - This pass converts invoke and unwind instructions to use sjlj
249 // exception handling mechanisms. Note that after this pass runs the CFG is not
250 // entirely accurate (exceptional control flow edges are not correct anymore) so
251 // only very simple things should be done after the lowerinvoke pass has run
252 // (like generation of native code). This should *NOT* be used as a general
253 // purpose "my LLVM-to-LLVM pass doesn't support the invoke instruction yet"
256 FunctionPass *createLowerInvokePass(const TargetLowering *TLI = 0);
257 FunctionPass *createLowerInvokePass(const TargetLowering *TLI,
258 bool useExpensiveEHSupport);
259 extern char &LowerInvokePassID;
261 //===----------------------------------------------------------------------===//
263 // BlockPlacement - This pass reorders basic blocks in order to increase the
264 // number of fall-through conditional branches.
266 FunctionPass *createBlockPlacementPass();
268 //===----------------------------------------------------------------------===//
270 // LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop
273 Pass *createLCSSAPass();
274 extern char &LCSSAID;
276 //===----------------------------------------------------------------------===//
278 // EarlyCSE - This pass performs a simple and fast CSE pass over the dominator
281 FunctionPass *createEarlyCSEPass();
283 //===----------------------------------------------------------------------===//
285 // GVN - This pass performs global value numbering and redundant load
286 // elimination cotemporaneously.
288 FunctionPass *createGVNPass(bool NoLoads = false);
290 //===----------------------------------------------------------------------===//
292 // MemCpyOpt - This pass performs optimizations related to eliminating memcpy
293 // calls and/or combining multiple stores into memset's.
295 FunctionPass *createMemCpyOptPass();
297 //===----------------------------------------------------------------------===//
299 // LoopDeletion - This pass performs DCE of non-infinite loops that it
300 // can prove are dead.
302 Pass *createLoopDeletionPass();
304 //===----------------------------------------------------------------------===//
306 /// createSimplifyLibCallsPass - This pass optimizes specific calls to
307 /// specific well-known (library) functions.
308 FunctionPass *createSimplifyLibCallsPass();
310 //===----------------------------------------------------------------------===//
312 // CodeGenPrepare - This pass prepares a function for instruction selection.
314 FunctionPass *createCodeGenPreparePass(const TargetLowering *TLI = 0);
316 //===----------------------------------------------------------------------===//
318 // InstructionNamer - Give any unnamed non-void instructions "tmp" names.
320 FunctionPass *createInstructionNamerPass();
321 extern char &InstructionNamerID;
323 //===----------------------------------------------------------------------===//
325 // Sink - Code Sinking
327 FunctionPass *createSinkingPass();
329 //===----------------------------------------------------------------------===//
331 // LowerAtomic - Lower atomic intrinsics to non-atomic form
333 Pass *createLowerAtomicPass();
335 //===----------------------------------------------------------------------===//
337 // ValuePropagation - Propagate CFG-derived value information
339 Pass *createCorrelatedValuePropagationPass();
341 //===----------------------------------------------------------------------===//
343 // InstructionSimplifier - Remove redundant instructions.
345 FunctionPass *createInstructionSimplifierPass();
346 extern char &InstructionSimplifierID;
349 //===----------------------------------------------------------------------===//
351 // LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates
352 // "block_weights" metadata.
353 FunctionPass *createLowerExpectIntrinsicPass();
356 } // End llvm namespace