Skip to content

Commit 78eafb1

Browse files
committed
[VPlan] Add getIndexFor(Predecessor|Successor) helpers (NFC).
Move code to get the index of a predecessor and successor to helpers in VPBlockBase, to avoid duplication and enable future reuse. Split off from #140409.
1 parent 7a688c0 commit 78eafb1

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,20 @@ class VPBlockBase {
320320
std::swap(Successors[0], Successors[1]);
321321
}
322322

323+
/// Returns the index for \p Pred in the blocks predecessors list.
324+
unsigned getIndexForPredecessor(const VPBlockBase *Pred) const {
325+
assert(count(Predecessors, Pred) == 1 &&
326+
"must have Pred exactly once in Predecessors");
327+
return std::distance(Predecessors.begin(), find(Predecessors, Pred));
328+
}
329+
330+
/// Returns the index for \p Succ in the blocks successor list.
331+
unsigned getIndexForSuccessor(const VPBlockBase *Succ) const {
332+
assert(count(Successors, Succ) == 1 &&
333+
"must have Succ exactly once in Successors");
334+
return std::distance(Successors.begin(), find(Successors, Succ));
335+
}
336+
323337
/// The method which generates the output IR that correspond to this
324338
/// VPBlockBase, thereby "executing" the VPlan.
325339
virtual void execute(VPTransformState *State) = 0;

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,10 +1852,7 @@ static void removeBranchOnCondTrue(VPlan &Plan) {
18521852
continue;
18531853

18541854
VPBasicBlock *RemovedSucc = cast<VPBasicBlock>(VPBB->getSuccessors()[1]);
1855-
const auto &Preds = RemovedSucc->getPredecessors();
1856-
assert(count(Preds, VPBB) == 1 &&
1857-
"There must be a single edge between VPBB and its successor");
1858-
unsigned DeadIdx = std::distance(Preds.begin(), find(Preds, VPBB));
1855+
unsigned DeadIdx = RemovedSucc->getIndexForPredecessor(VPBB);
18591856

18601857
// Values coming from VPBB into ResumePhi recipes of RemoveSucc are removed
18611858
// from these recipes.

llvm/lib/Transforms/Vectorize/VPlanUtils.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,8 @@ class VPBlockUtils {
232232
/// single edge between \p From and \p To.
233233
static void insertOnEdge(VPBlockBase *From, VPBlockBase *To,
234234
VPBlockBase *BlockPtr) {
235-
auto &Successors = From->getSuccessors();
236-
auto &Predecessors = To->getPredecessors();
237-
assert(count(Successors, To) == 1 && count(Predecessors, From) == 1 &&
238-
"must have single between From and To");
239-
unsigned SuccIdx = std::distance(Successors.begin(), find(Successors, To));
240-
unsigned PredIx =
241-
std::distance(Predecessors.begin(), find(Predecessors, From));
235+
unsigned SuccIdx = From->getIndexForSuccessor(To);
236+
unsigned PredIx = To->getIndexForPredecessor(From);
242237
VPBlockUtils::connectBlocks(From, BlockPtr, -1, SuccIdx);
243238
VPBlockUtils::connectBlocks(BlockPtr, To, PredIx, -1);
244239
}

0 commit comments

Comments
 (0)