|
LLVM
7.0.0
|
The RecurrenceDescriptor is used to identify recurrences variables in a loop. More...
#include "llvm/Transforms/Utils/LoopUtils.h"
Classes | |
| class | InstDesc |
| This POD struct holds information about a potential recurrence operation. More... | |
Public Types | |
| enum | RecurrenceKind { RK_NoRecurrence, RK_IntegerAdd, RK_IntegerMult, RK_IntegerOr, RK_IntegerAnd, RK_IntegerXor, RK_IntegerMinMax, RK_FloatAdd, RK_FloatMult, RK_FloatMinMax } |
| This enum represents the kinds of recurrences that we support. More... | |
| enum | MinMaxRecurrenceKind { MRK_Invalid, MRK_UIntMin, MRK_UIntMax, MRK_SIntMin, MRK_SIntMax, MRK_FloatMin, MRK_FloatMax } |
Public Member Functions | |
| RecurrenceDescriptor ()=default | |
| RecurrenceDescriptor (Value *Start, Instruction *Exit, RecurrenceKind K, MinMaxRecurrenceKind MK, Instruction *UAI, Type *RT, bool Signed, SmallPtrSetImpl< Instruction *> &CI) | |
| RecurrenceKind | getRecurrenceKind () |
| MinMaxRecurrenceKind | getMinMaxRecurrenceKind () |
| TrackingVH< Value > | getRecurrenceStartValue () |
| Instruction * | getLoopExitInstr () |
| bool | hasUnsafeAlgebra () |
| Returns true if the recurrence has unsafe algebra which requires a relaxed floating-point model. More... | |
| Instruction * | getUnsafeAlgebraInst () |
| Returns first unsafe algebra instruction in the PHI node's use-chain. More... | |
| Type * | getRecurrenceType () |
| Returns the type of the recurrence. More... | |
| SmallPtrSet< Instruction *, 8 > & | getCastInsts () |
| Returns a reference to the instructions used for type-promoting the recurrence. More... | |
| bool | isSigned () |
| Returns true if all source operands of the recurrence are SExtInsts. More... | |
Static Public Member Functions | |
| static InstDesc | isRecurrenceInstr (Instruction *I, RecurrenceKind Kind, InstDesc &Prev, bool HasFunNoNaNAttr) |
| Returns a struct describing if the instruction 'I' can be a recurrence variable of type 'Kind'. More... | |
| static bool | hasMultipleUsesOf (Instruction *I, SmallPtrSetImpl< Instruction *> &Insts) |
| Returns true if instruction I has multiple uses in Insts. More... | |
| static bool | areAllUsesIn (Instruction *I, SmallPtrSetImpl< Instruction *> &Set) |
| Returns true if all uses of the instruction I is within the Set. More... | |
| static InstDesc | isMinMaxSelectCmpPattern (Instruction *I, InstDesc &Prev) |
| Returns a struct describing if the instruction if the instruction is a Select(ICmp(X, Y), X, Y) instruction pattern corresponding to a min(X, Y) or max(X, Y). More... | |
| static Constant * | getRecurrenceIdentity (RecurrenceKind K, Type *Tp) |
| Returns identity corresponding to the RecurrenceKind. More... | |
| static unsigned | getRecurrenceBinOp (RecurrenceKind Kind) |
| Returns the opcode of binary operation corresponding to the RecurrenceKind. More... | |
| static Value * | createMinMaxOp (IRBuilder<> &Builder, MinMaxRecurrenceKind RK, Value *Left, Value *Right) |
| Returns a Min/Max operation corresponding to MinMaxRecurrenceKind. More... | |
| static bool | AddReductionVar (PHINode *Phi, RecurrenceKind Kind, Loop *TheLoop, bool HasFunNoNaNAttr, RecurrenceDescriptor &RedDes, DemandedBits *DB=nullptr, AssumptionCache *AC=nullptr, DominatorTree *DT=nullptr) |
| Returns true if Phi is a reduction of type Kind and adds it to the RecurrenceDescriptor. More... | |
| static bool | isReductionPHI (PHINode *Phi, Loop *TheLoop, RecurrenceDescriptor &RedDes, DemandedBits *DB=nullptr, AssumptionCache *AC=nullptr, DominatorTree *DT=nullptr) |
| Returns true if Phi is a reduction in TheLoop. More... | |
| static bool | isFirstOrderRecurrence (PHINode *Phi, Loop *TheLoop, DenseMap< Instruction *, Instruction *> &SinkAfter, DominatorTree *DT) |
| Returns true if Phi is a first-order recurrence. More... | |
| static bool | isIntegerRecurrenceKind (RecurrenceKind Kind) |
| Returns true if the recurrence kind is an integer kind. More... | |
| static bool | isFloatingPointRecurrenceKind (RecurrenceKind Kind) |
| Returns true if the recurrence kind is a floating point kind. More... | |
| static bool | isArithmeticRecurrenceKind (RecurrenceKind Kind) |
| Returns true if the recurrence kind is an arithmetic kind. More... | |
The RecurrenceDescriptor is used to identify recurrences variables in a loop.
Reduction is a special case of recurrence that has uses of the recurrence variable outside the loop. The method isReductionPHI identifies reductions that are basic recurrences.
Basic recurrences are defined as the summation, product, OR, AND, XOR, min, or max of a set of terms. For example: for(i=0; i<n; i++) { total += array[i]; } is a summation of array elements. Basic recurrences are a special case of chains of recurrences (CR). See ScalarEvolution for CR references. This struct holds information about recurrence variables.
Definition at line 64 of file LoopUtils.h.
| Enumerator | |
|---|---|
| MRK_Invalid | |
| MRK_UIntMin | |
| MRK_UIntMax | |
| MRK_SIntMin | |
| MRK_SIntMax | |
| MRK_FloatMin | |
| MRK_FloatMax | |
Definition at line 81 of file LoopUtils.h.
This enum represents the kinds of recurrences that we support.
Definition at line 67 of file LoopUtils.h.
|
default |
|
inline |
Definition at line 93 of file LoopUtils.h.
|
static |
Returns true if Phi is a reduction of type Kind and adds it to the RecurrenceDescriptor.
If either DB is non-null or AC and DT are non-null, the minimal bit width needed to compute the reduction will be computed.
Definition at line 191 of file LoopUtils.cpp.
References llvm::LoopBase< BlockT, LoopT >::getHeader(), llvm::PHINode::getIncomingValueForBlock(), llvm::LoopBase< BlockT, LoopT >::getLoopPreheader(), llvm::PHINode::getNumIncomingValues(), llvm::Instruction::getParent(), and llvm::Value::getType().
Referenced by llvm::RecurrenceDescriptor::InstDesc::getPatternInst(), and MatchReductions().
|
static |
Returns true if all uses of the instruction I is within the Set.
Definition at line 44 of file LoopUtils.cpp.
References llvm::SmallPtrSetImpl< PtrType >::count(), E, llvm::User::op_begin(), and llvm::User::op_end().
Referenced by llvm::RecurrenceDescriptor::InstDesc::getPatternInst().
|
static |
Returns a Min/Max operation corresponding to MinMaxRecurrenceKind.
Definition at line 711 of file LoopUtils.cpp.
References llvm::IRBuilder< T, Inserter >::CreateFCmp(), llvm::IRBuilder< T, Inserter >::CreateICmp(), llvm::IRBuilder< T, Inserter >::CreateSelect(), llvm::CmpInst::FCMP_OGT, llvm::CmpInst::FCMP_OLT, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULT, llvm::InductionDescriptor::InductionDescriptor(), llvm_unreachable, P, llvm::MCID::Select, llvm::FastMathFlags::setFast(), and llvm::IRBuilderBase::setFastMathFlags().
Referenced by llvm::InnerLoopVectorizer::fixReduction(), llvm::getOrderedReduction(), llvm::RecurrenceDescriptor::InstDesc::getPatternInst(), and llvm::getShuffleReduction().
|
inline |
Returns a reference to the instructions used for type-promoting the recurrence.
Definition at line 228 of file LoopUtils.h.
Referenced by llvm::LoopVectorizationCostModel::collectValuesToIgnore().
|
inline |
Definition at line 204 of file LoopUtils.h.
Referenced by llvm::LoopVectorizationLegality::isUniform().
|
inline |
Definition at line 200 of file LoopUtils.h.
Referenced by llvm::createTargetReduction().
|
static |
Returns the opcode of binary operation corresponding to the RecurrenceKind.
This function translates the recurrence kind to an LLVM binary operator.
Definition at line 686 of file LoopUtils.cpp.
References llvm::MCID::Add, and llvm_unreachable.
Referenced by llvm::InnerLoopVectorizer::fixReduction(), and llvm::RecurrenceDescriptor::InstDesc::getPatternInst().
|
static |
Returns identity corresponding to the RecurrenceKind.
This function returns the identity element (or neutral element) for the operation K.
Definition at line 660 of file LoopUtils.cpp.
References llvm::ConstantInt::get(), llvm::ConstantFP::get(), and llvm_unreachable.
Referenced by llvm::InnerLoopVectorizer::fixReduction(), and llvm::RecurrenceDescriptor::InstDesc::getPatternInst().
|
inline |
Definition at line 198 of file LoopUtils.h.
Referenced by llvm::createTargetReduction(), and llvm::InnerLoopVectorizer::fixReduction().
|
inline |
Definition at line 202 of file LoopUtils.h.
|
inline |
Returns the type of the recurrence.
This type can be narrower than the actual type of the Phi if the recurrence has been type-promoted.
Definition at line 224 of file LoopUtils.h.
Referenced by llvm::LoopVectorizationCostModel::getSmallestAndWidestTypes().
|
inline |
Returns first unsafe algebra instruction in the PHI node's use-chain.
Definition at line 211 of file LoopUtils.h.
References isArithmeticRecurrenceKind(), isFloatingPointRecurrenceKind(), and isIntegerRecurrenceKind().
Referenced by llvm::LoopVectorizationLegality::isUniform().
|
static |
Returns true if instruction I has multiple uses in Insts.
Definition at line 533 of file LoopUtils.cpp.
References llvm::SmallPtrSetImpl< PtrType >::count(), E, llvm::User::op_begin(), and llvm::User::op_end().
Referenced by llvm::RecurrenceDescriptor::InstDesc::getPatternInst().
|
inline |
Returns true if the recurrence has unsafe algebra which requires a relaxed floating-point model.
Definition at line 208 of file LoopUtils.h.
Referenced by llvm::LoopVectorizationLegality::isUniform().
|
static |
Returns true if the recurrence kind is an arithmetic kind.
Definition at line 71 of file LoopUtils.cpp.
Referenced by getUnsafeAlgebraInst().
|
static |
Returns true if Phi is a first-order recurrence.
A first-order recurrence is a non-reduction recurrence relation in which the value of the recurrence in the current loop iteration equals a value defined in the previous iteration. SinkAfter includes pairs of instructions where the first will be rescheduled to appear after the second if/when the loop is vectorized. It may be augmented with additional pairs if needed in order to handle Phi as a first-order recurrence.
Definition at line 606 of file LoopUtils.cpp.
References llvm::LoopBase< BlockT, LoopT >::contains(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::count(), llvm::DominatorTree::dominates(), llvm::dyn_cast(), llvm::PHINode::getBasicBlockIndex(), llvm::LoopBase< BlockT, LoopT >::getHeader(), llvm::PHINode::getIncomingValueForBlock(), llvm::LoopBase< BlockT, LoopT >::getLoopLatch(), llvm::LoopBase< BlockT, LoopT >::getLoopPreheader(), llvm::PHINode::getNumIncomingValues(), llvm::Instruction::getParent(), llvm::Value::hasOneUse(), I, llvm::Instruction::user_back(), and llvm::Value::users().
Referenced by llvm::RecurrenceDescriptor::InstDesc::getPatternInst(), and llvm::LoopVectorizationLegality::isUniform().
|
static |
Returns true if the recurrence kind is a floating point kind.
Definition at line 67 of file LoopUtils.cpp.
Referenced by getUnsafeAlgebraInst().
|
static |
Returns true if the recurrence kind is an integer kind.
Definition at line 52 of file LoopUtils.cpp.
Referenced by getUnsafeAlgebraInst().
|
static |
Returns a struct describing if the instruction if the instruction is a Select(ICmp(X, Y), X, Y) instruction pattern corresponding to a min(X, Y) or max(X, Y).
Returns true if the instruction is a Select(ICmp(X, Y), X, Y) instruction pattern corresponding to a min(X, Y) or max(X, Y).
Definition at line 446 of file LoopUtils.cpp.
References assert(), llvm::dyn_cast(), llvm::RecurrenceDescriptor::InstDesc::getMinMaxKind(), llvm::User::getOperand(), llvm::Value::hasOneUse(), llvm::PatternMatch::m_OrdFMax(), llvm::PatternMatch::m_OrdFMin(), llvm::PatternMatch::m_SMax(), llvm::PatternMatch::m_SMin(), llvm::PatternMatch::m_UMax(), llvm::PatternMatch::m_UMin(), llvm::PatternMatch::m_UnordFMax(), llvm::PatternMatch::m_UnordFMin(), llvm::PatternMatch::m_Value(), llvm::MCID::Select, and llvm::Value::user_begin().
Referenced by llvm::RecurrenceDescriptor::InstDesc::getPatternInst().
|
static |
Returns a struct describing if the instruction 'I' can be a recurrence variable of type 'Kind'.
If the recurrence is a min/max pattern of select(icmp()) this function advances the instruction pointer 'I' from the compare instruction to the select instruction and stores this pointer in 'PatternLastInst' member of the returned struct.
Definition at line 495 of file LoopUtils.cpp.
References llvm::MCID::Add, llvm::RecurrenceDescriptor::InstDesc::getMinMaxKind(), llvm::Instruction::getOpcode(), llvm::Value::getType(), llvm::RecurrenceDescriptor::InstDesc::getUnsafeAlgebraInst(), llvm::Instruction::isFast(), llvm::Type::isFloatingPointTy(), and llvm::MCID::Select.
Referenced by llvm::RecurrenceDescriptor::InstDesc::getPatternInst().
|
static |
Returns true if Phi is a reduction in TheLoop.
The RecurrenceDescriptor is returned in RedDes. If either DB is non-null or AC and DT are non-null, the minimal bit width needed to compute the reduction will be computed.
Definition at line 546 of file LoopUtils.cpp.
References llvm::dbgs(), F(), llvm::Function::getFnAttribute(), llvm::LoopBase< BlockT, LoopT >::getHeader(), llvm::BasicBlock::getParent(), llvm::Attribute::getValueAsString(), and LLVM_DEBUG.
Referenced by getInductionVariable(), llvm::RecurrenceDescriptor::InstDesc::getPatternInst(), and llvm::LoopVectorizationLegality::isUniform().
|
inline |
Returns true if all source operands of the recurrence are SExtInsts.
Definition at line 231 of file LoopUtils.h.
References MRK_Invalid, and RK_NoRecurrence.
1.8.13