X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firopt.c;h=0c7cf979ae8f470c81f26de68611afad451fc02c;hb=7719bf6a7bd442f4763731d56d856cb082156877;hp=3f59816c049e25c3234aedc3aa5bef7bd5696af4;hpb=1a26f4853c07d1ecd68a097409dd602edfe29eff;p=libfirm diff --git a/ir/ir/iropt.c b/ir/ir/iropt.c index 3f59816c0..0c7cf979a 100644 --- a/ir/ir/iropt.c +++ b/ir/ir/iropt.c @@ -696,9 +696,9 @@ static tarval *computed_value_Proj(const ir_node *proj) */ tarval *computed_value(const ir_node *n) { - if (mode_is_int(get_irn_mode(n)) && n->vrp.valid && tarval_is_all_one( - tarval_or(n->vrp.bits_set, n->vrp.bits_not_set))) { - return n->vrp.bits_set; + vrp_attr *vrp = vrp_get_info(n); + if (vrp && vrp->valid && tarval_cmp(vrp->bits_set, vrp->bits_not_set) == pn_Cmp_Eq) { + return vrp->bits_set; } if (n->op->ops.computed_value) return n->op->ops.computed_value(n); @@ -753,7 +753,8 @@ static ir_op_ops *firm_set_default_computed_value(ir_opcode code, ir_op_ops *ops CASE_PROJ(Quot); CASE(Proj); default: - /* leave NULL */; + /* leave NULL */ + break; } return ops; @@ -1698,7 +1699,7 @@ static ir_node *equivalent_node_Proj_Bound(ir_node *proj) break; default: /* cannot optimize pn_Bound_X_regular, handled in transform ... */ - ; + break; } } return proj; @@ -1979,7 +1980,8 @@ static ir_op_ops *firm_set_default_equivalent_node(ir_opcode code, ir_op_ops *op CASE(Mux); CASE(Confirm); default: - /* leave NULL */; + /* leave NULL */ + break; } return ops; @@ -2278,6 +2280,7 @@ static ir_node *transform_node_AddSub(ir_node *n) } /* transform_node_AddSub */ #define HANDLE_BINOP_PHI(eval, a, b, c, mode) \ + do { \ c = NULL; \ if (is_Const(b) && is_const_Phi(a)) { \ /* check for Op(Phi, Const) */ \ @@ -2294,9 +2297,11 @@ static ir_node *transform_node_AddSub(ir_node *n) if (c) { \ DBG_OPT_ALGSIM0(oldn, c, FS_OPT_CONST_PHI); \ return c; \ - } + } \ + } while(0) #define HANDLE_UNOP_PHI(eval, a, c) \ + do { \ c = NULL; \ if (is_const_Phi(a)) { \ /* check for Op(Phi) */ \ @@ -2305,7 +2310,8 @@ static ir_node *transform_node_AddSub(ir_node *n) DBG_OPT_ALGSIM0(oldn, c, FS_OPT_CONST_PHI); \ return c; \ } \ - } + } \ + } while(0) /** * Do the AddSub optimization, then Transform @@ -2320,6 +2326,7 @@ static ir_node *transform_node_Add(ir_node *n) { ir_mode *mode; ir_node *a, *b, *c, *oldn = n; + vrp_attr *a_vrp, *b_vrp; n = transform_node_AddSub(n); @@ -2331,7 +2338,7 @@ static ir_node *transform_node_Add(ir_node *n) if (mode_is_reference(mode)) { ir_mode *lmode = get_irn_mode(a); - if (is_Const(b) && is_Const_null(b) && mode_is_int(lmode)) { + if (is_Const(b) && is_Const_null(b) && mode_is_int(lmode)) { /* an Add(a, NULL) is a hidden Conv */ dbg_info *dbg = get_irn_dbg_info(n); return new_rd_Conv(dbg, get_nodes_block(n), a, mode); @@ -2410,10 +2417,14 @@ static ir_node *transform_node_Add(ir_node *n) } } } - if (mode_is_int(mode) && a->vrp.valid && b->vrp.valid) { + + a_vrp = vrp_get_info(a); + b_vrp = vrp_get_info(b); + + if (a_vrp && b_vrp) { tarval *c = tarval_and( - tarval_not(a->vrp.bits_not_set), - tarval_not(b->vrp.bits_not_set) + a_vrp->bits_not_set, + b_vrp->bits_not_set ); if (tarval_is_null(c)) { @@ -2666,7 +2677,7 @@ restart: get_irn_dbg_info(n), blk, mb, - new_Const_long(mode, 1), + new_Const(get_mode_one(mode)), mode), mode); DBG_OPT_ALGSIM0(oldn, n, FS_OPT_SUB_MUL_A_X_A); @@ -2681,7 +2692,7 @@ restart: get_irn_dbg_info(n), blk, ma, - new_Const_long(mode, 1), + new_Const(get_mode_one(mode)), mode), mode); DBG_OPT_ALGSIM0(oldn, n, FS_OPT_SUB_MUL_A_X_A); @@ -3463,6 +3474,7 @@ static ir_node *transform_node_And(ir_node *n) ir_node *a = get_And_left(n); ir_node *b = get_And_right(n); ir_mode *mode; + vrp_attr *a_vrp, *b_vrp; mode = get_irn_mode(n); HANDLE_BINOP_PHI((eval_func) tarval_and, a, b, c, mode); @@ -3473,13 +3485,12 @@ static ir_node *transform_node_And(ir_node *n) ir_node *pred_b = get_Proj_pred(b); if (pred_a == pred_b) { dbg_info *dbgi = get_irn_dbg_info(n); - ir_node *block = get_nodes_block(pred_a); pn_Cmp pn_a = get_Proj_proj(a); pn_Cmp pn_b = get_Proj_proj(b); /* yes, we can simply calculate with pncs */ pn_Cmp new_pnc = pn_a & pn_b; - return new_rd_Proj(dbgi, block, pred_a, mode_b, new_pnc); + return new_rd_Proj(dbgi, pred_a, mode_b, new_pnc); } } if (is_Or(a)) { @@ -3583,18 +3594,18 @@ static ir_node *transform_node_And(ir_node *n) return n; } - if (is_Const(a) && b->vrp.valid && (tarval_is_all_one(tarval_or(get_Const_tarval(a), - b->vrp.bits_not_set)))) { - return new_rd_Id(get_irn_dbg_info(n), get_nodes_block(n), - b, get_irn_mode(n)); + b_vrp = vrp_get_info(b); + if (is_Const(a) && b_vrp && (tarval_cmp(tarval_or(get_Const_tarval(a), + b_vrp->bits_not_set), get_Const_tarval(a)) == pn_Cmp_Eq)) { - } + return b; - if (is_Const(b) && a->vrp.valid && (tarval_is_all_one(tarval_or(get_Const_tarval(b), - a->vrp.bits_not_set)))) { - return new_rd_Id(get_irn_dbg_info(n), get_nodes_block(n), - a, get_irn_mode(n)); + } + a_vrp = vrp_get_info(a); + if (is_Const(b) && a_vrp && (tarval_cmp(tarval_or(get_Const_tarval(b), + a_vrp->bits_not_set), get_Const_tarval(b)) == pn_Cmp_Eq)) { + return a; } n = transform_bitwise_distributive(n, transform_node_And); @@ -3620,13 +3631,12 @@ static ir_node *transform_node_Eor(ir_node *n) ir_node *pred_b = get_Proj_pred(b); if (pred_a == pred_b) { dbg_info *dbgi = get_irn_dbg_info(n); - ir_node *block = get_nodes_block(pred_a); pn_Cmp pn_a = get_Proj_proj(a); pn_Cmp pn_b = get_Proj_proj(b); /* yes, we can simply calculate with pncs */ pn_Cmp new_pnc = pn_a ^ pn_b; - return new_rd_Proj(dbgi, block, pred_a, mode_b, new_pnc); + return new_rd_Proj(dbgi, pred_a, mode_b, new_pnc); } } @@ -3670,9 +3680,8 @@ static ir_node *transform_node_Not(ir_node *n) if (mode == mode_b && is_Proj(a)) { ir_node *a_pred = get_Proj_pred(a); if (is_Cmp(a_pred)) { - ir_node *cmp_block = get_nodes_block(a_pred); /* We negate a Cmp. The Cmp has the negated result anyways! */ - n = new_r_Proj(cmp_block, get_Proj_pred(a), + n = new_r_Proj(get_Proj_pred(a), mode_b, get_negated_pnc(get_Proj_proj(a), mode_b)); DBG_OPT_ALGSIM0(oldn, n, FS_OPT_NOT_CMP); return n; @@ -4085,31 +4094,32 @@ static ir_node *transform_node_Proj_Cond(ir_node *proj) } } else { long num = get_Proj_proj(proj); - if (num != get_Cond_default_proj(n) && b->vrp.valid) { + vrp_attr *b_vrp = vrp_get_info(b); + if (num != get_Cond_default_proj(n) && b_vrp) { /* Try handling with vrp data. We only remove dead parts. */ tarval *tp = new_tarval_from_long(num, get_irn_mode(b)); - if (b->vrp.range_type == VRP_RANGE) { - pn_Cmp cmp_result = tarval_cmp(b->vrp.range_bottom, tp); - pn_Cmp cmp_result2 = tarval_cmp(b->vrp.range_top, tp); + if (b_vrp->range_type == VRP_RANGE) { + pn_Cmp cmp_result = tarval_cmp(b_vrp->range_bottom, tp); + pn_Cmp cmp_result2 = tarval_cmp(b_vrp->range_top, tp); - if ((cmp_result & pn_Cmp_Lt) == cmp_result && (cmp_result2 - & pn_Cmp_Gt) == cmp_result2) { + if ((cmp_result & pn_Cmp_Gt) == cmp_result && (cmp_result2 + & pn_Cmp_Lt) == cmp_result2) { return get_irg_bad(current_ir_graph); } - } else if (b->vrp.range_type == VRP_ANTIRANGE) { - pn_Cmp cmp_result = tarval_cmp(b->vrp.range_bottom, tp); - pn_Cmp cmp_result2 = tarval_cmp(b->vrp.range_top, tp); + } else if (b_vrp->range_type == VRP_ANTIRANGE) { + pn_Cmp cmp_result = tarval_cmp(b_vrp->range_bottom, tp); + pn_Cmp cmp_result2 = tarval_cmp(b_vrp->range_top, tp); - if ((cmp_result & pn_Cmp_Ge) == cmp_result && (cmp_result2 - & pn_Cmp_Le) == cmp_result2) { + if ((cmp_result & pn_Cmp_Le) == cmp_result && (cmp_result2 + & pn_Cmp_Ge) == cmp_result2) { return get_irg_bad(current_ir_graph); } } if (!(tarval_cmp( - tarval_and( b->vrp.bits_set, tp), - b->vrp.bits_set + tarval_and( b_vrp->bits_set, tp), + b_vrp->bits_set ) == pn_Cmp_Eq)) { return get_irg_bad(current_ir_graph); @@ -4118,8 +4128,8 @@ static ir_node *transform_node_Proj_Cond(ir_node *proj) if (!(tarval_cmp( tarval_and( tarval_not(tp), - b->vrp.bits_not_set), - b->vrp.bits_not_set) + tarval_not(b_vrp->bits_not_set)), + tarval_not(b_vrp->bits_not_set)) == pn_Cmp_Eq)) { return get_irg_bad(current_ir_graph); @@ -4785,7 +4795,7 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) /* create a new compare */ n = new_rd_Cmp(get_irn_dbg_info(n), block, left, right); - proj = new_rd_Proj(get_irn_dbg_info(proj), block, n, get_irn_mode(proj), proj_nr); + proj = new_rd_Proj(get_irn_dbg_info(proj), n, get_irn_mode(proj), proj_nr); } return proj; @@ -5168,13 +5178,12 @@ static ir_node *transform_node_Or(ir_node *n) ir_node *pred_b = get_Proj_pred(b); if (pred_a == pred_b) { dbg_info *dbgi = get_irn_dbg_info(n); - ir_node *block = get_nodes_block(pred_a); pn_Cmp pn_a = get_Proj_proj(a); pn_Cmp pn_b = get_Proj_proj(b); /* yes, we can simply calculate with pncs */ pn_Cmp new_pnc = pn_a | pn_b; - return new_rd_Proj(dbgi, block, pred_a, mode_b, new_pnc); + return new_rd_Proj(dbgi, pred_a, mode_b, new_pnc); } } @@ -5359,7 +5368,6 @@ static ir_node *transform_node_shl_shr(ir_node *n) ir_node *left; ir_node *right = get_binop_right(n); ir_node *x; - ir_graph *irg; ir_node *block; ir_mode *mode; dbg_info *dbgi; @@ -5424,7 +5432,6 @@ static ir_node *transform_node_shl_shr(ir_node *n) assert(tv_mask != tarval_bad); assert(get_tarval_mode(tv_mask) == mode); - irg = get_irn_irg(n); block = get_nodes_block(n); dbgi = get_irn_dbg_info(n); @@ -5711,7 +5718,7 @@ static ir_node *transform_node_Mux(ir_node *n) /* Mux(x, 0, y) => Mux(x, y, 0) */ pn_Cmp pnc = get_Proj_proj(sel); - sel = new_r_Proj(get_nodes_block(cmp), cmp, mode_b, + sel = new_r_Proj(cmp, mode_b, get_negated_pnc(pnc, get_irn_mode(get_Cmp_left(cmp)))); n = new_rd_Mux(get_irn_dbg_info(n), get_nodes_block(n), sel, t, f, mode); tmp = t; @@ -6135,7 +6142,7 @@ static int node_cmp_attr_Const(ir_node *a, ir_node *b) /** Compares the attributes of two Proj nodes. */ static int node_cmp_attr_Proj(ir_node *a, ir_node *b) { - return get_irn_proj_attr(a) != get_irn_proj_attr(b); + return a->attr.proj != b->attr.proj; } /* node_cmp_attr_Proj */ /** Compares the attributes of two Filter nodes. */ @@ -6147,24 +6154,24 @@ static int node_cmp_attr_Filter(ir_node *a, ir_node *b) /** Compares the attributes of two Alloc nodes. */ static int node_cmp_attr_Alloc(ir_node *a, ir_node *b) { - const alloc_attr *pa = get_irn_alloc_attr(a); - const alloc_attr *pb = get_irn_alloc_attr(b); + const alloc_attr *pa = &a->attr.alloc; + const alloc_attr *pb = &b->attr.alloc; return (pa->where != pb->where) || (pa->type != pb->type); } /* node_cmp_attr_Alloc */ /** Compares the attributes of two Free nodes. */ static int node_cmp_attr_Free(ir_node *a, ir_node *b) { - const free_attr *pa = get_irn_free_attr(a); - const free_attr *pb = get_irn_free_attr(b); + const free_attr *pa = &a->attr.free; + const free_attr *pb = &b->attr.free; return (pa->where != pb->where) || (pa->type != pb->type); } /* node_cmp_attr_Free */ /** Compares the attributes of two SymConst nodes. */ static int node_cmp_attr_SymConst(ir_node *a, ir_node *b) { - const symconst_attr *pa = get_irn_symconst_attr(a); - const symconst_attr *pb = get_irn_symconst_attr(b); + const symconst_attr *pa = &a->attr.symc; + const symconst_attr *pb = &b->attr.symc; return (pa->kind != pb->kind) || (pa->sym.type_p != pb->sym.type_p) || (pa->tp != pb->tp); @@ -6173,8 +6180,8 @@ static int node_cmp_attr_SymConst(ir_node *a, ir_node *b) /** Compares the attributes of two Call nodes. */ static int node_cmp_attr_Call(ir_node *a, ir_node *b) { - const call_attr *pa = get_irn_call_attr(a); - const call_attr *pb = get_irn_call_attr(b); + const call_attr *pa = &a->attr.call; + const call_attr *pb = &b->attr.call; return (pa->type != pb->type) || (pa->tail_call != pb->tail_call); } /* node_cmp_attr_Call */ @@ -6184,16 +6191,6 @@ static int node_cmp_attr_Sel(ir_node *a, ir_node *b) { const ir_entity *a_ent = get_Sel_entity(a); const ir_entity *b_ent = get_Sel_entity(b); -#if 0 - return - (a_ent->kind != b_ent->kind) || - (a_ent->name != b_ent->name) || - (a_ent->owner != b_ent->owner) || - (a_ent->ld_name != b_ent->ld_name) || - (a_ent->type != b_ent->type); -#endif - /* Matze: inlining of functions can produce 2 entities with same type, - * name, etc. */ return a_ent != b_ent; } /* node_cmp_attr_Sel */ @@ -6204,7 +6201,7 @@ static int node_cmp_attr_Phi(ir_node *a, ir_node *b) hence it is enough to check if one of them is a Phi0 */ if (is_Phi0(a)) { /* check the Phi0 pos attribute */ - return get_irn_phi_attr(a)->u.pos != get_irn_phi_attr(b)->u.pos; + return a->attr.phi.u.pos != b->attr.phi.u.pos; } return 0; } /* node_cmp_attr_Phi */ @@ -6250,8 +6247,8 @@ static int node_cmp_attr_Store(ir_node *a, ir_node *b) /** Compares two exception attributes */ static int node_cmp_exception(ir_node *a, ir_node *b) { - const except_attr *ea = get_irn_except_attr(a); - const except_attr *eb = get_irn_except_attr(b); + const except_attr *ea = &a->attr.except; + const except_attr *eb = &b->attr.except; return ea->pin_state != eb->pin_state; } @@ -6261,8 +6258,8 @@ static int node_cmp_exception(ir_node *a, ir_node *b) /** Compares the attributes of two Div nodes. */ static int node_cmp_attr_Div(ir_node *a, ir_node *b) { - const divmod_attr *ma = get_irn_divmod_attr(a); - const divmod_attr *mb = get_irn_divmod_attr(b); + const divmod_attr *ma = &a->attr.divmod; + const divmod_attr *mb = &b->attr.divmod; return ma->exc.pin_state != mb->exc.pin_state || ma->resmode != mb->resmode || ma->no_remainder != mb->no_remainder; @@ -6271,8 +6268,8 @@ static int node_cmp_attr_Div(ir_node *a, ir_node *b) /** Compares the attributes of two DivMod nodes. */ static int node_cmp_attr_DivMod(ir_node *a, ir_node *b) { - const divmod_attr *ma = get_irn_divmod_attr(a); - const divmod_attr *mb = get_irn_divmod_attr(b); + const divmod_attr *ma = &a->attr.divmod; + const divmod_attr *mb = &b->attr.divmod; return ma->exc.pin_state != mb->exc.pin_state || ma->resmode != mb->resmode; } /* node_cmp_attr_DivMod */ @@ -6280,19 +6277,13 @@ static int node_cmp_attr_DivMod(ir_node *a, ir_node *b) /** Compares the attributes of two Mod nodes. */ static int node_cmp_attr_Mod(ir_node *a, ir_node *b) { - const divmod_attr *ma = get_irn_divmod_attr(a); - const divmod_attr *mb = get_irn_divmod_attr(b); - return ma->exc.pin_state != mb->exc.pin_state || - ma->resmode != mb->resmode; + return node_cmp_attr_DivMod(a, b); } /* node_cmp_attr_Mod */ /** Compares the attributes of two Quot nodes. */ static int node_cmp_attr_Quot(ir_node *a, ir_node *b) { - const divmod_attr *ma = get_irn_divmod_attr(a); - const divmod_attr *mb = get_irn_divmod_attr(b); - return ma->exc.pin_state != mb->exc.pin_state || - ma->resmode != mb->resmode; + return node_cmp_attr_DivMod(a, b); } /* node_cmp_attr_Quot */ /** Compares the attributes of two Confirm nodes. */ @@ -6305,11 +6296,8 @@ static int node_cmp_attr_Confirm(ir_node *a, ir_node *b) /** Compares the attributes of two Builtin nodes. */ static int node_cmp_attr_Builtin(ir_node *a, ir_node *b) { - const builtin_attr *ma = get_irn_builtin_attr(a); - const builtin_attr *mb = get_irn_builtin_attr(b); - /* no need to compare the type, equal kind means equal type */ - return ma->kind != mb->kind; + return get_Builtin_kind(a) != get_Builtin_kind(b); } /* node_cmp_attr_Builtin */ /** Compares the attributes of two ASM nodes. */ @@ -6408,7 +6396,8 @@ static ir_op_ops *firm_set_default_node_cmp_attr(ir_opcode code, ir_op_ops *ops) CASE(Dummy); /* FIXME CopyB */ default: - /* leave NULL */; + /* leave NULL */ + break; } return ops; @@ -6958,7 +6947,7 @@ static unsigned hash_Const(const ir_node *node) unsigned h; /* special value for const, as they only differ in their tarval. */ - h = HASH_PTR(node->attr.con.tv); + h = HASH_PTR(node->attr.con.tarval); return h; } /* hash_Const */