LLVM 24.0.0git
llvm::slpvectorizer::BaseShuffleAnalysis Class Reference

The base class for shuffle instruction emission and shuffle cost estimation. More...

#include "Transforms/Vectorize/SLPVectorizer/SLPShuffleAnalysis.h"

Inheritance diagram for llvm::slpvectorizer::BaseShuffleAnalysis:
[legend]

Protected Member Functions

 BaseShuffleAnalysis (Type *ScalarTy)
unsigned getVF (Value *V) const
 V is expected to be a vectorized value.

Static Protected Member Functions

static bool isIdentityMask (ArrayRef< int > Mask, const FixedVectorType *VecTy, bool IsStrict)
 Checks if the mask is an identity mask.
static void combineMasks (unsigned LocalVF, SmallVectorImpl< int > &Mask, ArrayRef< int > ExtMask)
 Tries to combine 2 different masks into single one.
static bool peekThroughShuffles (Value *&V, SmallVectorImpl< int > &Mask, bool SinglePermute)
 Looks through shuffles trying to reduce final number of shuffles in the code.
template<typename T, typename ShuffleBuilderTy, typename... Args>
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 vector for the actual shuffle instruction.
static void transformMaskAfterShuffle (MutableArrayRef< int > CommonMask, ArrayRef< int > Mask)
 Transforms mask CommonMask per given Mask to make proper set after shuffle emission.

Protected Attributes

TypeScalarTy = nullptr

Detailed Description

The base class for shuffle instruction emission and shuffle cost estimation.

Definition at line 36 of file SLPShuffleAnalysis.h.

Constructor & Destructor Documentation

◆ BaseShuffleAnalysis()

llvm::slpvectorizer::BaseShuffleAnalysis::BaseShuffleAnalysis ( Type * ScalarTy)
inlineprotected

Member Function Documentation

◆ combineMasks()

void llvm::slpvectorizer::BaseShuffleAnalysis::combineMasks ( unsigned LocalVF,
SmallVectorImpl< int > & Mask,
ArrayRef< int > ExtMask )
inlinestaticprotected

Tries to combine 2 different masks into single one.

Parameters
LocalVFVector length of the permuted input vector. Mask may change the size of the vector, LocalVF is the original size of the shuffled vector.

Definition at line 94 of file SLPShuffleAnalysis.h.

References I, llvm::PoisonMaskElem, and llvm::ArrayRef< T >::size().

Referenced by createShuffle(), and peekThroughShuffles().

◆ createShuffle()

template<typename T, typename ShuffleBuilderTy, typename... Args>
T llvm::slpvectorizer::BaseShuffleAnalysis::createShuffle ( Value * V1,
Value * V2,
ArrayRef< int > Mask,
ShuffleBuilderTy & Builder,
Type * ScalarTy,
bool ReVec,
Args... Arguments )
inlinestaticprotected

◆ getVF()

unsigned llvm::slpvectorizer::BaseShuffleAnalysis::getVF ( Value * V) const
inlineprotected

V is expected to be a vectorized value.

When REVEC is disabled, there is no difference between VF and VNumElements. When REVEC is enabled, VF is VNumElements / ScalarTyNumElements. e.g., if ScalarTy is <4 x Ty> and V1 is <8 x Ty>, 2 is returned instead of 8.

Definition at line 48 of file SLPShuffleAnalysis.h.

References assert(), llvm::cast(), llvm::slpvectorizer::getNumElements(), llvm::isa(), and ScalarTy.

Referenced by slpvectorizer::BoUpSLP::ShuffleCostEstimator::add(), slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::add(), and slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::add().

◆ isIdentityMask()

bool llvm::slpvectorizer::BaseShuffleAnalysis::isIdentityMask ( ArrayRef< int > Mask,
const FixedVectorType * VecTy,
bool IsStrict )
inlinestaticprotected

Checks if the mask is an identity mask.

Parameters
IsStrictif is true the function returns false if mask size does not match vector size.

Definition at line 66 of file SLPShuffleAnalysis.h.

References llvm::all_of(), llvm::equal_to(), llvm::FixedVectorType::getNumElements(), llvm::ShuffleVectorInst::isExtractSubvectorMask(), llvm::ShuffleVectorInst::isIdentityMask(), llvm::PoisonMaskElem, and llvm::seq().

Referenced by peekThroughShuffles().

◆ peekThroughShuffles()

bool llvm::slpvectorizer::BaseShuffleAnalysis::peekThroughShuffles ( Value *& V,
SmallVectorImpl< int > & Mask,
bool SinglePermute )
inlinestaticprotected

Looks through shuffles trying to reduce final number of shuffles in the code.

The function looks through the previously emitted shuffle instructions and properly mark indices in mask as undef. For example, given the code

%s1 = shufflevector <2 x ty> %0, poison, <1, 0>
%s2 = shufflevector <2 x ty> %1, poison, <1, 0>

and if need to emit shuffle of s1 and s2 with mask <1, 0, 3, 2>, it will look through s1 and s2 and select vectors %0 and %1 with mask <0, 1, 2, 3> for the shuffle. If 2 operands are of different size, the smallest one will be resized and the mask recalculated properly. For example, given the code

%s1 = shufflevector <2 x ty> %0, poison, <1, 0, 1, 0>
%s2 = shufflevector <2 x ty> %1, poison, <1, 0, 1, 0>

and if need to emit shuffle of s1 and s2 with mask <1, 0, 5, 4>, it will look through s1 and s2 and select vectors %0 and %1 with mask <0, 1, 2, 3> for the shuffle. So, it tries to transform permutations to simple vector merge, if possible.

Parameters
VThe input vector which must be shuffled using the given Mask. If the better candidate is found, V is set to this best candidate vector.
MaskThe input mask for the shuffle. If the best candidate is found during looking-through-shuffles attempt, it is updated accordingly.
SinglePermutetrue if the shuffle operation is originally a single-value-permutation. In this case the look-through-shuffles procedure may look for resizing shuffles as the best candidates.
Returns
true if the shuffle results in the non-resizing identity shuffle (and thus can be ignored), false - otherwise.

Definition at line 141 of file SLPShuffleAnalysis.h.

References llvm::all_of(), assert(), llvm::SmallVectorImpl< T >::assign(), llvm::slpvectorizer::buildUseMask(), llvm::cast(), combineMasks(), llvm::dyn_cast(), llvm::enumerate(), llvm::slpvectorizer::FirstArg, I, isIdentityMask(), llvm::slpvectorizer::isUndefVector(), llvm::ShuffleVectorInst::isZeroEltSplatMask(), P, llvm::PoisonMaskElem, llvm::slpvectorizer::SecondArg, and llvm::SmallVectorTemplateCommon< T, typename >::size().

Referenced by createShuffle().

◆ transformMaskAfterShuffle()

void llvm::slpvectorizer::BaseShuffleAnalysis::transformMaskAfterShuffle ( MutableArrayRef< int > CommonMask,
ArrayRef< int > Mask )
inlinestaticprotected

Member Data Documentation

◆ ScalarTy


The documentation for this class was generated from the following file: