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