blob: 97a4c06cdc904a4775545ebe0bd864e382f0d51a [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
17#include <functional>
18
19namespace llvm {
20
21class BasicBlockPass;
22class Function;
23class FunctionPass;
24class ModulePass;
25class Pass;
26class GetElementPtrInst;
27class PassInfo;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010028class TargetLowering;
29class TargetMachine;
30
31//===----------------------------------------------------------------------===//
32//
33// ConstantPropagation - A worklist driven constant propagation pass
34//
35FunctionPass *createConstantPropagationPass();
36
37//===----------------------------------------------------------------------===//
38//
39// AlignmentFromAssumptions - Use assume intrinsics to set load/store
40// alignments.
41//
42FunctionPass *createAlignmentFromAssumptionsPass();
43
44//===----------------------------------------------------------------------===//
45//
46// SCCP - Sparse conditional constant propagation.
47//
48FunctionPass *createSCCPPass();
49
50//===----------------------------------------------------------------------===//
51//
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.
55//
56Pass *createDeadInstEliminationPass();
57
58//===----------------------------------------------------------------------===//
59//
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
63// computations.
64//
65FunctionPass *createDeadCodeEliminationPass();
66
67//===----------------------------------------------------------------------===//
68//
69// DeadStoreElimination - This pass deletes stores that are post-dominated by
70// must-aliased stores and are not loaded used between the stores.
71//
72FunctionPass *createDeadStoreEliminationPass();
73
74
75//===----------------------------------------------------------------------===//
76//
77// CallSiteSplitting - This pass split call-site based on its known argument
78// values.
79FunctionPass *createCallSiteSplittingPass();
80
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010081//===----------------------------------------------------------------------===//
82//
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.
86//
87FunctionPass *createAggressiveDCEPass();
88
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010089//===----------------------------------------------------------------------===//
90//
91// GuardWidening - An optimization over the @llvm.experimental.guard intrinsic
92// that (optimistically) combines multiple guards into one to have fewer checks
93// at runtime.
94//
95FunctionPass *createGuardWideningPass();
96
97
98//===----------------------------------------------------------------------===//
99//
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100100// 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
103// possible.
104//
105Pass *createLoopGuardWideningPass();
106
107
108//===----------------------------------------------------------------------===//
109//
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100110// BitTrackingDCE - This pass uses a bit-tracking DCE algorithm in order to
111// remove computations of dead bits.
112//
113FunctionPass *createBitTrackingDCEPass();
114
115//===----------------------------------------------------------------------===//
116//
117// SROA - Replace aggregates or pieces of aggregates with scalar SSA values.
118//
119FunctionPass *createSROAPass();
120
121//===----------------------------------------------------------------------===//
122//
123// InductiveRangeCheckElimination - Transform loops to elide range checks on
124// linear functions of the induction variable.
125//
126Pass *createInductiveRangeCheckEliminationPass();
127
128//===----------------------------------------------------------------------===//
129//
130// InductionVariableSimplify - Transform induction variables in a program to all
131// use a single canonical induction variable per loop.
132//
133Pass *createIndVarSimplifyPass();
134
135//===----------------------------------------------------------------------===//
136//
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100137// LICM - This pass is a loop invariant code motion and memory promotion pass.
138//
139Pass *createLICMPass();
140
141//===----------------------------------------------------------------------===//
142//
143// LoopSink - This pass sinks invariants from preheader to loop body where
144// frequency is lower than loop preheader.
145//
146Pass *createLoopSinkPass();
147
148//===----------------------------------------------------------------------===//
149//
150// LoopPredication - This pass does loop predication on guards.
151//
152Pass *createLoopPredicationPass();
153
154//===----------------------------------------------------------------------===//
155//
156// LoopInterchange - This pass interchanges loops to provide a more
157// cache-friendly memory access patterns.
158//
159Pass *createLoopInterchangePass();
160
161//===----------------------------------------------------------------------===//
162//
163// LoopStrengthReduce - This pass is strength reduces GEP instructions that use
164// a loop's canonical induction variable as one of their indices.
165//
166Pass *createLoopStrengthReducePass();
167
168//===----------------------------------------------------------------------===//
169//
170// LoopUnswitch - This pass is a simple loop unswitching pass.
171//
172Pass *createLoopUnswitchPass(bool OptimizeForSize = false,
173 bool hasBranchDivergence = false);
174
175//===----------------------------------------------------------------------===//
176//
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100177// LoopInstSimplify - This pass simplifies instructions in a loop's body.
178//
179Pass *createLoopInstSimplifyPass();
180
181//===----------------------------------------------------------------------===//
182//
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100183// LoopUnroll - This pass is a simple loop unrolling pass.
184//
Andrew Walbran16937d02019-10-22 13:54:20 +0100185Pass *createLoopUnrollPass(int OptLevel = 2, bool OnlyWhenForced = false,
186 int Threshold = -1, int Count = -1,
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100187 int AllowPartial = -1, int Runtime = -1,
188 int UpperBound = -1, int AllowPeeling = -1);
189// Create an unrolling pass for full unrolling that uses exact trip count only.
Andrew Walbran16937d02019-10-22 13:54:20 +0100190Pass *createSimpleLoopUnrollPass(int OptLevel = 2, bool OnlyWhenForced = false);
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100191
192//===----------------------------------------------------------------------===//
193//
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100194// LoopUnrollAndJam - This pass is a simple loop unroll and jam pass.
195//
196Pass *createLoopUnrollAndJamPass(int OptLevel = 2);
197
198//===----------------------------------------------------------------------===//
199//
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100200// LoopReroll - This pass is a simple loop rerolling pass.
201//
202Pass *createLoopRerollPass();
203
204//===----------------------------------------------------------------------===//
205//
206// LoopRotate - This pass is a simple loop rotating pass.
207//
208Pass *createLoopRotatePass(int MaxHeaderSize = -1);
209
210//===----------------------------------------------------------------------===//
211//
212// LoopIdiom - This pass recognizes and replaces idioms in loops.
213//
214Pass *createLoopIdiomPass();
215
216//===----------------------------------------------------------------------===//
217//
218// LoopVersioningLICM - This pass is a loop versioning pass for LICM.
219//
220Pass *createLoopVersioningLICMPass();
221
222//===----------------------------------------------------------------------===//
223//
224// DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
225// references. In basically undoes the PromoteMemoryToRegister pass to make cfg
226// hacking easier.
227//
228FunctionPass *createDemoteRegisterToMemoryPass();
229extern char &DemoteRegisterToMemoryID;
230
231//===----------------------------------------------------------------------===//
232//
233// Reassociate - This pass reassociates commutative expressions in an order that
234// is designed to promote better constant propagation, GCSE, LICM, PRE...
235//
236// For example: 4 + (x + 5) -> x + (4 + 5)
237//
238FunctionPass *createReassociatePass();
239
240//===----------------------------------------------------------------------===//
241//
242// JumpThreading - Thread control through mult-pred/multi-succ blocks where some
243// preds always go to some succ. Thresholds other than minus one override the
244// internal BB duplication default threshold.
245//
246FunctionPass *createJumpThreadingPass(int Threshold = -1);
247
248//===----------------------------------------------------------------------===//
249//
250// CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
251// simplify terminator instructions, convert switches to lookup tables, etc.
252//
253FunctionPass *createCFGSimplificationPass(
254 unsigned Threshold = 1, bool ForwardSwitchCond = false,
255 bool ConvertSwitch = false, bool KeepLoops = true, bool SinkCommon = false,
256 std::function<bool(const Function &)> Ftor = nullptr);
257
258//===----------------------------------------------------------------------===//
259//
260// FlattenCFG - flatten CFG, reduce number of conditional branches by using
261// parallel-and and parallel-or mode, etc...
262//
263FunctionPass *createFlattenCFGPass();
264
265//===----------------------------------------------------------------------===//
266//
267// CFG Structurization - Remove irreducible control flow
268//
269///
270/// When \p SkipUniformRegions is true the structizer will not structurize
271/// regions that only contain uniform branches.
272Pass *createStructurizeCFGPass(bool SkipUniformRegions = false);
273
274//===----------------------------------------------------------------------===//
275//
276// TailCallElimination - This pass eliminates call instructions to the current
277// function which occur immediately before return instructions.
278//
279FunctionPass *createTailCallEliminationPass();
280
281//===----------------------------------------------------------------------===//
282//
283// EarlyCSE - This pass performs a simple and fast CSE pass over the dominator
284// tree.
285//
286FunctionPass *createEarlyCSEPass(bool UseMemorySSA = false);
287
288//===----------------------------------------------------------------------===//
289//
290// GVNHoist - This pass performs a simple and fast GVN pass over the dominator
291// tree to hoist common expressions from sibling branches.
292//
293FunctionPass *createGVNHoistPass();
294
295//===----------------------------------------------------------------------===//
296//
297// GVNSink - This pass uses an "inverted" value numbering to decide the
298// similarity of expressions and sinks similar expressions into successors.
299//
300FunctionPass *createGVNSinkPass();
301
302//===----------------------------------------------------------------------===//
303//
304// MergedLoadStoreMotion - This pass merges loads and stores in diamonds. Loads
305// are hoisted into the header, while stores sink into the footer.
306//
307FunctionPass *createMergedLoadStoreMotionPass();
308
309//===----------------------------------------------------------------------===//
310//
311// GVN - This pass performs global value numbering and redundant load
312// elimination cotemporaneously.
313//
314FunctionPass *createNewGVNPass();
315
316//===----------------------------------------------------------------------===//
317//
318// DivRemPairs - Hoist/decompose integer division and remainder instructions.
319//
320FunctionPass *createDivRemPairsPass();
321
322//===----------------------------------------------------------------------===//
323//
324// MemCpyOpt - This pass performs optimizations related to eliminating memcpy
325// calls and/or combining multiple stores into memset's.
326//
327FunctionPass *createMemCpyOptPass();
328
329//===----------------------------------------------------------------------===//
330//
331// LoopDeletion - This pass performs DCE of non-infinite loops that it
332// can prove are dead.
333//
334Pass *createLoopDeletionPass();
335
336//===----------------------------------------------------------------------===//
337//
338// ConstantHoisting - This pass prepares a function for expensive constants.
339//
340FunctionPass *createConstantHoistingPass();
341
342//===----------------------------------------------------------------------===//
343//
344// Sink - Code Sinking
345//
346FunctionPass *createSinkingPass();
347
348//===----------------------------------------------------------------------===//
349//
350// LowerAtomic - Lower atomic intrinsics to non-atomic form
351//
352Pass *createLowerAtomicPass();
353
354//===----------------------------------------------------------------------===//
355//
356// LowerGuardIntrinsic - Lower guard intrinsics to normal control flow.
357//
358Pass *createLowerGuardIntrinsicPass();
359
360//===----------------------------------------------------------------------===//
361//
Andrew Walbran16937d02019-10-22 13:54:20 +0100362// LowerWidenableCondition - Lower widenable condition to i1 true.
363//
364Pass *createLowerWidenableConditionPass();
365
366//===----------------------------------------------------------------------===//
367//
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100368// MergeICmps - Merge integer comparison chains into a memcmp
369//
370Pass *createMergeICmpsPass();
371
372//===----------------------------------------------------------------------===//
373//
374// ValuePropagation - Propagate CFG-derived value information
375//
376Pass *createCorrelatedValuePropagationPass();
377
378//===----------------------------------------------------------------------===//
379//
380// InferAddressSpaces - Modify users of addrspacecast instructions with values
381// in the source address space if using the destination address space is slower
382// on the target.
383//
384FunctionPass *createInferAddressSpacesPass();
385extern char &InferAddressSpacesID;
386
387//===----------------------------------------------------------------------===//
388//
389// LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates
390// "block_weights" metadata.
391FunctionPass *createLowerExpectIntrinsicPass();
392
393//===----------------------------------------------------------------------===//
394//
395// PartiallyInlineLibCalls - Tries to inline the fast path of library
396// calls such as sqrt.
397//
398FunctionPass *createPartiallyInlineLibCallsPass();
399
400//===----------------------------------------------------------------------===//
401//
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100402// SeparateConstOffsetFromGEP - Split GEPs for better CSE
403//
404FunctionPass *createSeparateConstOffsetFromGEPPass(bool LowerGEP = false);
405
406//===----------------------------------------------------------------------===//
407//
408// SpeculativeExecution - Aggressively hoist instructions to enable
409// speculative execution on targets where branches are expensive.
410//
411FunctionPass *createSpeculativeExecutionPass();
412
413// Same as createSpeculativeExecutionPass, but does nothing unless
414// TargetTransformInfo::hasBranchDivergence() is true.
415FunctionPass *createSpeculativeExecutionIfHasBranchDivergencePass();
416
417//===----------------------------------------------------------------------===//
418//
419// StraightLineStrengthReduce - This pass strength-reduces some certain
420// instruction patterns in straight-line code.
421//
422FunctionPass *createStraightLineStrengthReducePass();
423
424//===----------------------------------------------------------------------===//
425//
426// PlaceSafepoints - Rewrite any IR calls to gc.statepoints and insert any
427// safepoint polls (method entry, backedge) that might be required. This pass
428// does not generate explicit relocation sequences - that's handled by
429// RewriteStatepointsForGC which can be run at an arbitrary point in the pass
430// order following this pass.
431//
432FunctionPass *createPlaceSafepointsPass();
433
434//===----------------------------------------------------------------------===//
435//
436// RewriteStatepointsForGC - Rewrite any gc.statepoints which do not yet have
437// explicit relocations to include explicit relocations.
438//
439ModulePass *createRewriteStatepointsForGCLegacyPass();
440
441//===----------------------------------------------------------------------===//
442//
443// Float2Int - Demote floats to ints where possible.
444//
445FunctionPass *createFloat2IntPass();
446
447//===----------------------------------------------------------------------===//
448//
449// NaryReassociate - Simplify n-ary operations by reassociation.
450//
451FunctionPass *createNaryReassociatePass();
452
453//===----------------------------------------------------------------------===//
454//
455// LoopDistribute - Distribute loops.
456//
457FunctionPass *createLoopDistributePass();
458
459//===----------------------------------------------------------------------===//
460//
461// LoopLoadElimination - Perform loop-aware load elimination.
462//
463FunctionPass *createLoopLoadEliminationPass();
464
465//===----------------------------------------------------------------------===//
466//
467// LoopVersioning - Perform loop multi-versioning.
468//
469FunctionPass *createLoopVersioningPass();
470
471//===----------------------------------------------------------------------===//
472//
473// LoopDataPrefetch - Perform data prefetching in loops.
474//
475FunctionPass *createLoopDataPrefetchPass();
476
477///===---------------------------------------------------------------------===//
478ModulePass *createNameAnonGlobalPass();
Andrew Walbran16937d02019-10-22 13:54:20 +0100479ModulePass *createCanonicalizeAliasesPass();
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100480
481//===----------------------------------------------------------------------===//
482//
483// LibCallsShrinkWrap - Shrink-wraps a call to function if the result is not
484// used.
485//
486FunctionPass *createLibCallsShrinkWrapPass();
487
488//===----------------------------------------------------------------------===//
489//
490// LoopSimplifyCFG - This pass performs basic CFG simplification on loops,
491// primarily to help other loop passes.
492//
493Pass *createLoopSimplifyCFGPass();
Andrew Walbran16937d02019-10-22 13:54:20 +0100494
495//===----------------------------------------------------------------------===//
496//
497// WarnMissedTransformations - This pass emits warnings for leftover forced
498// transformations.
499//
500Pass *createWarnMissedTransformationsPass();
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100501} // End llvm namespace
502
503#endif