-
- 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
-//===----------------------------------------------------------------------===//
-
-char ETForest::ID = 0;
-static RegisterPass<ETForest>
-D("etforest", "ET Forest Construction", true);
-
-void ETForestBase::reset() {
- for (ETMapType::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I)
- delete I->second;
- Nodes.clear();
-}
-
-void ETForestBase::updateDFSNumbers()
-{
- int dfsnum = 0;
- // Iterate over all nodes in depth first order.
- for (unsigned i = 0, e = Roots.size(); i != e; ++i)
- for (df_iterator<BasicBlock*> I = df_begin(Roots[i]),
- E = df_end(Roots[i]); I != E; ++I) {
- BasicBlock *BB = *I;
- ETNode *ETN = getNode(BB);
- if (ETN && !ETN->hasFather())
- ETN->assignDFSNumber(dfsnum);
- }
- SlowQueries = 0;
- DFSInfoValid = true;
-}
-
-// dominates - Return true if A dominates B. THis performs the
-// special checks necessary if A and B are in the same basic block.
-bool ETForestBase::dominates(Instruction *A, Instruction *B) {
- BasicBlock *BBA = A->getParent(), *BBB = B->getParent();
- if (BBA != BBB) return dominates(BBA, BBB);
-
- // It is not possible to determine dominance between two PHI nodes
- // based on their ordering.
- if (isa<PHINode>(A) && isa<PHINode>(B))
- return false;
-
- // Loop through the basic block until we find A or B.
- BasicBlock::iterator I = BBA->begin();
- for (; &*I != A && &*I != B; ++I) /*empty*/;
-
- if(!IsPostDominators) {
- // A dominates B if it is found first in the basic block.
- return &*I == A;
- } else {
- // A post-dominates B if B is found first in the basic block.
- return &*I == B;
- }
-}
-
-/// isReachableFromEntry - Return true if A is dominated by the entry
-/// block of the function containing it.
-const bool ETForestBase::isReachableFromEntry(BasicBlock* A) {
- return dominates(&A->getParent()->getEntryBlock(), A);
-}
-
-// FIXME : There is no need to make getNodeForBlock public. Fix
-// predicate simplifier.
-ETNode *ETForest::getNodeForBlock(BasicBlock *BB) {
- ETNode *&BBNode = Nodes[BB];
- if (BBNode) return BBNode;
-
- // Haven't calculated this node yet? Get or calculate the node for the
- // immediate dominator.
- DomTreeNode *node= getAnalysis<DominatorTree>().getNode(BB);
-
- // If we are unreachable, we may not have an immediate dominator.
- if (!node || !node->getIDom())
- return BBNode = new ETNode(BB);
- else {
- ETNode *IDomNode = getNodeForBlock(node->getIDom()->getBlock());
-
- // Add a new tree node for this BasicBlock, and link it as a child of
- // IDomNode
- BBNode = new ETNode(BB);
- BBNode->setFather(IDomNode);
- return BBNode;