mirror of
https://github.com/RPCSX/llvm.git
synced 2024-12-12 14:17:59 +00:00
[PM] [cleanup] Run clang-format over this file. If fixes many
inconsistencies that I'll just need to fix myself as I edit things. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@195784 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
aba7b68814
commit
2bd48f03ba
@ -35,13 +35,13 @@ namespace llvm {
|
|||||||
/// This is implemented using Tarjan's DFS algorithm using an internal stack to
|
/// This is implemented using Tarjan's DFS algorithm using an internal stack to
|
||||||
/// build up a vector of nodes in a particular SCC. Note that it is a forward
|
/// build up a vector of nodes in a particular SCC. Note that it is a forward
|
||||||
/// iterator and thus you cannot backtrack or re-visit nodes.
|
/// iterator and thus you cannot backtrack or re-visit nodes.
|
||||||
template<class GraphT, class GT = GraphTraits<GraphT> >
|
template <class GraphT, class GT = GraphTraits<GraphT> >
|
||||||
class scc_iterator
|
class scc_iterator
|
||||||
: public std::iterator<std::forward_iterator_tag,
|
: public std::iterator<std::forward_iterator_tag,
|
||||||
std::vector<typename GT::NodeType>, ptrdiff_t> {
|
std::vector<typename GT::NodeType>, ptrdiff_t> {
|
||||||
typedef typename GT::NodeType NodeType;
|
typedef typename GT::NodeType NodeType;
|
||||||
typedef typename GT::ChildIteratorType ChildItTy;
|
typedef typename GT::ChildIteratorType ChildItTy;
|
||||||
typedef std::vector<NodeType*> SccTy;
|
typedef std::vector<NodeType *> SccTy;
|
||||||
typedef std::iterator<std::forward_iterator_tag,
|
typedef std::iterator<std::forward_iterator_tag,
|
||||||
std::vector<typename GT::NodeType>, ptrdiff_t> super;
|
std::vector<typename GT::NodeType>, ptrdiff_t> super;
|
||||||
typedef typename super::reference reference;
|
typedef typename super::reference reference;
|
||||||
@ -102,10 +102,11 @@ class scc_iterator
|
|||||||
// Compute the next SCC using the DFS traversal.
|
// Compute the next SCC using the DFS traversal.
|
||||||
void GetNextSCC() {
|
void GetNextSCC() {
|
||||||
assert(VisitStack.size() == MinVisitNumStack.size());
|
assert(VisitStack.size() == MinVisitNumStack.size());
|
||||||
CurrentSCC.clear(); // Prepare to compute the next SCC
|
CurrentSCC.clear(); // Prepare to compute the next SCC
|
||||||
while (!VisitStack.empty()) {
|
while (!VisitStack.empty()) {
|
||||||
DFSVisitChildren();
|
DFSVisitChildren();
|
||||||
assert(VisitStack.back().second ==GT::child_end(VisitStack.back().first));
|
assert(VisitStack.back().second ==
|
||||||
|
GT::child_end(VisitStack.back().first));
|
||||||
NodeType *visitingN = VisitStack.back().first;
|
NodeType *visitingN = VisitStack.back().first;
|
||||||
unsigned minVisitNum = MinVisitNumStack.back();
|
unsigned minVisitNum = MinVisitNumStack.back();
|
||||||
VisitStack.pop_back();
|
VisitStack.pop_back();
|
||||||
@ -139,13 +140,17 @@ class scc_iterator
|
|||||||
DFSVisitOne(entryN);
|
DFSVisitOne(entryN);
|
||||||
GetNextSCC();
|
GetNextSCC();
|
||||||
}
|
}
|
||||||
inline scc_iterator() { /* End is when DFS stack is empty */ }
|
|
||||||
|
// End is when the DFS stack is empty.
|
||||||
|
inline scc_iterator() {}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef scc_iterator<GraphT, GT> _Self;
|
typedef scc_iterator<GraphT, GT> _Self;
|
||||||
|
|
||||||
static inline _Self begin(const GraphT &G){return _Self(GT::getEntryNode(G));}
|
static inline _Self begin(const GraphT &G) {
|
||||||
static inline _Self end (const GraphT &) { return _Self(); }
|
return _Self(GT::getEntryNode(G));
|
||||||
|
}
|
||||||
|
static inline _Self end(const GraphT &) { return _Self(); }
|
||||||
|
|
||||||
/// \brief Direct loop termination test which is more efficient than
|
/// \brief Direct loop termination test which is more efficient than
|
||||||
/// comparison with \c end().
|
/// comparison with \c end().
|
||||||
@ -154,17 +159,19 @@ public:
|
|||||||
return CurrentSCC.empty();
|
return CurrentSCC.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator==(const _Self& x) const {
|
inline bool operator==(const _Self &x) const {
|
||||||
return VisitStack == x.VisitStack && CurrentSCC == x.CurrentSCC;
|
return VisitStack == x.VisitStack && CurrentSCC == x.CurrentSCC;
|
||||||
}
|
}
|
||||||
inline bool operator!=(const _Self& x) const { return !operator==(x); }
|
inline bool operator!=(const _Self &x) const { return !operator==(x); }
|
||||||
|
|
||||||
inline _Self& operator++() {
|
inline _Self &operator++() {
|
||||||
GetNextSCC();
|
GetNextSCC();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
inline _Self operator++(int) {
|
inline _Self operator++(int) {
|
||||||
_Self tmp = *this; ++*this; return tmp;
|
_Self tmp = *this;
|
||||||
|
++*this;
|
||||||
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const SccTy &operator*() const {
|
inline const SccTy &operator*() const {
|
||||||
@ -182,9 +189,11 @@ public:
|
|||||||
/// still contain a loop if the node has an edge back to itself.
|
/// still contain a loop if the node has an edge back to itself.
|
||||||
bool hasLoop() const {
|
bool hasLoop() const {
|
||||||
assert(!CurrentSCC.empty() && "Dereferencing END SCC iterator!");
|
assert(!CurrentSCC.empty() && "Dereferencing END SCC iterator!");
|
||||||
if (CurrentSCC.size() > 1) return true;
|
if (CurrentSCC.size() > 1)
|
||||||
|
return true;
|
||||||
NodeType *N = CurrentSCC.front();
|
NodeType *N = CurrentSCC.front();
|
||||||
for (ChildItTy CI = GT::child_begin(N), CE=GT::child_end(N); CI != CE; ++CI)
|
for (ChildItTy CI = GT::child_begin(N), CE = GT::child_end(N); CI != CE;
|
||||||
|
++CI)
|
||||||
if (*CI == N)
|
if (*CI == N)
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
@ -199,28 +208,23 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// \brief Construct the begin iterator for a deduced graph type T.
|
/// \brief Construct the begin iterator for a deduced graph type T.
|
||||||
template <class T>
|
template <class T> scc_iterator<T> scc_begin(const T &G) {
|
||||||
scc_iterator<T> scc_begin(const T &G) {
|
|
||||||
return scc_iterator<T>::begin(G);
|
return scc_iterator<T>::begin(G);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Construct the end iterator for a deduced graph type T.
|
/// \brief Construct the end iterator for a deduced graph type T.
|
||||||
template <class T>
|
template <class T> scc_iterator<T> scc_end(const T &G) {
|
||||||
scc_iterator<T> scc_end(const T &G) {
|
|
||||||
return scc_iterator<T>::end(G);
|
return scc_iterator<T>::end(G);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Construct the begin iterator for a deduced graph type T's Inverse<T>.
|
/// \brief Construct the begin iterator for a deduced graph type T's Inverse<T>.
|
||||||
template <class T>
|
template <class T> scc_iterator<Inverse<T> > scc_begin(const Inverse<T> &G) {
|
||||||
scc_iterator<Inverse<T> > scc_begin(const Inverse<T> &G) {
|
|
||||||
return scc_iterator<Inverse<T> >::begin(G);
|
return scc_iterator<Inverse<T> >::begin(G);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Construct the end iterator for a deduced graph type T's Inverse<T>.
|
/// \brief Construct the end iterator for a deduced graph type T's Inverse<T>.
|
||||||
template <class T>
|
template <class T> scc_iterator<Inverse<T> > scc_end(const Inverse<T> &G) {
|
||||||
scc_iterator<Inverse<T> > scc_end(const Inverse<T> &G) {
|
|
||||||
return scc_iterator<Inverse<T> >::end(G);
|
return scc_iterator<Inverse<T> >::end(G);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user