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
27 class GetElementPtrInst;
33 //===----------------------------------------------------------------------===//
35 // ConstantPropagation - A worklist driven constant propagation pass
37 FunctionPass *createConstantPropagationPass();
39 //===----------------------------------------------------------------------===//
41 // AlignmentFromAssumptions - Use assume intrinsics to set load/store
44 FunctionPass *createAlignmentFromAssumptionsPass();
46 //===----------------------------------------------------------------------===//
48 // SCCP - Sparse conditional constant propagation.
50 FunctionPass *createSCCPPass();
52 //===----------------------------------------------------------------------===//
54 // DeadInstElimination - This pass quickly removes trivially dead instructions
55 // without modifying the CFG of the function. It is a BasicBlockPass, so it
56 // runs efficiently when queued next to other BasicBlockPass's.
58 Pass *createDeadInstEliminationPass();
60 //===----------------------------------------------------------------------===//
62 // DeadCodeElimination - This pass is more powerful than DeadInstElimination,
63 // because it is worklist driven that can potentially revisit instructions when
64 // their other instructions become dead, to eliminate chains of dead
67 FunctionPass *createDeadCodeEliminationPass();
69 //===----------------------------------------------------------------------===//
71 // DeadStoreElimination - This pass deletes stores that are post-dominated by
72 // must-aliased stores and are not loaded used between the stores.
74 FunctionPass *createDeadStoreEliminationPass();
76 //===----------------------------------------------------------------------===//
78 // AggressiveDCE - This pass uses the SSA based Aggressive DCE algorithm. This
79 // algorithm assumes instructions are dead until proven otherwise, which makes
80 // it more successful are removing non-obviously dead instructions.
82 FunctionPass *createAggressiveDCEPass();
85 //===----------------------------------------------------------------------===//
87 // GuardWidening - An optimization over the @llvm.experimental.guard intrinsic
88 // that (optimistically) combines multiple guards into one to have fewer checks
91 FunctionPass *createGuardWideningPass();
94 //===----------------------------------------------------------------------===//
96 // BitTrackingDCE - This pass uses a bit-tracking DCE algorithm in order to
97 // remove computations of dead bits.
99 FunctionPass *createBitTrackingDCEPass();
101 //===----------------------------------------------------------------------===//
103 // SROA - Replace aggregates or pieces of aggregates with scalar SSA values.
105 FunctionPass *createSROAPass();
107 //===----------------------------------------------------------------------===//
109 // InductiveRangeCheckElimination - Transform loops to elide range checks on
110 // linear functions of the induction variable.
112 Pass *createInductiveRangeCheckEliminationPass();
114 //===----------------------------------------------------------------------===//
116 // InductionVariableSimplify - Transform induction variables in a program to all
117 // use a single canonical induction variable per loop.
119 Pass *createIndVarSimplifyPass();
121 //===----------------------------------------------------------------------===//
123 // InstructionCombining - Combine instructions to form fewer, simple
124 // instructions. This pass does not modify the CFG, and has a tendency to make
125 // instructions dead, so a subsequent DCE pass is useful.
127 // This pass combines things like:
128 // %Y = add int 1, %X
129 // %Z = add int 1, %Y
131 // %Z = add int 2, %X
133 FunctionPass *createInstructionCombiningPass(bool ExpensiveCombines = true);
135 //===----------------------------------------------------------------------===//
137 // LICM - This pass is a loop invariant code motion and memory promotion pass.
139 Pass *createLICMPass();
141 //===----------------------------------------------------------------------===//
143 // LoopInterchange - This pass interchanges loops to provide a more
144 // cache-friendly memory access patterns.
146 Pass *createLoopInterchangePass();
148 //===----------------------------------------------------------------------===//
150 // LoopStrengthReduce - This pass is strength reduces GEP instructions that use
151 // a loop's canonical induction variable as one of their indices.
153 Pass *createLoopStrengthReducePass();
155 //===----------------------------------------------------------------------===//
157 // LoopUnswitch - This pass is a simple loop unswitching pass.
159 Pass *createLoopUnswitchPass(bool OptimizeForSize = false);
161 //===----------------------------------------------------------------------===//
163 // LoopInstSimplify - This pass simplifies instructions in a loop's body.
165 Pass *createLoopInstSimplifyPass();
167 //===----------------------------------------------------------------------===//
169 // LoopUnroll - This pass is a simple loop unrolling pass.
171 Pass *createLoopUnrollPass(int Threshold = -1, int Count = -1,
172 int AllowPartial = -1, int Runtime = -1);
173 // Create an unrolling pass for full unrolling only.
174 Pass *createSimpleLoopUnrollPass();
176 //===----------------------------------------------------------------------===//
178 // LoopReroll - This pass is a simple loop rerolling pass.
180 Pass *createLoopRerollPass();
182 //===----------------------------------------------------------------------===//
184 // LoopRotate - This pass is a simple loop rotating pass.
186 Pass *createLoopRotatePass(int MaxHeaderSize = -1);
188 //===----------------------------------------------------------------------===//
190 // LoopIdiom - This pass recognizes and replaces idioms in loops.
192 Pass *createLoopIdiomPass();
194 //===----------------------------------------------------------------------===//
196 // LoopVersioningLICM - This pass is a loop versioning pass for LICM.
198 Pass *createLoopVersioningLICMPass();
200 //===----------------------------------------------------------------------===//
202 // PromoteMemoryToRegister - This pass is used to promote memory references to
203 // be register references. A simple example of the transformation performed by
207 // %X = alloca i32, i32 1 ret i32 42
208 // store i32 42, i32 *%X
212 FunctionPass *createPromoteMemoryToRegisterPass();
214 //===----------------------------------------------------------------------===//
216 // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
217 // references. In basically undoes the PromoteMemoryToRegister pass to make cfg
220 FunctionPass *createDemoteRegisterToMemoryPass();
221 extern char &DemoteRegisterToMemoryID;
223 //===----------------------------------------------------------------------===//
225 // Reassociate - This pass reassociates commutative expressions in an order that
226 // is designed to promote better constant propagation, GCSE, LICM, PRE...
228 // For example: 4 + (x + 5) -> x + (4 + 5)
230 FunctionPass *createReassociatePass();
232 //===----------------------------------------------------------------------===//
234 // JumpThreading - Thread control through mult-pred/multi-succ blocks where some
235 // preds always go to some succ. Thresholds other than minus one override the
236 // internal BB duplication default threshold.
238 FunctionPass *createJumpThreadingPass(int Threshold = -1);
240 //===----------------------------------------------------------------------===//
242 // CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
243 // simplify terminator instructions, etc...
245 FunctionPass *createCFGSimplificationPass(
246 int Threshold = -1, std::function<bool(const Function &)> Ftor = nullptr);
248 //===----------------------------------------------------------------------===//
250 // FlattenCFG - flatten CFG, reduce number of conditional branches by using
251 // parallel-and and parallel-or mode, etc...
253 FunctionPass *createFlattenCFGPass();
255 //===----------------------------------------------------------------------===//
257 // CFG Structurization - Remove irreducible control flow
260 /// When \p SkipUniformRegions is true the structizer will not structurize
261 /// regions that only contain uniform branches.
262 Pass *createStructurizeCFGPass(bool SkipUniformRegions = false);
264 //===----------------------------------------------------------------------===//
266 // BreakCriticalEdges - Break all of the critical edges in the CFG by inserting
267 // a dummy basic block. This pass may be "required" by passes that cannot deal
268 // with critical edges. For this usage, a pass must call:
270 // AU.addRequiredID(BreakCriticalEdgesID);
272 // This pass obviously invalidates the CFG, but can update forward dominator
273 // (set, immediate dominators, tree, and frontier) information.
275 FunctionPass *createBreakCriticalEdgesPass();
276 extern char &BreakCriticalEdgesID;
278 //===----------------------------------------------------------------------===//
280 // LoopSimplify - Insert Pre-header blocks into the CFG for every function in
281 // the module. This pass updates dominator information, loop information, and
282 // does not add critical edges to the CFG.
284 // AU.addRequiredID(LoopSimplifyID);
286 Pass *createLoopSimplifyPass();
287 extern char &LoopSimplifyID;
289 //===----------------------------------------------------------------------===//
291 // TailCallElimination - This pass eliminates call instructions to the current
292 // function which occur immediately before return instructions.
294 FunctionPass *createTailCallEliminationPass();
296 //===----------------------------------------------------------------------===//
298 // LowerSwitch - This pass converts SwitchInst instructions into a sequence of
299 // chained binary branch instructions.
301 FunctionPass *createLowerSwitchPass();
302 extern char &LowerSwitchID;
304 //===----------------------------------------------------------------------===//
306 // LowerInvoke - This pass removes invoke instructions, converting them to call
309 FunctionPass *createLowerInvokePass();
310 extern char &LowerInvokePassID;
312 //===----------------------------------------------------------------------===//
314 // LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop
317 Pass *createLCSSAPass();
318 extern char &LCSSAID;
320 //===----------------------------------------------------------------------===//
322 // EarlyCSE - This pass performs a simple and fast CSE pass over the dominator
325 FunctionPass *createEarlyCSEPass();
327 //===----------------------------------------------------------------------===//
329 // GVNHoist - This pass performs a simple and fast GVN pass over the dominator
330 // tree to hoist common expressions from sibling branches.
332 FunctionPass *createGVNHoistPass();
334 //===----------------------------------------------------------------------===//
336 // MergedLoadStoreMotion - This pass merges loads and stores in diamonds. Loads
337 // are hoisted into the header, while stores sink into the footer.
339 FunctionPass *createMergedLoadStoreMotionPass();
341 //===----------------------------------------------------------------------===//
343 // MemCpyOpt - This pass performs optimizations related to eliminating memcpy
344 // calls and/or combining multiple stores into memset's.
346 FunctionPass *createMemCpyOptPass();
348 //===----------------------------------------------------------------------===//
350 // LoopDeletion - This pass performs DCE of non-infinite loops that it
351 // can prove are dead.
353 Pass *createLoopDeletionPass();
355 //===----------------------------------------------------------------------===//
357 // ConstantHoisting - This pass prepares a function for expensive constants.
359 FunctionPass *createConstantHoistingPass();
361 //===----------------------------------------------------------------------===//
363 // InstructionNamer - Give any unnamed non-void instructions "tmp" names.
365 FunctionPass *createInstructionNamerPass();
366 extern char &InstructionNamerID;
368 //===----------------------------------------------------------------------===//
370 // Sink - Code Sinking
372 FunctionPass *createSinkingPass();
374 //===----------------------------------------------------------------------===//
376 // LowerAtomic - Lower atomic intrinsics to non-atomic form
378 Pass *createLowerAtomicPass();
380 //===----------------------------------------------------------------------===//
382 // LowerGuardIntrinsic - Lower guard intrinsics to normal control flow.
384 Pass *createLowerGuardIntrinsicPass();
386 //===----------------------------------------------------------------------===//
388 // ValuePropagation - Propagate CFG-derived value information
390 Pass *createCorrelatedValuePropagationPass();
392 //===----------------------------------------------------------------------===//
394 // InstructionSimplifier - Remove redundant instructions.
396 FunctionPass *createInstructionSimplifierPass();
397 extern char &InstructionSimplifierID;
399 //===----------------------------------------------------------------------===//
401 // LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates
402 // "block_weights" metadata.
403 FunctionPass *createLowerExpectIntrinsicPass();
405 //===----------------------------------------------------------------------===//
407 // PartiallyInlineLibCalls - Tries to inline the fast path of library
408 // calls such as sqrt.
410 FunctionPass *createPartiallyInlineLibCallsPass();
412 //===----------------------------------------------------------------------===//
414 // ScalarizerPass - Converts vector operations into scalar operations
416 FunctionPass *createScalarizerPass();
418 //===----------------------------------------------------------------------===//
420 // AddDiscriminators - Add DWARF path discriminators to the IR.
421 FunctionPass *createAddDiscriminatorsPass();
423 //===----------------------------------------------------------------------===//
425 // SeparateConstOffsetFromGEP - Split GEPs for better CSE
428 createSeparateConstOffsetFromGEPPass(const TargetMachine *TM = nullptr,
429 bool LowerGEP = false);
431 //===----------------------------------------------------------------------===//
433 // SpeculativeExecution - Aggressively hoist instructions to enable
434 // speculative execution on targets where branches are expensive.
436 FunctionPass *createSpeculativeExecutionPass();
438 // Same as createSpeculativeExecutionPass, but does nothing unless
439 // TargetTransformInfo::hasBranchDivergence() is true.
440 FunctionPass *createSpeculativeExecutionIfHasBranchDivergencePass();
442 //===----------------------------------------------------------------------===//
444 // LoadCombine - Combine loads into bigger loads.
446 BasicBlockPass *createLoadCombinePass();
448 //===----------------------------------------------------------------------===//
450 // StraightLineStrengthReduce - This pass strength-reduces some certain
451 // instruction patterns in straight-line code.
453 FunctionPass *createStraightLineStrengthReducePass();
455 //===----------------------------------------------------------------------===//
457 // PlaceSafepoints - Rewrite any IR calls to gc.statepoints and insert any
458 // safepoint polls (method entry, backedge) that might be required. This pass
459 // does not generate explicit relocation sequences - that's handled by
460 // RewriteStatepointsForGC which can be run at an arbitrary point in the pass
461 // order following this pass.
463 FunctionPass *createPlaceSafepointsPass();
465 //===----------------------------------------------------------------------===//
467 // RewriteStatepointsForGC - Rewrite any gc.statepoints which do not yet have
468 // explicit relocations to include explicit relocations.
470 ModulePass *createRewriteStatepointsForGCPass();
472 //===----------------------------------------------------------------------===//
474 // Float2Int - Demote floats to ints where possible.
476 FunctionPass *createFloat2IntPass();
478 //===----------------------------------------------------------------------===//
480 // NaryReassociate - Simplify n-ary operations by reassociation.
482 FunctionPass *createNaryReassociatePass();
484 //===----------------------------------------------------------------------===//
486 // LoopDistribute - Distribute loops.
488 // ProcessAllLoopsByDefault instructs the pass to look for distribution
489 // opportunities in all loops unless -enable-loop-distribute or the
490 // llvm.loop.distribute.enable metadata data override this default.
491 FunctionPass *createLoopDistributePass(bool ProcessAllLoopsByDefault);
493 //===----------------------------------------------------------------------===//
495 // LoopLoadElimination - Perform loop-aware load elimination.
497 FunctionPass *createLoopLoadEliminationPass();
499 //===----------------------------------------------------------------------===//
501 // LoopSimplifyCFG - This pass performs basic CFG simplification on loops,
502 // primarily to help other loop passes.
504 Pass *createLoopSimplifyCFGPass();
506 //===----------------------------------------------------------------------===//
508 // LoopVersioning - Perform loop multi-versioning.
510 FunctionPass *createLoopVersioningPass();
512 //===----------------------------------------------------------------------===//
514 // LoopDataPrefetch - Perform data prefetching in loops.
516 FunctionPass *createLoopDataPrefetchPass();
518 ///===---------------------------------------------------------------------===//
519 ModulePass *createNameAnonFunctionPass();
521 } // End llvm namespace