Home | History | Annotate | Download | only in Utils
      1 //===- llvm/Transforms/Utils/LoopUtils.h - Loop utilities -------*- 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 file defines some loop transformation utilities.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #ifndef LLVM_TRANSFORMS_UTILS_LOOPUTILS_H
     15 #define LLVM_TRANSFORMS_UTILS_LOOPUTILS_H
     16 
     17 #include "llvm/ADT/DenseMap.h"
     18 #include "llvm/ADT/Optional.h"
     19 #include "llvm/ADT/SmallPtrSet.h"
     20 #include "llvm/ADT/SmallVector.h"
     21 #include "llvm/ADT/StringRef.h"
     22 #include "llvm/Analysis/AliasAnalysis.h"
     23 #include "llvm/Analysis/EHPersonalities.h"
     24 #include "llvm/Analysis/TargetTransformInfo.h"
     25 #include "llvm/IR/Dominators.h"
     26 #include "llvm/IR/IRBuilder.h"
     27 #include "llvm/IR/InstrTypes.h"
     28 #include "llvm/IR/Operator.h"
     29 #include "llvm/IR/ValueHandle.h"
     30 #include "llvm/Support/Casting.h"
     31 
     32 namespace llvm {
     33 
     34 class AliasSet;
     35 class AliasSetTracker;
     36 class BasicBlock;
     37 class DataLayout;
     38 class Loop;
     39 class LoopInfo;
     40 class OptimizationRemarkEmitter;
     41 class PredicatedScalarEvolution;
     42 class PredIteratorCache;
     43 class ScalarEvolution;
     44 class SCEV;
     45 class TargetLibraryInfo;
     46 class TargetTransformInfo;
     47 
     48 /// \brief Captures loop safety information.
     49 /// It keep information for loop & its header may throw exception.
     50 struct LoopSafetyInfo {
     51   bool MayThrow = false;       // The current loop contains an instruction which
     52                                // may throw.
     53   bool HeaderMayThrow = false; // Same as previous, but specific to loop header
     54   // Used to update funclet bundle operands.
     55   DenseMap<BasicBlock *, ColorVector> BlockColors;
     56 
     57   LoopSafetyInfo() = default;
     58 };
     59 
     60 /// The RecurrenceDescriptor is used to identify recurrences variables in a
     61 /// loop. Reduction is a special case of recurrence that has uses of the
     62 /// recurrence variable outside the loop. The method isReductionPHI identifies
     63 /// reductions that are basic recurrences.
     64 ///
     65 /// Basic recurrences are defined as the summation, product, OR, AND, XOR, min,
     66 /// or max of a set of terms. For example: for(i=0; i<n; i++) { total +=
     67 /// array[i]; } is a summation of array elements. Basic recurrences are a
     68 /// special case of chains of recurrences (CR). See ScalarEvolution for CR
     69 /// references.
     70 
     71 /// This struct holds information about recurrence variables.
     72 class RecurrenceDescriptor {
     73 public:
     74   /// This enum represents the kinds of recurrences that we support.
     75   enum RecurrenceKind {
     76     RK_NoRecurrence,  ///< Not a recurrence.
     77     RK_IntegerAdd,    ///< Sum of integers.
     78     RK_IntegerMult,   ///< Product of integers.
     79     RK_IntegerOr,     ///< Bitwise or logical OR of numbers.
     80     RK_IntegerAnd,    ///< Bitwise or logical AND of numbers.
     81     RK_IntegerXor,    ///< Bitwise or logical XOR of numbers.
     82     RK_IntegerMinMax, ///< Min/max implemented in terms of select(cmp()).
     83     RK_FloatAdd,      ///< Sum of floats.
     84     RK_FloatMult,     ///< Product of floats.
     85     RK_FloatMinMax    ///< Min/max implemented in terms of select(cmp()).
     86   };
     87 
     88   // This enum represents the kind of minmax recurrence.
     89   enum MinMaxRecurrenceKind {
     90     MRK_Invalid,
     91     MRK_UIntMin,
     92     MRK_UIntMax,
     93     MRK_SIntMin,
     94     MRK_SIntMax,
     95     MRK_FloatMin,
     96     MRK_FloatMax
     97   };
     98 
     99   RecurrenceDescriptor() = default;
    100 
    101   RecurrenceDescriptor(Value *Start, Instruction *Exit, RecurrenceKind K,
    102                        MinMaxRecurrenceKind MK, Instruction *UAI, Type *RT,
    103                        bool Signed, SmallPtrSetImpl<Instruction *> &CI)
    104       : StartValue(Start), LoopExitInstr(Exit), Kind(K), MinMaxKind(MK),
    105         UnsafeAlgebraInst(UAI), RecurrenceType(RT), IsSigned(Signed) {
    106     CastInsts.insert(CI.begin(), CI.end());
    107   }
    108 
    109   /// This POD struct holds information about a potential recurrence operation.
    110   class InstDesc {
    111   public:
    112     InstDesc(bool IsRecur, Instruction *I, Instruction *UAI = nullptr)
    113         : IsRecurrence(IsRecur), PatternLastInst(I), MinMaxKind(MRK_Invalid),
    114           UnsafeAlgebraInst(UAI) {}
    115 
    116     InstDesc(Instruction *I, MinMaxRecurrenceKind K, Instruction *UAI = nullptr)
    117         : IsRecurrence(true), PatternLastInst(I), MinMaxKind(K),
    118           UnsafeAlgebraInst(UAI) {}
    119 
    120     bool isRecurrence() { return IsRecurrence; }
    121 
    122     bool hasUnsafeAlgebra() { return UnsafeAlgebraInst != nullptr; }
    123 
    124     Instruction *getUnsafeAlgebraInst() { return UnsafeAlgebraInst; }
    125 
    126     MinMaxRecurrenceKind getMinMaxKind() { return MinMaxKind; }
    127 
    128     Instruction *getPatternInst() { return PatternLastInst; }
    129 
    130   private:
    131     // Is this instruction a recurrence candidate.
    132     bool IsRecurrence;
    133     // The last instruction in a min/max pattern (select of the select(icmp())
    134     // pattern), or the current recurrence instruction otherwise.
    135     Instruction *PatternLastInst;
    136     // If this is a min/max pattern the comparison predicate.
    137     MinMaxRecurrenceKind MinMaxKind;
    138     // Recurrence has unsafe algebra.
    139     Instruction *UnsafeAlgebraInst;
    140   };
    141 
    142   /// Returns a struct describing if the instruction 'I' can be a recurrence
    143   /// variable of type 'Kind'. If the recurrence is a min/max pattern of
    144   /// select(icmp()) this function advances the instruction pointer 'I' from the
    145   /// compare instruction to the select instruction and stores this pointer in
    146   /// 'PatternLastInst' member of the returned struct.
    147   static InstDesc isRecurrenceInstr(Instruction *I, RecurrenceKind Kind,
    148                                     InstDesc &Prev, bool HasFunNoNaNAttr);
    149 
    150   /// Returns true if instruction I has multiple uses in Insts
    151   static bool hasMultipleUsesOf(Instruction *I,
    152                                 SmallPtrSetImpl<Instruction *> &Insts);
    153 
    154   /// Returns true if all uses of the instruction I is within the Set.
    155   static bool areAllUsesIn(Instruction *I, SmallPtrSetImpl<Instruction *> &Set);
    156 
    157   /// Returns a struct describing if the instruction if the instruction is a
    158   /// Select(ICmp(X, Y), X, Y) instruction pattern corresponding to a min(X, Y)
    159   /// or max(X, Y).
    160   static InstDesc isMinMaxSelectCmpPattern(Instruction *I, InstDesc &Prev);
    161 
    162   /// Returns identity corresponding to the RecurrenceKind.
    163   static Constant *getRecurrenceIdentity(RecurrenceKind K, Type *Tp);
    164 
    165   /// Returns the opcode of binary operation corresponding to the
    166   /// RecurrenceKind.
    167   static unsigned getRecurrenceBinOp(RecurrenceKind Kind);
    168 
    169   /// Returns a Min/Max operation corresponding to MinMaxRecurrenceKind.
    170   static Value *createMinMaxOp(IRBuilder<> &Builder, MinMaxRecurrenceKind RK,
    171                                Value *Left, Value *Right);
    172 
    173   /// Returns true if Phi is a reduction of type Kind and adds it to the
    174   /// RecurrenceDescriptor.
    175   static bool AddReductionVar(PHINode *Phi, RecurrenceKind Kind, Loop *TheLoop,
    176                               bool HasFunNoNaNAttr,
    177                               RecurrenceDescriptor &RedDes);
    178 
    179   /// Returns true if Phi is a reduction in TheLoop. The RecurrenceDescriptor is
    180   /// returned in RedDes.
    181   static bool isReductionPHI(PHINode *Phi, Loop *TheLoop,
    182                              RecurrenceDescriptor &RedDes);
    183 
    184   /// Returns true if Phi is a first-order recurrence. A first-order recurrence
    185   /// is a non-reduction recurrence relation in which the value of the
    186   /// recurrence in the current loop iteration equals a value defined in the
    187   /// previous iteration.
    188   static bool isFirstOrderRecurrence(PHINode *Phi, Loop *TheLoop,
    189                                      DominatorTree *DT);
    190 
    191   RecurrenceKind getRecurrenceKind() { return Kind; }
    192 
    193   MinMaxRecurrenceKind getMinMaxRecurrenceKind() { return MinMaxKind; }
    194 
    195   TrackingVH<Value> getRecurrenceStartValue() { return StartValue; }
    196 
    197   Instruction *getLoopExitInstr() { return LoopExitInstr; }
    198 
    199   /// Returns true if the recurrence has unsafe algebra which requires a relaxed
    200   /// floating-point model.
    201   bool hasUnsafeAlgebra() { return UnsafeAlgebraInst != nullptr; }
    202 
    203   /// Returns first unsafe algebra instruction in the PHI node's use-chain.
    204   Instruction *getUnsafeAlgebraInst() { return UnsafeAlgebraInst; }
    205 
    206   /// Returns true if the recurrence kind is an integer kind.
    207   static bool isIntegerRecurrenceKind(RecurrenceKind Kind);
    208 
    209   /// Returns true if the recurrence kind is a floating point kind.
    210   static bool isFloatingPointRecurrenceKind(RecurrenceKind Kind);
    211 
    212   /// Returns true if the recurrence kind is an arithmetic kind.
    213   static bool isArithmeticRecurrenceKind(RecurrenceKind Kind);
    214 
    215   /// Determines if Phi may have been type-promoted. If Phi has a single user
    216   /// that ANDs the Phi with a type mask, return the user. RT is updated to
    217   /// account for the narrower bit width represented by the mask, and the AND
    218   /// instruction is added to CI.
    219   static Instruction *lookThroughAnd(PHINode *Phi, Type *&RT,
    220                                      SmallPtrSetImpl<Instruction *> &Visited,
    221                                      SmallPtrSetImpl<Instruction *> &CI);
    222 
    223   /// Returns true if all the source operands of a recurrence are either
    224   /// SExtInsts or ZExtInsts. This function is intended to be used with
    225   /// lookThroughAnd to determine if the recurrence has been type-promoted. The
    226   /// source operands are added to CI, and IsSigned is updated to indicate if
    227   /// all source operands are SExtInsts.
    228   static bool getSourceExtensionKind(Instruction *Start, Instruction *Exit,
    229                                      Type *RT, bool &IsSigned,
    230                                      SmallPtrSetImpl<Instruction *> &Visited,
    231                                      SmallPtrSetImpl<Instruction *> &CI);
    232 
    233   /// Returns the type of the recurrence. This type can be narrower than the
    234   /// actual type of the Phi if the recurrence has been type-promoted.
    235   Type *getRecurrenceType() { return RecurrenceType; }
    236 
    237   /// Returns a reference to the instructions used for type-promoting the
    238   /// recurrence.
    239   SmallPtrSet<Instruction *, 8> &getCastInsts() { return CastInsts; }
    240 
    241   /// Returns true if all source operands of the recurrence are SExtInsts.
    242   bool isSigned() { return IsSigned; }
    243 
    244 private:
    245   // The starting value of the recurrence.
    246   // It does not have to be zero!
    247   TrackingVH<Value> StartValue;
    248   // The instruction who's value is used outside the loop.
    249   Instruction *LoopExitInstr = nullptr;
    250   // The kind of the recurrence.
    251   RecurrenceKind Kind = RK_NoRecurrence;
    252   // If this a min/max recurrence the kind of recurrence.
    253   MinMaxRecurrenceKind MinMaxKind = MRK_Invalid;
    254   // First occurrence of unasfe algebra in the PHI's use-chain.
    255   Instruction *UnsafeAlgebraInst = nullptr;
    256   // The type of the recurrence.
    257   Type *RecurrenceType = nullptr;
    258   // True if all source operands of the recurrence are SExtInsts.
    259   bool IsSigned = false;
    260   // Instructions used for type-promoting the recurrence.
    261   SmallPtrSet<Instruction *, 8> CastInsts;
    262 };
    263 
    264 /// A struct for saving information about induction variables.
    265 class InductionDescriptor {
    266 public:
    267   /// This enum represents the kinds of inductions that we support.
    268   enum InductionKind {
    269     IK_NoInduction,  ///< Not an induction variable.
    270     IK_IntInduction, ///< Integer induction variable. Step = C.
    271     IK_PtrInduction, ///< Pointer induction var. Step = C / sizeof(elem).
    272     IK_FpInduction   ///< Floating point induction variable.
    273   };
    274 
    275 public:
    276   /// Default constructor - creates an invalid induction.
    277   InductionDescriptor() = default;
    278 
    279   /// Get the consecutive direction. Returns:
    280   ///   0 - unknown or non-consecutive.
    281   ///   1 - consecutive and increasing.
    282   ///  -1 - consecutive and decreasing.
    283   int getConsecutiveDirection() const;
    284 
    285   /// Compute the transformed value of Index at offset StartValue using step
    286   /// StepValue.
    287   /// For integer induction, returns StartValue + Index * StepValue.
    288   /// For pointer induction, returns StartValue[Index * StepValue].
    289   /// FIXME: The newly created binary instructions should contain nsw/nuw
    290   /// flags, which can be found from the original scalar operations.
    291   Value *transform(IRBuilder<> &B, Value *Index, ScalarEvolution *SE,
    292                    const DataLayout& DL) const;
    293 
    294   Value *getStartValue() const { return StartValue; }
    295   InductionKind getKind() const { return IK; }
    296   const SCEV *getStep() const { return Step; }
    297   ConstantInt *getConstIntStepValue() const;
    298 
    299   /// Returns true if \p Phi is an induction in the loop \p L. If \p Phi is an
    300   /// induction, the induction descriptor \p D will contain the data describing
    301   /// this induction. If by some other means the caller has a better SCEV
    302   /// expression for \p Phi than the one returned by the ScalarEvolution
    303   /// analysis, it can be passed through \p Expr.
    304   static bool isInductionPHI(PHINode *Phi, const Loop* L, ScalarEvolution *SE,
    305                              InductionDescriptor &D,
    306                              const SCEV *Expr = nullptr);
    307 
    308   /// Returns true if \p Phi is a floating point induction in the loop \p L.
    309   /// If \p Phi is an induction, the induction descriptor \p D will contain
    310   /// the data describing this induction.
    311   static bool isFPInductionPHI(PHINode *Phi, const Loop* L,
    312                                ScalarEvolution *SE, InductionDescriptor &D);
    313 
    314   /// Returns true if \p Phi is a loop \p L induction, in the context associated
    315   /// with the run-time predicate of PSE. If \p Assume is true, this can add
    316   /// further SCEV predicates to \p PSE in order to prove that \p Phi is an
    317   /// induction.
    318   /// If \p Phi is an induction, \p D will contain the data describing this
    319   /// induction.
    320   static bool isInductionPHI(PHINode *Phi, const Loop* L,
    321                              PredicatedScalarEvolution &PSE,
    322                              InductionDescriptor &D, bool Assume = false);
    323 
    324   /// Returns true if the induction type is FP and the binary operator does
    325   /// not have the "fast-math" property. Such operation requires a relaxed FP
    326   /// mode.
    327   bool hasUnsafeAlgebra() {
    328     return InductionBinOp &&
    329       !cast<FPMathOperator>(InductionBinOp)->hasUnsafeAlgebra();
    330   }
    331 
    332   /// Returns induction operator that does not have "fast-math" property
    333   /// and requires FP unsafe mode.
    334   Instruction *getUnsafeAlgebraInst() {
    335     if (!InductionBinOp ||
    336         cast<FPMathOperator>(InductionBinOp)->hasUnsafeAlgebra())
    337       return nullptr;
    338     return InductionBinOp;
    339   }
    340 
    341   /// Returns binary opcode of the induction operator.
    342   Instruction::BinaryOps getInductionOpcode() const {
    343     return InductionBinOp ? InductionBinOp->getOpcode() :
    344       Instruction::BinaryOpsEnd;
    345   }
    346 
    347 private:
    348   /// Private constructor - used by \c isInductionPHI.
    349   InductionDescriptor(Value *Start, InductionKind K, const SCEV *Step,
    350                       BinaryOperator *InductionBinOp = nullptr);
    351 
    352   /// Start value.
    353   TrackingVH<Value> StartValue;
    354   /// Induction kind.
    355   InductionKind IK = IK_NoInduction;
    356   /// Step value.
    357   const SCEV *Step = nullptr;
    358   // Instruction that advances induction variable.
    359   BinaryOperator *InductionBinOp = nullptr;
    360 };
    361 
    362 BasicBlock *InsertPreheaderForLoop(Loop *L, DominatorTree *DT, LoopInfo *LI,
    363                                    bool PreserveLCSSA);
    364 
    365 /// Ensures LCSSA form for every instruction from the Worklist in the scope of
    366 /// innermost containing loop.
    367 ///
    368 /// For the given instruction which have uses outside of the loop, an LCSSA PHI
    369 /// node is inserted and the uses outside the loop are rewritten to use this
    370 /// node.
    371 ///
    372 /// LoopInfo and DominatorTree are required and, since the routine makes no
    373 /// changes to CFG, preserved.
    374 ///
    375 /// Returns true if any modifications are made.
    376 bool formLCSSAForInstructions(SmallVectorImpl<Instruction *> &Worklist,
    377                               DominatorTree &DT, LoopInfo &LI);
    378 
    379 /// \brief Put loop into LCSSA form.
    380 ///
    381 /// Looks at all instructions in the loop which have uses outside of the
    382 /// current loop. For each, an LCSSA PHI node is inserted and the uses outside
    383 /// the loop are rewritten to use this node.
    384 ///
    385 /// LoopInfo and DominatorTree are required and preserved.
    386 ///
    387 /// If ScalarEvolution is passed in, it will be preserved.
    388 ///
    389 /// Returns true if any modifications are made to the loop.
    390 bool formLCSSA(Loop &L, DominatorTree &DT, LoopInfo *LI, ScalarEvolution *SE);
    391 
    392 /// \brief Put a loop nest into LCSSA form.
    393 ///
    394 /// This recursively forms LCSSA for a loop nest.
    395 ///
    396 /// LoopInfo and DominatorTree are required and preserved.
    397 ///
    398 /// If ScalarEvolution is passed in, it will be preserved.
    399 ///
    400 /// Returns true if any modifications are made to the loop.
    401 bool formLCSSARecursively(Loop &L, DominatorTree &DT, LoopInfo *LI,
    402                           ScalarEvolution *SE);
    403 
    404 /// \brief Walk the specified region of the CFG (defined by all blocks
    405 /// dominated by the specified block, and that are in the current loop) in
    406 /// reverse depth first order w.r.t the DominatorTree. This allows us to visit
    407 /// uses before definitions, allowing us to sink a loop body in one pass without
    408 /// iteration. Takes DomTreeNode, AliasAnalysis, LoopInfo, DominatorTree,
    409 /// DataLayout, TargetLibraryInfo, Loop, AliasSet information for all
    410 /// instructions of the loop and loop safety information as
    411 /// arguments. Diagnostics is emitted via \p ORE. It returns changed status.
    412 bool sinkRegion(DomTreeNode *, AliasAnalysis *, LoopInfo *, DominatorTree *,
    413                 TargetLibraryInfo *, Loop *, AliasSetTracker *,
    414                 LoopSafetyInfo *, OptimizationRemarkEmitter *ORE);
    415 
    416 /// \brief Walk the specified region of the CFG (defined by all blocks
    417 /// dominated by the specified block, and that are in the current loop) in depth
    418 /// first order w.r.t the DominatorTree.  This allows us to visit definitions
    419 /// before uses, allowing us to hoist a loop body in one pass without iteration.
    420 /// Takes DomTreeNode, AliasAnalysis, LoopInfo, DominatorTree, DataLayout,
    421 /// TargetLibraryInfo, Loop, AliasSet information for all instructions of the
    422 /// loop and loop safety information as arguments. Diagnostics is emitted via \p
    423 /// ORE. It returns changed status.
    424 bool hoistRegion(DomTreeNode *, AliasAnalysis *, LoopInfo *, DominatorTree *,
    425                  TargetLibraryInfo *, Loop *, AliasSetTracker *,
    426                  LoopSafetyInfo *, OptimizationRemarkEmitter *ORE);
    427 
    428 /// \brief Try to promote memory values to scalars by sinking stores out of
    429 /// the loop and moving loads to before the loop.  We do this by looping over
    430 /// the stores in the loop, looking for stores to Must pointers which are
    431 /// loop invariant. It takes AliasSet, Loop exit blocks vector, loop exit blocks
    432 /// insertion point vector, PredIteratorCache, LoopInfo, DominatorTree, Loop,
    433 /// AliasSet information for all instructions of the loop and loop safety
    434 /// information as arguments. Diagnostics is emitted via \p ORE. It returns
    435 /// changed status.
    436 bool promoteLoopAccessesToScalars(AliasSet &, SmallVectorImpl<BasicBlock *> &,
    437                                   SmallVectorImpl<Instruction *> &,
    438                                   PredIteratorCache &, LoopInfo *,
    439                                   DominatorTree *, const TargetLibraryInfo *,
    440                                   Loop *, AliasSetTracker *, LoopSafetyInfo *,
    441                                   OptimizationRemarkEmitter *);
    442 
    443 /// \brief Computes safety information for a loop
    444 /// checks loop body & header for the possibility of may throw
    445 /// exception, it takes LoopSafetyInfo and loop as argument.
    446 /// Updates safety information in LoopSafetyInfo argument.
    447 void computeLoopSafetyInfo(LoopSafetyInfo *, Loop *);
    448 
    449 /// Returns true if the instruction in a loop is guaranteed to execute at least
    450 /// once.
    451 bool isGuaranteedToExecute(const Instruction &Inst, const DominatorTree *DT,
    452                            const Loop *CurLoop,
    453                            const LoopSafetyInfo *SafetyInfo);
    454 
    455 /// \brief Returns the instructions that use values defined in the loop.
    456 SmallVector<Instruction *, 8> findDefsUsedOutsideOfLoop(Loop *L);
    457 
    458 /// \brief Find string metadata for loop
    459 ///
    460 /// If it has a value (e.g. {"llvm.distribute", 1} return the value as an
    461 /// operand or null otherwise.  If the string metadata is not found return
    462 /// Optional's not-a-value.
    463 Optional<const MDOperand *> findStringMetadataForLoop(Loop *TheLoop,
    464                                                       StringRef Name);
    465 
    466 /// \brief Set input string into loop metadata by keeping other values intact.
    467 void addStringMetadataToLoop(Loop *TheLoop, const char *MDString,
    468                              unsigned V = 0);
    469 
    470 /// \brief Get a loop's estimated trip count based on branch weight metadata.
    471 /// Returns 0 when the count is estimated to be 0, or None when a meaningful
    472 /// estimate can not be made.
    473 Optional<unsigned> getLoopEstimatedTripCount(Loop *L);
    474 
    475 /// Helper to consistently add the set of standard passes to a loop pass's \c
    476 /// AnalysisUsage.
    477 ///
    478 /// All loop passes should call this as part of implementing their \c
    479 /// getAnalysisUsage.
    480 void getLoopAnalysisUsage(AnalysisUsage &AU);
    481 
    482 /// Returns true if the hoister and sinker can handle this instruction.
    483 /// If SafetyInfo is null, we are checking for sinking instructions from
    484 /// preheader to loop body (no speculation).
    485 /// If SafetyInfo is not null, we are checking for hoisting/sinking
    486 /// instructions from loop body to preheader/exit. Check if the instruction
    487 /// can execute speculatively.
    488 /// If \p ORE is set use it to emit optimization remarks.
    489 bool canSinkOrHoistInst(Instruction &I, AAResults *AA, DominatorTree *DT,
    490                         Loop *CurLoop, AliasSetTracker *CurAST,
    491                         LoopSafetyInfo *SafetyInfo,
    492                         OptimizationRemarkEmitter *ORE = nullptr);
    493 
    494 /// Generates a vector reduction using shufflevectors to reduce the value.
    495 Value *getShuffleReduction(IRBuilder<> &Builder, Value *Src, unsigned Op,
    496                            RecurrenceDescriptor::MinMaxRecurrenceKind
    497                                MinMaxKind = RecurrenceDescriptor::MRK_Invalid,
    498                            ArrayRef<Value *> RedOps = ArrayRef<Value *>());
    499 
    500 /// Create a target reduction of the given vector. The reduction operation
    501 /// is described by the \p Opcode parameter. min/max reductions require
    502 /// additional information supplied in \p Flags.
    503 /// The target is queried to determine if intrinsics or shuffle sequences are
    504 /// required to implement the reduction.
    505 Value *
    506 createSimpleTargetReduction(IRBuilder<> &B, const TargetTransformInfo *TTI,
    507                             unsigned Opcode, Value *Src,
    508                             TargetTransformInfo::ReductionFlags Flags =
    509                                 TargetTransformInfo::ReductionFlags(),
    510                             ArrayRef<Value *> RedOps = ArrayRef<Value *>());
    511 
    512 /// Create a generic target reduction using a recurrence descriptor \p Desc
    513 /// The target is queried to determine if intrinsics or shuffle sequences are
    514 /// required to implement the reduction.
    515 Value *createTargetReduction(IRBuilder<> &B, const TargetTransformInfo *TTI,
    516                              RecurrenceDescriptor &Desc, Value *Src,
    517                              bool NoNaN = false);
    518 
    519 /// Get the intersection (logical and) of all of the potential IR flags
    520 /// of each scalar operation (VL) that will be converted into a vector (I).
    521 /// Flag set: NSW, NUW, exact, and all of fast-math.
    522 void propagateIRFlags(Value *I, ArrayRef<Value *> VL);
    523 
    524 } // end namespace llvm
    525 
    526 #endif // LLVM_TRANSFORMS_UTILS_LOOPUTILS_H
    527