1//===-- Scalar.h - Scalar Transformations -----------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This header file defines prototypes for accessor functions that expose passes 11// in the Scalar transformations library. 12// 13//===----------------------------------------------------------------------===// 14 15#ifndef LLVM_TRANSFORMS_SCALAR_H 16#define LLVM_TRANSFORMS_SCALAR_H 17 18#include "llvm/ADT/StringRef.h" 19 20namespace llvm { 21 22class BasicBlockPass; 23class FunctionPass; 24class Pass; 25class GetElementPtrInst; 26class PassInfo; 27class TerminatorInst; 28class TargetLowering; 29class TargetMachine; 30 31//===----------------------------------------------------------------------===// 32// 33// ConstantPropagation - A worklist driven constant propagation pass 34// 35FunctionPass *createConstantPropagationPass(); 36 37//===----------------------------------------------------------------------===// 38// 39// SCCP - Sparse conditional constant propagation. 40// 41FunctionPass *createSCCPPass(); 42 43//===----------------------------------------------------------------------===// 44// 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. 48// 49Pass *createDeadInstEliminationPass(); 50 51//===----------------------------------------------------------------------===// 52// 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 56// computations. 57// 58FunctionPass *createDeadCodeEliminationPass(); 59 60//===----------------------------------------------------------------------===// 61// 62// DeadStoreElimination - This pass deletes stores that are post-dominated by 63// must-aliased stores and are not loaded used between the stores. 64// 65FunctionPass *createDeadStoreEliminationPass(); 66 67//===----------------------------------------------------------------------===// 68// 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. 72// 73FunctionPass *createAggressiveDCEPass(); 74 75//===----------------------------------------------------------------------===// 76// 77// SROA - Replace aggregates or pieces of aggregates with scalar SSA values. 78// 79FunctionPass *createSROAPass(bool RequiresDomTree = true); 80 81//===----------------------------------------------------------------------===// 82// 83// ScalarReplAggregates - Break up alloca's of aggregates into multiple allocas 84// if possible. 85// 86FunctionPass *createScalarReplAggregatesPass(signed Threshold = -1, 87 bool UseDomTree = true, 88 signed StructMemberThreshold = -1, 89 signed ArrayElementThreshold = -1, 90 signed ScalarLoadThreshold = -1); 91 92//===----------------------------------------------------------------------===// 93// 94// InductionVariableSimplify - Transform induction variables in a program to all 95// use a single canonical induction variable per loop. 96// 97Pass *createIndVarSimplifyPass(); 98 99//===----------------------------------------------------------------------===// 100// 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. 104// 105// This pass combines things like: 106// %Y = add int 1, %X 107// %Z = add int 1, %Y 108// into: 109// %Z = add int 2, %X 110// 111FunctionPass *createInstructionCombiningPass(); 112 113//===----------------------------------------------------------------------===// 114// 115// LICM - This pass is a loop invariant code motion and memory promotion pass. 116// 117Pass *createLICMPass(); 118 119//===----------------------------------------------------------------------===// 120// 121// LoopStrengthReduce - This pass is strength reduces GEP instructions that use 122// a loop's canonical induction variable as one of their indices. 123// 124Pass *createLoopStrengthReducePass(); 125 126Pass *createGlobalMergePass(const TargetMachine *TM = nullptr); 127 128//===----------------------------------------------------------------------===// 129// 130// LoopUnswitch - This pass is a simple loop unswitching pass. 131// 132Pass *createLoopUnswitchPass(bool OptimizeForSize = false); 133 134//===----------------------------------------------------------------------===// 135// 136// LoopInstSimplify - This pass simplifies instructions in a loop's body. 137// 138Pass *createLoopInstSimplifyPass(); 139 140//===----------------------------------------------------------------------===// 141// 142// LoopUnroll - This pass is a simple loop unrolling pass. 143// 144Pass *createLoopUnrollPass(int Threshold = -1, int Count = -1, 145 int AllowPartial = -1, int Runtime = -1); 146// Create an unrolling pass for full unrolling only. 147Pass *createSimpleLoopUnrollPass(); 148 149//===----------------------------------------------------------------------===// 150// 151// LoopReroll - This pass is a simple loop rerolling pass. 152// 153Pass *createLoopRerollPass(); 154 155//===----------------------------------------------------------------------===// 156// 157// LoopRotate - This pass is a simple loop rotating pass. 158// 159Pass *createLoopRotatePass(int MaxHeaderSize = -1); 160 161//===----------------------------------------------------------------------===// 162// 163// LoopIdiom - This pass recognizes and replaces idioms in loops. 164// 165Pass *createLoopIdiomPass(); 166 167//===----------------------------------------------------------------------===// 168// 169// PromoteMemoryToRegister - This pass is used to promote memory references to 170// be register references. A simple example of the transformation performed by 171// this pass is: 172// 173// FROM CODE TO CODE 174// %X = alloca i32, i32 1 ret i32 42 175// store i32 42, i32 *%X 176// %Y = load i32* %X 177// ret i32 %Y 178// 179FunctionPass *createPromoteMemoryToRegisterPass(); 180 181//===----------------------------------------------------------------------===// 182// 183// DemoteRegisterToMemoryPass - This pass is used to demote registers to memory 184// references. In basically undoes the PromoteMemoryToRegister pass to make cfg 185// hacking easier. 186// 187FunctionPass *createDemoteRegisterToMemoryPass(); 188extern char &DemoteRegisterToMemoryID; 189 190//===----------------------------------------------------------------------===// 191// 192// Reassociate - This pass reassociates commutative expressions in an order that 193// is designed to promote better constant propagation, GCSE, LICM, PRE... 194// 195// For example: 4 + (x + 5) -> x + (4 + 5) 196// 197FunctionPass *createReassociatePass(); 198 199//===----------------------------------------------------------------------===// 200// 201// JumpThreading - Thread control through mult-pred/multi-succ blocks where some 202// preds always go to some succ. 203// 204FunctionPass *createJumpThreadingPass(); 205 206//===----------------------------------------------------------------------===// 207// 208// CFGSimplification - Merge basic blocks, eliminate unreachable blocks, 209// simplify terminator instructions, etc... 210// 211FunctionPass *createCFGSimplificationPass(); 212 213//===----------------------------------------------------------------------===// 214// 215// FlattenCFG - flatten CFG, reduce number of conditional branches by using 216// parallel-and and parallel-or mode, etc... 217// 218FunctionPass *createFlattenCFGPass(); 219 220//===----------------------------------------------------------------------===// 221// 222// CFG Structurization - Remove irreducible control flow 223// 224Pass *createStructurizeCFGPass(); 225 226//===----------------------------------------------------------------------===// 227// 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: 231// 232// AU.addRequiredID(BreakCriticalEdgesID); 233// 234// This pass obviously invalidates the CFG, but can update forward dominator 235// (set, immediate dominators, tree, and frontier) information. 236// 237FunctionPass *createBreakCriticalEdgesPass(); 238extern char &BreakCriticalEdgesID; 239 240//===----------------------------------------------------------------------===// 241// 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. 245// 246// AU.addRequiredID(LoopSimplifyID); 247// 248Pass *createLoopSimplifyPass(); 249extern char &LoopSimplifyID; 250 251//===----------------------------------------------------------------------===// 252// 253// TailCallElimination - This pass eliminates call instructions to the current 254// function which occur immediately before return instructions. 255// 256FunctionPass *createTailCallEliminationPass(); 257 258//===----------------------------------------------------------------------===// 259// 260// LowerSwitch - This pass converts SwitchInst instructions into a sequence of 261// chained binary branch instructions. 262// 263FunctionPass *createLowerSwitchPass(); 264extern char &LowerSwitchID; 265 266//===----------------------------------------------------------------------===// 267// 268// LowerInvoke - This pass removes invoke instructions, converting them to call 269// instructions. 270// 271FunctionPass *createLowerInvokePass(); 272extern char &LowerInvokePassID; 273 274//===----------------------------------------------------------------------===// 275// 276// LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop 277// optimizations. 278// 279Pass *createLCSSAPass(); 280extern char &LCSSAID; 281 282//===----------------------------------------------------------------------===// 283// 284// EarlyCSE - This pass performs a simple and fast CSE pass over the dominator 285// tree. 286// 287FunctionPass *createEarlyCSEPass(); 288 289//===----------------------------------------------------------------------===// 290// 291// GVN - This pass performs global value numbering and redundant load 292// elimination cotemporaneously. 293// 294FunctionPass *createGVNPass(bool NoLoads = false); 295 296//===----------------------------------------------------------------------===// 297// 298// MemCpyOpt - This pass performs optimizations related to eliminating memcpy 299// calls and/or combining multiple stores into memset's. 300// 301FunctionPass *createMemCpyOptPass(); 302 303//===----------------------------------------------------------------------===// 304// 305// LoopDeletion - This pass performs DCE of non-infinite loops that it 306// can prove are dead. 307// 308Pass *createLoopDeletionPass(); 309 310//===----------------------------------------------------------------------===// 311// 312// ConstantHoisting - This pass prepares a function for expensive constants. 313// 314FunctionPass *createConstantHoistingPass(); 315 316//===----------------------------------------------------------------------===// 317// 318// InstructionNamer - Give any unnamed non-void instructions "tmp" names. 319// 320FunctionPass *createInstructionNamerPass(); 321extern char &InstructionNamerID; 322 323//===----------------------------------------------------------------------===// 324// 325// Sink - Code Sinking 326// 327FunctionPass *createSinkingPass(); 328 329//===----------------------------------------------------------------------===// 330// 331// LowerAtomic - Lower atomic intrinsics to non-atomic form 332// 333Pass *createLowerAtomicPass(); 334 335//===----------------------------------------------------------------------===// 336// 337// ValuePropagation - Propagate CFG-derived value information 338// 339Pass *createCorrelatedValuePropagationPass(); 340 341//===----------------------------------------------------------------------===// 342// 343// InstructionSimplifier - Remove redundant instructions. 344// 345FunctionPass *createInstructionSimplifierPass(); 346extern char &InstructionSimplifierID; 347 348//===----------------------------------------------------------------------===// 349// 350// LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates 351// "block_weights" metadata. 352FunctionPass *createLowerExpectIntrinsicPass(); 353 354//===----------------------------------------------------------------------===// 355// 356// PartiallyInlineLibCalls - Tries to inline the fast path of library 357// calls such as sqrt. 358// 359FunctionPass *createPartiallyInlineLibCallsPass(); 360 361//===----------------------------------------------------------------------===// 362// 363// SampleProfilePass - Loads sample profile data from disk and generates 364// IR metadata to reflect the profile. 365FunctionPass *createSampleProfileLoaderPass(); 366FunctionPass *createSampleProfileLoaderPass(StringRef Name); 367 368//===----------------------------------------------------------------------===// 369// 370// ScalarizerPass - Converts vector operations into scalar operations 371// 372FunctionPass *createScalarizerPass(); 373 374//===----------------------------------------------------------------------===// 375// 376// AddDiscriminators - Add DWARF path discriminators to the IR. 377FunctionPass *createAddDiscriminatorsPass(); 378 379//===----------------------------------------------------------------------===// 380// 381// SeparateConstOffsetFromGEP - Split GEPs for better CSE 382// 383FunctionPass *createSeparateConstOffsetFromGEPPass(); 384 385//===----------------------------------------------------------------------===// 386// 387// LoadCombine - Combine loads into bigger loads. 388// 389BasicBlockPass *createLoadCombinePass(); 390 391} // End llvm namespace 392 393#endif 394