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);
145 // Create an unrolling pass for full unrolling only.
146 Pass *createSimpleLoopUnrollPass();
148 //===----------------------------------------------------------------------===//
150 // LoopReroll - This pass is a simple loop rerolling pass.
152 Pass *createLoopRerollPass();
154 //===----------------------------------------------------------------------===//
156 // LoopRotate - This pass is a simple loop rotating pass.
158 Pass *createLoopRotatePass();
160 //===----------------------------------------------------------------------===//
162 // LoopIdiom - This pass recognizes and replaces idioms in loops.
164 Pass *createLoopIdiomPass();
166 //===----------------------------------------------------------------------===//
168 // PromoteMemoryToRegister - This pass is used to promote memory references to
169 // be register references. A simple example of the transformation performed by
173 // %X = alloca i32, i32 1 ret i32 42
174 // store i32 42, i32 *%X
178 FunctionPass *createPromoteMemoryToRegisterPass();
180 //===----------------------------------------------------------------------===//
182 // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
183 // references. In basically undoes the PromoteMemoryToRegister pass to make cfg
186 FunctionPass *createDemoteRegisterToMemoryPass();
187 extern char &DemoteRegisterToMemoryID;
189 //===----------------------------------------------------------------------===//
191 // Reassociate - This pass reassociates commutative expressions in an order that
192 // is designed to promote better constant propagation, GCSE, LICM, PRE...
194 // For example: 4 + (x + 5) -> x + (4 + 5)
196 FunctionPass *createReassociatePass();
198 //===----------------------------------------------------------------------===//
200 // JumpThreading - Thread control through mult-pred/multi-succ blocks where some
201 // preds always go to some succ.
203 FunctionPass *createJumpThreadingPass();
205 //===----------------------------------------------------------------------===//
207 // CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
208 // simplify terminator instructions, etc...
210 FunctionPass *createCFGSimplificationPass();
212 //===----------------------------------------------------------------------===//
214 // FlattenCFG - flatten CFG, reduce number of conditional branches by using
215 // parallel-and and parallel-or mode, etc...
217 FunctionPass *createFlattenCFGPass();
219 //===----------------------------------------------------------------------===//
221 // CFG Structurization - Remove irreducible control flow
223 Pass *createStructurizeCFGPass();
225 //===----------------------------------------------------------------------===//
227 // BreakCriticalEdges - Break all of the critical edges in the CFG by inserting
228 // a dummy basic block. This pass may be "required" by passes that cannot deal
229 // with critical edges. For this usage, a pass must call:
231 // AU.addRequiredID(BreakCriticalEdgesID);
233 // This pass obviously invalidates the CFG, but can update forward dominator
234 // (set, immediate dominators, tree, and frontier) information.
236 FunctionPass *createBreakCriticalEdgesPass();
237 extern char &BreakCriticalEdgesID;
239 //===----------------------------------------------------------------------===//
241 // LoopSimplify - Insert Pre-header blocks into the CFG for every function in
242 // the module. This pass updates dominator information, loop information, and
243 // does not add critical edges to the CFG.
245 // AU.addRequiredID(LoopSimplifyID);
247 Pass *createLoopSimplifyPass();
248 extern char &LoopSimplifyID;
250 //===----------------------------------------------------------------------===//
252 // TailCallElimination - This pass eliminates call instructions to the current
253 // function which occur immediately before return instructions.
255 FunctionPass *createTailCallEliminationPass();
257 //===----------------------------------------------------------------------===//
259 // LowerSwitch - This pass converts SwitchInst instructions into a sequence of
260 // chained binary branch instructions.
262 FunctionPass *createLowerSwitchPass();
263 extern char &LowerSwitchID;
265 //===----------------------------------------------------------------------===//
267 // LowerInvoke - This pass removes invoke instructions, converting them to call
270 FunctionPass *createLowerInvokePass();
271 extern char &LowerInvokePassID;
273 //===----------------------------------------------------------------------===//
275 // LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop
278 Pass *createLCSSAPass();
279 extern char &LCSSAID;
281 //===----------------------------------------------------------------------===//
283 // EarlyCSE - This pass performs a simple and fast CSE pass over the dominator
286 FunctionPass *createEarlyCSEPass();
288 //===----------------------------------------------------------------------===//
290 // GVN - This pass performs global value numbering and redundant load
291 // elimination cotemporaneously.
293 FunctionPass *createGVNPass(bool NoLoads = false);
295 //===----------------------------------------------------------------------===//
297 // MemCpyOpt - This pass performs optimizations related to eliminating memcpy
298 // calls and/or combining multiple stores into memset's.
300 FunctionPass *createMemCpyOptPass();
302 //===----------------------------------------------------------------------===//
304 // LoopDeletion - This pass performs DCE of non-infinite loops that it
305 // can prove are dead.
307 Pass *createLoopDeletionPass();
309 //===----------------------------------------------------------------------===//
311 // ConstantHoisting - This pass prepares a function for expensive constants.
313 FunctionPass *createConstantHoistingPass();
315 //===----------------------------------------------------------------------===//
317 // InstructionNamer - Give any unnamed non-void instructions "tmp" names.
319 FunctionPass *createInstructionNamerPass();
320 extern char &InstructionNamerID;
322 //===----------------------------------------------------------------------===//
324 // Sink - Code Sinking
326 FunctionPass *createSinkingPass();
328 //===----------------------------------------------------------------------===//
330 // LowerAtomic - Lower atomic intrinsics to non-atomic form
332 Pass *createLowerAtomicPass();
334 //===----------------------------------------------------------------------===//
336 // ValuePropagation - Propagate CFG-derived value information
338 Pass *createCorrelatedValuePropagationPass();
340 //===----------------------------------------------------------------------===//
342 // InstructionSimplifier - Remove redundant instructions.
344 FunctionPass *createInstructionSimplifierPass();
345 extern char &InstructionSimplifierID;
348 //===----------------------------------------------------------------------===//
350 // LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates
351 // "block_weights" metadata.
352 FunctionPass *createLowerExpectIntrinsicPass();
355 //===----------------------------------------------------------------------===//
357 // PartiallyInlineLibCalls - Tries to inline the fast path of library
358 // calls such as sqrt.
360 FunctionPass *createPartiallyInlineLibCallsPass();
362 //===----------------------------------------------------------------------===//
364 // SampleProfilePass - Loads sample profile data from disk and generates
365 // IR metadata to reflect the profile.
366 FunctionPass *createSampleProfileLoaderPass();
367 FunctionPass *createSampleProfileLoaderPass(StringRef Name);
369 //===----------------------------------------------------------------------===//
371 // ScalarizerPass - Converts vector operations into scalar operations
373 FunctionPass *createScalarizerPass();
375 //===----------------------------------------------------------------------===//
377 // AddDiscriminators - Add DWARF path discriminators to the IR.
378 FunctionPass *createAddDiscriminatorsPass();
380 } // End llvm namespace