LLVM 20.0.0git
Classes | Public Types | Public Member Functions | Friends | List of all members
llvm::slpvectorizer::BoUpSLP Class Reference

Bottom Up SLP Vectorizer. More...

Classes

struct  EdgeInfo
 This structure holds any data we need about the edges being traversed during buildTree_rec(). More...
 
class  LookAheadHeuristics
 A helper class used for scoring candidates for two consecutive lanes. More...
 
class  ShuffleCostEstimator
 Merges shuffle masks and emits final shuffle instruction, if required. More...
 
class  ShuffleInstructionBuilder
 Merges shuffle masks and emits final shuffle instruction, if required. More...
 
class  VLOperands
 A helper data structure to hold the operands of a vector of instructions. More...
 

Public Types

enum class  LoadsState { Gather , Vectorize , ScatterVectorize , StridedVectorize }
 Tracks the state we can represent the loads in the given sequence. More...
 
using ValueList = SmallVector< Value *, 8 >
 
using InstrList = SmallVector< Instruction *, 16 >
 
using ValueSet = SmallPtrSet< Value *, 16 >
 
using StoreList = SmallVector< StoreInst *, 8 >
 
using ExtraValueToDebugLocsMap = SmallDenseSet< Value *, 4 >
 
using OrdersType = SmallVector< unsigned, 4 >
 

Public Member Functions

 BoUpSLP (Function *Func, ScalarEvolution *Se, TargetTransformInfo *Tti, TargetLibraryInfo *TLi, AAResults *Aa, LoopInfo *Li, DominatorTree *Dt, AssumptionCache *AC, DemandedBits *DB, const DataLayout *DL, OptimizationRemarkEmitter *ORE)
 
ValuevectorizeTree ()
 Vectorize the tree that starts with the elements in VL.
 
ValuevectorizeTree (const ExtraValueToDebugLocsMap &ExternallyUsedValues, Instruction *ReductionRoot=nullptr)
 Vectorize the tree but with the list of externally used values ExternallyUsedValues.
 
InstructionCost getSpillCost () const
 
InstructionCost getTreeCost (ArrayRef< Value * > VectorizedVals={})
 
void buildTree (ArrayRef< Value * > Roots, const SmallDenseSet< Value * > &UserIgnoreLst)
 Construct a vectorizable tree that starts at Roots, ignoring users for the purpose of scheduling and extraction in the UserIgnoreLst.
 
void buildTree (ArrayRef< Value * > Roots)
 Construct a vectorizable tree that starts at Roots.
 
bool doesRootHaveInTreeUses () const
 Returns whether the root node has in-tree uses.
 
ArrayRef< Value * > getRootNodeScalars () const
 Return the scalars of the root node.
 
std::optional< std::pair< Type *, bool > > getRootNodeTypeWithNoCast () const
 Returns the type/is-signed info for the root node in the graph without casting.
 
bool isSignedMinBitwidthRootNode () const
 Checks if the root graph node can be emitted with narrower bitwidth at codegen and returns it signedness, if so.
 
FixedVectorTypegetReductionType () const
 Returns reduction type after minbitdth analysis.
 
void buildExternalUses (const ExtraValueToDebugLocsMap &ExternallyUsedValues={})
 Builds external uses of the vectorized scalars, i.e.
 
void transformNodes ()
 Transforms graph nodes to target specific representations, if profitable.
 
void deleteTree ()
 Clear the internal data structures that are created by 'buildTree'.
 
unsigned getTreeSize () const
 
unsigned getCanonicalGraphSize () const
 Returns the base graph size, before any transformations.
 
void optimizeGatherSequence ()
 Perform LICM and CSE on the newly generated gather sequences.
 
bool isIdentityOrder (ArrayRef< unsigned > Order) const
 Does this non-empty order represent an identity order? Identity should be represented as an empty order, so this is used to decide if we can canonicalize a computed order.
 
std::optional< OrdersTypefindReusedOrderedScalars (const TreeEntry &TE)
 Checks if the specified gather tree entry TE can be represented as a shuffled vector entry + (possibly) permutation with other gathers.
 
std::optional< OrdersTypefindPartiallyOrderedLoads (const TreeEntry &TE)
 Sort loads into increasing pointers offsets to allow greater clustering.
 
std::optional< OrdersTypegetReorderingData (const TreeEntry &TE, bool TopToBottom)
 Gets reordering data for the given tree entry.
 
void reorderTopToBottom ()
 Reorders the current graph to the most profitable order starting from the root node to the leaf nodes.
 
void reorderBottomToTop (bool IgnoreReorder=false)
 Reorders the current graph to the most profitable order starting from leaves to the root.
 
unsigned getVectorElementSize (Value *V)
 
void computeMinimumValueSizes ()
 Compute the minimum type sizes required to represent the entries in a vectorizable tree.
 
unsigned getMaxVecRegSize () const
 
unsigned getMinVecRegSize () const
 
unsigned getMinVF (unsigned Sz) const
 
unsigned getMaximumVF (unsigned ElemWidth, unsigned Opcode) const
 
unsigned canMapToVector (Type *T) const
 Check if homogeneous aggregate is isomorphic to some VectorType.
 
bool isTreeTinyAndNotFullyVectorizable (bool ForReduction=false) const
 
bool isTreeNotExtendable () const
 Checks if the graph and all its subgraphs cannot be better vectorized.
 
bool isLoadCombineReductionCandidate (RecurKind RdxKind) const
 Assume that a legal-sized 'or'-reduction of shifted/zexted loaded values can be load combined in the backend.
 
bool isLoadCombineCandidate (ArrayRef< Value * > Stores) const
 Assume that a vector of stores of bitwise-or/shifted/zexted loaded values can be load combined in the backend.
 
LoadsState canVectorizeLoads (ArrayRef< Value * > VL, const Value *VL0, SmallVectorImpl< unsigned > &Order, SmallVectorImpl< Value * > &PointerOps, unsigned *BestVF=nullptr, bool TryRecursiveCheck=true) const
 Checks if the given array of loads can be represented as a vectorized, scatter or just simple gather.
 
template<typename T >
void registerNonVectorizableLoads (ArrayRef< T * > VL)
 Registers non-vectorizable sequence of loads.
 
template<typename T >
bool areKnownNonVectorizableLoads (ArrayRef< T * > VL) const
 Checks if the given loads sequence is known as not vectorizable.
 
OptimizationRemarkEmittergetORE ()
 
std::optional< int > findBestRootPair (ArrayRef< std::pair< Value *, Value * > > Candidates, int Limit=LookAheadHeuristics::ScoreFail) const
 Evaluate each pair in Candidates and return index into Candidates for a pair which have highest score deemed to have best chance to form root of profitable tree to vectorize.
 
bool isDeleted (Instruction *I) const
 Checks if the instruction is marked for deletion.
 
void eraseInstruction (Instruction *I)
 Removes an instruction from its block and eventually deletes it.
 
template<typename T >
void removeInstructionsAndOperands (ArrayRef< T * > DeadVals)
 Remove instructions from the parent function and clear the operands of DeadVals instructions, marking for deletion trivially dead operands.
 
bool isAnalyzedReductionRoot (Instruction *I) const
 Checks if the instruction was already analyzed for being possible reduction root.
 
void analyzedReductionRoot (Instruction *I)
 Register given instruction as already analyzed for being possible reduction root.
 
bool areAnalyzedReductionVals (ArrayRef< Value * > VL) const
 Checks if the provided list of reduced values was checked already for vectorization.
 
void analyzedReductionVals (ArrayRef< Value * > VL)
 Adds the list of reduced values to list of already checked values for the vectorization.
 
void clearReductionData ()
 Clear the list of the analyzed reduction root instructions.
 
bool isAnyGathered (const SmallDenseSet< Value * > &Vals) const
 Checks if the given value is gathered in one of the nodes.
 
bool isGathered (const Value *V) const
 Checks if the given value is gathered in one of the nodes.
 
bool isNotScheduled (const Value *V) const
 Checks if the specified value was not schedule.
 
bool isVectorized (Value *V) const
 Check if the value is vectorized in the tree.
 
 ~BoUpSLP ()
 

Friends

struct GraphTraits< BoUpSLP * >
 
struct DOTGraphTraits< BoUpSLP * >
 
raw_ostreamoperator<< (raw_ostream &os, const BoUpSLP::ScheduleData &SD)
 

Detailed Description

Bottom Up SLP Vectorizer.

Definition at line 1314 of file SLPVectorizer.cpp.

Member Typedef Documentation

◆ ExtraValueToDebugLocsMap

Definition at line 1333 of file SLPVectorizer.cpp.

◆ InstrList

Definition at line 1330 of file SLPVectorizer.cpp.

◆ OrdersType

Definition at line 1334 of file SLPVectorizer.cpp.

◆ StoreList

Definition at line 1332 of file SLPVectorizer.cpp.

◆ ValueList

Definition at line 1329 of file SLPVectorizer.cpp.

◆ ValueSet

Definition at line 1331 of file SLPVectorizer.cpp.

Member Enumeration Documentation

◆ LoadsState

Tracks the state we can represent the loads in the given sequence.

Enumerator
Gather 
Vectorize 
ScatterVectorize 
StridedVectorize 

Definition at line 1322 of file SLPVectorizer.cpp.

Constructor & Destructor Documentation

◆ BoUpSLP()

llvm::slpvectorizer::BoUpSLP::BoUpSLP ( Function Func,
ScalarEvolution Se,
TargetTransformInfo Tti,
TargetLibraryInfo TLi,
AAResults Aa,
LoopInfo Li,
DominatorTree Dt,
AssumptionCache AC,
DemandedBits DB,
const DataLayout DL,
OptimizationRemarkEmitter ORE 
)
inline

◆ ~BoUpSLP()

BoUpSLP::~BoUpSLP ( )

Member Function Documentation

◆ analyzedReductionRoot()

void llvm::slpvectorizer::BoUpSLP::analyzedReductionRoot ( Instruction I)
inline

Register given instruction as already analyzed for being possible reduction root.

Definition at line 2894 of file SLPVectorizer.cpp.

References I.

◆ analyzedReductionVals()

void llvm::slpvectorizer::BoUpSLP::analyzedReductionVals ( ArrayRef< Value * >  VL)
inline

Adds the list of reduced values to list of already checked values for the vectorization.

Definition at line 2904 of file SLPVectorizer.cpp.

References llvm::hash_value(), and llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::insert().

Referenced by transformNodes().

◆ areAnalyzedReductionVals()

bool llvm::slpvectorizer::BoUpSLP::areAnalyzedReductionVals ( ArrayRef< Value * >  VL) const
inline

Checks if the provided list of reduced values was checked already for vectorization.

Definition at line 2899 of file SLPVectorizer.cpp.

References llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::contains(), and llvm::hash_value().

◆ areKnownNonVectorizableLoads()

template<typename T >
bool llvm::slpvectorizer::BoUpSLP::areKnownNonVectorizableLoads ( ArrayRef< T * >  VL) const
inline

Checks if the given loads sequence is known as not vectorizable.

Definition at line 1628 of file SLPVectorizer.cpp.

References llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::contains(), and llvm::hash_value().

Referenced by canVectorizeLoads(), and transformNodes().

◆ buildExternalUses()

void BoUpSLP::buildExternalUses ( const ExtraValueToDebugLocsMap ExternallyUsedValues = {})

Builds external uses of the vectorized scalars, i.e.

the list of vectorized scalars to be extracted, their lanes and their scalar users. ExternallyUsedValues contains additional list of external uses to handle vectorization of reductions.

Definition at line 6469 of file SLPVectorizer.cpp.

References assert(), llvm::dbgs(), doesInTreeUserNeedToExtract(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::end(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::find(), llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::find(), isDeleted(), LLVM_DEBUG, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::try_emplace(), and UsesLimit.

◆ buildTree() [1/2]

void BoUpSLP::buildTree ( ArrayRef< Value * >  Roots)

Construct a vectorizable tree that starts at Roots.

Definition at line 6702 of file SLPVectorizer.cpp.

References allSameType(), and deleteTree().

◆ buildTree() [2/2]

void BoUpSLP::buildTree ( ArrayRef< Value * >  Roots,
const SmallDenseSet< Value * > &  UserIgnoreLst 
)

Construct a vectorizable tree that starts at Roots, ignoring users for the purpose of scheduling and extraction in the UserIgnoreLst.

Definition at line 6693 of file SLPVectorizer.cpp.

References allSameType(), and deleteTree().

◆ canMapToVector()

unsigned BoUpSLP::canMapToVector ( Type T) const

Check if homogeneous aggregate is isomorphic to some VectorType.

Accepts homogeneous multidimensional aggregate of scalars/vectors like {[4 x i16], [4 x i16]}, { <2 x float>, <2 x float> }, {{{i16, i16}, {i16, i16}}, {{i16, i16}, {i16, i16}}} and so on.

Returns
number of elements in vector if isomorphism exists, 0 otherwise.

Definition at line 8823 of file SLPVectorizer.cpp.

References llvm::DataLayout::getTypeStoreSizeInBits(), getWidenedType(), llvm::Type::isEmptyTy(), isValidElementType(), and N.

◆ canVectorizeLoads()

BoUpSLP::LoadsState BoUpSLP::canVectorizeLoads ( ArrayRef< Value * >  VL,
const Value VL0,
SmallVectorImpl< unsigned > &  Order,
SmallVectorImpl< Value * > &  PointerOps,
unsigned BestVF = nullptr,
bool  TryRecursiveCheck = true 
) const

Checks if the given array of loads can be represented as a vectorized, scatter or just simple gather.

Parameters
VLlist of loads.
VL0main load value.
Orderreturned order of load instructions.
PointerOpsreturned list of pointer operands.
BestVFreturn best vector factor, if recursive check found better vectorization sequences rather than masked gather.
TryRecursiveCheckused to check if long masked gather can be represented as a serie of loads/insert subvector, if profitable.

Definition at line 4951 of file SLPVectorizer.cpp.

References llvm::all_of(), llvm::any_of(), areKnownNonVectorizableLoads(), arePointersCompatible(), llvm::SmallVectorTemplateCommon< T, typename >::back(), llvm::SmallVectorTemplateCommon< T, typename >::begin(), llvm::ArrayRef< T >::begin(), llvm::CallingConv::C, calculateRtStride(), canVectorizeLoads(), llvm::SmallVectorImpl< T >::clear(), llvm::APInt::clearAllBits(), CostKind, llvm::count_if(), DL, llvm::doesNotNeedToBeScheduled(), llvm::SmallVectorBase< Size_T >::empty(), llvm::ArrayRef< T >::end(), End, llvm::enumerate(), llvm::TargetTransformInfo::forceScalarizeMaskedGather(), llvm::SmallVectorTemplateCommon< T, typename >::front(), llvm::ArrayRef< T >::front(), Gather, GEP, llvm::APInt::getAllOnes(), llvm::TargetTransformInfo::getGatherScatterOpCost(), getGEPCosts(), llvm::TargetTransformInfo::getInstructionCost(), llvm::LoopInfoBase< BlockT, LoopT >::getLoopFor(), llvm::TargetTransformInfo::getMemoryOpCost(), getMinVF(), getNumElements(), llvm::APInt::getOneBitSet(), getParent(), llvm::getPointerOperand(), llvm::getPointersDiff(), llvm::TargetTransformInfo::getScalarizationOverhead(), getShuffleCost(), llvm::TargetTransformInfo::getStridedMemoryOpCost(), llvm::Value::getType(), llvm::getUnderlyingObject(), getWidenedType(), llvm::has_single_bit(), I, Idx, llvm::SmallSet< T, N, C >::insert(), llvm::APInt::isAllOnes(), llvm::TargetTransformInfo::isLegalMaskedGather(), llvm::TargetTransformInfo::isLegalStridedLoadStore(), isReverseOrder(), llvm::TargetTransformInfo::isTypeLegal(), llvm::APInt::isZero(), MaxProfitableLoadStride, MinProfitableStridedLoads, P, Ptr, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::SmallVectorImpl< T >::resize(), ScatterVectorize, llvm::APInt::setAllBits(), llvm::APInt::setBits(), llvm::ArrayRef< T >::size(), llvm::SmallSet< T, N, C >::size(), llvm::SmallVectorBase< Size_T >::size(), llvm::TargetTransformInfo::SK_Broadcast, llvm::TargetTransformInfo::SK_InsertSubvector, llvm::ArrayRef< T >::slice(), SLPCostThreshold, llvm::sortPtrAccesses(), StridedVectorize, llvm::TargetTransformInfo::TCK_RecipThroughput, and Vectorize.

Referenced by canVectorizeLoads(), getReorderingData(), and transformNodes().

◆ clearReductionData()

void llvm::slpvectorizer::BoUpSLP::clearReductionData ( )
inline

Clear the list of the analyzed reduction root instructions.

Definition at line 2908 of file SLPVectorizer.cpp.

References llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::clear().

◆ computeMinimumValueSizes()

void BoUpSLP::computeMinimumValueSizes ( )

Compute the minimum type sizes required to represent the entries in a vectorizable tree.

Definition at line 18072 of file SLPVectorizer.cpp.

References llvm::all_of(), llvm::any_of(), assert(), llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::begin(), llvm::SmallVectorTemplateCommon< T, typename >::begin(), llvm::ArrayRef< T >::begin(), llvm::bit_ceil(), llvm::SmallVectorImpl< T >::clear(), llvm::ComputeNumSignBits(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::contains(), llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::contains(), DL, llvm::slpvectorizer::BoUpSLP::EdgeInfo::EdgeIdx, llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::empty(), llvm::SmallVectorBase< Size_T >::empty(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::SmallVectorTemplateCommon< T, typename >::end(), llvm::ArrayRef< T >::end(), llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::erase(), F, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::find(), llvm::ArrayRef< T >::front(), llvm::IntegerType::get(), llvm::APInt::getBitsSetFrom(), llvm::DemandedBits::getDemandedBits(), llvm::IRBuilderBase::getInt1Ty(), llvm::TargetTransformInfo::getNumberOfParts(), getNumElements(), getOpcode(), getRdxKind(), llvm::Type::getScalarType(), llvm::Value::getType(), getWidenedType(), Idx, if(), llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::insert(), llvm::isGather(), llvm::RecurrenceDescriptor::isIntMinMaxRecurrenceKind(), llvm::isKnownNonNegative(), llvm::MaskedValueIsZero(), llvm::none_of(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::size(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::try_emplace(), llvm::slpvectorizer::BoUpSLP::EdgeInfo::UserTE, and UsesLimit.

◆ deleteTree()

void llvm::slpvectorizer::BoUpSLP::deleteTree ( )
inline

◆ doesRootHaveInTreeUses()

bool llvm::slpvectorizer::BoUpSLP::doesRootHaveInTreeUses ( ) const
inline

Returns whether the root node has in-tree uses.

Definition at line 1391 of file SLPVectorizer.cpp.

References llvm::SmallVectorBase< Size_T >::empty(), and llvm::SmallVectorTemplateCommon< T, typename >::front().

◆ eraseInstruction()

void llvm::slpvectorizer::BoUpSLP::eraseInstruction ( Instruction I)
inline

Removes an instruction from its block and eventually deletes it.

It's like Instruction::eraseFromParent() except that the actual deletion is delayed until BoUpSLP is destructed.

Definition at line 2798 of file SLPVectorizer.cpp.

References I.

Referenced by optimizeGatherSequence(), and vectorizeTree().

◆ findBestRootPair()

std::optional< int > llvm::slpvectorizer::BoUpSLP::findBestRootPair ( ArrayRef< std::pair< Value *, Value * > >  Candidates,
int  Limit = LookAheadHeuristics::ScoreFail 
) const
inline

Evaluate each pair in Candidates and return index into Candidates for a pair which have highest score deemed to have best chance to form root of profitable tree to vectorize.

Return std::nullopt if no candidate scored above the LookAheadHeuristics::ScoreFail.

Parameters
LimitLower limit of the cost, considered to be good enough score.

Definition at line 2773 of file SLPVectorizer.cpp.

References llvm::slpvectorizer::BoUpSLP::LookAheadHeuristics::getScoreAtLevelRec(), I, and RootLookAheadMaxDepth.

Referenced by transformNodes().

◆ findPartiallyOrderedLoads()

std::optional< BoUpSLP::OrdersType > BoUpSLP::findPartiallyOrderedLoads ( const TreeEntry &  TE)

Sort loads into increasing pointers offsets to allow greater clustering.

Definition at line 5399 of file SLPVectorizer.cpp.

References assert(), clusterSortPtrAccesses(), llvm::SetVector< T, Vector, Set, N >::contains(), DL, llvm::SmallVectorTemplateBase< T, bool >::push_back(), and llvm::SmallVectorImpl< T >::reserve().

Referenced by getReorderingData().

◆ findReusedOrderedScalars()

std::optional< BoUpSLP::OrdersType > BoUpSLP::findReusedOrderedScalars ( const TreeEntry &  TE)

◆ getCanonicalGraphSize()

unsigned llvm::slpvectorizer::BoUpSLP::getCanonicalGraphSize ( ) const
inline

Returns the base graph size, before any transformations.

Definition at line 1485 of file SLPVectorizer.cpp.

Referenced by isTreeNotExtendable(), and transformNodes().

◆ getMaximumVF()

unsigned llvm::slpvectorizer::BoUpSLP::getMaximumVF ( unsigned  ElemWidth,
unsigned  Opcode 
) const
inline

Definition at line 1563 of file SLPVectorizer.cpp.

References llvm::TargetTransformInfo::getMaximumVF(), and MaxVFOption.

◆ getMaxVecRegSize()

unsigned llvm::slpvectorizer::BoUpSLP::getMaxVecRegSize ( ) const
inline

Definition at line 1550 of file SLPVectorizer.cpp.

◆ getMinVecRegSize()

unsigned llvm::slpvectorizer::BoUpSLP::getMinVecRegSize ( ) const
inline

Definition at line 1555 of file SLPVectorizer.cpp.

Referenced by getMinVF().

◆ getMinVF()

unsigned llvm::slpvectorizer::BoUpSLP::getMinVF ( unsigned  Sz) const
inline

Definition at line 1559 of file SLPVectorizer.cpp.

References getMinVecRegSize().

Referenced by canVectorizeLoads(), and transformNodes().

◆ getORE()

OptimizationRemarkEmitter * llvm::slpvectorizer::BoUpSLP::getORE ( )
inline

Definition at line 1632 of file SLPVectorizer.cpp.

◆ getReductionType()

FixedVectorType * llvm::slpvectorizer::BoUpSLP::getReductionType ( ) const
inline

Returns reduction type after minbitdth analysis.

Definition at line 1428 of file SLPVectorizer.cpp.

References DL, llvm::SmallVectorTemplateCommon< T, typename >::front(), llvm::IntegerType::get(), and getWidenedType().

◆ getReorderingData()

std::optional< BoUpSLP::OrdersType > BoUpSLP::getReorderingData ( const TreeEntry &  TE,
bool  TopToBottom 
)

Gets reordering data for the given tree entry.

If the entry is vectorized

  • just return ReorderIndices, otherwise check if the scalars can be reordered and return the most optimal order.
    Returns
    std::nullopt if ordering is not important, empty order, if identity order is important, or the actual order.
    Parameters
    TopToBottomIf true, include the order of vectorized stores and insertelement nodes, otherwise skip them.

Definition at line 5475 of file SLPVectorizer.cpp.

References addMask(), llvm::all_of(), allConstant(), allSameType(), llvm::any_of(), assert(), llvm::SmallVectorTemplateCommon< T, typename >::begin(), canVectorizeLoads(), llvm::Instruction::comesBefore(), llvm::count_if(), llvm::Data, llvm::divideCeil(), E, llvm::SmallVectorBase< Size_T >::empty(), llvm::SmallVectorTemplateCommon< T, typename >::end(), llvm::enumerate(), llvm::find(), llvm::find_if(), findPartiallyOrderedLoads(), findReusedOrderedScalars(), fixupOrderingIndices(), llvm::PoisonValue::get(), getElementIndex(), getExtractIndex(), llvm::DominatorTreeBase< NodeT, IsPostDom >::getNode(), llvm::TargetTransformInfo::getNumberOfParts(), llvm::Value::getNumUses(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), getParent(), getShuffleCost(), llvm::TargetTransformInfo::getVectorInstrCost(), getWidenedType(), I, Idx, II, llvm::inversePermutation(), isIdentityOrder(), llvm::ShuffleVectorInst::isOneUseSingleSourceMask(), isReverseOrder(), isSplat(), llvm::PoisonMaskElem, reorderOrder(), llvm::SmallBitVector::set(), llvm::SmallVectorBase< Size_T >::size(), llvm::TargetTransformInfo::SK_PermuteSingleSrc, llvm::ArrayRef< T >::slice(), llvm::stable_sort(), StridedVectorize, llvm::TargetTransformInfo::TCK_RecipThroughput, llvm::SmallBitVector::test(), llvm::transform(), llvm::Value::user_begin(), Vectorize, VectorizeNonPowerOf2, and llvm::zip().

Referenced by reorderBottomToTop(), and reorderTopToBottom().

◆ getRootNodeScalars()

ArrayRef< Value * > llvm::slpvectorizer::BoUpSLP::getRootNodeScalars ( ) const
inline

Return the scalars of the root node.

Definition at line 1397 of file SLPVectorizer.cpp.

References assert(), llvm::SmallVectorBase< Size_T >::empty(), and llvm::SmallVectorTemplateCommon< T, typename >::front().

◆ getRootNodeTypeWithNoCast()

std::optional< std::pair< Type *, bool > > llvm::slpvectorizer::BoUpSLP::getRootNodeTypeWithNoCast ( ) const
inline

◆ getSpillCost()

InstructionCost BoUpSLP::getSpillCost ( ) const

◆ getTreeCost()

InstructionCost BoUpSLP::getTreeCost ( ArrayRef< Value * >  VectorizedVals = {})
Returns
the vectorization cost of the subtree that starts at VL. A negative number means that this is profitable.

Definition at line 12377 of file SLPVectorizer.cpp.

References llvm::all_of(), areTwoInsertFromSameBuildVector(), assert(), llvm::SmallVectorTemplateCommon< T, typename >::begin(), llvm::CallingConv::C, CostKind, llvm::SmallPtrSetImpl< PtrType >::count(), llvm::count_if(), llvm::Data, llvm::dbgs(), DL, llvm::SmallVectorImpl< T >::emplace_back(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::SmallVectorTemplateCommon< T, typename >::end(), llvm::enumerate(), F, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::find(), llvm::find_if(), llvm::for_each(), llvm::IntegerType::get(), llvm::TargetTransformInfo::getCastInstrCost(), getElementIndex(), llvm::TargetTransformInfo::getExtractWithExtendCost(), llvm::TargetTransformInfo::getInstructionCost(), llvm::User::getOperand(), llvm::BasicBlock::getParent(), llvm::InsertElementInst::getType(), llvm::TargetTransformInfo::getVectorInstrCost(), getWidenedType(), llvm::APInt::getZero(), llvm::has_single_bit(), I, II, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::insert(), llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::insert(), llvm::SmallPtrSetImpl< PtrType >::insert(), isFirstInsertElement(), llvm::isKnownNonNegative(), llvm::DominatorTree::isReachableFromEntry(), LLVM_DEBUG, llvm::TargetTransformInfo::None, llvm::none_of(), P, llvm::PoisonMaskElem, llvm::SmallVectorTemplateBase< T, bool >::push_back(), shortBundleName(), llvm::SmallVectorBase< Size_T >::size(), llvm::TargetTransformInfo::TCC_Basic, llvm::TargetTransformInfo::TCC_Free, llvm::TargetTransformInfo::TCK_RecipThroughput, and UsesLimit.

◆ getTreeSize()

unsigned llvm::slpvectorizer::BoUpSLP::getTreeSize ( ) const
inline

Definition at line 1482 of file SLPVectorizer.cpp.

References llvm::SmallVectorBase< Size_T >::size().

Referenced by isTreeNotExtendable(), and transformNodes().

◆ getVectorElementSize()

unsigned BoUpSLP::getVectorElementSize ( Value V)
Returns
The vector element size in bits to use when vectorizing the expression tree ending at V. If V is a store, the size is the width of the stored value. Otherwise, the size is the width of the largest loaded value reaching V. This method is used by the vectorizer to calculate vectorization factors.

Definition at line 17599 of file SLPVectorizer.cpp.

References DL, llvm::SmallVectorImpl< T >::emplace_back(), llvm::SmallVectorBase< Size_T >::empty(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::find(), llvm::IRBuilderBase::getInt1Ty(), getVectorElementSize(), I, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::isa(), llvm::SmallVectorImpl< T >::pop_back_val(), and RecursionMaxDepth.

Referenced by getVectorElementSize(), and transformNodes().

◆ isAnalyzedReductionRoot()

bool llvm::slpvectorizer::BoUpSLP::isAnalyzedReductionRoot ( Instruction I) const
inline

Checks if the instruction was already analyzed for being possible reduction root.

Definition at line 2889 of file SLPVectorizer.cpp.

References I.

◆ isAnyGathered()

bool llvm::slpvectorizer::BoUpSLP::isAnyGathered ( const SmallDenseSet< Value * > &  Vals) const
inline

Checks if the given value is gathered in one of the nodes.

Definition at line 2914 of file SLPVectorizer.cpp.

References llvm::any_of(), and llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::contains().

◆ isDeleted()

bool llvm::slpvectorizer::BoUpSLP::isDeleted ( Instruction I) const
inline

Checks if the instruction is marked for deletion.

Definition at line 2793 of file SLPVectorizer.cpp.

References I.

Referenced by buildExternalUses(), optimizeGatherSequence(), and transformNodes().

◆ isGathered()

bool llvm::slpvectorizer::BoUpSLP::isGathered ( const Value V) const
inline

Checks if the given value is gathered in one of the nodes.

Definition at line 2918 of file SLPVectorizer.cpp.

References llvm::SmallPtrSetImpl< PtrType >::contains().

◆ isIdentityOrder()

bool llvm::slpvectorizer::BoUpSLP::isIdentityOrder ( ArrayRef< unsigned Order) const
inline

Does this non-empty order represent an identity order? Identity should be represented as an empty order, so this is used to decide if we can canonicalize a computed order.

Undef elements (represented as size) are ignored.

Definition at line 1494 of file SLPVectorizer.cpp.

References llvm::all_of(), assert(), llvm::ArrayRef< T >::empty(), llvm::enumerate(), P, and llvm::ArrayRef< T >::size().

Referenced by getReorderingData(), reorderBottomToTop(), and reorderTopToBottom().

◆ isLoadCombineCandidate()

bool BoUpSLP::isLoadCombineCandidate ( ArrayRef< Value * >  Stores) const

Assume that a vector of stores of bitwise-or/shifted/zexted loaded values can be load combined in the backend.

Load combining may not be allowed in the IR optimizer, so we do not want to alter the pattern. For example, partially transforming a scalar bswap() pattern into vector code is effectively impossible for the backend to undo. TODO: If load combining is allowed in the IR optimizer, this analysis may not be necessary.

Definition at line 11972 of file SLPVectorizer.cpp.

References isLoadCombineCandidateImpl(), llvm::PatternMatch::m_Store(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::ArrayRef< T >::size(), and X.

◆ isLoadCombineReductionCandidate()

bool BoUpSLP::isLoadCombineReductionCandidate ( RecurKind  RdxKind) const

Assume that a legal-sized 'or'-reduction of shifted/zexted loaded values can be load combined in the backend.

Load combining may not be allowed in the IR optimizer, so we do not want to alter the pattern. For example, partially transforming a scalar bswap() pattern into vector code is effectively impossible for the backend to undo. TODO: If load combining is allowed in the IR optimizer, this analysis may not be necessary.

Definition at line 11962 of file SLPVectorizer.cpp.

References isLoadCombineCandidateImpl(), and llvm::Or.

◆ isNotScheduled()

bool llvm::slpvectorizer::BoUpSLP::isNotScheduled ( const Value V) const
inline

Checks if the specified value was not schedule.

Definition at line 2922 of file SLPVectorizer.cpp.

References llvm::SmallPtrSetImpl< PtrType >::contains().

◆ isSignedMinBitwidthRootNode()

bool llvm::slpvectorizer::BoUpSLP::isSignedMinBitwidthRootNode ( ) const
inline

Checks if the root graph node can be emitted with narrower bitwidth at codegen and returns it signedness, if so.

Definition at line 1423 of file SLPVectorizer.cpp.

References llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::at(), and llvm::SmallVectorTemplateCommon< T, typename >::front().

◆ isTreeNotExtendable()

bool BoUpSLP::isTreeNotExtendable ( ) const

Checks if the graph and all its subgraphs cannot be better vectorized.

It may happen, if all gather nodes are loads and they cannot be "clusterized". In this case even subgraphs cannot be vectorized more effectively than the base graph.

Definition at line 12067 of file SLPVectorizer.cpp.

References allConstant(), allSameBlock(), llvm::count_if(), getCanonicalGraphSize(), getTreeSize(), Idx, and isSplat().

◆ isTreeTinyAndNotFullyVectorizable()

bool BoUpSLP::isTreeTinyAndNotFullyVectorizable ( bool  ForReduction = false) const

◆ isVectorized()

bool llvm::slpvectorizer::BoUpSLP::isVectorized ( Value V) const
inline

Check if the value is vectorized in the tree.

Definition at line 2927 of file SLPVectorizer.cpp.

Referenced by transformNodes().

◆ optimizeGatherSequence()

void BoUpSLP::optimizeGatherSequence ( )

◆ registerNonVectorizableLoads()

template<typename T >
void llvm::slpvectorizer::BoUpSLP::registerNonVectorizableLoads ( ArrayRef< T * >  VL)
inline

Registers non-vectorizable sequence of loads.

Definition at line 1622 of file SLPVectorizer.cpp.

References llvm::hash_value(), and llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::insert().

Referenced by transformNodes().

◆ removeInstructionsAndOperands()

template<typename T >
void llvm::slpvectorizer::BoUpSLP::removeInstructionsAndOperands ( ArrayRef< T * >  DeadVals)
inline

◆ reorderBottomToTop()

void BoUpSLP::reorderBottomToTop ( bool  IgnoreReorder = false)

◆ reorderTopToBottom()

void BoUpSLP::reorderTopToBottom ( )

Reorders the current graph to the most profitable order starting from the root node to the leaf nodes.

The best order is chosen only from the nodes of the same size (vectorization factor). Smaller nodes are considered parts of subgraph with smaller VF and they are reordered independently. We can make it because we still need to extend smaller nodes to the wider VF and we can merge reordering shuffles with the widening shuffles.

Definition at line 5860 of file SLPVectorizer.cpp.

References addMask(), llvm::all_of(), assert(), llvm::SmallVectorTemplateCommon< T, typename >::begin(), Cleanup, combineOrders(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::count(), E, llvm::ArrayRef< T >::empty(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::empty(), llvm::SmallVectorBase< Size_T >::empty(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::erase(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::find(), fixupOrderingIndices(), llvm::for_each(), getAltInstrMask(), getReorderingData(), getWidenedType(), I, Idx, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::insert(), llvm::inversePermutation(), llvm::isa(), isIdentityOrder(), llvm::make_scope_exit(), llvm::none_of(), llvm::PoisonMaskElem, RecursionMaxDepth, reorderOrder(), llvm::reorderScalars(), llvm::ArrayRef< T >::size(), SLPReVec, llvm::transform(), and llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::try_emplace().

◆ transformNodes()

void BoUpSLP::transformNodes ( )

Transforms graph nodes to target specific representations, if profitable.

Definition at line 9674 of file SLPVectorizer.cpp.

References llvm::all_of(), allConstant(), allSameBlock(), analyzedReductionVals(), llvm::any_of(), areKnownNonVectorizableLoads(), assert(), llvm::ArrayRef< T >::back(), llvm::canConvertToMinOrMaxIntrinsic(), canVectorizeLoads(), CostKind, llvm::count(), llvm::count_if(), llvm::SmallVectorImpl< T >::emplace_back(), llvm::MapVector< KeyT, ValueT, MapType, VectorType >::empty(), llvm::SmallVectorBase< Size_T >::empty(), End, llvm::find_if(), findBestRootPair(), llvm::ArrayRef< T >::front(), Gather, gatherPossiblyVectorizableLoads(), getCanonicalGraphSize(), llvm::VectorType::getElementCount(), llvm::details::FixedOrScalableQuantity< LeafTy, ValueTy >::getFixedValue(), getFloorFullVectorNumberOfElements(), llvm::TargetTransformInfo::getInstructionCost(), llvm::TargetTransformInfo::getMemoryOpCost(), getMinVF(), llvm::TargetTransformInfo::getNumberOfParts(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::Type::getPointerAddressSpace(), llvm::LoadInst::getPointerOperand(), getSameOpcode(), getShuffleCost(), llvm::TargetTransformInfo::getStridedMemoryOpCost(), getTreeSize(), llvm::Value::getType(), llvm::getUnderlyingObject(), getVectorElementSize(), getWidenedType(), llvm::has_single_bit(), Idx, llvm::inversePermutation(), isDeleted(), llvm::ShuffleVectorInst::isInterleaveMask(), llvm::TargetTransformInfo::isLegalInterleavedAccessType(), llvm::TargetTransformInfo::isLegalStridedLoadStore(), isReverseOrder(), llvm::LoadInst::isSimple(), isSplat(), isVectorized(), llvm::Intrinsic::not_intrinsic, P, RecursionMaxDepth, registerNonVectorizableLoads(), llvm::reorderScalars(), llvm::reverse(), ScatterVectorize, llvm::slpvectorizer::BoUpSLP::LookAheadHeuristics::ScoreSplatLoads, llvm::ArrayRef< T >::size(), llvm::TargetTransformInfo::SK_Reverse, llvm::ArrayRef< T >::slice(), llvm::TargetTransformInfo::TCC_Expensive, and llvm::TargetTransformInfo::TCK_RecipThroughput.

◆ vectorizeTree() [1/2]

Value * BoUpSLP::vectorizeTree ( )

Vectorize the tree that starts with the elements in VL.

Returns the vectorized root.

Definition at line 16236 of file SLPVectorizer.cpp.

References vectorizeTree().

Referenced by vectorizeTree().

◆ vectorizeTree() [2/2]

Value * BoUpSLP::vectorizeTree ( const ExtraValueToDebugLocsMap ExternallyUsedValues,
Instruction ReductionRoot = nullptr 
)

Vectorize the tree but with the list of externally used values ExternallyUsedValues.

Values in this MapVector can be replaced but the generated extractvalue instructions.

Definition at line 16242 of file SLPVectorizer.cpp.

References llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::add(), llvm::any_of(), areTwoInsertFromSameBuildVector(), assert(), llvm::SmallVectorTemplateCommon< T, typename >::back(), llvm::ArrayRef< T >::back(), llvm::SmallVectorTemplateCommon< T, typename >::begin(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::clear(), llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::contains(), llvm::SmallPtrSetImpl< PtrType >::contains(), llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::count(), llvm::IRBuilderBase::CreateExtractElement(), llvm::IRBuilderBase::CreateExtractVector(), llvm::IRBuilderBase::CreateIntCast(), llvm::Data, llvm::dbgs(), DL, llvm::SmallVectorImpl< T >::emplace_back(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::SmallVectorTemplateCommon< T, typename >::end(), llvm::BasicBlock::end(), eraseInstruction(), F, llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::finalize(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::find(), llvm::find_if(), llvm::SmallVectorTemplateCommon< T, typename >::front(), llvm::ArrayRef< T >::front(), llvm::get(), llvm::FixedVectorType::get(), llvm::PoisonValue::get(), llvm::SetVector< T, Vector, Set, N >::getArrayRef(), getElementIndex(), llvm::IRBuilderBase::GetInsertBlock(), llvm::IRBuilderBase::GetInsertPoint(), llvm::IRBuilderBase::getInt32(), llvm::IRBuilderBase::getInt64(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::FixedVectorType::getNumElements(), llvm::User::getOperand(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::Type::getScalarType(), llvm::InsertElementInst::getType(), llvm::Value::getType(), getWidenedType(), I, Idx, II, llvm::SetVector< T, Vector, Set, N >::insert(), llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::insert(), llvm::is_contained(), isFirstInsertElement(), llvm::Type::isIntOrIntVectorTy(), llvm::isKnownNonNegative(), IV, LLVM_DEBUG, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::lookup(), llvm::mayHaveNonDefUseDependency(), llvm::Instruction::moveAfter(), PHI, llvm::PoisonMaskElem, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::SmallVectorTemplateCommon< T, typename >::rbegin(), llvm::SmallVectorTemplateCommon< T, typename >::rend(), llvm::Value::replaceAllUsesWith(), llvm::User::replaceUsesOfWith(), llvm::reverse(), llvm::IRBuilderBase::SetCurrentDebugLocation(), llvm::IRBuilderBase::SetInsertPoint(), llvm::SmallVectorBase< Size_T >::size(), SLPReVec, llvm::sort(), llvm::Value::takeName(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::try_emplace(), llvm::User::User(), UsesLimit, llvm::Vector, and vectorizeTree().

Friends And Related Function Documentation

◆ DOTGraphTraits< BoUpSLP * >

friend struct DOTGraphTraits< BoUpSLP * >
friend

Definition at line 4028 of file SLPVectorizer.cpp.

◆ GraphTraits< BoUpSLP * >

friend struct GraphTraits< BoUpSLP * >
friend

Definition at line 4028 of file SLPVectorizer.cpp.

◆ operator<<

raw_ostream & operator<< ( raw_ostream os,
const BoUpSLP::ScheduleData &  SD 
)
friend

Definition at line 4028 of file SLPVectorizer.cpp.


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