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