Scalar.h revision 353358
1//===-- Scalar.h - Scalar Transformations -----------------------*- C++ -*-===//
2//
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
6//
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;
28class 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
81//===----------------------------------------------------------------------===//
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
89//===----------------------------------------------------------------------===//
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//
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
103// possible.
104//
105Pass *createLoopGuardWideningPass();
106
107
108//===----------------------------------------------------------------------===//
109//
110// 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//
137// LICM - This pass is a loop invariant code motion and memory promotion pass.
138//
139Pass *createLICMPass();
140Pass *createLICMPass(unsigned LicmMssaOptCap,
141                     unsigned LicmMssaNoAccForPromotionCap);
142
143//===----------------------------------------------------------------------===//
144//
145// LoopSink - This pass sinks invariants from preheader to loop body where
146// frequency is lower than loop preheader.
147//
148Pass *createLoopSinkPass();
149
150//===----------------------------------------------------------------------===//
151//
152// LoopPredication - This pass does loop predication on guards.
153//
154Pass *createLoopPredicationPass();
155
156//===----------------------------------------------------------------------===//
157//
158// LoopInterchange - This pass interchanges loops to provide a more
159// cache-friendly memory access patterns.
160//
161Pass *createLoopInterchangePass();
162
163//===----------------------------------------------------------------------===//
164//
165// LoopStrengthReduce - This pass is strength reduces GEP instructions that use
166// a loop's canonical induction variable as one of their indices.
167//
168Pass *createLoopStrengthReducePass();
169
170//===----------------------------------------------------------------------===//
171//
172// LoopUnswitch - This pass is a simple loop unswitching pass.
173//
174Pass *createLoopUnswitchPass(bool OptimizeForSize = false,
175                             bool hasBranchDivergence = false);
176
177//===----------------------------------------------------------------------===//
178//
179// LoopInstSimplify - This pass simplifies instructions in a loop's body.
180//
181Pass *createLoopInstSimplifyPass();
182
183//===----------------------------------------------------------------------===//
184//
185// LoopUnroll - This pass is a simple loop unrolling pass.
186//
187Pass *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.
193Pass *createSimpleLoopUnrollPass(int OptLevel = 2, bool OnlyWhenForced = false,
194                                 bool ForgetAllSCEV = false);
195
196//===----------------------------------------------------------------------===//
197//
198// LoopUnrollAndJam - This pass is a simple loop unroll and jam pass.
199//
200Pass *createLoopUnrollAndJamPass(int OptLevel = 2);
201
202//===----------------------------------------------------------------------===//
203//
204// LoopReroll - This pass is a simple loop rerolling pass.
205//
206Pass *createLoopRerollPass();
207
208//===----------------------------------------------------------------------===//
209//
210// LoopRotate - This pass is a simple loop rotating pass.
211//
212Pass *createLoopRotatePass(int MaxHeaderSize = -1);
213
214//===----------------------------------------------------------------------===//
215//
216// LoopIdiom - This pass recognizes and replaces idioms in loops.
217//
218Pass *createLoopIdiomPass();
219
220//===----------------------------------------------------------------------===//
221//
222// LoopVersioningLICM - This pass is a loop versioning pass for LICM.
223//
224Pass *createLoopVersioningLICMPass();
225
226//===----------------------------------------------------------------------===//
227//
228// DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
229// references. In basically undoes the PromoteMemoryToRegister pass to make cfg
230// hacking easier.
231//
232FunctionPass *createDemoteRegisterToMemoryPass();
233extern char &DemoteRegisterToMemoryID;
234
235//===----------------------------------------------------------------------===//
236//
237// Reassociate - This pass reassociates commutative expressions in an order that
238// is designed to promote better constant propagation, GCSE, LICM, PRE...
239//
240// For example:  4 + (x + 5)  ->  x + (4 + 5)
241//
242FunctionPass *createReassociatePass();
243
244//===----------------------------------------------------------------------===//
245//
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.
249//
250FunctionPass *createJumpThreadingPass(int Threshold = -1);
251
252//===----------------------------------------------------------------------===//
253//
254// CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
255// simplify terminator instructions, convert switches to lookup tables, etc.
256//
257FunctionPass *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);
261
262//===----------------------------------------------------------------------===//
263//
264// FlattenCFG - flatten CFG, reduce number of conditional branches by using
265// parallel-and and parallel-or mode, etc...
266//
267FunctionPass *createFlattenCFGPass();
268
269//===----------------------------------------------------------------------===//
270//
271// CFG Structurization - Remove irreducible control flow
272//
273///
274/// When \p SkipUniformRegions is true the structizer will not structurize
275/// regions that only contain uniform branches.
276Pass *createStructurizeCFGPass(bool SkipUniformRegions = false);
277
278//===----------------------------------------------------------------------===//
279//
280// TailCallElimination - This pass eliminates call instructions to the current
281// function which occur immediately before return instructions.
282//
283FunctionPass *createTailCallEliminationPass();
284
285//===----------------------------------------------------------------------===//
286//
287// EarlyCSE - This pass performs a simple and fast CSE pass over the dominator
288// tree.
289//
290FunctionPass *createEarlyCSEPass(bool UseMemorySSA = false);
291
292//===----------------------------------------------------------------------===//
293//
294// GVNHoist - This pass performs a simple and fast GVN pass over the dominator
295// tree to hoist common expressions from sibling branches.
296//
297FunctionPass *createGVNHoistPass();
298
299//===----------------------------------------------------------------------===//
300//
301// GVNSink - This pass uses an "inverted" value numbering to decide the
302// similarity of expressions and sinks similar expressions into successors.
303//
304FunctionPass *createGVNSinkPass();
305
306//===----------------------------------------------------------------------===//
307//
308// MergedLoadStoreMotion - This pass merges loads and stores in diamonds. Loads
309// are hoisted into the header, while stores sink into the footer.
310//
311FunctionPass *createMergedLoadStoreMotionPass();
312
313//===----------------------------------------------------------------------===//
314//
315// GVN - This pass performs global value numbering and redundant load
316// elimination cotemporaneously.
317//
318FunctionPass *createNewGVNPass();
319
320//===----------------------------------------------------------------------===//
321//
322// DivRemPairs - Hoist/decompose integer division and remainder instructions.
323//
324FunctionPass *createDivRemPairsPass();
325
326//===----------------------------------------------------------------------===//
327//
328// MemCpyOpt - This pass performs optimizations related to eliminating memcpy
329// calls and/or combining multiple stores into memset's.
330//
331FunctionPass *createMemCpyOptPass();
332
333//===----------------------------------------------------------------------===//
334//
335// LoopDeletion - This pass performs DCE of non-infinite loops that it
336// can prove are dead.
337//
338Pass *createLoopDeletionPass();
339
340//===----------------------------------------------------------------------===//
341//
342// ConstantHoisting - This pass prepares a function for expensive constants.
343//
344FunctionPass *createConstantHoistingPass();
345
346//===----------------------------------------------------------------------===//
347//
348// Sink - Code Sinking
349//
350FunctionPass *createSinkingPass();
351
352//===----------------------------------------------------------------------===//
353//
354// LowerAtomic - Lower atomic intrinsics to non-atomic form
355//
356Pass *createLowerAtomicPass();
357
358//===----------------------------------------------------------------------===//
359//
360// LowerGuardIntrinsic - Lower guard intrinsics to normal control flow.
361//
362Pass *createLowerGuardIntrinsicPass();
363
364//===----------------------------------------------------------------------===//
365//
366// LowerWidenableCondition - Lower widenable condition to i1 true.
367//
368Pass *createLowerWidenableConditionPass();
369
370//===----------------------------------------------------------------------===//
371//
372// MergeICmps - Merge integer comparison chains into a memcmp
373//
374Pass *createMergeICmpsLegacyPass();
375
376//===----------------------------------------------------------------------===//
377//
378// ValuePropagation - Propagate CFG-derived value information
379//
380Pass *createCorrelatedValuePropagationPass();
381
382//===----------------------------------------------------------------------===//
383//
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.
388//
389FunctionPass *createInferAddressSpacesPass(unsigned AddressSpace = ~0u);
390extern char &InferAddressSpacesID;
391
392//===----------------------------------------------------------------------===//
393//
394// LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates
395// "block_weights" metadata.
396FunctionPass *createLowerExpectIntrinsicPass();
397
398//===----------------------------------------------------------------------===//
399//
400// PartiallyInlineLibCalls - Tries to inline the fast path of library
401// calls such as sqrt.
402//
403FunctionPass *createPartiallyInlineLibCallsPass();
404
405//===----------------------------------------------------------------------===//
406//
407// SeparateConstOffsetFromGEP - Split GEPs for better CSE
408//
409FunctionPass *createSeparateConstOffsetFromGEPPass(bool LowerGEP = false);
410
411//===----------------------------------------------------------------------===//
412//
413// SpeculativeExecution - Aggressively hoist instructions to enable
414// speculative execution on targets where branches are expensive.
415//
416FunctionPass *createSpeculativeExecutionPass();
417
418// Same as createSpeculativeExecutionPass, but does nothing unless
419// TargetTransformInfo::hasBranchDivergence() is true.
420FunctionPass *createSpeculativeExecutionIfHasBranchDivergencePass();
421
422//===----------------------------------------------------------------------===//
423//
424// StraightLineStrengthReduce - This pass strength-reduces some certain
425// instruction patterns in straight-line code.
426//
427FunctionPass *createStraightLineStrengthReducePass();
428
429//===----------------------------------------------------------------------===//
430//
431// PlaceSafepoints - Rewrite any IR calls to gc.statepoints and insert any
432// safepoint polls (method entry, backedge) that might be required.  This pass
433// does not generate explicit relocation sequences - that's handled by
434// RewriteStatepointsForGC which can be run at an arbitrary point in the pass
435// order following this pass.
436//
437FunctionPass *createPlaceSafepointsPass();
438
439//===----------------------------------------------------------------------===//
440//
441// RewriteStatepointsForGC - Rewrite any gc.statepoints which do not yet have
442// explicit relocations to include explicit relocations.
443//
444ModulePass *createRewriteStatepointsForGCLegacyPass();
445
446//===----------------------------------------------------------------------===//
447//
448// Float2Int - Demote floats to ints where possible.
449//
450FunctionPass *createFloat2IntPass();
451
452//===----------------------------------------------------------------------===//
453//
454// NaryReassociate - Simplify n-ary operations by reassociation.
455//
456FunctionPass *createNaryReassociatePass();
457
458//===----------------------------------------------------------------------===//
459//
460// LoopDistribute - Distribute loops.
461//
462FunctionPass *createLoopDistributePass();
463
464//===----------------------------------------------------------------------===//
465//
466// LoopFuse - Fuse loops.
467//
468FunctionPass *createLoopFusePass();
469
470//===----------------------------------------------------------------------===//
471//
472// LoopLoadElimination - Perform loop-aware load elimination.
473//
474FunctionPass *createLoopLoadEliminationPass();
475
476//===----------------------------------------------------------------------===//
477//
478// LoopVersioning - Perform loop multi-versioning.
479//
480FunctionPass *createLoopVersioningPass();
481
482//===----------------------------------------------------------------------===//
483//
484// LoopDataPrefetch - Perform data prefetching in loops.
485//
486FunctionPass *createLoopDataPrefetchPass();
487
488///===---------------------------------------------------------------------===//
489ModulePass *createNameAnonGlobalPass();
490ModulePass *createCanonicalizeAliasesPass();
491
492//===----------------------------------------------------------------------===//
493//
494// LibCallsShrinkWrap - Shrink-wraps a call to function if the result is not
495// used.
496//
497FunctionPass *createLibCallsShrinkWrapPass();
498
499//===----------------------------------------------------------------------===//
500//
501// LoopSimplifyCFG - This pass performs basic CFG simplification on loops,
502// primarily to help other loop passes.
503//
504Pass *createLoopSimplifyCFGPass();
505
506//===----------------------------------------------------------------------===//
507//
508// WarnMissedTransformations - This pass emits warnings for leftover forced
509// transformations.
510//
511Pass *createWarnMissedTransformationsPass();
512} // End llvm namespace
513
514#endif
515