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