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 class GetElementPtrInst
;
31 //===----------------------------------------------------------------------===//
33 // ConstantPropagation - A worklist driven constant propagation pass
35 FunctionPass
*createConstantPropagationPass();
37 //===----------------------------------------------------------------------===//
39 // AlignmentFromAssumptions - Use assume intrinsics to set load/store
42 FunctionPass
*createAlignmentFromAssumptionsPass();
44 //===----------------------------------------------------------------------===//
46 // SCCP - Sparse conditional constant propagation.
48 FunctionPass
*createSCCPPass();
50 //===----------------------------------------------------------------------===//
52 // DeadInstElimination - This pass quickly removes trivially dead instructions
53 // without modifying the CFG of the function. It is a BasicBlockPass, so it
54 // runs efficiently when queued next to other BasicBlockPass's.
56 Pass
*createDeadInstEliminationPass();
58 //===----------------------------------------------------------------------===//
60 // DeadCodeElimination - This pass is more powerful than DeadInstElimination,
61 // because it is worklist driven that can potentially revisit instructions when
62 // their other instructions become dead, to eliminate chains of dead
65 FunctionPass
*createDeadCodeEliminationPass();
67 //===----------------------------------------------------------------------===//
69 // DeadStoreElimination - This pass deletes stores that are post-dominated by
70 // must-aliased stores and are not loaded used between the stores.
72 FunctionPass
*createDeadStoreEliminationPass();
75 //===----------------------------------------------------------------------===//
77 // CallSiteSplitting - This pass split call-site based on its known argument
79 FunctionPass
*createCallSiteSplittingPass();
81 //===----------------------------------------------------------------------===//
83 // AggressiveDCE - This pass uses the SSA based Aggressive DCE algorithm. This
84 // algorithm assumes instructions are dead until proven otherwise, which makes
85 // it more successful are removing non-obviously dead instructions.
87 FunctionPass
*createAggressiveDCEPass();
89 //===----------------------------------------------------------------------===//
91 // GuardWidening - An optimization over the @llvm.experimental.guard intrinsic
92 // that (optimistically) combines multiple guards into one to have fewer checks
95 FunctionPass
*createGuardWideningPass();
98 //===----------------------------------------------------------------------===//
100 // LoopGuardWidening - Analogous to the GuardWidening pass, but restricted to a
101 // single loop at a time for use within a LoopPassManager. Desired effect is
102 // to widen guards into preheader or a single guard within loop if that's not
105 Pass
*createLoopGuardWideningPass();
108 //===----------------------------------------------------------------------===//
110 // BitTrackingDCE - This pass uses a bit-tracking DCE algorithm in order to
111 // remove computations of dead bits.
113 FunctionPass
*createBitTrackingDCEPass();
115 //===----------------------------------------------------------------------===//
117 // SROA - Replace aggregates or pieces of aggregates with scalar SSA values.
119 FunctionPass
*createSROAPass();
121 //===----------------------------------------------------------------------===//
123 // InductiveRangeCheckElimination - Transform loops to elide range checks on
124 // linear functions of the induction variable.
126 Pass
*createInductiveRangeCheckEliminationPass();
128 //===----------------------------------------------------------------------===//
130 // InductionVariableSimplify - Transform induction variables in a program to all
131 // use a single canonical induction variable per loop.
133 Pass
*createIndVarSimplifyPass();
135 //===----------------------------------------------------------------------===//
137 // LICM - This pass is a loop invariant code motion and memory promotion pass.
139 Pass
*createLICMPass();
140 Pass
*createLICMPass(unsigned LicmMssaOptCap
,
141 unsigned LicmMssaNoAccForPromotionCap
);
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, bool OnlyWhenForced
= false,
188 bool ForgetAllSCEV
= false, int Threshold
= -1,
189 int Count
= -1, int AllowPartial
= -1,
190 int Runtime
= -1, int UpperBound
= -1,
191 int AllowPeeling
= -1);
192 // Create an unrolling pass for full unrolling that uses exact trip count only.
193 Pass
*createSimpleLoopUnrollPass(int OptLevel
= 2, bool OnlyWhenForced
= false,
194 bool ForgetAllSCEV
= false);
196 //===----------------------------------------------------------------------===//
198 // LoopUnrollAndJam - This pass is a simple loop unroll and jam pass.
200 Pass
*createLoopUnrollAndJamPass(int OptLevel
= 2);
202 //===----------------------------------------------------------------------===//
204 // LoopReroll - This pass is a simple loop rerolling pass.
206 Pass
*createLoopRerollPass();
208 //===----------------------------------------------------------------------===//
210 // LoopRotate - This pass is a simple loop rotating pass.
212 Pass
*createLoopRotatePass(int MaxHeaderSize
= -1);
214 //===----------------------------------------------------------------------===//
216 // LoopIdiom - This pass recognizes and replaces idioms in loops.
218 Pass
*createLoopIdiomPass();
220 //===----------------------------------------------------------------------===//
222 // LoopVersioningLICM - This pass is a loop versioning pass for LICM.
224 Pass
*createLoopVersioningLICMPass();
226 //===----------------------------------------------------------------------===//
228 // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
229 // references. In basically undoes the PromoteMemoryToRegister pass to make cfg
232 FunctionPass
*createDemoteRegisterToMemoryPass();
233 extern char &DemoteRegisterToMemoryID
;
235 //===----------------------------------------------------------------------===//
237 // Reassociate - This pass reassociates commutative expressions in an order that
238 // is designed to promote better constant propagation, GCSE, LICM, PRE...
240 // For example: 4 + (x + 5) -> x + (4 + 5)
242 FunctionPass
*createReassociatePass();
244 //===----------------------------------------------------------------------===//
246 // JumpThreading - Thread control through mult-pred/multi-succ blocks where some
247 // preds always go to some succ. Thresholds other than minus one override the
248 // internal BB duplication default threshold.
250 FunctionPass
*createJumpThreadingPass(int Threshold
= -1);
252 //===----------------------------------------------------------------------===//
254 // CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
255 // simplify terminator instructions, convert switches to lookup tables, etc.
257 FunctionPass
*createCFGSimplificationPass(
258 unsigned Threshold
= 1, bool ForwardSwitchCond
= false,
259 bool ConvertSwitch
= false, bool KeepLoops
= true, bool SinkCommon
= false,
260 std::function
<bool(const Function
&)> Ftor
= nullptr);
262 //===----------------------------------------------------------------------===//
264 // FlattenCFG - flatten CFG, reduce number of conditional branches by using
265 // parallel-and and parallel-or mode, etc...
267 FunctionPass
*createFlattenCFGPass();
269 //===----------------------------------------------------------------------===//
271 // CFG Structurization - Remove irreducible control flow
274 /// When \p SkipUniformRegions is true the structizer will not structurize
275 /// regions that only contain uniform branches.
276 Pass
*createStructurizeCFGPass(bool SkipUniformRegions
= false);
278 //===----------------------------------------------------------------------===//
280 // TailCallElimination - This pass eliminates call instructions to the current
281 // function which occur immediately before return instructions.
283 FunctionPass
*createTailCallEliminationPass();
285 //===----------------------------------------------------------------------===//
287 // EarlyCSE - This pass performs a simple and fast CSE pass over the dominator
290 FunctionPass
*createEarlyCSEPass(bool UseMemorySSA
= false);
292 //===----------------------------------------------------------------------===//
294 // GVNHoist - This pass performs a simple and fast GVN pass over the dominator
295 // tree to hoist common expressions from sibling branches.
297 FunctionPass
*createGVNHoistPass();
299 //===----------------------------------------------------------------------===//
301 // GVNSink - This pass uses an "inverted" value numbering to decide the
302 // similarity of expressions and sinks similar expressions into successors.
304 FunctionPass
*createGVNSinkPass();
306 //===----------------------------------------------------------------------===//
308 // MergedLoadStoreMotion - This pass merges loads and stores in diamonds. Loads
309 // are hoisted into the header, while stores sink into the footer.
311 FunctionPass
*createMergedLoadStoreMotionPass(bool SplitFooterBB
= false);
313 //===----------------------------------------------------------------------===//
315 // GVN - This pass performs global value numbering and redundant load
316 // elimination cotemporaneously.
318 FunctionPass
*createNewGVNPass();
320 //===----------------------------------------------------------------------===//
322 // DivRemPairs - Hoist/decompose integer division and remainder instructions.
324 FunctionPass
*createDivRemPairsPass();
326 //===----------------------------------------------------------------------===//
328 // MemCpyOpt - This pass performs optimizations related to eliminating memcpy
329 // calls and/or combining multiple stores into memset's.
331 FunctionPass
*createMemCpyOptPass();
333 //===----------------------------------------------------------------------===//
335 // LoopDeletion - This pass performs DCE of non-infinite loops that it
336 // can prove are dead.
338 Pass
*createLoopDeletionPass();
340 //===----------------------------------------------------------------------===//
342 // ConstantHoisting - This pass prepares a function for expensive constants.
344 FunctionPass
*createConstantHoistingPass();
346 //===----------------------------------------------------------------------===//
348 // Sink - Code Sinking
350 FunctionPass
*createSinkingPass();
352 //===----------------------------------------------------------------------===//
354 // LowerAtomic - Lower atomic intrinsics to non-atomic form
356 Pass
*createLowerAtomicPass();
358 //===----------------------------------------------------------------------===//
360 // LowerGuardIntrinsic - Lower guard intrinsics to normal control flow.
362 Pass
*createLowerGuardIntrinsicPass();
364 //===----------------------------------------------------------------------===//
366 // LowerWidenableCondition - Lower widenable condition to i1 true.
368 Pass
*createLowerWidenableConditionPass();
370 //===----------------------------------------------------------------------===//
372 // MergeICmps - Merge integer comparison chains into a memcmp
374 Pass
*createMergeICmpsLegacyPass();
376 //===----------------------------------------------------------------------===//
378 // ValuePropagation - Propagate CFG-derived value information
380 Pass
*createCorrelatedValuePropagationPass();
382 //===----------------------------------------------------------------------===//
384 // InferAddressSpaces - Modify users of addrspacecast instructions with values
385 // in the source address space if using the destination address space is slower
386 // on the target. If AddressSpace is left to its default value, it will be
387 // obtained from the TargetTransformInfo.
389 FunctionPass
*createInferAddressSpacesPass(unsigned AddressSpace
= ~0u);
390 extern char &InferAddressSpacesID
;
392 //===----------------------------------------------------------------------===//
394 // LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates
395 // "block_weights" metadata.
396 FunctionPass
*createLowerExpectIntrinsicPass();
398 //===----------------------------------------------------------------------===//
400 // LowerConstantIntrinsicss - Expand any remaining llvm.objectsize and
401 // llvm.is.constant intrinsic calls, even for the unknown cases.
403 FunctionPass
*createLowerConstantIntrinsicsPass();
405 //===----------------------------------------------------------------------===//
407 // PartiallyInlineLibCalls - Tries to inline the fast path of library
408 // calls such as sqrt.
410 FunctionPass
*createPartiallyInlineLibCallsPass();
412 //===----------------------------------------------------------------------===//
414 // SeparateConstOffsetFromGEP - Split GEPs for better CSE
416 FunctionPass
*createSeparateConstOffsetFromGEPPass(bool LowerGEP
= false);
418 //===----------------------------------------------------------------------===//
420 // SpeculativeExecution - Aggressively hoist instructions to enable
421 // speculative execution on targets where branches are expensive.
423 FunctionPass
*createSpeculativeExecutionPass();
425 // Same as createSpeculativeExecutionPass, but does nothing unless
426 // TargetTransformInfo::hasBranchDivergence() is true.
427 FunctionPass
*createSpeculativeExecutionIfHasBranchDivergencePass();
429 //===----------------------------------------------------------------------===//
431 // StraightLineStrengthReduce - This pass strength-reduces some certain
432 // instruction patterns in straight-line code.
434 FunctionPass
*createStraightLineStrengthReducePass();
436 //===----------------------------------------------------------------------===//
438 // PlaceSafepoints - Rewrite any IR calls to gc.statepoints and insert any
439 // safepoint polls (method entry, backedge) that might be required. This pass
440 // does not generate explicit relocation sequences - that's handled by
441 // RewriteStatepointsForGC which can be run at an arbitrary point in the pass
442 // order following this pass.
444 FunctionPass
*createPlaceSafepointsPass();
446 //===----------------------------------------------------------------------===//
448 // RewriteStatepointsForGC - Rewrite any gc.statepoints which do not yet have
449 // explicit relocations to include explicit relocations.
451 ModulePass
*createRewriteStatepointsForGCLegacyPass();
453 //===----------------------------------------------------------------------===//
455 // Float2Int - Demote floats to ints where possible.
457 FunctionPass
*createFloat2IntPass();
459 //===----------------------------------------------------------------------===//
461 // NaryReassociate - Simplify n-ary operations by reassociation.
463 FunctionPass
*createNaryReassociatePass();
465 //===----------------------------------------------------------------------===//
467 // LoopDistribute - Distribute loops.
469 FunctionPass
*createLoopDistributePass();
471 //===----------------------------------------------------------------------===//
473 // LoopFuse - Fuse loops.
475 FunctionPass
*createLoopFusePass();
477 //===----------------------------------------------------------------------===//
479 // LoopLoadElimination - Perform loop-aware load elimination.
481 FunctionPass
*createLoopLoadEliminationPass();
483 //===----------------------------------------------------------------------===//
485 // LoopVersioning - Perform loop multi-versioning.
487 FunctionPass
*createLoopVersioningPass();
489 //===----------------------------------------------------------------------===//
491 // LoopDataPrefetch - Perform data prefetching in loops.
493 FunctionPass
*createLoopDataPrefetchPass();
495 ///===---------------------------------------------------------------------===//
496 ModulePass
*createNameAnonGlobalPass();
497 ModulePass
*createCanonicalizeAliasesPass();
499 //===----------------------------------------------------------------------===//
501 // LibCallsShrinkWrap - Shrink-wraps a call to function if the result is not
504 FunctionPass
*createLibCallsShrinkWrapPass();
506 //===----------------------------------------------------------------------===//
508 // LoopSimplifyCFG - This pass performs basic CFG simplification on loops,
509 // primarily to help other loop passes.
511 Pass
*createLoopSimplifyCFGPass();
513 //===----------------------------------------------------------------------===//
515 // WarnMissedTransformations - This pass emits warnings for leftover forced
518 Pass
*createWarnMissedTransformationsPass();
519 } // End llvm namespace