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();
77 //===----------------------------------------------------------------------===//
79 // CallSiteSplitting - This pass split call-site based on its known argument
81 FunctionPass *createCallSiteSplittingPass();
83 //===----------------------------------------------------------------------===//
85 // AggressiveDCE - This pass uses the SSA based Aggressive DCE algorithm. This
86 // algorithm assumes instructions are dead until proven otherwise, which makes
87 // it more successful are removing non-obviously dead instructions.
89 FunctionPass *createAggressiveDCEPass();
91 //===----------------------------------------------------------------------===//
93 // GuardWidening - An optimization over the @llvm.experimental.guard intrinsic
94 // that (optimistically) combines multiple guards into one to have fewer checks
97 FunctionPass *createGuardWideningPass();
100 //===----------------------------------------------------------------------===//
102 // LoopGuardWidening - Analogous to the GuardWidening pass, but restricted to a
103 // single loop at a time for use within a LoopPassManager. Desired effect is
104 // to widen guards into preheader or a single guard within loop if that's not
107 Pass *createLoopGuardWideningPass();
110 //===----------------------------------------------------------------------===//
112 // BitTrackingDCE - This pass uses a bit-tracking DCE algorithm in order to
113 // remove computations of dead bits.
115 FunctionPass *createBitTrackingDCEPass();
117 //===----------------------------------------------------------------------===//
119 // SROA - Replace aggregates or pieces of aggregates with scalar SSA values.
121 FunctionPass *createSROAPass();
123 //===----------------------------------------------------------------------===//
125 // InductiveRangeCheckElimination - Transform loops to elide range checks on
126 // linear functions of the induction variable.
128 Pass *createInductiveRangeCheckEliminationPass();
130 //===----------------------------------------------------------------------===//
132 // InductionVariableSimplify - Transform induction variables in a program to all
133 // use a single canonical induction variable per loop.
135 Pass *createIndVarSimplifyPass();
137 //===----------------------------------------------------------------------===//
139 // LICM - This pass is a loop invariant code motion and memory promotion pass.
141 Pass *createLICMPass();
143 //===----------------------------------------------------------------------===//
145 // LoopSink - This pass sinks invariants from preheader to loop body where
146 // frequency is lower than loop preheader.
148 Pass *createLoopSinkPass();
150 //===----------------------------------------------------------------------===//
152 // LoopPredication - This pass does loop predication on guards.
154 Pass *createLoopPredicationPass();
156 //===----------------------------------------------------------------------===//
158 // LoopInterchange - This pass interchanges loops to provide a more
159 // cache-friendly memory access patterns.
161 Pass *createLoopInterchangePass();
163 //===----------------------------------------------------------------------===//
165 // LoopStrengthReduce - This pass is strength reduces GEP instructions that use
166 // a loop's canonical induction variable as one of their indices.
168 Pass *createLoopStrengthReducePass();
170 //===----------------------------------------------------------------------===//
172 // LoopUnswitch - This pass is a simple loop unswitching pass.
174 Pass *createLoopUnswitchPass(bool OptimizeForSize = false,
175 bool hasBranchDivergence = false);
177 //===----------------------------------------------------------------------===//
179 // LoopInstSimplify - This pass simplifies instructions in a loop's body.
181 Pass *createLoopInstSimplifyPass();
183 //===----------------------------------------------------------------------===//
185 // LoopUnroll - This pass is a simple loop unrolling pass.
187 Pass *createLoopUnrollPass(int OptLevel = 2, int Threshold = -1, int Count = -1,
188 int AllowPartial = -1, int Runtime = -1,
189 int UpperBound = -1, int AllowPeeling = -1);
190 // Create an unrolling pass for full unrolling that uses exact trip count only.
191 Pass *createSimpleLoopUnrollPass(int OptLevel = 2);
193 //===----------------------------------------------------------------------===//
195 // LoopUnrollAndJam - This pass is a simple loop unroll and jam pass.
197 Pass *createLoopUnrollAndJamPass(int OptLevel = 2);
199 //===----------------------------------------------------------------------===//
201 // LoopReroll - This pass is a simple loop rerolling pass.
203 Pass *createLoopRerollPass();
205 //===----------------------------------------------------------------------===//
207 // LoopRotate - This pass is a simple loop rotating pass.
209 Pass *createLoopRotatePass(int MaxHeaderSize = -1);
211 //===----------------------------------------------------------------------===//
213 // LoopIdiom - This pass recognizes and replaces idioms in loops.
215 Pass *createLoopIdiomPass();
217 //===----------------------------------------------------------------------===//
219 // LoopVersioningLICM - This pass is a loop versioning pass for LICM.
221 Pass *createLoopVersioningLICMPass();
223 //===----------------------------------------------------------------------===//
225 // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
226 // references. In basically undoes the PromoteMemoryToRegister pass to make cfg
229 FunctionPass *createDemoteRegisterToMemoryPass();
230 extern char &DemoteRegisterToMemoryID;
232 //===----------------------------------------------------------------------===//
234 // Reassociate - This pass reassociates commutative expressions in an order that
235 // is designed to promote better constant propagation, GCSE, LICM, PRE...
237 // For example: 4 + (x + 5) -> x + (4 + 5)
239 FunctionPass *createReassociatePass();
241 //===----------------------------------------------------------------------===//
243 // JumpThreading - Thread control through mult-pred/multi-succ blocks where some
244 // preds always go to some succ. Thresholds other than minus one override the
245 // internal BB duplication default threshold.
247 FunctionPass *createJumpThreadingPass(int Threshold = -1);
249 //===----------------------------------------------------------------------===//
251 // CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
252 // simplify terminator instructions, convert switches to lookup tables, etc.
254 FunctionPass *createCFGSimplificationPass(
255 unsigned Threshold = 1, bool ForwardSwitchCond = false,
256 bool ConvertSwitch = false, bool KeepLoops = true, bool SinkCommon = false,
257 std::function<bool(const Function &)> Ftor = nullptr);
259 //===----------------------------------------------------------------------===//
261 // FlattenCFG - flatten CFG, reduce number of conditional branches by using
262 // parallel-and and parallel-or mode, etc...
264 FunctionPass *createFlattenCFGPass();
266 //===----------------------------------------------------------------------===//
268 // CFG Structurization - Remove irreducible control flow
271 /// When \p SkipUniformRegions is true the structizer will not structurize
272 /// regions that only contain uniform branches.
273 Pass *createStructurizeCFGPass(bool SkipUniformRegions = false);
275 //===----------------------------------------------------------------------===//
277 // TailCallElimination - This pass eliminates call instructions to the current
278 // function which occur immediately before return instructions.
280 FunctionPass *createTailCallEliminationPass();
282 //===----------------------------------------------------------------------===//
284 // EarlyCSE - This pass performs a simple and fast CSE pass over the dominator
287 FunctionPass *createEarlyCSEPass(bool UseMemorySSA = false);
289 //===----------------------------------------------------------------------===//
291 // GVNHoist - This pass performs a simple and fast GVN pass over the dominator
292 // tree to hoist common expressions from sibling branches.
294 FunctionPass *createGVNHoistPass();
296 //===----------------------------------------------------------------------===//
298 // GVNSink - This pass uses an "inverted" value numbering to decide the
299 // similarity of expressions and sinks similar expressions into successors.
301 FunctionPass *createGVNSinkPass();
303 //===----------------------------------------------------------------------===//
305 // MergedLoadStoreMotion - This pass merges loads and stores in diamonds. Loads
306 // are hoisted into the header, while stores sink into the footer.
308 FunctionPass *createMergedLoadStoreMotionPass();
310 //===----------------------------------------------------------------------===//
312 // GVN - This pass performs global value numbering and redundant load
313 // elimination cotemporaneously.
315 FunctionPass *createNewGVNPass();
317 //===----------------------------------------------------------------------===//
319 // DivRemPairs - Hoist/decompose integer division and remainder instructions.
321 FunctionPass *createDivRemPairsPass();
323 //===----------------------------------------------------------------------===//
325 // MemCpyOpt - This pass performs optimizations related to eliminating memcpy
326 // calls and/or combining multiple stores into memset's.
328 FunctionPass *createMemCpyOptPass();
330 //===----------------------------------------------------------------------===//
332 // LoopDeletion - This pass performs DCE of non-infinite loops that it
333 // can prove are dead.
335 Pass *createLoopDeletionPass();
337 //===----------------------------------------------------------------------===//
339 // ConstantHoisting - This pass prepares a function for expensive constants.
341 FunctionPass *createConstantHoistingPass();
343 //===----------------------------------------------------------------------===//
345 // Sink - Code Sinking
347 FunctionPass *createSinkingPass();
349 //===----------------------------------------------------------------------===//
351 // LowerAtomic - Lower atomic intrinsics to non-atomic form
353 Pass *createLowerAtomicPass();
355 //===----------------------------------------------------------------------===//
357 // LowerGuardIntrinsic - Lower guard intrinsics to normal control flow.
359 Pass *createLowerGuardIntrinsicPass();
361 //===----------------------------------------------------------------------===//
363 // MergeICmps - Merge integer comparison chains into a memcmp
365 Pass *createMergeICmpsPass();
367 //===----------------------------------------------------------------------===//
369 // ValuePropagation - Propagate CFG-derived value information
371 Pass *createCorrelatedValuePropagationPass();
373 //===----------------------------------------------------------------------===//
375 // InferAddressSpaces - Modify users of addrspacecast instructions with values
376 // in the source address space if using the destination address space is slower
379 FunctionPass *createInferAddressSpacesPass();
380 extern char &InferAddressSpacesID;
382 //===----------------------------------------------------------------------===//
384 // LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates
385 // "block_weights" metadata.
386 FunctionPass *createLowerExpectIntrinsicPass();
388 //===----------------------------------------------------------------------===//
390 // PartiallyInlineLibCalls - Tries to inline the fast path of library
391 // calls such as sqrt.
393 FunctionPass *createPartiallyInlineLibCallsPass();
395 //===----------------------------------------------------------------------===//
397 // ScalarizerPass - Converts vector operations into scalar operations
399 FunctionPass *createScalarizerPass();
401 //===----------------------------------------------------------------------===//
403 // SeparateConstOffsetFromGEP - Split GEPs for better CSE
405 FunctionPass *createSeparateConstOffsetFromGEPPass(bool LowerGEP = false);
407 //===----------------------------------------------------------------------===//
409 // SpeculativeExecution - Aggressively hoist instructions to enable
410 // speculative execution on targets where branches are expensive.
412 FunctionPass *createSpeculativeExecutionPass();
414 // Same as createSpeculativeExecutionPass, but does nothing unless
415 // TargetTransformInfo::hasBranchDivergence() is true.
416 FunctionPass *createSpeculativeExecutionIfHasBranchDivergencePass();
418 //===----------------------------------------------------------------------===//
420 // StraightLineStrengthReduce - This pass strength-reduces some certain
421 // instruction patterns in straight-line code.
423 FunctionPass *createStraightLineStrengthReducePass();
425 //===----------------------------------------------------------------------===//
427 // PlaceSafepoints - Rewrite any IR calls to gc.statepoints and insert any
428 // safepoint polls (method entry, backedge) that might be required. This pass
429 // does not generate explicit relocation sequences - that's handled by
430 // RewriteStatepointsForGC which can be run at an arbitrary point in the pass
431 // order following this pass.
433 FunctionPass *createPlaceSafepointsPass();
435 //===----------------------------------------------------------------------===//
437 // RewriteStatepointsForGC - Rewrite any gc.statepoints which do not yet have
438 // explicit relocations to include explicit relocations.
440 ModulePass *createRewriteStatepointsForGCLegacyPass();
442 //===----------------------------------------------------------------------===//
444 // Float2Int - Demote floats to ints where possible.
446 FunctionPass *createFloat2IntPass();
448 //===----------------------------------------------------------------------===//
450 // NaryReassociate - Simplify n-ary operations by reassociation.
452 FunctionPass *createNaryReassociatePass();
454 //===----------------------------------------------------------------------===//
456 // LoopDistribute - Distribute loops.
458 FunctionPass *createLoopDistributePass();
460 //===----------------------------------------------------------------------===//
462 // LoopLoadElimination - Perform loop-aware load elimination.
464 FunctionPass *createLoopLoadEliminationPass();
466 //===----------------------------------------------------------------------===//
468 // LoopVersioning - Perform loop multi-versioning.
470 FunctionPass *createLoopVersioningPass();
472 //===----------------------------------------------------------------------===//
474 // LoopDataPrefetch - Perform data prefetching in loops.
476 FunctionPass *createLoopDataPrefetchPass();
478 ///===---------------------------------------------------------------------===//
479 ModulePass *createNameAnonGlobalPass();
481 //===----------------------------------------------------------------------===//
483 // LibCallsShrinkWrap - Shrink-wraps a call to function if the result is not
486 FunctionPass *createLibCallsShrinkWrapPass();
488 //===----------------------------------------------------------------------===//
490 // LoopSimplifyCFG - This pass performs basic CFG simplification on loops,
491 // primarily to help other loop passes.
493 Pass *createLoopSimplifyCFGPass();
494 } // End llvm namespace