diff options
author | Devang Patel <dpatel@apple.com> | 2007-06-12 00:14:41 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2007-06-12 00:14:41 +0000 |
commit | 3726b82a55a1864c2f9af86beaaeb2e1f3fbc99b (patch) | |
tree | 2a8679ad7bfb27b308798cd4d28bfa89d4980def /lib/VMCore | |
parent | fe7d4e50b8a34e660a8713da79613041987c19d6 (diff) | |
download | external_llvm-3726b82a55a1864c2f9af86beaaeb2e1f3fbc99b.zip external_llvm-3726b82a55a1864c2f9af86beaaeb2e1f3fbc99b.tar.gz external_llvm-3726b82a55a1864c2f9af86beaaeb2e1f3fbc99b.tar.bz2 |
Maintain DFS number in DomTreeNode itself.
This means now ETNodes are not useful anymore.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37546 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/Dominators.cpp | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/lib/VMCore/Dominators.cpp b/lib/VMCore/Dominators.cpp index 8b2c1a4..225d8d2 100644 --- a/lib/VMCore/Dominators.cpp +++ b/lib/VMCore/Dominators.cpp @@ -319,9 +319,11 @@ void DominatorTreeBase::updateDFSNumbers() BasicBlock *BB = *I; DomTreeNode *BBNode = getNode(BB); if (BBNode) { - ETNode *ETN = BBNode->getETNode(); - if (ETN && !ETN->hasFather()) - ETN->assignDFSNumber(dfsnum); + if (!BBNode->getIDom()) + BBNode->assignDFSNumber(dfsnum); + //ETNode *ETN = BBNode->getETNode(); + //if (ETN && !ETN->hasFather()) + // ETN->assignDFSNumber(dfsnum); } } SlowQueries = 0; @@ -414,6 +416,38 @@ BasicBlock *DominatorTreeBase::findNearestCommonDominator(BasicBlock *A, BasicBl return NULL; } +/// assignDFSNumber - Assign In and Out numbers while walking dominator tree +/// in dfs order. +void DomTreeNode::assignDFSNumber(int num) { + std::vector<DomTreeNode *> workStack; + std::set<DomTreeNode *> visitedNodes; + + workStack.push_back(this); + visitedNodes.insert(this); + this->DFSNumIn = num++; + + while (!workStack.empty()) { + DomTreeNode *Node = workStack.back(); + + bool visitChild = false; + for (std::vector<DomTreeNode*>::iterator DI = Node->begin(), + E = Node->end(); DI != E && !visitChild; ++DI) { + DomTreeNode *Child = *DI; + if (visitedNodes.count(Child) == 0) { + visitChild = true; + Child->DFSNumIn = num++; + workStack.push_back(Child); + visitedNodes.insert(Child); + } + } + if (!visitChild) { + // If we reach here means all children are visited + Node->DFSNumOut = num++; + workStack.pop_back(); + } + } +} + void DomTreeNode::setIDom(DomTreeNode *NewIDom) { assert(IDom && "No immediate dominator?"); if (IDom != NewIDom) { |