Skip to content

Commit a53a5ed

Browse files
committed
[VPlan] Add VPBlockBase::hasPredecessors (NFC).
Split off from #154510, add helper to check if a block has any predecessors.
1 parent 1debf23 commit a53a5ed

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7276,7 +7276,7 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
72767276
// looked through single-entry phis.
72777277
ScalarEvolution &SE = *PSE.getSE();
72787278
for (VPIRBasicBlock *Exit : BestVPlan.getExitBlocks()) {
7279-
if (Exit->getNumPredecessors() == 0)
7279+
if (!Exit->hasPredecessors())
72807280
continue;
72817281
for (VPRecipeBase &PhiR : Exit->phis())
72827282
SE.forgetLcssaPhiWithNewPredecessor(
@@ -7320,7 +7320,7 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
73207320
}
73217321
}
73227322
VPBasicBlock *ScalarPH = BestVPlan.getScalarPreheader();
7323-
if (ScalarPH->getNumPredecessors() > 0) {
7323+
if (ScalarPH->hasPredecessors()) {
73247324
// If ScalarPH has predecessors, we may need to update its reduction
73257325
// resume values.
73267326
for (VPRecipeBase &R : ScalarPH->phis()) {

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ template <typename T> static T *getPlanEntry(T *Start) {
143143

144144
for (unsigned i = 0; i < WorkList.size(); i++) {
145145
T *Current = WorkList[i];
146-
if (Current->getNumPredecessors() == 0)
146+
if (!Current->hasPredecessors())
147147
return Current;
148148
auto &Predecessors = Current->getPredecessors();
149149
WorkList.insert_range(Predecessors);
@@ -216,7 +216,7 @@ bool VPBlockUtils::isHeader(const VPBlockBase *VPB,
216216
// If VPBB is in a region R, VPBB is a loop header if R is a loop region with
217217
// VPBB as its entry, i.e., free of predecessors.
218218
if (auto *R = VPBB->getParent())
219-
return !R->isReplicator() && VPBB->getNumPredecessors() == 0;
219+
return !R->isReplicator() && !VPBB->hasPredecessors();
220220

221221
// A header dominates its second predecessor (the latch), with the other
222222
// predecessor being the preheader
@@ -809,7 +809,7 @@ InstructionCost VPBasicBlock::cost(ElementCount VF, VPCostContext &Ctx) {
809809

810810
const VPBasicBlock *VPBasicBlock::getCFGPredecessor(unsigned Idx) const {
811811
const VPBlockBase *Pred = nullptr;
812-
if (getNumPredecessors() > 0) {
812+
if (hasPredecessors()) {
813813
Pred = getPredecessors()[Idx];
814814
} else {
815815
auto *Region = getParent();
@@ -1183,14 +1183,14 @@ VPlan *VPlan::duplicate() {
11831183

11841184
BasicBlock *ScalarHeaderIRBB = getScalarHeader()->getIRBasicBlock();
11851185
VPIRBasicBlock *NewScalarHeader = nullptr;
1186-
if (getScalarHeader()->getNumPredecessors() == 0) {
1187-
NewScalarHeader = createVPIRBasicBlock(ScalarHeaderIRBB);
1188-
} else {
1186+
if (getScalarHeader()->hasPredecessors()) {
11891187
NewScalarHeader = cast<VPIRBasicBlock>(*find_if(
11901188
vp_depth_first_shallow(NewEntry), [ScalarHeaderIRBB](VPBlockBase *VPB) {
11911189
auto *VPIRBB = dyn_cast<VPIRBasicBlock>(VPB);
11921190
return VPIRBB && VPIRBB->getIRBasicBlock() == ScalarHeaderIRBB;
11931191
}));
1192+
} else {
1193+
NewScalarHeader = createVPIRBasicBlock(ScalarHeaderIRBB);
11941194
}
11951195
// Create VPlan, clone live-ins and remap operands in the cloned blocks.
11961196
auto *NewPlan = new VPlan(cast<VPBasicBlock>(NewEntry), NewScalarHeader);

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ class LLVM_ABI_FOR_TEST VPBlockBase {
219219
size_t getNumSuccessors() const { return Successors.size(); }
220220
size_t getNumPredecessors() const { return Predecessors.size(); }
221221

222+
/// Returns true if this block has any predecessors.
223+
bool hasPredecessors() const { return !Predecessors.empty(); }
224+
222225
/// An Enclosing Block of a block B is any block containing B, including B
223226
/// itself. \return the closest enclosing block starting from "this", which
224227
/// has successors. \return the root enclosing block if all enclosing blocks
@@ -4301,17 +4304,16 @@ class VPlan {
43014304
/// via the other early exit).
43024305
bool hasEarlyExit() const {
43034306
return count_if(ExitBlocks,
4304-
[](VPIRBasicBlock *EB) {
4305-
return EB->getNumPredecessors() != 0;
4306-
}) > 1 ||
4307+
[](VPIRBasicBlock *EB) { return EB->hasPredecessors(); }) >
4308+
1 ||
43074309
(ExitBlocks.size() == 1 && ExitBlocks[0]->getNumPredecessors() > 1);
43084310
}
43094311

43104312
/// Returns true if the scalar tail may execute after the vector loop. Note
43114313
/// that this relies on unneeded branches to the scalar tail loop being
43124314
/// removed.
43134315
bool hasScalarTail() const {
4314-
return !(getScalarPreheader()->getNumPredecessors() == 0 ||
4316+
return !(!getScalarPreheader()->hasPredecessors() ||
43154317
getScalarPreheader()->getSinglePredecessor() == getEntry());
43164318
}
43174319
};

llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ bool VPlanVerifier::verifyRegion(const VPRegionBlock *Region) {
412412
const VPBlockBase *Exiting = Region->getExiting();
413413

414414
// Entry and Exiting shouldn't have any predecessor/successor, respectively.
415-
if (Entry->getNumPredecessors() != 0) {
415+
if (Entry->hasPredecessors()) {
416416
errs() << "region entry block has predecessors\n";
417417
return false;
418418
}

0 commit comments

Comments
 (0)