1 //===-- Scalar.h - Scalar Transformations -----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This header file defines prototypes for accessor functions that expose passes
11 // in the Scalar transformations library.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_TRANSFORMS_SCALAR_H
16 #define LLVM_TRANSFORMS_SCALAR_H
18 #include "llvm/ADT/StringRef.h"
26 class GetElementPtrInst;
32 //===----------------------------------------------------------------------===//
34 // ConstantPropagation - A worklist driven constant propagation pass
36 FunctionPass *createConstantPropagationPass();
38 //===----------------------------------------------------------------------===//
40 // AlignmentFromAssumptions - Use assume intrinsics to set load/store
43 FunctionPass *createAlignmentFromAssumptionsPass();
45 //===----------------------------------------------------------------------===//
47 // SCCP - Sparse conditional constant propagation.
49 FunctionPass *createSCCPPass();
51 //===----------------------------------------------------------------------===//
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.
57 Pass *createDeadInstEliminationPass();
59 //===----------------------------------------------------------------------===//
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
66 FunctionPass *createDeadCodeEliminationPass();
68 //===----------------------------------------------------------------------===//
70 // DeadStoreElimination - This pass deletes stores that are post-dominated by
71 // must-aliased stores and are not loaded used between the stores.
73 FunctionPass *createDeadStoreEliminationPass();
75 //===----------------------------------------------------------------------===//
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.
81 FunctionPass *createAggressiveDCEPass();
83 //===----------------------------------------------------------------------===//
85 // BitTrackingDCE - This pass uses a bit-tracking DCE algorithm in order to
86 // remove computations of dead bits.
88 FunctionPass *createBitTrackingDCEPass();
90 //===----------------------------------------------------------------------===//
92 // SROA - Replace aggregates or pieces of aggregates with scalar SSA values.
94 FunctionPass *createSROAPass(bool RequiresDomTree = true);
96 //===----------------------------------------------------------------------===//
98 // ScalarReplAggregates - Break up alloca's of aggregates into multiple allocas
101 FunctionPass *createScalarReplAggregatesPass(signed Threshold = -1,
102 bool UseDomTree = true,
103 signed StructMemberThreshold = -1,
104 signed ArrayElementThreshold = -1,
105 signed ScalarLoadThreshold = -1);
107 //===----------------------------------------------------------------------===//
109 // InductiveRangeCheckElimination - Transform loops to elide range checks on
110 // linear functions of the induction variable.
112 Pass *createInductiveRangeCheckEliminationPass();
114 //===----------------------------------------------------------------------===//
116 // InductionVariableSimplify - Transform induction variables in a program to all
117 // use a single canonical induction variable per loop.
119 Pass *createIndVarSimplifyPass();
121 //===----------------------------------------------------------------------===//
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.
127 // This pass combines things like:
128 // %Y = add int 1, %X
129 // %Z = add int 1, %Y
131 // %Z = add int 2, %X
133 FunctionPass *createInstructionCombiningPass();
135 //===----------------------------------------------------------------------===//
137 // LICM - This pass is a loop invariant code motion and memory promotion pass.
139 Pass *createLICMPass();
141 //===----------------------------------------------------------------------===//
143 // LoopInterchange - This pass interchanges loops to provide a more
144 // cache-friendly memory access patterns.
146 Pass *createLoopInterchangePass();
148 //===----------------------------------------------------------------------===//
150 // LoopStrengthReduce - This pass is strength reduces GEP instructions that use
151 // a loop's canonical induction variable as one of their indices.
153 Pass *createLoopStrengthReducePass();
155 Pass *createGlobalMergePass(const TargetMachine *TM, unsigned MaximalOffset);
157 //===----------------------------------------------------------------------===//
159 // LoopUnswitch - This pass is a simple loop unswitching pass.
161 Pass *createLoopUnswitchPass(bool OptimizeForSize = false);
163 //===----------------------------------------------------------------------===//
165 // LoopInstSimplify - This pass simplifies instructions in a loop's body.
167 Pass *createLoopInstSimplifyPass();
169 //===----------------------------------------------------------------------===//
171 // LoopUnroll - This pass is a simple loop unrolling pass.
173 Pass *createLoopUnrollPass(int Threshold = -1, int Count = -1,
174 int AllowPartial = -1, int Runtime = -1);
175 // Create an unrolling pass for full unrolling only.
176 Pass *createSimpleLoopUnrollPass();
178 //===----------------------------------------------------------------------===//
180 // LoopReroll - This pass is a simple loop rerolling pass.
182 Pass *createLoopRerollPass();
184 //===----------------------------------------------------------------------===//
186 // LoopRotate - This pass is a simple loop rotating pass.
188 Pass *createLoopRotatePass(int MaxHeaderSize = -1);
190 //===----------------------------------------------------------------------===//
192 // LoopIdiom - This pass recognizes and replaces idioms in loops.
194 Pass *createLoopIdiomPass();
196 //===----------------------------------------------------------------------===//
198 // PromoteMemoryToRegister - This pass is used to promote memory references to
199 // be register references. A simple example of the transformation performed by
203 // %X = alloca i32, i32 1 ret i32 42
204 // store i32 42, i32 *%X
208 FunctionPass *createPromoteMemoryToRegisterPass();
210 //===----------------------------------------------------------------------===//
212 // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
213 // references. In basically undoes the PromoteMemoryToRegister pass to make cfg
216 FunctionPass *createDemoteRegisterToMemoryPass();
217 extern char &DemoteRegisterToMemoryID;
219 //===----------------------------------------------------------------------===//
221 // Reassociate - This pass reassociates commutative expressions in an order that
222 // is designed to promote better constant propagation, GCSE, LICM, PRE...
224 // For example: 4 + (x + 5) -> x + (4 + 5)
226 FunctionPass *createReassociatePass();
228 //===----------------------------------------------------------------------===//
230 // JumpThreading - Thread control through mult-pred/multi-succ blocks where some
231 // preds always go to some succ. Thresholds other than minus one override the
232 // internal BB duplication default threshold.
234 FunctionPass *createJumpThreadingPass(int Threshold = -1);
236 //===----------------------------------------------------------------------===//
238 // CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
239 // simplify terminator instructions, etc...
241 FunctionPass *createCFGSimplificationPass(int Threshold = -1);
243 //===----------------------------------------------------------------------===//
245 // FlattenCFG - flatten CFG, reduce number of conditional branches by using
246 // parallel-and and parallel-or mode, etc...
248 FunctionPass *createFlattenCFGPass();
250 //===----------------------------------------------------------------------===//
252 // CFG Structurization - Remove irreducible control flow
254 Pass *createStructurizeCFGPass();
256 //===----------------------------------------------------------------------===//
258 // BreakCriticalEdges - Break all of the critical edges in the CFG by inserting
259 // a dummy basic block. This pass may be "required" by passes that cannot deal
260 // with critical edges. For this usage, a pass must call:
262 // AU.addRequiredID(BreakCriticalEdgesID);
264 // This pass obviously invalidates the CFG, but can update forward dominator
265 // (set, immediate dominators, tree, and frontier) information.
267 FunctionPass *createBreakCriticalEdgesPass();
268 extern char &BreakCriticalEdgesID;
270 //===----------------------------------------------------------------------===//
272 // LoopSimplify - Insert Pre-header blocks into the CFG for every function in
273 // the module. This pass updates dominator information, loop information, and
274 // does not add critical edges to the CFG.
276 // AU.addRequiredID(LoopSimplifyID);
278 Pass *createLoopSimplifyPass();
279 extern char &LoopSimplifyID;
281 //===----------------------------------------------------------------------===//
283 // TailCallElimination - This pass eliminates call instructions to the current
284 // function which occur immediately before return instructions.
286 FunctionPass *createTailCallEliminationPass();
288 //===----------------------------------------------------------------------===//
290 // LowerSwitch - This pass converts SwitchInst instructions into a sequence of
291 // chained binary branch instructions.
293 FunctionPass *createLowerSwitchPass();
294 extern char &LowerSwitchID;
296 //===----------------------------------------------------------------------===//
298 // LowerInvoke - This pass removes invoke instructions, converting them to call
301 FunctionPass *createLowerInvokePass();
302 extern char &LowerInvokePassID;
304 //===----------------------------------------------------------------------===//
306 // LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop
309 Pass *createLCSSAPass();
310 extern char &LCSSAID;
312 //===----------------------------------------------------------------------===//
314 // EarlyCSE - This pass performs a simple and fast CSE pass over the dominator
317 FunctionPass *createEarlyCSEPass();
319 //===----------------------------------------------------------------------===//
321 // MergedLoadStoreMotion - This pass merges loads and stores in diamonds. Loads
322 // are hoisted into the header, while stores sink into the footer.
324 FunctionPass *createMergedLoadStoreMotionPass();
326 //===----------------------------------------------------------------------===//
328 // GVN - This pass performs global value numbering and redundant load
329 // elimination cotemporaneously.
331 FunctionPass *createGVNPass(bool NoLoads = false);
333 //===----------------------------------------------------------------------===//
335 // MemCpyOpt - This pass performs optimizations related to eliminating memcpy
336 // calls and/or combining multiple stores into memset's.
338 FunctionPass *createMemCpyOptPass();
340 //===----------------------------------------------------------------------===//
342 // LoopDeletion - This pass performs DCE of non-infinite loops that it
343 // can prove are dead.
345 Pass *createLoopDeletionPass();
347 //===----------------------------------------------------------------------===//
349 // ConstantHoisting - This pass prepares a function for expensive constants.
351 FunctionPass *createConstantHoistingPass();
353 //===----------------------------------------------------------------------===//
355 // InstructionNamer - Give any unnamed non-void instructions "tmp" names.
357 FunctionPass *createInstructionNamerPass();
358 extern char &InstructionNamerID;
360 //===----------------------------------------------------------------------===//
362 // Sink - Code Sinking
364 FunctionPass *createSinkingPass();
366 //===----------------------------------------------------------------------===//
368 // LowerAtomic - Lower atomic intrinsics to non-atomic form
370 Pass *createLowerAtomicPass();
372 //===----------------------------------------------------------------------===//
374 // ValuePropagation - Propagate CFG-derived value information
376 Pass *createCorrelatedValuePropagationPass();
378 //===----------------------------------------------------------------------===//
380 // InstructionSimplifier - Remove redundant instructions.
382 FunctionPass *createInstructionSimplifierPass();
383 extern char &InstructionSimplifierID;
385 //===----------------------------------------------------------------------===//
387 // LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates
388 // "block_weights" metadata.
389 FunctionPass *createLowerExpectIntrinsicPass();
391 //===----------------------------------------------------------------------===//
393 // PartiallyInlineLibCalls - Tries to inline the fast path of library
394 // calls such as sqrt.
396 FunctionPass *createPartiallyInlineLibCallsPass();
398 //===----------------------------------------------------------------------===//
400 // SampleProfilePass - Loads sample profile data from disk and generates
401 // IR metadata to reflect the profile.
402 FunctionPass *createSampleProfileLoaderPass();
403 FunctionPass *createSampleProfileLoaderPass(StringRef Name);
405 //===----------------------------------------------------------------------===//
407 // ScalarizerPass - Converts vector operations into scalar operations
409 FunctionPass *createScalarizerPass();
411 //===----------------------------------------------------------------------===//
413 // AddDiscriminators - Add DWARF path discriminators to the IR.
414 FunctionPass *createAddDiscriminatorsPass();
416 //===----------------------------------------------------------------------===//
418 // SeparateConstOffsetFromGEP - Split GEPs for better CSE
421 createSeparateConstOffsetFromGEPPass(const TargetMachine *TM = nullptr,
422 bool LowerGEP = false);
424 //===----------------------------------------------------------------------===//
426 // LoadCombine - Combine loads into bigger loads.
428 BasicBlockPass *createLoadCombinePass();
430 FunctionPass *createStraightLineStrengthReducePass();
433 //===----------------------------------------------------------------------===//
435 // PlaceSafepoints - Rewrite any IR calls to gc.statepoints and insert any
436 // safepoint polls (method entry, backedge) that might be required. This pass
437 // does not generate explicit relocation sequences - that's handled by
438 // RewriteStatepointsForGC which can be run at an arbitrary point in the pass
439 // order following this pass.
441 ModulePass *createPlaceSafepointsPass();
443 //===----------------------------------------------------------------------===//
445 // RewriteStatepointsForGC - Rewrite any gc.statepoints which do not yet have
446 // explicit relocations to include explicit relocations.
448 FunctionPass *createRewriteStatepointsForGCPass();
450 } // End llvm namespace