Skip to content

Commit cfde685

Browse files
committed
[VPlan] Sink VPB2IRBB lookups to VPRecipeBuilder (NFC).
This allows migrating some more code to be based on VPBBs in VPRecipeBuilder, in preparation for #128420.
1 parent 94c0a0b commit cfde685

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9378,7 +9378,7 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range,
93789378
return !CM.requiresScalarEpilogue(VF.isVector());
93799379
},
93809380
Range);
9381-
DenseMap<VPBlockBase *, BasicBlock *> VPB2IRBB;
9381+
DenseMap<const VPBlockBase *, BasicBlock *> VPB2IRBB;
93829382
auto Plan = VPlanTransforms::buildPlainCFG(OrigLoop, *LI, VPB2IRBB);
93839383
VPlanTransforms::prepareForVectorization(
93849384
*Plan, Legal->getWidestInductionType(), PSE, RequiresScalarEpilogueCheck,
@@ -9412,7 +9412,7 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range,
94129412
}
94139413

94149414
VPRecipeBuilder RecipeBuilder(*Plan, OrigLoop, TLI, &TTI, Legal, CM, PSE,
9415-
Builder, LVer);
9415+
Builder, VPB2IRBB, LVer);
94169416

94179417
// ---------------------------------------------------------------------------
94189418
// Pre-construction: record ingredients whose recipes we'll need to further
@@ -9476,7 +9476,7 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range,
94769476
// FIXME: At the moment, masks need to be placed at the beginning of the
94779477
// block, as blends introduced for phi nodes need to use it. The created
94789478
// blends should be sunk after the mask recipes.
9479-
RecipeBuilder.createBlockInMask(VPB2IRBB.lookup(VPBB));
9479+
RecipeBuilder.createBlockInMask(VPBB);
94809480
}
94819481

94829482
// Convert input VPInstructions to widened recipes.
@@ -9681,7 +9681,7 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlan(VFRange &Range) {
96819681
assert(!OrigLoop->isInnermost());
96829682
assert(EnableVPlanNativePath && "VPlan-native path is not enabled.");
96839683

9684-
DenseMap<VPBlockBase *, BasicBlock *> VPB2IRBB;
9684+
DenseMap<const VPBlockBase *, BasicBlock *> VPB2IRBB;
96859685
auto Plan = VPlanTransforms::buildPlainCFG(OrigLoop, *LI, VPB2IRBB);
96869686
VPlanTransforms::prepareForVectorization(
96879687
*Plan, Legal->getWidestInductionType(), PSE, true, false, OrigLoop,
@@ -9702,7 +9702,7 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlan(VFRange &Range) {
97029702
// Collect mapping of IR header phis to header phi recipes, to be used in
97039703
// addScalarResumePhis.
97049704
VPRecipeBuilder RecipeBuilder(*Plan, OrigLoop, TLI, &TTI, Legal, CM, PSE,
9705-
Builder, nullptr /*LVer*/);
9705+
Builder, VPB2IRBB, nullptr /*LVer*/);
97069706
for (auto &R : Plan->getVectorLoopRegion()->getEntryBasicBlock()->phis()) {
97079707
if (isa<VPCanonicalIVPHIRecipe>(&R))
97089708
continue;

llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ class VPRecipeBuilder {
9090
/// A mapping of partial reduction exit instructions to their scaling factor.
9191
DenseMap<const Instruction *, unsigned> ScaledReductionMap;
9292

93+
/// A mapping from VP blocks to IR blocks, used temporarily while migrating
94+
/// away from IR references.
95+
const DenseMap<const VPBlockBase *, BasicBlock *> &VPB2IRBB;
96+
9397
/// Loop versioning instance for getting noalias metadata guaranteed by
9498
/// runtime checks.
9599
LoopVersioning *LVer;
@@ -160,9 +164,10 @@ class VPRecipeBuilder {
160164
LoopVectorizationLegality *Legal,
161165
LoopVectorizationCostModel &CM,
162166
PredicatedScalarEvolution &PSE, VPBuilder &Builder,
167+
const DenseMap<const VPBlockBase *, BasicBlock *> &VPB2IRBB,
163168
LoopVersioning *LVer)
164169
: Plan(Plan), OrigLoop(OrigLoop), TLI(TLI), TTI(TTI), Legal(Legal),
165-
CM(CM), PSE(PSE), Builder(Builder), LVer(LVer) {}
170+
CM(CM), PSE(PSE), Builder(Builder), VPB2IRBB(VPB2IRBB), LVer(LVer) {}
166171

167172
std::optional<unsigned> getScalingForReduction(const Instruction *ExitInst) {
168173
auto It = ScaledReductionMap.find(ExitInst);
@@ -199,8 +204,16 @@ class VPRecipeBuilder {
199204
/// A helper function that computes the predicate of the block BB, assuming
200205
/// that the header block of the loop is set to True or the loop mask when
201206
/// tail folding.
207+
void createBlockInMask(const VPBasicBlock *VPBB) {
208+
return createBlockInMask(VPB2IRBB.lookup(VPBB));
209+
}
202210
void createBlockInMask(BasicBlock *BB);
203211

212+
/// Returns the *entry* mask for the block \p VPBB.
213+
VPValue *getBlockInMask(const VPBasicBlock *VPBB) const {
214+
return getBlockInMask(VPB2IRBB.lookup(VPBB));
215+
}
216+
204217
/// Returns the *entry* mask for the block \p BB.
205218
VPValue *getBlockInMask(BasicBlock *BB) const;
206219

@@ -213,6 +226,9 @@ class VPRecipeBuilder {
213226

214227
/// A helper that returns the previously computed predicate of the edge
215228
/// between SRC and DST.
229+
VPValue *getEdgeMask(const VPBasicBlock *Src, const VPBasicBlock *Dst) const {
230+
return getEdgeMask(VPB2IRBB.lookup(Src), VPB2IRBB.lookup(Dst));
231+
}
216232
VPValue *getEdgeMask(BasicBlock *Src, BasicBlock *Dst) const;
217233

218234
/// Return the recipe created for given ingredient.

llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class PlainCFGBuilder {
6767

6868
/// Build plain CFG for TheLoop and connects it to Plan's entry.
6969
std::unique_ptr<VPlan>
70-
buildPlainCFG(DenseMap<VPBlockBase *, BasicBlock *> &VPB2IRBB);
70+
buildPlainCFG(DenseMap<const VPBlockBase *, BasicBlock *> &VPB2IRBB);
7171
};
7272
} // anonymous namespace
7373

@@ -243,7 +243,7 @@ void PlainCFGBuilder::createVPInstructionsForVPBB(VPBasicBlock *VPBB,
243243

244244
// Main interface to build the plain CFG.
245245
std::unique_ptr<VPlan> PlainCFGBuilder::buildPlainCFG(
246-
DenseMap<VPBlockBase *, BasicBlock *> &VPB2IRBB) {
246+
DenseMap<const VPBlockBase *, BasicBlock *> &VPB2IRBB) {
247247
VPIRBasicBlock *Entry = cast<VPIRBasicBlock>(Plan->getEntry());
248248
BB2VPBB[Entry->getIRBasicBlock()] = Entry;
249249
for (VPIRBasicBlock *ExitVPBB : Plan->getExitBlocks())
@@ -343,7 +343,7 @@ std::unique_ptr<VPlan> PlainCFGBuilder::buildPlainCFG(
343343

344344
std::unique_ptr<VPlan> VPlanTransforms::buildPlainCFG(
345345
Loop *TheLoop, LoopInfo &LI,
346-
DenseMap<VPBlockBase *, BasicBlock *> &VPB2IRBB) {
346+
DenseMap<const VPBlockBase *, BasicBlock *> &VPB2IRBB) {
347347
PlainCFGBuilder Builder(TheLoop, &LI);
348348
return Builder.buildPlainCFG(VPB2IRBB);
349349
}

llvm/lib/Transforms/Vectorize/VPlanTransforms.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct VPlanTransforms {
5555

5656
static std::unique_ptr<VPlan>
5757
buildPlainCFG(Loop *TheLoop, LoopInfo &LI,
58-
DenseMap<VPBlockBase *, BasicBlock *> &VPB2IRBB);
58+
DenseMap<const VPBlockBase *, BasicBlock *> &VPB2IRBB);
5959

6060
/// Prepare the plan for vectorization. It will introduce a dedicated
6161
/// VPBasicBlock for the vector pre-header as well as a VPBasicBlock as exit

llvm/unittests/Transforms/Vectorize/VPlanTestBase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class VPlanTestIRBase : public testing::Test {
7070

7171
Loop *L = LI->getLoopFor(LoopHeader);
7272
PredicatedScalarEvolution PSE(*SE, *L);
73-
DenseMap<VPBlockBase *, BasicBlock *> VPB2IRBB;
73+
DenseMap<const VPBlockBase *, BasicBlock *> VPB2IRBB;
7474
auto Plan = VPlanTransforms::buildPlainCFG(L, *LI, VPB2IRBB);
7575
VPlanTransforms::prepareForVectorization(*Plan, IntegerType::get(*Ctx, 64),
7676
PSE, true, false, L, {});

0 commit comments

Comments
 (0)