1 //===-- Scalar.h - Scalar Transformations -----------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This header file defines prototypes for accessor functions that expose passes 10 // in the Scalar transformations library. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_TRANSFORMS_SCALAR_H 15 #define LLVM_TRANSFORMS_SCALAR_H 16 17 #include "llvm/Transforms/Utils/SimplifyCFGOptions.h" 18 #include <functional> 19 20 namespace llvm { 21 22 class Function; 23 class FunctionPass; 24 class ModulePass; 25 class Pass; 26 27 //===----------------------------------------------------------------------===// 28 // 29 // AlignmentFromAssumptions - Use assume intrinsics to set load/store 30 // alignments. 31 // 32 FunctionPass *createAlignmentFromAssumptionsPass(); 33 34 //===----------------------------------------------------------------------===// 35 // 36 // AnnotationRemarks - Emit remarks for !annotation metadata. 37 // 38 FunctionPass *createAnnotationRemarksLegacyPass(); 39 40 //===----------------------------------------------------------------------===// 41 // 42 // SCCP - Sparse conditional constant propagation. 43 // 44 FunctionPass *createSCCPPass(); 45 46 //===----------------------------------------------------------------------===// 47 // 48 // RedundantDbgInstElimination - This pass removes redundant dbg intrinsics 49 // without modifying the CFG of the function. It is a FunctionPass. 50 // 51 Pass *createRedundantDbgInstEliminationPass(); 52 53 //===----------------------------------------------------------------------===// 54 // 55 // DeadCodeElimination - This pass is more powerful than DeadInstElimination, 56 // because it is worklist driven that can potentially revisit instructions when 57 // their other instructions become dead, to eliminate chains of dead 58 // computations. 59 // 60 FunctionPass *createDeadCodeEliminationPass(); 61 62 //===----------------------------------------------------------------------===// 63 // 64 // DeadStoreElimination - This pass deletes stores that are post-dominated by 65 // must-aliased stores and are not loaded used between the stores. 66 // 67 FunctionPass *createDeadStoreEliminationPass(); 68 69 70 //===----------------------------------------------------------------------===// 71 // 72 // CallSiteSplitting - This pass split call-site based on its known argument 73 // values. 74 FunctionPass *createCallSiteSplittingPass(); 75 76 //===----------------------------------------------------------------------===// 77 // 78 // AggressiveDCE - This pass uses the SSA based Aggressive DCE algorithm. This 79 // algorithm assumes instructions are dead until proven otherwise, which makes 80 // it more successful are removing non-obviously dead instructions. 81 // 82 FunctionPass *createAggressiveDCEPass(); 83 84 //===----------------------------------------------------------------------===// 85 // 86 // GuardWidening - An optimization over the @llvm.experimental.guard intrinsic 87 // that (optimistically) combines multiple guards into one to have fewer checks 88 // at runtime. 89 // 90 FunctionPass *createGuardWideningPass(); 91 92 93 //===----------------------------------------------------------------------===// 94 // 95 // LoopGuardWidening - Analogous to the GuardWidening pass, but restricted to a 96 // single loop at a time for use within a LoopPassManager. Desired effect is 97 // to widen guards into preheader or a single guard within loop if that's not 98 // possible. 99 // 100 Pass *createLoopGuardWideningPass(); 101 102 103 //===----------------------------------------------------------------------===// 104 // 105 // BitTrackingDCE - This pass uses a bit-tracking DCE algorithm in order to 106 // remove computations of dead bits. 107 // 108 FunctionPass *createBitTrackingDCEPass(); 109 110 //===----------------------------------------------------------------------===// 111 // 112 // SROA - Replace aggregates or pieces of aggregates with scalar SSA values. 113 // 114 FunctionPass *createSROAPass(); 115 116 //===----------------------------------------------------------------------===// 117 // 118 // InductiveRangeCheckElimination - Transform loops to elide range checks on 119 // linear functions of the induction variable. 120 // 121 Pass *createInductiveRangeCheckEliminationPass(); 122 123 //===----------------------------------------------------------------------===// 124 // 125 // InductionVariableSimplify - Transform induction variables in a program to all 126 // use a single canonical induction variable per loop. 127 // 128 Pass *createIndVarSimplifyPass(); 129 130 //===----------------------------------------------------------------------===// 131 // 132 // LICM - This pass is a loop invariant code motion and memory promotion pass. 133 // 134 Pass *createLICMPass(); 135 Pass *createLICMPass(unsigned LicmMssaOptCap, 136 unsigned LicmMssaNoAccForPromotionCap, 137 bool AllowSpeculation); 138 139 //===----------------------------------------------------------------------===// 140 // 141 // LoopSink - This pass sinks invariants from preheader to loop body where 142 // frequency is lower than loop preheader. 143 // 144 Pass *createLoopSinkPass(); 145 146 //===----------------------------------------------------------------------===// 147 // 148 // LoopPredication - This pass does loop predication on guards. 149 // 150 Pass *createLoopPredicationPass(); 151 152 //===----------------------------------------------------------------------===// 153 // 154 // LoopInterchange - This pass interchanges loops to provide a more 155 // cache-friendly memory access patterns. 156 // 157 Pass *createLoopInterchangePass(); 158 159 //===----------------------------------------------------------------------===// 160 // 161 // LoopFlatten - This pass flattens nested loops into a single loop. 162 // 163 FunctionPass *createLoopFlattenPass(); 164 165 //===----------------------------------------------------------------------===// 166 // 167 // LoopStrengthReduce - This pass is strength reduces GEP instructions that use 168 // a loop's canonical induction variable as one of their indices. 169 // 170 Pass *createLoopStrengthReducePass(); 171 172 //===----------------------------------------------------------------------===// 173 // 174 // LoopInstSimplify - This pass simplifies instructions in a loop's body. 175 // 176 Pass *createLoopInstSimplifyPass(); 177 178 //===----------------------------------------------------------------------===// 179 // 180 // LoopUnroll - This pass is a simple loop unrolling pass. 181 // 182 Pass *createLoopUnrollPass(int OptLevel = 2, bool OnlyWhenForced = false, 183 bool ForgetAllSCEV = false, int Threshold = -1, 184 int Count = -1, int AllowPartial = -1, 185 int Runtime = -1, int UpperBound = -1, 186 int AllowPeeling = -1); 187 // Create an unrolling pass for full unrolling that uses exact trip count only 188 // and also does peeling. 189 Pass *createSimpleLoopUnrollPass(int OptLevel = 2, bool OnlyWhenForced = false, 190 bool ForgetAllSCEV = false); 191 192 //===----------------------------------------------------------------------===// 193 // 194 // LoopUnrollAndJam - This pass is a simple loop unroll and jam pass. 195 // 196 Pass *createLoopUnrollAndJamPass(int OptLevel = 2); 197 198 //===----------------------------------------------------------------------===// 199 // 200 // LoopReroll - This pass is a simple loop rerolling pass. 201 // 202 Pass *createLoopRerollPass(); 203 204 //===----------------------------------------------------------------------===// 205 // 206 // LoopRotate - This pass is a simple loop rotating pass. 207 // 208 Pass *createLoopRotatePass(int MaxHeaderSize = -1, bool PrepareForLTO = false); 209 210 //===----------------------------------------------------------------------===// 211 // 212 // LoopIdiom - This pass recognizes and replaces idioms in loops. 213 // 214 Pass *createLoopIdiomPass(); 215 216 //===----------------------------------------------------------------------===// 217 // 218 // LoopVersioningLICM - This pass is a loop versioning pass for LICM. 219 // 220 Pass *createLoopVersioningLICMPass(); 221 222 //===----------------------------------------------------------------------===// 223 // 224 // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory 225 // references. In basically undoes the PromoteMemoryToRegister pass to make cfg 226 // hacking easier. 227 // 228 FunctionPass *createDemoteRegisterToMemoryPass(); 229 extern char &DemoteRegisterToMemoryID; 230 231 //===----------------------------------------------------------------------===// 232 // 233 // Reassociate - This pass reassociates commutative expressions in an order that 234 // is designed to promote better constant propagation, GCSE, LICM, PRE... 235 // 236 // For example: 4 + (x + 5) -> x + (4 + 5) 237 // 238 FunctionPass *createReassociatePass(); 239 240 //===----------------------------------------------------------------------===// 241 // 242 // JumpThreading - Thread control through mult-pred/multi-succ blocks where some 243 // preds always go to some succ. Thresholds other than minus one 244 // override the internal BB duplication default threshold. 245 // 246 FunctionPass *createJumpThreadingPass(int Threshold = -1); 247 248 //===----------------------------------------------------------------------===// 249 // 250 // DFAJumpThreading - When a switch statement inside a loop is used to 251 // implement a deterministic finite automata we can jump thread the switch 252 // statement reducing number of conditional jumps. 253 // 254 FunctionPass *createDFAJumpThreadingPass(); 255 256 //===----------------------------------------------------------------------===// 257 // 258 // CFGSimplification - Merge basic blocks, eliminate unreachable blocks, 259 // simplify terminator instructions, convert switches to lookup tables, etc. 260 // 261 FunctionPass *createCFGSimplificationPass( 262 SimplifyCFGOptions Options = SimplifyCFGOptions(), 263 std::function<bool(const Function &)> Ftor = nullptr); 264 265 //===----------------------------------------------------------------------===// 266 // 267 // FlattenCFG - flatten CFG, reduce number of conditional branches by using 268 // parallel-and and parallel-or mode, etc... 269 // 270 FunctionPass *createFlattenCFGPass(); 271 272 //===----------------------------------------------------------------------===// 273 // 274 // CFG Structurization - Remove irreducible control flow 275 // 276 /// 277 /// When \p SkipUniformRegions is true the structizer will not structurize 278 /// regions that only contain uniform branches. 279 Pass *createStructurizeCFGPass(bool SkipUniformRegions = false); 280 281 //===----------------------------------------------------------------------===// 282 // 283 // TailCallElimination - This pass eliminates call instructions to the current 284 // function which occur immediately before return instructions. 285 // 286 FunctionPass *createTailCallEliminationPass(); 287 288 //===----------------------------------------------------------------------===// 289 // 290 // EarlyCSE - This pass performs a simple and fast CSE pass over the dominator 291 // tree. 292 // 293 FunctionPass *createEarlyCSEPass(bool UseMemorySSA = false); 294 295 //===----------------------------------------------------------------------===// 296 // 297 // GVNHoist - This pass performs a simple and fast GVN pass over the dominator 298 // tree to hoist common expressions from sibling branches. 299 // 300 FunctionPass *createGVNHoistPass(); 301 302 //===----------------------------------------------------------------------===// 303 // 304 // GVNSink - This pass uses an "inverted" value numbering to decide the 305 // similarity of expressions and sinks similar expressions into successors. 306 // 307 FunctionPass *createGVNSinkPass(); 308 309 //===----------------------------------------------------------------------===// 310 // 311 // MergedLoadStoreMotion - This pass merges loads and stores in diamonds. Loads 312 // are hoisted into the header, while stores sink into the footer. 313 // 314 FunctionPass *createMergedLoadStoreMotionPass(bool SplitFooterBB = false); 315 316 //===----------------------------------------------------------------------===// 317 // 318 // GVN - This pass performs global value numbering and redundant load 319 // elimination cotemporaneously. 320 // 321 FunctionPass *createNewGVNPass(); 322 323 //===----------------------------------------------------------------------===// 324 // 325 // DivRemPairs - Hoist/decompose integer division and remainder instructions. 326 // 327 FunctionPass *createDivRemPairsPass(); 328 329 //===----------------------------------------------------------------------===// 330 // 331 // MemCpyOpt - This pass performs optimizations related to eliminating memcpy 332 // calls and/or combining multiple stores into memset's. 333 // 334 FunctionPass *createMemCpyOptPass(); 335 336 //===----------------------------------------------------------------------===// 337 // 338 // LoopDeletion - This pass performs DCE of non-infinite loops that it 339 // can prove are dead. 340 // 341 Pass *createLoopDeletionPass(); 342 343 //===----------------------------------------------------------------------===// 344 // 345 // ConstantHoisting - This pass prepares a function for expensive constants. 346 // 347 FunctionPass *createConstantHoistingPass(); 348 349 //===----------------------------------------------------------------------===// 350 // 351 // ConstraintElimination - This pass eliminates conditions based on found 352 // constraints. 353 // 354 FunctionPass *createConstraintEliminationPass(); 355 356 //===----------------------------------------------------------------------===// 357 // 358 // Sink - Code Sinking 359 // 360 FunctionPass *createSinkingPass(); 361 362 //===----------------------------------------------------------------------===// 363 // 364 // LowerAtomic - Lower atomic intrinsics to non-atomic form 365 // 366 Pass *createLowerAtomicPass(); 367 368 //===----------------------------------------------------------------------===// 369 // 370 // LowerGuardIntrinsic - Lower guard intrinsics to normal control flow. 371 // 372 Pass *createLowerGuardIntrinsicPass(); 373 374 //===----------------------------------------------------------------------===// 375 // 376 // LowerMatrixIntrinsics - Lower matrix intrinsics to vector operations. 377 // 378 Pass *createLowerMatrixIntrinsicsPass(); 379 380 //===----------------------------------------------------------------------===// 381 // 382 // LowerMatrixIntrinsicsMinimal - Lower matrix intrinsics to vector operations 383 // (lightweight, does not require extra analysis) 384 // 385 Pass *createLowerMatrixIntrinsicsMinimalPass(); 386 387 //===----------------------------------------------------------------------===// 388 // 389 // LowerWidenableCondition - Lower widenable condition to i1 true. 390 // 391 Pass *createLowerWidenableConditionPass(); 392 393 //===----------------------------------------------------------------------===// 394 // 395 // MergeICmps - Merge integer comparison chains into a memcmp 396 // 397 Pass *createMergeICmpsLegacyPass(); 398 399 //===----------------------------------------------------------------------===// 400 // 401 // ValuePropagation - Propagate CFG-derived value information 402 // 403 Pass *createCorrelatedValuePropagationPass(); 404 405 //===----------------------------------------------------------------------===// 406 // 407 // InferAddressSpaces - Modify users of addrspacecast instructions with values 408 // in the source address space if using the destination address space is slower 409 // on the target. If AddressSpace is left to its default value, it will be 410 // obtained from the TargetTransformInfo. 411 // 412 FunctionPass *createInferAddressSpacesPass(unsigned AddressSpace = ~0u); 413 extern char &InferAddressSpacesID; 414 415 //===----------------------------------------------------------------------===// 416 // 417 // LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates 418 // "block_weights" metadata. 419 FunctionPass *createLowerExpectIntrinsicPass(); 420 421 //===----------------------------------------------------------------------===// 422 // 423 // TLSVariableHoist - This pass reduce duplicated TLS address call. 424 // 425 FunctionPass *createTLSVariableHoistPass(); 426 427 //===----------------------------------------------------------------------===// 428 // 429 // LowerConstantIntrinsicss - Expand any remaining llvm.objectsize and 430 // llvm.is.constant intrinsic calls, even for the unknown cases. 431 // 432 FunctionPass *createLowerConstantIntrinsicsPass(); 433 434 //===----------------------------------------------------------------------===// 435 // 436 // PartiallyInlineLibCalls - Tries to inline the fast path of library 437 // calls such as sqrt. 438 // 439 FunctionPass *createPartiallyInlineLibCallsPass(); 440 441 //===----------------------------------------------------------------------===// 442 // 443 // SeparateConstOffsetFromGEP - Split GEPs for better CSE 444 // 445 FunctionPass *createSeparateConstOffsetFromGEPPass(bool LowerGEP = false); 446 447 //===----------------------------------------------------------------------===// 448 // 449 // SpeculativeExecution - Aggressively hoist instructions to enable 450 // speculative execution on targets where branches are expensive. 451 // 452 FunctionPass *createSpeculativeExecutionPass(); 453 454 // Same as createSpeculativeExecutionPass, but does nothing unless 455 // TargetTransformInfo::hasBranchDivergence() is true. 456 FunctionPass *createSpeculativeExecutionIfHasBranchDivergencePass(); 457 458 //===----------------------------------------------------------------------===// 459 // 460 // StraightLineStrengthReduce - This pass strength-reduces some certain 461 // instruction patterns in straight-line code. 462 // 463 FunctionPass *createStraightLineStrengthReducePass(); 464 465 //===----------------------------------------------------------------------===// 466 // 467 // PlaceSafepoints - Rewrite any IR calls to gc.statepoints and insert any 468 // safepoint polls (method entry, backedge) that might be required. This pass 469 // does not generate explicit relocation sequences - that's handled by 470 // RewriteStatepointsForGC which can be run at an arbitrary point in the pass 471 // order following this pass. 472 // 473 FunctionPass *createPlaceSafepointsPass(); 474 475 //===----------------------------------------------------------------------===// 476 // 477 // RewriteStatepointsForGC - Rewrite any gc.statepoints which do not yet have 478 // explicit relocations to include explicit relocations. 479 // 480 ModulePass *createRewriteStatepointsForGCLegacyPass(); 481 482 //===----------------------------------------------------------------------===// 483 // 484 // Float2Int - Demote floats to ints where possible. 485 // 486 FunctionPass *createFloat2IntPass(); 487 488 //===----------------------------------------------------------------------===// 489 // 490 // NaryReassociate - Simplify n-ary operations by reassociation. 491 // 492 FunctionPass *createNaryReassociatePass(); 493 494 //===----------------------------------------------------------------------===// 495 // 496 // LoopDistribute - Distribute loops. 497 // 498 FunctionPass *createLoopDistributePass(); 499 500 //===----------------------------------------------------------------------===// 501 // 502 // LoopFuse - Fuse loops. 503 // 504 FunctionPass *createLoopFusePass(); 505 506 //===----------------------------------------------------------------------===// 507 // 508 // LoopLoadElimination - Perform loop-aware load elimination. 509 // 510 FunctionPass *createLoopLoadEliminationPass(); 511 512 //===----------------------------------------------------------------------===// 513 // 514 // LoopVersioning - Perform loop multi-versioning. 515 // 516 FunctionPass *createLoopVersioningPass(); 517 518 //===----------------------------------------------------------------------===// 519 // 520 // LoopDataPrefetch - Perform data prefetching in loops. 521 // 522 FunctionPass *createLoopDataPrefetchPass(); 523 524 //===----------------------------------------------------------------------===// 525 // 526 // LibCallsShrinkWrap - Shrink-wraps a call to function if the result is not 527 // used. 528 // 529 FunctionPass *createLibCallsShrinkWrapPass(); 530 531 //===----------------------------------------------------------------------===// 532 // 533 // LoopSimplifyCFG - This pass performs basic CFG simplification on loops, 534 // primarily to help other loop passes. 535 // 536 Pass *createLoopSimplifyCFGPass(); 537 538 //===----------------------------------------------------------------------===// 539 // 540 // WarnMissedTransformations - This pass emits warnings for leftover forced 541 // transformations. 542 // 543 Pass *createWarnMissedTransformationsPass(); 544 545 //===----------------------------------------------------------------------===// 546 // 547 // This pass does instruction simplification on each 548 // instruction in a function. 549 // 550 FunctionPass *createInstSimplifyLegacyPass(); 551 552 553 //===----------------------------------------------------------------------===// 554 // 555 // createScalarizeMaskedMemIntrinPass - Replace masked load, store, gather 556 // and scatter intrinsics with scalar code when target doesn't support them. 557 // 558 FunctionPass *createScalarizeMaskedMemIntrinLegacyPass(); 559 } // End llvm namespace 560 561 #endif 562