16#ifndef LLVM_ADT_POSTORDERITERATOR_H
17#define LLVM_ADT_POSTORDERITERATOR_H
58template<
class SetType,
bool External>
64 template <
typename NodeRef>
65 bool insertEdge(std::optional<NodeRef> From, NodeRef To) {
66 return Visited.insert(To).second;
74template<
class SetType>
85 template <
class NodeRef>
86 bool insertEdge(std::optional<NodeRef> From, NodeRef To) {
87 return Visited.insert(To).second;
101 if (
Size < Data.size())
102 Data.resize(
Size,
false);
107 if (Idx >= Data.size())
108 Data.resize(Idx + 1);
109 bool Inserted = !Data[Idx];
111 return {std::nullopt, Inserted};
115template <
typename GraphT>
117 std::conditional_t<GraphHasNodeNumbers<GraphT>,
123template <
class GraphT,
class SetType = po_detail::DefaultSet<GraphT>,
124 bool ExtStorage = false,
class GT = GraphTraits<GraphT>>
129 std::conditional_t<ExtStorage, std::input_iterator_tag,
130 std::forward_iterator_tag>;
137 using NodeRef =
typename GT::NodeRef;
138 using ChildItTy =
typename GT::ChildIteratorType;
145 po_iterator(NodeRef BB) {
146 this->
insertEdge(std::optional<NodeRef>(), BB);
147 VisitStack.emplace_back(BB, GT::child_begin(BB), GT::child_end(BB));
155 if (this->
insertEdge(std::optional<NodeRef>(), BB)) {
156 VisitStack.
emplace_back(BB, GT::child_begin(BB), GT::child_end(BB));
161 po_iterator(SetType &S)
162 : po_iterator_storage<SetType, ExtStorage>(S) {
165 void traverseChild() {
167 auto &
Entry = VisitStack.back();
168 if (std::get<1>(Entry) == std::get<2>(Entry))
170 NodeRef BB = *std::get<1>(Entry)++;
171 if (this->
insertEdge(std::optional<NodeRef>(std::get<0>(Entry)), BB)) {
173 VisitStack.emplace_back(BB, GT::child_begin(BB), GT::child_end(BB));
180 static po_iterator
begin(
const GraphT &
G) {
181 return po_iterator(GT::getEntryNode(
G));
183 static po_iterator
end(
const GraphT &
G) {
return po_iterator(); }
185 static po_iterator
begin(
const GraphT &
G, SetType &S) {
186 return po_iterator(GT::getEntryNode(
G), S);
188 static po_iterator
end(
const GraphT &
G, SetType &S) {
return po_iterator(S); }
191 return VisitStack == x.VisitStack;
193 bool operator!=(
const po_iterator &x)
const {
return !(*
this == x); }
205 VisitStack.pop_back();
206 if (!VisitStack.empty())
212 po_iterator tmp = *
this;
230template <class T, class SetType = std::set<typename GraphTraits<T>::NodeRef>>
233 po_iterator<
T, SetType,
true>(V) {}
236template <
class T,
class SetType>
241template <
class T,
class SetType>
246template <
class T,
class SetType>
252template <class T, class SetType = std::set<typename GraphTraits<T>::NodeRef>,
253 bool External =
false>
256 po_iterator<
Inverse<
T>, SetType, External> (V) {}
275template <class T, class SetType = std::set<typename GraphTraits<T>::NodeRef>>
283template <
class T,
class SetType>
288template <
class T,
class SetType>
293template <
class T,
class SetType>
326template<
class GraphT,
class GT = GraphTraits<GraphT>>
328 using NodeRef =
typename GT::NodeRef;
333 void Initialize(
const GraphT &
G) {
This file defines the little GraphTraits<X> template class that should be specialized by classes that...
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
const_rpo_iterator end() const
const_rpo_iterator begin() const
ReversePostOrderTraversal(const GraphT &G)
typename VecTy::reverse_iterator rpo_iterator
typename VecTy::const_reverse_iterator const_rpo_iterator
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
reference emplace_back(ArgTypes &&... Args)
std::reverse_iterator< const_iterator > const_reverse_iterator
std::reverse_iterator< iterator > reverse_iterator
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
A range adaptor for a pair of iterators.
std::pair< std::nullopt_t, bool > insert(NodeRef Node)
void reserve(size_t Size)
void finishPostorder(NodeRef BB)
po_iterator_storage(const po_iterator_storage &S)
bool insertEdge(std::optional< NodeRef > From, NodeRef To)
po_iterator_storage(SetType &VSet)
Default po_iterator_storage implementation with an internal set object.
bool insertEdge(std::optional< NodeRef > From, NodeRef To)
void finishPostorder(NodeRef BB)
static po_iterator end(const GraphT &G, SetType &S)
reference operator*() const
std::ptrdiff_t difference_type
static po_iterator end(const GraphT &G)
const value_type & reference
NodeRef operator->() const
typename GT::NodeRef value_type
static po_iterator begin(const GraphT &G)
po_iterator & operator++()
po_iterator operator++(int)
std::conditional_t< ExtStorage, std::input_iterator_tag, std::forward_iterator_tag > iterator_category
bool operator==(const po_iterator &x) const
bool operator!=(const po_iterator &x) const
static po_iterator begin(const GraphT &G, SetType &S)
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
std::conditional_t< GraphHasNodeNumbers< GraphT >, NumberSet< typename GraphTraits< GraphT >::NodeRef >, SmallPtrSet< typename GraphTraits< GraphT >::NodeRef, 8 > > DefaultSet
This is an optimization pass for GlobalISel generic memory operations.
ipo_iterator< T > ipo_end(const T &G)
iterator_range< po_ext_iterator< T, SetType > > post_order_ext(const T &G, SetType &S)
iterator_range< ipo_ext_iterator< T, SetType > > inverse_post_order_ext(const T &G, SetType &S)
ipo_ext_iterator< T, SetType > ipo_ext_begin(const T &G, SetType &S)
iterator_range< ipo_iterator< T > > inverse_post_order(const T &G)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
iterator_range< po_iterator< T > > post_order(const T &G)
po_iterator< T > po_begin(const T &G)
ipo_ext_iterator< T, SetType > ipo_ext_end(const T &G, SetType &S)
ipo_iterator< T > ipo_begin(const T &G)
po_ext_iterator< T, SetType > po_ext_begin(const T &G, SetType &S)
po_ext_iterator< T, SetType > po_ext_end(const T &G, SetType &S)
iterator_range(Container &&) -> iterator_range< llvm::detail::IterOfRange< Container > >
po_iterator< T > po_end(const T &G)
ipo_ext_iterator(const ipo_iterator< T, SetType, true > &V)
ipo_ext_iterator(const po_iterator< Inverse< T >, SetType, true > &V)
ipo_iterator(const po_iterator< Inverse< T >, SetType, External > &V)
po_ext_iterator(const po_iterator< T, SetType, true > &V)