13 #ifndef LLVM_ANALYSIS_VECTORUTILS_H 14 #define LLVM_ANALYSIS_VECTORUTILS_H 65 int LinearStepOrPos = 0;
70 return std::tie(ParamPos, ParamKind, LinearStepOrPos, Alignment) ==
88 return std::tie(VF, IsScalable, Parameters) ==
96 assert(hasValidParameterList() &&
"Invalid parameter list");
105 for (
unsigned I = 0;
I < CI.arg_size(); ++
I)
111 return {EC.Min, EC.Scalable, Parameters};
114 bool hasValidParameterList()
const;
126 return std::tie(Shape, ScalarName, VectorName, ISA) ==
133 static constexpr
char const *
_LLVM_ =
"_LLVM_";
170 template <
typename T>
class ArrayRef;
180 namespace Intrinsic {
352 unsigned Stride,
unsigned VF);
366 unsigned NumInts,
unsigned NumUndefs);
420 : Factor(Factor), Reverse(Reverse), Alignment(Alignment),
421 InsertPos(nullptr) {}
424 : Alignment(Alignment), InsertPos(Instr) {
426 assert(Factor > 1 &&
"Invalid interleave factor");
428 Reverse = Stride < 0;
447 int32_t
Key = *MaybeKey;
450 if (Members.find(Key) != Members.end())
453 if (Key > LargestKey) {
455 if (Index >= static_cast<int32_t>(Factor))
459 }
else if (Key < SmallestKey) {
463 if (!MaybeLargestIndex)
467 if (*MaybeLargestIndex >= static_cast<int64_t>(Factor))
474 Alignment = std::min(Alignment, NewAlign);
475 Members[
Key] = Instr;
484 auto Member = Members.find(Key);
485 if (Member == Members.end())
488 return Member->second;
494 for (
auto I : Members) {
495 if (
I.second == Instr)
496 return I.first - SmallestKey;
511 void addMetadata(InstTy *NewInst)
const;
517 if (getMember(getFactor() - 1))
522 assert(!getMember(0)->mayWriteToMemory() &&
523 "Group should have been invalidated");
524 assert(!isReverse() &&
"Group should have been invalidated");
535 int32_t SmallestKey = 0;
536 int32_t LargestKey = 0;
565 : PSE(PSE), TheLoop(L), DT(DT), LI(LI), LAI(LAI) {}
573 void analyzeInterleaving(
bool EnableMaskedInterleavedGroup);
580 InterleaveGroupMap.clear();
581 for (
auto *Ptr : InterleaveGroups)
583 InterleaveGroups.clear();
584 RequiresScalarEpilogue =
false;
590 return InterleaveGroupMap.find(Instr) != InterleaveGroupMap.end();
598 if (InterleaveGroupMap.count(Instr))
599 return InterleaveGroupMap.find(Instr)->second;
605 return make_range(InterleaveGroups.begin(), InterleaveGroups.end());
615 void invalidateGroupsRequiringScalarEpilogue();
632 bool RequiresScalarEpilogue =
false;
644 struct StrideDescriptor {
645 StrideDescriptor() =
default;
646 StrideDescriptor(int64_t Stride,
const SCEV *Scev, uint64_t
Size,
648 : Stride(Stride), Scev(Scev),
Size(Size), Alignment(Alignment) {}
654 const SCEV *Scev =
nullptr;
664 using StrideEntry = std::pair<Instruction *, StrideDescriptor>;
673 "Already in an interleaved access group");
674 InterleaveGroupMap[Instr] =
676 InterleaveGroups.
insert(InterleaveGroupMap[Instr]);
677 return InterleaveGroupMap[Instr];
682 for (
unsigned i = 0; i < Group->
getFactor(); i++)
684 InterleaveGroupMap.
erase(Member);
686 InterleaveGroups.
erase(Group);
691 void collectConstStrideAccesses(
696 static bool isStrided(
int Stride);
704 bool areDependencesValid()
const {
713 bool canReorderMemAccessesForInterleavedGroups(StrideEntry *A,
714 StrideEntry *
B)
const {
730 auto *Src = A->first;
731 auto SrcDes = A->second;
734 auto *
Sink = B->first;
735 auto SinkDes = B->second;
739 if (!Src->mayWriteToMemory())
743 if (!isStrided(SrcDes.Stride) && !isStrided(SinkDes.Stride))
748 if (!areDependencesValid())
753 return Dependences.
find(Src) == Dependences.
end() ||
761 void collectDependences() {
762 if (!areDependencesValid())
765 for (
auto Dep : *Deps)
766 Dependences[Dep.getSource(*LAI)].
insert(Dep.getDestination(*LAI));
Value * getStrideFromPointer(Value *Ptr, ScalarEvolution *SE, Loop *Lp)
Get the stride of a pointer access in a loop.
iterator_range< SmallPtrSetIterator< llvm::InterleaveGroup< Instruction > * > > getInterleaveGroups()
Value * stripGetElementPtr(Value *Ptr, ScalarEvolution *SE, Loop *Lp)
If the argument is a GEP, then returns the operand identified by getGEPInductionOperand.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
void setInsertPos(InstTy *Inst)
const MemoryDepChecker & getDepChecker() const
the Memory Dependence Checker which can determine the loop-independent and loop-carried dependences b...
MapVector< Instruction *, uint64_t > computeMinimumValueSizes(ArrayRef< BasicBlock *> Blocks, DemandedBits &DB, const TargetTransformInfo *TTI=nullptr)
Compute a map of integer instructions to their minimum legal type size.
void getVectorVariantNames(const CallInst &CI, SmallVectorImpl< std::string > &VariantMappings)
Populates a set of strings representing the Vector Function ABI variants associated to the CallInst C...
Value * findScalarElement(Value *V, unsigned EltNo)
Given a vector and an element number, see if the scalar value is already around as a register...
This class represents lattice values for constants.
const Value * getSplatValue(const Value *V)
Get splat value if the input is a splat vector or return nullptr.
void push_back(const T &Elt)
Instruction * propagateMetadata(Instruction *I, ArrayRef< Value *> VL)
Specifically, let Kinds = [MD_tbaa, MD_alias_scope, MD_noalias, MD_fpmath, MD_nontemporal, MD_access_group].
The main scalar evolution driver.
bool isInterleaved(Instruction *Instr) const
Check if Instr belongs to any interleave group.
This class represents a function call, abstracting a target machine's calling convention.
This class implements a map that also provides access to all stored values in a deterministic order...
Contains the information about the kind of vectorization available.
std::enable_if< std::is_signed< T >::value, llvm::Optional< T > >::type checkedAdd(T LHS, T RHS)
Add two signed integers LHS and RHS.
static constexpr char const * _LLVM_
LLVM Internal VFABI ISA token for vector functions.
Holds the VFShape for a specific scalar to vector function mapping.
bool insertMember(InstTy *Instr, int32_t Index, Align NewAlign)
Try to insert a new member Instr with index Index and alignment NewAlign.
Intrinsic::ID getVectorIntrinsicIDForCall(const CallInst *CI, const TargetLibraryInfo *TLI)
Returns intrinsic ID for call.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
void reset()
Invalidate groups, e.g., in case all blocks in loop will be predicated contrary to original assumptio...
SmallVector< VFParameter, 8 > Parameters
bool operator==(const VFInfo &Other) const
InterleaveGroup(InstTy *Instr, int32_t Stride, Align Alignment)
Constant * createSequentialMask(IRBuilder<> &Builder, unsigned Start, unsigned NumInts, unsigned NumUndefs)
Create a sequential shuffle mask.
Drive the analysis of interleaved memory accesses in the loop.
static constexpr char const * MappingsAttrName
bool isSplatValue(const Value *V, unsigned Depth=0)
Return true if the input value is known to be a vector with all identical elements (potentially inclu...
The group of interleaved loads/stores sharing the same stride and close to each other.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
bool maskIsAllOneOrUndef(Value *Mask)
Given a mask vector of the form <Y x="" i1>="">, Return true if all of the elements of this predicate...
VFISAKind
Describes the type of Instruction Set Architecture.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
MDNode * intersectAccessGroups(const Instruction *Inst1, const Instruction *Inst2)
Compute the access-group list of access groups that Inst1 and Inst2 are both in.
InstTy * getMember(uint32_t Index) const
Get the member with the given index Index.
iterator find(const_arg_type_t< KeyT > Val)
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
bool erase(const KeyT &Val)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Value * concatenateVectors(IRBuilder<> &Builder, ArrayRef< Value *> Vecs)
Concatenate a list of vectors.
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
InterleaveGroup< Instruction > * getInterleaveGroup(const Instruction *Instr) const
Get the interleave group that Instr belongs to.
This is an important base class in LLVM.
Constant * createReplicatedMask(IRBuilder<> &Builder, unsigned ReplicationFactor, unsigned VF)
Create a mask with replicated elements.
Encapsulates information needed to describe a parameter.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool operator==(const VFShape &Other) const
void updateParam(VFParameter P)
Update the parameter in position P.ParamPos to P.
uint32_t getIndex(const InstTy *Instr) const
Get the index for the given member.
Optional< VFInfo > tryDemangleForVFABI(StringRef MangledName)
Function to contruct a VFInfo out of a mangled names in the following format:
Constant * createBitMaskForGaps(IRBuilder<> &Builder, unsigned VF, const InterleaveGroup< Instruction > &Group)
Create a mask that filters the members of an interleave group where there are gaps.
bool requiresScalarEpilogue() const
Returns true if an interleaved group that may access memory out-of-bounds requires a scalar epilogue ...
InterleaveGroup(uint32_t Factor, bool Reverse, Align Alignment)
bool maskIsAllZeroOrUndef(Value *Mask)
Given a mask vector of the form <Y x="" i1>="">, Return true if all of the elements of this predicate...
MDNode * uniteAccessGroups(MDNode *AccGroups1, MDNode *AccGroups2)
Compute the union of two access-group lists.
InterleavedAccessInfo(PredicatedScalarEvolution &PSE, Loop *L, DominatorTree *DT, LoopInfo *LI, const LoopAccessInfo *LAI)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This struct is a compact representation of a valid (non-zero power of two) alignment.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
const SmallVectorImpl< Dependence > * getDependences() const
Returns the memory dependences.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
bool erase(PtrType Ptr)
erase - If the set contains the specified pointer, remove it and return true, otherwise return false...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Provides information about what library functions are available for the current target.
An interface layer with SCEV used to manage how we see SCEV expressions for values in the context of ...
Drive the analysis of memory accesses in the loop.
bool hasVectorInstrinsicScalarOpd(Intrinsic::ID ID, unsigned ScalarOpdIdx)
Identifies if the vector form of the intrinsic has a scalar operand.
uint32_t getAlignment() const
A range adaptor for a pair of iterators.
Class for arbitrary precision integers.
bool isPredicated(MCInstrInfo const &MCII, MCInst const &MCI)
VFParamKind
Describes the type of Parameters.
Value * getUniqueCastUse(Value *Ptr, Loop *Lp, Type *Ty)
If a value has only one user that is a CastInst, return it.
Constant * createStrideMask(IRBuilder<> &Builder, unsigned Start, unsigned Stride, unsigned VF)
Create a stride shuffle mask.
unsigned getGEPInductionOperand(const GetElementPtrInst *Gep)
Find the operand of the GEP that should be checked for consecutive stores.
APInt possiblyDemandedEltsInMask(Value *Mask)
Given a mask vector of the form <Y x="" i1>="">, return an APInt (of bitwidth Y) for each lane which ...
This class represents an analyzed expression in the program.
Represents a single loop in the control flow graph.
APFloat abs(APFloat X)
Returns the absolute value of the argument.
uint32_t getFactor() const
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
VFParamKind getVFParamKindFromString(const StringRef Token)
Retrieve the VFParamKind from a string token.
Constant * createInterleaveMask(IRBuilder<> &Builder, unsigned VF, unsigned NumVecs)
Create an interleave shuffle mask.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
InstTy * getInsertPos() const
LLVM Value Representation.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
static bool blockNeedsPredication(BasicBlock *BB, Loop *TheLoop, DominatorTree *DT)
Return true if the block BB needs to be predicated in order for the loop to be vectorized.
StringRef - Represent a constant reference to a string, i.e.
std::enable_if< std::is_signed< T >::value, llvm::Optional< T > >::type checkedSub(T LHS, T RHS)
Subtract two signed integers LHS and RHS.
uint32_t getNumMembers() const
bool requiresScalarEpilogue() const
Returns true if this Group requires a scalar iteration to handle gaps.
bool operator==(const VFParameter &Other) const
bool isTriviallyVectorizable(Intrinsic::ID ID)
Identify if the intrinsic is trivially vectorizable.