Exemple #1
0
	virtual IR_OPT * alloc_dce()
	{
		IR_DCE * opt = new IR_DCE(m_ru);
		opt->set_elim_cfs(true);
		return opt;
	}
Exemple #2
0
void PassMgr::performScalarOpt(OptCtx & oc)
{
    TTab<Pass*> opt_tab;
    List<Pass*> passlist;
    SimpCtx simp;
    if (g_do_gvn) { registerPass(PASS_GVN); }

    if (g_do_pre) {
        //Do PRE individually.
        //Since it will incur the opposite effect with Copy-Propagation.
        Pass * pre = registerPass(PASS_PRE);
        pre->perform(oc);
        ASSERT0(verifyIRandBB(m_ru->get_bb_list(), m_ru));
    }

    if (g_do_dce) {
        IR_DCE * dce = (IR_DCE*)registerPass(PASS_DCE);
        passlist.append_tail(dce);
        if (g_do_dce_aggressive) {
            dce->set_elim_cfs(true);
        }
    }

    bool in_ssa_form = false;
    IR_SSA_MGR * ssamgr =
            (IR_SSA_MGR*)(m_ru->get_pass_mgr()->queryPass(PASS_SSA_MGR));
    if (ssamgr != NULL && ssamgr->is_ssa_constructed()) {
        in_ssa_form = true;
    }

    if (!in_ssa_form) {
        //RP can reduce the memory operations and
        //improve the effect of PR SSA, so perform
        //RP before SSA construction.
        //TODO: Do SSA renaming when after register promotion done.
        if (g_do_rp) {
            //First RP.
            passlist.append_tail(registerPass(PASS_RP));
        }
    }

    if (g_do_cp) {
        IR_CP * pass = (IR_CP*)registerPass(PASS_CP);
        pass->set_prop_kind(CP_PROP_SIMPLEX);
        passlist.append_tail(pass);
    }

    if (g_do_rp) {
        //Second RP.
        passlist.append_tail(registerPass(PASS_RP));
    }

    if (g_do_gcse) {
        passlist.append_tail(registerPass(PASS_GCSE));
    }

    if (g_do_lcse) {
        passlist.append_tail(registerPass(PASS_LCSE));
    }

    if (g_do_rce) {
        passlist.append_tail(registerPass(PASS_RCE));
    }

    if (g_do_dse) {
        passlist.append_tail(registerPass(PASS_DSE));
    }

    if (g_do_licm) {
        passlist.append_tail(registerPass(PASS_LICM));
    }

    if (g_do_ivr) {
        passlist.append_tail(registerPass(PASS_IVR));
    }

    if (g_do_loop_convert) {
        passlist.append_tail(registerPass(PASS_LOOP_CVT));
    }

    bool change;
    UINT count = 0;
    BBList * bbl = m_ru->get_bb_list();
    IR_CFG * cfg = m_ru->get_cfg();
    UNUSED(cfg);
    do {
        change = false;
        for (Pass * pass = passlist.get_head();
             pass != NULL; pass = passlist.get_next()) {
            CHAR const* passname = pass->get_pass_name();
            ASSERT0(verifyIRandBB(bbl, m_ru));
            ULONGLONG t = getusec();
            bool doit = pass->perform(oc);
            appendTimeInfo(passname, getusec() - t);
            if (doit) {
                change = true;
                ASSERT0(verifyIRandBB(bbl, m_ru));
                ASSERT0(cfg->verify());
            }
            RefineCtx rc;
            m_ru->refineBBlist(bbl, rc);
            ASSERT0(m_ru->verifyRPO(oc));
        }
        count++;
    } while (change && count < 20);
    ASSERT0(!change);

    if (g_do_lcse) {
        IR_LCSE * lcse = (IR_LCSE*)registerPass(PASS_LCSE);
        lcse->set_enable_filter(false);
        ULONGLONG t = getusec();
        lcse->perform(oc);
        t = getusec() - t;
        appendTimeInfo(lcse->get_pass_name(), t);
    }

    if (g_do_rp) {
        IR_RP * r = (IR_RP*)registerPass(PASS_RP);
        ULONGLONG t = getusec();
        r->perform(oc);
        appendTimeInfo(r->get_pass_name(), getusec() - t);
    }
}