//
//===----------------------------------------------------------------------===//
-static RegisterAnalysis<ImmediateDominators>
+static RegisterPass<ImmediateDominators>
C("idom", "Immediate Dominators Construction", true);
unsigned ImmediateDominators::DFSPass(BasicBlock *V, InfoRec &VInfo,
return false;
}
+/// dominates - Return true if A dominates B.
+///
+bool ImmediateDominatorsBase::dominates(BasicBlock *A, BasicBlock *B) const {
+ assert(A && B && "Null pointers?");
+
+ // Walk up the dominator tree from B to determine if A dom B.
+ while (A != B && B)
+ B = get(B);
+ return A == B;
+}
+
void ImmediateDominatorsBase::print(std::ostream &o, const Module* ) const {
Function *F = getRoots()[0]->getParent();
for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) {
// DominatorSet Implementation
//===----------------------------------------------------------------------===//
-static RegisterAnalysis<DominatorSet>
+static RegisterPass<DominatorSet>
B("domset", "Dominator Set Construction", true);
// dominates - Return true if A dominates B. This performs the special checks
// DominatorTree Implementation
//===----------------------------------------------------------------------===//
-static RegisterAnalysis<DominatorTree>
+static RegisterPass<DominatorTree>
E("domtree", "Dominator Tree Construction", true);
// DominatorTreeBase::reset - Free all of the tree node memory.
// DominanceFrontier Implementation
//===----------------------------------------------------------------------===//
-static RegisterAnalysis<DominanceFrontier>
+static RegisterPass<DominanceFrontier>
G("domfrontier", "Dominance Frontier Construction", true);
const DominanceFrontier::DomSetType &
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
//===----------------------------------------------------------------------===//
-static RegisterAnalysis<ETForest>
+static RegisterPass<ETForest>
D("etforest", "ET Forest Construction", true);
void ETForestBase::reset() {