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
18 #include "llvm/ADT/StringRef.h"
24 class GetElementPtrInst;
30 //===----------------------------------------------------------------------===//
32 // ConstantPropagation - A worklist driven constant propagation pass
34 FunctionPass *createConstantPropagationPass();
36 //===----------------------------------------------------------------------===//
38 // SCCP - Sparse conditional constant propagation.
40 FunctionPass *createSCCPPass();
42 //===----------------------------------------------------------------------===//
44 // DeadInstElimination - This pass quickly removes trivially dead instructions
45 // without modifying the CFG of the function. It is a BasicBlockPass, so it
46 // runs efficiently when queued next to other BasicBlockPass's.
48 Pass *createDeadInstEliminationPass();
50 //===----------------------------------------------------------------------===//
52 // DeadCodeElimination - This pass is more powerful than DeadInstElimination,
53 // because it is worklist driven that can potentially revisit instructions when
54 // their other instructions become dead, to eliminate chains of dead
57 FunctionPass *createDeadCodeEliminationPass();
59 //===----------------------------------------------------------------------===//
61 // DeadStoreElimination - This pass deletes stores that are post-dominated by
62 // must-aliased stores and are not loaded used between the stores.
64 FunctionPass *createDeadStoreEliminationPass();
66 //===----------------------------------------------------------------------===//
68 // AggressiveDCE - This pass uses the SSA based Aggressive DCE algorithm. This
69 // algorithm assumes instructions are dead until proven otherwise, which makes
70 // it more successful are removing non-obviously dead instructions.
72 FunctionPass *createAggressiveDCEPass();
74 //===----------------------------------------------------------------------===//
76 // SROA - Replace aggregates or pieces of aggregates with scalar SSA values.
78 FunctionPass *createSROAPass(bool RequiresDomTree = true);
80 //===----------------------------------------------------------------------===//
82 // ScalarReplAggregates - Break up alloca's of aggregates into multiple allocas
85 FunctionPass *createScalarReplAggregatesPass(signed Threshold = -1,
86 bool UseDomTree = true,
87 signed StructMemberThreshold = -1,
88 signed ArrayElementThreshold = -1,
89 signed ScalarLoadThreshold = -1);
91 //===----------------------------------------------------------------------===//
93 // InductionVariableSimplify - Transform induction variables in a program to all
94 // use a single canonical induction variable per loop.
96 Pass *createIndVarSimplifyPass();
98 //===----------------------------------------------------------------------===//
100 // InstructionCombining - Combine instructions to form fewer, simple
101 // instructions. This pass does not modify the CFG, and has a tendency to make
102 // instructions dead, so a subsequent DCE pass is useful.
104 // This pass combines things like:
105 // %Y = add int 1, %X
106 // %Z = add int 1, %Y
108 // %Z = add int 2, %X
110 FunctionPass *createInstructionCombiningPass();
112 //===----------------------------------------------------------------------===//
114 // LICM - This pass is a loop invariant code motion and memory promotion pass.
116 Pass *createLICMPass();
118 //===----------------------------------------------------------------------===//
120 // LoopStrengthReduce - This pass is strength reduces GEP instructions that use
121 // a loop's canonical induction variable as one of their indices.
123 Pass *createLoopStrengthReducePass();
125 Pass *createGlobalMergePass(const TargetMachine *TM = 0);
127 //===----------------------------------------------------------------------===//
129 // LoopUnswitch - This pass is a simple loop unswitching pass.
131 Pass *createLoopUnswitchPass(bool OptimizeForSize = false);
133 //===----------------------------------------------------------------------===//
135 // LoopInstSimplify - This pass simplifies instructions in a loop's body.
137 Pass *createLoopInstSimplifyPass();
139 //===----------------------------------------------------------------------===//
141 // LoopUnroll - This pass is a simple loop unrolling pass.
143 Pass *createLoopUnrollPass(int Threshold = -1, int Count = -1,
144 int AllowPartial = -1, int Runtime = -1);
146 //===----------------------------------------------------------------------===//
148 // LoopReroll - This pass is a simple loop rerolling pass.
150 Pass *createLoopRerollPass();
152 //===----------------------------------------------------------------------===//
154 // LoopRotate - This pass is a simple loop rotating pass.
156 Pass *createLoopRotatePass();
158 //===----------------------------------------------------------------------===//
160 // LoopIdiom - This pass recognizes and replaces idioms in loops.
162 Pass *createLoopIdiomPass();
164 //===----------------------------------------------------------------------===//
166 // PromoteMemoryToRegister - This pass is used to promote memory references to
167 // be register references. A simple example of the transformation performed by
171 // %X = alloca i32, i32 1 ret i32 42
172 // store i32 42, i32 *%X
176 FunctionPass *createPromoteMemoryToRegisterPass();
178 //===----------------------------------------------------------------------===//
180 // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
181 // references. In basically undoes the PromoteMemoryToRegister pass to make cfg
184 FunctionPass *createDemoteRegisterToMemoryPass();
185 extern char &DemoteRegisterToMemoryID;
187 //===----------------------------------------------------------------------===//
189 // Reassociate - This pass reassociates commutative expressions in an order that
190 // is designed to promote better constant propagation, GCSE, LICM, PRE...
192 // For example: 4 + (x + 5) -> x + (4 + 5)
194 FunctionPass *createReassociatePass();
196 //===----------------------------------------------------------------------===//
198 // JumpThreading - Thread control through mult-pred/multi-succ blocks where some
199 // preds always go to some succ.
201 FunctionPass *createJumpThreadingPass();
203 //===----------------------------------------------------------------------===//
205 // CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
206 // simplify terminator instructions, etc...
208 FunctionPass *createCFGSimplificationPass();
210 //===----------------------------------------------------------------------===//
212 // FlattenCFG - flatten CFG, reduce number of conditional branches by using
213 // parallel-and and parallel-or mode, etc...
215 FunctionPass *createFlattenCFGPass();
217 //===----------------------------------------------------------------------===//
219 // CFG Structurization - Remove irreducible control flow
221 Pass *createStructurizeCFGPass();
223 //===----------------------------------------------------------------------===//
225 // BreakCriticalEdges - Break all of the critical edges in the CFG by inserting
226 // a dummy basic block. This pass may be "required" by passes that cannot deal
227 // with critical edges. For this usage, a pass must call:
229 // AU.addRequiredID(BreakCriticalEdgesID);
231 // This pass obviously invalidates the CFG, but can update forward dominator
232 // (set, immediate dominators, tree, and frontier) information.
234 FunctionPass *createBreakCriticalEdgesPass();
235 extern char &BreakCriticalEdgesID;
237 //===----------------------------------------------------------------------===//
239 // LoopSimplify - Insert Pre-header blocks into the CFG for every function in
240 // the module. This pass updates dominator information, loop information, and
241 // does not add critical edges to the CFG.
243 // AU.addRequiredID(LoopSimplifyID);
245 Pass *createLoopSimplifyPass();
246 extern char &LoopSimplifyID;
248 //===----------------------------------------------------------------------===//
250 // TailCallElimination - This pass eliminates call instructions to the current
251 // function which occur immediately before return instructions.
253 FunctionPass *createTailCallEliminationPass();
255 //===----------------------------------------------------------------------===//
257 // LowerSwitch - This pass converts SwitchInst instructions into a sequence of
258 // chained binary branch instructions.
260 FunctionPass *createLowerSwitchPass();
261 extern char &LowerSwitchID;
263 //===----------------------------------------------------------------------===//
265 // LowerInvoke - This pass converts invoke and unwind instructions to use sjlj
266 // exception handling mechanisms. Note that after this pass runs the CFG is not
267 // entirely accurate (exceptional control flow edges are not correct anymore) so
268 // only very simple things should be done after the lowerinvoke pass has run
269 // (like generation of native code). This should *NOT* be used as a general
270 // purpose "my LLVM-to-LLVM pass doesn't support the invoke instruction yet"
273 FunctionPass *createLowerInvokePass(const TargetMachine *TM = 0,
274 bool useExpensiveEHSupport = false);
275 extern char &LowerInvokePassID;
277 //===----------------------------------------------------------------------===//
279 // LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop
282 Pass *createLCSSAPass();
283 extern char &LCSSAID;
285 //===----------------------------------------------------------------------===//
287 // EarlyCSE - This pass performs a simple and fast CSE pass over the dominator
290 FunctionPass *createEarlyCSEPass();
292 //===----------------------------------------------------------------------===//
294 // GVN - This pass performs global value numbering and redundant load
295 // elimination cotemporaneously.
297 FunctionPass *createGVNPass(bool NoLoads = false);
299 //===----------------------------------------------------------------------===//
301 // MemCpyOpt - This pass performs optimizations related to eliminating memcpy
302 // calls and/or combining multiple stores into memset's.
304 FunctionPass *createMemCpyOptPass();
306 //===----------------------------------------------------------------------===//
308 // LoopDeletion - This pass performs DCE of non-infinite loops that it
309 // can prove are dead.
311 Pass *createLoopDeletionPass();
313 //===----------------------------------------------------------------------===//
315 // CodeGenPrepare - This pass prepares a function for instruction selection.
317 FunctionPass *createCodeGenPreparePass(const TargetMachine *TM = 0);
319 //===----------------------------------------------------------------------===//
321 // InstructionNamer - Give any unnamed non-void instructions "tmp" names.
323 FunctionPass *createInstructionNamerPass();
324 extern char &InstructionNamerID;
326 //===----------------------------------------------------------------------===//
328 // Sink - Code Sinking
330 FunctionPass *createSinkingPass();
332 //===----------------------------------------------------------------------===//
334 // LowerAtomic - Lower atomic intrinsics to non-atomic form
336 Pass *createLowerAtomicPass();
338 //===----------------------------------------------------------------------===//
340 // ValuePropagation - Propagate CFG-derived value information
342 Pass *createCorrelatedValuePropagationPass();
344 //===----------------------------------------------------------------------===//
346 // InstructionSimplifier - Remove redundant instructions.
348 FunctionPass *createInstructionSimplifierPass();
349 extern char &InstructionSimplifierID;
352 //===----------------------------------------------------------------------===//
354 // LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates
355 // "block_weights" metadata.
356 FunctionPass *createLowerExpectIntrinsicPass();
359 //===----------------------------------------------------------------------===//
361 // PartiallyInlineLibCalls - Tries to inline the fast path of library
362 // calls such as sqrt.
364 FunctionPass *createPartiallyInlineLibCallsPass();
366 //===----------------------------------------------------------------------===//
368 // SampleProfilePass - Loads sample profile data from disk and generates
369 // IR metadata to reflect the profile.
370 FunctionPass *createSampleProfileLoaderPass();
371 FunctionPass *createSampleProfileLoaderPass(StringRef Name);
373 //===----------------------------------------------------------------------===//
375 // ScalarizerPass - Converts vector operations into scalar operations
377 FunctionPass *createScalarizerPass();
379 } // End llvm namespace