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; }
/* Perform high-level optimizaitions. Basis step to do: 1. Build control flow graph. 2. Compute POINT-TO info. 3. Compute DEF-USE info. 4. Compute Lived Expression info. Optimizations to be performed: 1. Auto Parallel 2. Loop interchange 3. Loop reverese(may be a little helpful) 4. Loop tiling 5. Loop fusion 6. Loop unrolling */ bool Region::HighProcess(OptCTX & oc) { g_indent = 0; note("\n\n==== Region:%s HIGHEST LEVEL FARMAT ====\n\n", get_ru_name()); SimpCTX simp; if (g_do_cfs_opt) { IR_CFS_OPT co(this); co.perform(simp); ASSERT0(verify_irs(get_ir_list(), NULL, this)); } PassMgr * passmgr = initPassMgr(); ASSERT0(passmgr); if (g_build_cfs) { SIMP_is_record_cfs(&simp) = true; CfsMgr * cfsmgr = (CfsMgr*)passmgr->registerPass(PASS_CFS_MGR); ASSERT0(cfsmgr); SIMP_cfs_mgr(&simp) = cfsmgr; } simp.set_simp_cf(); set_ir_list(simplifyStmtList(get_ir_list(), &simp)); ASSERT0(verify_simp(get_ir_list(), simp)); ASSERT0(verify_irs(get_ir_list(), NULL, this)); if (g_cst_bb_list) { constructIRBBlist(); ASSERT0(verifyIRandBB(get_bb_list(), this)); set_ir_list(NULL); //All IRs have been moved to each IRBB. } if (g_do_cfg) { ASSERT0(g_cst_bb_list); IR_CFG * cfg = (IR_CFG*)passmgr->registerPass(PASS_CFG); ASSERT0(cfg); cfg->initCfg(oc); if (g_do_loop_ana) { ASSERT0(g_do_cfg_dom); cfg->LoopAnalysis(oc); } } if (g_do_ssa) { //Note lowering IR now may be too early and will be //a hindrance to optmizations. //low_to_pr_mode(oc); IR_SSA_MGR * ssamgr = (IR_SSA_MGR*)passmgr->registerPass(PASS_SSA_MGR); ASSERT0(ssamgr); ssamgr->construction(oc); } if (g_do_aa) { ASSERT0(g_cst_bb_list && OC_is_cfg_valid(oc)); IR_AA * aa = (IR_AA*)passmgr->registerPass(PASS_AA); ASSERT0(aa); aa->initAliasAnalysis(); aa->perform(oc); } if (g_do_du_ana) { ASSERT0(g_cst_bb_list && OC_is_cfg_valid(oc) && OC_is_aa_valid(oc)); IR_DU_MGR * dumgr = (IR_DU_MGR*)passmgr->registerPass(PASS_DU_MGR); ASSERT0(dumgr); UINT f = SOL_REACH_DEF|SOL_REF; //f |= SOL_AVAIL_REACH_DEF|SOL_AVAIL_EXPR|SOL_RU_REF; if (g_do_ivr) { f |= SOL_AVAIL_REACH_DEF|SOL_AVAIL_EXPR; } if (g_do_compute_available_exp) { f |= SOL_AVAIL_EXPR; } dumgr->perform(oc, f); dumgr->computeMDDUChain(oc); } if (g_do_expr_tab) { ASSERT0(g_cst_bb_list); IR_EXPR_TAB * exprtab = (IR_EXPR_TAB*)passmgr->registerPass(PASS_EXPR_TAB); ASSERT0(exprtab); exprtab->perform(oc); } if (g_do_cdg) { ASSERT0(g_cst_bb_list && OC_is_cfg_valid(oc)); CDG * cdg = (CDG*)passmgr->registerPass(PASS_CDG); ASSERT0(cdg); cdg->build(oc, *get_cfg()); } if (g_opt_level == NO_OPT) { return false; } /* Regenerate high level IR, and do high level optimizations. Now, I get one thing: We cannot or not very easy construct High Level Control IR, (IF,DO_LOOP,...) via analysing CFG. e.g: if (i > j) { //BB1 ... } else { return 2; //S1 } BB1 does not have a ipdom, so we can not find the indispensible 3 parts: True body, False body, and the Sibling node. Solution: We can scan IF stmt first, in order to mark start stmt and end stmt of IF. //AbsNode * an = REGION_analysis_instrument(this)->m_cfs_mgr->construct_abstract_cfs(); //Polyhedra optimization. //IR_POLY * poly = newPoly(); //if (poly->construct_poly(an)) { // poly->perform_poly_trans(); //} //delete poly; */ return true; }