[llvm] [SandboxVectorizer] Add container class to track and manage SeedBundles (PR #112048)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 14 11:45:09 PDT 2024
================
@@ -61,4 +65,73 @@ MutableArrayRef<Instruction *> SeedBundle::getSlice(unsigned StartIdx,
return {};
}
+template <typename LoadOrStoreT>
+SeedContainer::KeyT SeedContainer::getKey(LoadOrStoreT *LSI) const {
+ assert((isa<LoadInst>(LSI) || isa<StoreInst>(LSI)) &&
+ "Expected Load or Store!");
+ Value *Ptr = Utils::getMemInstructionBase(LSI);
+ Instruction::Opcode Op = LSI->getOpcode();
+ Type *Ty = Utils::getExpectedType(LSI);
+ if (auto *VTy = dyn_cast<VectorType>(Ty))
+ Ty = VTy->getElementType();
+ return {Ptr, Ty, Op};
+}
+
+// Explicit instantiations
+template SeedContainer::KeyT
+SeedContainer::getKey<LoadInst>(LoadInst *LSI) const;
+template SeedContainer::KeyT
+SeedContainer::getKey<StoreInst>(StoreInst *LSI) const;
+
+bool SeedContainer::erase(Instruction *I) {
+ assert((isa<LoadInst>(I) || isa<StoreInst>(I)) && "Expected Load or Store!");
+ auto It = SeedLookupMap.find(I);
+ if (It == SeedLookupMap.end())
+ return false;
+ SeedBundle *Bndl = It->second;
+ Bndl->setUsed(I);
+ return true;
+}
+
+template <typename LoadOrStoreT> void SeedContainer::insert(LoadOrStoreT *LSI) {
+ // Find the bundle containing seeds for this symbol and type-of-access.
+ auto &BundleVec = Bundles[getKey(LSI)];
+ // Fill this vector of bundles front to back so that only the last bundle in
+ // the vector may have available space. This avoids iteration to find one with
+ // space.
+ if (BundleVec.empty() || BundleVec.back()->size() == SeedBundleSizeLimit)
+ BundleVec.emplace_back(std::make_unique<MemSeedBundle<LoadOrStoreT>>(LSI));
+ else
+ BundleVec.back()->insert(LSI, SE);
+
+ SeedLookupMap[LSI] = BundleVec.back().get();
+ this->dump();
+}
+
+// Explicit instantiations
+template void SeedContainer::insert<LoadInst>(LoadInst *);
+template void SeedContainer::insert<StoreInst>(StoreInst *);
+
+#ifndef NDEBUG
+void SeedContainer::dump(raw_ostream &OS) const {
+ for (const auto &Pair : Bundles) {
+ auto [I, Ty, Opc] = Pair.first;
+ const auto &SeedsVec = Pair.second;
+ std::string RefType = dyn_cast<LoadInst>(I) ? "Load"
+ : dyn_cast<StoreInst>(I) ? "Store"
+ : "Other";
+ OS << "[Inst=" << *I << " Ty=" << Ty << " " << RefType << "]\n";
+ for (const auto &SeedPtr : SeedsVec) {
+ SeedPtr->dump(OS);
+ OS << "\n";
+ }
+ }
+}
+
+void SeedContainer::dump() const {
+ dump(dbgs());
+ dbgs() << "\n";
+}
+#endif // NDEBUG
----------------
vporpo wrote:
I would prefer a `print(OS)` and a `dump() { print(dbgs()); }` because then you can easily add an `operator<<` that can also call `print(OS)`.
https://github.com/llvm/llvm-project/pull/112048
More information about the llvm-commits
mailing list