22 #ifndef LLVM_ADT_SCCITERATOR_H 23 #define LLVM_ADT_SCCITERATOR_H 41 template <
class GraphT,
class GT = GraphTraits<GraphT>>
43 scc_iterator<GraphT, GT>, std::forward_iterator_tag,
44 const std::vector<typename GT::NodeRef>, ptrdiff_t> {
45 using NodeRef =
typename GT::NodeRef;
46 using ChildItTy =
typename GT::ChildIteratorType;
47 using SccTy = std::vector<NodeRef>;
48 using reference =
typename scc_iterator::reference;
56 StackElement(NodeRef Node,
const ChildItTy &Child,
unsigned Min)
57 : Node(Node), NextChild(Child), MinVisited(Min) {}
60 return Node == Other.Node &&
61 NextChild == Other.NextChild &&
62 MinVisited == Other.MinVisited;
74 std::vector<NodeRef> SCCNodeStack;
81 std::vector<StackElement> VisitStack;
84 void DFSVisitOne(NodeRef
N);
87 void DFSVisitChildren();
109 assert(!CurrentSCC.empty() || VisitStack.empty());
110 return CurrentSCC.empty();
114 return VisitStack == x.VisitStack && CurrentSCC == x.CurrentSCC;
123 assert(!CurrentSCC.empty() &&
"Dereferencing END SCC iterator!");
136 assert(nodeVisitNumbers.
count(Old) &&
"Old not in scc_iterator?");
139 auto tempVal = nodeVisitNumbers[Old];
140 nodeVisitNumbers[New] = tempVal;
141 nodeVisitNumbers.
erase(Old);
145 template <
class GraphT,
class GT>
148 nodeVisitNumbers[
N] = visitNum;
149 SCCNodeStack.push_back(N);
150 VisitStack.push_back(StackElement(N, GT::child_begin(N), visitNum));
151 #if 0 // Enable if needed when debugging. 152 dbgs() <<
"TarjanSCC: Node " << N <<
153 " : visitNum = " << visitNum <<
"\n";
157 template <
class GraphT,
class GT>
159 assert(!VisitStack.empty());
160 while (VisitStack.back().NextChild != GT::child_end(VisitStack.back().Node)) {
162 NodeRef childN = *VisitStack.back().NextChild++;
164 nodeVisitNumbers.
find(childN);
165 if (Visited == nodeVisitNumbers.
end()) {
171 unsigned childNum = Visited->second;
172 if (VisitStack.back().MinVisited > childNum)
173 VisitStack.back().MinVisited = childNum;
179 while (!VisitStack.empty()) {
183 NodeRef visitingN = VisitStack.back().Node;
184 unsigned minVisitNum = VisitStack.back().MinVisited;
185 assert(VisitStack.back().NextChild == GT::child_end(visitingN));
186 VisitStack.pop_back();
189 if (!VisitStack.empty() && VisitStack.back().MinVisited > minVisitNum)
190 VisitStack.back().MinVisited = minVisitNum;
192 #if 0 // Enable if needed when debugging. 193 dbgs() <<
"TarjanSCC: Popped node " << visitingN <<
194 " : minVisitNum = " << minVisitNum <<
"; Node visit num = " <<
195 nodeVisitNumbers[visitingN] <<
"\n";
198 if (minVisitNum != nodeVisitNumbers[visitingN])
206 CurrentSCC.push_back(SCCNodeStack.back());
207 SCCNodeStack.pop_back();
208 nodeVisitNumbers[CurrentSCC.back()] = ~0U;
209 }
while (CurrentSCC.back() != visitingN);
214 template <
class GraphT,
class GT>
216 assert(!CurrentSCC.empty() &&
"Dereferencing END SCC iterator!");
217 if (CurrentSCC.size() > 1)
219 NodeRef N = CurrentSCC.front();
220 for (ChildItTy CI = GT::child_begin(N), CE = GT::child_end(N); CI != CE;
239 #endif // LLVM_ADT_SCCITERATOR_H This class represents lattice values for constants.
void ReplaceNode(NodeRef Old, NodeRef New)
This informs the scc_iterator that the specified Old node has been deleted, and New is to be used in ...
scc_iterator & operator++()
scc_iterator< T > scc_begin(const T &G)
Construct the begin iterator for a deduced graph type T.
bool isAtEnd() const
Direct loop termination test which is more efficient than comparison with end().
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
reference operator*() const
iterator find(const_arg_type_t< KeyT > Val)
bool erase(const KeyT &Val)
scc_iterator< T > scc_end(const T &G)
Construct the end iterator for a deduced graph type T.
bool operator==(const scc_iterator &x) const
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static scc_iterator end(const GraphT &)
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool hasLoop() const
Test if the current SCC has a loop.
static scc_iterator begin(const GraphT &G)
Enumerate the SCCs of a directed graph in reverse topological order of the SCC DAG.