12#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_VECUTILS_H
13#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_VECUTILS_H
47 assert(!isa<ScalableVectorType>(Ty));
48 return Ty->
isVectorTy() ? cast<FixedVectorType>(Ty)->getNumElements() : 1;
52 return Ty->
isVectorTy() ? cast<FixedVectorType>(Ty)->getElementType() : Ty;
57 template <
typename LoadOrStoreT>
60 static_assert(std::is_same<LoadOrStoreT, LoadInst>::value ||
61 std::is_same<LoadOrStoreT, StoreInst>::value,
62 "Expected Load or Store!");
67 return *Diff == ElmBytes;
70 template <
typename LoadOrStoreT>
73 static_assert(std::is_same<LoadOrStoreT, LoadInst>::value ||
74 std::is_same<LoadOrStoreT, StoreInst>::value,
75 "Expected Load or Store!");
76 assert(isa<LoadOrStoreT>(Bndl[0]) &&
"Expected Load or Store!");
77 auto *LastLS = cast<LoadOrStoreT>(Bndl[0]);
79 assert(isa<LoadOrStoreT>(V) &&
80 "Unimplemented: we only support StoreInst!");
81 auto *LS = cast<LoadOrStoreT>(V);
92 assert(!isa<ScalableVectorType>(Ty) &&
"Expect scalar or fixed vector");
93 if (
auto *FixedVecTy = dyn_cast<FixedVectorType>(Ty))
94 return FixedVecTy->getNumElements();
107 for (
Value *V : Bndl)
116 auto *VecTy = cast<FixedVectorType>(ElemTy);
117 ElemTy = VecTy->getElementType();
118 NumElts = VecTy->getNumElements() * NumElts;
137 return isa<Instruction>(V) && cast<Instruction>(V)->getParent() == BB;
140 if (It == Vals.
end())
147 auto *
I = dyn_cast<Instruction>(V);
152 if (
I->getParent() != BB)
166 while (
I !=
nullptr && isa<PHINode>(
I)) {
168 I =
I->getNextNode();
182 if (NScalarTy != ScalarTy)
231 if (!isa<InsertElementInst>(
I))
233 auto *BB0 =
I->getParent();
236 assert(ExpectedNumInserts >= 2 &&
"Expected at least 2 inserts!");
238 Pack.Operands.resize(ExpectedNumInserts);
241 for (
auto ExpectedLane :
reverse(seq<unsigned>(ExpectedNumInserts))) {
242 if (InsertI ==
nullptr)
247 auto *LaneC = dyn_cast<ConstantInt>(InsertI->
getOperand(2));
248 if (LaneC ==
nullptr || LaneC->getSExtValue() != ExpectedLane)
250 Pack.Instrs.push_back(InsertI);
254 if (ExpectedLane == 0) {
256 if (!isa<PoisonValue>(
Op))
259 InsertI = dyn_cast<InsertElementInst>(
Op);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
const T & front() const
front - Get the first element.
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
The main scalar evolution driver.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
LLVM Value Representation.
Contains a list of sandboxir::Instruction's.
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
A sandboxir::User with operands, opcode and linked with previous/next instructions in an instruction ...
bool comesBefore(const Instruction *Other) const
Given an instruction Other in the same basic block as this instruction, return true if this instructi...
LLVM_ABI BasicBlock * getParent() const
\Returns the BasicBlock containing this Instruction, or null if it is detached.
Just like llvm::Type these are immutable, unique, never get freed and can only be created via static ...
bool isVectorTy() const
True if this is an instance of VectorType.
Value * getOperand(unsigned OpIdx) const
static std::optional< int > getPointerDiffInBytes(LoadOrStoreT *I0, LoadOrStoreT *I1, ScalarEvolution &SE)
\Returns the gap between the memory locations accessed by I0 and I1 in bytes.
static unsigned getNumBits(Type *Ty, const DataLayout &DL)
\Returns the number of bits of Ty.
static Type * getExpectedType(const Value *V)
\Returns the expected type of Value V.
A SandboxIR Value has users. This is the base class.
static Type * tryGetCommonScalarType(ArrayRef< Value * > Bndl)
If all values in Bndl are of the same scalar type then return it, otherwise return nullptr.
static Instruction * getLowest(ArrayRef< Instruction * > Instrs)
\Returns the instruction in Instrs that is lowest in the BB.
static Type * getCommonScalarType(ArrayRef< Value * > Bndl)
Similar to tryGetCommonScalarType() but will assert that there is a common type.
static int getNumElements(Type *Ty)
\Returns the number of elements in Ty.
static std::optional< PackPattern > matchPack(Instruction *I)
If I is the last instruction of a pack pattern (i.e., an InsertElement into a vector),...
static Instruction * getLastPHIOrSelf(Instruction *I)
If I is not a PHI it returns it.
static unsigned getNumLanes(Type *Ty)
\Returns the number of vector lanes of Ty or 1 if not a vector.
static Instruction * getLowest(ArrayRef< Value * > Vals, BasicBlock *BB)
\Returns the lowest instruction in Vals, or nullptr if no instructions are found.
static LLVM_DUMP_METHOD void dump(ArrayRef< Value * > Bndl)
Helper dump function for debugging.
static Type * getWideType(Type *ElemTy, unsigned NumElts)
\Returns <NumElts x ElemTy>.
static bool areConsecutive(LoadOrStoreT *I1, LoadOrStoreT *I2, ScalarEvolution &SE, const DataLayout &DL)
\Returns true if I1 and I2 are load/stores accessing consecutive memory addresses.
static Type * getElementType(Type *Ty)
Returns Ty if scalar or its element type if vector.
static bool areConsecutive(ArrayRef< Value * > &Bndl, ScalarEvolution &SE, const DataLayout &DL)
static unsigned getNumLanes(Value *V)
\Returns the expected vector lanes of V or 1 if not a vector.
static unsigned getNumLanes(ArrayRef< Value * > Bndl)
\Returns the total number of lanes across all values in Bndl.
static LLVM_ABI unsigned getFloorPowerOf2(unsigned Num)
\Returns the first integer power of 2 that is <= Num.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
auto reverse(ContainerTy &&C)
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
static bool isEqual(const SmallVector< sandboxir::Value * > &Vec1, const SmallVector< sandboxir::Value * > &Vec2)
static SmallVector< sandboxir::Value * > getEmptyKey()
static unsigned getHashValue(const SmallVector< sandboxir::Value * > &Vec)
static SmallVector< sandboxir::Value * > getTombstoneKey()
An information struct used to provide DenseMap with the various necessary components for a given valu...
Helper struct for matchPack().
SmallVector< Value * > Operands
The "external" operands of the pack pattern, i.e., the values that get packed into a vector,...
SmallVector< Instruction * > Instrs
The insertelement instructions that form the pack pattern in bottom-up order, i.e....