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 ModulePass; 25class Pass; 26class GetElementPtrInst; 27class PassInfo; 28class TerminatorInst; 29class TargetLowering; 30class TargetMachine; 31 32//===----------------------------------------------------------------------===// 33// 34// ConstantPropagation - A worklist driven constant propagation pass 35// 36FunctionPass *createConstantPropagationPass(); 37 38//===----------------------------------------------------------------------===// 39// 40// AlignmentFromAssumptions - Use assume intrinsics to set load/store 41// alignments. 42// 43FunctionPass *createAlignmentFromAssumptionsPass(); 44 45//===----------------------------------------------------------------------===// 46// 47// SCCP - Sparse conditional constant propagation. 48// 49FunctionPass *createSCCPPass(); 50 51//===----------------------------------------------------------------------===// 52// 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. 56// 57Pass *createDeadInstEliminationPass(); 58 59//===----------------------------------------------------------------------===// 60// 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 64// computations. 65// 66FunctionPass *createDeadCodeEliminationPass(); 67 68//===----------------------------------------------------------------------===// 69// 70// DeadStoreElimination - This pass deletes stores that are post-dominated by 71// must-aliased stores and are not loaded used between the stores. 72// 73FunctionPass *createDeadStoreEliminationPass(); 74 75//===----------------------------------------------------------------------===// 76// 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. 80// 81FunctionPass *createAggressiveDCEPass(); 82 83//===----------------------------------------------------------------------===// 84// 85// BitTrackingDCE - This pass uses a bit-tracking DCE algorithm in order to 86// remove computations of dead bits. 87// 88FunctionPass *createBitTrackingDCEPass(); 89 90//===----------------------------------------------------------------------===// 91// 92// SROA - Replace aggregates or pieces of aggregates with scalar SSA values. 93// 94FunctionPass *createSROAPass(bool RequiresDomTree = true); 95 96//===----------------------------------------------------------------------===// 97// 98// ScalarReplAggregates - Break up alloca's of aggregates into multiple allocas 99// if possible. 100// 101FunctionPass *createScalarReplAggregatesPass(signed Threshold = -1, 102 bool UseDomTree = true, 103 signed StructMemberThreshold = -1, 104 signed ArrayElementThreshold = -1, 105 signed ScalarLoadThreshold = -1); 106 107//===----------------------------------------------------------------------===// 108// 109// InductiveRangeCheckElimination - Transform loops to elide range checks on 110// linear functions of the induction variable. 111// 112Pass *createInductiveRangeCheckEliminationPass(); 113 114//===----------------------------------------------------------------------===// 115// 116// InductionVariableSimplify - Transform induction variables in a program to all 117// use a single canonical induction variable per loop. 118// 119Pass *createIndVarSimplifyPass(); 120 121//===----------------------------------------------------------------------===// 122// 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. 126// 127// This pass combines things like: 128// %Y = add int 1, %X 129// %Z = add int 1, %Y 130// into: 131// %Z = add int 2, %X 132// 133FunctionPass *createInstructionCombiningPass(); 134 135//===----------------------------------------------------------------------===// 136// 137// LICM - This pass is a loop invariant code motion and memory promotion pass. 138// 139Pass *createLICMPass(); 140 141//===----------------------------------------------------------------------===// 142// 143// LoopInterchange - This pass interchanges loops to provide a more 144// cache-friendly memory access patterns. 145// 146Pass *createLoopInterchangePass(); 147 148//===----------------------------------------------------------------------===// 149// 150// LoopStrengthReduce - This pass is strength reduces GEP instructions that use 151// a loop's canonical induction variable as one of their indices. 152// 153Pass *createLoopStrengthReducePass(); 154 155Pass *createGlobalMergePass(const TargetMachine *TM, unsigned MaximalOffset); 156 157//===----------------------------------------------------------------------===// 158// 159// LoopUnswitch - This pass is a simple loop unswitching pass. 160// 161Pass *createLoopUnswitchPass(bool OptimizeForSize = false); 162 163//===----------------------------------------------------------------------===// 164// 165// LoopInstSimplify - This pass simplifies instructions in a loop's body. 166// 167Pass *createLoopInstSimplifyPass(); 168 169//===----------------------------------------------------------------------===// 170// 171// LoopUnroll - This pass is a simple loop unrolling pass. 172// 173Pass *createLoopUnrollPass(int Threshold = -1, int Count = -1, 174 int AllowPartial = -1, int Runtime = -1); 175// Create an unrolling pass for full unrolling only. 176Pass *createSimpleLoopUnrollPass(); 177 178//===----------------------------------------------------------------------===// 179// 180// LoopReroll - This pass is a simple loop rerolling pass. 181// 182Pass *createLoopRerollPass(); 183 184//===----------------------------------------------------------------------===// 185// 186// LoopRotate - This pass is a simple loop rotating pass. 187// 188Pass *createLoopRotatePass(int MaxHeaderSize = -1); 189 190//===----------------------------------------------------------------------===// 191// 192// LoopIdiom - This pass recognizes and replaces idioms in loops. 193// 194Pass *createLoopIdiomPass(); 195 196//===----------------------------------------------------------------------===// 197// 198// PromoteMemoryToRegister - This pass is used to promote memory references to 199// be register references. A simple example of the transformation performed by 200// this pass is: 201// 202// FROM CODE TO CODE 203// %X = alloca i32, i32 1 ret i32 42 204// store i32 42, i32 *%X 205// %Y = load i32* %X 206// ret i32 %Y 207// 208FunctionPass *createPromoteMemoryToRegisterPass(); 209 210//===----------------------------------------------------------------------===// 211// 212// DemoteRegisterToMemoryPass - This pass is used to demote registers to memory 213// references. In basically undoes the PromoteMemoryToRegister pass to make cfg 214// hacking easier. 215// 216FunctionPass *createDemoteRegisterToMemoryPass(); 217extern char &DemoteRegisterToMemoryID; 218 219//===----------------------------------------------------------------------===// 220// 221// Reassociate - This pass reassociates commutative expressions in an order that 222// is designed to promote better constant propagation, GCSE, LICM, PRE... 223// 224// For example: 4 + (x + 5) -> x + (4 + 5) 225// 226FunctionPass *createReassociatePass(); 227 228//===----------------------------------------------------------------------===// 229// 230// JumpThreading - Thread control through mult-pred/multi-succ blocks where some 231// preds always go to some succ. Thresholds other than minus one override the 232// internal BB duplication default threshold. 233// 234FunctionPass *createJumpThreadingPass(int Threshold = -1); 235 236//===----------------------------------------------------------------------===// 237// 238// CFGSimplification - Merge basic blocks, eliminate unreachable blocks, 239// simplify terminator instructions, etc... 240// 241FunctionPass *createCFGSimplificationPass(int Threshold = -1); 242 243//===----------------------------------------------------------------------===// 244// 245// FlattenCFG - flatten CFG, reduce number of conditional branches by using 246// parallel-and and parallel-or mode, etc... 247// 248FunctionPass *createFlattenCFGPass(); 249 250//===----------------------------------------------------------------------===// 251// 252// CFG Structurization - Remove irreducible control flow 253// 254Pass *createStructurizeCFGPass(); 255 256//===----------------------------------------------------------------------===// 257// 258// BreakCriticalEdges - Break all of the critical edges in the CFG by inserting 259// a dummy basic block. This pass may be "required" by passes that cannot deal 260// with critical edges. For this usage, a pass must call: 261// 262// AU.addRequiredID(BreakCriticalEdgesID); 263// 264// This pass obviously invalidates the CFG, but can update forward dominator 265// (set, immediate dominators, tree, and frontier) information. 266// 267FunctionPass *createBreakCriticalEdgesPass(); 268extern char &BreakCriticalEdgesID; 269 270//===----------------------------------------------------------------------===// 271// 272// LoopSimplify - Insert Pre-header blocks into the CFG for every function in 273// the module. This pass updates dominator information, loop information, and 274// does not add critical edges to the CFG. 275// 276// AU.addRequiredID(LoopSimplifyID); 277// 278Pass *createLoopSimplifyPass(); 279extern char &LoopSimplifyID; 280 281//===----------------------------------------------------------------------===// 282// 283// TailCallElimination - This pass eliminates call instructions to the current 284// function which occur immediately before return instructions. 285// 286FunctionPass *createTailCallEliminationPass(); 287 288//===----------------------------------------------------------------------===// 289// 290// LowerSwitch - This pass converts SwitchInst instructions into a sequence of 291// chained binary branch instructions. 292// 293FunctionPass *createLowerSwitchPass(); 294extern char &LowerSwitchID; 295 296//===----------------------------------------------------------------------===// 297// 298// LowerInvoke - This pass removes invoke instructions, converting them to call 299// instructions. 300// 301FunctionPass *createLowerInvokePass(); 302extern char &LowerInvokePassID; 303 304//===----------------------------------------------------------------------===// 305// 306// LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop 307// optimizations. 308// 309Pass *createLCSSAPass(); 310extern char &LCSSAID; 311 312//===----------------------------------------------------------------------===// 313// 314// EarlyCSE - This pass performs a simple and fast CSE pass over the dominator 315// tree. 316// 317FunctionPass *createEarlyCSEPass(); 318 319//===----------------------------------------------------------------------===// 320// 321// MergedLoadStoreMotion - This pass merges loads and stores in diamonds. Loads 322// are hoisted into the header, while stores sink into the footer. 323// 324FunctionPass *createMergedLoadStoreMotionPass(); 325 326//===----------------------------------------------------------------------===// 327// 328// GVN - This pass performs global value numbering and redundant load 329// elimination cotemporaneously. 330// 331FunctionPass *createGVNPass(bool NoLoads = false); 332 333//===----------------------------------------------------------------------===// 334// 335// MemCpyOpt - This pass performs optimizations related to eliminating memcpy 336// calls and/or combining multiple stores into memset's. 337// 338FunctionPass *createMemCpyOptPass(); 339 340//===----------------------------------------------------------------------===// 341// 342// LoopDeletion - This pass performs DCE of non-infinite loops that it 343// can prove are dead. 344// 345Pass *createLoopDeletionPass(); 346 347//===----------------------------------------------------------------------===// 348// 349// ConstantHoisting - This pass prepares a function for expensive constants. 350// 351FunctionPass *createConstantHoistingPass(); 352 353//===----------------------------------------------------------------------===// 354// 355// InstructionNamer - Give any unnamed non-void instructions "tmp" names. 356// 357FunctionPass *createInstructionNamerPass(); 358extern char &InstructionNamerID; 359 360//===----------------------------------------------------------------------===// 361// 362// Sink - Code Sinking 363// 364FunctionPass *createSinkingPass(); 365 366//===----------------------------------------------------------------------===// 367// 368// LowerAtomic - Lower atomic intrinsics to non-atomic form 369// 370Pass *createLowerAtomicPass(); 371 372//===----------------------------------------------------------------------===// 373// 374// ValuePropagation - Propagate CFG-derived value information 375// 376Pass *createCorrelatedValuePropagationPass(); 377 378//===----------------------------------------------------------------------===// 379// 380// InstructionSimplifier - Remove redundant instructions. 381// 382FunctionPass *createInstructionSimplifierPass(); 383extern char &InstructionSimplifierID; 384 385//===----------------------------------------------------------------------===// 386// 387// LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates 388// "block_weights" metadata. 389FunctionPass *createLowerExpectIntrinsicPass(); 390 391//===----------------------------------------------------------------------===// 392// 393// PartiallyInlineLibCalls - Tries to inline the fast path of library 394// calls such as sqrt. 395// 396FunctionPass *createPartiallyInlineLibCallsPass(); 397 398//===----------------------------------------------------------------------===// 399// 400// SampleProfilePass - Loads sample profile data from disk and generates 401// IR metadata to reflect the profile. 402FunctionPass *createSampleProfileLoaderPass(); 403FunctionPass *createSampleProfileLoaderPass(StringRef Name); 404 405//===----------------------------------------------------------------------===// 406// 407// ScalarizerPass - Converts vector operations into scalar operations 408// 409FunctionPass *createScalarizerPass(); 410 411//===----------------------------------------------------------------------===// 412// 413// AddDiscriminators - Add DWARF path discriminators to the IR. 414FunctionPass *createAddDiscriminatorsPass(); 415 416//===----------------------------------------------------------------------===// 417// 418// SeparateConstOffsetFromGEP - Split GEPs for better CSE 419// 420FunctionPass * 421createSeparateConstOffsetFromGEPPass(const TargetMachine *TM = nullptr, 422 bool LowerGEP = false); 423 424//===----------------------------------------------------------------------===// 425// 426// LoadCombine - Combine loads into bigger loads. 427// 428BasicBlockPass *createLoadCombinePass(); 429 430//===----------------------------------------------------------------------===// 431// 432// StraightLineStrengthReduce - This pass strength-reduces some certain 433// instruction patterns in straight-line code. 434// 435FunctionPass *createStraightLineStrengthReducePass(); 436 437//===----------------------------------------------------------------------===// 438// 439// PlaceSafepoints - Rewrite any IR calls to gc.statepoints and insert any 440// safepoint polls (method entry, backedge) that might be required. This pass 441// does not generate explicit relocation sequences - that's handled by 442// RewriteStatepointsForGC which can be run at an arbitrary point in the pass 443// order following this pass. 444// 445ModulePass *createPlaceSafepointsPass(); 446 447//===----------------------------------------------------------------------===// 448// 449// RewriteStatepointsForGC - Rewrite any gc.statepoints which do not yet have 450// explicit relocations to include explicit relocations. 451// 452FunctionPass *createRewriteStatepointsForGCPass(); 453 454//===----------------------------------------------------------------------===// 455// 456// Float2Int - Demote floats to ints where possible. 457// 458FunctionPass *createFloat2IntPass(); 459 460//===----------------------------------------------------------------------===// 461// 462// NaryReassociate - Simplify n-ary operations by reassociation. 463// 464FunctionPass *createNaryReassociatePass(); 465 466} // End llvm namespace 467 468#endif 469