Skip to content

Commit

Permalink
[VPlan] Add insertOnEdge to VPBlockUtils (NFC).
Browse files Browse the repository at this point in the history
Add a new helper to insert a new VPBlockBase on an edge between 2
blocks. Suggested in #114292
and also useful for some existing code.
  • Loading branch information
fhahn committed Nov 9, 2024
1 parent 69fb9bc commit ccb40b0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
18 changes: 18 additions & 0 deletions llvm/lib/Transforms/Vectorize/VPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -4177,6 +4177,24 @@ class VPBlockUtils {
return cast<BlockTy>(&Block);
});
}

/// Inserts \p BlockPtr on the edge between \p From and \p To. That is, update
/// \p From's successor to \p To to point to \p BlockPtr and \p To's
/// predecessor from \p From to \p BlockPtr. \p From and \p To are added to \p
/// BlockPtr's predecessors and successors respectively. There must be a
/// single edge between \p From and \p To.
static void insertOnEdge(VPBlockBase *From, VPBlockBase *To,
VPBlockBase *BlockPtr) {
auto &Successors = From->getSuccessors();
auto &Predecessors = To->getPredecessors();
assert(count(Successors, To) == 1 && count(Predecessors, From) == 1 &&
"must have single between From and To");
unsigned SuccIdx = std::distance(Successors.begin(), find(Successors, To));
unsigned PredIx =
std::distance(Predecessors.begin(), find(Predecessors, From));
VPBlockUtils::connectBlocks(From, BlockPtr, -1, SuccIdx);
VPBlockUtils::connectBlocks(BlockPtr, To, PredIx, -1);
}
};

class VPInterleavedAccessInfo {
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,7 @@ static void addReplicateRegions(VPlan &Plan) {
// Record predicated instructions for above packing optimizations.
VPBlockBase *Region = createReplicateRegion(RepR, Plan);
Region->setParent(CurrentBlock->getParent());
VPBlockUtils::connectBlocks(CurrentBlock, Region, -1, 0);
VPBlockUtils::connectBlocks(Region, SplitBlock, 0, -1);
VPBlockUtils::insertOnEdge(CurrentBlock, SplitBlock, Region);
}
}

Expand Down

0 comments on commit ccb40b0

Please sign in to comment.