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"
25 class GetElementPtrInst;
31 //===----------------------------------------------------------------------===//
33 // ConstantPropagation - A worklist driven constant propagation pass
35 FunctionPass *createConstantPropagationPass();
37 //===----------------------------------------------------------------------===//
39 // AlignmentFromAssumptions - Use assume intrinsics to set load/store
42 FunctionPass *createAlignmentFromAssumptionsPass();
44 //===----------------------------------------------------------------------===//
46 // SCCP - Sparse conditional constant propagation.
48 FunctionPass *createSCCPPass();
50 //===----------------------------------------------------------------------===//
52 // DeadInstElimination - This pass quickly removes trivially dead instructions
53 // without modifying the CFG of the function. It is a BasicBlockPass, so it
54 // runs efficiently when queued next to other BasicBlockPass's.
56 Pass *createDeadInstEliminationPass();
58 //===----------------------------------------------------------------------===//
60 // DeadCodeElimination - This pass is more powerful than DeadInstElimination,
61 // because it is worklist driven that can potentially revisit instructions when
62 // their other instructions become dead, to eliminate chains of dead
65 FunctionPass *createDeadCodeEliminationPass();
67 //===----------------------------------------------------------------------===//
69 // DeadStoreElimination - This pass deletes stores that are post-dominated by
70 // must-aliased stores and are not loaded used between the stores.
72 FunctionPass *createDeadStoreEliminationPass();
74 //===----------------------------------------------------------------------===//
76 // AggressiveDCE - This pass uses the SSA based Aggressive DCE algorithm. This
77 // algorithm assumes instructions are dead until proven otherwise, which makes
78 // it more successful are removing non-obviously dead instructions.
80 FunctionPass *createAggressiveDCEPass();
82 //===----------------------------------------------------------------------===//
84 // SROA - Replace aggregates or pieces of aggregates with scalar SSA values.
86 FunctionPass *createSROAPass(bool RequiresDomTree = true);
88 //===----------------------------------------------------------------------===//
90 // ScalarReplAggregates - Break up alloca's of aggregates into multiple allocas
93 FunctionPass *createScalarReplAggregatesPass(signed Threshold = -1,
94 bool UseDomTree = true,
95 signed StructMemberThreshold = -1,
96 signed ArrayElementThreshold = -1,
97 signed ScalarLoadThreshold = -1);
99 //===----------------------------------------------------------------------===//
101 // InductiveRangeCheckElimination - Transform loops to elide range checks on
102 // linear functions of the induction variable.
104 Pass *createInductiveRangeCheckEliminationPass();
106 //===----------------------------------------------------------------------===//
108 // InductionVariableSimplify - Transform induction variables in a program to all
109 // use a single canonical induction variable per loop.
111 Pass *createIndVarSimplifyPass();
113 //===----------------------------------------------------------------------===//
115 // InstructionCombining - Combine instructions to form fewer, simple
116 // instructions. This pass does not modify the CFG, and has a tendency to make
117 // instructions dead, so a subsequent DCE pass is useful.
119 // This pass combines things like:
120 // %Y = add int 1, %X
121 // %Z = add int 1, %Y
123 // %Z = add int 2, %X
125 FunctionPass *createInstructionCombiningPass();
127 //===----------------------------------------------------------------------===//
129 // LICM - This pass is a loop invariant code motion and memory promotion pass.
131 Pass *createLICMPass();
133 //===----------------------------------------------------------------------===//
135 // LoopStrengthReduce - This pass is strength reduces GEP instructions that use
136 // a loop's canonical induction variable as one of their indices.
138 Pass *createLoopStrengthReducePass();
140 Pass *createGlobalMergePass(const TargetMachine *TM = nullptr);
142 //===----------------------------------------------------------------------===//
144 // LoopUnswitch - This pass is a simple loop unswitching pass.
146 Pass *createLoopUnswitchPass(bool OptimizeForSize = false);
148 //===----------------------------------------------------------------------===//
150 // LoopInstSimplify - This pass simplifies instructions in a loop's body.
152 Pass *createLoopInstSimplifyPass();
154 //===----------------------------------------------------------------------===//
156 // LoopUnroll - This pass is a simple loop unrolling pass.
158 Pass *createLoopUnrollPass(int Threshold = -1, int Count = -1,
159 int AllowPartial = -1, int Runtime = -1);
160 // Create an unrolling pass for full unrolling only.
161 Pass *createSimpleLoopUnrollPass();
163 //===----------------------------------------------------------------------===//
165 // LoopReroll - This pass is a simple loop rerolling pass.
167 Pass *createLoopRerollPass();
169 //===----------------------------------------------------------------------===//
171 // LoopRotate - This pass is a simple loop rotating pass.
173 Pass *createLoopRotatePass(int MaxHeaderSize = -1);
175 //===----------------------------------------------------------------------===//
177 // LoopIdiom - This pass recognizes and replaces idioms in loops.
179 Pass *createLoopIdiomPass();
181 //===----------------------------------------------------------------------===//
183 // PromoteMemoryToRegister - This pass is used to promote memory references to
184 // be register references. A simple example of the transformation performed by
188 // %X = alloca i32, i32 1 ret i32 42
189 // store i32 42, i32 *%X
193 FunctionPass *createPromoteMemoryToRegisterPass();
195 //===----------------------------------------------------------------------===//
197 // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
198 // references. In basically undoes the PromoteMemoryToRegister pass to make cfg
201 FunctionPass *createDemoteRegisterToMemoryPass();
202 extern char &DemoteRegisterToMemoryID;
204 //===----------------------------------------------------------------------===//
206 // Reassociate - This pass reassociates commutative expressions in an order that
207 // is designed to promote better constant propagation, GCSE, LICM, PRE...
209 // For example: 4 + (x + 5) -> x + (4 + 5)
211 FunctionPass *createReassociatePass();
213 //===----------------------------------------------------------------------===//
215 // JumpThreading - Thread control through mult-pred/multi-succ blocks where some
216 // preds always go to some succ. Thresholds other than minus one override the
217 // internal BB duplication default threshold.
219 FunctionPass *createJumpThreadingPass(int Threshold = -1);
221 //===----------------------------------------------------------------------===//
223 // CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
224 // simplify terminator instructions, etc...
226 FunctionPass *createCFGSimplificationPass(int Threshold = -1);
228 //===----------------------------------------------------------------------===//
230 // FlattenCFG - flatten CFG, reduce number of conditional branches by using
231 // parallel-and and parallel-or mode, etc...
233 FunctionPass *createFlattenCFGPass();
235 //===----------------------------------------------------------------------===//
237 // CFG Structurization - Remove irreducible control flow
239 Pass *createStructurizeCFGPass();
241 //===----------------------------------------------------------------------===//
243 // BreakCriticalEdges - Break all of the critical edges in the CFG by inserting
244 // a dummy basic block. This pass may be "required" by passes that cannot deal
245 // with critical edges. For this usage, a pass must call:
247 // AU.addRequiredID(BreakCriticalEdgesID);
249 // This pass obviously invalidates the CFG, but can update forward dominator
250 // (set, immediate dominators, tree, and frontier) information.
252 FunctionPass *createBreakCriticalEdgesPass();
253 extern char &BreakCriticalEdgesID;
255 //===----------------------------------------------------------------------===//
257 // LoopSimplify - Insert Pre-header blocks into the CFG for every function in
258 // the module. This pass updates dominator information, loop information, and
259 // does not add critical edges to the CFG.
261 // AU.addRequiredID(LoopSimplifyID);
263 Pass *createLoopSimplifyPass();
264 extern char &LoopSimplifyID;
266 //===----------------------------------------------------------------------===//
268 // TailCallElimination - This pass eliminates call instructions to the current
269 // function which occur immediately before return instructions.
271 FunctionPass *createTailCallEliminationPass();
273 //===----------------------------------------------------------------------===//
275 // LowerSwitch - This pass converts SwitchInst instructions into a sequence of
276 // chained binary branch instructions.
278 FunctionPass *createLowerSwitchPass();
279 extern char &LowerSwitchID;
281 //===----------------------------------------------------------------------===//
283 // LowerInvoke - This pass removes invoke instructions, converting them to call
286 FunctionPass *createLowerInvokePass();
287 extern char &LowerInvokePassID;
289 //===----------------------------------------------------------------------===//
291 // LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop
294 Pass *createLCSSAPass();
295 extern char &LCSSAID;
297 //===----------------------------------------------------------------------===//
299 // EarlyCSE - This pass performs a simple and fast CSE pass over the dominator
302 FunctionPass *createEarlyCSEPass();
304 //===----------------------------------------------------------------------===//
306 // MergedLoadStoreMotion - This pass merges loads and stores in diamonds. Loads
307 // are hoisted into the header, while stores sink into the footer.
309 FunctionPass *createMergedLoadStoreMotionPass();
311 //===----------------------------------------------------------------------===//
313 // GVN - This pass performs global value numbering and redundant load
314 // elimination cotemporaneously.
316 FunctionPass *createGVNPass(bool NoLoads = false);
318 //===----------------------------------------------------------------------===//
320 // MemCpyOpt - This pass performs optimizations related to eliminating memcpy
321 // calls and/or combining multiple stores into memset's.
323 FunctionPass *createMemCpyOptPass();
325 //===----------------------------------------------------------------------===//
327 // LoopDeletion - This pass performs DCE of non-infinite loops that it
328 // can prove are dead.
330 Pass *createLoopDeletionPass();
332 //===----------------------------------------------------------------------===//
334 // ConstantHoisting - This pass prepares a function for expensive constants.
336 FunctionPass *createConstantHoistingPass();
338 //===----------------------------------------------------------------------===//
340 // InstructionNamer - Give any unnamed non-void instructions "tmp" names.
342 FunctionPass *createInstructionNamerPass();
343 extern char &InstructionNamerID;
345 //===----------------------------------------------------------------------===//
347 // Sink - Code Sinking
349 FunctionPass *createSinkingPass();
351 //===----------------------------------------------------------------------===//
353 // LowerAtomic - Lower atomic intrinsics to non-atomic form
355 Pass *createLowerAtomicPass();
357 //===----------------------------------------------------------------------===//
359 // ValuePropagation - Propagate CFG-derived value information
361 Pass *createCorrelatedValuePropagationPass();
363 //===----------------------------------------------------------------------===//
365 // InstructionSimplifier - Remove redundant instructions.
367 FunctionPass *createInstructionSimplifierPass();
368 extern char &InstructionSimplifierID;
370 //===----------------------------------------------------------------------===//
372 // LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates
373 // "block_weights" metadata.
374 FunctionPass *createLowerExpectIntrinsicPass();
376 //===----------------------------------------------------------------------===//
378 // PartiallyInlineLibCalls - Tries to inline the fast path of library
379 // calls such as sqrt.
381 FunctionPass *createPartiallyInlineLibCallsPass();
383 //===----------------------------------------------------------------------===//
385 // SampleProfilePass - Loads sample profile data from disk and generates
386 // IR metadata to reflect the profile.
387 FunctionPass *createSampleProfileLoaderPass();
388 FunctionPass *createSampleProfileLoaderPass(StringRef Name);
390 //===----------------------------------------------------------------------===//
392 // ScalarizerPass - Converts vector operations into scalar operations
394 FunctionPass *createScalarizerPass();
396 //===----------------------------------------------------------------------===//
398 // AddDiscriminators - Add DWARF path discriminators to the IR.
399 FunctionPass *createAddDiscriminatorsPass();
401 //===----------------------------------------------------------------------===//
403 // SeparateConstOffsetFromGEP - Split GEPs for better CSE
406 createSeparateConstOffsetFromGEPPass(const TargetMachine *TM = nullptr,
407 bool LowerGEP = false);
409 //===----------------------------------------------------------------------===//
411 // LoadCombine - Combine loads into bigger loads.
413 BasicBlockPass *createLoadCombinePass();
415 FunctionPass *createStraightLineStrengthReducePass();
417 } // End llvm namespace