Пример #1
0
void GRAPH::dump_dot(CHAR const* name)
{
	if (name == NULL) {
		name = "graph.dot";
	}
	unlink(name);
	FILE * h = fopen(name, "a+");
	IS_TRUE(h, ("%s create failed!!!", name));

	fprintf(h, "digraph G {\n");
	//Print node
	INT c;
	for (VERTEX const* v = m_vertexs.get_first(c); 
		 v != NULL; v = m_vertexs.get_next(c)) {
		fprintf(h, "\nnode%d [shape = Mrecord, label=\"{BB%d}\"];", 
				VERTEX_id(v), VERTEX_id(v));
	}

	//Print edge
	for (EDGE const* e = m_edges.get_first(c); 
		 e != NULL; e = m_edges.get_next(c)) {
		fprintf(h, "\nnode%d->node%d[label=\"%s\"]",
					VERTEX_id(EDGE_from(e)), 
					VERTEX_id(EDGE_to(e)),
					""); 
	}
	fprintf(h, "\n}\n");
	fclose(h);
}
Пример #2
0
void DGRAPH::sort_dom_tree_in_postorder(IN GRAPH & dom_tree, IN VERTEX * root,
										OUT LIST<VERTEX*> & lst)
{
	IS_TRUE0(root);
	BITSET is_visited;

	//Find the leaf node.
	VERTEX * v;
	SSTACK<VERTEX*> stk;
	stk.push(root);
	while ((v = stk.pop()) != NULL) {
		//Visit children first.
		EDGE_C * el = VERTEX_out_list(v);
		bool find = false; //find unvisited kid.
		VERTEX * succ;
		while (el != NULL) {
			succ = EDGE_to(EC_edge(el));
			if (!is_visited.is_contain(VERTEX_id(succ))) {
				stk.push(v);
				stk.push(succ);
				find = true;
				break;
			}
			el = EC_next(el);
		}
		if (!find) {
			is_visited.bunion(VERTEX_id(v));
			//The only place to process vertex.
			lst.append_tail(v);
		}
	}	
}
Пример #3
0
void DGRAPH::sort_dom_tree_in_preorder(IN GRAPH & dom_tree, IN VERTEX * root,
									   OUT LIST<VERTEX*> & lst)
{
	IS_TRUE0(root);
	BITSET is_visited;
	is_visited.bunion(VERTEX_id(root));
	lst.append_tail(root);
	
	VERTEX * v;
	SSTACK<VERTEX*> stk;
	stk.push(root);
	while ((v = stk.pop()) != NULL) {
		if (!is_visited.is_contain(VERTEX_id(v))) {
			is_visited.bunion(VERTEX_id(v));
			stk.push(v);
			//The only place to process vertex.
			lst.append_tail(v);			
		}
		
		//Visit children.
		EDGE_C * el = VERTEX_out_list(v);
		VERTEX * succ;
		while (el != NULL) {
			succ = EDGE_to(EC_edge(el));
			if (!is_visited.is_contain(VERTEX_id(succ))) {
				stk.push(v);
				stk.push(succ);
				break;
			}
			el = EC_next(el);
		}		
	}
}
Пример #4
0
/*
Sort vertice by rporder, and 
record to vlst in incremental order.
*/
void DGRAPH::compute_rpo_norec(IN VERTEX * root, OUT LIST<VERTEX*> & vlst)
{
	BITSET is_visited;
	SSTACK<VERTEX*> stk;
	stk.push(root);
	VERTEX * v;
	while ((v = stk.pop()) != NULL) {
		is_visited.bunion(VERTEX_id(v));
		EDGE_C * el = VERTEX_out_list(v);
		bool find = false; //find unvisited kid.
		while (el != NULL) {
			VERTEX * succ = EDGE_to(EC_edge(el));
			if (!is_visited.is_contain(VERTEX_id(succ))) {
				stk.push(v);
				stk.push(succ);
				find = true;
				break;				
			}
			el = EC_next(el);
		}
		if (!find) {			
			vlst.append_head(v);
		}
	}
}
Пример #5
0
EDGE * GRAPH::new_edge(VERTEX * from, VERTEX * to)
{
	IS_TRUE(m_pool != NULL, ("not yet initialized."));
	if (from == NULL || to == NULL) return NULL;
	EDGE teste;
	VERTEX testfrom, testto;
	if (m_is_unique) {
		VERTEX_id(&testfrom) = VERTEX_id(from);
		VERTEX_id(&testto) = VERTEX_id(to);
		EDGE_from(&teste) = &testfrom;
		EDGE_to(&teste) = &testto;
		if (m_is_direction) {			
			return m_edges.append((ULONG)&teste, NULL);
		} else {
			EDGE * e = NULL;
			if (m_edges.find(&teste, &e)) {
				IS_TRUE0(e);
				return e;
			}
			
			//Both check from->to and to->from
			EDGE_from(&teste) = &testto;
			EDGE_to(&teste) = &testfrom;
			return m_edges.append((ULONG)&teste, NULL);
		}
		IS_TRUE0(0);
	}
	return m_edges.append(new_edge_c(from, to));
}
Пример #6
0
//
//START EDGE_HASH
//
EDGE * EDGE_HASH::create(ULONG v)
{
	EDGE * t = (EDGE*)v;
	VERTEX * from = m_g->get_vertex(VERTEX_id(EDGE_from(t)));
	VERTEX * to = m_g->get_vertex(VERTEX_id(EDGE_to(t)));
	IS_TRUE0(from && to);
	t = m_g->new_edge_c(from, to);
	return t;
}
Пример #7
0
BITSET * DGRAPH::get_pdom_set(IN VERTEX * v)
{
	IS_TRUE0(v != NULL && m_bs_mgr != NULL);
	BITSET * set = m_pdom_set.get(VERTEX_id(v));
	if (set == NULL) {
		set = m_bs_mgr->create();
		m_pdom_set.set(VERTEX_id(v), set);
	}
	return set;
}
Пример #8
0
//Reverse edge direction
EDGE * GRAPH::rev_edge(EDGE * e)
{
	IS_TRUE(m_pool != NULL, ("not yet initialized."));
	IS_TRUE(m_is_direction, ("graph is indirection"));
	void * einfo = EDGE_info(e);
	VERTEX * from = EDGE_from(e);
	VERTEX * to = EDGE_to(e);
	remove_edge(e);
	e = add_edge(VERTEX_id(to), VERTEX_id(from));
	EDGE_info(e) = einfo;
	return e;
}
Пример #9
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;
}
Пример #10
0
//Before removing bb, revising phi opnd if there are phis
//in one of bb's successors.
void IRBB::removeSuccessorPhiOpnd(CFG<IRBB, IR> * cfg)
{
    IR_CFG * ircfg = (IR_CFG*)cfg;
    Region * ru = ircfg->get_ru();
    Vertex * vex = ircfg->get_vertex(BB_id(this));
    ASSERT0(vex);
    for (EdgeC * out = VERTEX_out_list(vex);
         out != NULL; out = EC_next(out)) {
        Vertex * succ_vex = EDGE_to(EC_edge(out));
        IRBB * succ = ircfg->get_bb(VERTEX_id(succ_vex));
        ASSERT0(succ);

        UINT const pos = ircfg->WhichPred(this, succ);

        for (IR * ir = BB_first_ir(succ);
             ir != NULL; ir = BB_next_ir(succ)) {
            if (!ir->is_phi()) { break; }

            ASSERT0(cnt_list(PHI_opnd_list(ir)) ==
                     cnt_list(VERTEX_in_list(succ_vex)));

            IR * opnd;
            UINT lpos = pos;
            for (opnd = PHI_opnd_list(ir);
                 lpos != 0; opnd = IR_next(opnd)) {
                ASSERT0(opnd);
                lpos--;
            }

            opnd->removeSSAUse();
            ((CPhi*)ir)->removeOpnd(opnd);
            ru->freeIRTree(opnd);
        }
    }
}
Пример #11
0
/* Find the bb that is the start of the unqiue backedge of loop.
   BB1: loop start bb
   BB2: body start bb
   BB3: goto loop start bb

   BB2 is the loop header fallthrough bb. */
bool find_loop_header_two_succ_bb(LI<IR_BB> const* li, IR_CFG * cfg,
								UINT * succ1, UINT * succ2)
{
	IS_TRUE0(li && cfg && succ1 && succ2);
	IR_BB * head = LI_loop_head(li);

	VERTEX * headvex = cfg->get_vertex(IR_BB_id(head));
	if (cfg->get_out_degree(headvex) != 2) {
		//Not natural loop.
		return false;
	}

	EDGE_C const* ec = VERTEX_out_list(headvex);
	IS_TRUE0(ec && EC_next(ec));

	*succ1 = VERTEX_id(EDGE_to(EC_edge(ec)));
	*succ2 = VERTEX_id(EDGE_to(EC_edge(EC_next(ec))));
	return true;
}
Пример #12
0
//Before removing bb or change bb successor,
//you need remove the related PHI operand if BB successor has PHI stmt.
void IRBB::removeSuccessorPhiOpnd(CFG<IRBB, IR> * cfg)
{
    Vertex * vex = cfg->get_vertex(BB_id(this));
    ASSERT0(vex);
    for (EdgeC * out = VERTEX_out_list(vex); out != NULL; out = EC_next(out)) {
        IRBB * succ = ((IR_CFG*)cfg)->get_bb(VERTEX_id(EDGE_to(EC_edge(out))));
        ASSERT0(succ);
        removeSuccessorDesignatePhiOpnd(cfg, succ);
    }
}
Пример #13
0
//'dom': output dominator tree.
void DGRAPH::get_dom_tree(OUT GRAPH & dom)
{
	INT c;
	for (VERTEX * v = m_vertexs.get_first(c); 
		 v != NULL; v = m_vertexs.get_next(c)) {
		UINT vid = VERTEX_id(v);
		dom.add_vertex(vid);
		if (m_idom_set.get(vid) != 0) {
			dom.add_edge(m_idom_set.get(vid), vid);
		}
	}
}
Пример #14
0
//'pdom': output post-dominator tree.
void DGRAPH::get_pdom_tree(OUT GRAPH & pdom)
{
	INT c;
	for (VERTEX * v = m_vertexs.get_first(c); 
		 v != NULL; v = m_vertexs.get_next(c)) {
		UINT vid = VERTEX_id(v);
		pdom.add_vertex(vid);
		if (m_ipdom_set.get(vid) != 0) { //id of bb starting at 1.
			pdom.add_edge(m_ipdom_set.get(vid), vid);
		}	
	}
}
Пример #15
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);
	}
}
Пример #16
0
//Is there exist a path connect 'from' and 'to'.
bool GRAPH::is_reachable(VERTEX * from, VERTEX * to)
{
	IS_TRUE(m_pool != NULL, ("not yet initialized."));
	IS_TRUE(from != NULL && to != NULL, ("parameters cannot be NULL"));
	EDGE_C * el = VERTEX_out_list(from);
	EDGE * e = NULL;
	if (el == NULL) return false;
	
	//Walk through each succ of 'from'
	for (e = EC_edge(el); e != NULL; el = EC_next(el), 
		 e = el ? EC_edge(el):NULL) {
		VERTEX * succ = EDGE_to(e);
		if (VERTEX_id(succ) == VERTEX_id(to)) {
			return true;
		} else {
			if (is_reachable(succ, to)) {
				return true;
			}
		}
	} //end for
	return false;
}
Пример #17
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);
}
Пример #18
0
//Return true if b is control dependent on a.
bool CDG::is_cd(UINT a, UINT b)
{
	IS_TRUE0(get_vertex(b));
	VERTEX * v = get_vertex(a);
	IS_TRUE0(v != NULL);
	EDGE_C * out = VERTEX_out_list(v);
	while (out != NULL) {
		if (VERTEX_id(EDGE_to(EC_edge(out))) == b) {
			return true;
		}
		out = EC_next(out);
	}
	return false;
}
Пример #19
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");
	}
}
Пример #20
0
/*
Return all neighbors of 'vid' on graph.
Return false if 'vid' is not on graph.
*/
bool GRAPH::get_neighbor_list(OUT LIST<UINT> & ni_list, IN UINT vid)
{
	IS_TRUE(m_pool != NULL, ("not yet initialized."));
	UINT degree = 0;
	VERTEX * vex  = m_vertexs.find(vid);
	if (vex == NULL) return false;
	EDGE_C * el = VERTEX_in_list(vex);
	while (el != NULL) {
		INT v = VERTEX_id(EDGE_from(EC_edge(el)));
		if (!ni_list.find(v)) {
			ni_list.append_tail(v);
		}
		el = EC_next(el);
	}
	el = VERTEX_out_list(vex);
	while (el != NULL) {
		INT v = VERTEX_id(EDGE_to(EC_edge(el)));
		if (!ni_list.find(v)) {
			ni_list.append_tail(v);
		}	
		el = EC_next(el);
	}
	return true;
}
Пример #21
0
bool GRAPH::clone(GRAPH & src)
{
	erasure();
	m_is_unique = src.m_is_unique; 
	m_is_direction = src.m_is_direction; 

	//Clone vertexs
	INT c;
	for (VERTEX * srcv = src.get_first_vertex(c); 
		 srcv != NULL; srcv = src.get_next_vertex(c)) {
		VERTEX * v = add_vertex(VERTEX_id(srcv));

		/*
		Calls inherited class method.
		Vertex info of memory should allocated by inherited class method
		*/
		if (VERTEX_info(srcv) != NULL) {
			VERTEX_info(v) = clone_vertex_info(srcv);
		}
	}

	//Clone edges
	for (EDGE * srce = src.get_first_edge(c); 
		 srce != NULL; srce = src.get_next_edge(c)) {
		EDGE * e = add_edge(VERTEX_id(EDGE_from(srce)), 
							VERTEX_id(EDGE_to(srce)));

		/*Calls inherited class method.
		 *Edge info of memory should allocated by inherited class method
		 * */
		if (EDGE_info(srce) != NULL) {
			EDGE_info(e) = clone_edge_info(srce);
		}
	}
	return true;
}
Пример #22
0
bool IR_CP::perform(OptCtx & oc)
{
    START_TIMER_AFTER();
    ASSERT0(OC_is_cfg_valid(oc));

    if (m_prop_kind == CP_PROP_CONST) {

        m_ru->checkValidAndRecompute(&oc, PASS_DOM, PASS_DU_REF,
            PASS_DU_CHAIN, PASS_UNDEF);
    } else {
        m_ru->checkValidAndRecompute(&oc, PASS_DOM, PASS_DU_REF,
            PASS_LIVE_EXPR, PASS_DU_CHAIN, PASS_UNDEF);
    }

    if (!OC_is_du_chain_valid(oc)) {
        END_TIMER_AFTER(get_pass_name());
        return false;
    }

    bool change = false;
    IRBB * entry = m_ru->get_cfg()->get_entry();
    ASSERT(entry, ("Not unique entry, invalid Region"));
    Graph domtree;
    m_cfg->get_dom_tree(domtree);
    List<Vertex*> lst;
    Vertex * root = domtree.get_vertex(BB_id(entry));
    m_cfg->sortDomTreeInPreorder(root, lst);
    Vector<IR*> usevec;

    for (Vertex * v = lst.get_head(); v != NULL; v = lst.get_next()) {
        IRBB * bb = m_cfg->get_bb(VERTEX_id(v));
        ASSERT0(bb);
        change |= doProp(bb, usevec);
    }

    if (change) {
        doFinalRefine();
        OC_is_expr_tab_valid(oc) = false;
        OC_is_aa_valid(oc) = false;
        OC_is_du_chain_valid(oc) = true; //already update.
        OC_is_ref_valid(oc) = true; //already update.
        ASSERT0(m_ru->verifyMDRef() && m_du->verifyMDDUChain());
        ASSERT0(verifySSAInfo(m_ru));
    }

    END_TIMER_AFTER(get_pass_name());
    return change;
}
Пример #23
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;
}
Пример #24
0
/* Find preheader BB. If it does not exist, insert one before loop 'li'.

'insert_bb': return true if this function insert a new bb before loop,
	otherwise return false.

'force': force to insert preheader BB whatever it has exist.
	Return the new BB if insertion is successful.

Note if we find the preheader, the last IR of it may be call.
So if you are going to insert IR at the tail of preheader, the best is
force to insert a new bb. */
IR_BB * find_and_insert_prehead(LI<IR_BB> const* li, REGION * ru,
								OUT bool & insert_bb,
								bool force)
{
	IS_TRUE0(li && ru);
	insert_bb = false;
	IR_CFG * cfg = ru->get_cfg();
	IR_BB_LIST * bblst = ru->get_bb_list();
	IR_BB * head = LI_loop_head(li);

	C<IR_BB*> * bbholder = NULL;
	bblst->find(head, &bbholder);
	IS_TRUE0(bbholder);
	C<IR_BB*> * tt = bbholder;
	IR_BB * prev = bblst->get_prev(&tt);

	//Find appropriate BB to be prehead.
	bool find_appropriate_prev_bb = false;
	EDGE_C const* ec = VERTEX_in_list(cfg->get_vertex(IR_BB_id(head)));
	while (ec != NULL) {
		UINT pred = VERTEX_id(EDGE_from(EC_edge(ec)));
		if (pred == IR_BB_id(prev)) {
			find_appropriate_prev_bb = true;
			break;
		}
		ec = EC_next(ec);
	}

	if (!force && find_appropriate_prev_bb) { return prev; }

	LIST<IR_BB*> preds;
	cfg->get_preds(preds, head);
	insert_bb = true;
	IR_BB * newbb = ru->new_bb();
	bblst->insert_before(newbb, bbholder);
	BITSET * loop_body = LI_bb_set(li);
	for (IR_BB * p = preds.get_head(); p != NULL; p = preds.get_next()) {
		if (loop_body->is_contain(IR_BB_id(p))) {
			continue;
		}
		cfg->add_bb(newbb);
		cfg->insert_vertex_between(IR_BB_id(p), IR_BB_id(head),
								   IR_BB_id(newbb));
		IR_BB_is_fallthrough(newbb) = 1;
	}
	return newbb;
}
Пример #25
0
//Return true if one of bb's successor has a phi.
bool IRBB::successorHasPhi(CFG<IRBB, IR> * cfg)
{
    Vertex * vex = cfg->get_vertex(BB_id(this));
    ASSERT0(vex);
    for (EdgeC * out = VERTEX_out_list(vex);
         out != NULL; out = EC_next(out)) {
        Vertex * succ_vex = EDGE_to(EC_edge(out));
        IRBB * succ = cfg->get_bb(VERTEX_id(succ_vex));
        ASSERT0(succ);

        for (IR * ir = BB_first_ir(succ);
             ir != NULL; ir = BB_next_ir(succ)) {
            if (ir->is_phi()) { return true; }
        }
    }
    return false;
}
Пример #26
0
bool DGRAPH::clone_bs(DGRAPH & src)
{
	IS_TRUE0(m_bs_mgr != NULL);	
	INT c;
	for (VERTEX * srcv = src.m_vertexs.get_first(c); 
		 srcv != NULL; srcv = src.m_vertexs.get_next(c)) {
		INT src_vid = VERTEX_id(srcv);
		VERTEX * tgtv = get_vertex(src_vid);
		IS_TRUE0(tgtv != NULL);

		get_dom_set(tgtv)->copy(*src.get_dom_set(srcv));
		get_pdom_set(tgtv)->copy(*src.get_pdom_set(srcv));
	} //end for each vertexs
	m_idom_set.copy(src.m_idom_set);
	m_ipdom_set.copy(src.m_ipdom_set);
	return true;
}
Пример #27
0
VERTEX * GRAPH::new_vertex(UINT vid)
{
	IS_TRUE(m_pool != NULL, ("not yet initialized."));
	VERTEX * vex = NULL;
	#ifndef ALWAYS_VERTEX_UNIQUE
	if (m_is_unique)
	#endif
	{
		VERTEX * v = m_vertexs.find(vid);
		if (v != NULL) {
			return v;
		}
	}
	vex = m_v_free_list.get_free_elem();
	vex = (vex == NULL) ? (VERTEX*)_xmalloc(sizeof(VERTEX)) : vex;
	VERTEX_id(vex) = vid;
	return vex;
}
Пример #28
0
//'order_buf': record the bfs-order for each vertex.
void DGRAPH::sort_in_bfs_order(SVECTOR<UINT> & order_buf, GRAPH & domtree,
							   VERTEX * root)
{		
	LIST<VERTEX*> worklst;
	worklst.append_tail(root);
	UINT order = 1;
	while (worklst.get_elem_count() > 0) {
		VERTEX * sv = worklst.remove_head();
		order_buf.set(VERTEX_id(sv), order);
		order++;
		EDGE_C * el = VERTEX_out_list(sv);
		while (el != NULL) {
			VERTEX * to = EDGE_to(EC_edge(el));
			worklst.append_tail(to);
			el = EC_next(el);
		}
	}
}
Пример #29
0
//Duplicate and add an operand that indicated by opnd_pos at phi stmt
//in one of bb's successors.
void IRBB::dupSuccessorPhiOpnd(CFG<IRBB, IR> * cfg, Region * ru, UINT opnd_pos)
{
    IR_CFG * ircfg = (IR_CFG*)cfg;
    Vertex * vex = ircfg->get_vertex(BB_id(this));
    ASSERT0(vex);
    for (EdgeC * out = VERTEX_out_list(vex);
            out != NULL; out = EC_next(out)) {
        Vertex * succ_vex = EDGE_to(EC_edge(out));
        IRBB * succ = ircfg->get_bb(VERTEX_id(succ_vex));
        ASSERT0(succ);

        for (IR * ir = BB_first_ir(succ);
                ir != NULL; ir = BB_next_ir(succ)) {
            if (!ir->is_phi()) {
                break;
            }

            ASSERT0(cnt_list(PHI_opnd_list(ir)) >= opnd_pos);

            IR * opnd;
            UINT lpos = opnd_pos;
            for (opnd = PHI_opnd_list(ir);
                    lpos != 0; opnd = opnd->get_next()) {
                ASSERT0(opnd);
                lpos--;
            }

            IR * newopnd = ru->dupIRTree(opnd);
            if (opnd->is_read_pr()) {
                newopnd->copyRef(opnd, ru);
                ASSERT0(PR_ssainfo(opnd));
                PR_ssainfo(newopnd) = PR_ssainfo(opnd);
                SSA_uses(PR_ssainfo(newopnd)).append(newopnd);
            }

            ((CPhi*)ir)->addOpnd(newopnd);
        }
    }
}
Пример #30
0
/* Find the bb that is the start of the unqiue backedge of loop.
   BB1: loop start bb
   BB2: body
   BB3: goto loop start bb

   BB3 is the backedge start bb. */
IR_BB * find_single_backedge_start_bb(LI<IR_BB> const* li, IR_CFG * cfg)
{
	IS_TRUE0(li && cfg);
	IR_BB * head = LI_loop_head(li);

	UINT backedgebbid = 0;
	UINT backedgecount = 0;
	EDGE_C const* ec = VERTEX_in_list(cfg->get_vertex(IR_BB_id(head)));
	while (ec != NULL) {
		backedgecount++;
		UINT pred = VERTEX_id(EDGE_from(EC_edge(ec)));
		if (li->inside_loop(pred)) {
			backedgebbid = pred;
		}
		ec = EC_next(ec);
	}
	IS_TRUE0(backedgebbid > 0 && cfg->get_bb(backedgebbid));
	if (backedgecount > 2) {
		//There are multiple backedges.
		return NULL;
	}
	return cfg->get_bb(backedgebbid);
}