34#ifndef LLVM_ADT_DEPTHFIRSTITERATOR_H
35#define LLVM_ADT_DEPTHFIRSTITERATOR_H
49template<
class SetType,
bool External>
55template<
class SetType>
68template <
typename NodeRef,
unsigned SmallSize=8>
74 template <
typename IterT>
81template <
class GraphT,
83 df_iterator_default_set<typename GraphTraits<GraphT>::NodeRef>,
84 bool ExtStorage =
false,
class GT = GraphTraits<GraphT>>
94 using NodeRef =
typename GT::NodeRef;
95 using ChildItTy =
typename GT::ChildIteratorType;
100 using StackElement = std::pair<NodeRef, std::optional<ChildItTy>>;
103 std::vector<StackElement> VisitStack;
107 VisitStack.push_back(StackElement(
Node, std::nullopt));
114 if (this->
Visited.insert(Node).second)
115 VisitStack.push_back(StackElement(
Node, std::nullopt));
118 inline df_iterator(SetType &S)
119 : df_iterator_storage<SetType, ExtStorage>(S) {
123 inline void toNext() {
125 NodeRef
Node = VisitStack.back().first;
126 std::optional<ChildItTy> &Opt = VisitStack.back().second;
129 Opt.emplace(GT::child_begin(
Node));
134 while (*Opt != GT::child_end(
Node)) {
135 NodeRef Next = *(*Opt)++;
137 if (this->
Visited.insert(Next).second) {
139 VisitStack.push_back(StackElement(Next, std::nullopt));
146 VisitStack.pop_back();
147 }
while (!VisitStack.empty());
164 return VisitStack == x.VisitStack;
186 VisitStack.pop_back();
187 if (!VisitStack.empty())
203 return this->
Visited.contains(Node);
212 NodeRef
getPath(
unsigned n)
const {
return VisitStack[n].first; }
234template <class T, class SetTy = df_iterator_default_set<typename GraphTraits<T>::NodeRef>>
240template <
class T,
class SetTy>
245template <
class T,
class SetTy>
250template <
class T,
class SetTy>
259 df_iterator_default_set<typename GraphTraits<T>::NodeRef>,
260 bool External =
false>
283template <class T, class SetTy = df_iterator_default_set<typename GraphTraits<T>::NodeRef>>
291template <
class T,
class SetTy>
296template <
class T,
class SetTy>
301template <
class T,
class SetTy>
This file defines the little GraphTraits<X> template class that should be specialized by classes that...
This file defines the SmallPtrSet class.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSetIterator< PtrType > iterator
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
df_iterator_storage(const df_iterator_storage &S)
df_iterator_storage(SetType &VSet)
df_iterator & operator++()
static df_iterator begin(const GraphT &G)
NodeRef operator->() const
static df_iterator end(const GraphT &G)
const value_type & reference
static df_iterator end(const GraphT &G, SetType &S)
df_iterator & skipChildren()
Skips all children of the current node and traverses to next node.
unsigned getPathLength() const
getPathLength - Return the length of the path from the entry node to the current node,...
bool operator==(const df_iterator &x) const
df_iterator operator++(int)
bool operator!=(const df_iterator &x) const
bool nodeVisited(NodeRef Node) const
NodeRef getPath(unsigned n) const
getPath - Return the n'th node in the path from the entry node to the current node.
static df_iterator begin(const GraphT &G, SetType &S)
reference operator*() const
std::ptrdiff_t difference_type
std::forward_iterator_tag iterator_category
typename GT::NodeRef value_type
A range adaptor for a pair of iterators.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< df_ext_iterator< T, SetTy > > depth_first_ext(const T &G, SetTy &S)
idf_ext_iterator< T, SetTy > idf_ext_end(const T &G, SetTy &S)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
df_iterator< T > df_begin(const T &G)
idf_ext_iterator< T, SetTy > idf_ext_begin(const T &G, SetTy &S)
iterator_range< idf_iterator< T > > inverse_depth_first(const T &G)
df_ext_iterator< T, SetTy > df_ext_begin(const T &G, SetTy &S)
idf_iterator< T > idf_end(const T &G)
iterator_range< idf_ext_iterator< T, SetTy > > inverse_depth_first_ext(const T &G, SetTy &S)
idf_iterator< T > idf_begin(const T &G)
df_ext_iterator< T, SetTy > df_ext_end(const T &G, SetTy &S)
df_iterator< T > df_end(const T &G)
iterator_range< df_iterator< T > > depth_first(const T &G)
df_ext_iterator(const df_iterator< T, SetTy, true > &V)
void insert(IterT Begin, IterT End)
typename BaseSet::iterator iterator
std::pair< iterator, bool > insert(NodeRef N)
idf_ext_iterator(const idf_iterator< T, SetTy, true > &V)
idf_ext_iterator(const df_iterator< Inverse< T >, SetTy, true > &V)
idf_iterator(const df_iterator< Inverse< T >, SetTy, External > &V)