llvm.org GIT mirror llvm / 2d3e1ee
Minor cleanups git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9958 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 16 years ago
2 changed file(s) with 72 addition(s) and 82 deletion(s). Raw diff Collapse all Expand all
7777 // The stack-based DFS traversal; defined below.
7878 void DFSVisitChildren() {
7979 assert(!VisitStack.empty());
80 while (VisitStack.back().second != GT::child_end(VisitStack.back().first))
81 { // TOS has at least one more child so continue DFS
82 NodeType *childN = *VisitStack.back().second++;
83 if (nodeVisitNumbers.find(childN) == nodeVisitNumbers.end())
84 { // this node has never been seen
85 DFSVisitOne(childN);
86 }
87 else
88 {
89 unsigned childNum = nodeVisitNumbers[childN];
90 if (MinVisitNumStack.back() > childNum)
91 MinVisitNumStack.back() = childNum;
92 }
80 while (VisitStack.back().second != GT::child_end(VisitStack.back().first)) {
81 // TOS has at least one more child so continue DFS
82 NodeType *childN = *VisitStack.back().second++;
83 if (!nodeVisitNumbers.count(childN)) {
84 // this node has never been seen
85 DFSVisitOne(childN);
86 } else {
87 unsigned childNum = nodeVisitNumbers[childN];
88 if (MinVisitNumStack.back() > childNum)
89 MinVisitNumStack.back() = childNum;
9390 }
91 }
9492 }
9593
9694 // Compute the next SCC using the DFS traversal.
9795 void GetNextSCC() {
9896 assert(VisitStack.size() == MinVisitNumStack.size());
9997 CurrentSCC.clear(); // Prepare to compute the next SCC
100 while (! VisitStack.empty())
101 {
102 DFSVisitChildren();
98 while (!VisitStack.empty()) {
99 DFSVisitChildren();
100 assert(VisitStack.back().second ==GT::child_end(VisitStack.back().first));
101 NodeType* visitingN = VisitStack.back().first;
102 unsigned minVisitNum = MinVisitNumStack.back();
103 VisitStack.pop_back();
104 MinVisitNumStack.pop_back();
105 if (!MinVisitNumStack.empty() && MinVisitNumStack.back() > minVisitNum)
106 MinVisitNumStack.back() = minVisitNum;
103107
104 assert(VisitStack.back().second ==
105 GT::child_end(VisitStack.back().first));
106 NodeType* visitingN = VisitStack.back().first;
107 unsigned minVisitNum = MinVisitNumStack.back();
108 VisitStack.pop_back();
109 MinVisitNumStack.pop_back();
110 if (! MinVisitNumStack.empty() && MinVisitNumStack.back() > minVisitNum)
111 MinVisitNumStack.back() = minVisitNum;
108 //DEBUG(std::cerr << "TarjanSCC: Popped node " << visitingN <<
109 // " : minVisitNum = " << minVisitNum << "; Node visit num = " <<
110 // nodeVisitNumbers[visitingN] << "\n");
112111
113 //DEBUG(std::cerr << "TarjanSCC: Popped node " << visitingN <<
114 // " : minVisitNum = " << minVisitNum << "; Node visit num = " <<
115 // nodeVisitNumbers[visitingN] << "\n");
116
117 if (minVisitNum == nodeVisitNumbers[visitingN])
118 { // A full SCC is on the SCCNodeStack! It includes all nodes below
119 // visitingN on the stack. Copy those nodes to CurrentSCC,
120 // reset their minVisit values, and return (this suspends
121 // the DFS traversal till the next ++).
122 do {
123 CurrentSCC.push_back(SCCNodeStack.back());
124 SCCNodeStack.pop_back();
125 nodeVisitNumbers[CurrentSCC.back()] = ~0UL;
126 } while (CurrentSCC.back() != visitingN);
127 return;
128 }
129 }
112 if (minVisitNum == nodeVisitNumbers[visitingN]) {
113 // A full SCC is on the SCCNodeStack! It includes all nodes below
114 // visitingN on the stack. Copy those nodes to CurrentSCC,
115 // reset their minVisit values, and return (this suspends
116 // the DFS traversal till the next ++).
117 do {
118 CurrentSCC.push_back(SCCNodeStack.back());
119 SCCNodeStack.pop_back();
120 nodeVisitNumbers[CurrentSCC.back()] = ~0UL;
121 } while (CurrentSCC.back() != visitingN);
122 return;
123 }
124 }
130125 }
131126
132127 inline scc_iterator(NodeType *entryN) : visitNum(0) {
7777 // The stack-based DFS traversal; defined below.
7878 void DFSVisitChildren() {
7979 assert(!VisitStack.empty());
80 while (VisitStack.back().second != GT::child_end(VisitStack.back().first))
81 { // TOS has at least one more child so continue DFS
82 NodeType *childN = *VisitStack.back().second++;
83 if (nodeVisitNumbers.find(childN) == nodeVisitNumbers.end())
84 { // this node has never been seen
85 DFSVisitOne(childN);
86 }
87 else
88 {
89 unsigned childNum = nodeVisitNumbers[childN];
90 if (MinVisitNumStack.back() > childNum)
91 MinVisitNumStack.back() = childNum;
92 }
80 while (VisitStack.back().second != GT::child_end(VisitStack.back().first)) {
81 // TOS has at least one more child so continue DFS
82 NodeType *childN = *VisitStack.back().second++;
83 if (!nodeVisitNumbers.count(childN)) {
84 // this node has never been seen
85 DFSVisitOne(childN);
86 } else {
87 unsigned childNum = nodeVisitNumbers[childN];
88 if (MinVisitNumStack.back() > childNum)
89 MinVisitNumStack.back() = childNum;
9390 }
91 }
9492 }
9593
9694 // Compute the next SCC using the DFS traversal.
9795 void GetNextSCC() {
9896 assert(VisitStack.size() == MinVisitNumStack.size());
9997 CurrentSCC.clear(); // Prepare to compute the next SCC
100 while (! VisitStack.empty())
101 {
102 DFSVisitChildren();
98 while (!VisitStack.empty()) {
99 DFSVisitChildren();
100 assert(VisitStack.back().second ==GT::child_end(VisitStack.back().first));
101 NodeType* visitingN = VisitStack.back().first;
102 unsigned minVisitNum = MinVisitNumStack.back();
103 VisitStack.pop_back();
104 MinVisitNumStack.pop_back();
105 if (!MinVisitNumStack.empty() && MinVisitNumStack.back() > minVisitNum)
106 MinVisitNumStack.back() = minVisitNum;
103107
104 assert(VisitStack.back().second ==
105 GT::child_end(VisitStack.back().first));
106 NodeType* visitingN = VisitStack.back().first;
107 unsigned minVisitNum = MinVisitNumStack.back();
108 VisitStack.pop_back();
109 MinVisitNumStack.pop_back();
110 if (! MinVisitNumStack.empty() && MinVisitNumStack.back() > minVisitNum)
111 MinVisitNumStack.back() = minVisitNum;
108 //DEBUG(std::cerr << "TarjanSCC: Popped node " << visitingN <<
109 // " : minVisitNum = " << minVisitNum << "; Node visit num = " <<
110 // nodeVisitNumbers[visitingN] << "\n");
112111
113 //DEBUG(std::cerr << "TarjanSCC: Popped node " << visitingN <<
114 // " : minVisitNum = " << minVisitNum << "; Node visit num = " <<
115 // nodeVisitNumbers[visitingN] << "\n");
116
117 if (minVisitNum == nodeVisitNumbers[visitingN])
118 { // A full SCC is on the SCCNodeStack! It includes all nodes below
119 // visitingN on the stack. Copy those nodes to CurrentSCC,
120 // reset their minVisit values, and return (this suspends
121 // the DFS traversal till the next ++).
122 do {
123 CurrentSCC.push_back(SCCNodeStack.back());
124 SCCNodeStack.pop_back();
125 nodeVisitNumbers[CurrentSCC.back()] = ~0UL;
126 } while (CurrentSCC.back() != visitingN);
127 return;
128 }
129 }
112 if (minVisitNum == nodeVisitNumbers[visitingN]) {
113 // A full SCC is on the SCCNodeStack! It includes all nodes below
114 // visitingN on the stack. Copy those nodes to CurrentSCC,
115 // reset their minVisit values, and return (this suspends
116 // the DFS traversal till the next ++).
117 do {
118 CurrentSCC.push_back(SCCNodeStack.back());
119 SCCNodeStack.pop_back();
120 nodeVisitNumbers[CurrentSCC.back()] = ~0UL;
121 } while (CurrentSCC.back() != visitingN);
122 return;
123 }
124 }
130125 }
131126
132127 inline scc_iterator(NodeType *entryN) : visitNum(0) {