Skip to content

Commit 9cc1585

Browse files
committed
[VPlan] Add VPBlockUtils::transferSuccessors (NFCI).
Add a new helper to transfer successors to a new, unconnected VPBB. Helps to simplify existing code, and prepare for upcoming changes.
1 parent 4014d83 commit 9cc1585

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -843,15 +843,14 @@ void VPRegionBlock::dissolveToCFGLoop() {
843843

844844
VPBlockBase *Preheader = getSinglePredecessor();
845845
auto *ExitingLatch = cast<VPBasicBlock>(getExiting());
846-
VPBlockBase *Middle = getSingleSuccessor();
846+
847847
VPBlockUtils::disconnectBlocks(Preheader, this);
848-
VPBlockUtils::disconnectBlocks(this, Middle);
849848

850849
for (VPBlockBase *VPB : vp_depth_first_shallow(Entry))
851850
VPB->setParent(getParent());
852851

853852
VPBlockUtils::connectBlocks(Preheader, Header);
854-
VPBlockUtils::connectBlocks(ExitingLatch, Middle);
853+
VPBlockUtils::transferSuccessors(this, ExitingLatch);
855854
VPBlockUtils::connectBlocks(ExitingLatch, Header);
856855
}
857856

llvm/lib/Transforms/Vectorize/VPlanUtils.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,7 @@ class VPBlockUtils {
116116
NewBlock->getPredecessors().empty() &&
117117
"Can't insert new block with predecessors or successors.");
118118
NewBlock->setParent(BlockPtr->getParent());
119-
SmallVector<VPBlockBase *> Succs(BlockPtr->successors());
120-
for (VPBlockBase *Succ : Succs) {
121-
Succ->replacePredecessor(BlockPtr, NewBlock);
122-
NewBlock->appendSuccessor(Succ);
123-
}
124-
BlockPtr->clearSuccessors();
119+
transferSuccessors(BlockPtr, NewBlock);
125120
connectBlocks(BlockPtr, NewBlock);
126121
}
127122

@@ -205,6 +200,14 @@ class VPBlockUtils {
205200
Old->clearSuccessors();
206201
}
207202

203+
/// Transfer successors from \p Old to \p New. \p New must have no successors.
204+
static void transferSuccessors(VPBlockBase *Old, VPBlockBase *New) {
205+
for (auto *Succ : Old->getSuccessors())
206+
Succ->replacePredecessor(Old, New);
207+
New->setSuccessors(Old->getSuccessors());
208+
Old->clearSuccessors();
209+
}
210+
208211
/// Return an iterator range over \p Range which only includes \p BlockTy
209212
/// blocks. The accesses are casted to \p BlockTy.
210213
template <typename BlockTy, typename T>

0 commit comments

Comments
 (0)