Exemple #1
0
void destroy_scope_list()
{
	for (SCOPE * sc = g_scope_list.get_head();
		 sc != NULL; sc = g_scope_list.get_next()) {
		sc->destroy();
	}
}
Exemple #2
0
void IR_GVN::dump_bb_labs(LIST<LABEL_INFO*> & lst)
{
	for (LABEL_INFO * li = lst.get_head(); li != NULL; li = lst.get_next()) {
		switch (LABEL_INFO_type(li)) {
		case L_CLABEL:
			note(CLABEL_STR_FORMAT, CLABEL_CONT(li));
			break;
		case L_ILABEL:
			note(ILABEL_STR_FORMAT, ILABEL_CONT(li));
			break;
		case L_PRAGMA:
			note("%s", LABEL_INFO_pragma(li));
			break;
		default: IS_TRUE(0,("unsupport"));
		}
		if (LABEL_INFO_is_try_start(li) ||
			LABEL_INFO_is_try_end(li) ||
			LABEL_INFO_is_catch_start(li)) {
			fprintf(g_tfile, "(");
			if (LABEL_INFO_is_try_start(li)) {
				fprintf(g_tfile, "try_start,");
			}
			if (LABEL_INFO_is_try_end(li)) {
				fprintf(g_tfile, "try_end,");
			}
			if (LABEL_INFO_is_catch_start(li)) {
				fprintf(g_tfile, "catch_start");
			}
			fprintf(g_tfile, ")");
		}
		fprintf(g_tfile, " ");
	}
}
Exemple #3
0
//Reverse all edge direction
void GRAPH::rev_edges()
{
	IS_TRUE(m_pool != NULL, ("not yet initialized."));
	IS_TRUE(m_is_direction, ("graph is indirection"));
	LIST<EDGE*> list;
	EDGE * e;
	INT c;
	for (e = get_first_edge(c); e != NULL; e = get_next_edge(c)) {
		list.append_tail(e);		
	}
	for (e = list.get_head(); e != NULL; e = list.get_next()) { 
		rev_edge(e);
	}	
}
Exemple #4
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;
}
Exemple #5
0
/*
Sort graph vertices in topological order. 
'vex_vec': record nodes with topological sort.
NOTE: current graph will be empty at function return.
	If one need to keep the graph unchanged, clone graph
	as a tmpgraph and operate on the tmpgraph.
	e.g: GRAPH org; 
		And org must be unchanged, 
		GRAPH tmp(org);
		tmp.sort_in_toplog_order(...)	
*/
bool GRAPH::sort_in_toplog_order(OUT SVECTOR<UINT> & vex_vec, bool is_topdown)
{
	IS_TRUE(m_pool != NULL, ("Graph still not yet initialize."));
	if (get_vertex_num() == 0) {
		return true;
	}
	LIST<VERTEX*> vlst;
	UINT pos = 0;
	vex_vec.clean();
	vex_vec.grow(get_vertex_num());
	while (this->get_vertex_num() != 0) {
		vlst.clean();
		VERTEX * v;
		INT c;
		for (v = this->get_first_vertex(c);
			 v != NULL; v = this->get_next_vertex(c)) {
			if (is_topdown) {
				if (VERTEX_in_list(v) == NULL) {
					vlst.append_tail(v);
				}
			} else if (VERTEX_out_list(v) == NULL) {
				vlst.append_tail(v);				
			}
		}
		if (vlst.get_elem_count() == 0 && this->get_vertex_num() != 0) {
			IS_TRUE(0, ("exist cycle in graph"));
			return false;
		}
		for (v = vlst.get_head(); v != NULL; v = vlst.get_next()) {
			vex_vec.set(pos, VERTEX_id(v));
			pos++;
			this->remove_vertex(v);
		}
	}
	return true;
}