Home | History | Annotate | Download | only in Transforms
      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 <functional>
     19 
     20 namespace llvm {
     21 
     22 class BasicBlockPass;
     23 class Function;
     24 class FunctionPass;
     25 class ModulePass;
     26 class Pass;
     27 class GetElementPtrInst;
     28 class PassInfo;
     29 class TerminatorInst;
     30 class TargetLowering;
     31 class TargetMachine;
     32 
     33 //===----------------------------------------------------------------------===//
     34 //
     35 // ConstantPropagation - A worklist driven constant propagation pass
     36 //
     37 FunctionPass *createConstantPropagationPass();
     38 
     39 //===----------------------------------------------------------------------===//
     40 //
     41 // AlignmentFromAssumptions - Use assume intrinsics to set load/store
     42 // alignments.
     43 //
     44 FunctionPass *createAlignmentFromAssumptionsPass();
     45 
     46 //===----------------------------------------------------------------------===//
     47 //
     48 // SCCP - Sparse conditional constant propagation.
     49 //
     50 FunctionPass *createSCCPPass();
     51 
     52 //===----------------------------------------------------------------------===//
     53 //
     54 // DeadInstElimination - This pass quickly removes trivially dead instructions
     55 // without modifying the CFG of the function.  It is a BasicBlockPass, so it
     56 // runs efficiently when queued next to other BasicBlockPass's.
     57 //
     58 Pass *createDeadInstEliminationPass();
     59 
     60 //===----------------------------------------------------------------------===//
     61 //
     62 // DeadCodeElimination - This pass is more powerful than DeadInstElimination,
     63 // because it is worklist driven that can potentially revisit instructions when
     64 // their other instructions become dead, to eliminate chains of dead
     65 // computations.
     66 //
     67 FunctionPass *createDeadCodeEliminationPass();
     68 
     69 //===----------------------------------------------------------------------===//
     70 //
     71 // DeadStoreElimination - This pass deletes stores that are post-dominated by
     72 // must-aliased stores and are not loaded used between the stores.
     73 //
     74 FunctionPass *createDeadStoreEliminationPass();
     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 //
     87 // GuardWidening - An optimization over the @llvm.experimental.guard intrinsic
     88 // that (optimistically) combines multiple guards into one to have fewer checks
     89 // at runtime.
     90 //
     91 FunctionPass *createGuardWideningPass();
     92 
     93 
     94 //===----------------------------------------------------------------------===//
     95 //
     96 // BitTrackingDCE - This pass uses a bit-tracking DCE algorithm in order to
     97 // remove computations of dead bits.
     98 //
     99 FunctionPass *createBitTrackingDCEPass();
    100 
    101 //===----------------------------------------------------------------------===//
    102 //
    103 // SROA - Replace aggregates or pieces of aggregates with scalar SSA values.
    104 //
    105 FunctionPass *createSROAPass();
    106 
    107 //===----------------------------------------------------------------------===//
    108 //
    109 // InductiveRangeCheckElimination - Transform loops to elide range checks on
    110 // linear functions of the induction variable.
    111 //
    112 Pass *createInductiveRangeCheckEliminationPass();
    113 
    114 //===----------------------------------------------------------------------===//
    115 //
    116 // InductionVariableSimplify - Transform induction variables in a program to all
    117 // use a single canonical induction variable per loop.
    118 //
    119 Pass *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 //
    133 FunctionPass *createInstructionCombiningPass(bool ExpensiveCombines = true);
    134 
    135 //===----------------------------------------------------------------------===//
    136 //
    137 // LICM - This pass is a loop invariant code motion and memory promotion pass.
    138 //
    139 Pass *createLICMPass();
    140 
    141 //===----------------------------------------------------------------------===//
    142 //
    143 // LoopSink - This pass sinks invariants from preheader to loop body where
    144 // frequency is lower than loop preheader.
    145 //
    146 Pass *createLoopSinkPass();
    147 
    148 //===----------------------------------------------------------------------===//
    149 //
    150 // LoopPredication - This pass does loop predication on guards.
    151 //
    152 Pass *createLoopPredicationPass();
    153 
    154 //===----------------------------------------------------------------------===//
    155 //
    156 // LoopInterchange - This pass interchanges loops to provide a more
    157 // cache-friendly memory access patterns.
    158 //
    159 Pass *createLoopInterchangePass();
    160 
    161 //===----------------------------------------------------------------------===//
    162 //
    163 // LoopStrengthReduce - This pass is strength reduces GEP instructions that use
    164 // a loop's canonical induction variable as one of their indices.
    165 //
    166 Pass *createLoopStrengthReducePass();
    167 
    168 //===----------------------------------------------------------------------===//
    169 //
    170 // LoopUnswitch - This pass is a simple loop unswitching pass.
    171 //
    172 Pass *createLoopUnswitchPass(bool OptimizeForSize = false,
    173                              bool hasBranchDivergence = false);
    174 
    175 //===----------------------------------------------------------------------===//
    176 //
    177 // LoopInstSimplify - This pass simplifies instructions in a loop's body.
    178 //
    179 Pass *createLoopInstSimplifyPass();
    180 
    181 //===----------------------------------------------------------------------===//
    182 //
    183 // LoopUnroll - This pass is a simple loop unrolling pass.
    184 //
    185 Pass *createLoopUnrollPass(int OptLevel = 2, int Threshold = -1, int Count = -1,
    186                            int AllowPartial = -1, int Runtime = -1,
    187                            int UpperBound = -1, int AllowPeeling = -1);
    188 // Create an unrolling pass for full unrolling that uses exact trip count only.
    189 Pass *createSimpleLoopUnrollPass(int OptLevel = 2);
    190 
    191 //===----------------------------------------------------------------------===//
    192 //
    193 // LoopReroll - This pass is a simple loop rerolling pass.
    194 //
    195 Pass *createLoopRerollPass();
    196 
    197 //===----------------------------------------------------------------------===//
    198 //
    199 // LoopRotate - This pass is a simple loop rotating pass.
    200 //
    201 Pass *createLoopRotatePass(int MaxHeaderSize = -1);
    202 
    203 //===----------------------------------------------------------------------===//
    204 //
    205 // LoopIdiom - This pass recognizes and replaces idioms in loops.
    206 //
    207 Pass *createLoopIdiomPass();
    208 
    209 //===----------------------------------------------------------------------===//
    210 //
    211 // LoopVersioningLICM - This pass is a loop versioning pass for LICM.
    212 //
    213 Pass *createLoopVersioningLICMPass();
    214 
    215 //===----------------------------------------------------------------------===//
    216 //
    217 // PromoteMemoryToRegister - This pass is used to promote memory references to
    218 // be register references. A simple example of the transformation performed by
    219 // this pass is:
    220 //
    221 //        FROM CODE                           TO CODE
    222 //   %X = alloca i32, i32 1                 ret i32 42
    223 //   store i32 42, i32 *%X
    224 //   %Y = load i32* %X
    225 //   ret i32 %Y
    226 //
    227 FunctionPass *createPromoteMemoryToRegisterPass();
    228 
    229 //===----------------------------------------------------------------------===//
    230 //
    231 // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
    232 // references. In basically undoes the PromoteMemoryToRegister pass to make cfg
    233 // hacking easier.
    234 //
    235 FunctionPass *createDemoteRegisterToMemoryPass();
    236 extern char &DemoteRegisterToMemoryID;
    237 
    238 //===----------------------------------------------------------------------===//
    239 //
    240 // Reassociate - This pass reassociates commutative expressions in an order that
    241 // is designed to promote better constant propagation, GCSE, LICM, PRE...
    242 //
    243 // For example:  4 + (x + 5)  ->  x + (4 + 5)
    244 //
    245 FunctionPass *createReassociatePass();
    246 
    247 //===----------------------------------------------------------------------===//
    248 //
    249 // JumpThreading - Thread control through mult-pred/multi-succ blocks where some
    250 // preds always go to some succ. Thresholds other than minus one override the
    251 // internal BB duplication default threshold.
    252 //
    253 FunctionPass *createJumpThreadingPass(int Threshold = -1);
    254 
    255 //===----------------------------------------------------------------------===//
    256 //
    257 // CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
    258 // simplify terminator instructions, etc...
    259 //
    260 FunctionPass *createCFGSimplificationPass(
    261     int Threshold = -1, std::function<bool(const Function &)> Ftor = nullptr);
    262 
    263 //===----------------------------------------------------------------------===//
    264 //
    265 // LateCFGSimplification - Like CFGSimplification, but may also
    266 // convert switches to lookup tables.
    267 //
    268 FunctionPass *createLateCFGSimplificationPass(
    269     int Threshold = -1, std::function<bool(const Function &)> Ftor = nullptr);
    270 
    271 //===----------------------------------------------------------------------===//
    272 //
    273 // FlattenCFG - flatten CFG, reduce number of conditional branches by using
    274 // parallel-and and parallel-or mode, etc...
    275 //
    276 FunctionPass *createFlattenCFGPass();
    277 
    278 //===----------------------------------------------------------------------===//
    279 //
    280 // CFG Structurization - Remove irreducible control flow
    281 //
    282 ///
    283 /// When \p SkipUniformRegions is true the structizer will not structurize
    284 /// regions that only contain uniform branches.
    285 Pass *createStructurizeCFGPass(bool SkipUniformRegions = false);
    286 
    287 //===----------------------------------------------------------------------===//
    288 //
    289 // BreakCriticalEdges - Break all of the critical edges in the CFG by inserting
    290 // a dummy basic block. This pass may be "required" by passes that cannot deal
    291 // with critical edges. For this usage, a pass must call:
    292 //
    293 //   AU.addRequiredID(BreakCriticalEdgesID);
    294 //
    295 // This pass obviously invalidates the CFG, but can update forward dominator
    296 // (set, immediate dominators, tree, and frontier) information.
    297 //
    298 FunctionPass *createBreakCriticalEdgesPass();
    299 extern char &BreakCriticalEdgesID;
    300 
    301 //===----------------------------------------------------------------------===//
    302 //
    303 // LoopSimplify - Insert Pre-header blocks into the CFG for every function in
    304 // the module.  This pass updates dominator information, loop information, and
    305 // does not add critical edges to the CFG.
    306 //
    307 //   AU.addRequiredID(LoopSimplifyID);
    308 //
    309 Pass *createLoopSimplifyPass();
    310 extern char &LoopSimplifyID;
    311 
    312 //===----------------------------------------------------------------------===//
    313 //
    314 // TailCallElimination - This pass eliminates call instructions to the current
    315 // function which occur immediately before return instructions.
    316 //
    317 FunctionPass *createTailCallEliminationPass();
    318 
    319 //===----------------------------------------------------------------------===//
    320 //
    321 // LowerSwitch - This pass converts SwitchInst instructions into a sequence of
    322 // chained binary branch instructions.
    323 //
    324 FunctionPass *createLowerSwitchPass();
    325 extern char &LowerSwitchID;
    326 
    327 //===----------------------------------------------------------------------===//
    328 //
    329 // LowerInvoke - This pass removes invoke instructions, converting them to call
    330 // instructions.
    331 //
    332 FunctionPass *createLowerInvokePass();
    333 extern char &LowerInvokePassID;
    334 
    335 //===----------------------------------------------------------------------===//
    336 //
    337 // LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop
    338 // optimizations.
    339 //
    340 Pass *createLCSSAPass();
    341 extern char &LCSSAID;
    342 
    343 //===----------------------------------------------------------------------===//
    344 //
    345 // EarlyCSE - This pass performs a simple and fast CSE pass over the dominator
    346 // tree.
    347 //
    348 FunctionPass *createEarlyCSEPass(bool UseMemorySSA = false);
    349 
    350 //===----------------------------------------------------------------------===//
    351 //
    352 // GVNHoist - This pass performs a simple and fast GVN pass over the dominator
    353 // tree to hoist common expressions from sibling branches.
    354 //
    355 FunctionPass *createGVNHoistPass();
    356 
    357 //===----------------------------------------------------------------------===//
    358 //
    359 // GVNSink - This pass uses an "inverted" value numbering to decide the
    360 // similarity of expressions and sinks similar expressions into successors.
    361 //
    362 FunctionPass *createGVNSinkPass();
    363 
    364 //===----------------------------------------------------------------------===//
    365 //
    366 // MergedLoadStoreMotion - This pass merges loads and stores in diamonds. Loads
    367 // are hoisted into the header, while stores sink into the footer.
    368 //
    369 FunctionPass *createMergedLoadStoreMotionPass();
    370 
    371 //===----------------------------------------------------------------------===//
    372 //
    373 // GVN - This pass performs global value numbering and redundant load
    374 // elimination cotemporaneously.
    375 //
    376 FunctionPass *createNewGVNPass();
    377 
    378 //===----------------------------------------------------------------------===//
    379 //
    380 // DivRemPairs - Hoist/decompose integer division and remainder instructions.
    381 //
    382 FunctionPass *createDivRemPairsPass();
    383 
    384 //===----------------------------------------------------------------------===//
    385 //
    386 // MemCpyOpt - This pass performs optimizations related to eliminating memcpy
    387 // calls and/or combining multiple stores into memset's.
    388 //
    389 FunctionPass *createMemCpyOptPass();
    390 
    391 //===----------------------------------------------------------------------===//
    392 //
    393 // LoopDeletion - This pass performs DCE of non-infinite loops that it
    394 // can prove are dead.
    395 //
    396 Pass *createLoopDeletionPass();
    397 
    398 //===----------------------------------------------------------------------===//
    399 //
    400 // ConstantHoisting - This pass prepares a function for expensive constants.
    401 //
    402 FunctionPass *createConstantHoistingPass();
    403 
    404 //===----------------------------------------------------------------------===//
    405 //
    406 // InstructionNamer - Give any unnamed non-void instructions "tmp" names.
    407 //
    408 FunctionPass *createInstructionNamerPass();
    409 extern char &InstructionNamerID;
    410 
    411 //===----------------------------------------------------------------------===//
    412 //
    413 // Sink - Code Sinking
    414 //
    415 FunctionPass *createSinkingPass();
    416 
    417 //===----------------------------------------------------------------------===//
    418 //
    419 // LowerAtomic - Lower atomic intrinsics to non-atomic form
    420 //
    421 Pass *createLowerAtomicPass();
    422 
    423 //===----------------------------------------------------------------------===//
    424 //
    425 // LowerGuardIntrinsic - Lower guard intrinsics to normal control flow.
    426 //
    427 Pass *createLowerGuardIntrinsicPass();
    428 
    429 //===----------------------------------------------------------------------===//
    430 //
    431 // MergeICmps - Merge integer comparison chains
    432 //
    433 Pass *createMergeICmpsPass();
    434 
    435 //===----------------------------------------------------------------------===//
    436 //
    437 // ValuePropagation - Propagate CFG-derived value information
    438 //
    439 Pass *createCorrelatedValuePropagationPass();
    440 
    441 //===----------------------------------------------------------------------===//
    442 //
    443 // InferAddressSpaces - Modify users of addrspacecast instructions with values
    444 // in the source address space if using the destination address space is slower
    445 // on the target.
    446 //
    447 FunctionPass *createInferAddressSpacesPass();
    448 extern char &InferAddressSpacesID;
    449 
    450 //===----------------------------------------------------------------------===//
    451 //
    452 // InstructionSimplifier - Remove redundant instructions.
    453 //
    454 FunctionPass *createInstructionSimplifierPass();
    455 extern char &InstructionSimplifierID;
    456 
    457 //===----------------------------------------------------------------------===//
    458 //
    459 // LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates
    460 // "block_weights" metadata.
    461 FunctionPass *createLowerExpectIntrinsicPass();
    462 
    463 //===----------------------------------------------------------------------===//
    464 //
    465 // PartiallyInlineLibCalls - Tries to inline the fast path of library
    466 // calls such as sqrt.
    467 //
    468 FunctionPass *createPartiallyInlineLibCallsPass();
    469 
    470 //===----------------------------------------------------------------------===//
    471 //
    472 // ScalarizerPass - Converts vector operations into scalar operations
    473 //
    474 FunctionPass *createScalarizerPass();
    475 
    476 //===----------------------------------------------------------------------===//
    477 //
    478 // AddDiscriminators - Add DWARF path discriminators to the IR.
    479 FunctionPass *createAddDiscriminatorsPass();
    480 
    481 //===----------------------------------------------------------------------===//
    482 //
    483 // SeparateConstOffsetFromGEP - Split GEPs for better CSE
    484 //
    485 FunctionPass *
    486 createSeparateConstOffsetFromGEPPass(const TargetMachine *TM = nullptr,
    487                                      bool LowerGEP = false);
    488 
    489 //===----------------------------------------------------------------------===//
    490 //
    491 // SpeculativeExecution - Aggressively hoist instructions to enable
    492 // speculative execution on targets where branches are expensive.
    493 //
    494 FunctionPass *createSpeculativeExecutionPass();
    495 
    496 // Same as createSpeculativeExecutionPass, but does nothing unless
    497 // TargetTransformInfo::hasBranchDivergence() is true.
    498 FunctionPass *createSpeculativeExecutionIfHasBranchDivergencePass();
    499 
    500 //===----------------------------------------------------------------------===//
    501 //
    502 // StraightLineStrengthReduce - This pass strength-reduces some certain
    503 // instruction patterns in straight-line code.
    504 //
    505 FunctionPass *createStraightLineStrengthReducePass();
    506 
    507 //===----------------------------------------------------------------------===//
    508 //
    509 // PlaceSafepoints - Rewrite any IR calls to gc.statepoints and insert any
    510 // safepoint polls (method entry, backedge) that might be required.  This pass
    511 // does not generate explicit relocation sequences - that's handled by
    512 // RewriteStatepointsForGC which can be run at an arbitrary point in the pass
    513 // order following this pass.
    514 //
    515 FunctionPass *createPlaceSafepointsPass();
    516 
    517 //===----------------------------------------------------------------------===//
    518 //
    519 // RewriteStatepointsForGC - Rewrite any gc.statepoints which do not yet have
    520 // explicit relocations to include explicit relocations.
    521 //
    522 ModulePass *createRewriteStatepointsForGCPass();
    523 
    524 //===----------------------------------------------------------------------===//
    525 //
    526 // StripGCRelocates - Remove GC relocates that have been inserted by
    527 // RewriteStatepointsForGC. The resulting IR is incorrect, but this is useful
    528 // for manual inspection.
    529 FunctionPass *createStripGCRelocatesPass();
    530 
    531 //===----------------------------------------------------------------------===//
    532 //
    533 // Float2Int - Demote floats to ints where possible.
    534 //
    535 FunctionPass *createFloat2IntPass();
    536 
    537 //===----------------------------------------------------------------------===//
    538 //
    539 // NaryReassociate - Simplify n-ary operations by reassociation.
    540 //
    541 FunctionPass *createNaryReassociatePass();
    542 
    543 //===----------------------------------------------------------------------===//
    544 //
    545 // LoopDistribute - Distribute loops.
    546 //
    547 FunctionPass *createLoopDistributePass();
    548 
    549 //===----------------------------------------------------------------------===//
    550 //
    551 // LoopLoadElimination - Perform loop-aware load elimination.
    552 //
    553 FunctionPass *createLoopLoadEliminationPass();
    554 
    555 //===----------------------------------------------------------------------===//
    556 //
    557 // LoopSimplifyCFG - This pass performs basic CFG simplification on loops,
    558 // primarily to help other loop passes.
    559 //
    560 Pass *createLoopSimplifyCFGPass();
    561 
    562 //===----------------------------------------------------------------------===//
    563 //
    564 // LoopVersioning - Perform loop multi-versioning.
    565 //
    566 FunctionPass *createLoopVersioningPass();
    567 
    568 //===----------------------------------------------------------------------===//
    569 //
    570 // LoopDataPrefetch - Perform data prefetching in loops.
    571 //
    572 FunctionPass *createLoopDataPrefetchPass();
    573 
    574 ///===---------------------------------------------------------------------===//
    575 ModulePass *createNameAnonGlobalPass();
    576 
    577 //===----------------------------------------------------------------------===//
    578 //
    579 // LibCallsShrinkWrap - Shrink-wraps a call to function if the result is not
    580 // used.
    581 //
    582 FunctionPass *createLibCallsShrinkWrapPass();
    583 } // End llvm namespace
    584 
    585 #endif
    586