23 unsigned MaxVecRegBits,
36 assert(!
isUsed(StartIdx) &&
"Expected unused at StartIdx");
40 if (
isUsed(StartIdx + NumElements))
44 if (BitCount + InstBits > MaxVecRegBits)
49 NumElementsPowerOfTwo = NumElements;
50 BitCountPowerOfTwo = BitCount;
54 NumElements = NumElementsPowerOfTwo;
55 BitCount = BitCountPowerOfTwo;
59 if (NumElements > 1) {
61 "Must be a power of two");
67template <
typename LoadOrStoreT>
68SeedContainer::KeyT SeedContainer::getKey(LoadOrStoreT *LSI,
69 bool AllowDiffTypes)
const {
71 "Expected Load or Store!");
80 Ty = VTy->getElementType();
86template SeedContainer::KeyT
87SeedContainer::getKey<LoadInst>(
LoadInst *LSI,
bool AllowDiffTypes)
const;
88template SeedContainer::KeyT
89SeedContainer::getKey<StoreInst>(
StoreInst *LSI,
bool AllowDiffTypes)
const;
93 auto It = SeedLookupMap.find(
I);
94 if (It == SeedLookupMap.end())
102 const VectorizeOptions &Opts =
104 BundleSizeLimit = Opts.sbvec_seed_bundle_size_limit;
107template <
typename LoadOrStoreT>
110 auto &
BundleVec = Bundles[getKey(LSI, AllowDiffTypes)];
119 SeedLookupMap[LSI] =
BundleVec.back().get();
130 for (
const auto &Pair : Bundles) {
131 auto [
I, Ty,
Opc] = Pair.first;
132 const auto &SeedsVec = Pair.second;
136 OS <<
"[Inst=" << *
I <<
" Ty=" << Ty <<
" " << RefType <<
"]\n";
137 for (
const auto &SeedPtr : SeedsVec) {
149 if (!LSI->isSimple())
153 if (Ty->isX86_FP80Ty() || Ty->isPPC_FP128Ty())
167 bool CollectStores,
bool CollectLoads,
169 : StoreSeeds(SE), LoadSeeds(SE), Ctx(BB->
getContext()) {
171 if (!CollectStores && !CollectLoads)
174 EraseCallbackID = Ctx.registerEraseInstrCallback([
this](
Instruction *
I) {
176 StoreSeeds.erase(
SI);
182 const VectorizeOptions &Opts =
184 for (
auto &
I : *BB) {
187 StoreSeeds.insert(
SI, AllowDiffTypes);
190 LoadSeeds.insert(LI, AllowDiffTypes);
192 if (totalNumSeedGroups() > Opts.sbvec_seed_groups_limit)
198 Ctx.unregisterEraseInstrCallback(EraseCallbackID);
203 OS <<
"=== StoreSeeds ===\n";
204 StoreSeeds.print(OS);
205 OS <<
"=== LoadSeeds ===\n";
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
#define LLVM_EXPORT_TEMPLATE
Represent a constant reference to an array (0 or more elements consecutively in memory),...
The main scalar evolution driver.
This class implements an extremely fast bulk output stream that can only output to a stream.
This is a simple bottom-up (top-down) vectorizer Region pass.
A sandboxir::User with operands, opcode and linked with previous/next instructions in an instruction ...
Specialization of SeedBundle for memory access instructions.
A set of candidate Instructions for vectorizing together.
bool isUsed(unsigned Element) const
\Returns whether or not Element has been used.
SmallVector< Instruction * > Seeds
LLVM_ABI ArrayRef< Instruction * > getSlice(unsigned StartIdx, unsigned MaxVecRegBits, bool ForcePowOf2)
\Returns a slice of seed elements, starting at the element StartIdx, with a total size <= MaxVecRegBi...
void setUsed(Instruction *I)
Marks instruction I "used" within the bundle.
LLVM_ABI ~SeedCollector()
LLVM_ABI SeedCollector(BasicBlock *BB, ScalarEvolution &SE, bool CollectStores, bool CollectLoads, bool AllowDiffTypes=false)
void print(raw_ostream &OS) const
LLVM_DUMP_METHOD void dump() const
void print(raw_ostream &OS) const
void insert(LoadOrStoreT *LSI, bool AllowDiffTypes)
LLVM_ABI SeedContainer(ScalarEvolution &SE)
LLVM_DUMP_METHOD void dump() const
LLVM_ABI bool erase(Instruction *I)
Just like llvm::Type these are immutable, unique, never get freed and can only be created via static ...
static unsigned getNumBits(Type *Ty, const DataLayout &DL)
\Returns the number of bits of Ty.
static Type * getExpectedType(const Value *V)
\Returns the expected type of Value V.
static Value * getMemInstructionBase(const LoadOrStoreT *LSI)
\Returns the base Value for load or store instruction LSI.
A SandboxIR Value has users. This is the base class.
static LLVM_ABI bool isValidElementType(Type *ElemTy)
Context & getContext() const
template bool isValidMemSeed< StoreInst >(StoreInst *LSI)
static bool isValidMemSeed(LoadOrStoreT *LSI)
BasicBlock(llvm::BasicBlock *BB, Context &SBCtx)
template bool isValidMemSeed< LoadInst >(LoadInst *LSI)
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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...
DWARFExpression::Operation Op