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"
28 class GetElementPtrInst;
34 //===----------------------------------------------------------------------===//
36 // ConstantPropagation - A worklist driven constant propagation pass
38 FunctionPass *createConstantPropagationPass();
40 //===----------------------------------------------------------------------===//
42 // AlignmentFromAssumptions - Use assume intrinsics to set load/store
45 FunctionPass *createAlignmentFromAssumptionsPass();
47 //===----------------------------------------------------------------------===//
49 // SCCP - Sparse conditional constant propagation.
51 FunctionPass *createSCCPPass();
53 //===----------------------------------------------------------------------===//
55 // DeadInstElimination - This pass quickly removes trivially dead instructions
56 // without modifying the CFG of the function. It is a BasicBlockPass, so it
57 // runs efficiently when queued next to other BasicBlockPass's.
59 Pass *createDeadInstEliminationPass();
61 //===----------------------------------------------------------------------===//
63 // DeadCodeElimination - This pass is more powerful than DeadInstElimination,
64 // because it is worklist driven that can potentially revisit instructions when
65 // their other instructions become dead, to eliminate chains of dead
68 FunctionPass *createDeadCodeEliminationPass();
70 //===----------------------------------------------------------------------===//
72 // DeadStoreElimination - This pass deletes stores that are post-dominated by
73 // must-aliased stores and are not loaded used between the stores.
75 FunctionPass *createDeadStoreEliminationPass();
77 //===----------------------------------------------------------------------===//
79 // AggressiveDCE - This pass uses the SSA based Aggressive DCE algorithm. This
80 // algorithm assumes instructions are dead until proven otherwise, which makes
81 // it more successful are removing non-obviously dead instructions.
83 FunctionPass *createAggressiveDCEPass();
85 //===----------------------------------------------------------------------===//
87 // BitTrackingDCE - This pass uses a bit-tracking DCE algorithm in order to
88 // remove computations of dead bits.
90 FunctionPass *createBitTrackingDCEPass();
92 //===----------------------------------------------------------------------===//
94 // SROA - Replace aggregates or pieces of aggregates with scalar SSA values.
96 FunctionPass *createSROAPass(bool RequiresDomTree = true);
98 //===----------------------------------------------------------------------===//
100 // ScalarReplAggregates - Break up alloca's of aggregates into multiple allocas
103 FunctionPass *createScalarReplAggregatesPass(signed Threshold = -1,
104 bool UseDomTree = true,
105 signed StructMemberThreshold = -1,
106 signed ArrayElementThreshold = -1,
107 signed ScalarLoadThreshold = -1);
109 //===----------------------------------------------------------------------===//
111 // InductiveRangeCheckElimination - Transform loops to elide range checks on
112 // linear functions of the induction variable.
114 Pass *createInductiveRangeCheckEliminationPass();
116 //===----------------------------------------------------------------------===//
118 // InductionVariableSimplify - Transform induction variables in a program to all
119 // use a single canonical induction variable per loop.
121 Pass *createIndVarSimplifyPass();
123 //===----------------------------------------------------------------------===//
125 // InstructionCombining - Combine instructions to form fewer, simple
126 // instructions. This pass does not modify the CFG, and has a tendency to make
127 // instructions dead, so a subsequent DCE pass is useful.
129 // This pass combines things like:
130 // %Y = add int 1, %X
131 // %Z = add int 1, %Y
133 // %Z = add int 2, %X
135 FunctionPass *createInstructionCombiningPass();
137 //===----------------------------------------------------------------------===//
139 // LICM - This pass is a loop invariant code motion and memory promotion pass.
141 Pass *createLICMPass();
143 //===----------------------------------------------------------------------===//
145 // LoopInterchange - This pass interchanges loops to provide a more
146 // cache-friendly memory access patterns.
148 Pass *createLoopInterchangePass();
150 //===----------------------------------------------------------------------===//
152 // LoopStrengthReduce - This pass is strength reduces GEP instructions that use
153 // a loop's canonical induction variable as one of their indices.
155 Pass *createLoopStrengthReducePass();
157 //===----------------------------------------------------------------------===//
159 // GlobalMerge - This pass merges internal (by default) globals into structs
160 // to enable reuse of a base pointer by indexed addressing modes.
161 // It can also be configured to focus on size optimizations only.
163 Pass *createGlobalMergePass(const TargetMachine *TM, unsigned MaximalOffset,
164 bool OnlyOptimizeForSize = false);
166 //===----------------------------------------------------------------------===//
168 // LoopUnswitch - This pass is a simple loop unswitching pass.
170 Pass *createLoopUnswitchPass(bool OptimizeForSize = false);
172 //===----------------------------------------------------------------------===//
174 // LoopInstSimplify - This pass simplifies instructions in a loop's body.
176 Pass *createLoopInstSimplifyPass();
178 //===----------------------------------------------------------------------===//
180 // LoopUnroll - This pass is a simple loop unrolling pass.
182 Pass *createLoopUnrollPass(int Threshold = -1, int Count = -1,
183 int AllowPartial = -1, int Runtime = -1);
184 // Create an unrolling pass for full unrolling only.
185 Pass *createSimpleLoopUnrollPass();
187 //===----------------------------------------------------------------------===//
189 // LoopReroll - This pass is a simple loop rerolling pass.
191 Pass *createLoopRerollPass();
193 //===----------------------------------------------------------------------===//
195 // LoopRotate - This pass is a simple loop rotating pass.
197 Pass *createLoopRotatePass(int MaxHeaderSize = -1);
199 //===----------------------------------------------------------------------===//
201 // LoopIdiom - This pass recognizes and replaces idioms in loops.
203 Pass *createLoopIdiomPass();
205 //===----------------------------------------------------------------------===//
207 // PromoteMemoryToRegister - This pass is used to promote memory references to
208 // be register references. A simple example of the transformation performed by
212 // %X = alloca i32, i32 1 ret i32 42
213 // store i32 42, i32 *%X
217 FunctionPass *createPromoteMemoryToRegisterPass();
219 //===----------------------------------------------------------------------===//
221 // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
222 // references. In basically undoes the PromoteMemoryToRegister pass to make cfg
225 FunctionPass *createDemoteRegisterToMemoryPass();
226 extern char &DemoteRegisterToMemoryID;
228 //===----------------------------------------------------------------------===//
230 // Reassociate - This pass reassociates commutative expressions in an order that
231 // is designed to promote better constant propagation, GCSE, LICM, PRE...
233 // For example: 4 + (x + 5) -> x + (4 + 5)
235 FunctionPass *createReassociatePass();
237 //===----------------------------------------------------------------------===//
239 // JumpThreading - Thread control through mult-pred/multi-succ blocks where some
240 // preds always go to some succ. Thresholds other than minus one override the
241 // internal BB duplication default threshold.
243 FunctionPass *createJumpThreadingPass(int Threshold = -1);
245 //===----------------------------------------------------------------------===//
247 // CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
248 // simplify terminator instructions, etc...
250 FunctionPass *createCFGSimplificationPass(
251 int Threshold = -1, std::function<bool(const Function &)> Ftor = nullptr);
253 //===----------------------------------------------------------------------===//
255 // FlattenCFG - flatten CFG, reduce number of conditional branches by using
256 // parallel-and and parallel-or mode, etc...
258 FunctionPass *createFlattenCFGPass();
260 //===----------------------------------------------------------------------===//
262 // CFG Structurization - Remove irreducible control flow
264 Pass *createStructurizeCFGPass();
266 //===----------------------------------------------------------------------===//
268 // BreakCriticalEdges - Break all of the critical edges in the CFG by inserting
269 // a dummy basic block. This pass may be "required" by passes that cannot deal
270 // with critical edges. For this usage, a pass must call:
272 // AU.addRequiredID(BreakCriticalEdgesID);
274 // This pass obviously invalidates the CFG, but can update forward dominator
275 // (set, immediate dominators, tree, and frontier) information.
277 FunctionPass *createBreakCriticalEdgesPass();
278 extern char &BreakCriticalEdgesID;
280 //===----------------------------------------------------------------------===//
282 // LoopSimplify - Insert Pre-header blocks into the CFG for every function in
283 // the module. This pass updates dominator information, loop information, and
284 // does not add critical edges to the CFG.
286 // AU.addRequiredID(LoopSimplifyID);
288 Pass *createLoopSimplifyPass();
289 extern char &LoopSimplifyID;
291 //===----------------------------------------------------------------------===//
293 // TailCallElimination - This pass eliminates call instructions to the current
294 // function which occur immediately before return instructions.
296 FunctionPass *createTailCallEliminationPass();
298 //===----------------------------------------------------------------------===//
300 // LowerSwitch - This pass converts SwitchInst instructions into a sequence of
301 // chained binary branch instructions.
303 FunctionPass *createLowerSwitchPass();
304 extern char &LowerSwitchID;
306 //===----------------------------------------------------------------------===//
308 // LowerInvoke - This pass removes invoke instructions, converting them to call
311 FunctionPass *createLowerInvokePass();
312 extern char &LowerInvokePassID;
314 //===----------------------------------------------------------------------===//
316 // LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop
319 Pass *createLCSSAPass();
320 extern char &LCSSAID;
322 //===----------------------------------------------------------------------===//
324 // EarlyCSE - This pass performs a simple and fast CSE pass over the dominator
327 FunctionPass *createEarlyCSEPass();
329 //===----------------------------------------------------------------------===//
331 // MergedLoadStoreMotion - This pass merges loads and stores in diamonds. Loads
332 // are hoisted into the header, while stores sink into the footer.
334 FunctionPass *createMergedLoadStoreMotionPass();
336 //===----------------------------------------------------------------------===//
338 // GVN - This pass performs global value numbering and redundant load
339 // elimination cotemporaneously.
341 FunctionPass *createGVNPass(bool NoLoads = false);
343 //===----------------------------------------------------------------------===//
345 // MemCpyOpt - This pass performs optimizations related to eliminating memcpy
346 // calls and/or combining multiple stores into memset's.
348 FunctionPass *createMemCpyOptPass();
350 //===----------------------------------------------------------------------===//
352 // LoopDeletion - This pass performs DCE of non-infinite loops that it
353 // can prove are dead.
355 Pass *createLoopDeletionPass();
357 //===----------------------------------------------------------------------===//
359 // ConstantHoisting - This pass prepares a function for expensive constants.
361 FunctionPass *createConstantHoistingPass();
363 //===----------------------------------------------------------------------===//
365 // InstructionNamer - Give any unnamed non-void instructions "tmp" names.
367 FunctionPass *createInstructionNamerPass();
368 extern char &InstructionNamerID;
370 //===----------------------------------------------------------------------===//
372 // Sink - Code Sinking
374 FunctionPass *createSinkingPass();
376 //===----------------------------------------------------------------------===//
378 // LowerAtomic - Lower atomic intrinsics to non-atomic form
380 Pass *createLowerAtomicPass();
382 //===----------------------------------------------------------------------===//
384 // ValuePropagation - Propagate CFG-derived value information
386 Pass *createCorrelatedValuePropagationPass();
388 //===----------------------------------------------------------------------===//
390 // InstructionSimplifier - Remove redundant instructions.
392 FunctionPass *createInstructionSimplifierPass();
393 extern char &InstructionSimplifierID;
395 //===----------------------------------------------------------------------===//
397 // LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates
398 // "block_weights" metadata.
399 FunctionPass *createLowerExpectIntrinsicPass();
401 //===----------------------------------------------------------------------===//
403 // PartiallyInlineLibCalls - Tries to inline the fast path of library
404 // calls such as sqrt.
406 FunctionPass *createPartiallyInlineLibCallsPass();
408 //===----------------------------------------------------------------------===//
410 // SampleProfilePass - Loads sample profile data from disk and generates
411 // IR metadata to reflect the profile.
412 FunctionPass *createSampleProfileLoaderPass();
413 FunctionPass *createSampleProfileLoaderPass(StringRef Name);
415 //===----------------------------------------------------------------------===//
417 // ScalarizerPass - Converts vector operations into scalar operations
419 FunctionPass *createScalarizerPass();
421 //===----------------------------------------------------------------------===//
423 // AddDiscriminators - Add DWARF path discriminators to the IR.
424 FunctionPass *createAddDiscriminatorsPass();
426 //===----------------------------------------------------------------------===//
428 // SeparateConstOffsetFromGEP - Split GEPs for better CSE
431 createSeparateConstOffsetFromGEPPass(const TargetMachine *TM = nullptr,
432 bool LowerGEP = false);
434 //===----------------------------------------------------------------------===//
436 // SpeculativeExecution - Aggressively hoist instructions to enable
437 // speculative execution on targets where branches are expensive.
439 FunctionPass *createSpeculativeExecutionPass();
441 //===----------------------------------------------------------------------===//
443 // LoadCombine - Combine loads into bigger loads.
445 BasicBlockPass *createLoadCombinePass();
447 //===----------------------------------------------------------------------===//
449 // StraightLineStrengthReduce - This pass strength-reduces some certain
450 // instruction patterns in straight-line code.
452 FunctionPass *createStraightLineStrengthReducePass();
454 //===----------------------------------------------------------------------===//
456 // PlaceSafepoints - Rewrite any IR calls to gc.statepoints and insert any
457 // safepoint polls (method entry, backedge) that might be required. This pass
458 // does not generate explicit relocation sequences - that's handled by
459 // RewriteStatepointsForGC which can be run at an arbitrary point in the pass
460 // order following this pass.
462 FunctionPass *createPlaceSafepointsPass();
464 //===----------------------------------------------------------------------===//
466 // RewriteStatepointsForGC - Rewrite any gc.statepoints which do not yet have
467 // explicit relocations to include explicit relocations.
469 ModulePass *createRewriteStatepointsForGCPass();
471 //===----------------------------------------------------------------------===//
473 // Float2Int - Demote floats to ints where possible.
475 FunctionPass *createFloat2IntPass();
477 //===----------------------------------------------------------------------===//
479 // NaryReassociate - Simplify n-ary operations by reassociation.
481 FunctionPass *createNaryReassociatePass();
483 //===----------------------------------------------------------------------===//
485 // LoopDistribute - Distribute loops.
487 FunctionPass *createLoopDistributePass();
489 } // End llvm namespace