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"
25 class GetElementPtrInst;
31 //===----------------------------------------------------------------------===//
33 // ConstantPropagation - A worklist driven constant propagation pass
35 FunctionPass *createConstantPropagationPass();
37 //===----------------------------------------------------------------------===//
39 // SCCP - Sparse conditional constant propagation.
41 FunctionPass *createSCCPPass();
43 //===----------------------------------------------------------------------===//
45 // DeadInstElimination - This pass quickly removes trivially dead instructions
46 // without modifying the CFG of the function. It is a BasicBlockPass, so it
47 // runs efficiently when queued next to other BasicBlockPass's.
49 Pass *createDeadInstEliminationPass();
51 //===----------------------------------------------------------------------===//
53 // DeadCodeElimination - This pass is more powerful than DeadInstElimination,
54 // because it is worklist driven that can potentially revisit instructions when
55 // their other instructions become dead, to eliminate chains of dead
58 FunctionPass *createDeadCodeEliminationPass();
60 //===----------------------------------------------------------------------===//
62 // DeadStoreElimination - This pass deletes stores that are post-dominated by
63 // must-aliased stores and are not loaded used between the stores.
65 FunctionPass *createDeadStoreEliminationPass();
67 //===----------------------------------------------------------------------===//
69 // AggressiveDCE - This pass uses the SSA based Aggressive DCE algorithm. This
70 // algorithm assumes instructions are dead until proven otherwise, which makes
71 // it more successful are removing non-obviously dead instructions.
73 FunctionPass *createAggressiveDCEPass();
75 //===----------------------------------------------------------------------===//
77 // SROA - Replace aggregates or pieces of aggregates with scalar SSA values.
79 FunctionPass *createSROAPass(bool RequiresDomTree = true);
81 //===----------------------------------------------------------------------===//
83 // ScalarReplAggregates - Break up alloca's of aggregates into multiple allocas
86 FunctionPass *createScalarReplAggregatesPass(signed Threshold = -1,
87 bool UseDomTree = true,
88 signed StructMemberThreshold = -1,
89 signed ArrayElementThreshold = -1,
90 signed ScalarLoadThreshold = -1);
92 //===----------------------------------------------------------------------===//
94 // InductionVariableSimplify - Transform induction variables in a program to all
95 // use a single canonical induction variable per loop.
97 Pass *createIndVarSimplifyPass();
99 //===----------------------------------------------------------------------===//
101 // InstructionCombining - Combine instructions to form fewer, simple
102 // instructions. This pass does not modify the CFG, and has a tendency to make
103 // instructions dead, so a subsequent DCE pass is useful.
105 // This pass combines things like:
106 // %Y = add int 1, %X
107 // %Z = add int 1, %Y
109 // %Z = add int 2, %X
111 FunctionPass *createInstructionCombiningPass();
113 //===----------------------------------------------------------------------===//
115 // LICM - This pass is a loop invariant code motion and memory promotion pass.
117 Pass *createLICMPass();
119 //===----------------------------------------------------------------------===//
121 // LoopStrengthReduce - This pass is strength reduces GEP instructions that use
122 // a loop's canonical induction variable as one of their indices.
124 Pass *createLoopStrengthReducePass();
126 Pass *createGlobalMergePass(const TargetMachine *TM = nullptr);
128 //===----------------------------------------------------------------------===//
130 // LoopUnswitch - This pass is a simple loop unswitching pass.
132 Pass *createLoopUnswitchPass(bool OptimizeForSize = false);
134 //===----------------------------------------------------------------------===//
136 // LoopInstSimplify - This pass simplifies instructions in a loop's body.
138 Pass *createLoopInstSimplifyPass();
140 //===----------------------------------------------------------------------===//
142 // LoopUnroll - This pass is a simple loop unrolling pass.
144 Pass *createLoopUnrollPass(int Threshold = -1, int Count = -1,
145 int AllowPartial = -1, int Runtime = -1);
146 // Create an unrolling pass for full unrolling only.
147 Pass *createSimpleLoopUnrollPass();
149 //===----------------------------------------------------------------------===//
151 // LoopReroll - This pass is a simple loop rerolling pass.
153 Pass *createLoopRerollPass();
155 //===----------------------------------------------------------------------===//
157 // LoopRotate - This pass is a simple loop rotating pass.
159 Pass *createLoopRotatePass(int MaxHeaderSize = -1);
161 //===----------------------------------------------------------------------===//
163 // LoopIdiom - This pass recognizes and replaces idioms in loops.
165 Pass *createLoopIdiomPass();
167 //===----------------------------------------------------------------------===//
169 // PromoteMemoryToRegister - This pass is used to promote memory references to
170 // be register references. A simple example of the transformation performed by
174 // %X = alloca i32, i32 1 ret i32 42
175 // store i32 42, i32 *%X
179 FunctionPass *createPromoteMemoryToRegisterPass();
181 //===----------------------------------------------------------------------===//
183 // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
184 // references. In basically undoes the PromoteMemoryToRegister pass to make cfg
187 FunctionPass *createDemoteRegisterToMemoryPass();
188 extern char &DemoteRegisterToMemoryID;
190 //===----------------------------------------------------------------------===//
192 // Reassociate - This pass reassociates commutative expressions in an order that
193 // is designed to promote better constant propagation, GCSE, LICM, PRE...
195 // For example: 4 + (x + 5) -> x + (4 + 5)
197 FunctionPass *createReassociatePass();
199 //===----------------------------------------------------------------------===//
201 // JumpThreading - Thread control through mult-pred/multi-succ blocks where some
202 // preds always go to some succ.
204 FunctionPass *createJumpThreadingPass();
206 //===----------------------------------------------------------------------===//
208 // CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
209 // simplify terminator instructions, etc...
211 FunctionPass *createCFGSimplificationPass();
213 //===----------------------------------------------------------------------===//
215 // FlattenCFG - flatten CFG, reduce number of conditional branches by using
216 // parallel-and and parallel-or mode, etc...
218 FunctionPass *createFlattenCFGPass();
220 //===----------------------------------------------------------------------===//
222 // CFG Structurization - Remove irreducible control flow
224 Pass *createStructurizeCFGPass();
226 //===----------------------------------------------------------------------===//
228 // BreakCriticalEdges - Break all of the critical edges in the CFG by inserting
229 // a dummy basic block. This pass may be "required" by passes that cannot deal
230 // with critical edges. For this usage, a pass must call:
232 // AU.addRequiredID(BreakCriticalEdgesID);
234 // This pass obviously invalidates the CFG, but can update forward dominator
235 // (set, immediate dominators, tree, and frontier) information.
237 FunctionPass *createBreakCriticalEdgesPass();
238 extern char &BreakCriticalEdgesID;
240 //===----------------------------------------------------------------------===//
242 // LoopSimplify - Insert Pre-header blocks into the CFG for every function in
243 // the module. This pass updates dominator information, loop information, and
244 // does not add critical edges to the CFG.
246 // AU.addRequiredID(LoopSimplifyID);
248 Pass *createLoopSimplifyPass();
249 extern char &LoopSimplifyID;
251 //===----------------------------------------------------------------------===//
253 // TailCallElimination - This pass eliminates call instructions to the current
254 // function which occur immediately before return instructions.
256 FunctionPass *createTailCallEliminationPass();
258 //===----------------------------------------------------------------------===//
260 // LowerSwitch - This pass converts SwitchInst instructions into a sequence of
261 // chained binary branch instructions.
263 FunctionPass *createLowerSwitchPass();
264 extern char &LowerSwitchID;
266 //===----------------------------------------------------------------------===//
268 // LowerInvoke - This pass removes invoke instructions, converting them to call
271 FunctionPass *createLowerInvokePass();
272 extern char &LowerInvokePassID;
274 //===----------------------------------------------------------------------===//
276 // LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop
279 Pass *createLCSSAPass();
280 extern char &LCSSAID;
282 //===----------------------------------------------------------------------===//
284 // EarlyCSE - This pass performs a simple and fast CSE pass over the dominator
287 FunctionPass *createEarlyCSEPass();
289 //===----------------------------------------------------------------------===//
291 // GVN - This pass performs global value numbering and redundant load
292 // elimination cotemporaneously.
294 FunctionPass *createGVNPass(bool NoLoads = false);
296 //===----------------------------------------------------------------------===//
298 // MemCpyOpt - This pass performs optimizations related to eliminating memcpy
299 // calls and/or combining multiple stores into memset's.
301 FunctionPass *createMemCpyOptPass();
303 //===----------------------------------------------------------------------===//
305 // LoopDeletion - This pass performs DCE of non-infinite loops that it
306 // can prove are dead.
308 Pass *createLoopDeletionPass();
310 //===----------------------------------------------------------------------===//
312 // ConstantHoisting - This pass prepares a function for expensive constants.
314 FunctionPass *createConstantHoistingPass();
316 //===----------------------------------------------------------------------===//
318 // InstructionNamer - Give any unnamed non-void instructions "tmp" names.
320 FunctionPass *createInstructionNamerPass();
321 extern char &InstructionNamerID;
323 //===----------------------------------------------------------------------===//
325 // Sink - Code Sinking
327 FunctionPass *createSinkingPass();
329 //===----------------------------------------------------------------------===//
331 // LowerAtomic - Lower atomic intrinsics to non-atomic form
333 Pass *createLowerAtomicPass();
335 //===----------------------------------------------------------------------===//
337 // ValuePropagation - Propagate CFG-derived value information
339 Pass *createCorrelatedValuePropagationPass();
341 //===----------------------------------------------------------------------===//
343 // InstructionSimplifier - Remove redundant instructions.
345 FunctionPass *createInstructionSimplifierPass();
346 extern char &InstructionSimplifierID;
348 //===----------------------------------------------------------------------===//
350 // LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates
351 // "block_weights" metadata.
352 FunctionPass *createLowerExpectIntrinsicPass();
354 //===----------------------------------------------------------------------===//
356 // PartiallyInlineLibCalls - Tries to inline the fast path of library
357 // calls such as sqrt.
359 FunctionPass *createPartiallyInlineLibCallsPass();
361 //===----------------------------------------------------------------------===//
363 // SampleProfilePass - Loads sample profile data from disk and generates
364 // IR metadata to reflect the profile.
365 FunctionPass *createSampleProfileLoaderPass();
366 FunctionPass *createSampleProfileLoaderPass(StringRef Name);
368 //===----------------------------------------------------------------------===//
370 // ScalarizerPass - Converts vector operations into scalar operations
372 FunctionPass *createScalarizerPass();
374 //===----------------------------------------------------------------------===//
376 // AddDiscriminators - Add DWARF path discriminators to the IR.
377 FunctionPass *createAddDiscriminatorsPass();
379 //===----------------------------------------------------------------------===//
381 // SeparateConstOffsetFromGEP - Split GEPs for better CSE
383 FunctionPass *createSeparateConstOffsetFromGEPPass();
385 //===----------------------------------------------------------------------===//
387 // LoadCombine - Combine loads into bigger loads.
389 BasicBlockPass *createLoadCombinePass();
391 } // End llvm namespace