示例#1
0
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
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);
	}
}
示例#3
0
/*
Dump dom set, pdom set, idom, ipdom.
'dump_dom_tree': set to be true to dump dominate 
	tree, and post dominate Tree.
*/
void DGRAPH::dump_dom(FILE * h, bool dump_dom_tree)
{
	if (h == NULL) return;
	fprintf(h, "\n\n\n\n========= DUMP DOM/PDOM/IDOM/IPDOM =======");
	INT c;
	for (VERTEX * v = m_vertexs.get_first(c); 
		 v != NULL; v = m_vertexs.get_next(c)) {
		INT vid = VERTEX_id(v);
		fprintf(h, "\nVERTEX(%d) dom: ", vid);
		BITSET * bs;
		if ((bs = m_dom_set.get(vid)) != NULL) {
			for (INT id = bs->get_first(); id != -1 ; id = bs->get_next(id)) {
				if (id != vid) {
					fprintf(h, "%d ", id);
				}
			}
		}
		fprintf(h, "\n     pdom: ");
		if ((bs = m_pdom_set.get(vid)) != NULL) {
			for (INT id = bs->get_first(); id != -1; id = bs->get_next(id)) {
				if (id != vid) {
					fprintf(h, "%d ", id);
				}
			}
		}
		if (m_idom_set.get(vid) != 0) {
			fprintf(h, "\n     idom: %d", m_idom_set.get(vid));
		} else {
			fprintf(h, "\n");
		}

		if (m_ipdom_set.get(vid) != 0) {
			fprintf(h, "\n     ipdom: %d", m_ipdom_set.get(vid));
		} else {
			fprintf(h, "\n");
		}
	} //end for each vertexs
	fprintf(h, "\n");
	fflush(h);

	if (dump_dom_tree) {
		GRAPH dom;
		get_dom_tree(dom);
		dom.dump_vcg("graph_dom_tree.vcg");
		dom.erasure();
		get_pdom_tree(dom);
		dom.dump_vcg("graph_pdom_tree.vcg");
	}
}
示例#4
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;
}
示例#5
0
//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);
	}
}
示例#6
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;
}
示例#7
0
文件: cdg.cpp 项目: Grainspring/xoc
void CDG::build(IN OUT OPT_CTX & oc, DGRAPH & cfg)
{
	if (cfg.get_vertex_num() == 0) { return; }
	START_TIMER("CDG");
	IS_TRUE0(OPTC_is_cfg_valid(oc));
	m_ru->check_valid_and_recompute(&oc, OPT_PDOM, OPT_UNDEF);

	GRAPH pdom_tree;
	cfg.get_pdom_tree(pdom_tree);
	if (pdom_tree.get_vertex_num() == 0) { return; }

	SVECTOR<UINT> top_order;
	pdom_tree.sort_in_toplog_order(top_order, false);
	//dump_vec(top_order);

	BITSET_MGR bs_mgr;
	SVECTOR<BITSET*> cd_set;
	for (INT j = 0; j <= top_order.get_last_idx(); j++) {
		UINT ii = top_order.get(j);
		VERTEX * v = cfg.get_vertex(ii);
		IS_TRUE0(v != NULL);
		add_vertex(VERTEX_id(v));
		BITSET * cd_of_v = cd_set.get(VERTEX_id(v));
		if (cd_of_v == NULL) {
			cd_of_v = bs_mgr.create();
			cd_set.set(VERTEX_id(v), cd_of_v);
		}

		EDGE_C * in = VERTEX_in_list(v);
		while (in != NULL) {
			VERTEX * pred = EDGE_from(EC_edge(in));
			if (VERTEX_id(v) != ((DGRAPH&)cfg).get_ipdom(VERTEX_id(pred))) {
				cd_of_v->bunion(VERTEX_id(pred));
				//if (pred != v)
				{
					add_edge(VERTEX_id(pred), VERTEX_id(v));
				}
			}
			in = EC_next(in);
		}
		INT c;
		for (VERTEX * z = cfg.get_first_vertex(c);
			 z != NULL; z = cfg.get_next_vertex(c)) {
			if (((DGRAPH&)cfg).get_ipdom(VERTEX_id(z)) == VERTEX_id(v)) {
				BITSET * cd = cd_set.get(VERTEX_id(z));
				if (cd == NULL) {
					cd = bs_mgr.create();
					cd_set.set(VERTEX_id(z), cd);
				}
				for (INT i = cd->get_first(); i != -1; i = cd->get_next(i)) {
					if (VERTEX_id(v) != ((DGRAPH&)cfg).get_ipdom(i)) {
						cd_of_v->bunion(i);
						//if (i != (INT)VERTEX_id(v))
						{
							add_edge(i, VERTEX_id(v));
						}
					}
				}
			}
		}
	} //end for

	OPTC_is_cdg_valid(oc) = true;
	END_TIMER();
}
示例#8
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;
}
示例#9
0
/*
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
}
示例#10
0
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;
}
示例#11
0
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;
}
示例#12
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;
}
示例#13
0
文件: BSP.cpp 项目: baibaiwei/CubicVR
//Calculate which faces to draw given a position & frustum
void BSP::CalculateVisibleFaces(const XYZ &cameraPosition_xyz, FRUSTUM &frustum, BITSET &segmentMask)
{
	if (disable_vis) return;
	
	//Clear the list of faces drawn
	if (single_cluster)
	{
		if (!show_all) segmentMask.clearAll();
	}
	else
	{
		if (!show_all) leafActive.clearAll();
	}
	
	VECTOR3D cameraPosition;
	cameraPosition.x = cameraPosition_xyz.x;
	cameraPosition.y = cameraPosition_xyz.y;
	cameraPosition.z = cameraPosition_xyz.z;
	
	//calculate the camera leaf
	int cameraLeaf=CalculateCameraLeaf(cameraPosition);
	int cameraCluster=leaves[cameraLeaf].cluster;

	//loop through the leaves
	for(int i=0; i<numLeaves; ++i)
	{
		//if the leaf is not in the PVS, continue
		if(!isClusterVisible(cameraCluster, leaves[i].cluster))
			continue;

		//if this leaf does not lie in the frustum, continue
		if(!frustum.isBoundingBoxInside(leaves[i].boundingBoxVertices))
			continue;

		//loop through faces in this leaf and mark them to be drawn
		if (single_cluster)
		{
			for(int j=0; j<leaves[i].numFaces; ++j)
			{
				//facesToDraw.Set(leafFaces[leaves[i].firstLeafFace+j]);
				int faceNumber = leafFaces[leaves[i].firstLeafFace+j];
				
				if (faceDirectory[faceNumber].faceType==bspPolygonFace)
				{
					int polygonFaceNumber = faceDirectory[faceNumber].typeFaceNumber;
					
//					printf("polygonFaces[polygonFaceNumber].segmentIndex: %d\n",polygonFaces[polygonFaceNumber].segmentIndex);
					if (polygonFaces[polygonFaceNumber].segmentIndex)
					{
						segmentMask.set(polygonFaces[polygonFaceNumber].segmentIndex);
					}
				}
				if (faceDirectory[faceNumber].faceType==bspPatch)
				{
					int polygonFaceNumber = faceDirectory[faceNumber].typeFaceNumber;
					
//					printf("patches[polygonFaceNumber].segmentIndex: %d\n",patches[polygonFaceNumber].segmentIndex);
					if (patches[polygonFaceNumber].segmentIndex)
					{
						segmentMask.set(patches[polygonFaceNumber].segmentIndex);
					}
				}
				if (faceDirectory[faceNumber].faceType==bspMeshFace)
				{
					int polygonFaceNumber = faceDirectory[faceNumber].typeFaceNumber;
					
//					printf("meshFaces[polygonFaceNumber].segmentIndex: %d\n",meshFaces[polygonFaceNumber].segmentIndex);
					if (meshFaces[polygonFaceNumber].segmentIndex)
					{
						segmentMask.set(meshFaces[polygonFaceNumber].segmentIndex);
					}
				}
			}
		}
		else
		{
			leafActive.set(i);
		}
	}
}