class DomTreeNode {
BasicBlock *TheBB;
DomTreeNode *IDom;
- ETNode *ETN;
std::vector<DomTreeNode*> Children;
int DFSNumIn, DFSNumOut;
inline BasicBlock *getBlock() const { return TheBB; }
inline DomTreeNode *getIDom() const { return IDom; }
- inline ETNode *getETNode() const { return ETN; }
inline const std::vector<DomTreeNode*> &getChildren() const { return Children; }
- inline DomTreeNode(BasicBlock *BB, DomTreeNode *iDom, ETNode *E)
- : TheBB(BB), IDom(iDom), ETN(E), DFSNumIn(-1), DFSNumOut(-1) {
- if (IDom)
- ETN->setFather(IDom->getETNode());
- }
+ inline DomTreeNode(BasicBlock *BB, DomTreeNode *iDom)
+ : TheBB(BB), IDom(iDom), DFSNumIn(-1), DFSNumOut(-1) { }
inline DomTreeNode *addChild(DomTreeNode *C) { Children.push_back(C); return C; }
void setIDom(DomTreeNode *NewIDom);
DomTreeNodeMapType DomTreeNodes;
DomTreeNode *RootNode;
- typedef std::map<BasicBlock*, ETNode*> ETMapType;
- ETMapType ETNodes;
-
bool DFSInfoValid;
unsigned int SlowQueries;
// Information record used during immediate dominators computation.
void updateDFSNumbers();
- /// Return the nearest common dominator of A and B.
- BasicBlock *nearestCommonDominator(BasicBlock *A, BasicBlock *B) const {
- ETNode *NodeA = getNode(A)->getETNode();
- ETNode *NodeB = getNode(B)->getETNode();
-
- ETNode *Common = NodeA->NCA(NodeB);
- if (!Common)
- return NULL;
- return Common->getData<BasicBlock>();
- }
-
/// isReachableFromEntry - Return true if A is dominated by the entry
/// block of the function containing it.
const bool isReachableFromEntry(BasicBlock* A);
if (A == 0 || B == 0)
return false;
- ETNode *NodeA = A->getETNode();
- ETNode *NodeB = B->getETNode();
-
if (DFSInfoValid)
return B->DominatedBy(A);
- //return NodeB->DominatedBy(NodeA);
// If we end up with too many slow queries, just update the
// DFS numbers on the theory that we are going to keep querying.
if (SlowQueries > 32) {
updateDFSNumbers();
return B->DominatedBy(A);
- //return NodeB->DominatedBy(NodeA);
}
- //return NodeB->DominatedBySlow(NodeA);
+
return dominatedBySlowTreeWalk(A, B);
}
DomTreeNode *IDomNode = getNode(DomBB);
assert(IDomNode && "Not immediate dominator specified for block!");
DFSInfoValid = false;
- ETNode *E = new ETNode(BB);
- ETNodes[BB] = E;
return DomTreeNodes[BB] =
- IDomNode->addChild(new DomTreeNode(BB, IDomNode, E));
+ IDomNode->addChild(new DomTreeNode(BB, IDomNode));
}
/// changeImmediateDominator - This method is used to update the dominator
};
-/// PostETForest Class - Concrete subclass of ETForestBase that is used to
-/// compute a forwards post-dominator ET-Forest.
-struct PostETForest : public ETForestBase {
- static char ID;
- PostETForest() : ETForestBase((intptr_t)&ID, true) {}
-
- virtual void getAnalysisUsage(AnalysisUsage &AU) const {
- AU.setPreservesAll();
- AU.addRequired<PostDominatorTree>();
- }
-
- virtual bool runOnFunction(Function &F) {
- reset(); // Reset from the last time we were run...
- PostDominatorTree &DT = getAnalysis<PostDominatorTree>();
- Roots = DT.getRoots();
- calculate(DT);
- return false;
- }
-
- void calculate(const PostDominatorTree &DT);
- ETNode *getNodeForBlock(BasicBlock *BB);
-};
-
-
/// PostDominanceFrontier Class - Concrete subclass of DominanceFrontier that is
/// used to compute the a post-dominance frontier.
///
char PostDominatorTree::ID = 0;
char PostDominanceFrontier::ID = 0;
-char PostETForest::ID = 0;
static RegisterPass<PostDominatorTree>
F("postdomtree", "Post-Dominator Tree Construction", true);
// one exit block, or it may be the virtual exit (denoted by (BasicBlock *)0)
// which postdominates all real exits if there are multiple exit blocks.
BasicBlock *Root = Roots.size() == 1 ? Roots[0] : 0;
- ETNode *ERoot = new ETNode(Root);
- ETNodes[Root] = ERoot;
- DomTreeNodes[Root] = RootNode = new DomTreeNode(Root, 0, ERoot);
+ DomTreeNodes[Root] = RootNode = new DomTreeNode(Root, 0);
// Loop over all of the reachable blocks in the function...
for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
// Add a new tree node for this BasicBlock, and link it as a child of
// IDomNode
- ETNode *ET = new ETNode(I);
- ETNodes[I] = ET;
- DomTreeNode *C = new DomTreeNode(I, IPDomNode, ET);
+ DomTreeNode *C = new DomTreeNode(I, IPDomNode);
DomTreeNodes[I] = C;
BBNode = IPDomNode->addChild(C);
}
for (unsigned i = 0, e = Roots.size(); i != e; ++i)
for (idf_iterator<BasicBlock*> I = idf_begin(Roots[i]),
E = idf_end(Roots[i]); I != E; ++I) {
- if (!getNodeForBlock(*I)->getETNode()->hasFather())
- getNodeForBlock(*I)->getETNode()->assignDFSNumber(dfsnum);
+ if (!getNodeForBlock(*I)->getIDom())
+ getNodeForBlock(*I)->assignDFSNumber(dfsnum);
}
DFSInfoValid = true;
}
// Add a new tree node for this BasicBlock, and link it as a child of
// IDomNode
- ETNode *ET = new ETNode(BB);
- ETNodes[BB] = ET;
- DomTreeNode *C = new DomTreeNode(BB, IPDomNode, ET);
+ DomTreeNode *C = new DomTreeNode(BB, IPDomNode);
DomTreeNodes[BB] = C;
return BBNode = IPDomNode->addChild(C);
}
-//===----------------------------------------------------------------------===//
-// PostETForest Implementation
-//===----------------------------------------------------------------------===//
-
-static RegisterPass<PostETForest>
-G("postetforest", "Post-ET-Forest Construction", true);
-
-ETNode *PostETForest::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<PostDominatorTree>().getNode(BB);
-
- // If we are unreachable, we may not have an immediate dominator.
- if (!node)
- return 0;
- else if (!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;
- }
-}
-
-void PostETForest::calculate(const PostDominatorTree &DT) {
- for (unsigned i = 0, e = Roots.size(); i != e; ++i)
- Nodes[Roots[i]] = new ETNode(Roots[i]); // Add a node for the root
-
- // Iterate over all nodes in inverse depth first order.
- for (unsigned i = 0, e = Roots.size(); i != e; ++i)
- for (idf_iterator<BasicBlock*> I = idf_begin(Roots[i]),
- E = idf_end(Roots[i]); I != E; ++I) {
- BasicBlock *BB = *I;
- ETNode *&BBNode = Nodes[BB];
- if (!BBNode) {
- ETNode *IDomNode = NULL;
- DomTreeNode *node = DT.getNode(BB);
- if (node && node->getIDom())
- IDomNode = getNodeForBlock(node->getIDom()->getBlock());
-
- // Add a new ETNode for this BasicBlock, and set it's parent
- // to it's immediate dominator.
- BBNode = new ETNode(BB);
- if (IDomNode)
- BBNode->setFather(IDomNode);
- }
- }
-
- int dfsnum = 0;
- // Iterate over all nodes in depth first order...
- for (unsigned i = 0, e = Roots.size(); i != e; ++i)
- for (idf_iterator<BasicBlock*> I = idf_begin(Roots[i]),
- E = idf_end(Roots[i]); I != E; ++I) {
- if (!getNodeForBlock(*I)->hasFather())
- getNodeForBlock(*I)->assignDFSNumber(dfsnum);
- }
- DFSInfoValid = true;
-}
-
//===----------------------------------------------------------------------===//
// PostDominanceFrontier Implementation
//===----------------------------------------------------------------------===//
BasicBlock* Root = Roots[0];
// Add a node for the root...
- ETNode *ERoot = new ETNode(Root);
- ETNodes[Root] = ERoot;
- DomTreeNodes[Root] = RootNode = new DomTreeNode(Root, 0, ERoot);
+ DomTreeNodes[Root] = RootNode = new DomTreeNode(Root, 0);
Vertex.push_back(0);
// Add a new tree node for this BasicBlock, and link it as a child of
// IDomNode
- ETNode *ET = new ETNode(I);
- ETNodes[I] = ET;
- DomTreeNode *C = new DomTreeNode(I, IDomNode, ET);
+ DomTreeNode *C = new DomTreeNode(I, IDomNode);
DomTreeNodes[I] = C;
BBNode = IDomNode->addChild(C);
}
if (BBNode) {
if (!BBNode->getIDom())
BBNode->assignDFSNumber(dfsnum);
- //ETNode *ETN = BBNode->getETNode();
- //if (ETN && !ETN->hasFather())
- // ETN->assignDFSNumber(dfsnum);
}
}
SlowQueries = 0;
// Switch to new dominator
IDom = NewIDom;
IDom->Children.push_back(this);
-
- if (!ETN->hasFather())
- ETN->setFather(IDom->getETNode());
- else if (ETN->getFather()->getData<BasicBlock>() != IDom->getBlock()) {
- ETN->Split();
- ETN->setFather(IDom->getETNode());
- }
}
}
// Add a new tree node for this BasicBlock, and link it as a child of
// IDomNode
- ETNode *ET = new ETNode(BB);
- ETNodes[BB] = ET;
- DomTreeNode *C = new DomTreeNode(BB, IDomNode, ET);
+ DomTreeNode *C = new DomTreeNode(BB, IDomNode);
DomTreeNodes[BB] = C;
return BBNode = IDomNode->addChild(C);
}