Scalar.h revision 9d6565a5b1fbc4286d6ee638d8f47a3171a9ed7e
1//===-- Scalar.h - Scalar Transformations -----------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source 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 <cstdlib>
19
20namespace llvm {
21
22class FunctionPass;
23class Pass;
24class GetElementPtrInst;
25class PassInfo;
26class TerminatorInst;
27class TargetLowering;
28
29//===----------------------------------------------------------------------===//
30//
31// ConstantPropagation - A worklist driven constant propagation pass
32//
33FunctionPass *createConstantPropagationPass();
34
35//===----------------------------------------------------------------------===//
36//
37// SCCP - Sparse conditional constant propagation.
38//
39FunctionPass *createSCCPPass();
40
41//===----------------------------------------------------------------------===//
42//
43// DeadInstElimination - This pass quickly removes trivially dead instructions
44// without modifying the CFG of the function.  It is a BasicBlockPass, so it
45// runs efficiently when queued next to other BasicBlockPass's.
46//
47Pass *createDeadInstEliminationPass();
48
49//===----------------------------------------------------------------------===//
50//
51// DeadCodeElimination - This pass is more powerful than DeadInstElimination,
52// because it is worklist driven that can potentially revisit instructions when
53// their other instructions become dead, to eliminate chains of dead
54// computations.
55//
56FunctionPass *createDeadCodeEliminationPass();
57
58//===----------------------------------------------------------------------===//
59//
60// DeadStoreElimination - This pass deletes stores that are post-dominated by
61// must-aliased stores and are not loaded used between the stores.
62//
63FunctionPass *createDeadStoreEliminationPass();
64
65//===----------------------------------------------------------------------===//
66//
67// AggressiveDCE - This pass uses the SSA based Aggressive DCE algorithm.  This
68// algorithm assumes instructions are dead until proven otherwise, which makes
69// it more successful are removing non-obviously dead instructions.
70//
71FunctionPass *createAggressiveDCEPass();
72
73//===----------------------------------------------------------------------===//
74//
75// ScalarReplAggregates - Break up alloca's of aggregates into multiple allocas
76// if possible.
77//
78FunctionPass *createScalarReplAggregatesPass();
79
80//===----------------------------------------------------------------------===//
81//
82// GCSE - This pass is designed to be a very quick global transformation that
83// eliminates global common subexpressions from a function.  It does this by
84// examining the SSA value graph of the function, instead of doing slow
85// bit-vector computations.
86//
87FunctionPass *createGCSEPass();
88
89//===----------------------------------------------------------------------===//
90//
91// InductionVariableSimplify - Transform induction variables in a program to all
92// use a single canonical induction variable per loop.
93//
94FunctionPass *createIndVarSimplifyPass();
95
96//===----------------------------------------------------------------------===//
97//
98// InstructionCombining - Combine instructions to form fewer, simple
99// instructions. This pass does not modify the CFG, and has a tendency to make
100// instructions dead, so a subsequent DCE pass is useful.
101//
102// This pass combines things like:
103//    %Y = add int 1, %X
104//    %Z = add int 1, %Y
105// into:
106//    %Z = add int 2, %X
107//
108FunctionPass *createInstructionCombiningPass();
109
110//===----------------------------------------------------------------------===//
111//
112// LICM - This pass is a loop invariant code motion and memory promotion pass.
113//
114FunctionPass *createLICMPass();
115
116//===----------------------------------------------------------------------===//
117//
118// LoopStrengthReduce - This pass is strength reduces GEP instructions that use
119// a loop's canonical induction variable as one of their indices.  It takes an
120// optional parameter used to consult the target machine whether certain
121// transformations are profitable.
122//
123FunctionPass *createLoopStrengthReducePass(const TargetLowering *TLI = NULL);
124
125//===----------------------------------------------------------------------===//
126//
127// LoopUnswitch - This pass is a simple loop unswitching pass.
128//
129FunctionPass *createLoopUnswitchPass();
130
131//===----------------------------------------------------------------------===//
132//
133// LoopUnroll - This pass is a simple loop unrolling pass.
134//
135FunctionPass *createLoopUnrollPass();
136
137//===----------------------------------------------------------------------===//
138//
139// PromoteMemoryToRegister - This pass is used to promote memory references to
140// be register references. A simple example of the transformation performed by
141// this pass is:
142//
143//        FROM CODE                           TO CODE
144//   %X = alloca int, uint 1                 ret int 42
145//   store int 42, int *%X
146//   %Y = load int* %X
147//   ret int %Y
148//
149FunctionPass *createPromoteMemoryToRegisterPass();
150extern const PassInfo *PromoteMemoryToRegisterID;
151
152//===----------------------------------------------------------------------===//
153//
154// DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
155// references. In basically undoes the PromoteMemoryToRegister pass to make cfg
156// hacking easier.
157//
158FunctionPass *createDemoteRegisterToMemoryPass();
159extern const PassInfo *DemoteRegisterToMemoryID;
160
161//===----------------------------------------------------------------------===//
162//
163// Reassociate - This pass reassociates commutative expressions in an order that
164// is designed to promote better constant propagation, GCSE, LICM, PRE...
165//
166// For example:  4 + (x + 5)  ->  x + (4 + 5)
167//
168FunctionPass *createReassociatePass();
169
170//===----------------------------------------------------------------------===//
171//
172// CorrelatedExpressionElimination - This pass eliminates correlated
173// conditions, such as these:
174//  if (X == 0)
175//    if (X > 2) ;   // Known false
176//    else
177//      Y = X * Z;   // = 0
178//
179FunctionPass *createCorrelatedExpressionEliminationPass();
180
181//===----------------------------------------------------------------------===//
182//
183// CondPropagationPass - This pass propagates information about conditional
184// expressions through the program, allowing it to eliminate conditional
185// branches in some cases.
186//
187FunctionPass *createCondPropagationPass();
188
189//===----------------------------------------------------------------------===//
190//
191// TailDuplication - Eliminate unconditional branches through controlled code
192// duplication, creating simpler CFG structures.
193//
194FunctionPass *createTailDuplicationPass();
195
196//===----------------------------------------------------------------------===//
197//
198// CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
199// simplify terminator instructions, etc...
200//
201FunctionPass *createCFGSimplificationPass();
202
203//===----------------------------------------------------------------------===//
204//
205// BreakCriticalEdges - Break all of the critical edges in the CFG by inserting
206// a dummy basic block. This pass may be "required" by passes that cannot deal
207// with critical edges. For this usage, a pass must call:
208//
209//   AU.addRequiredID(BreakCriticalEdgesID);
210//
211// This pass obviously invalidates the CFG, but can update forward dominator
212// (set, immediate dominators, tree, and frontier) information.
213//
214FunctionPass *createBreakCriticalEdgesPass();
215extern const PassInfo *BreakCriticalEdgesID;
216
217//===----------------------------------------------------------------------===//
218//
219// LoopSimplify - Insert Pre-header blocks into the CFG for every function in
220// the module.  This pass updates dominator information, loop information, and
221// does not add critical edges to the CFG.
222//
223//   AU.addRequiredID(LoopSimplifyID);
224//
225FunctionPass *createLoopSimplifyPass();
226extern const PassInfo *LoopSimplifyID;
227
228//===----------------------------------------------------------------------===//
229//
230// LowerSelect - This pass converts SelectInst instructions into conditional
231// branch and PHI instructions. If the OnlyFP flag is set to true, then only
232// floating point select instructions are lowered.
233//
234FunctionPass *createLowerSelectPass(bool OnlyFP = false);
235extern const PassInfo *LowerSelectID;
236
237//===----------------------------------------------------------------------===//
238//
239// LowerAllocations - Turn malloc and free instructions into %malloc and %free
240// calls.
241//
242//   AU.addRequiredID(LowerAllocationsID);
243//
244Pass *createLowerAllocationsPass(bool LowerMallocArgToInteger = false);
245extern const PassInfo *LowerAllocationsID;
246
247//===----------------------------------------------------------------------===//
248//
249// TailCallElimination - This pass eliminates call instructions to the current
250// function which occur immediately before return instructions.
251//
252FunctionPass *createTailCallEliminationPass();
253
254//===----------------------------------------------------------------------===//
255//
256// LowerSwitch - This pass converts SwitchInst instructions into a sequence of
257// chained binary branch instructions.
258//
259FunctionPass *createLowerSwitchPass();
260extern const PassInfo *LowerSwitchID;
261
262//===----------------------------------------------------------------------===//
263//
264// LowerPacked - This pass converts VectorType operations into low-level scalar
265// operations.
266//
267FunctionPass *createLowerPackedPass();
268
269//===----------------------------------------------------------------------===//
270//
271// LowerInvoke - This pass converts invoke and unwind instructions to use sjlj
272// exception handling mechanisms.  Note that after this pass runs the CFG is not
273// entirely accurate (exceptional control flow edges are not correct anymore) so
274// only very simple things should be done after the lowerinvoke pass has run
275// (like generation of native code).  This should *NOT* be used as a general
276// purpose "my LLVM-to-LLVM pass doesn't support the invoke instruction yet"
277// lowering pass.
278//
279FunctionPass *createLowerInvokePass(const TargetLowering *TLI = NULL);
280extern const PassInfo *LowerInvokePassID;
281
282//===----------------------------------------------------------------------===//
283//
284// LowerGCPass - This function returns an instance of the "lowergc" pass, which
285// lowers garbage collection intrinsics to normal LLVM code.
286//
287FunctionPass *createLowerGCPass();
288
289//===----------------------------------------------------------------------===//
290//
291// BlockPlacement - This pass reorders basic blocks in order to increase the
292// number of fall-through conditional branches.
293//
294FunctionPass *createBlockPlacementPass();
295
296//===----------------------------------------------------------------------===//
297//
298// LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop
299// optimizations.
300//
301FunctionPass *createLCSSAPass();
302extern const PassInfo *LCSSAID;
303
304//===----------------------------------------------------------------------===//
305//
306// PredicateSimplifier - This pass collapses duplicate variables into one
307// canonical form, and tries to simplify expressions along the way.
308//
309FunctionPass *createPredicateSimplifierPass();
310
311} // End llvm namespace
312
313#endif
314