LLVM 24.0.0git
llvm::sandboxir::VecUtils Class Reference

#include "llvm/Transforms/Vectorize/SandboxVectorizer/VecUtils.h"

Classes

class  BndlTypeClassifier
 Classifies whether all bundle elements are integers, halves, floats, doubles, or pointers. More...
class  DeadInstructionMorgue
 Utility class to collect and erase dead instructions. More...
class  LaneValueEnumerator
 Iterate over all lanes and Value pairs. More...
struct  PackPattern
 Helper struct for matchPack(). More...

Static Public Member Functions

static int getNumElements (Type *Ty)
 \Returns the number of elements in Ty.
static Type * getElementType (Type *Ty)
 Returns Ty if scalar or its element type if vector.
template<typename LoadOrStoreT>
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.
template<typename LoadOrStoreT, typename ValT>
static bool areConsecutive (ArrayRef< ValT * > Bndl, ScalarEvolution &SE, const DataLayout &DL)
static unsigned getNumLanes (Type *Ty)
 \Returns the number of vector lanes of Ty or 1 if not a vector.
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 Type * getWideType (Type *ElemTy, unsigned NumElts)
 \Returns <NumElts x ElemTy>.
template<typename T>
static Type * getCombinedVectorTypeFor (BndlRef< T * > Bndl, const DataLayout &DL)
 \Returns the combined vector type for Bndl, even when the element types differ.
static Type * getCombinedVectorTypeFor (std::initializer_list< Value * > Bndl, const DataLayout &DL)
static Instruction * getLowest (ArrayRef< Instruction * > Instrs)
 \Returns the instruction in Instrs that is lowest in the BB.
static Instruction * getHighest (ArrayRef< Instruction * > Instrs)
 \Returns the instruction in Instrs that is highest in the BB.
static Instruction * getLowest (ArrayRef< Value * > Vals, BasicBlock *BB)
 \Returns the lowest instruction in Vals, or nullptr if no instructions are found.
static Instruction * getLastPHIOrSelf (Instruction *I)
 If I is not a PHI it returns it.
static BasicBlock::iterator getInsertPointAfterInstrs (ArrayRef< Value * > Vals, BasicBlock *BB)
 \Returns the BB iterator after the lowest instruction in Vals (skipping instructions not in BB), or the top of BB if no instruction found in Vals.
static Type * tryGetCommonScalarType (ArrayRef< Value * > Bndl)
 If all values in Bndl are of the same scalar type then return it, otherwise return nullptr.
static Type * getCommonScalarType (ArrayRef< Value * > Bndl)
 Similar to tryGetCommonScalarType() but will assert that there is a common type.
static LLVM_ABI unsigned getFloorPowerOf2 (unsigned Num)
 \Returns the first integer power of 2 that is <= Num.
static LLVM_ABI SmallVector< BundleTy > getNextUserBundles (ArrayRef< Value * > Bndl, const InstrMaps &IMaps, SmallPtrSet< Instruction *, 4 > &Claimed)
 For each user of lane 0 in Bndl, try to form a bundle of matching users for all lanes.
static std::optional< PackPattern > matchPack (Instruction *I)
 If I is the last instruction of a pack pattern (i.e., an InsertElement into a vector), then this function returns the instructions in the pack and the operands in the pack, else returns nullopt.
static Value * unpack (Value *FromVec, Type *ExtrTy, unsigned Lane, BasicBlock::iterator WhereIt)
 Emits the necessary instruction sequence to extract element of type ExtrTy at Lane from FromVec.
template<typename ValueContainerT>
static auto enumerateLanes (const ValueContainerT &Range)
 Helper for creating LaneValueEnumerator ranges.
template<typename AlignRangeT, typename TypeRangeT>
static Align getVecAlignment (AlignRangeT AlignRange, TypeRangeT TypeRange)
 Given the alignments of the instructions before vectorization, this returns the alignment of the vectorized instruction.
template<typename InstrRangeT>
static Align getVecAlignment (InstrRangeT InstrRange)
 Helper for getVecAlignment(AlignRange, TypeRange).
static LLVM_DUMP_METHOD void dump (ArrayRef< Value * > Bndl)
 Helper dump function for debugging.
static LLVM_DUMP_METHOD void dump (ArrayRef< Instruction * > Bndl)

Detailed Description

Definition at line 84 of file VecUtils.h.

Member Function Documentation

◆ areConsecutive() [1/2]

template<typename LoadOrStoreT, typename ValT>
bool llvm::sandboxir::VecUtils::areConsecutive ( ArrayRef< ValT * > Bndl,
ScalarEvolution & SE,
const DataLayout & DL )
inlinestatic

Definition at line 114 of file VecUtils.h.

References areConsecutive(), assert(), llvm::cast(), DL, llvm::drop_begin(), and llvm::isa().

◆ areConsecutive() [2/2]

template<typename LoadOrStoreT>
bool llvm::sandboxir::VecUtils::areConsecutive ( LoadOrStoreT * I1,
LoadOrStoreT * I2,
ScalarEvolution & SE,
const DataLayout & DL )
inlinestatic

\Returns true if I1 and I2 are load/stores accessing consecutive memory addresses.

Definition at line 101 of file VecUtils.h.

References DL, llvm::sandboxir::Utils::getNumBits(), and llvm::sandboxir::Utils::getPointerDiffInBytes().

Referenced by areConsecutive().

◆ dump() [1/2]

void llvm::sandboxir::VecUtils::dump ( ArrayRef< Instruction * > Bndl)
static

Definition at line 168 of file VecUtils.cpp.

References llvm::sandboxir::dumpImpl().

◆ dump() [2/2]

void llvm::sandboxir::VecUtils::dump ( ArrayRef< Value * > Bndl)
static

Helper dump function for debugging.

Definition at line 167 of file VecUtils.cpp.

References llvm::sandboxir::dumpImpl().

◆ enumerateLanes()

template<typename ValueContainerT>
auto llvm::sandboxir::VecUtils::enumerateLanes ( const ValueContainerT & Range)
inlinestatic

Helper for creating LaneValueEnumerator ranges.

Can be used in for loops like: for (auto [Lane, V] : enumerateLanes(Range))

Definition at line 536 of file VecUtils.h.

References llvm::End, llvm::make_range(), and Range.

◆ getCombinedVectorTypeFor() [1/2]

template<typename T>
Type * llvm::sandboxir::VecUtils::getCombinedVectorTypeFor ( BndlRef< T * > Bndl,
const DataLayout & DL )
inlinestatic

◆ getCombinedVectorTypeFor() [2/2]

Type * llvm::sandboxir::VecUtils::getCombinedVectorTypeFor ( std::initializer_list< Value * > Bndl,
const DataLayout & DL )
inlinestatic

Definition at line 234 of file VecUtils.h.

References DL, and getCombinedVectorTypeFor().

◆ getCommonScalarType()

Type * llvm::sandboxir::VecUtils::getCommonScalarType ( ArrayRef< Value * > Bndl)
inlinestatic

Similar to tryGetCommonScalarType() but will assert that there is a common type.

So this is faster in release builds as it won't iterate through the values.

Definition at line 331 of file VecUtils.h.

References assert(), getElementType(), llvm::sandboxir::Utils::getExpectedType(), and tryGetCommonScalarType().

◆ getElementType()

Type * llvm::sandboxir::VecUtils::getElementType ( Type * Ty)
inlinestatic

◆ getFloorPowerOf2()

unsigned llvm::sandboxir::VecUtils::getFloorPowerOf2 ( unsigned Num)
static

\Returns the first integer power of 2 that is <= Num.

Definition at line 94 of file VecUtils.cpp.

Referenced by llvm::sandboxir::SeedCollection::runOnFunction().

◆ getHighest()

Instruction * llvm::sandboxir::VecUtils::getHighest ( ArrayRef< Instruction * > Instrs)
inlinestatic

\Returns the instruction in Instrs that is highest in the BB.

Expects that all instructions are in the same BB.

Definition at line 250 of file VecUtils.h.

References llvm::drop_begin(), llvm::ArrayRef< T >::front(), and I.

Referenced by llvm::sandboxir::Scheduler::trySchedule().

◆ getInsertPointAfterInstrs()

BasicBlock::iterator llvm::sandboxir::VecUtils::getInsertPointAfterInstrs ( ArrayRef< Value * > Vals,
BasicBlock * BB )
inlinestatic

\Returns the BB iterator after the lowest instruction in Vals (skipping instructions not in BB), or the top of BB if no instruction found in Vals.

Definition at line 302 of file VecUtils.h.

References llvm::sandboxir::BasicBlock(), llvm::BasicBlock::begin(), llvm::BasicBlock::empty(), llvm::sandboxir::Instruction::getIterator(), getLastPHIOrSelf(), and getLowest().

◆ getLastPHIOrSelf()

Instruction * llvm::sandboxir::VecUtils::getLastPHIOrSelf ( Instruction * I)
inlinestatic

If I is not a PHI it returns it.

Else it walks down the instruction chain looking for the last PHI and returns it. \Returns nullptr if I is nullptr.

Definition at line 290 of file VecUtils.h.

References I, and llvm::isa().

Referenced by getInsertPointAfterInstrs().

◆ getLowest() [1/2]

Instruction * llvm::sandboxir::VecUtils::getLowest ( ArrayRef< Instruction * > Instrs)
inlinestatic

\Returns the instruction in Instrs that is lowest in the BB.

Expects that all instructions are in the same BB.

Definition at line 240 of file VecUtils.h.

References llvm::sandboxir::Instruction::comesBefore(), llvm::drop_begin(), llvm::ArrayRef< T >::front(), and I.

Referenced by getInsertPointAfterInstrs(), and llvm::sandboxir::Scheduler::trySchedule().

◆ getLowest() [2/2]

Instruction * llvm::sandboxir::VecUtils::getLowest ( ArrayRef< Value * > Vals,
BasicBlock * BB )
inlinestatic

\Returns the lowest instruction in Vals, or nullptr if no instructions are found.

Skips instructions not in BB.

Definition at line 260 of file VecUtils.h.

References llvm::sandboxir::BasicBlock(), llvm::cast(), llvm::sandboxir::Instruction::comesBefore(), llvm::dyn_cast(), llvm::ArrayRef< T >::end(), llvm::find_if(), I, llvm::isa(), and llvm::make_range().

◆ getNextUserBundles()

SmallVector< BundleTy > llvm::sandboxir::VecUtils::getNextUserBundles ( ArrayRef< Value * > Bndl,
const InstrMaps & IMaps,
SmallPtrSet< Instruction *, 4 > & Claimed )
static

For each user of lane 0 in Bndl, try to form a bundle of matching users for all lanes.

Returns all complete user bundles found. Claimed contains instructions that have already been claimed by a bundle.

Definition at line 64 of file VecUtils.cpp.

References llvm::SmallPtrSetImpl< PtrType >::contains(), llvm::dyn_cast(), llvm::SmallVectorImpl< T >::emplace_back(), llvm::ArrayRef< T >::empty(), llvm::sandboxir::getMatchingBundle(), llvm::detail::DenseSetImpl< ValueT, MapTy >::insert(), llvm::sandboxir::InstrMaps::isVectorized(), and llvm::detail::DenseSetImpl< ValueT, MapTy >::size().

◆ getNumElements()

int llvm::sandboxir::VecUtils::getNumElements ( Type * Ty)
inlinestatic

\Returns the number of elements in Ty.

That is the number of lanes if a fixed vector or 1 if scalar. ScalableVectors have unknown size and therefore are unsupported.

Definition at line 89 of file VecUtils.h.

References assert(), llvm::cast(), and llvm::isa().

◆ getNumLanes() [1/3]

unsigned llvm::sandboxir::VecUtils::getNumLanes ( ArrayRef< Value * > Bndl)
inlinestatic

\Returns the total number of lanes across all values in Bndl.

Definition at line 148 of file VecUtils.h.

References getNumLanes().

◆ getNumLanes() [2/3]

unsigned llvm::sandboxir::VecUtils::getNumLanes ( Type * Ty)
inlinestatic

\Returns the number of vector lanes of Ty or 1 if not a vector.

NOTE: It asserts that Ty is a fixed vector type.

Definition at line 134 of file VecUtils.h.

References assert(), llvm::dyn_cast(), and llvm::isa().

Referenced by getCombinedVectorTypeFor(), getNumLanes(), getNumLanes(), matchPack(), and llvm::sandboxir::InstrMaps::registerVector().

◆ getNumLanes() [3/3]

unsigned llvm::sandboxir::VecUtils::getNumLanes ( Value * V)
inlinestatic

\Returns the expected vector lanes of V or 1 if not a vector.

NOTE: It asserts that V is a fixed vector.

Definition at line 143 of file VecUtils.h.

References llvm::sandboxir::Utils::getExpectedType(), and getNumLanes().

◆ getVecAlignment() [1/2]

template<typename AlignRangeT, typename TypeRangeT>
Align llvm::sandboxir::VecUtils::getVecAlignment ( AlignRangeT AlignRange,
TypeRangeT TypeRange )
inlinestatic

Given the alignments of the instructions before vectorization, this returns the alignment of the vectorized instruction.

Definition at line 547 of file VecUtils.h.

References assert().

Referenced by getVecAlignment().

◆ getVecAlignment() [2/2]

template<typename InstrRangeT>
Align llvm::sandboxir::VecUtils::getVecAlignment ( InstrRangeT InstrRange)
inlinestatic

Helper for getVecAlignment(AlignRange, TypeRange).

Definition at line 560 of file VecUtils.h.

References llvm::sandboxir::Utils::getExpectedType(), llvm::sandboxir::getLoadStoreAlignment(), getVecAlignment(), I, and llvm::map_range().

◆ getWideType()

Type * llvm::sandboxir::VecUtils::getWideType ( Type * ElemTy,
unsigned NumElts )
inlinestatic

\Returns <NumElts x ElemTy>.

It works for both scalar and vector ElemTy.

Definition at line 157 of file VecUtils.h.

References llvm::cast(), and llvm::sandboxir::FixedVectorType::get().

◆ matchPack()

std::optional< PackPattern > llvm::sandboxir::VecUtils::matchPack ( Instruction * I)
inlinestatic

If I is the last instruction of a pack pattern (i.e., an InsertElement into a vector), then this function returns the instructions in the pack and the operands in the pack, else returns nullopt.

Here is an example of a matched pattern: PackA0 = insertelement <2 x i8> poison, i8 v0, i64 0 PackA1 = insertelement <2 x i8> PackA0, i8 v1, i64 1 TODO: this currently detects only simple canonicalized patterns.

Definition at line 374 of file VecUtils.h.

References assert(), llvm::dyn_cast(), getNumLanes(), llvm::sandboxir::User::getOperand(), llvm::sandboxir::Instruction::getParent(), I, llvm::isa(), llvm::reverse(), and llvm::seq().

Referenced by llvm::sandboxir::PackReuse::runOnRegion().

◆ tryGetCommonScalarType()

Type * llvm::sandboxir::VecUtils::tryGetCommonScalarType ( ArrayRef< Value * > Bndl)
inlinestatic

If all values in Bndl are of the same scalar type then return it, otherwise return nullptr.

Definition at line 315 of file VecUtils.h.

References llvm::drop_begin(), getElementType(), and llvm::sandboxir::Utils::getExpectedType().

Referenced by getCommonScalarType().

◆ unpack()

Value * llvm::sandboxir::VecUtils::unpack ( Value * FromVec,
Type * ExtrTy,
unsigned Lane,
BasicBlock::iterator WhereIt )
inlinestatic

Emits the necessary instruction sequence to extract element of type ExtrTy at Lane from FromVec.

Emits instructions before WhereIt. Returns the extracted value. Note: This handles both vectors and scalars. In the vector case it extracts an N-wide element (with N dictated by ExtrTy).

Definition at line 418 of file VecUtils.h.

References assert(), llvm::cast(), llvm::sandboxir::ExtractElementInst::create(), llvm::sandboxir::ShuffleVectorInst::create(), E(), llvm::sandboxir::PoisonValue::get(), llvm::sandboxir::Value::getContext(), llvm::sandboxir::Type::getInt32Ty(), llvm::sandboxir::ConstantInt::getSigned(), llvm::sandboxir::Value::getType(), llvm::isa(), and llvm::sandboxir::Type::isVectorTy().


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