blob: 3217257150a95953dc91e4b77f964da339c2c71a [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===-- Scalar.h - Scalar Transformations -----------------------*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
7//===----------------------------------------------------------------------===//
8//
9// This header file defines prototypes for accessor functions that expose passes
10// in the Scalar transformations library.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_TRANSFORMS_SCALAR_H
15#define LLVM_TRANSFORMS_SCALAR_H
16
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020017#include "llvm/Transforms/Utils/SimplifyCFGOptions.h"
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010018#include <functional>
19
20namespace llvm {
21
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010022class Function;
23class FunctionPass;
24class ModulePass;
25class Pass;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010026
27//===----------------------------------------------------------------------===//
28//
29// AlignmentFromAssumptions - Use assume intrinsics to set load/store
30// alignments.
31//
32FunctionPass *createAlignmentFromAssumptionsPass();
33
34//===----------------------------------------------------------------------===//
35//
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020036// AnnotationRemarks - Emit remarks for !annotation metadata.
37//
38FunctionPass *createAnnotationRemarksLegacyPass();
39
40//===----------------------------------------------------------------------===//
41//
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010042// SCCP - Sparse conditional constant propagation.
43//
44FunctionPass *createSCCPPass();
45
46//===----------------------------------------------------------------------===//
47//
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020048// RedundantDbgInstElimination - This pass removes redundant dbg intrinsics
49// without modifying the CFG of the function. It is a FunctionPass.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010050//
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020051Pass *createRedundantDbgInstEliminationPass();
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010052
53//===----------------------------------------------------------------------===//
54//
55// DeadCodeElimination - This pass is more powerful than DeadInstElimination,
56// because it is worklist driven that can potentially revisit instructions when
57// their other instructions become dead, to eliminate chains of dead
58// computations.
59//
60FunctionPass *createDeadCodeEliminationPass();
61
62//===----------------------------------------------------------------------===//
63//
64// DeadStoreElimination - This pass deletes stores that are post-dominated by
65// must-aliased stores and are not loaded used between the stores.
66//
67FunctionPass *createDeadStoreEliminationPass();
68
69
70//===----------------------------------------------------------------------===//
71//
72// CallSiteSplitting - This pass split call-site based on its known argument
73// values.
74FunctionPass *createCallSiteSplittingPass();
75
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010076//===----------------------------------------------------------------------===//
77//
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.
81//
82FunctionPass *createAggressiveDCEPass();
83
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010084//===----------------------------------------------------------------------===//
85//
86// GuardWidening - An optimization over the @llvm.experimental.guard intrinsic
87// that (optimistically) combines multiple guards into one to have fewer checks
88// at runtime.
89//
90FunctionPass *createGuardWideningPass();
91
92
93//===----------------------------------------------------------------------===//
94//
Andrew Scullcdfcccc2018-10-05 20:58:37 +010095// LoopGuardWidening - Analogous to the GuardWidening pass, but restricted to a
96// single loop at a time for use within a LoopPassManager. Desired effect is
97// to widen guards into preheader or a single guard within loop if that's not
98// possible.
99//
100Pass *createLoopGuardWideningPass();
101
102
103//===----------------------------------------------------------------------===//
104//
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100105// BitTrackingDCE - This pass uses a bit-tracking DCE algorithm in order to
106// remove computations of dead bits.
107//
108FunctionPass *createBitTrackingDCEPass();
109
110//===----------------------------------------------------------------------===//
111//
112// SROA - Replace aggregates or pieces of aggregates with scalar SSA values.
113//
114FunctionPass *createSROAPass();
115
116//===----------------------------------------------------------------------===//
117//
118// InductiveRangeCheckElimination - Transform loops to elide range checks on
119// linear functions of the induction variable.
120//
121Pass *createInductiveRangeCheckEliminationPass();
122
123//===----------------------------------------------------------------------===//
124//
125// InductionVariableSimplify - Transform induction variables in a program to all
126// use a single canonical induction variable per loop.
127//
128Pass *createIndVarSimplifyPass();
129
130//===----------------------------------------------------------------------===//
131//
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100132// LICM - This pass is a loop invariant code motion and memory promotion pass.
133//
134Pass *createLICMPass();
Andrew Walbran3d2c1972020-04-07 12:24:26 +0100135Pass *createLICMPass(unsigned LicmMssaOptCap,
136 unsigned LicmMssaNoAccForPromotionCap);
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100137
138//===----------------------------------------------------------------------===//
139//
140// LoopSink - This pass sinks invariants from preheader to loop body where
141// frequency is lower than loop preheader.
142//
143Pass *createLoopSinkPass();
144
145//===----------------------------------------------------------------------===//
146//
147// LoopPredication - This pass does loop predication on guards.
148//
149Pass *createLoopPredicationPass();
150
151//===----------------------------------------------------------------------===//
152//
153// LoopInterchange - This pass interchanges loops to provide a more
154// cache-friendly memory access patterns.
155//
156Pass *createLoopInterchangePass();
157
158//===----------------------------------------------------------------------===//
159//
Olivier Deprezf4ef2d02021-04-20 13:36:24 +0200160// LoopFlatten - This pass flattens nested loops into a single loop.
161//
162FunctionPass *createLoopFlattenPass();
163
164//===----------------------------------------------------------------------===//
165//
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100166// LoopStrengthReduce - This pass is strength reduces GEP instructions that use
167// a loop's canonical induction variable as one of their indices.
168//
169Pass *createLoopStrengthReducePass();
170
171//===----------------------------------------------------------------------===//
172//
173// LoopUnswitch - This pass is a simple loop unswitching pass.
174//
175Pass *createLoopUnswitchPass(bool OptimizeForSize = false,
176 bool hasBranchDivergence = false);
177
178//===----------------------------------------------------------------------===//
179//
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100180// LoopInstSimplify - This pass simplifies instructions in a loop's body.
181//
182Pass *createLoopInstSimplifyPass();
183
184//===----------------------------------------------------------------------===//
185//
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100186// LoopUnroll - This pass is a simple loop unrolling pass.
187//
Andrew Walbran16937d02019-10-22 13:54:20 +0100188Pass *createLoopUnrollPass(int OptLevel = 2, bool OnlyWhenForced = false,
Andrew Walbran3d2c1972020-04-07 12:24:26 +0100189 bool ForgetAllSCEV = false, int Threshold = -1,
190 int Count = -1, int AllowPartial = -1,
191 int Runtime = -1, int UpperBound = -1,
192 int AllowPeeling = -1);
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100193// Create an unrolling pass for full unrolling that uses exact trip count only.
Andrew Walbran3d2c1972020-04-07 12:24:26 +0100194Pass *createSimpleLoopUnrollPass(int OptLevel = 2, bool OnlyWhenForced = false,
195 bool ForgetAllSCEV = false);
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100196
197//===----------------------------------------------------------------------===//
198//
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100199// LoopUnrollAndJam - This pass is a simple loop unroll and jam pass.
200//
201Pass *createLoopUnrollAndJamPass(int OptLevel = 2);
202
203//===----------------------------------------------------------------------===//
204//
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100205// LoopReroll - This pass is a simple loop rerolling pass.
206//
207Pass *createLoopRerollPass();
208
209//===----------------------------------------------------------------------===//
210//
211// LoopRotate - This pass is a simple loop rotating pass.
212//
213Pass *createLoopRotatePass(int MaxHeaderSize = -1);
214
215//===----------------------------------------------------------------------===//
216//
217// LoopIdiom - This pass recognizes and replaces idioms in loops.
218//
219Pass *createLoopIdiomPass();
220
221//===----------------------------------------------------------------------===//
222//
223// LoopVersioningLICM - This pass is a loop versioning pass for LICM.
224//
225Pass *createLoopVersioningLICMPass();
226
227//===----------------------------------------------------------------------===//
228//
229// DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
230// references. In basically undoes the PromoteMemoryToRegister pass to make cfg
231// hacking easier.
232//
233FunctionPass *createDemoteRegisterToMemoryPass();
234extern char &DemoteRegisterToMemoryID;
235
236//===----------------------------------------------------------------------===//
237//
238// Reassociate - This pass reassociates commutative expressions in an order that
239// is designed to promote better constant propagation, GCSE, LICM, PRE...
240//
241// For example: 4 + (x + 5) -> x + (4 + 5)
242//
243FunctionPass *createReassociatePass();
244
245//===----------------------------------------------------------------------===//
246//
247// JumpThreading - Thread control through mult-pred/multi-succ blocks where some
Olivier Deprezf4ef2d02021-04-20 13:36:24 +0200248// preds always go to some succ. If FreezeSelectCond is true, unfold the
249// condition of a select that unfolds to branch. Thresholds other than minus one
250// override the internal BB duplication default threshold.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100251//
Olivier Deprezf4ef2d02021-04-20 13:36:24 +0200252FunctionPass *createJumpThreadingPass(bool FreezeSelectCond = false,
253 int Threshold = -1);
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100254
255//===----------------------------------------------------------------------===//
256//
257// CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
258// simplify terminator instructions, convert switches to lookup tables, etc.
259//
260FunctionPass *createCFGSimplificationPass(
Olivier Deprezf4ef2d02021-04-20 13:36:24 +0200261 SimplifyCFGOptions Options = SimplifyCFGOptions(),
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100262 std::function<bool(const Function &)> Ftor = nullptr);
263
264//===----------------------------------------------------------------------===//
265//
266// FlattenCFG - flatten CFG, reduce number of conditional branches by using
267// parallel-and and parallel-or mode, etc...
268//
269FunctionPass *createFlattenCFGPass();
270
271//===----------------------------------------------------------------------===//
272//
273// CFG Structurization - Remove irreducible control flow
274//
275///
276/// When \p SkipUniformRegions is true the structizer will not structurize
277/// regions that only contain uniform branches.
278Pass *createStructurizeCFGPass(bool SkipUniformRegions = false);
279
280//===----------------------------------------------------------------------===//
281//
282// TailCallElimination - This pass eliminates call instructions to the current
283// function which occur immediately before return instructions.
284//
285FunctionPass *createTailCallEliminationPass();
286
287//===----------------------------------------------------------------------===//
288//
289// EarlyCSE - This pass performs a simple and fast CSE pass over the dominator
290// tree.
291//
292FunctionPass *createEarlyCSEPass(bool UseMemorySSA = false);
293
294//===----------------------------------------------------------------------===//
295//
296// GVNHoist - This pass performs a simple and fast GVN pass over the dominator
297// tree to hoist common expressions from sibling branches.
298//
299FunctionPass *createGVNHoistPass();
300
301//===----------------------------------------------------------------------===//
302//
303// GVNSink - This pass uses an "inverted" value numbering to decide the
304// similarity of expressions and sinks similar expressions into successors.
305//
306FunctionPass *createGVNSinkPass();
307
308//===----------------------------------------------------------------------===//
309//
310// MergedLoadStoreMotion - This pass merges loads and stores in diamonds. Loads
311// are hoisted into the header, while stores sink into the footer.
312//
Olivier Deprezf4ef2d02021-04-20 13:36:24 +0200313FunctionPass *createMergedLoadStoreMotionPass(bool SplitFooterBB = false);
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100314
315//===----------------------------------------------------------------------===//
316//
317// GVN - This pass performs global value numbering and redundant load
318// elimination cotemporaneously.
319//
320FunctionPass *createNewGVNPass();
321
322//===----------------------------------------------------------------------===//
323//
324// DivRemPairs - Hoist/decompose integer division and remainder instructions.
325//
326FunctionPass *createDivRemPairsPass();
327
328//===----------------------------------------------------------------------===//
329//
330// MemCpyOpt - This pass performs optimizations related to eliminating memcpy
331// calls and/or combining multiple stores into memset's.
332//
333FunctionPass *createMemCpyOptPass();
334
335//===----------------------------------------------------------------------===//
336//
337// LoopDeletion - This pass performs DCE of non-infinite loops that it
338// can prove are dead.
339//
340Pass *createLoopDeletionPass();
341
342//===----------------------------------------------------------------------===//
343//
344// ConstantHoisting - This pass prepares a function for expensive constants.
345//
346FunctionPass *createConstantHoistingPass();
347
348//===----------------------------------------------------------------------===//
349//
Olivier Deprezf4ef2d02021-04-20 13:36:24 +0200350// ConstraintElimination - This pass eliminates conditions based on found
351// constraints.
352//
353FunctionPass *createConstraintEliminationPass();
354
355//===----------------------------------------------------------------------===//
356//
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100357// Sink - Code Sinking
358//
359FunctionPass *createSinkingPass();
360
361//===----------------------------------------------------------------------===//
362//
363// LowerAtomic - Lower atomic intrinsics to non-atomic form
364//
365Pass *createLowerAtomicPass();
366
367//===----------------------------------------------------------------------===//
368//
369// LowerGuardIntrinsic - Lower guard intrinsics to normal control flow.
370//
371Pass *createLowerGuardIntrinsicPass();
372
373//===----------------------------------------------------------------------===//
374//
Olivier Deprezf4ef2d02021-04-20 13:36:24 +0200375// LowerMatrixIntrinsics - Lower matrix intrinsics to vector operations.
376//
377Pass *createLowerMatrixIntrinsicsPass();
378
379//===----------------------------------------------------------------------===//
380//
381// LowerMatrixIntrinsicsMinimal - Lower matrix intrinsics to vector operations
382// (lightweight, does not require extra analysis)
383//
384Pass *createLowerMatrixIntrinsicsMinimalPass();
385
386//===----------------------------------------------------------------------===//
387//
Andrew Walbran16937d02019-10-22 13:54:20 +0100388// LowerWidenableCondition - Lower widenable condition to i1 true.
389//
390Pass *createLowerWidenableConditionPass();
391
392//===----------------------------------------------------------------------===//
393//
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100394// MergeICmps - Merge integer comparison chains into a memcmp
395//
Andrew Walbran3d2c1972020-04-07 12:24:26 +0100396Pass *createMergeICmpsLegacyPass();
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100397
398//===----------------------------------------------------------------------===//
399//
400// ValuePropagation - Propagate CFG-derived value information
401//
402Pass *createCorrelatedValuePropagationPass();
403
404//===----------------------------------------------------------------------===//
405//
406// InferAddressSpaces - Modify users of addrspacecast instructions with values
407// in the source address space if using the destination address space is slower
Andrew Walbran3d2c1972020-04-07 12:24:26 +0100408// on the target. If AddressSpace is left to its default value, it will be
409// obtained from the TargetTransformInfo.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100410//
Andrew Walbran3d2c1972020-04-07 12:24:26 +0100411FunctionPass *createInferAddressSpacesPass(unsigned AddressSpace = ~0u);
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100412extern char &InferAddressSpacesID;
413
414//===----------------------------------------------------------------------===//
415//
416// LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates
417// "block_weights" metadata.
418FunctionPass *createLowerExpectIntrinsicPass();
419
420//===----------------------------------------------------------------------===//
421//
Olivier Deprezf4ef2d02021-04-20 13:36:24 +0200422// LowerConstantIntrinsicss - Expand any remaining llvm.objectsize and
423// llvm.is.constant intrinsic calls, even for the unknown cases.
424//
425FunctionPass *createLowerConstantIntrinsicsPass();
426
427//===----------------------------------------------------------------------===//
428//
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100429// PartiallyInlineLibCalls - Tries to inline the fast path of library
430// calls such as sqrt.
431//
432FunctionPass *createPartiallyInlineLibCallsPass();
433
434//===----------------------------------------------------------------------===//
435//
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100436// SeparateConstOffsetFromGEP - Split GEPs for better CSE
437//
438FunctionPass *createSeparateConstOffsetFromGEPPass(bool LowerGEP = false);
439
440//===----------------------------------------------------------------------===//
441//
442// SpeculativeExecution - Aggressively hoist instructions to enable
443// speculative execution on targets where branches are expensive.
444//
445FunctionPass *createSpeculativeExecutionPass();
446
447// Same as createSpeculativeExecutionPass, but does nothing unless
448// TargetTransformInfo::hasBranchDivergence() is true.
449FunctionPass *createSpeculativeExecutionIfHasBranchDivergencePass();
450
451//===----------------------------------------------------------------------===//
452//
453// StraightLineStrengthReduce - This pass strength-reduces some certain
454// instruction patterns in straight-line code.
455//
456FunctionPass *createStraightLineStrengthReducePass();
457
458//===----------------------------------------------------------------------===//
459//
460// PlaceSafepoints - Rewrite any IR calls to gc.statepoints and insert any
461// safepoint polls (method entry, backedge) that might be required. This pass
462// does not generate explicit relocation sequences - that's handled by
463// RewriteStatepointsForGC which can be run at an arbitrary point in the pass
464// order following this pass.
465//
466FunctionPass *createPlaceSafepointsPass();
467
468//===----------------------------------------------------------------------===//
469//
470// RewriteStatepointsForGC - Rewrite any gc.statepoints which do not yet have
471// explicit relocations to include explicit relocations.
472//
473ModulePass *createRewriteStatepointsForGCLegacyPass();
474
475//===----------------------------------------------------------------------===//
476//
477// Float2Int - Demote floats to ints where possible.
478//
479FunctionPass *createFloat2IntPass();
480
481//===----------------------------------------------------------------------===//
482//
483// NaryReassociate - Simplify n-ary operations by reassociation.
484//
485FunctionPass *createNaryReassociatePass();
486
487//===----------------------------------------------------------------------===//
488//
489// LoopDistribute - Distribute loops.
490//
491FunctionPass *createLoopDistributePass();
492
493//===----------------------------------------------------------------------===//
494//
Andrew Walbran3d2c1972020-04-07 12:24:26 +0100495// LoopFuse - Fuse loops.
496//
497FunctionPass *createLoopFusePass();
498
499//===----------------------------------------------------------------------===//
500//
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100501// LoopLoadElimination - Perform loop-aware load elimination.
502//
503FunctionPass *createLoopLoadEliminationPass();
504
505//===----------------------------------------------------------------------===//
506//
507// LoopVersioning - Perform loop multi-versioning.
508//
509FunctionPass *createLoopVersioningPass();
510
511//===----------------------------------------------------------------------===//
512//
513// LoopDataPrefetch - Perform data prefetching in loops.
514//
515FunctionPass *createLoopDataPrefetchPass();
516
517///===---------------------------------------------------------------------===//
518ModulePass *createNameAnonGlobalPass();
Andrew Walbran16937d02019-10-22 13:54:20 +0100519ModulePass *createCanonicalizeAliasesPass();
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100520
521//===----------------------------------------------------------------------===//
522//
523// LibCallsShrinkWrap - Shrink-wraps a call to function if the result is not
524// used.
525//
526FunctionPass *createLibCallsShrinkWrapPass();
527
528//===----------------------------------------------------------------------===//
529//
530// LoopSimplifyCFG - This pass performs basic CFG simplification on loops,
531// primarily to help other loop passes.
532//
533Pass *createLoopSimplifyCFGPass();
Andrew Walbran16937d02019-10-22 13:54:20 +0100534
535//===----------------------------------------------------------------------===//
536//
537// WarnMissedTransformations - This pass emits warnings for leftover forced
538// transformations.
539//
540Pass *createWarnMissedTransformationsPass();
Olivier Deprezf4ef2d02021-04-20 13:36:24 +0200541
542//===----------------------------------------------------------------------===//
543//
544// This pass does instruction simplification on each
545// instruction in a function.
546//
547FunctionPass *createInstSimplifyLegacyPass();
548
549
550//===----------------------------------------------------------------------===//
551//
552// createScalarizeMaskedMemIntrinPass - Replace masked load, store, gather
553// and scatter intrinsics with scalar code when target doesn't support them.
554//
555FunctionPass *createScalarizeMaskedMemIntrinLegacyPass();
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100556} // End llvm namespace
557
558#endif