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 //===----------------------------------------------------------------------===//
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.
161 Pass *createGlobalMergePass(const TargetMachine *TM, unsigned MaximalOffset,
162 bool OnlyOptimizeForSize = false);
164 //===----------------------------------------------------------------------===//
166 // LoopUnswitch - This pass is a simple loop unswitching pass.
168 Pass *createLoopUnswitchPass(bool OptimizeForSize = false);
170 //===----------------------------------------------------------------------===//
172 // LoopInstSimplify - This pass simplifies instructions in a loop's body.
174 Pass *createLoopInstSimplifyPass();
176 //===----------------------------------------------------------------------===//
178 // LoopUnroll - This pass is a simple loop unrolling pass.
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();
185 //===----------------------------------------------------------------------===//
187 // LoopReroll - This pass is a simple loop rerolling pass.
189 Pass *createLoopRerollPass();
191 //===----------------------------------------------------------------------===//
193 // LoopRotate - This pass is a simple loop rotating pass.
195 Pass *createLoopRotatePass(int MaxHeaderSize = -1);
197 //===----------------------------------------------------------------------===//
199 // LoopIdiom - This pass recognizes and replaces idioms in loops.
201 Pass *createLoopIdiomPass();
203 //===----------------------------------------------------------------------===//
205 // PromoteMemoryToRegister - This pass is used to promote memory references to
206 // be register references. A simple example of the transformation performed by
210 // %X = alloca i32, i32 1 ret i32 42
211 // store i32 42, i32 *%X
215 FunctionPass *createPromoteMemoryToRegisterPass();
217 //===----------------------------------------------------------------------===//
219 // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
220 // references. In basically undoes the PromoteMemoryToRegister pass to make cfg
223 FunctionPass *createDemoteRegisterToMemoryPass();
224 extern char &DemoteRegisterToMemoryID;
226 //===----------------------------------------------------------------------===//
228 // Reassociate - This pass reassociates commutative expressions in an order that
229 // is designed to promote better constant propagation, GCSE, LICM, PRE...
231 // For example: 4 + (x + 5) -> x + (4 + 5)
233 FunctionPass *createReassociatePass();
235 //===----------------------------------------------------------------------===//
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.
241 FunctionPass *createJumpThreadingPass(int Threshold = -1);
243 //===----------------------------------------------------------------------===//
245 // CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
246 // simplify terminator instructions, etc...
248 FunctionPass *createCFGSimplificationPass(int Threshold = -1);
250 //===----------------------------------------------------------------------===//
252 // FlattenCFG - flatten CFG, reduce number of conditional branches by using
253 // parallel-and and parallel-or mode, etc...
255 FunctionPass *createFlattenCFGPass();
257 //===----------------------------------------------------------------------===//
259 // CFG Structurization - Remove irreducible control flow
261 Pass *createStructurizeCFGPass();
263 //===----------------------------------------------------------------------===//
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:
269 // AU.addRequiredID(BreakCriticalEdgesID);
271 // This pass obviously invalidates the CFG, but can update forward dominator
272 // (set, immediate dominators, tree, and frontier) information.
274 FunctionPass *createBreakCriticalEdgesPass();
275 extern char &BreakCriticalEdgesID;
277 //===----------------------------------------------------------------------===//
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.
283 // AU.addRequiredID(LoopSimplifyID);
285 Pass *createLoopSimplifyPass();
286 extern char &LoopSimplifyID;
288 //===----------------------------------------------------------------------===//
290 // TailCallElimination - This pass eliminates call instructions to the current
291 // function which occur immediately before return instructions.
293 FunctionPass *createTailCallEliminationPass();
295 //===----------------------------------------------------------------------===//
297 // LowerSwitch - This pass converts SwitchInst instructions into a sequence of
298 // chained binary branch instructions.
300 FunctionPass *createLowerSwitchPass();
301 extern char &LowerSwitchID;
303 //===----------------------------------------------------------------------===//
305 // LowerInvoke - This pass removes invoke instructions, converting them to call
308 FunctionPass *createLowerInvokePass();
309 extern char &LowerInvokePassID;
311 //===----------------------------------------------------------------------===//
313 // LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop
316 Pass *createLCSSAPass();
317 extern char &LCSSAID;
319 //===----------------------------------------------------------------------===//
321 // EarlyCSE - This pass performs a simple and fast CSE pass over the dominator
324 FunctionPass *createEarlyCSEPass();
326 //===----------------------------------------------------------------------===//
328 // MergedLoadStoreMotion - This pass merges loads and stores in diamonds. Loads
329 // are hoisted into the header, while stores sink into the footer.
331 FunctionPass *createMergedLoadStoreMotionPass();
333 //===----------------------------------------------------------------------===//
335 // GVN - This pass performs global value numbering and redundant load
336 // elimination cotemporaneously.
338 FunctionPass *createGVNPass(bool NoLoads = false);
340 //===----------------------------------------------------------------------===//
342 // MemCpyOpt - This pass performs optimizations related to eliminating memcpy
343 // calls and/or combining multiple stores into memset's.
345 FunctionPass *createMemCpyOptPass();
347 //===----------------------------------------------------------------------===//
349 // LoopDeletion - This pass performs DCE of non-infinite loops that it
350 // can prove are dead.
352 Pass *createLoopDeletionPass();
354 //===----------------------------------------------------------------------===//
356 // ConstantHoisting - This pass prepares a function for expensive constants.
358 FunctionPass *createConstantHoistingPass();
360 //===----------------------------------------------------------------------===//
362 // InstructionNamer - Give any unnamed non-void instructions "tmp" names.
364 FunctionPass *createInstructionNamerPass();
365 extern char &InstructionNamerID;
367 //===----------------------------------------------------------------------===//
369 // Sink - Code Sinking
371 FunctionPass *createSinkingPass();
373 //===----------------------------------------------------------------------===//
375 // LowerAtomic - Lower atomic intrinsics to non-atomic form
377 Pass *createLowerAtomicPass();
379 //===----------------------------------------------------------------------===//
381 // ValuePropagation - Propagate CFG-derived value information
383 Pass *createCorrelatedValuePropagationPass();
385 //===----------------------------------------------------------------------===//
387 // InstructionSimplifier - Remove redundant instructions.
389 FunctionPass *createInstructionSimplifierPass();
390 extern char &InstructionSimplifierID;
392 //===----------------------------------------------------------------------===//
394 // LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates
395 // "block_weights" metadata.
396 FunctionPass *createLowerExpectIntrinsicPass();
398 //===----------------------------------------------------------------------===//
400 // PartiallyInlineLibCalls - Tries to inline the fast path of library
401 // calls such as sqrt.
403 FunctionPass *createPartiallyInlineLibCallsPass();
405 //===----------------------------------------------------------------------===//
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);
412 //===----------------------------------------------------------------------===//
414 // ScalarizerPass - Converts vector operations into scalar operations
416 FunctionPass *createScalarizerPass();
418 //===----------------------------------------------------------------------===//
420 // AddDiscriminators - Add DWARF path discriminators to the IR.
421 FunctionPass *createAddDiscriminatorsPass();
423 //===----------------------------------------------------------------------===//
425 // SeparateConstOffsetFromGEP - Split GEPs for better CSE
428 createSeparateConstOffsetFromGEPPass(const TargetMachine *TM = nullptr,
429 bool LowerGEP = false);
431 //===----------------------------------------------------------------------===//
433 // SpeculativeExecution - Aggressively hoist instructions to enable
434 // speculative execution on targets where branches are expensive.
436 FunctionPass *createSpeculativeExecutionPass();
438 //===----------------------------------------------------------------------===//
440 // LoadCombine - Combine loads into bigger loads.
442 BasicBlockPass *createLoadCombinePass();
444 //===----------------------------------------------------------------------===//
446 // StraightLineStrengthReduce - This pass strength-reduces some certain
447 // instruction patterns in straight-line code.
449 FunctionPass *createStraightLineStrengthReducePass();
451 //===----------------------------------------------------------------------===//
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.
459 FunctionPass *createPlaceSafepointsPass();
461 //===----------------------------------------------------------------------===//
463 // RewriteStatepointsForGC - Rewrite any gc.statepoints which do not yet have
464 // explicit relocations to include explicit relocations.
466 ModulePass *createRewriteStatepointsForGCPass();
468 //===----------------------------------------------------------------------===//
470 // Float2Int - Demote floats to ints where possible.
472 FunctionPass *createFloat2IntPass();
474 //===----------------------------------------------------------------------===//
476 // NaryReassociate - Simplify n-ary operations by reassociation.
478 FunctionPass *createNaryReassociatePass();
480 //===----------------------------------------------------------------------===//
482 // LoopDistribute - Distribute loops.
484 FunctionPass *createLoopDistributePass();
486 } // End llvm namespace