Skip to content

Commit 99ad49e

Browse files
committed
!fixup address latest comments, thanks
1 parent 0be6939 commit 99ad49e

File tree

5 files changed

+29
-31
lines changed

5 files changed

+29
-31
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9324,6 +9324,8 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
93249324
auto Plan = std::make_unique<VPlan>(OrigLoop);
93259325
// Build hierarchical CFG.
93269326
VPlanHCFGBuilder HCFGBuilder(OrigLoop, LI, *Plan);
9327+
// TODO: Convert to VPlan-transform and consoliate all transforms for VPlan
9328+
// creation.
93279329
HCFGBuilder.buildHierarchicalCFG();
93289330

93299331
VPlanTransforms::introduceTopLevelVectorLoopRegion(

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3602,11 +3602,17 @@ class VPlan {
36023602
/// the original trip count have been replaced.
36033603
void resetTripCount(VPValue *NewTripCount) {
36043604
assert(TripCount && NewTripCount && TripCount->getNumUsers() == 0 &&
3605-
"TripCount always must be set");
3605+
"TripCount must be set when resetting");
36063606
TripCount = NewTripCount;
36073607
}
36083608

3609-
void setTripCount(VPValue *NewTripCount) { TripCount = NewTripCount; }
3609+
// Set the trip count assuming it is currently null; if it is not - use
3610+
// resetTripCount().
3611+
void setTripCount(VPValue *NewTripCount) {
3612+
assert(!TripCount && NewTripCount && "TripCount should not be set yet.");
3613+
3614+
TripCount = NewTripCount;
3615+
}
36103616

36113617
/// The backedge taken count of the original loop.
36123618
VPValue *getOrCreateBackedgeTakenCount() {

llvm/lib/Transforms/Vectorize/VPlanHCFGBuilder.cpp

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ VPBasicBlock *PlainCFGBuilder::getOrCreateVPBB(BasicBlock *BB) {
178178
VPBasicBlock *VPBB = Plan.createVPBasicBlock(Name);
179179
BB2VPBB[BB] = VPBB;
180180

181-
// Get or create a region for the loop containing BB.
181+
// Get or create a region for the loop containing BB, except for the top
182+
// region of TheLoop which is created later.
182183
Loop *LoopOfBB = LI->getLoopFor(BB);
183184
if (!LoopOfBB || LoopOfBB == TheLoop || !doesContainLoop(LoopOfBB, TheLoop))
184185
return VPBB;
@@ -194,12 +195,8 @@ VPBasicBlock *PlainCFGBuilder::getOrCreateVPBB(BasicBlock *BB) {
194195
assert(!RegionOfVPBB &&
195196
"First visit of a header basic block expects to register its region.");
196197
// Handle a header - take care of its Region.
197-
if (LoopOfBB == TheLoop) {
198-
RegionOfVPBB = Plan.getVectorLoopRegion();
199-
} else {
200-
RegionOfVPBB = Plan.createVPRegionBlock(Name.str(), false /*isReplicator*/);
201-
RegionOfVPBB->setParent(Loop2Region[LoopOfBB->getParentLoop()]);
202-
}
198+
RegionOfVPBB = Plan.createVPRegionBlock(Name.str(), false /*isReplicator*/);
199+
RegionOfVPBB->setParent(Loop2Region[LoopOfBB->getParentLoop()]);
203200
RegionOfVPBB->setEntry(VPBB);
204201
Loop2Region[LoopOfBB] = RegionOfVPBB;
205202
return VPBB;
@@ -383,11 +380,10 @@ void PlainCFGBuilder::buildPlainCFG(
383380
// Set VPBB predecessors in the same order as they are in the incoming BB.
384381
if (!isHeaderBB(BB, LoopForBB)) {
385382
setVPBBPredsFromBB(VPBB, BB);
386-
} else {
387-
// BB is a loop header, set the predecessor for the region, except for the
388-
// top region, whose predecessor was set when creating VPlan's skeleton.
389-
if (LoopForBB != TheLoop)
390-
setRegionPredsFromBB(Region, BB);
383+
} else if (Region) {
384+
// BB is a loop header and there's a corresponding region , set the
385+
// predecessor for it.
386+
setRegionPredsFromBB(Region, BB);
391387
}
392388

393389
// Create VPInstructions for BB.
@@ -427,22 +423,15 @@ void PlainCFGBuilder::buildPlainCFG(
427423
VPBasicBlock *Successor0 = getOrCreateVPBB(IRSucc0);
428424
VPBasicBlock *Successor1 = getOrCreateVPBB(IRSucc1);
429425
if (BB == LoopForBB->getLoopLatch()) {
430-
// For a latch we need to set the successor of the region rather
431-
// than that
432-
// of VPBB and it should be set to the exit, i.e., non-header
433-
// successor,
434-
// except for the top region, whose successor was set when creating
435-
// VPlan's skeleton.
426+
// For a latch we need to set the successor of the region rather than that
427+
// of VPBB and it should be set to the exit, i.e., non-header successor,
428+
// except for the top region, which is handled elsewhere.
436429
assert(LoopForBB != TheLoop &&
437430
"Latch of the top region should have been handled earlier");
438431
Region->setOneSuccessor(isHeaderVPBB(Successor0) ? Successor1
439432
: Successor0);
440433
Region->setExiting(VPBB);
441434
continue;
442-
443-
VPBasicBlock *HeaderVPBB = getOrCreateVPBB(LoopForBB->getHeader());
444-
VPBlockUtils::connectBlocks(VPBB, HeaderVPBB);
445-
continue;
446435
}
447436

448437
// Don't connect any blocks outside the current loop except the latch for

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ using namespace llvm;
3535
void VPlanTransforms::introduceTopLevelVectorLoopRegion(
3636
VPlan &Plan, Type *InductionTy, PredicatedScalarEvolution &PSE,
3737
bool RequiresScalarEpilogueCheck, bool TailFolded, Loop *TheLoop) {
38+
// TODO: Generalize to introduce all loop regions.
3839
auto *HeaderVPBB = cast<VPBasicBlock>(Plan.getEntry()->getSingleSuccessor());
3940
VPBlockUtils::disconnectBlocks(Plan.getEntry(), HeaderVPBB);
4041

@@ -43,6 +44,7 @@ void VPlanTransforms::introduceTopLevelVectorLoopRegion(
4344
VPBlockUtils::disconnectBlocks(OriginalLatch, HeaderVPBB);
4445
VPBasicBlock *VecPreheader = Plan.createVPBasicBlock("vector.ph");
4546
VPBlockUtils::connectBlocks(Plan.getEntry(), VecPreheader);
47+
assert(OriginalLatch->getNumSuccessors() == 0 && "expected no predecessors");
4648

4749
// Create SCEV and VPValue for the trip count.
4850
// We use the symbolic max backedge-taken-count, which works also when
@@ -56,15 +58,14 @@ void VPlanTransforms::introduceTopLevelVectorLoopRegion(
5658
Plan.setTripCount(
5759
vputils::getOrCreateVPValueForSCEVExpr(Plan, TripCount, SE));
5860

59-
// Create VPRegionBlock, with empty header and latch blocks, to be filled
60-
// during processing later.
61+
// Create VPRegionBlock, with existing header and new empty latch block, to be
62+
// filled
6163
VPBasicBlock *LatchVPBB = Plan.createVPBasicBlock("vector.latch");
6264
VPBlockUtils::insertBlockAfter(LatchVPBB, OriginalLatch);
6365
auto *TopRegion = Plan.createVPRegionBlock(
6466
HeaderVPBB, LatchVPBB, "vector loop", false /*isReplicator*/);
65-
for (VPBlockBase *VPBB : vp_depth_first_shallow(HeaderVPBB)) {
67+
for (VPBlockBase *VPBB : vp_depth_first_shallow(HeaderVPBB))
6668
VPBB->setParent(TopRegion);
67-
}
6869

6970
VPBlockUtils::insertBlockAfter(TopRegion, VecPreheader);
7071
VPBasicBlock *MiddleVPBB = Plan.createVPBasicBlock("middle.block");

llvm/lib/Transforms/Vectorize/VPlanTransforms.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ struct VPlanTransforms {
5353
}
5454

5555
/// Introduce the top-level VPRegionBlock for the main loop in \p Plan. Coming
56-
/// in this function, \p Plan's top-level loop is modeled using a plain CFG.
57-
/// This transforms replaces the plain CFG with a VPRegionBlock wrapping the
58-
/// top-level loop and creates a VPValue expressions for the original trip
56+
/// into this function, \p Plan's top-level loop is modeled using a plain CFG.
57+
/// This transform wraps the plain CFG of the top-level loop within a
58+
/// VPRegionBlock and creates a VPValue expressions for the original trip
5959
/// count. It will also introduce a dedicated VPBasicBlock for the vector
6060
/// pre-header as well a VPBasicBlock as exit block of the region
6161
/// (middle.block). If a check is needed to guard executing the scalar

0 commit comments

Comments
 (0)