From c334965e603a35836ccea3cc836c9313a0470012 Mon Sep 17 00:00:00 2001 From: Alessandro Di Federico Date: Wed, 29 Apr 2026 11:42:12 +0200 Subject: [PATCH] [ADT] PostOrderIterator.h: honor GraphTraits --- llvm/include/llvm/ADT/PostOrderIterator.h | 47 +++++++++++++++-------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/llvm/include/llvm/ADT/PostOrderIterator.h b/llvm/include/llvm/ADT/PostOrderIterator.h index a80eed78c94d..59ce17bf0835 100644 --- a/llvm/include/llvm/ADT/PostOrderIterator.h +++ b/llvm/include/llvm/ADT/PostOrderIterator.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -144,12 +145,18 @@ class po_iterator : public po_iterator_storage { public: // Provide static "constructors"... static po_iterator begin(const GraphT &G) { - return po_iterator(GT::getEntryNode(G)); + if constexpr (std::is_same_v) + return po_iterator(G); + else + return po_iterator(GT::getEntryNode(G)); } static po_iterator end(const GraphT &G) { return po_iterator(); } static po_iterator begin(const GraphT &G, SetType &S) { - return po_iterator(GT::getEntryNode(G), S); + if constexpr (std::is_same_v) + return po_iterator(G, S); + else + return po_iterator(GT::getEntryNode(G), S); } static po_iterator end(const GraphT &G, SetType &S) { return po_iterator(S); } @@ -193,10 +200,11 @@ template iterator_range> post_order(const T &G) { } // Provide global definitions of external postorder iterators... -template ::NodeRef>> -struct po_ext_iterator : public po_iterator { - po_ext_iterator(const po_iterator &V) : - po_iterator(V) {} +template ::NodeRef>, + class GT = GraphTraits> +struct po_ext_iterator : public po_iterator { + po_ext_iterator(const po_iterator &V) : + po_iterator(V) {} }; template @@ -216,10 +224,10 @@ iterator_range> post_order_ext(const T &G, SetType & // Provide global definitions of inverse post order iterators... template ::NodeRef>, - bool External = false> -struct ipo_iterator : public po_iterator, SetType, External> { - ipo_iterator(const po_iterator, SetType, External> &V) : - po_iterator, SetType, External> (V) {} + bool External = false, class GT = GraphTraits>> +struct ipo_iterator : public po_iterator, SetType, External, GT> { + ipo_iterator(const po_iterator, SetType, External, GT> &V) : + po_iterator, SetType, External, GT> (V) {} }; template @@ -238,12 +246,13 @@ iterator_range> inverse_post_order(const T &G) { } // Provide global definitions of external inverse postorder iterators... -template ::NodeRef>> -struct ipo_ext_iterator : public ipo_iterator { - ipo_ext_iterator(const ipo_iterator &V) : - ipo_iterator(V) {} - ipo_ext_iterator(const po_iterator, SetType, true> &V) : - ipo_iterator(V) {} +template ::NodeRef>, + class GT = GraphTraits>> +struct ipo_ext_iterator : public ipo_iterator { + ipo_ext_iterator(const ipo_iterator &V) : + ipo_iterator(V) {} + ipo_ext_iterator(const po_iterator, SetType, true, GT> &V) : + ipo_iterator(V) {} }; template @@ -296,7 +305,11 @@ class ReversePostOrderTraversal { std::vector Blocks; // Block list in normal PO order void Initialize(const GraphT &G) { - std::copy(po_begin(G), po_end(G), std::back_inserter(Blocks)); + using POIter = po_iterator, + false, + GT>; + std::copy(POIter::begin(G), POIter::end(G), std::back_inserter(Blocks)); } public: