コード例 #1
0
ファイル: ir_gvn.cpp プロジェクト: Grainspring/xoc
void IR_GVN::clean()
{
	m_vn_count = 1;
	if (m_md2vn.get_bucket_size() != 0) {
		m_md2vn.clean();
	}
	if (m_ll2vn.get_bucket_size() != 0) {
		m_ll2vn.clean();
	}
	if (m_fp2vn.get_bucket_size() != 0) {
		m_fp2vn.clean();
	}
	if (m_str2vn.get_bucket_size() != 0) {
		m_str2vn.clean();
	}
	BITSET inlst;
	for (INT k = 0; k <= m_ir2vn.get_last_idx(); k++) {
		VN * x = m_ir2vn.get(k);
		if (x != NULL && !inlst.is_contain(VN_id(x))) {
			inlst.bunion(VN_id(x));
			m_free_lst.append_tail(x);
		}
	}
	m_ir2vn.clean();
	for (SVECTOR<VN*> * v = m_vnvec_lst.get_head();
		 v != NULL; v = m_vnvec_lst.get_next()) {
		v->clean();
	}

	m_def2ildtab.clean();
	m_def2arrtab.clean();
	m_def2sctab.clean();
	m_stmt2domdef.clean();
	m_zero_vn = NULL;
}
コード例 #2
0
ファイル: cfs_mgr.cpp プロジェクト: Grainspring/xoc
//Record IR list into 'irset'.
void CFS_MGR::record_ir_stmt(IR * ir_list, BITSET & irset)
{
	while (ir_list != NULL) {
		irset.bunion(IR_id(ir_list));
		ir_list = IR_next(ir_list);
	}
}
コード例 #3
0
ファイル: sgraph.cpp プロジェクト: bruce2008github/xocfe
void DGRAPH::_remove_unreach_node(UINT id, BITSET & visited)
{
	visited.bunion(id);
	VERTEX * vex = get_vertex(id);
	EDGE_C * el = VERTEX_out_list(vex);	
	while (el != NULL) {
		UINT succ = VERTEX_id(EDGE_to(EC_edge(el)));
		if (!visited.is_contain(succ)) {
			_remove_unreach_node(succ, visited);
		}	
		el = EC_next(el);
	}
}
コード例 #4
0
ファイル: sgraph.cpp プロジェクト: bruce2008github/xocfe
bool GRAPH::is_equal(GRAPH & g)
{
	if (get_vertex_num() != g.get_vertex_num() ||
		get_edge_num() != g.get_edge_num()) {
		return false;
	}
	
	BITSET vs;
	INT c;
	for (VERTEX * v1 = get_first_vertex(c); 
		 v1 != NULL; v1 = get_next_vertex(c)) {
		VERTEX * v2 = g.get_vertex(VERTEX_id(v1));
		if (v2 == NULL) {
			return false; 
		}

		vs.clean();
		EDGE_C * el = VERTEX_out_list(v1);		
		EDGE * e = NULL;
		UINT v1_succ_n = 0;
		if (el == NULL) {
			if (VERTEX_out_list(v2) != NULL) {
				return false;
			}
			continue;
		}
		for (e = EC_edge(el); e != NULL; el = EC_next(el), 
			 e = el ? EC_edge(el) : NULL) {
			vs.bunion(VERTEX_id(EDGE_to(e)));
			v1_succ_n++;
		}

		UINT v2_succ_n = 0;
		el = VERTEX_out_list(v2);
		for (e = EC_edge(el); e != NULL; el = EC_next(el), 
			 e = el ? EC_edge(el) : NULL) {
			v2_succ_n++;
			if (!vs.is_contain(VERTEX_id(EDGE_to(e)))) {
				return false;
			}			
		}
		
		if (v1_succ_n != v2_succ_n) { 
			return false; 
		}
	}
	return true;
}
コード例 #5
0
ファイル: sgraph.cpp プロジェクト: bruce2008github/xocfe
/*
Vertexs should have been sorted in topological order.
And we access them by reverse-topological order.
'vlst': compute dominator for vertices in vlst if it 
	is not empty or else compute all graph.
'uni': universe.	
*/
bool DGRAPH::compute_dom(IN LIST<VERTEX*> * vlst, BITSET const* uni)
{
	LIST<VERTEX*> tmpvlst;
	LIST<VERTEX*> * pvlst = &tmpvlst;
	if (vlst != NULL) {
		pvlst = vlst;
	} else {
		INT c;
		for (VERTEX * u = get_first_vertex(c); 
			 u != NULL; u = get_next_vertex(c)) {
			pvlst->append_tail(u);
		}
	}

	BITSET const* luni = NULL;
	if (uni != NULL) {
		luni = uni;
	} else {
		BITSET * x = new BITSET();	
		for (VERTEX * u = pvlst->get_head(); 
			 u != NULL; u = pvlst->get_next()) {
			x->bunion(VERTEX_id(u));		
		}
		luni = x;
	}

	//Initialize dom-set for each BB.	
	for (VERTEX * v = pvlst->get_head();
		 v != NULL; v = pvlst->get_next()) {
		if (is_graph_entry(v)) {
			BITSET * dom = get_dom_set(v);
			dom->clean();
			dom->bunion(VERTEX_id(v));
		} else {
			get_dom_set(v)->copy(*luni);
		}
	}
	
	/*
	DOM[entry] = {entry}
	DOM[n] = {n} ¡È { ¡É(DOM[pred] of predecessor of 'n') }	
	*/
	bool change = true;
	BITSET tmp;
	UINT count = 0;
	while (change && count < 10) {
		count++;
		change = false;
		for (VERTEX * v = pvlst->get_head(); 
			 v != NULL; v = pvlst->get_next()) {
			UINT vid = VERTEX_id(v);
			if (is_graph_entry(v)) {
				continue;
			} else {
				//Access each preds
				EDGE_C * ec = VERTEX_in_list(v);
				while (ec != NULL) {
					VERTEX * pred = EDGE_from(EC_edge(ec));
					if (ec == VERTEX_in_list(v)) {
						tmp.copy(*m_dom_set.get(VERTEX_id(pred)));		
					} else {
						tmp.intersect(*m_dom_set.get(VERTEX_id(pred)));
					}
					ec = EC_next(ec);
				}
				tmp.bunion(vid);

				BITSET * dom = m_dom_set.get(VERTEX_id(v));
				if (!dom->is_equal(tmp)) {
					dom->copy(tmp);
					change = true;
				}				
			} //end else
		} //end for
	}//end while
	IS_TRUE0(!change);
	if (uni == NULL && luni != NULL) {
		delete luni;
	}
	return true;
}
コード例 #6
0
ファイル: sgraph.cpp プロジェクト: bruce2008github/xocfe
/*
Remove transitive edge.
e.g: Given edges of G, there are v1->v2->v3, v1->v3, then v1->v3 named
transitive edge.

Algo: 
	INPUT: Graph with N edges.
	1. Sort vertices in topological order.
	2. Associate each edges with indicator respective, 
	   and recording them in one matrix(N*N) 	   
		e.g: e1:v0->v2, e2:v1->v2, e3:v0->v1
			  0   1    2
			0 --  e3   e1 
			1 --  --   e2
			2 --  --   --

	3. Scan vertices according to toplogical order, 
	   remove all edges which the target-node has been 
	   marked at else rows.
		e.g: There are dependence edges: v0->v1, v0->v2.
		 If v1->v2 has been marked, we said v0->v2 is removable, 
		 and the same goes for the rest of edges.
*/
void GRAPH::remove_transitive_edge()
{
	BITSET_MGR bs_mgr;
	SVECTOR<UINT> vex_vec;
	sort_in_toplog_order(vex_vec, true);
	SVECTOR<UINT> vid2pos_in_bitset_map; //Map from VERTEX-ID to BITSET.
	INT i;

	//Mapping vertex id to its position in 'vex_vec'.
	for (i = 0; i <= vex_vec.get_last_idx(); i++) {
		vid2pos_in_bitset_map.set(vex_vec.get(i), i); 
	}

	//Associate each edges with indicator respective.
	UINT vex_num = get_vertex_num();
	SVECTOR<BITSET*> edge_indicator; //container of bitset.
	INT c;
	for (EDGE * e = m_edges.get_first(c); e != NULL; e = m_edges.get_next(c)) {
		UINT from = VERTEX_id(EDGE_from(e));
		UINT to = VERTEX_id(EDGE_to(e));
	
		UINT frompos = vid2pos_in_bitset_map.get(from);
		BITSET * bs = edge_indicator.get(frompos);
		if (bs == NULL) {
			bs = bs_mgr.create();
			edge_indicator.set(frompos, bs);
		}
		
		//Each from-vertex is associated with 
		//a bitset to record all to-vertices.
		bs->bunion(vid2pos_in_bitset_map.get(to));
	} //end for each of edge
	
	//Scanning vertexs in topological order.
	for (i = 0; i < vex_vec.get_last_idx(); i++) {
		//Get the successor vector.
		BITSET * bs = edge_indicator.get(i); 
		if (bs != NULL && bs->get_elem_count() >= 2) {
			//Do NOT remove the first edge. Position in bitset 
			//has been sorted in topological order.
			for (INT pos_i = bs->get_first(); pos_i >= 0; 
				 pos_i = bs->get_next(pos_i)) {
				INT kid_from_vid = vex_vec.get(pos_i);
				INT kid_from_pos = vid2pos_in_bitset_map.get(kid_from_vid);

				//Get bitset that 'pos_i' associated.
				BITSET * kid_from_bs = edge_indicator.get(kid_from_pos);
				if (kid_from_bs != NULL) {
					for (INT pos_j = bs->get_next(pos_i); pos_j >= 0; 
						 pos_j = bs->get_next(pos_j)) {
						if (kid_from_bs->is_contain(pos_j)) {
							//The edge 'i->pos_j' is redundant.
							INT to_vid = vex_vec.get(pos_j);
							UINT src_vid = vex_vec.get(i);
							remove_edge(get_edge(src_vid, to_vid));
							bs->diff(pos_j);
						}
					}
				} //end if
			} //end for
		} //end if
	} //end for each vertex
}
コード例 #7
0
ファイル: sgraph.cpp プロジェクト: bruce2008github/xocfe
bool DGRAPH::compute_ipdom()
{
	bool change = true;

	//Initialize ipdom-set for each BB.
	m_ipdom_set.clean();

	//Processing in reverse-topological order.
	INT c;
	for (VERTEX * v = m_vertexs.get_last(c); 
		 v != NULL; v = m_vertexs.get_prev(c)) {
		INT cur_id = VERTEX_id(v);
		if (is_graph_exit(v)) {
			continue;
		} else if (m_pdom_set.get(cur_id)->get_elem_count() > 1) {			
			BITSET * p = m_pdom_set.get(cur_id);
			IS_TRUE(p != NULL, ("should compute pdom first"));
			if (p->get_elem_count() == 1) {
				//There is no ipdom if 'pdom' set only contain itself.
				IS_TRUE0(m_ipdom_set.get(cur_id) == 0);
				continue;
			}
			p->diff(cur_id);

			#define TRICKY_METHOD
			#ifdef TRICKY_METHOD
			INT i;
			for (i = p->get_first(); i != -1; i = p->get_next(i)) {
				if (m_pdom_set.get(i)->is_equal(*p)) {
					IS_TRUE0(m_ipdom_set.get(cur_id) == 0);
					m_ipdom_set.set(cur_id, i);
					break;
				}
			}
			//IS_TRUE(i != -1, ("not find ipdom")); //Not find.
			#else
			/*
			//Then , we can find a node which is not 
			//post-dominate any other elems reside in 'tmp'.
			for (INT i = tmp.get_first(); i != -1; i = tmp.get_next(i)) {
				for (INT j = tmp.get_first(); j != -1; j = tmp.get_next(j)) {
					if (i == j) {
						continue;
					}
					if (m_pdom_set.get(j)->is_contain(i)) {
						tmp.diff(i);
						i = tmp.get_first();
						j = i;
					} //end if
				} //end for 
			} //end for
			//There is only one elemment in 'tmp'
			IS_TRUE(tmp.get_elem_count() == 1, ("illegal in compute_ipdom"));
			INT i = tmp.get_first();
			IS_TRUE(i != -1, ("cannot find ipdom of BB:%d", cur_id));
			IS_TRUE(m_ipdom_set.get(cur_id) == 0, 
					("recompute ipdom for BB:%d", cur_id));
			m_ipdom_set.set(cur_id, i);
			*/
			#endif
			p->bunion(cur_id);
		} //end else if
	} //end for
	return true;
}
コード例 #8
0
ファイル: sgraph.cpp プロジェクト: bruce2008github/xocfe
bool DGRAPH::compute_idom()
{
	bool change = true;

	//Initialize idom-set for each BB.
	m_idom_set.clean(); 

	//Access with topological order.
	INT c;
	for (VERTEX * v = m_vertexs.get_first(c); 
		 v != NULL; v = m_vertexs.get_next(c)) { 
		INT cur_id = VERTEX_id(v);
		if (is_graph_entry(v)) {
			continue;
		} else if (m_dom_set.get(cur_id)->get_elem_count() >= 2) {
			BITSET * p = m_dom_set.get(cur_id);
			IS_TRUE(p != NULL, ("should compute dom first"));
			if (p->get_elem_count() == 1) {
				//There is no idom if 'dom' set only contain itself.
				IS_TRUE0(m_idom_set.get(cur_id) == 0);
				continue;
			}
			p->diff(cur_id);
							
			#define TRICKY_METHOD
			#ifdef TRICKY_METHOD
			INT i;
			for (i = p->get_first(); i != -1; i = p->get_next(i)) {
				if (m_dom_set.get(i)->is_equal(*p)) {
					IS_TRUE0(m_idom_set.get(cur_id) == 0);
					m_idom_set.set(cur_id, i);
					break;
				}
			}
			IS_TRUE(i != -1, ("not find idom?"));
			#else
			/*
			We can find a node that is not dominate any other elems in 'tmp'.
			INT i;
			for (i = tmp.get_first(); i != -1; i = tmp.get_next(i)) {
				for (INT j = tmp.get_first(); j != -1; j = tmp.get_next(j)) {
					if (i == j) {
						continue;
					}
					if (m_dom_set.get(j)->is_contain(i)) {
						tmp.diff(i);
						//Search 'tmp' over again.
						i = tmp.get_first();
						j = i;
					}
				}
			}

			//There is only one elemment in 'tmp'
			i = tmp.get_first();
			IS_TRUE(i != -1, ("cannot find idom of BB:%d", cur_id));
			IS_TRUE(m_idom_set.get(cur_id) == 0, ("recompute idom for BB:%d", cur_id));
			m_idom_set.set(cur_id, i);
			*/
			#endif
			p->bunion(cur_id);
		} //end else if 
	} //end for
	return true;
}
コード例 #9
0
ファイル: sgraph.cpp プロジェクト: bruce2008github/xocfe
//Vertexs should have been sorted in topological order.
//And we access them by reverse-topological order.
bool DGRAPH::compute_pdom(IN LIST<VERTEX*> * vlst, BITSET const* uni)
{
	LIST<VERTEX*> tmpvlst;
	LIST<VERTEX*> * pvlst = &tmpvlst;
	if (vlst != NULL) {
		pvlst = vlst;
	} else {
		INT c;
		for (VERTEX * v = get_first_vertex(c); 
			 v != NULL; v = get_next_vertex(c)) {
			pvlst->append_tail(v);
		}
	}
	
	BITSET const* luni = NULL;
	if (uni != NULL) {
		luni = uni;
	} else {
		BITSET * x = new BITSET();	
		for (VERTEX * u = pvlst->get_head();
			 u != NULL; u = pvlst->get_next()) {
			x->bunion(VERTEX_id(u));		
		}
		luni = x;
	}

	//Initialize pdom for each bb
	for (VERTEX * v = pvlst->get_head(); 
		 v != NULL; v = pvlst->get_next()) {
		if (is_graph_exit(v)) {
			BITSET * pdom = get_pdom_set(v);
			pdom->clean();
			pdom->bunion(VERTEX_id(v));
		} else {
			get_pdom_set(v)->copy(*luni);
		}
	}

	/*
	PDOM[exit] = {exit} 
	PDOM[n] = {n} U {¡É(PDOM[succ] of each succ of n)}	
	*/
	bool change = true;
	BITSET tmp;
	UINT count = 0;
	while (change && count < 10) {
		count++;
		change = false;
		for (VERTEX * v = pvlst->get_head(); 
			 v != NULL; v = pvlst->get_next()) {
			UINT vid = VERTEX_id(v);			
			if (is_graph_exit(v)) {
				continue;
			} else {
				tmp.clean();	
				//Access each succs
				EDGE_C * ec = VERTEX_out_list(v);
				while (ec != NULL) {
					VERTEX * succ = EDGE_to(EC_edge(ec));
					if (ec == VERTEX_out_list(v)) {
						tmp.copy(*m_pdom_set.get(VERTEX_id(succ)));	
					} else {
						tmp.intersect(*m_pdom_set.get(VERTEX_id(succ)));
					}
					ec = EC_next(ec);
				}
				tmp.bunion(vid);
				
				BITSET * pdom = m_pdom_set.get(VERTEX_id(v));
				if (!pdom->is_equal(tmp)) {
					pdom->copy(tmp);
					change = true;
				}
			}			
		} //end for
	}// end while
	IS_TRUE0(!change);
	if (uni == NULL && luni != NULL) {
		delete luni;
	}
	return true;
}