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