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 int UpperBound = -1);
174 // Create an unrolling pass for full unrolling that uses exact trip count only.
175 Pass *createSimpleLoopUnrollPass();
177 //===----------------------------------------------------------------------===//
179 // LoopReroll - This pass is a simple loop rerolling pass.
181 Pass *createLoopRerollPass();
183 //===----------------------------------------------------------------------===//
185 // LoopRotate - This pass is a simple loop rotating pass.
187 Pass *createLoopRotatePass(int MaxHeaderSize = -1);
189 //===----------------------------------------------------------------------===//
191 // LoopIdiom - This pass recognizes and replaces idioms in loops.
193 Pass *createLoopIdiomPass();
195 //===----------------------------------------------------------------------===//
197 // LoopVersioningLICM - This pass is a loop versioning pass for LICM.
199 Pass *createLoopVersioningLICMPass();
201 //===----------------------------------------------------------------------===//
203 // PromoteMemoryToRegister - This pass is used to promote memory references to
204 // be register references. A simple example of the transformation performed by
208 // %X = alloca i32, i32 1 ret i32 42
209 // store i32 42, i32 *%X
213 FunctionPass *createPromoteMemoryToRegisterPass();
215 //===----------------------------------------------------------------------===//
217 // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
218 // references. In basically undoes the PromoteMemoryToRegister pass to make cfg
221 FunctionPass *createDemoteRegisterToMemoryPass();
222 extern char &DemoteRegisterToMemoryID;
224 //===----------------------------------------------------------------------===//
226 // Reassociate - This pass reassociates commutative expressions in an order that
227 // is designed to promote better constant propagation, GCSE, LICM, PRE...
229 // For example: 4 + (x + 5) -> x + (4 + 5)
231 FunctionPass *createReassociatePass();
233 //===----------------------------------------------------------------------===//
235 // JumpThreading - Thread control through mult-pred/multi-succ blocks where some
236 // preds always go to some succ. Thresholds other than minus one override the
237 // internal BB duplication default threshold.
239 FunctionPass *createJumpThreadingPass(int Threshold = -1);
241 //===----------------------------------------------------------------------===//
243 // CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
244 // simplify terminator instructions, etc...
246 FunctionPass *createCFGSimplificationPass(
247 int Threshold = -1, std::function<bool(const Function &)> Ftor = nullptr);
249 //===----------------------------------------------------------------------===//
251 // FlattenCFG - flatten CFG, reduce number of conditional branches by using
252 // parallel-and and parallel-or mode, etc...
254 FunctionPass *createFlattenCFGPass();
256 //===----------------------------------------------------------------------===//
258 // CFG Structurization - Remove irreducible control flow
261 /// When \p SkipUniformRegions is true the structizer will not structurize
262 /// regions that only contain uniform branches.
263 Pass *createStructurizeCFGPass(bool SkipUniformRegions = false);
265 //===----------------------------------------------------------------------===//
267 // BreakCriticalEdges - Break all of the critical edges in the CFG by inserting
268 // a dummy basic block. This pass may be "required" by passes that cannot deal
269 // with critical edges. For this usage, a pass must call:
271 // AU.addRequiredID(BreakCriticalEdgesID);
273 // This pass obviously invalidates the CFG, but can update forward dominator
274 // (set, immediate dominators, tree, and frontier) information.
276 FunctionPass *createBreakCriticalEdgesPass();
277 extern char &BreakCriticalEdgesID;
279 //===----------------------------------------------------------------------===//
281 // LoopSimplify - Insert Pre-header blocks into the CFG for every function in
282 // the module. This pass updates dominator information, loop information, and
283 // does not add critical edges to the CFG.
285 // AU.addRequiredID(LoopSimplifyID);
287 Pass *createLoopSimplifyPass();
288 extern char &LoopSimplifyID;
290 //===----------------------------------------------------------------------===//
292 // TailCallElimination - This pass eliminates call instructions to the current
293 // function which occur immediately before return instructions.
295 FunctionPass *createTailCallEliminationPass();
297 //===----------------------------------------------------------------------===//
299 // LowerSwitch - This pass converts SwitchInst instructions into a sequence of
300 // chained binary branch instructions.
302 FunctionPass *createLowerSwitchPass();
303 extern char &LowerSwitchID;
305 //===----------------------------------------------------------------------===//
307 // LowerInvoke - This pass removes invoke instructions, converting them to call
310 FunctionPass *createLowerInvokePass();
311 extern char &LowerInvokePassID;
313 //===----------------------------------------------------------------------===//
315 // LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop
318 Pass *createLCSSAPass();
319 extern char &LCSSAID;
321 //===----------------------------------------------------------------------===//
323 // EarlyCSE - This pass performs a simple and fast CSE pass over the dominator
326 FunctionPass *createEarlyCSEPass(bool UseMemorySSA = false);
328 //===----------------------------------------------------------------------===//
330 // GVNHoist - This pass performs a simple and fast GVN pass over the dominator
331 // tree to hoist common expressions from sibling branches.
333 FunctionPass *createGVNHoistPass();
335 //===----------------------------------------------------------------------===//
337 // MergedLoadStoreMotion - This pass merges loads and stores in diamonds. Loads
338 // are hoisted into the header, while stores sink into the footer.
340 FunctionPass *createMergedLoadStoreMotionPass();
342 //===----------------------------------------------------------------------===//
344 // MemCpyOpt - This pass performs optimizations related to eliminating memcpy
345 // calls and/or combining multiple stores into memset's.
347 FunctionPass *createMemCpyOptPass();
349 //===----------------------------------------------------------------------===//
351 // LoopDeletion - This pass performs DCE of non-infinite loops that it
352 // can prove are dead.
354 Pass *createLoopDeletionPass();
356 //===----------------------------------------------------------------------===//
358 // ConstantHoisting - This pass prepares a function for expensive constants.
360 FunctionPass *createConstantHoistingPass();
362 //===----------------------------------------------------------------------===//
364 // InstructionNamer - Give any unnamed non-void instructions "tmp" names.
366 FunctionPass *createInstructionNamerPass();
367 extern char &InstructionNamerID;
369 //===----------------------------------------------------------------------===//
371 // Sink - Code Sinking
373 FunctionPass *createSinkingPass();
375 //===----------------------------------------------------------------------===//
377 // LowerAtomic - Lower atomic intrinsics to non-atomic form
379 Pass *createLowerAtomicPass();
381 //===----------------------------------------------------------------------===//
383 // LowerGuardIntrinsic - Lower guard intrinsics to normal control flow.
385 Pass *createLowerGuardIntrinsicPass();
387 //===----------------------------------------------------------------------===//
389 // ValuePropagation - Propagate CFG-derived value information
391 Pass *createCorrelatedValuePropagationPass();
393 //===----------------------------------------------------------------------===//
395 // InstructionSimplifier - Remove redundant instructions.
397 FunctionPass *createInstructionSimplifierPass();
398 extern char &InstructionSimplifierID;
400 //===----------------------------------------------------------------------===//
402 // LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates
403 // "block_weights" metadata.
404 FunctionPass *createLowerExpectIntrinsicPass();
406 //===----------------------------------------------------------------------===//
408 // PartiallyInlineLibCalls - Tries to inline the fast path of library
409 // calls such as sqrt.
411 FunctionPass *createPartiallyInlineLibCallsPass();
413 //===----------------------------------------------------------------------===//
415 // ScalarizerPass - Converts vector operations into scalar operations
417 FunctionPass *createScalarizerPass();
419 //===----------------------------------------------------------------------===//
421 // AddDiscriminators - Add DWARF path discriminators to the IR.
422 FunctionPass *createAddDiscriminatorsPass();
424 //===----------------------------------------------------------------------===//
426 // SeparateConstOffsetFromGEP - Split GEPs for better CSE
429 createSeparateConstOffsetFromGEPPass(const TargetMachine *TM = nullptr,
430 bool LowerGEP = false);
432 //===----------------------------------------------------------------------===//
434 // SpeculativeExecution - Aggressively hoist instructions to enable
435 // speculative execution on targets where branches are expensive.
437 FunctionPass *createSpeculativeExecutionPass();
439 // Same as createSpeculativeExecutionPass, but does nothing unless
440 // TargetTransformInfo::hasBranchDivergence() is true.
441 FunctionPass *createSpeculativeExecutionIfHasBranchDivergencePass();
443 //===----------------------------------------------------------------------===//
445 // LoadCombine - Combine loads into bigger loads.
447 BasicBlockPass *createLoadCombinePass();
449 //===----------------------------------------------------------------------===//
451 // StraightLineStrengthReduce - This pass strength-reduces some certain
452 // instruction patterns in straight-line code.
454 FunctionPass *createStraightLineStrengthReducePass();
456 //===----------------------------------------------------------------------===//
458 // PlaceSafepoints - Rewrite any IR calls to gc.statepoints and insert any
459 // safepoint polls (method entry, backedge) that might be required. This pass
460 // does not generate explicit relocation sequences - that's handled by
461 // RewriteStatepointsForGC which can be run at an arbitrary point in the pass
462 // order following this pass.
464 FunctionPass *createPlaceSafepointsPass();
466 //===----------------------------------------------------------------------===//
468 // RewriteStatepointsForGC - Rewrite any gc.statepoints which do not yet have
469 // explicit relocations to include explicit relocations.
471 ModulePass *createRewriteStatepointsForGCPass();
473 //===----------------------------------------------------------------------===//
475 // StripGCRelocates - Remove GC relocates that have been inserted by
476 // RewriteStatepointsForGC. The resulting IR is incorrect, but this is useful
477 // for manual inspection.
478 FunctionPass *createStripGCRelocatesPass();
480 //===----------------------------------------------------------------------===//
482 // Float2Int - Demote floats to ints where possible.
484 FunctionPass *createFloat2IntPass();
486 //===----------------------------------------------------------------------===//
488 // NaryReassociate - Simplify n-ary operations by reassociation.
490 FunctionPass *createNaryReassociatePass();
492 //===----------------------------------------------------------------------===//
494 // LoopDistribute - Distribute loops.
496 // ProcessAllLoopsByDefault instructs the pass to look for distribution
497 // opportunities in all loops unless -enable-loop-distribute or the
498 // llvm.loop.distribute.enable metadata data override this default.
499 FunctionPass *createLoopDistributePass(bool ProcessAllLoopsByDefault);
501 //===----------------------------------------------------------------------===//
503 // LoopLoadElimination - Perform loop-aware load elimination.
505 FunctionPass *createLoopLoadEliminationPass();
507 //===----------------------------------------------------------------------===//
509 // LoopSimplifyCFG - This pass performs basic CFG simplification on loops,
510 // primarily to help other loop passes.
512 Pass *createLoopSimplifyCFGPass();
514 //===----------------------------------------------------------------------===//
516 // LoopVersioning - Perform loop multi-versioning.
518 FunctionPass *createLoopVersioningPass();
520 //===----------------------------------------------------------------------===//
522 // LoopDataPrefetch - Perform data prefetching in loops.
524 FunctionPass *createLoopDataPrefetchPass();
526 ///===---------------------------------------------------------------------===//
527 ModulePass *createNameAnonGlobalPass();
529 //===----------------------------------------------------------------------===//
531 // LibCallsShrinkWrap - Shrink-wraps a call to function if the result is not
534 FunctionPass *createLibCallsShrinkWrapPass();
535 } // End llvm namespace