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