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 // LoopStrengthReduce - This pass is strength reduces GEP instructions that use
144 // a loop's canonical induction variable as one of their indices.
146 Pass *createLoopStrengthReducePass();
148 Pass *createGlobalMergePass(const TargetMachine *TM, unsigned MaximalOffset);
150 //===----------------------------------------------------------------------===//
152 // LoopUnswitch - This pass is a simple loop unswitching pass.
154 Pass *createLoopUnswitchPass(bool OptimizeForSize = false);
156 //===----------------------------------------------------------------------===//
158 // LoopInstSimplify - This pass simplifies instructions in a loop's body.
160 Pass *createLoopInstSimplifyPass();
162 //===----------------------------------------------------------------------===//
164 // LoopUnroll - This pass is a simple loop unrolling pass.
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();
171 //===----------------------------------------------------------------------===//
173 // LoopReroll - This pass is a simple loop rerolling pass.
175 Pass *createLoopRerollPass();
177 //===----------------------------------------------------------------------===//
179 // LoopRotate - This pass is a simple loop rotating pass.
181 Pass *createLoopRotatePass(int MaxHeaderSize = -1);
183 //===----------------------------------------------------------------------===//
185 // LoopIdiom - This pass recognizes and replaces idioms in loops.
187 Pass *createLoopIdiomPass();
189 //===----------------------------------------------------------------------===//
191 // PromoteMemoryToRegister - This pass is used to promote memory references to
192 // be register references. A simple example of the transformation performed by
196 // %X = alloca i32, i32 1 ret i32 42
197 // store i32 42, i32 *%X
201 FunctionPass *createPromoteMemoryToRegisterPass();
203 //===----------------------------------------------------------------------===//
205 // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
206 // references. In basically undoes the PromoteMemoryToRegister pass to make cfg
209 FunctionPass *createDemoteRegisterToMemoryPass();
210 extern char &DemoteRegisterToMemoryID;
212 //===----------------------------------------------------------------------===//
214 // Reassociate - This pass reassociates commutative expressions in an order that
215 // is designed to promote better constant propagation, GCSE, LICM, PRE...
217 // For example: 4 + (x + 5) -> x + (4 + 5)
219 FunctionPass *createReassociatePass();
221 //===----------------------------------------------------------------------===//
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.
227 FunctionPass *createJumpThreadingPass(int Threshold = -1);
229 //===----------------------------------------------------------------------===//
231 // CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
232 // simplify terminator instructions, etc...
234 FunctionPass *createCFGSimplificationPass(int Threshold = -1);
236 //===----------------------------------------------------------------------===//
238 // FlattenCFG - flatten CFG, reduce number of conditional branches by using
239 // parallel-and and parallel-or mode, etc...
241 FunctionPass *createFlattenCFGPass();
243 //===----------------------------------------------------------------------===//
245 // CFG Structurization - Remove irreducible control flow
247 Pass *createStructurizeCFGPass();
249 //===----------------------------------------------------------------------===//
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:
255 // AU.addRequiredID(BreakCriticalEdgesID);
257 // This pass obviously invalidates the CFG, but can update forward dominator
258 // (set, immediate dominators, tree, and frontier) information.
260 FunctionPass *createBreakCriticalEdgesPass();
261 extern char &BreakCriticalEdgesID;
263 //===----------------------------------------------------------------------===//
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.
269 // AU.addRequiredID(LoopSimplifyID);
271 Pass *createLoopSimplifyPass();
272 extern char &LoopSimplifyID;
274 //===----------------------------------------------------------------------===//
276 // TailCallElimination - This pass eliminates call instructions to the current
277 // function which occur immediately before return instructions.
279 FunctionPass *createTailCallEliminationPass();
281 //===----------------------------------------------------------------------===//
283 // LowerSwitch - This pass converts SwitchInst instructions into a sequence of
284 // chained binary branch instructions.
286 FunctionPass *createLowerSwitchPass();
287 extern char &LowerSwitchID;
289 //===----------------------------------------------------------------------===//
291 // LowerInvoke - This pass removes invoke instructions, converting them to call
294 FunctionPass *createLowerInvokePass();
295 extern char &LowerInvokePassID;
297 //===----------------------------------------------------------------------===//
299 // LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop
302 Pass *createLCSSAPass();
303 extern char &LCSSAID;
305 //===----------------------------------------------------------------------===//
307 // EarlyCSE - This pass performs a simple and fast CSE pass over the dominator
310 FunctionPass *createEarlyCSEPass();
312 //===----------------------------------------------------------------------===//
314 // MergedLoadStoreMotion - This pass merges loads and stores in diamonds. Loads
315 // are hoisted into the header, while stores sink into the footer.
317 FunctionPass *createMergedLoadStoreMotionPass();
319 //===----------------------------------------------------------------------===//
321 // GVN - This pass performs global value numbering and redundant load
322 // elimination cotemporaneously.
324 FunctionPass *createGVNPass(bool NoLoads = false);
326 //===----------------------------------------------------------------------===//
328 // MemCpyOpt - This pass performs optimizations related to eliminating memcpy
329 // calls and/or combining multiple stores into memset's.
331 FunctionPass *createMemCpyOptPass();
333 //===----------------------------------------------------------------------===//
335 // LoopDeletion - This pass performs DCE of non-infinite loops that it
336 // can prove are dead.
338 Pass *createLoopDeletionPass();
340 //===----------------------------------------------------------------------===//
342 // ConstantHoisting - This pass prepares a function for expensive constants.
344 FunctionPass *createConstantHoistingPass();
346 //===----------------------------------------------------------------------===//
348 // InstructionNamer - Give any unnamed non-void instructions "tmp" names.
350 FunctionPass *createInstructionNamerPass();
351 extern char &InstructionNamerID;
353 //===----------------------------------------------------------------------===//
355 // Sink - Code Sinking
357 FunctionPass *createSinkingPass();
359 //===----------------------------------------------------------------------===//
361 // LowerAtomic - Lower atomic intrinsics to non-atomic form
363 Pass *createLowerAtomicPass();
365 //===----------------------------------------------------------------------===//
367 // ValuePropagation - Propagate CFG-derived value information
369 Pass *createCorrelatedValuePropagationPass();
371 //===----------------------------------------------------------------------===//
373 // InstructionSimplifier - Remove redundant instructions.
375 FunctionPass *createInstructionSimplifierPass();
376 extern char &InstructionSimplifierID;
378 //===----------------------------------------------------------------------===//
380 // LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates
381 // "block_weights" metadata.
382 FunctionPass *createLowerExpectIntrinsicPass();
384 //===----------------------------------------------------------------------===//
386 // PartiallyInlineLibCalls - Tries to inline the fast path of library
387 // calls such as sqrt.
389 FunctionPass *createPartiallyInlineLibCallsPass();
391 //===----------------------------------------------------------------------===//
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);
398 //===----------------------------------------------------------------------===//
400 // ScalarizerPass - Converts vector operations into scalar operations
402 FunctionPass *createScalarizerPass();
404 //===----------------------------------------------------------------------===//
406 // AddDiscriminators - Add DWARF path discriminators to the IR.
407 FunctionPass *createAddDiscriminatorsPass();
409 //===----------------------------------------------------------------------===//
411 // SeparateConstOffsetFromGEP - Split GEPs for better CSE
414 createSeparateConstOffsetFromGEPPass(const TargetMachine *TM = nullptr,
415 bool LowerGEP = false);
417 //===----------------------------------------------------------------------===//
419 // LoadCombine - Combine loads into bigger loads.
421 BasicBlockPass *createLoadCombinePass();
423 FunctionPass *createStraightLineStrengthReducePass();
426 //===----------------------------------------------------------------------===//
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.
434 ModulePass *createPlaceSafepointsPass();
436 //===----------------------------------------------------------------------===//
438 // RewriteStatepointsForGC - Rewrite any gc.statepoints which do not yet have
439 // explicit relocations to include explicit relocations.
441 FunctionPass *createRewriteStatepointsForGCPass();
443 } // End llvm namespace