cloud9_root/src/cloud9/lib/Module/ControlDependence.cpp
// From Ferrante et al. the algorithm for obtaining control dependency
// information is:
//
// Let S consist of all edges (A,B) in the control flow graph (A->B) such that
// B is not an ancestor of A in the post-dominator tree (ie B does not
// post-dominate A).
//
// Each pair (A,B) in S is then examined. Let L denote the least common
// ancestor of A and B in the post-dominator tree. L can be two things (see the
// paper for proofs)
//
// Case 1. L = parent of A. All nodes in the post-dominator tree on the path
// from L to B, including B but not L, should be made control dependent on A. 
//
// Case 2. L = A. All nodes in the post-dominator tree on the path from A to B,
// including A and B, should be made control dependent on A. (This case
// captures loop dependence.)
//
// This can be done by simply traversing backwards from B in the post-dominator
// tree until we reach A's parent (if it exists). We mark every node as control
// dependent on A.
From Ferrante et al. the algorithm for obtaining control dependency
information is.

Let S consist of all edges (A,B) in the control flow graph (A->B) such that
B is not an ancestor of A in the post-dominator tree .

Each pair (A,B) in S is then examined. Let L denote the least common
ancestor of A and B in the post-dominator tree. L can be two things (see the
paper for proofs)

Case 1. L = parent of A. All nodes in the post-dominator tree on the path
from L to B, including B but not L, should be made control dependent on A.

Case 2. L = A. All nodes in the post-dominator tree on the path from A to B,
including A and B, should be made control dependent on A. (This case
captures loop dependence.)

This can be done by simply traversing backwards from B in the post-dominator
tree until we reach A's parent (if it exists). We mark every node as control
dependent on A.
From Ferrante et al . the algorithm for obtaining control dependency information is . Let S consist of all edges ( A B ) in the control flow graph ( A - > B ) such that B is not an ancestor of A in the post - dominator tree . Each pair ( A B ) in S is then examined . Let L denote the least common ancestor of A and B in the post - dominator tree . L can be two things ( see the paper for proofs ) Case 1 . L = parent of A . All nodes in the post - dominator tree on the path from L to B including B but not L should be made control dependent on A . Case 2 . L = A . All nodes in the post - dominator tree on the path from A to B including A and B should be made control dependent on A . ( This case captures loop dependence . ) This can be done by simply traversing backwards from B in the post - dominator tree until we reach A ' s parent ( if it exists ) . We mark every node as control dependent on A .
void ControlDependence::getControlDependencies(Function &F, PostDominatorTree &PDT) {
	vector<CFGEdge> S;
	S = getNonPDomEdges(F, PDT);
#ifdef MK_DEBUG
	errs() << "[MK DEBUG] Size of set S: " << S.size() << '\n';
#endif
	updateControlDependencies(S, PDT);
	for (depmap::iterator mi = controlDeps_.begin(), me = controlDeps_.end(); mi != me; ++mi) {
		std::set<BasicBlock *> curSet;
		curSet = mi->second;
		BasicBlock *A = mi->first;
		for (std::set<BasicBlock *>::iterator si = curSet.begin(), se = curSet.end(); si != se; ++si) {
			BasicBlock *curBlock = *si;
			reverseControlDeps_[curBlock].insert(A);
		} 
	} 
}
void ControlDependence :: getControlDependencies ( Function & F , PostDominatorTree & PDT ) { vector < CFGEdge > S ; S = getNonPDomEdges ( F , PDT ) ; #ifdef MK_DEBUG errs ( ) << " " << S . size ( ) << ' \n ' ; #endif updateControlDependencies ( S , PDT ) ; for ( depmap :: iterator mi = controlDeps_ . begin ( ) , me = controlDeps_ . end ( ) ; mi != me ; ++ mi ) { std :: set < BasicBlock * > curSet ; curSet = mi -> second ; BasicBlock * A = mi -> first ; for ( std :: set < BasicBlock * > :: iterator si = curSet . begin ( ) , se = curSet . end ( ) ; si != se ; ++ si ) { BasicBlock * curBlock = * si ; reverseControlDeps_ [ curBlock ] . insert ( A ) ; } } }
From Ferrante et al.
From Ferrante et al .
// All edges in the CFG (A->B) such that B does not post-dominate A // Generate a helper map which is the reverse of the control dependence graph // controlDeps is a graph with edges (A, B) where B is the set of // BasicBlocks control dependent on A. To do the reverse, we insert an edge // to A for each BasicBlock in B. // for (std::set<BasicBlock *>::iterator // for (depmap::iterator mi = controlDeps_.begin())