Skip to content

Commit

Permalink
[VPlan] Add PredIdx and SuccIdx arguments to connectBlocks (NFC).
Browse files Browse the repository at this point in the history
Add extra arguments to connectBlocks which allow selecting which
existing predecessor/successor to update. This avoids having to
disconnect blocks first unnecessarily.

Suggested in llvm#114292.
  • Loading branch information
fhahn authored and Groverkss committed Nov 15, 2024
1 parent 25aafc4 commit adace2c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
28 changes: 20 additions & 8 deletions llvm/lib/Transforms/Vectorize/VPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -4113,17 +4113,29 @@ class VPBlockUtils {
IfFalse->setParent(BlockPtr->getParent());
}

/// Connect VPBlockBases \p From and \p To bi-directionally. Append \p To to
/// the successors of \p From and \p From to the predecessors of \p To. Both
/// VPBlockBases must have the same parent, which can be null. Both
/// VPBlockBases can be already connected to other VPBlockBases.
static void connectBlocks(VPBlockBase *From, VPBlockBase *To) {
/// Connect VPBlockBases \p From and \p To bi-directionally. If \p PredIdx is
/// -1, append \p From to the predecessors of \p To, otherwise set \p To's
/// predecessor at \p PredIdx to \p From. If \p SuccIdx is -1, append \p To to
/// the successors of \p From, otherwise set \p From's successor at \p SuccIdx
/// to \p To. Both VPBlockBases must have the same parent, which can be null.
/// Both VPBlockBases can be already connected to other VPBlockBases.
static void connectBlocks(VPBlockBase *From, VPBlockBase *To,
unsigned PredIdx = -1u, unsigned SuccIdx = -1u) {
assert((From->getParent() == To->getParent()) &&
"Can't connect two block with different parents");
assert(From->getNumSuccessors() < 2 &&
assert((SuccIdx != -1u || From->getNumSuccessors() < 2) &&
"Blocks can't have more than two successors.");
From->appendSuccessor(To);
To->appendPredecessor(From);
assert((PredIdx != -1u || To->getNumPredecessors() < 2) &&
"Blocks can't have more than two predecessors.");
if (SuccIdx == -1u)
From->appendSuccessor(To);
else
From->getSuccessors()[SuccIdx] = To;

if (PredIdx == -1u)
To->appendPredecessor(From);
else
To->getPredecessors()[PredIdx] = From;
}

/// Disconnect VPBlockBases \p From and \p To bi-directionally. Remove \p To
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,8 @@ static void addReplicateRegions(VPlan &Plan) {
// Record predicated instructions for above packing optimizations.
VPBlockBase *Region = createReplicateRegion(RepR, Plan);
Region->setParent(CurrentBlock->getParent());
VPBlockUtils::disconnectBlocks(CurrentBlock, SplitBlock);
VPBlockUtils::connectBlocks(CurrentBlock, Region);
VPBlockUtils::connectBlocks(Region, SplitBlock);
VPBlockUtils::connectBlocks(CurrentBlock, Region, -1, 0);
VPBlockUtils::connectBlocks(Region, SplitBlock, 0, -1);
}
}

Expand Down

0 comments on commit adace2c

Please sign in to comment.