Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
/*
Perform DFS to seek for unreachable node.
Return true if some nodes removed.
*/
bool DGRAPH::remove_unreach_node(UINT entry_id)
{
	if (get_vertex_num() == 0) return false;
	bool removed = false;
	BITSET visited;
	_remove_unreach_node(entry_id, visited);
	INT c;
	for (VERTEX * v = get_first_vertex(c); 
		 v != NULL; v = get_next_vertex(c)) {
		if (!visited.is_contain(VERTEX_id(v))) {
			remove_vertex(v);
			removed = true;
		}
	}
	return removed;
}
Exemplo n.º 3
0
 void increment()
 {
   face_handle_t curr_face_handle(m_face_handles[m_lead]);
   vertex_t first = get_first_vertex(curr_face_handle, Time());
   vertex_t second = get_second_vertex(curr_face_handle, Time());
   if (first == m_follow)
     {
       m_follow = m_lead;
       set_edge_to_second_dispatch(curr_face_handle, ValueType(), Time());
       m_lead = second;
     }
   else if (second == m_follow)
     {
       m_follow = m_lead;
       set_edge_to_first_dispatch(curr_face_handle, ValueType(), Time());
       m_lead = first;
     }
   else
     m_lead = m_follow = graph_traits<Graph>::null_vertex();
 }
Exemplo n.º 4
0
//
//START CDG
//
void CDG::dump()
{
	dump_vcg("graph_cd_tree.vcg");
	if (g_tfile == NULL) return;
	fprintf(g_tfile, "\n==---- DUMP Control Dependence ----==");
	INT c;
	for (VERTEX * v = get_first_vertex(c);
		 v != NULL; v = get_next_vertex(c)) {
		EDGE_C * in = VERTEX_in_list(v);
		if (in == NULL) {
			fprintf(g_tfile, "\nBB%d has NO ctrl BB", VERTEX_id(v));
			continue;
		}
		fprintf(g_tfile, "\nBB%d ctrl BB is: ", VERTEX_id(v));
		while (in != NULL) {
			VERTEX * pred = EDGE_from(EC_edge(in));
			fprintf(g_tfile, "%d,", VERTEX_id(pred));
			in = EC_next(in);
		}
	}
	fprintf(g_tfile, "\n");
	fflush(g_tfile);
}
Exemplo n.º 5
0
/*
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;
}
Exemplo n.º 6
0
//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;
}
Exemplo n.º 7
0
 inline void set_lead_dispatch(face_handle_t anchor_handle, first_side)
 {
   m_lead = get_first_vertex(anchor_handle, Time());
   set_edge_to_first_dispatch(anchor_handle, ValueType(), Time());
 }