1 //===-- Scalar.h - Scalar Transformations -----------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This header file defines prototypes for accessor functions that expose passes
10 // in the Scalar transformations library.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_TRANSFORMS_SCALAR_H
15 #define LLVM_TRANSFORMS_SCALAR_H
26 //===----------------------------------------------------------------------===//
28 // ConstantPropagation - A worklist driven constant propagation pass
30 FunctionPass *createConstantPropagationPass();
32 //===----------------------------------------------------------------------===//
34 // AlignmentFromAssumptions - Use assume intrinsics to set load/store
37 FunctionPass *createAlignmentFromAssumptionsPass();
39 //===----------------------------------------------------------------------===//
41 // SCCP - Sparse conditional constant propagation.
43 FunctionPass *createSCCPPass();
45 //===----------------------------------------------------------------------===//
47 // DeadInstElimination - This pass quickly removes trivially dead instructions
48 // without modifying the CFG of the function. It is a FunctionPass.
50 Pass *createDeadInstEliminationPass();
52 //===----------------------------------------------------------------------===//
54 // RedundantDbgInstElimination - This pass removes redundant dbg intrinsics
55 // without modifying the CFG of the function. It is a FunctionPass.
57 Pass *createRedundantDbgInstEliminationPass();
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();
76 //===----------------------------------------------------------------------===//
78 // CallSiteSplitting - This pass split call-site based on its known argument
80 FunctionPass *createCallSiteSplittingPass();
82 //===----------------------------------------------------------------------===//
84 // AggressiveDCE - This pass uses the SSA based Aggressive DCE algorithm. This
85 // algorithm assumes instructions are dead until proven otherwise, which makes
86 // it more successful are removing non-obviously dead instructions.
88 FunctionPass *createAggressiveDCEPass();
90 //===----------------------------------------------------------------------===//
92 // GuardWidening - An optimization over the @llvm.experimental.guard intrinsic
93 // that (optimistically) combines multiple guards into one to have fewer checks
96 FunctionPass *createGuardWideningPass();
99 //===----------------------------------------------------------------------===//
101 // LoopGuardWidening - Analogous to the GuardWidening pass, but restricted to a
102 // single loop at a time for use within a LoopPassManager. Desired effect is
103 // to widen guards into preheader or a single guard within loop if that's not
106 Pass *createLoopGuardWideningPass();
109 //===----------------------------------------------------------------------===//
111 // BitTrackingDCE - This pass uses a bit-tracking DCE algorithm in order to
112 // remove computations of dead bits.
114 FunctionPass *createBitTrackingDCEPass();
116 //===----------------------------------------------------------------------===//
118 // SROA - Replace aggregates or pieces of aggregates with scalar SSA values.
120 FunctionPass *createSROAPass();
122 //===----------------------------------------------------------------------===//
124 // InductiveRangeCheckElimination - Transform loops to elide range checks on
125 // linear functions of the induction variable.
127 Pass *createInductiveRangeCheckEliminationPass();
129 //===----------------------------------------------------------------------===//
131 // InductionVariableSimplify - Transform induction variables in a program to all
132 // use a single canonical induction variable per loop.
134 Pass *createIndVarSimplifyPass();
136 //===----------------------------------------------------------------------===//
138 // LICM - This pass is a loop invariant code motion and memory promotion pass.
140 Pass *createLICMPass();
141 Pass *createLICMPass(unsigned LicmMssaOptCap,
142 unsigned LicmMssaNoAccForPromotionCap);
144 //===----------------------------------------------------------------------===//
146 // LoopSink - This pass sinks invariants from preheader to loop body where
147 // frequency is lower than loop preheader.
149 Pass *createLoopSinkPass();
151 //===----------------------------------------------------------------------===//
153 // LoopPredication - This pass does loop predication on guards.
155 Pass *createLoopPredicationPass();
157 //===----------------------------------------------------------------------===//
159 // LoopInterchange - This pass interchanges loops to provide a more
160 // cache-friendly memory access patterns.
162 Pass *createLoopInterchangePass();
164 //===----------------------------------------------------------------------===//
166 // LoopStrengthReduce - This pass is strength reduces GEP instructions that use
167 // a loop's canonical induction variable as one of their indices.
169 Pass *createLoopStrengthReducePass();
171 //===----------------------------------------------------------------------===//
173 // LoopUnswitch - This pass is a simple loop unswitching pass.
175 Pass *createLoopUnswitchPass(bool OptimizeForSize = false,
176 bool hasBranchDivergence = false);
178 //===----------------------------------------------------------------------===//
180 // LoopInstSimplify - This pass simplifies instructions in a loop's body.
182 Pass *createLoopInstSimplifyPass();
184 //===----------------------------------------------------------------------===//
186 // LoopUnroll - This pass is a simple loop unrolling pass.
188 Pass *createLoopUnrollPass(int OptLevel = 2, bool OnlyWhenForced = false,
189 bool ForgetAllSCEV = false, int Threshold = -1,
190 int Count = -1, int AllowPartial = -1,
191 int Runtime = -1, int UpperBound = -1,
192 int AllowPeeling = -1);
193 // Create an unrolling pass for full unrolling that uses exact trip count only.
194 Pass *createSimpleLoopUnrollPass(int OptLevel = 2, bool OnlyWhenForced = false,
195 bool ForgetAllSCEV = false);
197 //===----------------------------------------------------------------------===//
199 // LoopUnrollAndJam - This pass is a simple loop unroll and jam pass.
201 Pass *createLoopUnrollAndJamPass(int OptLevel = 2);
203 //===----------------------------------------------------------------------===//
205 // LoopReroll - This pass is a simple loop rerolling pass.
207 Pass *createLoopRerollPass();
209 //===----------------------------------------------------------------------===//
211 // LoopRotate - This pass is a simple loop rotating pass.
213 Pass *createLoopRotatePass(int MaxHeaderSize = -1);
215 //===----------------------------------------------------------------------===//
217 // LoopIdiom - This pass recognizes and replaces idioms in loops.
219 Pass *createLoopIdiomPass();
221 //===----------------------------------------------------------------------===//
223 // LoopVersioningLICM - This pass is a loop versioning pass for LICM.
225 Pass *createLoopVersioningLICMPass();
227 //===----------------------------------------------------------------------===//
229 // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
230 // references. In basically undoes the PromoteMemoryToRegister pass to make cfg
233 FunctionPass *createDemoteRegisterToMemoryPass();
234 extern char &DemoteRegisterToMemoryID;
236 //===----------------------------------------------------------------------===//
238 // Reassociate - This pass reassociates commutative expressions in an order that
239 // is designed to promote better constant propagation, GCSE, LICM, PRE...
241 // For example: 4 + (x + 5) -> x + (4 + 5)
243 FunctionPass *createReassociatePass();
245 //===----------------------------------------------------------------------===//
247 // JumpThreading - Thread control through mult-pred/multi-succ blocks where some
248 // preds always go to some succ. Thresholds other than minus one override the
249 // internal BB duplication default threshold.
251 FunctionPass *createJumpThreadingPass(int Threshold = -1);
253 //===----------------------------------------------------------------------===//
255 // CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
256 // simplify terminator instructions, convert switches to lookup tables, etc.
258 FunctionPass *createCFGSimplificationPass(
259 unsigned Threshold = 1, bool ForwardSwitchCond = false,
260 bool ConvertSwitch = false, bool KeepLoops = true, bool SinkCommon = false,
261 std::function<bool(const Function &)> Ftor = nullptr);
263 //===----------------------------------------------------------------------===//
265 // FlattenCFG - flatten CFG, reduce number of conditional branches by using
266 // parallel-and and parallel-or mode, etc...
268 FunctionPass *createFlattenCFGPass();
270 //===----------------------------------------------------------------------===//
272 // CFG Structurization - Remove irreducible control flow
275 /// When \p SkipUniformRegions is true the structizer will not structurize
276 /// regions that only contain uniform branches.
277 Pass *createStructurizeCFGPass(bool SkipUniformRegions = false);
279 //===----------------------------------------------------------------------===//
281 // TailCallElimination - This pass eliminates call instructions to the current
282 // function which occur immediately before return instructions.
284 FunctionPass *createTailCallEliminationPass();
286 //===----------------------------------------------------------------------===//
288 // EarlyCSE - This pass performs a simple and fast CSE pass over the dominator
291 FunctionPass *createEarlyCSEPass(bool UseMemorySSA = false);
293 //===----------------------------------------------------------------------===//
295 // GVNHoist - This pass performs a simple and fast GVN pass over the dominator
296 // tree to hoist common expressions from sibling branches.
298 FunctionPass *createGVNHoistPass();
300 //===----------------------------------------------------------------------===//
302 // GVNSink - This pass uses an "inverted" value numbering to decide the
303 // similarity of expressions and sinks similar expressions into successors.
305 FunctionPass *createGVNSinkPass();
307 //===----------------------------------------------------------------------===//
309 // MergedLoadStoreMotion - This pass merges loads and stores in diamonds. Loads
310 // are hoisted into the header, while stores sink into the footer.
312 FunctionPass *createMergedLoadStoreMotionPass(bool SplitFooterBB = false);
314 //===----------------------------------------------------------------------===//
316 // GVN - This pass performs global value numbering and redundant load
317 // elimination cotemporaneously.
319 FunctionPass *createNewGVNPass();
321 //===----------------------------------------------------------------------===//
323 // DivRemPairs - Hoist/decompose integer division and remainder instructions.
325 FunctionPass *createDivRemPairsPass();
327 //===----------------------------------------------------------------------===//
329 // MemCpyOpt - This pass performs optimizations related to eliminating memcpy
330 // calls and/or combining multiple stores into memset's.
332 FunctionPass *createMemCpyOptPass();
334 //===----------------------------------------------------------------------===//
336 // LoopDeletion - This pass performs DCE of non-infinite loops that it
337 // can prove are dead.
339 Pass *createLoopDeletionPass();
341 //===----------------------------------------------------------------------===//
343 // ConstantHoisting - This pass prepares a function for expensive constants.
345 FunctionPass *createConstantHoistingPass();
347 //===----------------------------------------------------------------------===//
349 // Sink - Code Sinking
351 FunctionPass *createSinkingPass();
353 //===----------------------------------------------------------------------===//
355 // LowerAtomic - Lower atomic intrinsics to non-atomic form
357 Pass *createLowerAtomicPass();
359 //===----------------------------------------------------------------------===//
361 // LowerGuardIntrinsic - Lower guard intrinsics to normal control flow.
363 Pass *createLowerGuardIntrinsicPass();
365 //===----------------------------------------------------------------------===//
367 // LowerMatrixIntrinsics - Lower matrix intrinsics to vector operations.
369 Pass *createLowerMatrixIntrinsicsPass();
371 //===----------------------------------------------------------------------===//
373 // LowerWidenableCondition - Lower widenable condition to i1 true.
375 Pass *createLowerWidenableConditionPass();
377 //===----------------------------------------------------------------------===//
379 // MergeICmps - Merge integer comparison chains into a memcmp
381 Pass *createMergeICmpsLegacyPass();
383 //===----------------------------------------------------------------------===//
385 // ValuePropagation - Propagate CFG-derived value information
387 Pass *createCorrelatedValuePropagationPass();
389 //===----------------------------------------------------------------------===//
391 // InferAddressSpaces - Modify users of addrspacecast instructions with values
392 // in the source address space if using the destination address space is slower
393 // on the target. If AddressSpace is left to its default value, it will be
394 // obtained from the TargetTransformInfo.
396 FunctionPass *createInferAddressSpacesPass(unsigned AddressSpace = ~0u);
397 extern char &InferAddressSpacesID;
399 //===----------------------------------------------------------------------===//
401 // LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates
402 // "block_weights" metadata.
403 FunctionPass *createLowerExpectIntrinsicPass();
405 //===----------------------------------------------------------------------===//
407 // LowerConstantIntrinsicss - Expand any remaining llvm.objectsize and
408 // llvm.is.constant intrinsic calls, even for the unknown cases.
410 FunctionPass *createLowerConstantIntrinsicsPass();
412 //===----------------------------------------------------------------------===//
414 // PartiallyInlineLibCalls - Tries to inline the fast path of library
415 // calls such as sqrt.
417 FunctionPass *createPartiallyInlineLibCallsPass();
419 //===----------------------------------------------------------------------===//
421 // SeparateConstOffsetFromGEP - Split GEPs for better CSE
423 FunctionPass *createSeparateConstOffsetFromGEPPass(bool LowerGEP = false);
425 //===----------------------------------------------------------------------===//
427 // SpeculativeExecution - Aggressively hoist instructions to enable
428 // speculative execution on targets where branches are expensive.
430 FunctionPass *createSpeculativeExecutionPass();
432 // Same as createSpeculativeExecutionPass, but does nothing unless
433 // TargetTransformInfo::hasBranchDivergence() is true.
434 FunctionPass *createSpeculativeExecutionIfHasBranchDivergencePass();
436 //===----------------------------------------------------------------------===//
438 // StraightLineStrengthReduce - This pass strength-reduces some certain
439 // instruction patterns in straight-line code.
441 FunctionPass *createStraightLineStrengthReducePass();
443 //===----------------------------------------------------------------------===//
445 // PlaceSafepoints - Rewrite any IR calls to gc.statepoints and insert any
446 // safepoint polls (method entry, backedge) that might be required. This pass
447 // does not generate explicit relocation sequences - that's handled by
448 // RewriteStatepointsForGC which can be run at an arbitrary point in the pass
449 // order following this pass.
451 FunctionPass *createPlaceSafepointsPass();
453 //===----------------------------------------------------------------------===//
455 // RewriteStatepointsForGC - Rewrite any gc.statepoints which do not yet have
456 // explicit relocations to include explicit relocations.
458 ModulePass *createRewriteStatepointsForGCLegacyPass();
460 //===----------------------------------------------------------------------===//
462 // Float2Int - Demote floats to ints where possible.
464 FunctionPass *createFloat2IntPass();
466 //===----------------------------------------------------------------------===//
468 // NaryReassociate - Simplify n-ary operations by reassociation.
470 FunctionPass *createNaryReassociatePass();
472 //===----------------------------------------------------------------------===//
474 // LoopDistribute - Distribute loops.
476 FunctionPass *createLoopDistributePass();
478 //===----------------------------------------------------------------------===//
480 // LoopFuse - Fuse loops.
482 FunctionPass *createLoopFusePass();
484 //===----------------------------------------------------------------------===//
486 // LoopLoadElimination - Perform loop-aware load elimination.
488 FunctionPass *createLoopLoadEliminationPass();
490 //===----------------------------------------------------------------------===//
492 // LoopVersioning - Perform loop multi-versioning.
494 FunctionPass *createLoopVersioningPass();
496 //===----------------------------------------------------------------------===//
498 // LoopDataPrefetch - Perform data prefetching in loops.
500 FunctionPass *createLoopDataPrefetchPass();
502 ///===---------------------------------------------------------------------===//
503 ModulePass *createNameAnonGlobalPass();
504 ModulePass *createCanonicalizeAliasesPass();
506 //===----------------------------------------------------------------------===//
508 // LibCallsShrinkWrap - Shrink-wraps a call to function if the result is not
511 FunctionPass *createLibCallsShrinkWrapPass();
513 //===----------------------------------------------------------------------===//
515 // LoopSimplifyCFG - This pass performs basic CFG simplification on loops,
516 // primarily to help other loop passes.
518 Pass *createLoopSimplifyCFGPass();
520 //===----------------------------------------------------------------------===//
522 // WarnMissedTransformations - This pass emits warnings for leftover forced
525 Pass *createWarnMissedTransformationsPass();
526 } // End llvm namespace