[llvm] 3e3d2b6 - [VPlan] Add hasPredecessors and hasSuccessors to VPBlockBase (NFC).
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 14 13:08:08 PDT 2026
Author: Florian Hahn
Date: 2026-03-14T20:07:42Z
New Revision: 3e3d2b6fbce0ad132a60bb38dace9722f37db314
URL: https://github.com/llvm/llvm-project/commit/3e3d2b6fbce0ad132a60bb38dace9722f37db314
DIFF: https://github.com/llvm/llvm-project/commit/3e3d2b6fbce0ad132a60bb38dace9722f37db314.diff
LOG: [VPlan] Add hasPredecessors and hasSuccessors to VPBlockBase (NFC).
Add/move helpers to VPBlockBase, and use in a few more places.
Split off from https://github.com/llvm/llvm-project/pull/156262 as
suggested.
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlan.cpp
llvm/lib/Transforms/Vectorize/VPlan.h
llvm/lib/Transforms/Vectorize/VPlanUtils.h
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index aec6c92de0555..da631984a9a3c 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -664,7 +664,7 @@ void VPBlockBase::print(raw_ostream &O) const {
}
void VPBlockBase::printSuccessors(raw_ostream &O, const Twine &Indent) const {
- if (getSuccessors().empty()) {
+ if (!hasSuccessors()) {
O << Indent << "No successors\n";
} else {
O << Indent << "Successor(s): ";
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index ce19e41f5d889..35fa8a2aff352 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -199,6 +199,11 @@ class LLVM_ABI_FOR_TEST VPBlockBase {
const VPBlocksTy &getSuccessors() const { return Successors; }
VPBlocksTy &getSuccessors() { return Successors; }
+ /// Returns true if this block has any successors.
+ bool hasSuccessors() const { return !Successors.empty(); }
+ /// Returns true if this block has any predecessors.
+ bool hasPredecessors() const { return !Predecessors.empty(); }
+
iterator_range<VPBlockBase **> successors() { return Successors; }
iterator_range<VPBlockBase **> predecessors() { return Predecessors; }
@@ -220,9 +225,6 @@ class LLVM_ABI_FOR_TEST VPBlockBase {
size_t getNumSuccessors() const { return Successors.size(); }
size_t getNumPredecessors() const { return Predecessors.size(); }
- /// Returns true if this block has any predecessors.
- bool hasPredecessors() const { return !Predecessors.empty(); }
-
/// An Enclosing Block of a block B is any block containing B, including B
/// itself. \return the closest enclosing block starting from "this", which
/// has successors. \return the root enclosing block if all enclosing blocks
@@ -4441,8 +4443,8 @@ class LLVM_ABI_FOR_TEST VPRegionBlock : public VPBlockBase {
const std::string &Name = "", bool IsReplicator = false)
: VPBlockBase(VPRegionBlockSC, Name), Entry(Entry), Exiting(Exiting),
IsReplicator(IsReplicator) {
- assert(Entry->getPredecessors().empty() && "Entry block has predecessors.");
- assert(Exiting->getSuccessors().empty() && "Exit block has successors.");
+ assert(!Entry->hasPredecessors() && "Entry block has predecessors.");
+ assert(!Exiting->hasSuccessors() && "Exit block has successors.");
Entry->setParent(this);
Exiting->setParent(this);
}
@@ -4464,7 +4466,7 @@ class LLVM_ABI_FOR_TEST VPRegionBlock : public VPBlockBase {
/// Set \p EntryBlock as the entry VPBlockBase of this VPRegionBlock. \p
/// EntryBlock must have no predecessors.
void setEntry(VPBlockBase *EntryBlock) {
- assert(EntryBlock->getPredecessors().empty() &&
+ assert(!EntryBlock->hasPredecessors() &&
"Entry block cannot have predecessors.");
Entry = EntryBlock;
EntryBlock->setParent(this);
@@ -4476,7 +4478,7 @@ class LLVM_ABI_FOR_TEST VPRegionBlock : public VPBlockBase {
/// Set \p ExitingBlock as the exiting VPBlockBase of this VPRegionBlock. \p
/// ExitingBlock must have no successors.
void setExiting(VPBlockBase *ExitingBlock) {
- assert(ExitingBlock->getSuccessors().empty() &&
+ assert(!ExitingBlock->hasSuccessors() &&
"Exit block cannot have successors.");
Exiting = ExitingBlock;
ExitingBlock->setParent(this);
diff --git a/llvm/lib/Transforms/Vectorize/VPlanUtils.h b/llvm/lib/Transforms/Vectorize/VPlanUtils.h
index a5692699d9d76..c4cacebcd78ba 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanUtils.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanUtils.h
@@ -168,8 +168,7 @@ class VPBlockUtils {
/// successors are moved from \p BlockPtr to \p NewBlock. \p NewBlock must
/// have neither successors nor predecessors.
static void insertBlockAfter(VPBlockBase *NewBlock, VPBlockBase *BlockPtr) {
- assert(NewBlock->getSuccessors().empty() &&
- NewBlock->getPredecessors().empty() &&
+ assert(!NewBlock->hasSuccessors() && !NewBlock->hasPredecessors() &&
"Can't insert new block with predecessors or successors.");
NewBlock->setParent(BlockPtr->getParent());
transferSuccessors(BlockPtr, NewBlock);
@@ -181,8 +180,7 @@ class VPBlockUtils {
/// NewBlock. Add \p NewBlock as predecessor of \p BlockPtr and \p BlockPtr as
/// successor of \p NewBlock.
static void insertBlockBefore(VPBlockBase *NewBlock, VPBlockBase *BlockPtr) {
- assert(NewBlock->getSuccessors().empty() &&
- NewBlock->getPredecessors().empty() &&
+ assert(!NewBlock->hasSuccessors() && !NewBlock->hasPredecessors() &&
"Can't insert new block with predecessors or successors.");
NewBlock->setParent(BlockPtr->getParent());
for (VPBlockBase *Pred : to_vector(BlockPtr->predecessors())) {
@@ -201,9 +199,8 @@ class VPBlockUtils {
/// predecessors.
static void insertTwoBlocksAfter(VPBlockBase *IfTrue, VPBlockBase *IfFalse,
VPBlockBase *BlockPtr) {
- assert(IfTrue->getSuccessors().empty() &&
- "Can't insert IfTrue with successors.");
- assert(IfFalse->getSuccessors().empty() &&
+ assert(!IfTrue->hasSuccessors() && "Can't insert IfTrue with successors.");
+ assert(!IfFalse->hasSuccessors() &&
"Can't insert IfFalse with successors.");
BlockPtr->setTwoSuccessors(IfTrue, IfFalse);
IfTrue->setPredecessors({BlockPtr});
More information about the llvm-commits
mailing list