LLVM 24.0.0git
slpvectorizer::BoUpSLP::ShuffleInstructionBuilder Class Referencefinal

Merges shuffle masks and emits final shuffle instruction, if required. More...

Inheritance diagram for slpvectorizer::BoUpSLP::ShuffleInstructionBuilder:
[legend]

Public Member Functions

 ShuffleInstructionBuilder (Type *ScalarTy, IRBuilderBase &Builder, BoUpSLP &R)
ValueadjustExtracts (const TreeEntry *E, MutableArrayRef< int > Mask, ArrayRef< std::optional< TTI::ShuffleKind > > ShuffleKinds, unsigned NumParts, bool &UseVecBaseAsInput)
 Adjusts extractelements after reusing them.
std::optional< Value * > needToDelay (const TreeEntry *E, ArrayRef< SmallVector< const TreeEntry * > > Deps) const
 Checks if the specified entry E needs to be delayed because of its dependency nodes.
void resetForSameNode ()
 Reset the builder to handle perfect diamond match.
void add (const TreeEntry &E1, const TreeEntry &E2, ArrayRef< int > Mask)
 Adds 2 input vectors (in form of tree entries) and the mask for their shuffling.
void add (const TreeEntry &E1, ArrayRef< int > Mask)
 Adds single input vector (in form of tree entry) and the mask for its shuffling.
void add (Value *V1, Value *V2, ArrayRef< int > Mask)
 Adds 2 input vectors and the mask for their shuffling.
void add (Value *V1, ArrayRef< int > Mask, bool=false)
 Adds another one input vector and the mask for the shuffling.
void addOrdered (Value *V1, ArrayRef< unsigned > Order)
 Adds another one input vector and the mask for the shuffling.
Valuegather (ArrayRef< Value * > VL, unsigned MaskVF=0, Value *Root=nullptr)
ValuecreateFreeze (Value *V)
Valuefinalize (ArrayRef< int > ExtMask, ArrayRef< std::pair< const TreeEntry *, unsigned > > SubVectors, ArrayRef< int > SubVectorsMask, unsigned VF=0, function_ref< void(Value *&, SmallVectorImpl< int > &, function_ref< Value *(Value *, Value *, ArrayRef< int >)>)> Action={})
 Finalize emission of the shuffles.
 ~ShuffleInstructionBuilder ()

Additional Inherited Members

Protected Member Functions inherited from llvm::slpvectorizer::BaseShuffleAnalysis
 BaseShuffleAnalysis (Type *ScalarTy)
unsigned getVF (Value *V) const
 V is expected to be a vectorized value.
Static Protected Member Functions inherited from llvm::slpvectorizer::BaseShuffleAnalysis
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 inherited from llvm::slpvectorizer::BaseShuffleAnalysis
TypeScalarTy = nullptr

Detailed Description

Merges shuffle masks and emits final shuffle instruction, if required.

It supports shuffling of 2 input vectors. It implements lazy shuffles emission, when the actual shuffle instruction is generated only if this is actually required. Otherwise, the shuffle instruction emission is delayed till the end of the process, to reduce the number of emitted instructions and further analysis/transformations. The class also will look 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 emit

%res = shufflevector <2 x ty> %0, %1, <0, 1, 2, 3>

instead. 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 emit

%res = shufflevector <2 x ty> %0, %1, <0, 1, 2, 3>

instead.

Definition at line 21302 of file SLPVectorizer.cpp.

Constructor & Destructor Documentation

◆ ShuffleInstructionBuilder()

slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::ShuffleInstructionBuilder ( Type * ScalarTy,
IRBuilderBase & Builder,
BoUpSLP & R )
inline

◆ ~ShuffleInstructionBuilder()

slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::~ShuffleInstructionBuilder ( )
inline

Definition at line 21833 of file SLPVectorizer.cpp.

References assert().

Member Function Documentation

◆ add() [1/4]

void slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::add ( const TreeEntry & E1,
ArrayRef< int > Mask )
inline

Adds single input vector (in form of tree entry) and the mask for its shuffling.

Definition at line 21620 of file SLPVectorizer.cpp.

References add(), and llvm::V1.

◆ add() [2/4]

void slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::add ( const TreeEntry & E1,
const TreeEntry & E2,
ArrayRef< int > Mask )
inline

Adds 2 input vectors (in form of tree entries) and the mask for their shuffling.

Definition at line 21613 of file SLPVectorizer.cpp.

References add(), and llvm::V1.

Referenced by add(), add(), and addOrdered().

◆ add() [3/4]

void slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::add ( Value * V1,
ArrayRef< int > Mask,
bool = false )
inline

◆ add() [4/4]

void slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::add ( Value * V1,
Value * V2,
ArrayRef< int > Mask )
inline

◆ addOrdered()

void slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::addOrdered ( Value * V1,
ArrayRef< unsigned > Order )
inline

Adds another one input vector and the mask for the shuffling.

Definition at line 21712 of file SLPVectorizer.cpp.

References add(), llvm::slpvectorizer::inversePermutation(), and llvm::V1.

◆ adjustExtracts()

Value * slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::adjustExtracts ( const TreeEntry * E,
MutableArrayRef< int > Mask,
ArrayRef< std::optional< TTI::ShuffleKind > > ShuffleKinds,
unsigned NumParts,
bool & UseVecBaseAsInput )
inline

◆ createFreeze()

Value * slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::createFreeze ( Value * V)
inline

Definition at line 21724 of file SLPVectorizer.cpp.

◆ finalize()

Value * slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::finalize ( ArrayRef< int > ExtMask,
ArrayRef< std::pair< const TreeEntry *, unsigned > > SubVectors,
ArrayRef< int > SubVectorsMask,
unsigned VF = 0,
function_ref< void(Value *&, SmallVectorImpl< int > &, function_ref< Value *(Value *, Value *, ArrayRef< int >)>)> Action = {} )
inline

Finalize emission of the shuffles.

Parameters
Actionthe action (if any) to be performed before final applying of the ExtMask mask.

Definition at line 21728 of file SLPVectorizer.cpp.

◆ gather()

Value * slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::gather ( ArrayRef< Value * > VL,
unsigned MaskVF = 0,
Value * Root = nullptr )
inline

◆ needToDelay()

std::optional< Value * > slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::needToDelay ( const TreeEntry * E,
ArrayRef< SmallVector< const TreeEntry * > > Deps ) const
inline

Checks if the specified entry E needs to be delayed because of its dependency nodes.

Definition at line 21589 of file SLPVectorizer.cpp.

References llvm::all_of(), llvm::PoisonValue::get(), llvm::PointerType::getUnqual(), llvm::slpvectorizer::getWidenedType(), and llvm::slpvectorizer::BaseShuffleAnalysis::ScalarTy.

◆ resetForSameNode()

void slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::resetForSameNode ( )
inline

Reset the builder to handle perfect diamond match.

Definition at line 21606 of file SLPVectorizer.cpp.


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