mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-25 06:51:30 +00:00
Use iterative algorith to assign DFS number. This reduces
call stack depth. llvm-svn: 30575
This commit is contained in:
parent
86f1992481
commit
8248ba3afc
@ -250,16 +250,7 @@ public:
|
||||
return this->Below(other);
|
||||
}
|
||||
|
||||
void assignDFSNumber(int &num) {
|
||||
DFSNumIn = num++;
|
||||
|
||||
if (Son) {
|
||||
Son->assignDFSNumber(num);
|
||||
for (ETNode *son = Son->Right; son != Son; son = son->Right)
|
||||
son->assignDFSNumber(num);
|
||||
}
|
||||
DFSNumOut = num++;
|
||||
}
|
||||
void assignDFSNumber (int);
|
||||
|
||||
bool hasFather() const {
|
||||
return Father != NULL;
|
||||
|
@ -809,6 +809,53 @@ ETNode *ETNode::NCA(ETNode *other) {
|
||||
return occmin->OccFor;
|
||||
}
|
||||
|
||||
void ETNode::assignDFSNumber(int num) {
|
||||
std::vector<ETNode *> workStack;
|
||||
std::set<ETNode *> visitedNodes;
|
||||
|
||||
workStack.push_back(this);
|
||||
visitedNodes.insert(this);
|
||||
this->DFSNumIn = num++;
|
||||
|
||||
while (!workStack.empty()) {
|
||||
ETNode *Node = workStack.back();
|
||||
|
||||
// If this is leaf node then set DFSNumOut and pop the stack
|
||||
if (!Node->Son) {
|
||||
Node->DFSNumOut = num++;
|
||||
workStack.pop_back();
|
||||
continue;
|
||||
}
|
||||
|
||||
ETNode *son = Node->Son;
|
||||
|
||||
// Visit Node->Son first
|
||||
if (visitedNodes.count(son) == 0) {
|
||||
son->DFSNumIn = num++;
|
||||
workStack.push_back(son);
|
||||
visitedNodes.insert(son);
|
||||
continue;
|
||||
}
|
||||
|
||||
bool visitChild = false;
|
||||
// Visit remaining children
|
||||
for (ETNode *s = son->Right; s != son && !visitChild; s = s->Right) {
|
||||
if (visitedNodes.count(s) == 0) {
|
||||
visitChild = true;
|
||||
s->DFSNumIn = num++;
|
||||
workStack.push_back(s);
|
||||
visitedNodes.insert(s);
|
||||
}
|
||||
}
|
||||
|
||||
if (!visitChild) {
|
||||
// If we reach here means all children are visited
|
||||
Node->DFSNumOut = num++;
|
||||
workStack.pop_back();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// ETForest implementation
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
Loading…
x
Reference in New Issue
Block a user