|
LLVM
4.0.0
|
The RecurrenceDescriptor is used to identify recurrences variables in a loop. More...
#include <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 () | |
| 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) |
| 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) |
| Returns true if Phi is a reduction in TheLoop. More... | |
| static bool | isFirstOrderRecurrence (PHINode *Phi, Loop *TheLoop, 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... | |
| static Instruction * | lookThroughAnd (PHINode *Phi, Type *&RT, SmallPtrSetImpl< Instruction * > &Visited, SmallPtrSetImpl< Instruction * > &CI) |
| Determines if Phi may have been type-promoted. More... | |
| static bool | getSourceExtensionKind (Instruction *Start, Instruction *Exit, Type *RT, bool &IsSigned, SmallPtrSetImpl< Instruction * > &Visited, SmallPtrSetImpl< Instruction * > &CI) |
| Returns true if all the source operands of a recurrence are either SExtInsts or ZExtInsts. 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 63 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.
|
inline |
Definition at line 91 of file LoopUtils.h.
|
inline |
Definition at line 96 of file LoopUtils.h.
References llvm::SmallPtrSetImpl< PtrType >::begin(), llvm::SmallPtrSetImpl< PtrType >::end(), and llvm::SmallPtrSetImpl< PtrType >::insert().
|
static |
Returns true if Phi is a reduction of type Kind and adds it to the RecurrenceDescriptor.
Definition at line 164 of file LoopUtils.cpp.
References llvm::SmallVectorImpl< T >::append(), llvm::SmallVectorTemplateCommon< T >::back(), llvm::SmallVectorTemplateCommon< T >::begin(), llvm::LoopBase< N, M >::contains(), llvm::SmallPtrSetImpl< PtrType >::count(), llvm::SmallVectorBase::empty(), llvm::SmallVectorTemplateCommon< T >::end(), llvm::LoopBase< N, M >::getHeader(), llvm::PHINode::getIncomingValueForBlock(), llvm::LoopBase< N, M >::getLoopPreheader(), llvm::RecurrenceDescriptor::InstDesc::getMinMaxKind(), llvm::PHINode::getNumIncomingValues(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::Value::getType(), llvm::RecurrenceDescriptor::InstDesc::getUnsafeAlgebraInst(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::is_contained(), llvm::Instruction::isCommutative(), llvm::Type::isFloatingPointTy(), llvm::RecurrenceDescriptor::InstDesc::isRecurrence(), llvm::User::operands(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::pop_back(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::Value::use_empty(), and llvm::Value::users().
|
static |
Returns true if all uses of the instruction I is within the Set.
Definition at line 38 of file LoopUtils.cpp.
References llvm::SmallPtrSetImpl< PtrType >::count(), E, llvm::User::op_begin(), and llvm::User::op_end().
|
static |
Returns a Min/Max operation corresponding to MinMaxRecurrenceKind.
Definition at line 614 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_unreachable, P, llvm::MCID::Select, llvm::IRBuilderBase::setFastMathFlags(), and llvm::FastMathFlags::setUnsafeAlgebra().
|
inline |
Returns a reference to the instructions used for type-promoting the recurrence.
Definition at line 235 of file LoopUtils.h.
|
inline |
Definition at line 193 of file LoopUtils.h.
|
inline |
Definition at line 189 of file LoopUtils.h.
|
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 589 of file LoopUtils.cpp.
References llvm::MCID::Add, llvm::APIntOps::And(), llvm_unreachable, llvm::APIntOps::Or(), and llvm::APIntOps::Xor().
|
static |
Returns identity corresponding to the RecurrenceKind.
This function returns the identity element (or neutral element) for the operation K.
Definition at line 563 of file LoopUtils.cpp.
References llvm::ConstantInt::get(), llvm::ConstantFP::get(), L, and llvm_unreachable.
|
inline |
Definition at line 187 of file LoopUtils.h.
|
inline |
Definition at line 191 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 231 of file LoopUtils.h.
|
static |
Returns true if all the source operands of a recurrence are either SExtInsts or ZExtInsts.
This function is intended to be used with lookThroughAnd to determine if the recurrence has been type-promoted. The source operands are added to CI, and IsSigned is updated to indicate if all source operands are SExtInsts.
Definition at line 103 of file LoopUtils.cpp.
References llvm::SmallPtrSetImpl< PtrType >::count(), llvm::dyn_cast(), llvm::SmallVectorBase::empty(), llvm::Type::getPrimitiveSizeInBits(), llvm::CastInst::getSrcTy(), llvm::Value::hasOneUse(), I, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::User::operands(), llvm::SmallVectorImpl< T >::pop_back_val(), and llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back().
|
inline |
Returns first unsafe algebra instruction in the PHI node's use-chain.
Definition at line 200 of file LoopUtils.h.
|
static |
Returns true if instruction I has multiple uses in Insts.
Definition at line 462 of file LoopUtils.cpp.
References llvm::SmallPtrSetImpl< PtrType >::count(), E, llvm::User::op_begin(), and llvm::User::op_end().
|
inline |
Returns true if the recurrence has unsafe algebra which requires a relaxed floating-point model.
Definition at line 197 of file LoopUtils.h.
|
static |
Returns true if the recurrence kind is an arithmetic kind.
Definition at line 65 of file LoopUtils.cpp.
|
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.
Definition at line 524 of file LoopUtils.cpp.
References llvm::LoopBase< N, M >::contains(), llvm::DominatorTree::dominates(), llvm::dyn_cast(), llvm::PHINode::getBasicBlockIndex(), llvm::LoopBase< N, M >::getHeader(), llvm::PHINode::getIncomingValueForBlock(), llvm::LoopBase< N, M >::getLoopLatch(), llvm::LoopBase< N, M >::getLoopPreheader(), llvm::PHINode::getNumIncomingValues(), llvm::Instruction::getParent(), I, and llvm::Value::users().
|
static |
Returns true if the recurrence kind is a floating point kind.
Definition at line 61 of file LoopUtils.cpp.
|
static |
Returns true if the recurrence kind is an integer kind.
Definition at line 46 of file LoopUtils.cpp.
|
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 375 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().
|
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 424 of file LoopUtils.cpp.
References llvm::MCID::Add, llvm::APIntOps::And(), llvm::RecurrenceDescriptor::InstDesc::getMinMaxKind(), llvm::Instruction::getOpcode(), llvm::Value::getType(), llvm::RecurrenceDescriptor::InstDesc::getUnsafeAlgebraInst(), llvm::Instruction::hasUnsafeAlgebra(), llvm::Type::isFloatingPointTy(), llvm::APIntOps::Or(), llvm::MCID::Select, and llvm::APIntOps::Xor().
|
static |
Returns true if Phi is a reduction in TheLoop.
The RecurrenceDescriptor is returned in RedDes.
Definition at line 475 of file LoopUtils.cpp.
References llvm::dbgs(), DEBUG, F, llvm::Function::getFnAttribute(), llvm::LoopBase< N, M >::getHeader(), llvm::BasicBlock::getParent(), and llvm::Attribute::getValueAsString().
|
inline |
Returns true if all source operands of the recurrence are SExtInsts.
Definition at line 238 of file LoopUtils.h.
|
static |
Determines if Phi may have been type-promoted.
If Phi has a single user that ANDs the Phi with a type mask, return the user. RT is updated to account for the narrower bit width represented by the mask, and the AND instruction is added to CI.
Definition at line 79 of file LoopUtils.cpp.
References llvm::tgtok::Bits, llvm::IntegerType::get(), llvm::Value::getContext(), llvm::Value::hasOneUse(), I, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_CombineOr(), llvm::PatternMatch::m_Instruction(), llvm::PatternMatch::match(), and llvm::Value::use_begin().
1.8.6