[BDCE] Add a bit-tracking DCE pass
[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 // LoopStrengthReduce - This pass is strength reduces GEP instructions that use
144 // a loop's canonical induction variable as one of their indices.
145 //
146 Pass *createLoopStrengthReducePass();
147
148 Pass *createGlobalMergePass(const TargetMachine *TM = nullptr);
149
150 //===----------------------------------------------------------------------===//
151 //
152 // LoopUnswitch - This pass is a simple loop unswitching pass.
153 //
154 Pass *createLoopUnswitchPass(bool OptimizeForSize = false);
155
156 //===----------------------------------------------------------------------===//
157 //
158 // LoopInstSimplify - This pass simplifies instructions in a loop's body.
159 //
160 Pass *createLoopInstSimplifyPass();
161
162 //===----------------------------------------------------------------------===//
163 //
164 // LoopUnroll - This pass is a simple loop unrolling pass.
165 //
166 Pass *createLoopUnrollPass(int Threshold = -1, int Count = -1,
167                            int AllowPartial = -1, int Runtime = -1);
168 // Create an unrolling pass for full unrolling only.
169 Pass *createSimpleLoopUnrollPass();
170
171 //===----------------------------------------------------------------------===//
172 //
173 // LoopReroll - This pass is a simple loop rerolling pass.
174 //
175 Pass *createLoopRerollPass();
176
177 //===----------------------------------------------------------------------===//
178 //
179 // LoopRotate - This pass is a simple loop rotating pass.
180 //
181 Pass *createLoopRotatePass(int MaxHeaderSize = -1);
182
183 //===----------------------------------------------------------------------===//
184 //
185 // LoopIdiom - This pass recognizes and replaces idioms in loops.
186 //
187 Pass *createLoopIdiomPass();
188
189 //===----------------------------------------------------------------------===//
190 //
191 // PromoteMemoryToRegister - This pass is used to promote memory references to
192 // be register references. A simple example of the transformation performed by
193 // this pass is:
194 //
195 //        FROM CODE                           TO CODE
196 //   %X = alloca i32, i32 1                 ret i32 42
197 //   store i32 42, i32 *%X
198 //   %Y = load i32* %X
199 //   ret i32 %Y
200 //
201 FunctionPass *createPromoteMemoryToRegisterPass();
202
203 //===----------------------------------------------------------------------===//
204 //
205 // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
206 // references. In basically undoes the PromoteMemoryToRegister pass to make cfg
207 // hacking easier.
208 //
209 FunctionPass *createDemoteRegisterToMemoryPass();
210 extern char &DemoteRegisterToMemoryID;
211
212 //===----------------------------------------------------------------------===//
213 //
214 // Reassociate - This pass reassociates commutative expressions in an order that
215 // is designed to promote better constant propagation, GCSE, LICM, PRE...
216 //
217 // For example:  4 + (x + 5)  ->  x + (4 + 5)
218 //
219 FunctionPass *createReassociatePass();
220
221 //===----------------------------------------------------------------------===//
222 //
223 // JumpThreading - Thread control through mult-pred/multi-succ blocks where some
224 // preds always go to some succ. Thresholds other than minus one override the
225 // internal BB duplication default threshold.
226 //
227 FunctionPass *createJumpThreadingPass(int Threshold = -1);
228
229 //===----------------------------------------------------------------------===//
230 //
231 // CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
232 // simplify terminator instructions, etc...
233 //
234 FunctionPass *createCFGSimplificationPass(int Threshold = -1);
235
236 //===----------------------------------------------------------------------===//
237 //
238 // FlattenCFG - flatten CFG, reduce number of conditional branches by using
239 // parallel-and and parallel-or mode, etc...
240 //
241 FunctionPass *createFlattenCFGPass();
242
243 //===----------------------------------------------------------------------===//
244 //
245 // CFG Structurization - Remove irreducible control flow
246 //
247 Pass *createStructurizeCFGPass();
248
249 //===----------------------------------------------------------------------===//
250 //
251 // BreakCriticalEdges - Break all of the critical edges in the CFG by inserting
252 // a dummy basic block. This pass may be "required" by passes that cannot deal
253 // with critical edges. For this usage, a pass must call:
254 //
255 //   AU.addRequiredID(BreakCriticalEdgesID);
256 //
257 // This pass obviously invalidates the CFG, but can update forward dominator
258 // (set, immediate dominators, tree, and frontier) information.
259 //
260 FunctionPass *createBreakCriticalEdgesPass();
261 extern char &BreakCriticalEdgesID;
262
263 //===----------------------------------------------------------------------===//
264 //
265 // LoopSimplify - Insert Pre-header blocks into the CFG for every function in
266 // the module.  This pass updates dominator information, loop information, and
267 // does not add critical edges to the CFG.
268 //
269 //   AU.addRequiredID(LoopSimplifyID);
270 //
271 Pass *createLoopSimplifyPass();
272 extern char &LoopSimplifyID;
273
274 //===----------------------------------------------------------------------===//
275 //
276 // TailCallElimination - This pass eliminates call instructions to the current
277 // function which occur immediately before return instructions.
278 //
279 FunctionPass *createTailCallEliminationPass();
280
281 //===----------------------------------------------------------------------===//
282 //
283 // LowerSwitch - This pass converts SwitchInst instructions into a sequence of
284 // chained binary branch instructions.
285 //
286 FunctionPass *createLowerSwitchPass();
287 extern char &LowerSwitchID;
288
289 //===----------------------------------------------------------------------===//
290 //
291 // LowerInvoke - This pass removes invoke instructions, converting them to call
292 // instructions.
293 //
294 FunctionPass *createLowerInvokePass();
295 extern char &LowerInvokePassID;
296
297 //===----------------------------------------------------------------------===//
298 //
299 // LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop
300 // optimizations.
301 //
302 Pass *createLCSSAPass();
303 extern char &LCSSAID;
304
305 //===----------------------------------------------------------------------===//
306 //
307 // EarlyCSE - This pass performs a simple and fast CSE pass over the dominator
308 // tree.
309 //
310 FunctionPass *createEarlyCSEPass();
311
312 //===----------------------------------------------------------------------===//
313 //
314 // MergedLoadStoreMotion - This pass merges loads and stores in diamonds. Loads
315 // are hoisted into the header, while stores sink into the footer.
316 //
317 FunctionPass *createMergedLoadStoreMotionPass();
318
319 //===----------------------------------------------------------------------===//
320 //
321 // GVN - This pass performs global value numbering and redundant load
322 // elimination cotemporaneously.
323 //
324 FunctionPass *createGVNPass(bool NoLoads = false);
325
326 //===----------------------------------------------------------------------===//
327 //
328 // MemCpyOpt - This pass performs optimizations related to eliminating memcpy
329 // calls and/or combining multiple stores into memset's.
330 //
331 FunctionPass *createMemCpyOptPass();
332
333 //===----------------------------------------------------------------------===//
334 //
335 // LoopDeletion - This pass performs DCE of non-infinite loops that it
336 // can prove are dead.
337 //
338 Pass *createLoopDeletionPass();
339
340 //===----------------------------------------------------------------------===//
341 //
342 // ConstantHoisting - This pass prepares a function for expensive constants.
343 //
344 FunctionPass *createConstantHoistingPass();
345
346 //===----------------------------------------------------------------------===//
347 //
348 // InstructionNamer - Give any unnamed non-void instructions "tmp" names.
349 //
350 FunctionPass *createInstructionNamerPass();
351 extern char &InstructionNamerID;
352
353 //===----------------------------------------------------------------------===//
354 //
355 // Sink - Code Sinking
356 //
357 FunctionPass *createSinkingPass();
358
359 //===----------------------------------------------------------------------===//
360 //
361 // LowerAtomic - Lower atomic intrinsics to non-atomic form
362 //
363 Pass *createLowerAtomicPass();
364
365 //===----------------------------------------------------------------------===//
366 //
367 // ValuePropagation - Propagate CFG-derived value information
368 //
369 Pass *createCorrelatedValuePropagationPass();
370
371 //===----------------------------------------------------------------------===//
372 //
373 // InstructionSimplifier - Remove redundant instructions.
374 //
375 FunctionPass *createInstructionSimplifierPass();
376 extern char &InstructionSimplifierID;
377
378 //===----------------------------------------------------------------------===//
379 //
380 // LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates
381 // "block_weights" metadata.
382 FunctionPass *createLowerExpectIntrinsicPass();
383
384 //===----------------------------------------------------------------------===//
385 //
386 // PartiallyInlineLibCalls - Tries to inline the fast path of library
387 // calls such as sqrt.
388 //
389 FunctionPass *createPartiallyInlineLibCallsPass();
390
391 //===----------------------------------------------------------------------===//
392 //
393 // SampleProfilePass - Loads sample profile data from disk and generates
394 // IR metadata to reflect the profile.
395 FunctionPass *createSampleProfileLoaderPass();
396 FunctionPass *createSampleProfileLoaderPass(StringRef Name);
397
398 //===----------------------------------------------------------------------===//
399 //
400 // ScalarizerPass - Converts vector operations into scalar operations
401 //
402 FunctionPass *createScalarizerPass();
403
404 //===----------------------------------------------------------------------===//
405 //
406 // AddDiscriminators - Add DWARF path discriminators to the IR.
407 FunctionPass *createAddDiscriminatorsPass();
408
409 //===----------------------------------------------------------------------===//
410 //
411 // SeparateConstOffsetFromGEP - Split GEPs for better CSE
412 //
413 FunctionPass *
414 createSeparateConstOffsetFromGEPPass(const TargetMachine *TM = nullptr,
415                                      bool LowerGEP = false);
416
417 //===----------------------------------------------------------------------===//
418 //
419 // LoadCombine - Combine loads into bigger loads.
420 //
421 BasicBlockPass *createLoadCombinePass();
422
423 FunctionPass *createStraightLineStrengthReducePass();
424
425
426 //===----------------------------------------------------------------------===//
427 //
428 // PlaceSafepoints - Rewrite any IR calls to gc.statepoints and insert any
429 // safepoint polls (method entry, backedge) that might be required.  This pass
430 // does not generate explicit relocation sequences - that's handled by
431 // RewriteStatepointsForGC which can be run at an arbitrary point in the pass
432 // order following this pass.
433 //
434 ModulePass *createPlaceSafepointsPass();
435
436 } // End llvm namespace
437
438 #endif