Scalar.h revision 261991
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
20namespace llvm {
21
22class FunctionPass;
23class Pass;
24class GetElementPtrInst;
25class PassInfo;
26class TerminatorInst;
27class TargetLowering;
28class TargetMachine;
29
30//===----------------------------------------------------------------------===//
31//
32// ConstantPropagation - A worklist driven constant propagation pass
33//
34FunctionPass *createConstantPropagationPass();
35
36//===----------------------------------------------------------------------===//
37//
38// SCCP - Sparse conditional constant propagation.
39//
40FunctionPass *createSCCPPass();
41
42//===----------------------------------------------------------------------===//
43//
44// DeadInstElimination - This pass quickly removes trivially dead instructions
45// without modifying the CFG of the function.  It is a BasicBlockPass, so it
46// runs efficiently when queued next to other BasicBlockPass's.
47//
48Pass *createDeadInstEliminationPass();
49
50//===----------------------------------------------------------------------===//
51//
52// DeadCodeElimination - This pass is more powerful than DeadInstElimination,
53// because it is worklist driven that can potentially revisit instructions when
54// their other instructions become dead, to eliminate chains of dead
55// computations.
56//
57FunctionPass *createDeadCodeEliminationPass();
58
59//===----------------------------------------------------------------------===//
60//
61// DeadStoreElimination - This pass deletes stores that are post-dominated by
62// must-aliased stores and are not loaded used between the stores.
63//
64FunctionPass *createDeadStoreEliminationPass();
65
66//===----------------------------------------------------------------------===//
67//
68// AggressiveDCE - This pass uses the SSA based Aggressive DCE algorithm.  This
69// algorithm assumes instructions are dead until proven otherwise, which makes
70// it more successful are removing non-obviously dead instructions.
71//
72FunctionPass *createAggressiveDCEPass();
73
74//===----------------------------------------------------------------------===//
75//
76// SROA - Replace aggregates or pieces of aggregates with scalar SSA values.
77//
78FunctionPass *createSROAPass(bool RequiresDomTree = true);
79
80//===----------------------------------------------------------------------===//
81//
82// ScalarReplAggregates - Break up alloca's of aggregates into multiple allocas
83// if possible.
84//
85FunctionPass *createScalarReplAggregatesPass(signed Threshold = -1,
86                                             bool UseDomTree = true,
87                                             signed StructMemberThreshold = -1,
88                                             signed ArrayElementThreshold = -1,
89                                             signed ScalarLoadThreshold = -1);
90
91//===----------------------------------------------------------------------===//
92//
93// InductionVariableSimplify - Transform induction variables in a program to all
94// use a single canonical induction variable per loop.
95//
96Pass *createIndVarSimplifyPass();
97
98//===----------------------------------------------------------------------===//
99//
100// InstructionCombining - Combine instructions to form fewer, simple
101// instructions. This pass does not modify the CFG, and has a tendency to make
102// instructions dead, so a subsequent DCE pass is useful.
103//
104// This pass combines things like:
105//    %Y = add int 1, %X
106//    %Z = add int 1, %Y
107// into:
108//    %Z = add int 2, %X
109//
110FunctionPass *createInstructionCombiningPass();
111
112//===----------------------------------------------------------------------===//
113//
114// LICM - This pass is a loop invariant code motion and memory promotion pass.
115//
116Pass *createLICMPass();
117
118//===----------------------------------------------------------------------===//
119//
120// LoopStrengthReduce - This pass is strength reduces GEP instructions that use
121// a loop's canonical induction variable as one of their indices.
122//
123Pass *createLoopStrengthReducePass();
124
125Pass *createGlobalMergePass(const TargetMachine *TM = 0);
126
127//===----------------------------------------------------------------------===//
128//
129// LoopUnswitch - This pass is a simple loop unswitching pass.
130//
131Pass *createLoopUnswitchPass(bool OptimizeForSize = false);
132
133//===----------------------------------------------------------------------===//
134//
135// LoopInstSimplify - This pass simplifies instructions in a loop's body.
136//
137Pass *createLoopInstSimplifyPass();
138
139//===----------------------------------------------------------------------===//
140//
141// LoopUnroll - This pass is a simple loop unrolling pass.
142//
143Pass *createLoopUnrollPass(int Threshold = -1, int Count = -1,
144                           int AllowPartial = -1, int Runtime = -1);
145
146//===----------------------------------------------------------------------===//
147//
148// LoopReroll - This pass is a simple loop rerolling pass.
149//
150Pass *createLoopRerollPass();
151
152//===----------------------------------------------------------------------===//
153//
154// LoopRotate - This pass is a simple loop rotating pass.
155//
156Pass *createLoopRotatePass();
157
158//===----------------------------------------------------------------------===//
159//
160// LoopIdiom - This pass recognizes and replaces idioms in loops.
161//
162Pass *createLoopIdiomPass();
163
164//===----------------------------------------------------------------------===//
165//
166// PromoteMemoryToRegister - This pass is used to promote memory references to
167// be register references. A simple example of the transformation performed by
168// this pass is:
169//
170//        FROM CODE                           TO CODE
171//   %X = alloca i32, i32 1                 ret i32 42
172//   store i32 42, i32 *%X
173//   %Y = load i32* %X
174//   ret i32 %Y
175//
176FunctionPass *createPromoteMemoryToRegisterPass();
177
178//===----------------------------------------------------------------------===//
179//
180// DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
181// references. In basically undoes the PromoteMemoryToRegister pass to make cfg
182// hacking easier.
183//
184FunctionPass *createDemoteRegisterToMemoryPass();
185extern char &DemoteRegisterToMemoryID;
186
187//===----------------------------------------------------------------------===//
188//
189// Reassociate - This pass reassociates commutative expressions in an order that
190// is designed to promote better constant propagation, GCSE, LICM, PRE...
191//
192// For example:  4 + (x + 5)  ->  x + (4 + 5)
193//
194FunctionPass *createReassociatePass();
195
196//===----------------------------------------------------------------------===//
197//
198// JumpThreading - Thread control through mult-pred/multi-succ blocks where some
199// preds always go to some succ.
200//
201FunctionPass *createJumpThreadingPass();
202
203//===----------------------------------------------------------------------===//
204//
205// CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
206// simplify terminator instructions, etc...
207//
208FunctionPass *createCFGSimplificationPass();
209
210//===----------------------------------------------------------------------===//
211//
212// FlattenCFG - flatten CFG, reduce number of conditional branches by using
213// parallel-and and parallel-or mode, etc...
214//
215FunctionPass *createFlattenCFGPass();
216
217//===----------------------------------------------------------------------===//
218//
219// CFG Structurization - Remove irreducible control flow
220//
221Pass *createStructurizeCFGPass();
222
223//===----------------------------------------------------------------------===//
224//
225// BreakCriticalEdges - Break all of the critical edges in the CFG by inserting
226// a dummy basic block. This pass may be "required" by passes that cannot deal
227// with critical edges. For this usage, a pass must call:
228//
229//   AU.addRequiredID(BreakCriticalEdgesID);
230//
231// This pass obviously invalidates the CFG, but can update forward dominator
232// (set, immediate dominators, tree, and frontier) information.
233//
234FunctionPass *createBreakCriticalEdgesPass();
235extern char &BreakCriticalEdgesID;
236
237//===----------------------------------------------------------------------===//
238//
239// LoopSimplify - Insert Pre-header blocks into the CFG for every function in
240// the module.  This pass updates dominator information, loop information, and
241// does not add critical edges to the CFG.
242//
243//   AU.addRequiredID(LoopSimplifyID);
244//
245Pass *createLoopSimplifyPass();
246extern char &LoopSimplifyID;
247
248//===----------------------------------------------------------------------===//
249//
250// TailCallElimination - This pass eliminates call instructions to the current
251// function which occur immediately before return instructions.
252//
253FunctionPass *createTailCallEliminationPass();
254
255//===----------------------------------------------------------------------===//
256//
257// LowerSwitch - This pass converts SwitchInst instructions into a sequence of
258// chained binary branch instructions.
259//
260FunctionPass *createLowerSwitchPass();
261extern char &LowerSwitchID;
262
263//===----------------------------------------------------------------------===//
264//
265// LowerInvoke - This pass converts invoke and unwind instructions to use sjlj
266// exception handling mechanisms.  Note that after this pass runs the CFG is not
267// entirely accurate (exceptional control flow edges are not correct anymore) so
268// only very simple things should be done after the lowerinvoke pass has run
269// (like generation of native code).  This should *NOT* be used as a general
270// purpose "my LLVM-to-LLVM pass doesn't support the invoke instruction yet"
271// lowering pass.
272//
273FunctionPass *createLowerInvokePass(const TargetMachine *TM = 0,
274                                    bool useExpensiveEHSupport = false);
275extern char &LowerInvokePassID;
276
277//===----------------------------------------------------------------------===//
278//
279// LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop
280// optimizations.
281//
282Pass *createLCSSAPass();
283extern char &LCSSAID;
284
285//===----------------------------------------------------------------------===//
286//
287// EarlyCSE - This pass performs a simple and fast CSE pass over the dominator
288// tree.
289//
290FunctionPass *createEarlyCSEPass();
291
292//===----------------------------------------------------------------------===//
293//
294// GVN - This pass performs global value numbering and redundant load
295// elimination cotemporaneously.
296//
297FunctionPass *createGVNPass(bool NoLoads = false);
298
299//===----------------------------------------------------------------------===//
300//
301// MemCpyOpt - This pass performs optimizations related to eliminating memcpy
302// calls and/or combining multiple stores into memset's.
303//
304FunctionPass *createMemCpyOptPass();
305
306//===----------------------------------------------------------------------===//
307//
308// LoopDeletion - This pass performs DCE of non-infinite loops that it
309// can prove are dead.
310//
311Pass *createLoopDeletionPass();
312
313//===----------------------------------------------------------------------===//
314//
315// CodeGenPrepare - This pass prepares a function for instruction selection.
316//
317FunctionPass *createCodeGenPreparePass(const TargetMachine *TM = 0);
318
319//===----------------------------------------------------------------------===//
320//
321// InstructionNamer - Give any unnamed non-void instructions "tmp" names.
322//
323FunctionPass *createInstructionNamerPass();
324extern char &InstructionNamerID;
325
326//===----------------------------------------------------------------------===//
327//
328// Sink - Code Sinking
329//
330FunctionPass *createSinkingPass();
331
332//===----------------------------------------------------------------------===//
333//
334// LowerAtomic - Lower atomic intrinsics to non-atomic form
335//
336Pass *createLowerAtomicPass();
337
338//===----------------------------------------------------------------------===//
339//
340// ValuePropagation - Propagate CFG-derived value information
341//
342Pass *createCorrelatedValuePropagationPass();
343
344//===----------------------------------------------------------------------===//
345//
346// InstructionSimplifier - Remove redundant instructions.
347//
348FunctionPass *createInstructionSimplifierPass();
349extern char &InstructionSimplifierID;
350
351
352//===----------------------------------------------------------------------===//
353//
354// LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates
355// "block_weights" metadata.
356FunctionPass *createLowerExpectIntrinsicPass();
357
358
359//===----------------------------------------------------------------------===//
360//
361// PartiallyInlineLibCalls - Tries to inline the fast path of library
362// calls such as sqrt.
363//
364FunctionPass *createPartiallyInlineLibCallsPass();
365
366//===----------------------------------------------------------------------===//
367//
368// SampleProfilePass - Loads sample profile data from disk and generates
369// IR metadata to reflect the profile.
370FunctionPass *createSampleProfileLoaderPass();
371FunctionPass *createSampleProfileLoaderPass(StringRef Name);
372
373} // End llvm namespace
374
375#endif
376