llvm.org GIT mirror llvm / 2bd48f0
[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 Chandler Carruth 6 years ago
1 changed file(s) with 30 addition(s) and 26 deletion(s). Raw diff Collapse all Expand all
3434 /// This is implemented using Tarjan's DFS algorithm using an internal stack to
3535 /// build up a vector of nodes in a particular SCC. Note that it is a forward
3636 /// iterator and thus you cannot backtrack or re-visit nodes.
37 template >
37 template >
3838 class scc_iterator
39 : public std::iterator
40 std::vector, ptrdiff_t> {
41 typedef typename GT::NodeType NodeType;
39 : public std::iterator
40 std::vector, ptrdiff_t> {
41 typedef typename GT::NodeType NodeType;
4242 typedef typename GT::ChildIteratorType ChildItTy;
43 typedef std::vector*> SccTy;
43 typedef std::vector *> SccTy;
4444 typedef std::iterator
4545 std::vector, ptrdiff_t> super;
4646 typedef typename super::reference reference;
101101 // Compute the next SCC using the DFS traversal.
102102 void GetNextSCC() {
103103 assert(VisitStack.size() == MinVisitNumStack.size());
104 CurrentSCC.clear(); // Prepare to compute the next SCC
104 CurrentSCC.clear(); // Prepare to compute the next SCC
105105 while (!VisitStack.empty()) {
106106 DFSVisitChildren();
107 assert(VisitStack.back().second ==GT::child_end(VisitStack.back().first));
107 assert(VisitStack.back().second ==
108 GT::child_end(VisitStack.back().first));
108109 NodeType *visitingN = VisitStack.back().first;
109110 unsigned minVisitNum = MinVisitNumStack.back();
110111 VisitStack.pop_back();
138139 DFSVisitOne(entryN);
139140 GetNextSCC();
140141 }
141 inline scc_iterator() { /* End is when DFS stack is empty */ }
142
143 // End is when the DFS stack is empty.
144 inline scc_iterator() {}
142145
143146 public:
144147 typedef scc_iterator _Self;
145148
146 static inline _Self begin(const GraphT &G){return _Self(GT::getEntryNode(G));}
147 static inline _Self end (const GraphT &) { return _Self(); }
149 static inline _Self begin(const GraphT &G) {
150 return _Self(GT::getEntryNode(G));
151 }
152 static inline _Self end(const GraphT &) { return _Self(); }
148153
149154 /// \brief Direct loop termination test which is more efficient than
150155 /// comparison with \c end().
153158 return CurrentSCC.empty();
154159 }
155160
156 inline bool operator==(const _Self& x) const {
161 inline bool operator==(const _Self &x) const {
157162 return VisitStack == x.VisitStack && CurrentSCC == x.CurrentSCC;
158163 }
159 inline bool operator!=(const _Self& x) const { return !operator==(x); }
160
161 inline _Self& operator++() {
164 inline bool operator!=(const _Self &x) const { return !operator==(x); }
165
166 inline _Self &operator++() {
162167 GetNextSCC();
163168 return *this;
164169 }
165170 inline _Self operator++(int) {
166 _Self tmp = *this; ++*this; return tmp;
171 _Self tmp = *this;
172 ++*this;
173 return tmp;
167174 }
168175
169176 inline const SccTy &operator*() const {
181188 /// still contain a loop if the node has an edge back to itself.
182189 bool hasLoop() const {
183190 assert(!CurrentSCC.empty() && "Dereferencing END SCC iterator!");
184 if (CurrentSCC.size() > 1) return true;
191 if (CurrentSCC.size() > 1)
192 return true;
185193 NodeType *N = CurrentSCC.front();
186 for (ChildItTy CI = GT::child_begin(N), CE=GT::child_end(N); CI != CE; ++CI)
194 for (ChildItTy CI = GT::child_begin(N), CE = GT::child_end(N); CI != CE;
195 ++CI)
187196 if (*CI == N)
188197 return true;
189198 return false;
198207 }
199208 };
200209
201
202210 /// \brief Construct the begin iterator for a deduced graph type T.
203 template
204 scc_iterator scc_begin(const T &G) {
211 template scc_iterator scc_begin(const T &G) {
205212 return scc_iterator::begin(G);
206213 }
207214
208215 /// \brief Construct the end iterator for a deduced graph type T.
209 template
210 scc_iterator scc_end(const T &G) {
216 template scc_iterator scc_end(const T &G) {
211217 return scc_iterator::end(G);
212218 }
213219
214220 /// \brief Construct the begin iterator for a deduced graph type T's Inverse.
215 template
216 scc_iterator > scc_begin(const Inverse &G) {
221 template scc_iterator > scc_begin(const Inverse &G) {
217222 return scc_iterator >::begin(G);
218223 }
219224
220225 /// \brief Construct the end iterator for a deduced graph type T's Inverse.
221 template
222 scc_iterator > scc_end(const Inverse &G) {
226 template scc_iterator > scc_end(const Inverse &G) {
223227 return scc_iterator >::end(G);
224228 }
225229