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