15#ifndef LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPSHUFFLEANALYSIS_H
16#define LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPSHUFFLEANALYSIS_H
49 assert(V &&
"V cannot be nullptr");
51 "V does not have FixedVectorType");
54 unsigned VNumElements =
56 assert(VNumElements > ScalarTyNumElements &&
57 "the number of elements of V is not large enough");
58 assert(VNumElements % ScalarTyNumElements == 0 &&
59 "the number of elements of V is not a vectorized value");
60 return VNumElements / ScalarTyNumElements;
68 int Limit = Mask.size();
80 if (Limit % VF == 0 &&
all_of(
seq<int>(0, Limit / VF), [=](
int Idx) {
96 unsigned VF = Mask.size();
98 for (
int I = 0, Sz = ExtMask.
size();
I < Sz; ++
I) {
101 int MaskedIdx = Mask[ExtMask[
I] % VF];
142 bool SinglePermute) {
155 if (!IdentityOp || !SinglePermute ||
158 IdentityMask.
size()))) {
163 IdentityMask.
assign(Mask);
183 if (SV->isZeroEltSplat()) {
185 IdentityMask.
assign(Mask);
187 int LocalVF = Mask.size();
190 LocalVF = SVOpTy->getNumElements();
194 static_cast<unsigned>(
I) >= SV->getShuffleMask().size())
196 ExtMask[Idx] = SV->getMaskValue(
I);
206 if (!IsOp1Undef && !IsOp2Undef) {
208 for (
int &
I : Mask) {
211 if (SV->getMaskValue(
I % SV->getShuffleMask().size()) ==
219 Mask.swap(ShuffleMask);
221 Op = SV->getOperand(0);
223 Op = SV->getOperand(1);
231 "Expected masks of same sizes.");
236 Mask.swap(IdentityMask);
238 return SinglePermute &&
241 (Shuffle && Mask.size() == Shuffle->getShuffleMask().size() &&
242 Shuffle->isZeroEltSplat() &&
246 Shuffle->getShuffleMask()[
P.index()] == 0;
259 template <
typename T,
typename ShuffleBuilderTy,
typename... Args>
262 [[maybe_unused]]
bool ReVec, Args...
Arguments) {
263 assert(
V1 &&
"Expected at least one vector value.");
266 if (ScalarTyNumElements != 1) {
267 assert(ReVec &&
"FixedVectorType is not expected.");
272 Builder.resizeToMatch(
V1, V2);
273 int VF = Mask.size();
275 VF = FTy->getNumElements();
286 for (
int I = 0,
E = Mask.size();
I <
E; ++
I) {
288 CombinedMask1[
I] = Mask[
I];
290 CombinedMask2[
I] = Mask[
I] - VF;
304 for (
auto [Idx,
I] :
enumerate(CombinedMask1)) {
307 ExtMask1[Idx] = SV1->getMaskValue(
I);
314 for (
auto [Idx,
I] :
enumerate(CombinedMask2)) {
317 ExtMask2[Idx] = SV2->getMaskValue(
I);
323 if (SV1->getOperand(0)->getType() ==
324 SV2->getOperand(0)->getType() &&
325 SV1->getOperand(0)->getType() != SV1->getType() &&
328 Op1 = SV1->getOperand(0);
329 Op2 = SV2->getOperand(0);
331 int LocalVF = ShuffleMask1.
size();
333 LocalVF = FTy->getNumElements();
335 CombinedMask1.
swap(ShuffleMask1);
337 LocalVF = ShuffleMask2.
size();
339 LocalVF = FTy->getNumElements();
341 CombinedMask2.
swap(ShuffleMask2);
344 }
while (PrevOp1 != Op1 || PrevOp2 != Op2);
345 Builder.resizeToMatch(Op1, Op2);
351 .getKnownMinValue());
352 for (
int I = 0,
E = Mask.size();
I <
E; ++
I) {
355 "Expected undefined mask element");
356 CombinedMask1[
I] = CombinedMask2[
I] + (Op1 == Op2 ? 0 : VF);
365 return Builder.createIdentity(Op1);
366 return Builder.createShuffleVector(
371 return Builder.createPoison(
374 assert(
V1 &&
"Expected non-null value after looking through shuffles.");
377 return Builder.createShuffleVector(
V1, NewMask,
Arguments...);
378 return Builder.createIdentity(
V1);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU Lower Kernel Arguments
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Provides some synthesis utilities to produce sequences of values.
This file implements the SmallBitVector class.
This file defines the SmallVector class.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
Class to represent fixed width SIMD vectors.
unsigned getNumElements() const
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
This instruction constructs a fixed permutation of two input vectors.
static LLVM_ABI bool isZeroEltSplatMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask chooses all elements with the same value as the first element of exa...
static LLVM_ABI bool isIdentityMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask chooses elements from exactly one source vector without lane crossin...
static LLVM_ABI bool isExtractSubvectorMask(ArrayRef< int > Mask, int NumSrcElts, int &Index)
Return true if this shuffle mask is an extract subvector mask.
This is a 'bitvector' (really, a variable-sized bit array), optimized for the case when the array is ...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void assign(size_type NumElts, ValueParamT Elt)
void swap(SmallVectorImpl &RHS)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
BaseShuffleAnalysis(Type *ScalarTy)
static bool isIdentityMask(ArrayRef< int > Mask, const FixedVectorType *VecTy, bool IsStrict)
Checks if the mask is an identity mask.
static void transformMaskAfterShuffle(MutableArrayRef< int > CommonMask, ArrayRef< int > Mask)
Transforms mask CommonMask per given Mask to make proper set after shuffle emission.
unsigned getVF(Value *V) const
V is expected to be a vectorized value.
static void combineMasks(unsigned LocalVF, SmallVectorImpl< int > &Mask, ArrayRef< int > ExtMask)
Tries to combine 2 different masks into single one.
static T createShuffle(Value *V1, Value *V2, ArrayRef< int > Mask, ShuffleBuilderTy &Builder, Type *ScalarTy, bool ReVec, Args... Arguments)
Smart shuffle instruction emission, walks through shuffles trees and tries to find the best matching ...
static bool peekThroughShuffles(Value *&V, SmallVectorImpl< int > &Mask, bool SinglePermute)
Looks through shuffles trying to reduce final number of shuffles in the code.
A private "module" namespace for types and utilities used by this pass.
SmallBitVector isUndefVector(const Value *V, const SmallBitVector &UseMask)
Checks if the given value is actually an undefined constant vector.
unsigned getNumElements(Type *Ty)
void transformScalarShuffleIndiciesToVector(unsigned VecTyNumElements, SmallVectorImpl< int > &Mask)
SmallBitVector buildUseMask(int VF, ArrayRef< int > Mask, UseMask MaskArg)
Prepares a use bitset for the given mask either for the first argument or for the second.
@ SecondArg
The mask is expected to be for permutation of 2 vectors, check for the mask elements for the second a...
@ FirstArg
The mask is expected to be for permutation of 1-2 vectors, check for the mask elements for the first ...
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
constexpr auto equal_to(T &&Arg)
Functor variant of std::equal_to that can be used as a UnaryPredicate in functional algorithms like a...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
constexpr int PoisonMaskElem
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
constexpr auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.