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 // LoopSink - This pass sinks invariants from preheader to loop body where
144 // frequency is lower than loop preheader.
146 Pass *createLoopSinkPass();
148 //===----------------------------------------------------------------------===//
150 // LoopPredication - This pass does loop predication on guards.
152 Pass *createLoopPredicationPass();
154 //===----------------------------------------------------------------------===//
156 // LoopInterchange - This pass interchanges loops to provide a more
157 // cache-friendly memory access patterns.
159 Pass *createLoopInterchangePass();
161 //===----------------------------------------------------------------------===//
163 // LoopStrengthReduce - This pass is strength reduces GEP instructions that use
164 // a loop's canonical induction variable as one of their indices.
166 Pass *createLoopStrengthReducePass();
168 //===----------------------------------------------------------------------===//
170 // LoopUnswitch - This pass is a simple loop unswitching pass.
172 Pass *createLoopUnswitchPass(bool OptimizeForSize = false,
173 bool hasBranchDivergence = false);
175 //===----------------------------------------------------------------------===//
177 // LoopInstSimplify - This pass simplifies instructions in a loop's body.
179 Pass *createLoopInstSimplifyPass();
181 //===----------------------------------------------------------------------===//
183 // LoopUnroll - This pass is a simple loop unrolling pass.
185 Pass *createLoopUnrollPass(int OptLevel = 2, int Threshold = -1, int Count = -1,
186 int AllowPartial = -1, int Runtime = -1,
187 int UpperBound = -1);
188 // Create an unrolling pass for full unrolling that uses exact trip count only.
189 Pass *createSimpleLoopUnrollPass(int OptLevel = 2);
191 //===----------------------------------------------------------------------===//
193 // LoopReroll - This pass is a simple loop rerolling pass.
195 Pass *createLoopRerollPass();
197 //===----------------------------------------------------------------------===//
199 // LoopRotate - This pass is a simple loop rotating pass.
201 Pass *createLoopRotatePass(int MaxHeaderSize = -1);
203 //===----------------------------------------------------------------------===//
205 // LoopIdiom - This pass recognizes and replaces idioms in loops.
207 Pass *createLoopIdiomPass();
209 //===----------------------------------------------------------------------===//
211 // LoopVersioningLICM - This pass is a loop versioning pass for LICM.
213 Pass *createLoopVersioningLICMPass();
215 //===----------------------------------------------------------------------===//
217 // PromoteMemoryToRegister - This pass is used to promote memory references to
218 // be register references. A simple example of the transformation performed by
222 // %X = alloca i32, i32 1 ret i32 42
223 // store i32 42, i32 *%X
227 FunctionPass *createPromoteMemoryToRegisterPass();
229 //===----------------------------------------------------------------------===//
231 // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
232 // references. In basically undoes the PromoteMemoryToRegister pass to make cfg
235 FunctionPass *createDemoteRegisterToMemoryPass();
236 extern char &DemoteRegisterToMemoryID;
238 //===----------------------------------------------------------------------===//
240 // Reassociate - This pass reassociates commutative expressions in an order that
241 // is designed to promote better constant propagation, GCSE, LICM, PRE...
243 // For example: 4 + (x + 5) -> x + (4 + 5)
245 FunctionPass *createReassociatePass();
247 //===----------------------------------------------------------------------===//
249 // JumpThreading - Thread control through mult-pred/multi-succ blocks where some
250 // preds always go to some succ. Thresholds other than minus one override the
251 // internal BB duplication default threshold.
253 FunctionPass *createJumpThreadingPass(int Threshold = -1);
255 //===----------------------------------------------------------------------===//
257 // CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
258 // simplify terminator instructions, etc...
260 FunctionPass *createCFGSimplificationPass(
261 int Threshold = -1, std::function<bool(const Function &)> Ftor = nullptr);
263 //===----------------------------------------------------------------------===//
265 // LateCFGSimplification - Like CFGSimplification, but may also
266 // convert switches to lookup tables.
268 FunctionPass *createLateCFGSimplificationPass(
269 int Threshold = -1, std::function<bool(const Function &)> Ftor = nullptr);
271 //===----------------------------------------------------------------------===//
273 // FlattenCFG - flatten CFG, reduce number of conditional branches by using
274 // parallel-and and parallel-or mode, etc...
276 FunctionPass *createFlattenCFGPass();
278 //===----------------------------------------------------------------------===//
280 // CFG Structurization - Remove irreducible control flow
283 /// When \p SkipUniformRegions is true the structizer will not structurize
284 /// regions that only contain uniform branches.
285 Pass *createStructurizeCFGPass(bool SkipUniformRegions = false);
287 //===----------------------------------------------------------------------===//
289 // BreakCriticalEdges - Break all of the critical edges in the CFG by inserting
290 // a dummy basic block. This pass may be "required" by passes that cannot deal
291 // with critical edges. For this usage, a pass must call:
293 // AU.addRequiredID(BreakCriticalEdgesID);
295 // This pass obviously invalidates the CFG, but can update forward dominator
296 // (set, immediate dominators, tree, and frontier) information.
298 FunctionPass *createBreakCriticalEdgesPass();
299 extern char &BreakCriticalEdgesID;
301 //===----------------------------------------------------------------------===//
303 // LoopSimplify - Insert Pre-header blocks into the CFG for every function in
304 // the module. This pass updates dominator information, loop information, and
305 // does not add critical edges to the CFG.
307 // AU.addRequiredID(LoopSimplifyID);
309 Pass *createLoopSimplifyPass();
310 extern char &LoopSimplifyID;
312 //===----------------------------------------------------------------------===//
314 // TailCallElimination - This pass eliminates call instructions to the current
315 // function which occur immediately before return instructions.
317 FunctionPass *createTailCallEliminationPass();
319 //===----------------------------------------------------------------------===//
321 // LowerSwitch - This pass converts SwitchInst instructions into a sequence of
322 // chained binary branch instructions.
324 FunctionPass *createLowerSwitchPass();
325 extern char &LowerSwitchID;
327 //===----------------------------------------------------------------------===//
329 // LowerInvoke - This pass removes invoke instructions, converting them to call
332 FunctionPass *createLowerInvokePass();
333 extern char &LowerInvokePassID;
335 //===----------------------------------------------------------------------===//
337 // LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop
340 Pass *createLCSSAPass();
341 extern char &LCSSAID;
343 //===----------------------------------------------------------------------===//
345 // EarlyCSE - This pass performs a simple and fast CSE pass over the dominator
348 FunctionPass *createEarlyCSEPass(bool UseMemorySSA = false);
350 //===----------------------------------------------------------------------===//
352 // GVNHoist - This pass performs a simple and fast GVN pass over the dominator
353 // tree to hoist common expressions from sibling branches.
355 FunctionPass *createGVNHoistPass();
357 //===----------------------------------------------------------------------===//
359 // MergedLoadStoreMotion - This pass merges loads and stores in diamonds. Loads
360 // are hoisted into the header, while stores sink into the footer.
362 FunctionPass *createMergedLoadStoreMotionPass();
364 //===----------------------------------------------------------------------===//
366 // GVN - This pass performs global value numbering and redundant load
367 // elimination cotemporaneously.
369 FunctionPass *createNewGVNPass();
371 //===----------------------------------------------------------------------===//
373 // MemCpyOpt - This pass performs optimizations related to eliminating memcpy
374 // calls and/or combining multiple stores into memset's.
376 FunctionPass *createMemCpyOptPass();
378 //===----------------------------------------------------------------------===//
380 // LoopDeletion - This pass performs DCE of non-infinite loops that it
381 // can prove are dead.
383 Pass *createLoopDeletionPass();
385 //===----------------------------------------------------------------------===//
387 // ConstantHoisting - This pass prepares a function for expensive constants.
389 FunctionPass *createConstantHoistingPass();
391 //===----------------------------------------------------------------------===//
393 // InstructionNamer - Give any unnamed non-void instructions "tmp" names.
395 FunctionPass *createInstructionNamerPass();
396 extern char &InstructionNamerID;
398 //===----------------------------------------------------------------------===//
400 // Sink - Code Sinking
402 FunctionPass *createSinkingPass();
404 //===----------------------------------------------------------------------===//
406 // LowerAtomic - Lower atomic intrinsics to non-atomic form
408 Pass *createLowerAtomicPass();
410 //===----------------------------------------------------------------------===//
412 // LowerGuardIntrinsic - Lower guard intrinsics to normal control flow.
414 Pass *createLowerGuardIntrinsicPass();
416 //===----------------------------------------------------------------------===//
418 // ValuePropagation - Propagate CFG-derived value information
420 Pass *createCorrelatedValuePropagationPass();
422 //===----------------------------------------------------------------------===//
424 // InferAddressSpaces - Modify users of addrspacecast instructions with values
425 // in the source address space if using the destination address space is slower
428 FunctionPass *createInferAddressSpacesPass();
429 extern char &InferAddressSpacesID;
431 //===----------------------------------------------------------------------===//
433 // InstructionSimplifier - Remove redundant instructions.
435 FunctionPass *createInstructionSimplifierPass();
436 extern char &InstructionSimplifierID;
438 //===----------------------------------------------------------------------===//
440 // LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates
441 // "block_weights" metadata.
442 FunctionPass *createLowerExpectIntrinsicPass();
444 //===----------------------------------------------------------------------===//
446 // PartiallyInlineLibCalls - Tries to inline the fast path of library
447 // calls such as sqrt.
449 FunctionPass *createPartiallyInlineLibCallsPass();
451 //===----------------------------------------------------------------------===//
453 // ScalarizerPass - Converts vector operations into scalar operations
455 FunctionPass *createScalarizerPass();
457 //===----------------------------------------------------------------------===//
459 // AddDiscriminators - Add DWARF path discriminators to the IR.
460 FunctionPass *createAddDiscriminatorsPass();
462 //===----------------------------------------------------------------------===//
464 // SeparateConstOffsetFromGEP - Split GEPs for better CSE
467 createSeparateConstOffsetFromGEPPass(const TargetMachine *TM = nullptr,
468 bool LowerGEP = false);
470 //===----------------------------------------------------------------------===//
472 // SpeculativeExecution - Aggressively hoist instructions to enable
473 // speculative execution on targets where branches are expensive.
475 FunctionPass *createSpeculativeExecutionPass();
477 // Same as createSpeculativeExecutionPass, but does nothing unless
478 // TargetTransformInfo::hasBranchDivergence() is true.
479 FunctionPass *createSpeculativeExecutionIfHasBranchDivergencePass();
481 //===----------------------------------------------------------------------===//
483 // LoadCombine - Combine loads into bigger loads.
485 BasicBlockPass *createLoadCombinePass();
487 //===----------------------------------------------------------------------===//
489 // StraightLineStrengthReduce - This pass strength-reduces some certain
490 // instruction patterns in straight-line code.
492 FunctionPass *createStraightLineStrengthReducePass();
494 //===----------------------------------------------------------------------===//
496 // PlaceSafepoints - Rewrite any IR calls to gc.statepoints and insert any
497 // safepoint polls (method entry, backedge) that might be required. This pass
498 // does not generate explicit relocation sequences - that's handled by
499 // RewriteStatepointsForGC which can be run at an arbitrary point in the pass
500 // order following this pass.
502 FunctionPass *createPlaceSafepointsPass();
504 //===----------------------------------------------------------------------===//
506 // RewriteStatepointsForGC - Rewrite any gc.statepoints which do not yet have
507 // explicit relocations to include explicit relocations.
509 ModulePass *createRewriteStatepointsForGCPass();
511 //===----------------------------------------------------------------------===//
513 // StripGCRelocates - Remove GC relocates that have been inserted by
514 // RewriteStatepointsForGC. The resulting IR is incorrect, but this is useful
515 // for manual inspection.
516 FunctionPass *createStripGCRelocatesPass();
518 //===----------------------------------------------------------------------===//
520 // Float2Int - Demote floats to ints where possible.
522 FunctionPass *createFloat2IntPass();
524 //===----------------------------------------------------------------------===//
526 // NaryReassociate - Simplify n-ary operations by reassociation.
528 FunctionPass *createNaryReassociatePass();
530 //===----------------------------------------------------------------------===//
532 // LoopDistribute - Distribute loops.
534 FunctionPass *createLoopDistributePass();
536 //===----------------------------------------------------------------------===//
538 // LoopLoadElimination - Perform loop-aware load elimination.
540 FunctionPass *createLoopLoadEliminationPass();
542 //===----------------------------------------------------------------------===//
544 // LoopSimplifyCFG - This pass performs basic CFG simplification on loops,
545 // primarily to help other loop passes.
547 Pass *createLoopSimplifyCFGPass();
549 //===----------------------------------------------------------------------===//
551 // LoopVersioning - Perform loop multi-versioning.
553 FunctionPass *createLoopVersioningPass();
555 //===----------------------------------------------------------------------===//
557 // LoopDataPrefetch - Perform data prefetching in loops.
559 FunctionPass *createLoopDataPrefetchPass();
561 ///===---------------------------------------------------------------------===//
562 ModulePass *createNameAnonGlobalPass();
564 //===----------------------------------------------------------------------===//
566 // LibCallsShrinkWrap - Shrink-wraps a call to function if the result is not
569 FunctionPass *createLibCallsShrinkWrapPass();
570 } // End llvm namespace