void IR_GVN::comp_array_addr_ref(IR const* ir, bool & change) { IS_TRUE0(ir->is_st_array()); IR const* arr = IST_base(ir); comp_vn(ARR_base(arr), change); for (IR const* s = ARR_sub_list(arr); s != NULL; s = IR_next(s)) { comp_vn(s, change); } }
/* 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(); }
VN * IR_GVN::comp_array(IR const* exp, bool & change) { IS_TRUE0(IR_type(exp) == IR_ARRAY); for (IR const* s = ARR_sub_list(exp); s != NULL; s = IR_next(s)) { comp_vn(s, change); } VN * evn = m_ir2vn.get(IR_id(exp)); if (evn != NULL) { return evn; } evn = comp_mem(exp, change); if (evn != NULL) { return evn; } VN const* abase_vn = NULL; VN const* aofst_vn = NULL; if (((CARRAY*)exp)->get_dimn() == 1) { //only handle one dim array. abase_vn = comp_vn(ARR_base(exp), change); if (abase_vn == NULL) { return NULL; } aofst_vn = m_ir2vn.get(IR_id(ARR_sub_list(exp))); if (aofst_vn == NULL) { return NULL; } } else { return NULL; } DU_SET const* du = m_du->get_du_c(exp); if (du == NULL || du->get_elem_count() == 0) { //Array does not have any DEF. VN * x = register_qua_vn(IR_ARRAY, abase_vn, aofst_vn, register_int_vn(ARR_ofst(exp)), register_int_vn(exp->get_dt_size(m_dm))); if (m_ir2vn.get(IR_id(exp)) != x) { m_ir2vn.set(IR_id(exp), x); change = true; } return x; } IR const* exp_stmt = const_cast<IR*>(exp)->get_stmt(); IS_TRUE0(exp_stmt->is_stmt()); IR const* domdef = m_du->find_dom_def(exp, exp_stmt, du, false); if (domdef == NULL) { return NULL; } if (domdef->is_st_array() && IST_ofst(domdef) != ARR_ofst(exp)) { return NULL; } if (!domdef->is_st_array()) { return comp_array_by_anon_domdef(exp, abase_vn, aofst_vn, domdef, change); } IS_TRUE0(IR_type(domdef) == IR_IST); //Check if VN expression is match. IR const* narr = IST_base(domdef); IS_TRUE(((CARRAY*)narr)->get_dimn() == 1, ("only handle one dim array.")); VN const* b = m_ir2vn.get(IR_id(ARR_base(narr))); if (b == NULL || b != abase_vn) { return NULL; } VN const* o = m_ir2vn.get(IR_id(ARR_sub_list(narr))); if (o == NULL || o != aofst_vn) { return NULL; } VN * uni_vn = m_ir2vn.get(IR_id(domdef)); if (uni_vn == NULL) { uni_vn = register_qua_vn(IR_ARRAY, abase_vn, aofst_vn, register_int_vn(ARR_ofst(exp)), register_int_vn(exp->get_dt_size(m_dm))); m_ir2vn.set(IR_id(domdef), uni_vn); m_ir2vn.set(IR_id(narr), uni_vn); } m_ir2vn.set(IR_id(exp), uni_vn); change = true; return uni_vn; }