From ec54fef601205145c384dd72e8eb144dfbcd92ca Mon Sep 17 00:00:00 2001 From: Vasileios Porpodas Date: Tue, 11 Mar 2025 10:56:55 -0700 Subject: [PATCH] [SandboxVec][SeedCollector][NFC] Replace cl::opt flags with constructor args The `SeedCollector` class gets two new arguments: `CollectStores` and `CollectLoads`. These replace the `sbvec-collect-seeds` cl::opt flag. This is done to help with reusing the SeedCollector class in a future pass. The cl::opt flag is moved to the seed collection pass: Passes/SeedCollection.cpp --- .../Vectorize/SandboxVectorizer/SeedCollector.h | 3 ++- .../SandboxVectorizer/Passes/SeedCollection.cpp | 11 ++++++++++- .../Vectorize/SandboxVectorizer/SeedCollector.cpp | 12 +++--------- .../SandboxVectorizer/SeedCollectorTest.cpp | 15 ++++++++++----- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/SeedCollector.h b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/SeedCollector.h index 6d2144b14bb00..ec70350691abe 100644 --- a/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/SeedCollector.h +++ b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/SeedCollector.h @@ -307,7 +307,8 @@ class SeedCollector { } public: - LLVM_ABI SeedCollector(BasicBlock *BB, ScalarEvolution &SE); + LLVM_ABI SeedCollector(BasicBlock *BB, ScalarEvolution &SE, + bool CollectStores, bool CollectLoads); LLVM_ABI ~SeedCollector(); iterator_range getStoreSeeds() { diff --git a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/SeedCollection.cpp b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/SeedCollection.cpp index f3b62e36e5115..ddb4a1e154a18 100644 --- a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/SeedCollection.cpp +++ b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/SeedCollection.cpp @@ -24,6 +24,13 @@ static cl::opt AllowNonPow2("sbvec-allow-non-pow2", cl::init(false), cl::Hidden, cl::desc("Allow non-power-of-2 vectorization.")); +#define LoadSeedsDef "loads" +#define StoreSeedsDef "stores" +cl::opt CollectSeeds( + "sbvec-collect-seeds", cl::init(StoreSeedsDef), cl::Hidden, + cl::desc("Collect these seeds. Use empty for none or a comma-separated " + "list of '" StoreSeedsDef "' and '" LoadSeedsDef "'.")); + namespace sandboxir { SeedCollection::SeedCollection(StringRef Pipeline) : FunctionPass("seed-collection"), @@ -38,10 +45,12 @@ bool SeedCollection::runOnFunction(Function &F, const Analyses &A) { : A.getTTI() .getRegisterBitWidth(TargetTransformInfo::RGK_FixedWidthVector) .getFixedValue(); + bool CollectStores = CollectSeeds.find(StoreSeedsDef) != std::string::npos; + bool CollectLoads = CollectSeeds.find(LoadSeedsDef) != std::string::npos; // TODO: Start from innermost BBs first for (auto &BB : F) { - SeedCollector SC(&BB, A.getScalarEvolution()); + SeedCollector SC(&BB, A.getScalarEvolution(), CollectStores, CollectLoads); for (SeedBundle &Seeds : SC.getStoreSeeds()) { unsigned ElmBits = Utils::getNumBits(VecUtils::getElementType(Utils::getExpectedType( diff --git a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SeedCollector.cpp b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SeedCollector.cpp index 008976ac9749d..1934326866cdf 100644 --- a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SeedCollector.cpp +++ b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SeedCollector.cpp @@ -21,12 +21,7 @@ namespace llvm::sandboxir { static cl::opt SeedBundleSizeLimit( "sbvec-seed-bundle-size-limit", cl::init(32), cl::Hidden, cl::desc("Limit the size of the seed bundle to cap compilation time.")); -#define LoadSeedsDef "loads" -#define StoreSeedsDef "stores" -static cl::opt CollectSeeds( - "sbvec-collect-seeds", cl::init(LoadSeedsDef "," StoreSeedsDef), cl::Hidden, - cl::desc("Collect these seeds. Use empty for none or a comma-separated " - "list of '" LoadSeedsDef "' and '" StoreSeedsDef "'.")); + static cl::opt SeedGroupsLimit( "sbvec-seed-groups-limit", cl::init(256), cl::Hidden, cl::desc("Limit the number of collected seeds groups in a BB to " @@ -162,11 +157,10 @@ template static bool isValidMemSeed(LoadOrStoreT *LSI) { template bool isValidMemSeed(LoadInst *LSI); template bool isValidMemSeed(StoreInst *LSI); -SeedCollector::SeedCollector(BasicBlock *BB, ScalarEvolution &SE) +SeedCollector::SeedCollector(BasicBlock *BB, ScalarEvolution &SE, + bool CollectStores, bool CollectLoads) : StoreSeeds(SE), LoadSeeds(SE), Ctx(BB->getContext()) { - bool CollectStores = CollectSeeds.find(StoreSeedsDef) != std::string::npos; - bool CollectLoads = CollectSeeds.find(LoadSeedsDef) != std::string::npos; if (!CollectStores && !CollectLoads) return; diff --git a/llvm/unittests/Transforms/Vectorize/SandboxVectorizer/SeedCollectorTest.cpp b/llvm/unittests/Transforms/Vectorize/SandboxVectorizer/SeedCollectorTest.cpp index 3c66f985fe6e1..7f9a59bd428a0 100644 --- a/llvm/unittests/Transforms/Vectorize/SandboxVectorizer/SeedCollectorTest.cpp +++ b/llvm/unittests/Transforms/Vectorize/SandboxVectorizer/SeedCollectorTest.cpp @@ -315,7 +315,8 @@ define void @foo(ptr noalias %ptr, float %val) { sandboxir::Context Ctx(C); auto &F = *Ctx.createFunction(&LLVMF); auto BB = F.begin(); - sandboxir::SeedCollector SC(&*BB, SE); + sandboxir::SeedCollector SC(&*BB, SE, /*CollectStores=*/true, + /*CollectLoads=*/false); // Find the stores auto It = std::next(BB->begin(), 4); @@ -359,7 +360,8 @@ define void @foo(ptr noalias %ptr, float %val) { sandboxir::Context Ctx(C); auto &F = *Ctx.createFunction(&LLVMF); auto BB = F.begin(); - sandboxir::SeedCollector SC(&*BB, SE); + sandboxir::SeedCollector SC(&*BB, SE, /*CollectStores=*/true, + /*CollectLoads=*/false); // Find the stores auto It = std::next(BB->begin(), 4); @@ -419,7 +421,8 @@ define void @foo(ptr noalias %ptr, <2 x float> %val0, i64 %val1) { sandboxir::Context Ctx(C); auto &F = *Ctx.createFunction(&LLVMF); auto BB = F.begin(); - sandboxir::SeedCollector SC(&*BB, SE); + sandboxir::SeedCollector SC(&*BB, SE, /*CollectStores=*/true, + /*CollectLoads=*/false); // Find the stores auto It = std::next(BB->begin(), 3); @@ -460,7 +463,8 @@ define void @foo(ptr noalias %ptr, float %v, <2 x float> %val) { sandboxir::Context Ctx(C); auto &F = *Ctx.createFunction(&LLVMF); auto BB = F.begin(); - sandboxir::SeedCollector SC(&*BB, SE); + sandboxir::SeedCollector SC(&*BB, SE, /*CollectStores=*/true, + /*CollectLoads=*/false); // Find the stores auto It = std::next(BB->begin(), 3); @@ -503,7 +507,8 @@ define void @foo(ptr noalias %ptr, <2 x float> %val0) { sandboxir::Context Ctx(C); auto &F = *Ctx.createFunction(&LLVMF); auto BB = F.begin(); - sandboxir::SeedCollector SC(&*BB, SE); + sandboxir::SeedCollector SC(&*BB, SE, /*CollectStores=*/false, + /*CollectLoads=*/true); // Find the loads auto It = std::next(BB->begin(), 2);