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);
79 //===----------------------------------------------------------------------===//
81 // InductionVariableSimplify - Transform induction variables in a program to all
82 // use a single canonical induction variable per loop.
84 Pass *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 Pass *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 Pass *createLoopStrengthReducePass(const TargetLowering *TLI = 0);
115 Pass *createGlobalMergePass(const TargetLowering *TLI = 0);
117 //===----------------------------------------------------------------------===//
119 // LoopUnswitch - This pass is a simple loop unswitching pass.
121 Pass *createLoopUnswitchPass(bool OptimizeForSize = false);
123 //===----------------------------------------------------------------------===//
125 // LoopInstSimplify - This pass simplifies instructions in a loop's body.
127 Pass *createLoopInstSimplifyPass();
129 //===----------------------------------------------------------------------===//
131 // LoopUnroll - This pass is a simple loop unrolling pass.
133 Pass *createLoopUnrollPass(int Threshold = -1, int Count = -1, int AllowPartial = -1);
135 //===----------------------------------------------------------------------===//
137 // LoopRotate - This pass is a simple loop rotating pass.
139 Pass *createLoopRotatePass();
141 //===----------------------------------------------------------------------===//
143 // LoopIdiom - This pass recognizes and replaces idioms in loops.
145 Pass *createLoopIdiomPass();
147 //===----------------------------------------------------------------------===//
149 // PromoteMemoryToRegister - This pass is used to promote memory references to
150 // be register references. A simple example of the transformation performed by
154 // %X = alloca i32, i32 1 ret i32 42
155 // store i32 42, i32 *%X
159 FunctionPass *createPromoteMemoryToRegisterPass();
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 char &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 // JumpThreading - Thread control through mult-pred/multi-succ blocks where some
182 // preds always go to some succ.
184 FunctionPass *createJumpThreadingPass();
186 //===----------------------------------------------------------------------===//
188 // CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
189 // simplify terminator instructions, etc...
191 FunctionPass *createCFGSimplificationPass();
193 //===----------------------------------------------------------------------===//
195 // BreakCriticalEdges - Break all of the critical edges in the CFG by inserting
196 // a dummy basic block. This pass may be "required" by passes that cannot deal
197 // with critical edges. For this usage, a pass must call:
199 // AU.addRequiredID(BreakCriticalEdgesID);
201 // This pass obviously invalidates the CFG, but can update forward dominator
202 // (set, immediate dominators, tree, and frontier) information.
204 FunctionPass *createBreakCriticalEdgesPass();
205 extern char &BreakCriticalEdgesID;
207 //===----------------------------------------------------------------------===//
209 // LoopSimplify - Insert Pre-header blocks into the CFG for every function in
210 // the module. This pass updates dominator information, loop information, and
211 // does not add critical edges to the CFG.
213 // AU.addRequiredID(LoopSimplifyID);
215 Pass *createLoopSimplifyPass();
216 extern char &LoopSimplifyID;
218 //===----------------------------------------------------------------------===//
220 // TailCallElimination - This pass eliminates call instructions to the current
221 // function which occur immediately before return instructions.
223 FunctionPass *createTailCallEliminationPass();
225 //===----------------------------------------------------------------------===//
227 // LowerSwitch - This pass converts SwitchInst instructions into a sequence of
228 // chained binary branch instructions.
230 FunctionPass *createLowerSwitchPass();
231 extern char &LowerSwitchID;
233 //===----------------------------------------------------------------------===//
235 // LowerInvoke - This pass converts invoke and unwind instructions to use sjlj
236 // exception handling mechanisms. Note that after this pass runs the CFG is not
237 // entirely accurate (exceptional control flow edges are not correct anymore) so
238 // only very simple things should be done after the lowerinvoke pass has run
239 // (like generation of native code). This should *NOT* be used as a general
240 // purpose "my LLVM-to-LLVM pass doesn't support the invoke instruction yet"
243 FunctionPass *createLowerInvokePass(const TargetLowering *TLI = 0);
244 FunctionPass *createLowerInvokePass(const TargetLowering *TLI,
245 bool useExpensiveEHSupport);
246 extern char &LowerInvokePassID;
248 //===----------------------------------------------------------------------===//
250 // BlockPlacement - This pass reorders basic blocks in order to increase the
251 // number of fall-through conditional branches.
253 FunctionPass *createBlockPlacementPass();
255 //===----------------------------------------------------------------------===//
257 // LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop
260 Pass *createLCSSAPass();
261 extern char &LCSSAID;
263 //===----------------------------------------------------------------------===//
265 // EarlyCSE - This pass performs a simple and fast CSE pass over the dominator
268 FunctionPass *createEarlyCSEPass();
270 //===----------------------------------------------------------------------===//
272 // GVN - This pass performs global value numbering and redundant load
273 // elimination cotemporaneously.
275 FunctionPass *createGVNPass(bool NoLoads = false);
277 //===----------------------------------------------------------------------===//
279 // MemCpyOpt - This pass performs optimizations related to eliminating memcpy
280 // calls and/or combining multiple stores into memset's.
282 FunctionPass *createMemCpyOptPass();
284 //===----------------------------------------------------------------------===//
286 // LoopDeletion - This pass performs DCE of non-infinite loops that it
287 // can prove are dead.
289 Pass *createLoopDeletionPass();
291 //===----------------------------------------------------------------------===//
293 /// createSimplifyLibCallsPass - This pass optimizes specific calls to
294 /// specific well-known (library) functions.
295 FunctionPass *createSimplifyLibCallsPass();
297 //===----------------------------------------------------------------------===//
299 // CodeGenPrepare - This pass prepares a function for instruction selection.
301 FunctionPass *createCodeGenPreparePass(const TargetLowering *TLI = 0);
303 //===----------------------------------------------------------------------===//
305 // InstructionNamer - Give any unnamed non-void instructions "tmp" names.
307 FunctionPass *createInstructionNamerPass();
308 extern char &InstructionNamerID;
310 //===----------------------------------------------------------------------===//
312 // Sink - Code Sinking
314 FunctionPass *createSinkingPass();
316 //===----------------------------------------------------------------------===//
318 // LowerAtomic - Lower atomic intrinsics to non-atomic form
320 Pass *createLowerAtomicPass();
322 //===----------------------------------------------------------------------===//
324 // ValuePropagation - Propagate CFG-derived value information
326 Pass *createCorrelatedValuePropagationPass();
328 //===----------------------------------------------------------------------===//
330 // ObjCARCAPElim - ObjC ARC autorelease pool elimination.
332 Pass *createObjCARCAPElimPass();
334 //===----------------------------------------------------------------------===//
336 // ObjCARCExpand - ObjC ARC preliminary simplifications.
338 Pass *createObjCARCExpandPass();
340 //===----------------------------------------------------------------------===//
342 // ObjCARCContract - Late ObjC ARC cleanups.
344 Pass *createObjCARCContractPass();
346 //===----------------------------------------------------------------------===//
348 // ObjCARCOpt - ObjC ARC optimization.
350 Pass *createObjCARCOptPass();
352 //===----------------------------------------------------------------------===//
354 // InstructionSimplifier - Remove redundant instructions.
356 FunctionPass *createInstructionSimplifierPass();
357 extern char &InstructionSimplifierID;
360 //===----------------------------------------------------------------------===//
362 // LowerExpectIntriniscs - Removes llvm.expect intrinsics and creates
363 // "block_weights" metadata.
364 FunctionPass *createLowerExpectIntrinsicPass();
367 } // End llvm namespace