+/// 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();
+ }
+ }
+}
+