Scalar.h revision 309124
1//===-- Scalar.h - Scalar Transformations -----------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This header file defines prototypes for accessor functions that expose passes
11// in the Scalar transformations library.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_TRANSFORMS_SCALAR_H
16#define LLVM_TRANSFORMS_SCALAR_H
17
18#include <functional>
19
20namespace llvm {
21
22class BasicBlockPass;
23class Function;
24class FunctionPass;
25class ModulePass;
26class Pass;
27class GetElementPtrInst;
28class PassInfo;
29class TerminatorInst;
30class TargetLowering;
31class TargetMachine;
32
33//===----------------------------------------------------------------------===//
34//
35// ConstantPropagation - A worklist driven constant propagation pass
36//
37FunctionPass *createConstantPropagationPass();
38
39//===----------------------------------------------------------------------===//
40//
41// AlignmentFromAssumptions - Use assume intrinsics to set load/store
42// alignments.
43//
44FunctionPass *createAlignmentFromAssumptionsPass();
45
46//===----------------------------------------------------------------------===//
47//
48// SCCP - Sparse conditional constant propagation.
49//
50FunctionPass *createSCCPPass();
51
52//===----------------------------------------------------------------------===//
53//
54// DeadInstElimination - This pass quickly removes trivially dead instructions
55// without modifying the CFG of the function.  It is a BasicBlockPass, so it
56// runs efficiently when queued next to other BasicBlockPass's.
57//
58Pass *createDeadInstEliminationPass();
59
60//===----------------------------------------------------------------------===//
61//
62// DeadCodeElimination - This pass is more powerful than DeadInstElimination,
63// because it is worklist driven that can potentially revisit instructions when
64// their other instructions become dead, to eliminate chains of dead
65// computations.
66//
67FunctionPass *createDeadCodeEliminationPass();
68
69//===----------------------------------------------------------------------===//
70//
71// DeadStoreElimination - This pass deletes stores that are post-dominated by
72// must-aliased stores and are not loaded used between the stores.
73//
74FunctionPass *createDeadStoreEliminationPass();
75
76//===----------------------------------------------------------------------===//
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
84
85//===----------------------------------------------------------------------===//
86//
87// GuardWidening - An optimization over the @llvm.experimental.guard intrinsic
88// that (optimistically) combines multiple guards into one to have fewer checks
89// at runtime.
90//
91FunctionPass *createGuardWideningPass();
92
93
94//===----------------------------------------------------------------------===//
95//
96// BitTrackingDCE - This pass uses a bit-tracking DCE algorithm in order to
97// remove computations of dead bits.
98//
99FunctionPass *createBitTrackingDCEPass();
100
101//===----------------------------------------------------------------------===//
102//
103// SROA - Replace aggregates or pieces of aggregates with scalar SSA values.
104//
105FunctionPass *createSROAPass();
106
107//===----------------------------------------------------------------------===//
108//
109// InductiveRangeCheckElimination - Transform loops to elide range checks on
110// linear functions of the induction variable.
111//
112Pass *createInductiveRangeCheckEliminationPass();
113
114//===----------------------------------------------------------------------===//
115//
116// InductionVariableSimplify - Transform induction variables in a program to all
117// use a single canonical induction variable per loop.
118//
119Pass *createIndVarSimplifyPass();
120
121//===----------------------------------------------------------------------===//
122//
123// InstructionCombining - Combine instructions to form fewer, simple
124// instructions. This pass does not modify the CFG, and has a tendency to make
125// instructions dead, so a subsequent DCE pass is useful.
126//
127// This pass combines things like:
128//    %Y = add int 1, %X
129//    %Z = add int 1, %Y
130// into:
131//    %Z = add int 2, %X
132//
133FunctionPass *createInstructionCombiningPass(bool ExpensiveCombines = true);
134
135//===----------------------------------------------------------------------===//
136//
137// LICM - This pass is a loop invariant code motion and memory promotion pass.
138//
139Pass *createLICMPass();
140
141//===----------------------------------------------------------------------===//
142//
143// LoopInterchange - This pass interchanges loops to provide a more
144// cache-friendly memory access patterns.
145//
146Pass *createLoopInterchangePass();
147
148//===----------------------------------------------------------------------===//
149//
150// LoopStrengthReduce - This pass is strength reduces GEP instructions that use
151// a loop's canonical induction variable as one of their indices.
152//
153Pass *createLoopStrengthReducePass();
154
155//===----------------------------------------------------------------------===//
156//
157// LoopUnswitch - This pass is a simple loop unswitching pass.
158//
159Pass *createLoopUnswitchPass(bool OptimizeForSize = false);
160
161//===----------------------------------------------------------------------===//
162//
163// LoopInstSimplify - This pass simplifies instructions in a loop's body.
164//
165Pass *createLoopInstSimplifyPass();
166
167//===----------------------------------------------------------------------===//
168//
169// LoopUnroll - This pass is a simple loop unrolling pass.
170//
171Pass *createLoopUnrollPass(int Threshold = -1, int Count = -1,
172                           int AllowPartial = -1, int Runtime = -1);
173// Create an unrolling pass for full unrolling only.
174Pass *createSimpleLoopUnrollPass();
175
176//===----------------------------------------------------------------------===//
177//
178// LoopReroll - This pass is a simple loop rerolling pass.
179//
180Pass *createLoopRerollPass();
181
182//===----------------------------------------------------------------------===//
183//
184// LoopRotate - This pass is a simple loop rotating pass.
185//
186Pass *createLoopRotatePass(int MaxHeaderSize = -1);
187
188//===----------------------------------------------------------------------===//
189//
190// LoopIdiom - This pass recognizes and replaces idioms in loops.
191//
192Pass *createLoopIdiomPass();
193
194//===----------------------------------------------------------------------===//
195//
196// LoopVersioningLICM - This pass is a loop versioning pass for LICM.
197//
198Pass *createLoopVersioningLICMPass();
199
200//===----------------------------------------------------------------------===//
201//
202// PromoteMemoryToRegister - This pass is used to promote memory references to
203// be register references. A simple example of the transformation performed by
204// this pass is:
205//
206//        FROM CODE                           TO CODE
207//   %X = alloca i32, i32 1                 ret i32 42
208//   store i32 42, i32 *%X
209//   %Y = load i32* %X
210//   ret i32 %Y
211//
212FunctionPass *createPromoteMemoryToRegisterPass();
213
214//===----------------------------------------------------------------------===//
215//
216// DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
217// references. In basically undoes the PromoteMemoryToRegister pass to make cfg
218// hacking easier.
219//
220FunctionPass *createDemoteRegisterToMemoryPass();
221extern char &DemoteRegisterToMemoryID;
222
223//===----------------------------------------------------------------------===//
224//
225// Reassociate - This pass reassociates commutative expressions in an order that
226// is designed to promote better constant propagation, GCSE, LICM, PRE...
227//
228// For example:  4 + (x + 5)  ->  x + (4 + 5)
229//
230FunctionPass *createReassociatePass();
231
232//===----------------------------------------------------------------------===//
233//
234// JumpThreading - Thread control through mult-pred/multi-succ blocks where some
235// preds always go to some succ. Thresholds other than minus one override the
236// internal BB duplication default threshold.
237//
238FunctionPass *createJumpThreadingPass(int Threshold = -1);
239
240//===----------------------------------------------------------------------===//
241//
242// CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
243// simplify terminator instructions, etc...
244//
245FunctionPass *createCFGSimplificationPass(
246    int Threshold = -1, std::function<bool(const Function &)> Ftor = nullptr);
247
248//===----------------------------------------------------------------------===//
249//
250// FlattenCFG - flatten CFG, reduce number of conditional branches by using
251// parallel-and and parallel-or mode, etc...
252//
253FunctionPass *createFlattenCFGPass();
254
255//===----------------------------------------------------------------------===//
256//
257// CFG Structurization - Remove irreducible control flow
258//
259///
260/// When \p SkipUniformRegions is true the structizer will not structurize
261/// regions that only contain uniform branches.
262Pass *createStructurizeCFGPass(bool SkipUniformRegions = false);
263
264//===----------------------------------------------------------------------===//
265//
266// BreakCriticalEdges - Break all of the critical edges in the CFG by inserting
267// a dummy basic block. This pass may be "required" by passes that cannot deal
268// with critical edges. For this usage, a pass must call:
269//
270//   AU.addRequiredID(BreakCriticalEdgesID);
271//
272// This pass obviously invalidates the CFG, but can update forward dominator
273// (set, immediate dominators, tree, and frontier) information.
274//
275FunctionPass *createBreakCriticalEdgesPass();
276extern char &BreakCriticalEdgesID;
277
278//===----------------------------------------------------------------------===//
279//
280// LoopSimplify - Insert Pre-header blocks into the CFG for every function in
281// the module.  This pass updates dominator information, loop information, and
282// does not add critical edges to the CFG.
283//
284//   AU.addRequiredID(LoopSimplifyID);
285//
286Pass *createLoopSimplifyPass();
287extern char &LoopSimplifyID;
288
289//===----------------------------------------------------------------------===//
290//
291// TailCallElimination - This pass eliminates call instructions to the current
292// function which occur immediately before return instructions.
293//
294FunctionPass *createTailCallEliminationPass();
295
296//===----------------------------------------------------------------------===//
297//
298// LowerSwitch - This pass converts SwitchInst instructions into a sequence of
299// chained binary branch instructions.
300//
301FunctionPass *createLowerSwitchPass();
302extern char &LowerSwitchID;
303
304//===----------------------------------------------------------------------===//
305//
306// LowerInvoke - This pass removes invoke instructions, converting them to call
307// instructions.
308//
309FunctionPass *createLowerInvokePass();
310extern char &LowerInvokePassID;
311
312//===----------------------------------------------------------------------===//
313//
314// LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop
315// optimizations.
316//
317Pass *createLCSSAPass();
318extern char &LCSSAID;
319
320//===----------------------------------------------------------------------===//
321//
322// EarlyCSE - This pass performs a simple and fast CSE pass over the dominator
323// tree.
324//
325FunctionPass *createEarlyCSEPass();
326
327//===----------------------------------------------------------------------===//
328//
329// GVNHoist - This pass performs a simple and fast GVN pass over the dominator
330// tree to hoist common expressions from sibling branches.
331//
332FunctionPass *createGVNHoistPass();
333
334//===----------------------------------------------------------------------===//
335//
336// MergedLoadStoreMotion - This pass merges loads and stores in diamonds. Loads
337// are hoisted into the header, while stores sink into the footer.
338//
339FunctionPass *createMergedLoadStoreMotionPass();
340
341//===----------------------------------------------------------------------===//
342//
343// MemCpyOpt - This pass performs optimizations related to eliminating memcpy
344// calls and/or combining multiple stores into memset's.
345//
346FunctionPass *createMemCpyOptPass();
347
348//===----------------------------------------------------------------------===//
349//
350// LoopDeletion - This pass performs DCE of non-infinite loops that it
351// can prove are dead.
352//
353Pass *createLoopDeletionPass();
354
355//===----------------------------------------------------------------------===//
356//
357// ConstantHoisting - This pass prepares a function for expensive constants.
358//
359FunctionPass *createConstantHoistingPass();
360
361//===----------------------------------------------------------------------===//
362//
363// InstructionNamer - Give any unnamed non-void instructions "tmp" names.
364//
365FunctionPass *createInstructionNamerPass();
366extern char &InstructionNamerID;
367
368//===----------------------------------------------------------------------===//
369//
370// Sink - Code Sinking
371//
372FunctionPass *createSinkingPass();
373
374//===----------------------------------------------------------------------===//
375//
376// LowerAtomic - Lower atomic intrinsics to non-atomic form
377//
378Pass *createLowerAtomicPass();
379
380//===----------------------------------------------------------------------===//
381//
382// LowerGuardIntrinsic - Lower guard intrinsics to normal control flow.
383//
384Pass *createLowerGuardIntrinsicPass();
385
386//===----------------------------------------------------------------------===//
387//
388// ValuePropagation - Propagate CFG-derived value information
389//
390Pass *createCorrelatedValuePropagationPass();
391
392//===----------------------------------------------------------------------===//
393//
394// InstructionSimplifier - Remove redundant instructions.
395//
396FunctionPass *createInstructionSimplifierPass();
397extern char &InstructionSimplifierID;
398
399//===----------------------------------------------------------------------===//
400//
401// LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates
402// "block_weights" metadata.
403FunctionPass *createLowerExpectIntrinsicPass();
404
405//===----------------------------------------------------------------------===//
406//
407// PartiallyInlineLibCalls - Tries to inline the fast path of library
408// calls such as sqrt.
409//
410FunctionPass *createPartiallyInlineLibCallsPass();
411
412//===----------------------------------------------------------------------===//
413//
414// ScalarizerPass - Converts vector operations into scalar operations
415//
416FunctionPass *createScalarizerPass();
417
418//===----------------------------------------------------------------------===//
419//
420// AddDiscriminators - Add DWARF path discriminators to the IR.
421FunctionPass *createAddDiscriminatorsPass();
422
423//===----------------------------------------------------------------------===//
424//
425// SeparateConstOffsetFromGEP - Split GEPs for better CSE
426//
427FunctionPass *
428createSeparateConstOffsetFromGEPPass(const TargetMachine *TM = nullptr,
429                                     bool LowerGEP = false);
430
431//===----------------------------------------------------------------------===//
432//
433// SpeculativeExecution - Aggressively hoist instructions to enable
434// speculative execution on targets where branches are expensive.
435//
436FunctionPass *createSpeculativeExecutionPass();
437
438// Same as createSpeculativeExecutionPass, but does nothing unless
439// TargetTransformInfo::hasBranchDivergence() is true.
440FunctionPass *createSpeculativeExecutionIfHasBranchDivergencePass();
441
442//===----------------------------------------------------------------------===//
443//
444// LoadCombine - Combine loads into bigger loads.
445//
446BasicBlockPass *createLoadCombinePass();
447
448//===----------------------------------------------------------------------===//
449//
450// StraightLineStrengthReduce - This pass strength-reduces some certain
451// instruction patterns in straight-line code.
452//
453FunctionPass *createStraightLineStrengthReducePass();
454
455//===----------------------------------------------------------------------===//
456//
457// PlaceSafepoints - Rewrite any IR calls to gc.statepoints and insert any
458// safepoint polls (method entry, backedge) that might be required.  This pass
459// does not generate explicit relocation sequences - that's handled by
460// RewriteStatepointsForGC which can be run at an arbitrary point in the pass
461// order following this pass.
462//
463FunctionPass *createPlaceSafepointsPass();
464
465//===----------------------------------------------------------------------===//
466//
467// RewriteStatepointsForGC - Rewrite any gc.statepoints which do not yet have
468// explicit relocations to include explicit relocations.
469//
470ModulePass *createRewriteStatepointsForGCPass();
471
472//===----------------------------------------------------------------------===//
473//
474// Float2Int - Demote floats to ints where possible.
475//
476FunctionPass *createFloat2IntPass();
477
478//===----------------------------------------------------------------------===//
479//
480// NaryReassociate - Simplify n-ary operations by reassociation.
481//
482FunctionPass *createNaryReassociatePass();
483
484//===----------------------------------------------------------------------===//
485//
486// LoopDistribute - Distribute loops.
487//
488// ProcessAllLoopsByDefault instructs the pass to look for distribution
489// opportunities in all loops unless -enable-loop-distribute or the
490// llvm.loop.distribute.enable metadata data override this default.
491FunctionPass *createLoopDistributePass(bool ProcessAllLoopsByDefault);
492
493//===----------------------------------------------------------------------===//
494//
495// LoopLoadElimination - Perform loop-aware load elimination.
496//
497FunctionPass *createLoopLoadEliminationPass();
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// LoopVersioning - Perform loop multi-versioning.
509//
510FunctionPass *createLoopVersioningPass();
511
512//===----------------------------------------------------------------------===//
513//
514// LoopDataPrefetch - Perform data prefetching in loops.
515//
516FunctionPass *createLoopDataPrefetchPass();
517
518///===---------------------------------------------------------------------===//
519ModulePass *createNameAnonFunctionPass();
520
521} // End llvm namespace
522
523#endif
524