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;
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 // SROA - Replace aggregates or pieces of aggregates with scalar SSA values.
76 FunctionPass *createSROAPass(bool RequiresDomTree = true);
78 //===----------------------------------------------------------------------===//
80 // ScalarReplAggregates - Break up alloca's of aggregates into multiple allocas
83 FunctionPass *createScalarReplAggregatesPass(signed Threshold = -1,
84 bool UseDomTree = true,
85 signed StructMemberThreshold = -1,
86 signed ArrayElementThreshold = -1,
87 signed ScalarLoadThreshold = -1);
89 //===----------------------------------------------------------------------===//
91 // InductionVariableSimplify - Transform induction variables in a program to all
92 // use a single canonical induction variable per loop.
94 Pass *createIndVarSimplifyPass();
96 //===----------------------------------------------------------------------===//
98 // InstructionCombining - Combine instructions to form fewer, simple
99 // instructions. This pass does not modify the CFG, and has a tendency to make
100 // instructions dead, so a subsequent DCE pass is useful.
102 // This pass combines things like:
103 // %Y = add int 1, %X
104 // %Z = add int 1, %Y
106 // %Z = add int 2, %X
108 FunctionPass *createInstructionCombiningPass();
110 //===----------------------------------------------------------------------===//
112 // LICM - This pass is a loop invariant code motion and memory promotion pass.
114 Pass *createLICMPass();
116 //===----------------------------------------------------------------------===//
118 // LoopStrengthReduce - This pass is strength reduces GEP instructions that use
119 // a loop's canonical induction variable as one of their indices.
121 Pass *createLoopStrengthReducePass();
123 Pass *createGlobalMergePass(const TargetMachine *TM = 0);
125 //===----------------------------------------------------------------------===//
127 // LoopUnswitch - This pass is a simple loop unswitching pass.
129 Pass *createLoopUnswitchPass(bool OptimizeForSize = false);
131 //===----------------------------------------------------------------------===//
133 // LoopInstSimplify - This pass simplifies instructions in a loop's body.
135 Pass *createLoopInstSimplifyPass();
137 //===----------------------------------------------------------------------===//
139 // LoopUnroll - This pass is a simple loop unrolling pass.
141 Pass *createLoopUnrollPass(int Threshold = -1, int Count = -1,
142 int AllowPartial = -1, int Runtime = -1);
144 //===----------------------------------------------------------------------===//
146 // LoopRotate - This pass is a simple loop rotating pass.
148 Pass *createLoopRotatePass();
150 //===----------------------------------------------------------------------===//
152 // LoopIdiom - This pass recognizes and replaces idioms in loops.
154 Pass *createLoopIdiomPass();
156 //===----------------------------------------------------------------------===//
158 // PromoteMemoryToRegister - This pass is used to promote memory references to
159 // be register references. A simple example of the transformation performed by
163 // %X = alloca i32, i32 1 ret i32 42
164 // store i32 42, i32 *%X
168 FunctionPass *createPromoteMemoryToRegisterPass();
170 //===----------------------------------------------------------------------===//
172 // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
173 // references. In basically undoes the PromoteMemoryToRegister pass to make cfg
176 FunctionPass *createDemoteRegisterToMemoryPass();
177 extern char &DemoteRegisterToMemoryID;
179 //===----------------------------------------------------------------------===//
181 // Reassociate - This pass reassociates commutative expressions in an order that
182 // is designed to promote better constant propagation, GCSE, LICM, PRE...
184 // For example: 4 + (x + 5) -> x + (4 + 5)
186 FunctionPass *createReassociatePass();
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 // FlattenCFG - flatten CFG, reduce number of conditional branches by using
205 // parallel-and and parallel-or mode, etc...
207 FunctionPass *createFlattenCFGPass();
209 //===----------------------------------------------------------------------===//
211 // CFG Structurization - Remove irreducible control flow
213 Pass *createStructurizeCFGPass();
215 //===----------------------------------------------------------------------===//
217 // BreakCriticalEdges - Break all of the critical edges in the CFG by inserting
218 // a dummy basic block. This pass may be "required" by passes that cannot deal
219 // with critical edges. For this usage, a pass must call:
221 // AU.addRequiredID(BreakCriticalEdgesID);
223 // This pass obviously invalidates the CFG, but can update forward dominator
224 // (set, immediate dominators, tree, and frontier) information.
226 FunctionPass *createBreakCriticalEdgesPass();
227 extern char &BreakCriticalEdgesID;
229 //===----------------------------------------------------------------------===//
231 // LoopSimplify - Insert Pre-header blocks into the CFG for every function in
232 // the module. This pass updates dominator information, loop information, and
233 // does not add critical edges to the CFG.
235 // AU.addRequiredID(LoopSimplifyID);
237 Pass *createLoopSimplifyPass();
238 extern char &LoopSimplifyID;
240 //===----------------------------------------------------------------------===//
242 // TailCallElimination - This pass eliminates call instructions to the current
243 // function which occur immediately before return instructions.
245 FunctionPass *createTailCallEliminationPass();
247 //===----------------------------------------------------------------------===//
249 // LowerSwitch - This pass converts SwitchInst instructions into a sequence of
250 // chained binary branch instructions.
252 FunctionPass *createLowerSwitchPass();
253 extern char &LowerSwitchID;
255 //===----------------------------------------------------------------------===//
257 // LowerInvoke - This pass converts invoke and unwind instructions to use sjlj
258 // exception handling mechanisms. Note that after this pass runs the CFG is not
259 // entirely accurate (exceptional control flow edges are not correct anymore) so
260 // only very simple things should be done after the lowerinvoke pass has run
261 // (like generation of native code). This should *NOT* be used as a general
262 // purpose "my LLVM-to-LLVM pass doesn't support the invoke instruction yet"
265 FunctionPass *createLowerInvokePass(const TargetMachine *TM = 0,
266 bool useExpensiveEHSupport = false);
267 extern char &LowerInvokePassID;
269 //===----------------------------------------------------------------------===//
271 // LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop
274 Pass *createLCSSAPass();
275 extern char &LCSSAID;
277 //===----------------------------------------------------------------------===//
279 // EarlyCSE - This pass performs a simple and fast CSE pass over the dominator
282 FunctionPass *createEarlyCSEPass();
284 //===----------------------------------------------------------------------===//
286 // GVN - This pass performs global value numbering and redundant load
287 // elimination cotemporaneously.
289 FunctionPass *createGVNPass(bool NoLoads = false);
291 //===----------------------------------------------------------------------===//
293 // MemCpyOpt - This pass performs optimizations related to eliminating memcpy
294 // calls and/or combining multiple stores into memset's.
296 FunctionPass *createMemCpyOptPass();
298 //===----------------------------------------------------------------------===//
300 // LoopDeletion - This pass performs DCE of non-infinite loops that it
301 // can prove are dead.
303 Pass *createLoopDeletionPass();
305 //===----------------------------------------------------------------------===//
307 // CodeGenPrepare - This pass prepares a function for instruction selection.
309 FunctionPass *createCodeGenPreparePass(const TargetMachine *TM = 0);
311 //===----------------------------------------------------------------------===//
313 // InstructionNamer - Give any unnamed non-void instructions "tmp" names.
315 FunctionPass *createInstructionNamerPass();
316 extern char &InstructionNamerID;
318 //===----------------------------------------------------------------------===//
320 // Sink - Code Sinking
322 FunctionPass *createSinkingPass();
324 //===----------------------------------------------------------------------===//
326 // LowerAtomic - Lower atomic intrinsics to non-atomic form
328 Pass *createLowerAtomicPass();
330 //===----------------------------------------------------------------------===//
332 // ValuePropagation - Propagate CFG-derived value information
334 Pass *createCorrelatedValuePropagationPass();
336 //===----------------------------------------------------------------------===//
338 // InstructionSimplifier - Remove redundant instructions.
340 FunctionPass *createInstructionSimplifierPass();
341 extern char &InstructionSimplifierID;
344 //===----------------------------------------------------------------------===//
346 // LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates
347 // "block_weights" metadata.
348 FunctionPass *createLowerExpectIntrinsicPass();
351 //===----------------------------------------------------------------------===//
353 // PartiallyInlineLibCalls - Tries to inline the fast path of library
354 // calls such as sqrt.
356 FunctionPass *createPartiallyInlineLibCallsPass();
358 } // End llvm namespace