コード例 #1
0
ファイル: loop.cpp プロジェクト: Grainspring/xoc
/* 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;
}
コード例 #2
0
ファイル: mdssainfo.cpp プロジェクト: clear-wing/xoc
void MDPhi::dump(Region * rg, UseDefMgr * mgr)
{
    ASSERT0(rg);
    ASSERT0(is_phi());
    if (g_tfile == NULL) { return; }

    List<IRBB*> preds;
    IR_CFG * cfg = rg->getCFG();
    ASSERT0(cfg);
    cfg->get_preds(preds, getBB());
    IRBB * pred = preds.get_head();

    ASSERT0(getResult());
    fprintf(g_tfile, "Phi: MD%dV%d <- ",
        getResult()->mdid(), getResult()->version());
    for (IR const* opnd = getOpndList(); opnd != NULL; opnd = opnd->get_next()) {
        if (opnd != getOpndList()) {
            fprintf(g_tfile, ", ");
        }

        switch (opnd->get_code()) {
        case IR_CONST:
            fprintf(g_tfile, "Const");
            break;
        case IR_LDA:
            fprintf(g_tfile, "Lda");
            break;
        case IR_ID:
            {
                VMD * vopnd = getOpndVMD(opnd, mgr);
                fprintf(g_tfile, "MD%dV%d(id:%d)",
                    vopnd->mdid(), vopnd->version(), opnd->id());
            }
            break;
        default: UNREACH();
        }

        ASSERT0(pred);
        fprintf(g_tfile, "(BB%d)", pred->id());
        pred = preds.get_next();
    }

    VMD * res = getResult();
    ASSERT0(res);
    fprintf(g_tfile, "|UsedBy:");
    SEGIter * vit = NULL;
    bool first = true;
    for (INT i2 = res->getOccSet()->get_first(&vit);
        i2 >= 0; i2 = res->getOccSet()->get_next(i2, &vit)) {
        if (first) {
            first = false;
        } else {
            fprintf(g_tfile, ",");
        }

        IR const* use = rg->getIR(i2);
        ASSERT0(use && (use->isMemoryRef() || use->is_id()));
        fprintf(g_tfile, "%s(id:%d)", IRNAME(use), use->id());
    }

    fflush(g_tfile);
}