llvm.org GIT mirror llvm / 22ab2a1
Remove usage of unsigned long: unsigned should be enough! Remove explicit use of a stack<>, use a vector instead git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8246 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 16 years ago
2 changed file(s) with 46 addition(s) and 46 deletion(s). Raw diff Collapse all Expand all
1818 #include "Support/Debug.h"
1919 #include "Support/iterator"
2020 #include
21 #include
2221 #include
2322
2423 //--------------------------------------------------------------------------
6867 // The visit counters used to detect when a complete SCC is on the stack.
6968 // visitNum is the global counter.
7069 // nodeVisitNumbers are per-node visit numbers, also used as DFS flags.
71 unsigned long visitNum;
72 std::map nodeVisitNumbers;
70 unsigned visitNum;
71 std::map nodeVisitNumbers;
7372
7473 // SCCNodeStack - Stack holding nodes of the SCC.
75 std::stack SCCNodeStack;
74 std::vector SCCNodeStack;
7675
7776 // CurrentSCC - The current SCC, retrieved using operator*().
7877 SccTy CurrentSCC;
7978
8079 // VisitStack - Used to maintain the ordering. Top = current block
8180 // First element is basic block pointer, second is the 'next child' to visit
82 std::stack > VisitStack;
81 std::vector > VisitStack;
8382
8483 // MinVistNumStack - Stack holding the "min" values for each node in the DFS.
8584 // This is used to track the minimum uplink values for all children of
8685 // the corresponding node on the VisitStack.
87 std::stack> MinVisitNumStack;
86 std::vector> MinVisitNumStack;
8887
8988 // A single "visit" within the non-recursive DFS traversal.
9089 void DFSVisitOne(NodeType* N) {
9190 ++visitNum; // Global counter for the visit order
9291 nodeVisitNumbers[N] = visitNum;
93 SCCNodeStack.push(N);
94 MinVisitNumStack.push(visitNum);
95 VisitStack.push(make_pair(N, GT::child_begin(N)));
92 SCCNodeStack.push_back(N);
93 MinVisitNumStack.push_back(visitNum);
94 VisitStack.push_back(make_pair(N, GT::child_begin(N)));
9695 //DEBUG(std::cerr << "TarjanSCC: Node " << N <<
9796 // " : visitNum = " << visitNum << "\n");
9897 }
10099 // The stack-based DFS traversal; defined below.
101100 void DFSVisitChildren() {
102101 assert(!VisitStack.empty());
103 while (VisitStack.top().second != GT::child_end(VisitStack.top().first))
102 while (VisitStack.back().second != GT::child_end(VisitStack.back().first))
104103 { // TOS has at least one more child so continue DFS
105 NodeType *childN = *VisitStack.top().second++;
104 NodeType *childN = *VisitStack.back().second++;
106105 if (nodeVisitNumbers.find(childN) == nodeVisitNumbers.end())
107106 { // this node has never been seen
108107 DFSVisitOne(childN);
109108 }
110109 else
111110 {
112 unsigned long childNum = nodeVisitNumbers[childN];
113 if (MinVisitNumStack.top() > childNum)
114 MinVisitNumStack.top() = childNum;
111 unsigned childNum = nodeVisitNumbers[childN];
112 if (MinVisitNumStack.back() > childNum)
113 MinVisitNumStack.back() = childNum;
115114 }
116115 }
117116 }
124123 {
125124 DFSVisitChildren();
126125
127 assert(VisitStack.top().second==GT::child_end(VisitStack.top().first));
128 NodeType* visitingN = VisitStack.top().first;
129 unsigned long minVisitNum = MinVisitNumStack.top();
130 VisitStack.pop();
131 MinVisitNumStack.pop();
132 if (! MinVisitNumStack.empty() && MinVisitNumStack.top() > minVisitNum)
133 MinVisitNumStack.top() = minVisitNum;
126 assert(VisitStack.back().second ==
127 GT::child_end(VisitStack.back().first));
128 NodeType* visitingN = VisitStack.back().first;
129 unsigned minVisitNum = MinVisitNumStack.back();
130 VisitStack.pop_back();
131 MinVisitNumStack.pop_back();
132 if (! MinVisitNumStack.empty() && MinVisitNumStack.back() > minVisitNum)
133 MinVisitNumStack.back() = minVisitNum;
134134
135135 //DEBUG(std::cerr << "TarjanSCC: Popped node " << visitingN <<
136136 // " : minVisitNum = " << minVisitNum << "; Node visit num = " <<
142142 // reset their minVisit values, and return (this suspends
143143 // the DFS traversal till the next ++).
144144 do {
145 CurrentSCC.push_back(SCCNodeStack.top());
146 SCCNodeStack.pop();
145 CurrentSCC.push_back(SCCNodeStack.back());
146 SCCNodeStack.pop_back();
147147 nodeVisitNumbers[CurrentSCC.back()] = ~0UL;
148148 } while (CurrentSCC.back() != visitingN);
149149 return;
1818 #include "Support/Debug.h"
1919 #include "Support/iterator"
2020 #include
21 #include
2221 #include
2322
2423 //--------------------------------------------------------------------------
6867 // The visit counters used to detect when a complete SCC is on the stack.
6968 // visitNum is the global counter.
7069 // nodeVisitNumbers are per-node visit numbers, also used as DFS flags.
71 unsigned long visitNum;
72 std::map nodeVisitNumbers;
70 unsigned visitNum;
71 std::map nodeVisitNumbers;
7372
7473 // SCCNodeStack - Stack holding nodes of the SCC.
75 std::stack SCCNodeStack;
74 std::vector SCCNodeStack;
7675
7776 // CurrentSCC - The current SCC, retrieved using operator*().
7877 SccTy CurrentSCC;
7978
8079 // VisitStack - Used to maintain the ordering. Top = current block
8180 // First element is basic block pointer, second is the 'next child' to visit
82 std::stack > VisitStack;
81 std::vector > VisitStack;
8382
8483 // MinVistNumStack - Stack holding the "min" values for each node in the DFS.
8584 // This is used to track the minimum uplink values for all children of
8685 // the corresponding node on the VisitStack.
87 std::stack> MinVisitNumStack;
86 std::vector> MinVisitNumStack;
8887
8988 // A single "visit" within the non-recursive DFS traversal.
9089 void DFSVisitOne(NodeType* N) {
9190 ++visitNum; // Global counter for the visit order
9291 nodeVisitNumbers[N] = visitNum;
93 SCCNodeStack.push(N);
94 MinVisitNumStack.push(visitNum);
95 VisitStack.push(make_pair(N, GT::child_begin(N)));
92 SCCNodeStack.push_back(N);
93 MinVisitNumStack.push_back(visitNum);
94 VisitStack.push_back(make_pair(N, GT::child_begin(N)));
9695 //DEBUG(std::cerr << "TarjanSCC: Node " << N <<
9796 // " : visitNum = " << visitNum << "\n");
9897 }
10099 // The stack-based DFS traversal; defined below.
101100 void DFSVisitChildren() {
102101 assert(!VisitStack.empty());
103 while (VisitStack.top().second != GT::child_end(VisitStack.top().first))
102 while (VisitStack.back().second != GT::child_end(VisitStack.back().first))
104103 { // TOS has at least one more child so continue DFS
105 NodeType *childN = *VisitStack.top().second++;
104 NodeType *childN = *VisitStack.back().second++;
106105 if (nodeVisitNumbers.find(childN) == nodeVisitNumbers.end())
107106 { // this node has never been seen
108107 DFSVisitOne(childN);
109108 }
110109 else
111110 {
112 unsigned long childNum = nodeVisitNumbers[childN];
113 if (MinVisitNumStack.top() > childNum)
114 MinVisitNumStack.top() = childNum;
111 unsigned childNum = nodeVisitNumbers[childN];
112 if (MinVisitNumStack.back() > childNum)
113 MinVisitNumStack.back() = childNum;
115114 }
116115 }
117116 }
124123 {
125124 DFSVisitChildren();
126125
127 assert(VisitStack.top().second==GT::child_end(VisitStack.top().first));
128 NodeType* visitingN = VisitStack.top().first;
129 unsigned long minVisitNum = MinVisitNumStack.top();
130 VisitStack.pop();
131 MinVisitNumStack.pop();
132 if (! MinVisitNumStack.empty() && MinVisitNumStack.top() > minVisitNum)
133 MinVisitNumStack.top() = minVisitNum;
126 assert(VisitStack.back().second ==
127 GT::child_end(VisitStack.back().first));
128 NodeType* visitingN = VisitStack.back().first;
129 unsigned minVisitNum = MinVisitNumStack.back();
130 VisitStack.pop_back();
131 MinVisitNumStack.pop_back();
132 if (! MinVisitNumStack.empty() && MinVisitNumStack.back() > minVisitNum)
133 MinVisitNumStack.back() = minVisitNum;
134134
135135 //DEBUG(std::cerr << "TarjanSCC: Popped node " << visitingN <<
136136 // " : minVisitNum = " << minVisitNum << "; Node visit num = " <<
142142 // reset their minVisit values, and return (this suspends
143143 // the DFS traversal till the next ++).
144144 do {
145 CurrentSCC.push_back(SCCNodeStack.top());
146 SCCNodeStack.pop();
145 CurrentSCC.push_back(SCCNodeStack.back());
146 SCCNodeStack.pop_back();
147147 nodeVisitNumbers[CurrentSCC.back()] = ~0UL;
148148 } while (CurrentSCC.back() != visitingN);
149149 return;