34#ifndef LLVM_ADT_DEPTHFIRSTITERATOR_H
35#define LLVM_ADT_DEPTHFIRSTITERATOR_H
51template<
class SetType,
bool External>
57template<
class SetType>
70template <
typename NodeRef,
unsigned SmallSize = 8>
76 template <
typename IterT>
83template <
class GraphT,
85 df_iterator_default_set<typename GraphTraits<GraphT>::NodeRef>,
86 bool ExtStorage =
false,
class GT = GraphTraits<GraphT>>
91 std::conditional_t<ExtStorage, std::input_iterator_tag,
92 std::forward_iterator_tag>;
99 using NodeRef =
typename GT::NodeRef;
100 using ChildItTy =
typename GT::ChildIteratorType;
105 using StackElement = std::pair<NodeRef, std::optional<ChildItTy>>;
110 inline df_iterator(NodeRef
Node) {
112 VisitStack.push_back(StackElement(
Node, std::nullopt));
119 if (this->
Visited.insert(Node).second)
123 inline df_iterator(SetType &S)
124 : df_iterator_storage<SetType, ExtStorage>(S) {
128 inline void toNext() {
130 NodeRef
Node = VisitStack.back().first;
131 std::optional<ChildItTy> &Opt = VisitStack.back().second;
134 Opt.emplace(GT::child_begin(Node));
139 while (*Opt != GT::child_end(Node)) {
140 NodeRef
Next = *(*Opt)++;
144 VisitStack.push_back(StackElement(
Next, std::nullopt));
151 VisitStack.pop_back();
152 }
while (!VisitStack.empty());
157 static df_iterator
begin(
const GraphT &
G) {
158 return df_iterator(GT::getEntryNode(
G));
160 static df_iterator
end(
const GraphT &
G) {
return df_iterator(); }
163 static df_iterator
begin(
const GraphT &
G, SetType &S) {
164 return df_iterator(GT::getEntryNode(
G), S);
166 static df_iterator
end(
const GraphT &
G, SetType &S) {
return df_iterator(S); }
169 return VisitStack == x.VisitStack;
171 bool operator!=(
const df_iterator &x)
const {
return !(*
this == x); }
191 VisitStack.pop_back();
192 if (!VisitStack.empty())
198 df_iterator tmp = *
this;
216 NodeRef
getPath(
unsigned n)
const {
return VisitStack[n].first; }
240 df_iterator_default_set<typename GraphTraits<T>::NodeRef>>
243 : df_iterator<
T, SetTy,
true>(V) {}
246template <
class T,
class SetTy>
251template <
class T,
class SetTy>
256template <
class T,
class SetTy>
265 df_iterator_default_set<typename GraphTraits<T>::NodeRef>,
266 bool External =
false>
269 : df_iterator<
Inverse<
T>, SetTy, External>(V) {}
291 df_iterator_default_set<typename GraphTraits<T>::NodeRef>>
299template <
class T,
class SetTy>
304template <
class T,
class SetTy>
309template <
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.
This file defines the SmallVector class.
std::pair< iterator, bool > insert(NodeRef Ptr)
SmallPtrSetIterator< NodeRef > iterator
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
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
std::conditional_t< ExtStorage, std::input_iterator_tag, std::forward_iterator_tag > iterator_category
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
Return the length of the path from the entry node to the current node, counting both nodes.
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
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
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.
NodeAddr< NodeBase * > Node
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)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next
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
SmallPtrSet< NodeRef, SmallSize > BaseSet
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)