//Canonicalize det of IF. //e.g: if (a=10,b+=3,c<a) {...} //be replaced by // a = 10; // b += 3; // if (c<a) {...} bool IR_CFS_OPT::hoistIf(IR ** head, IR * ir) { ASSERT(ir->is_if(), ("need IF")); ASSERT(IF_det(ir), ("DET is NULL")); IR * det = IF_det(ir); INT i = 0; while (det != NULL) { i++; det = det->get_next(); } IR * new_list = NULL; if (i > 1) { det = IF_det(ir); while (i > 1) { IR * c = det; ASSERT(c->is_stmt(), ("Non-stmt ir should be remove during reshape_ir_tree()")); det = det->get_next(); xcom::remove(&IF_det(ir), c); xcom::add_next(&new_list, c); i--; } xcom::insertbefore(head, ir, new_list); return true; } return false; }
//Hoist det of loop. //e.g: while (a=10,b+=3,c<a) { // IR-List; // } // //be replaced by // // a = 10; // b += 3; // while (c<a) { // IR-List; // a = 10; // b += 3; // } bool IR_CFS_OPT::hoistLoop(IR ** head, IR * ir) { ASSERT0(ir->is_dowhile() || ir->is_whiledo() || ir->is_doloop()); ASSERT(LOOP_det(ir), ("DET is NULL")); IR * det = LOOP_det(ir); INT i = 0; while (det != NULL) { i++; det = det->get_next(); } IR * new_list = NULL, * new_body_list = NULL; if (i > 1) { det = LOOP_det(ir); while (i > 1) { IR * c = det; ASSERT(c->is_stmt(), ("Non-stmt ir should be remove " "during reshape_ir_tree()")); det = det->get_next(); xcom::remove(&LOOP_det(ir), c); xcom::add_next(&new_list, c); i--; } new_body_list = m_ru->dupIRTreeList(new_list); xcom::insertbefore(head, ir, new_list); xcom::add_next(&LOOP_body(ir), new_body_list); return true; } return false; }
/* Canonicalize det of IF. e.g: if (a=10,b+=3,c<a) {...} be replaced by a = 10; b += 3; if (c<a) {...} */ bool IR_CFS_OPT::hoist_if(IR ** head, IR * ir) { IS_TRUE(IR_type(ir) == IR_IF, ("need IF")); IS_TRUE(IF_det(ir), ("DET is NULL")); IR * det = IF_det(ir); INT i = 0; while (det != NULL) { i++; det = IR_next(det); } IR * new_list = NULL; if (i > 1) { det = IF_det(ir); while (i > 1) { IR * c = det; IS_TRUE(c->is_stmt(), ("Non-stmt ir should be remove during reshape_ir_tree()")); det = IR_next(det); remove(&IF_det(ir), c); add_next(&new_list, c); i--; } insertbefore(head, ir, new_list); return true; } return false; }
/* Hoist det of loop. e.g: while (a=10,b+=3,c<a) { IR-LIST; } be replaced by a = 10; b += 3; while (c<a) { IR-LIST; a = 10; b += 3; } */ bool IR_CFS_OPT::hoist_loop(IR ** head, IR * ir) { IS_TRUE(IR_type(ir)==IR_DO_WHILE || IR_type(ir)==IR_WHILE_DO || IR_type(ir)==IR_DO_LOOP, ("need LOOP")); IS_TRUE(LOOP_det(ir), ("DET is NULL")); IR * det = LOOP_det(ir); INT i = 0; while (det != NULL) { i++; det = IR_next(det); } IR * new_list = NULL, * new_body_list = NULL; if (i > 1) { det = LOOP_det(ir); while (i > 1) { IR * c = det; IS_TRUE(c->is_stmt(), ("Non-stmt ir should be remove " "during reshape_ir_tree()")); det = IR_next(det); remove(&LOOP_det(ir), c); add_next(&new_list, c); i--; } new_body_list = m_ru->dup_irs_list(new_list); insertbefore(head, ir, new_list); add_next(&LOOP_body(ir), new_body_list); return true; } return false; }
/* Encode expression for single BB. Scan IR statement literally, and encoding it for generating the unique id for each individual expressions, and update the 'GEN-SET' and 'KILL-SET' of IR-EXPR for BB as well as. */ void IR_EXPR_TAB::encode_bb(IRBB * bb) { C<IR*> * ct; for (IR * ir = BB_irlist(bb).get_head(&ct); ir != NULL; ir = BB_irlist(bb).get_next(&ct)) { ASSERT0(ir->is_stmt()); switch (IR_code(ir)) { case IR_ST: { ExpRep * ie = encode_expr(ST_rhs(ir)); if (ie != NULL) { set_map_ir2ir_expr(ST_rhs(ir), ie); } } break; case IR_STPR: { ExpRep * ie = encode_expr(STPR_rhs(ir)); if (ie != NULL) { set_map_ir2ir_expr(STPR_rhs(ir), ie); } } break; case IR_STARRAY: { ExpRep * ie = encode_expr(ARR_base(ir)); if (ie != NULL) { set_map_ir2ir_expr(ARR_base(ir), ie); } for (IR * sub = ARR_sub_list(ir); sub != NULL; sub = IR_next(sub)) { ExpRep * ie = encode_expr(sub); if (ie != NULL) { set_map_ir2ir_expr(sub, ie); } } ie = encode_expr(STARR_rhs(ir)); if (ie != NULL) { set_map_ir2ir_expr(STARR_rhs(ir), ie); } } break; case IR_IST: { ExpRep * ie = encode_expr(IST_rhs(ir)); if (ie != NULL) { set_map_ir2ir_expr(IST_rhs(ir), ie); } ie = encode_istore_memaddr(IST_base(ir)); if (ie != NULL) { set_map_ir2ir_expr(IST_base(ir), ie); } } break; case IR_ICALL: //indirective call { ExpRep * ie = encode_expr(ICALL_callee(ir)); if (ie != NULL) { set_map_ir2ir_expr(ICALL_callee(ir), ie); } } case IR_CALL: { IR * parm = CALL_param_list(ir); while (parm != NULL) { ExpRep * ie = encode_expr(parm); if (ie != NULL) { set_map_ir2ir_expr(parm, ie); } parm = IR_next(parm); } } break; case IR_GOTO: break; case IR_IGOTO: { ExpRep * ie = encode_expr(IGOTO_vexp(ir)); if (ie != NULL) { set_map_ir2ir_expr(IGOTO_vexp(ir), ie); } } break; case IR_DO_WHILE: case IR_WHILE_DO: case IR_DO_LOOP: //loop with init , boundary , and step info case IR_IF: ASSERT(0, ("High level IR should be simplified")); break; case IR_LABEL: break; case IR_CASE: case IR_REGION: break; case IR_TRUEBR: case IR_FALSEBR: { ExpRep * ie = encode_expr(BR_det(ir)); if (ie != NULL) { set_map_ir2ir_expr(BR_det(ir), ie); } } break; case IR_SWITCH: { ExpRep * ie = encode_expr(SWITCH_vexp(ir)); if (ie != NULL) { set_map_ir2ir_expr(SWITCH_vexp(ir), ie); } } break; case IR_RETURN: { ExpRep * ie = encode_expr(RET_exp(ir)); if (ie != NULL) { set_map_ir2ir_expr(RET_exp(ir), ie); } } break; case IR_PHI: break; default: ASSERT0(0); } //end switch } //end for IR //dump_ir_expr_tab(); }
void PRDF::computeLocal(IRBB * bb, List<IR const*> & lst) { DefSBitSetCore * gen = get_def(BB_id(bb)); DefSBitSetCore * use = get_use(BB_id(bb)); gen->clean(m_sbs_mgr); use->clean(m_sbs_mgr); for (IR * x = BB_last_ir(bb); x != NULL; x = BB_prev_ir(bb)) { ASSERT0(x->is_stmt()); switch (IR_code(x)) { case IR_ST: lst.clean(); processOpnd(ST_rhs(x), lst, use, gen); break; case IR_STPR: gen->bunion(STPR_no(x), m_sbs_mgr); use->diff(STPR_no(x), m_sbs_mgr); processMay(x, gen, use, true); lst.clean(); processOpnd(STPR_rhs(x), lst, use, gen); break; case IR_SETELEM: gen->bunion(SETELEM_prno(x), m_sbs_mgr); use->diff(SETELEM_prno(x), m_sbs_mgr); processMay(x, gen, use, true); lst.clean(); processOpnd(SETELEM_rhs(x), lst, use, gen); lst.clean(); processOpnd(SETELEM_ofst(x), lst, use, gen); break; case IR_GETELEM: gen->bunion(GETELEM_prno(x), m_sbs_mgr); use->diff(GETELEM_prno(x), m_sbs_mgr); processMay(x, gen, use, true); lst.clean(); processOpnd(GETELEM_base(x), lst, use, gen); lst.clean(); processOpnd(GETELEM_ofst(x), lst, use, gen); break; case IR_STARRAY: lst.clean(); processOpnd(x, lst, use, gen); break; case IR_IST: lst.clean(); processOpnd(x, lst, use, gen); break; case IR_SWITCH: lst.clean(); processOpnd(SWITCH_vexp(x), lst, use, gen); break; case IR_IGOTO: lst.clean(); processOpnd(IGOTO_vexp(x), lst, use, gen); break; case IR_GOTO: break; case IR_CALL: case IR_ICALL: if (x->hasReturnValue()) { gen->bunion(CALL_prno(x), m_sbs_mgr); use->diff(CALL_prno(x), m_sbs_mgr); processMay(x, gen, use, true); } lst.clean(); processOpnd(CALL_param_list(x), lst, use, gen); if (x->is_icall() && ICALL_callee(x)->is_pr()) { use->bunion(PR_no(ICALL_callee(x)), m_sbs_mgr); processMay(ICALL_callee(x), gen, use, false); } break; case IR_TRUEBR: case IR_FALSEBR: lst.clean(); processOpnd(BR_det(x), lst, use, gen); break; case IR_RETURN: lst.clean(); processOpnd(RET_exp(x), lst, use, gen); break; case IR_PHI: gen->bunion(PHI_prno(x), m_sbs_mgr); use->diff(PHI_prno(x), m_sbs_mgr); processMay(x, gen, use, true); lst.clean(); processOpnd(PHI_opnd_list(x), lst, use, gen); break; case IR_REGION: break; default: ASSERT0(0); } } }