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"
26 class GetElementPtrInst;
32 //===----------------------------------------------------------------------===//
34 // ConstantPropagation - A worklist driven constant propagation pass
36 FunctionPass *createConstantPropagationPass();
38 //===----------------------------------------------------------------------===//
40 // AlignmentFromAssumptions - Use assume intrinsics to set load/store
43 FunctionPass *createAlignmentFromAssumptionsPass();
45 //===----------------------------------------------------------------------===//
47 // SCCP - Sparse conditional constant propagation.
49 FunctionPass *createSCCPPass();
51 //===----------------------------------------------------------------------===//
53 // DeadInstElimination - This pass quickly removes trivially dead instructions
54 // without modifying the CFG of the function. It is a BasicBlockPass, so it
55 // runs efficiently when queued next to other BasicBlockPass's.
57 Pass *createDeadInstEliminationPass();
59 //===----------------------------------------------------------------------===//
61 // DeadCodeElimination - This pass is more powerful than DeadInstElimination,
62 // because it is worklist driven that can potentially revisit instructions when
63 // their other instructions become dead, to eliminate chains of dead
66 FunctionPass *createDeadCodeEliminationPass();
68 //===----------------------------------------------------------------------===//
70 // DeadStoreElimination - This pass deletes stores that are post-dominated by
71 // must-aliased stores and are not loaded used between the stores.
73 FunctionPass *createDeadStoreEliminationPass();
75 //===----------------------------------------------------------------------===//
77 // AggressiveDCE - This pass uses the SSA based Aggressive DCE algorithm. This
78 // algorithm assumes instructions are dead until proven otherwise, which makes
79 // it more successful are removing non-obviously dead instructions.
81 FunctionPass *createAggressiveDCEPass();
83 //===----------------------------------------------------------------------===//
85 // SROA - Replace aggregates or pieces of aggregates with scalar SSA values.
87 FunctionPass *createSROAPass(bool RequiresDomTree = true);
89 //===----------------------------------------------------------------------===//
91 // ScalarReplAggregates - Break up alloca's of aggregates into multiple allocas
94 FunctionPass *createScalarReplAggregatesPass(signed Threshold = -1,
95 bool UseDomTree = true,
96 signed StructMemberThreshold = -1,
97 signed ArrayElementThreshold = -1,
98 signed ScalarLoadThreshold = -1);
100 //===----------------------------------------------------------------------===//
102 // InductiveRangeCheckElimination - Transform loops to elide range checks on
103 // linear functions of the induction variable.
105 Pass *createInductiveRangeCheckEliminationPass();
107 //===----------------------------------------------------------------------===//
109 // InductionVariableSimplify - Transform induction variables in a program to all
110 // use a single canonical induction variable per loop.
112 Pass *createIndVarSimplifyPass();
114 //===----------------------------------------------------------------------===//
116 // InstructionCombining - Combine instructions to form fewer, simple
117 // instructions. This pass does not modify the CFG, and has a tendency to make
118 // instructions dead, so a subsequent DCE pass is useful.
120 // This pass combines things like:
121 // %Y = add int 1, %X
122 // %Z = add int 1, %Y
124 // %Z = add int 2, %X
126 FunctionPass *createInstructionCombiningPass();
128 //===----------------------------------------------------------------------===//
130 // LICM - This pass is a loop invariant code motion and memory promotion pass.
132 Pass *createLICMPass();
134 //===----------------------------------------------------------------------===//
136 // LoopStrengthReduce - This pass is strength reduces GEP instructions that use
137 // a loop's canonical induction variable as one of their indices.
139 Pass *createLoopStrengthReducePass();
141 Pass *createGlobalMergePass(const TargetMachine *TM = nullptr);
143 //===----------------------------------------------------------------------===//
145 // LoopUnswitch - This pass is a simple loop unswitching pass.
147 Pass *createLoopUnswitchPass(bool OptimizeForSize = false);
149 //===----------------------------------------------------------------------===//
151 // LoopInstSimplify - This pass simplifies instructions in a loop's body.
153 Pass *createLoopInstSimplifyPass();
155 //===----------------------------------------------------------------------===//
157 // LoopUnroll - This pass is a simple loop unrolling pass.
159 Pass *createLoopUnrollPass(int Threshold = -1, int Count = -1,
160 int AllowPartial = -1, int Runtime = -1);
161 // Create an unrolling pass for full unrolling only.
162 Pass *createSimpleLoopUnrollPass();
164 //===----------------------------------------------------------------------===//
166 // LoopReroll - This pass is a simple loop rerolling pass.
168 Pass *createLoopRerollPass();
170 //===----------------------------------------------------------------------===//
172 // LoopRotate - This pass is a simple loop rotating pass.
174 Pass *createLoopRotatePass(int MaxHeaderSize = -1);
176 //===----------------------------------------------------------------------===//
178 // LoopIdiom - This pass recognizes and replaces idioms in loops.
180 Pass *createLoopIdiomPass();
182 //===----------------------------------------------------------------------===//
184 // PromoteMemoryToRegister - This pass is used to promote memory references to
185 // be register references. A simple example of the transformation performed by
189 // %X = alloca i32, i32 1 ret i32 42
190 // store i32 42, i32 *%X
194 FunctionPass *createPromoteMemoryToRegisterPass();
196 //===----------------------------------------------------------------------===//
198 // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
199 // references. In basically undoes the PromoteMemoryToRegister pass to make cfg
202 FunctionPass *createDemoteRegisterToMemoryPass();
203 extern char &DemoteRegisterToMemoryID;
205 //===----------------------------------------------------------------------===//
207 // Reassociate - This pass reassociates commutative expressions in an order that
208 // is designed to promote better constant propagation, GCSE, LICM, PRE...
210 // For example: 4 + (x + 5) -> x + (4 + 5)
212 FunctionPass *createReassociatePass();
214 //===----------------------------------------------------------------------===//
216 // JumpThreading - Thread control through mult-pred/multi-succ blocks where some
217 // preds always go to some succ. Thresholds other than minus one override the
218 // internal BB duplication default threshold.
220 FunctionPass *createJumpThreadingPass(int Threshold = -1);
222 //===----------------------------------------------------------------------===//
224 // CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
225 // simplify terminator instructions, etc...
227 FunctionPass *createCFGSimplificationPass(int Threshold = -1);
229 //===----------------------------------------------------------------------===//
231 // FlattenCFG - flatten CFG, reduce number of conditional branches by using
232 // parallel-and and parallel-or mode, etc...
234 FunctionPass *createFlattenCFGPass();
236 //===----------------------------------------------------------------------===//
238 // CFG Structurization - Remove irreducible control flow
240 Pass *createStructurizeCFGPass();
242 //===----------------------------------------------------------------------===//
244 // BreakCriticalEdges - Break all of the critical edges in the CFG by inserting
245 // a dummy basic block. This pass may be "required" by passes that cannot deal
246 // with critical edges. For this usage, a pass must call:
248 // AU.addRequiredID(BreakCriticalEdgesID);
250 // This pass obviously invalidates the CFG, but can update forward dominator
251 // (set, immediate dominators, tree, and frontier) information.
253 FunctionPass *createBreakCriticalEdgesPass();
254 extern char &BreakCriticalEdgesID;
256 //===----------------------------------------------------------------------===//
258 // LoopSimplify - Insert Pre-header blocks into the CFG for every function in
259 // the module. This pass updates dominator information, loop information, and
260 // does not add critical edges to the CFG.
262 // AU.addRequiredID(LoopSimplifyID);
264 Pass *createLoopSimplifyPass();
265 extern char &LoopSimplifyID;
267 //===----------------------------------------------------------------------===//
269 // TailCallElimination - This pass eliminates call instructions to the current
270 // function which occur immediately before return instructions.
272 FunctionPass *createTailCallEliminationPass();
274 //===----------------------------------------------------------------------===//
276 // LowerSwitch - This pass converts SwitchInst instructions into a sequence of
277 // chained binary branch instructions.
279 FunctionPass *createLowerSwitchPass();
280 extern char &LowerSwitchID;
282 //===----------------------------------------------------------------------===//
284 // LowerInvoke - This pass removes invoke instructions, converting them to call
287 FunctionPass *createLowerInvokePass();
288 extern char &LowerInvokePassID;
290 //===----------------------------------------------------------------------===//
292 // LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop
295 Pass *createLCSSAPass();
296 extern char &LCSSAID;
298 //===----------------------------------------------------------------------===//
300 // EarlyCSE - This pass performs a simple and fast CSE pass over the dominator
303 FunctionPass *createEarlyCSEPass();
305 //===----------------------------------------------------------------------===//
307 // MergedLoadStoreMotion - This pass merges loads and stores in diamonds. Loads
308 // are hoisted into the header, while stores sink into the footer.
310 FunctionPass *createMergedLoadStoreMotionPass();
312 //===----------------------------------------------------------------------===//
314 // GVN - This pass performs global value numbering and redundant load
315 // elimination cotemporaneously.
317 FunctionPass *createGVNPass(bool NoLoads = false);
319 //===----------------------------------------------------------------------===//
321 // MemCpyOpt - This pass performs optimizations related to eliminating memcpy
322 // calls and/or combining multiple stores into memset's.
324 FunctionPass *createMemCpyOptPass();
326 //===----------------------------------------------------------------------===//
328 // LoopDeletion - This pass performs DCE of non-infinite loops that it
329 // can prove are dead.
331 Pass *createLoopDeletionPass();
333 //===----------------------------------------------------------------------===//
335 // ConstantHoisting - This pass prepares a function for expensive constants.
337 FunctionPass *createConstantHoistingPass();
339 //===----------------------------------------------------------------------===//
341 // InstructionNamer - Give any unnamed non-void instructions "tmp" names.
343 FunctionPass *createInstructionNamerPass();
344 extern char &InstructionNamerID;
346 //===----------------------------------------------------------------------===//
348 // Sink - Code Sinking
350 FunctionPass *createSinkingPass();
352 //===----------------------------------------------------------------------===//
354 // LowerAtomic - Lower atomic intrinsics to non-atomic form
356 Pass *createLowerAtomicPass();
358 //===----------------------------------------------------------------------===//
360 // ValuePropagation - Propagate CFG-derived value information
362 Pass *createCorrelatedValuePropagationPass();
364 //===----------------------------------------------------------------------===//
366 // InstructionSimplifier - Remove redundant instructions.
368 FunctionPass *createInstructionSimplifierPass();
369 extern char &InstructionSimplifierID;
371 //===----------------------------------------------------------------------===//
373 // LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates
374 // "block_weights" metadata.
375 FunctionPass *createLowerExpectIntrinsicPass();
377 //===----------------------------------------------------------------------===//
379 // PartiallyInlineLibCalls - Tries to inline the fast path of library
380 // calls such as sqrt.
382 FunctionPass *createPartiallyInlineLibCallsPass();
384 //===----------------------------------------------------------------------===//
386 // SampleProfilePass - Loads sample profile data from disk and generates
387 // IR metadata to reflect the profile.
388 FunctionPass *createSampleProfileLoaderPass();
389 FunctionPass *createSampleProfileLoaderPass(StringRef Name);
391 //===----------------------------------------------------------------------===//
393 // ScalarizerPass - Converts vector operations into scalar operations
395 FunctionPass *createScalarizerPass();
397 //===----------------------------------------------------------------------===//
399 // AddDiscriminators - Add DWARF path discriminators to the IR.
400 FunctionPass *createAddDiscriminatorsPass();
402 //===----------------------------------------------------------------------===//
404 // SeparateConstOffsetFromGEP - Split GEPs for better CSE
407 createSeparateConstOffsetFromGEPPass(const TargetMachine *TM = nullptr,
408 bool LowerGEP = false);
410 //===----------------------------------------------------------------------===//
412 // LoadCombine - Combine loads into bigger loads.
414 BasicBlockPass *createLoadCombinePass();
416 FunctionPass *createStraightLineStrengthReducePass();
419 //===----------------------------------------------------------------------===//
421 // PlaceSafepoints - Rewrite any IR calls to gc.statepoints and insert any
422 // safepoint polls (method entry, backedge) that might be required. This pass
423 // does not generate explicit relocation sequences - that's handled by
424 // RewriteStatepointsForGC which can be run at an arbitrary point in the pass
425 // order following this pass.
427 ModulePass *createPlaceSafepointsPass();
429 } // End llvm namespace