Skip to content

Commit e6ace74

Browse files
vporporlavaee
authored andcommitted
[SandboxVec][SeedCollector][NFC] Replace cl::opt flags with constructor args (llvm#143206)
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
1 parent 2f0c5d3 commit e6ace74

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed

llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/SeedCollector.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ class SeedCollector {
307307
}
308308

309309
public:
310-
LLVM_ABI SeedCollector(BasicBlock *BB, ScalarEvolution &SE);
310+
LLVM_ABI SeedCollector(BasicBlock *BB, ScalarEvolution &SE,
311+
bool CollectStores, bool CollectLoads);
311312
LLVM_ABI ~SeedCollector();
312313

313314
iterator_range<SeedContainer::iterator> getStoreSeeds() {

llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/SeedCollection.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ static cl::opt<bool>
2424
AllowNonPow2("sbvec-allow-non-pow2", cl::init(false), cl::Hidden,
2525
cl::desc("Allow non-power-of-2 vectorization."));
2626

27+
#define LoadSeedsDef "loads"
28+
#define StoreSeedsDef "stores"
29+
cl::opt<std::string> CollectSeeds(
30+
"sbvec-collect-seeds", cl::init(StoreSeedsDef), cl::Hidden,
31+
cl::desc("Collect these seeds. Use empty for none or a comma-separated "
32+
"list of '" StoreSeedsDef "' and '" LoadSeedsDef "'."));
33+
2734
namespace sandboxir {
2835
SeedCollection::SeedCollection(StringRef Pipeline)
2936
: FunctionPass("seed-collection"),
@@ -38,10 +45,12 @@ bool SeedCollection::runOnFunction(Function &F, const Analyses &A) {
3845
: A.getTTI()
3946
.getRegisterBitWidth(TargetTransformInfo::RGK_FixedWidthVector)
4047
.getFixedValue();
48+
bool CollectStores = CollectSeeds.find(StoreSeedsDef) != std::string::npos;
49+
bool CollectLoads = CollectSeeds.find(LoadSeedsDef) != std::string::npos;
4150

4251
// TODO: Start from innermost BBs first
4352
for (auto &BB : F) {
44-
SeedCollector SC(&BB, A.getScalarEvolution());
53+
SeedCollector SC(&BB, A.getScalarEvolution(), CollectStores, CollectLoads);
4554
for (SeedBundle &Seeds : SC.getStoreSeeds()) {
4655
unsigned ElmBits =
4756
Utils::getNumBits(VecUtils::getElementType(Utils::getExpectedType(

llvm/lib/Transforms/Vectorize/SandboxVectorizer/SeedCollector.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,7 @@ namespace llvm::sandboxir {
2121
static cl::opt<unsigned> SeedBundleSizeLimit(
2222
"sbvec-seed-bundle-size-limit", cl::init(32), cl::Hidden,
2323
cl::desc("Limit the size of the seed bundle to cap compilation time."));
24-
#define LoadSeedsDef "loads"
25-
#define StoreSeedsDef "stores"
26-
static cl::opt<std::string> CollectSeeds(
27-
"sbvec-collect-seeds", cl::init(LoadSeedsDef "," StoreSeedsDef), cl::Hidden,
28-
cl::desc("Collect these seeds. Use empty for none or a comma-separated "
29-
"list of '" LoadSeedsDef "' and '" StoreSeedsDef "'."));
24+
3025
static cl::opt<unsigned> SeedGroupsLimit(
3126
"sbvec-seed-groups-limit", cl::init(256), cl::Hidden,
3227
cl::desc("Limit the number of collected seeds groups in a BB to "
@@ -162,11 +157,10 @@ template <typename LoadOrStoreT> static bool isValidMemSeed(LoadOrStoreT *LSI) {
162157
template bool isValidMemSeed<LoadInst>(LoadInst *LSI);
163158
template bool isValidMemSeed<StoreInst>(StoreInst *LSI);
164159

165-
SeedCollector::SeedCollector(BasicBlock *BB, ScalarEvolution &SE)
160+
SeedCollector::SeedCollector(BasicBlock *BB, ScalarEvolution &SE,
161+
bool CollectStores, bool CollectLoads)
166162
: StoreSeeds(SE), LoadSeeds(SE), Ctx(BB->getContext()) {
167163

168-
bool CollectStores = CollectSeeds.find(StoreSeedsDef) != std::string::npos;
169-
bool CollectLoads = CollectSeeds.find(LoadSeedsDef) != std::string::npos;
170164
if (!CollectStores && !CollectLoads)
171165
return;
172166

llvm/unittests/Transforms/Vectorize/SandboxVectorizer/SeedCollectorTest.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,8 @@ define void @foo(ptr noalias %ptr, float %val) {
315315
sandboxir::Context Ctx(C);
316316
auto &F = *Ctx.createFunction(&LLVMF);
317317
auto BB = F.begin();
318-
sandboxir::SeedCollector SC(&*BB, SE);
318+
sandboxir::SeedCollector SC(&*BB, SE, /*CollectStores=*/true,
319+
/*CollectLoads=*/false);
319320

320321
// Find the stores
321322
auto It = std::next(BB->begin(), 4);
@@ -359,7 +360,8 @@ define void @foo(ptr noalias %ptr, float %val) {
359360
sandboxir::Context Ctx(C);
360361
auto &F = *Ctx.createFunction(&LLVMF);
361362
auto BB = F.begin();
362-
sandboxir::SeedCollector SC(&*BB, SE);
363+
sandboxir::SeedCollector SC(&*BB, SE, /*CollectStores=*/true,
364+
/*CollectLoads=*/false);
363365

364366
// Find the stores
365367
auto It = std::next(BB->begin(), 4);
@@ -419,7 +421,8 @@ define void @foo(ptr noalias %ptr, <2 x float> %val0, i64 %val1) {
419421
sandboxir::Context Ctx(C);
420422
auto &F = *Ctx.createFunction(&LLVMF);
421423
auto BB = F.begin();
422-
sandboxir::SeedCollector SC(&*BB, SE);
424+
sandboxir::SeedCollector SC(&*BB, SE, /*CollectStores=*/true,
425+
/*CollectLoads=*/false);
423426

424427
// Find the stores
425428
auto It = std::next(BB->begin(), 3);
@@ -460,7 +463,8 @@ define void @foo(ptr noalias %ptr, float %v, <2 x float> %val) {
460463
sandboxir::Context Ctx(C);
461464
auto &F = *Ctx.createFunction(&LLVMF);
462465
auto BB = F.begin();
463-
sandboxir::SeedCollector SC(&*BB, SE);
466+
sandboxir::SeedCollector SC(&*BB, SE, /*CollectStores=*/true,
467+
/*CollectLoads=*/false);
464468

465469
// Find the stores
466470
auto It = std::next(BB->begin(), 3);
@@ -503,7 +507,8 @@ define void @foo(ptr noalias %ptr, <2 x float> %val0) {
503507
sandboxir::Context Ctx(C);
504508
auto &F = *Ctx.createFunction(&LLVMF);
505509
auto BB = F.begin();
506-
sandboxir::SeedCollector SC(&*BB, SE);
510+
sandboxir::SeedCollector SC(&*BB, SE, /*CollectStores=*/false,
511+
/*CollectLoads=*/true);
507512

508513
// Find the loads
509514
auto It = std::next(BB->begin(), 2);

0 commit comments

Comments
 (0)