[llvm] [VPlan] Generalize `VPAllSuccessorsIterator` to support predecessors (PR #178724)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 2 04:51:36 PST 2026
================
@@ -25,90 +25,132 @@ namespace llvm {
// GraphTraits specializations for VPlan Hierarchical Control-Flow Graphs //
//===----------------------------------------------------------------------===//
-/// Iterator to traverse all successors of a VPBlockBase node. This includes the
-/// entry node of VPRegionBlocks. Exit blocks of a region implicitly have their
-/// parent region's successors. This ensures all blocks in a region are visited
-/// before any blocks in a successor region when doing a reverse post-order
-// traversal of the graph. Region blocks themselves traverse only their entries
-// directly and not their successors. Those will be traversed when a region's
-// exiting block is traversed
-template <typename BlockPtrTy>
-class VPAllSuccessorsIterator
- : public iterator_facade_base<VPAllSuccessorsIterator<BlockPtrTy>,
- std::bidirectional_iterator_tag,
- VPBlockBase> {
+/// Iterator to traverse all successors/predecessors of a VPBlockBase node, such
+/// that:
+///
+/// A
+/// |
+/// +-----+ <- Region R
+/// | b |
+/// | |
+/// | ... |
+/// | |
+/// | e |
+/// +-----+
+/// |
+/// B
+///
+/// children(A) == {R} ; Forward == true
+/// children(R) == {b} ; Forward == true
+/// children(e) == {B} ; Forward == true
+///
+/// children(B) == {R} ; Forward == false
+/// children(R) == {e} ; Forward == false
+/// children(b) == {A} ; Forward == false
+///
+/// This ensures that all blocks of the region are visited before continuing
+/// traversal outside the region when doing a reverse post-order traversal of
+/// the VPlan.
+///
+template <typename BlockPtrTy, bool Forward = true>
+class VPImmediateHierarchicalChildrenIterator
+ : public iterator_facade_base<
+ VPImmediateHierarchicalChildrenIterator<BlockPtrTy, Forward>,
+ std::bidirectional_iterator_tag, VPBlockBase> {
BlockPtrTy Block;
- /// Index of the current successor. For VPBasicBlock nodes, this simply is the
- /// index for the successor array. For VPRegionBlock, SuccessorIdx == 0 is
- /// used for the region's entry block, and SuccessorIdx - 1 are the indices
- /// for the successor array.
- size_t SuccessorIdx;
-
- static BlockPtrTy getBlockWithSuccs(BlockPtrTy Current) {
- while (Current && Current->getNumSuccessors() == 0)
+ /// Index of the current successor/predecessor.
+ ///
+ /// For VPBasicBlock nodes, this simply is the index for the
+ /// successors/predecessors array. For VPRegionBlock, EdgeIdx == 0 is used for
+ /// the region's entry/exiting block, and EdgeIdx - 1 are the indices for the
+ /// successors/predecessors array.
----------------
fhahn wrote:
hard to tell from the diff if anything changes. if not, can retain original formatting?
https://github.com/llvm/llvm-project/pull/178724
More information about the llvm-commits
mailing list