summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2006-09-22 01:05:33 +0000
committerDevang Patel <dpatel@apple.com>2006-09-22 01:05:33 +0000
commit0c4e730c9cc800fc96a4a9555e847c630fc18e28 (patch)
tree74fb30616fef1ad1242e5c01ec3d25797025c4cf /llvm
parent7d3fd4f888eccb65dd260e7840ce85d78ebf9370 (diff)
downloadbcm5719-llvm-0c4e730c9cc800fc96a4a9555e847c630fc18e28.tar.gz
bcm5719-llvm-0c4e730c9cc800fc96a4a9555e847c630fc18e28.zip
Use iterative algorith to assign DFS number. This reduces
call stack depth. llvm-svn: 30575
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/Analysis/ET-Forest.h11
-rw-r--r--llvm/lib/VMCore/Dominators.cpp47
2 files changed, 48 insertions, 10 deletions
diff --git a/llvm/include/llvm/Analysis/ET-Forest.h b/llvm/include/llvm/Analysis/ET-Forest.h
index b05776a9e0f..be9df98e26b 100644
--- a/llvm/include/llvm/Analysis/ET-Forest.h
+++ b/llvm/include/llvm/Analysis/ET-Forest.h
@@ -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;
diff --git a/llvm/lib/VMCore/Dominators.cpp b/llvm/lib/VMCore/Dominators.cpp
index 9f7e5d9365d..940653d1ec2 100644
--- a/llvm/lib/VMCore/Dominators.cpp
+++ b/llvm/lib/VMCore/Dominators.cpp
@@ -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
//===----------------------------------------------------------------------===//
OpenPOWER on IntegriCloud