X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firopt.c;h=25d0cd8a185a0cb3fbabe4f603de93c82b90d3fc;hb=69d11aa49aa17358468bbb2f5506ef5f009514e9;hp=f1acccb3111c6de93664e4e562332728eeefaf52;hpb=14083b56a12675c3da21c26eeb8a8e021074b5c7;p=libfirm diff --git a/ir/ir/iropt.c b/ir/ir/iropt.c index f1acccb31..25d0cd8a1 100644 --- a/ir/ir/iropt.c +++ b/ir/ir/iropt.c @@ -42,7 +42,6 @@ #include "irhooks.h" #include "irarch.h" #include "hashptr.h" -#include "archop.h" #include "opt_confirms.h" #include "opt_polymorphy.h" #include "irtools.h" @@ -758,8 +757,8 @@ static ir_node *equivalent_node_Block(ir_node *n) ir_node *oldn = n; int n_preds; - /* don't optimize dead blocks */ - if (is_Block_dead(n)) + /* don't optimize dead or labeled blocks */ + if (is_Block_dead(n) || has_Block_label(n)) return n; n_preds = get_Block_n_cfgpreds(n); @@ -1169,13 +1168,28 @@ static ir_node *equivalent_node_And(ir_node *n) { DBG_OPT_ALGSIM0(oldn, n, FS_OPT_AND); return n; } - /* constants are cormalized to right, check this site first */ + /* constants are normalized to right, check this site first */ tv = value_of(b); if (tarval_is_all_one(tv)) { n = a; DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_AND); return n; } + if (tv != get_tarval_bad()) { + ir_mode *mode = get_irn_mode(n); + if (!mode_is_signed(mode) && is_Conv(a)) { + ir_node *convop = get_Conv_op(a); + ir_mode *convopmode = get_irn_mode(convop); + if (!mode_is_signed(convopmode)) { + if (tarval_is_all_one(tarval_convert_to(tv, convopmode))) { + /* Conv(X) & all_one(mode(X)) = Conv(X) */ + n = a; + DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_AND); + return n; + } + } + } + } tv = value_of(a); if (tarval_is_all_one(tv)) { n = b; @@ -1984,8 +1998,7 @@ static ir_node *apply_binop_on_phi(ir_node *phi, tarval *other, tarval *(*eval)( irg = current_ir_graph; for (i = 0; i < n; ++i) { pred = get_irn_n(phi, i); - res[i] = new_r_Const_type(irg, get_irg_start_block(irg), - mode, res[i], get_Const_type(pred)); + res[i] = new_r_Const_type(irg, res[i], get_Const_type(pred)); } return new_r_Phi(irg, get_nodes_block(phi), n, (ir_node **)res, mode); } /* apply_binop_on_phi */ @@ -2029,7 +2042,7 @@ static ir_node *apply_binop_on_2_phis(ir_node *a, ir_node *b, tarval *(*eval)(), irg = current_ir_graph; for (i = 0; i < n; ++i) { pred = get_irn_n(a, i); - res[i] = new_r_Const_type(irg, get_irg_start_block(irg), mode, res[i], get_Const_type(pred)); + res[i] = new_r_Const_type(irg, res[i], get_Const_type(pred)); } return new_r_Phi(irg, get_nodes_block(a), n, (ir_node **)res, mode); } /* apply_binop_on_2_phis */ @@ -2066,8 +2079,7 @@ static ir_node *apply_unop_on_phi(ir_node *phi, tarval *(*eval)(tarval *)) { irg = current_ir_graph; for (i = 0; i < n; ++i) { pred = get_irn_n(phi, i); - res[i] = new_r_Const_type(irg, get_irg_start_block(irg), - mode, res[i], get_Const_type(pred)); + res[i] = new_r_Const_type(irg, res[i], get_Const_type(pred)); } return new_r_Phi(irg, get_nodes_block(phi), n, (ir_node **)res, mode); } /* apply_unop_on_phi */ @@ -2101,8 +2113,7 @@ static ir_node *apply_conv_on_phi(ir_node *phi, ir_mode *mode) { irg = current_ir_graph; for (i = 0; i < n; ++i) { pred = get_irn_n(phi, i); - res[i] = new_r_Const_type(irg, get_irg_start_block(irg), - mode, res[i], get_Const_type(pred)); + res[i] = new_r_Const_type(irg, res[i], get_Const_type(pred)); } return new_r_Phi(irg, get_nodes_block(phi), n, (ir_node **)res, mode); } /* apply_conv_on_phi */ @@ -2259,7 +2270,7 @@ static ir_node *transform_node_Add(ir_node *n) { current_ir_graph, block, a, - new_r_Const_long(current_ir_graph, block, mode, 2), + new_Const_long(mode, 2), mode); DBG_OPT_ALGSIM0(oldn, n, FS_OPT_ADD_A_A); return n; @@ -2300,8 +2311,7 @@ static ir_node *transform_node_Add(ir_node *n) { } if (op == b) { /* ~x + x = -1 */ - ir_node *blk = get_nodes_block(n); - n = new_r_Const(current_ir_graph, blk, mode, get_mode_minus_one(mode)); + n = new_Const(get_mode_minus_one(mode)); DBG_OPT_ALGSIM0(oldn, n, FS_OPT_ADD_X_NOT_X); return n; } @@ -2311,8 +2321,7 @@ static ir_node *transform_node_Add(ir_node *n) { if (op == a) { /* x + ~x = -1 */ - ir_node *blk = get_nodes_block(n); - n = new_r_Const(current_ir_graph, blk, mode, get_mode_minus_one(mode)); + n = new_Const(get_mode_minus_one(mode)); DBG_OPT_ALGSIM0(oldn, n, FS_OPT_ADD_X_NOT_X); return n; } @@ -2329,10 +2338,8 @@ static ir_node *const_negate(ir_node *cnst) { tarval *tv = tarval_neg(get_Const_tarval(cnst)); dbg_info *dbgi = get_irn_dbg_info(cnst); ir_graph *irg = get_irn_irg(cnst); - ir_node *block = get_nodes_block(cnst); - ir_mode *mode = get_irn_mode(cnst); if (tv == tarval_bad) return NULL; - return new_rd_Const(dbgi, irg, block, mode, tv); + return new_rd_Const(dbgi, irg, tv); } /** @@ -2387,7 +2394,7 @@ restart: if (mode_is_float(mode) && (get_irg_fp_model(current_ir_graph) & fp_strict_algebraic)) return n; - if (is_Const(b) && get_irn_mode(b) != mode_P) { + if (is_Const(b) && !mode_is_reference(get_irn_mode(b))) { /* a - C -> a + (-C) */ ir_node *cnst = const_negate(b); if (cnst != NULL) { @@ -2429,7 +2436,7 @@ restart: ir_node *s_left = get_Sub_left(b); ir_node *s_right = get_Sub_right(b); ir_mode *s_mode = get_irn_mode(b); - if (s_mode == mode_P) { + if (mode_is_reference(s_mode)) { ir_node *sub = new_rd_Sub(s_dbg, irg, s_block, a, s_left, mode); dbg_info *a_dbg = get_irn_dbg_info(n); ir_node *a_block = get_nodes_block(n); @@ -2569,7 +2576,7 @@ restart: get_irn_dbg_info(n), current_ir_graph, blk, mb, - new_r_Const_long(current_ir_graph, blk, mode, 1), + new_Const_long(mode, 1), mode), mode); DBG_OPT_ALGSIM0(oldn, n, FS_OPT_SUB_MUL_A_X_A); @@ -2584,7 +2591,7 @@ restart: get_irn_dbg_info(n), current_ir_graph, blk, ma, - new_r_Const_long(current_ir_graph, blk, mode, 1), + new_Const_long(mode, 1), mode), mode); DBG_OPT_ALGSIM0(oldn, n, FS_OPT_SUB_MUL_A_X_A); @@ -2632,7 +2639,7 @@ restart: tv = tarval_add(tv, get_mode_one(mode)); if (tv != tarval_bad) { ir_node *blk = get_nodes_block(n); - ir_node *c = new_r_Const(current_ir_graph, blk, mode, tv); + ir_node *c = new_Const(tv); n = new_rd_Add(get_irn_dbg_info(n), current_ir_graph, blk, get_Not_op(b), c, mode); DBG_OPT_ALGSIM0(oldn, n, FS_OPT_SUB_C_NOT_X); return n; @@ -2822,7 +2829,7 @@ static ir_node *transform_node_Div(ir_node *n) { value = n; tv = value_of(n); if (tv != tarval_bad) { - value = new_Const(get_tarval_mode(tv), tv); + value = new_Const(tv); DBG_OPT_CSTEVAL(n, value); goto make_tuple; @@ -2833,7 +2840,7 @@ static ir_node *transform_node_Div(ir_node *n) { if (a == b && value_not_zero(a, &dummy)) { /* BEWARE: we can optimize a/a to 1 only if this cannot cause a exception */ - value = new_Const(mode, get_mode_one(mode)); + value = new_Const(get_mode_one(mode)); DBG_OPT_CSTEVAL(n, value); goto make_tuple; } else { @@ -2909,7 +2916,7 @@ static ir_node *transform_node_Mod(ir_node *n) { value = n; tv = value_of(n); if (tv != tarval_bad) { - value = new_Const(get_tarval_mode(tv), tv); + value = new_Const(tv); DBG_OPT_CSTEVAL(n, value); goto make_tuple; @@ -2920,7 +2927,7 @@ static ir_node *transform_node_Mod(ir_node *n) { if (a == b && value_not_zero(a, &dummy)) { /* BEWARE: we can optimize a%a to 0 only if this cannot cause a exception */ - value = new_Const(mode, get_mode_null(mode)); + value = new_Const(get_mode_null(mode)); DBG_OPT_CSTEVAL(n, value); goto make_tuple; } else { @@ -2929,7 +2936,7 @@ static ir_node *transform_node_Mod(ir_node *n) { if (tv == get_mode_minus_one(mode)) { /* a % -1 = 0 */ - value = new_Const(mode, get_mode_null(mode)); + value = new_Const(get_mode_null(mode)); DBG_OPT_CSTEVAL(n, value); goto make_tuple; } @@ -3006,7 +3013,7 @@ static ir_node *transform_node_DivMod(ir_node *n) { if (tb != tarval_bad) { if (tb == get_mode_one(get_tarval_mode(tb))) { va = a; - vb = new_Const(mode, get_mode_null(mode)); + vb = new_Const(get_mode_null(mode)); DBG_OPT_CSTEVAL(n, vb); goto make_tuple; } else if (ta != tarval_bad) { @@ -3016,14 +3023,14 @@ static ir_node *transform_node_DivMod(ir_node *n) { Jmp for X result!? */ resb = tarval_mod(ta, tb); if (resb == tarval_bad) return n; /* Causes exception! */ - va = new_Const(mode, resa); - vb = new_Const(mode, resb); + va = new_Const(resa); + vb = new_Const(resb); DBG_OPT_CSTEVAL(n, va); DBG_OPT_CSTEVAL(n, vb); goto make_tuple; } else if (mode_is_signed(mode) && tb == get_mode_minus_one(mode)) { va = new_rd_Minus(get_irn_dbg_info(n), current_ir_graph, get_nodes_block(n), a, mode); - vb = new_Const(mode, get_mode_null(mode)); + vb = new_Const(get_mode_null(mode)); DBG_OPT_CSTEVAL(n, va); DBG_OPT_CSTEVAL(n, vb); goto make_tuple; @@ -3036,8 +3043,8 @@ static ir_node *transform_node_DivMod(ir_node *n) { } else if (a == b) { if (value_not_zero(a, &dummy)) { /* a/a && a != 0 */ - va = new_Const(mode, get_mode_one(mode)); - vb = new_Const(mode, get_mode_null(mode)); + va = new_Const(get_mode_one(mode)); + vb = new_Const(get_mode_null(mode)); DBG_OPT_CSTEVAL(n, va); DBG_OPT_CSTEVAL(n, vb); goto make_tuple; @@ -3083,7 +3090,7 @@ static ir_node *transform_node_Quot(ir_node *n) { tarval *tv = value_of(b); if (tv != tarval_bad) { - int rem; + int rem = tarval_fp_ops_enabled(); /* * Floating point constant folding might be disabled here to @@ -3091,16 +3098,16 @@ static ir_node *transform_node_Quot(ir_node *n) { * However, as we check for exact result, doing it is safe. * Switch it on. */ - rem = tarval_enable_fp_ops(1); + tarval_enable_fp_ops(1); tv = tarval_quo(get_mode_one(mode), tv); - (void)tarval_enable_fp_ops(rem); + tarval_enable_fp_ops(rem); /* Do the transformation if the result is either exact or we are not using strict rules. */ if (tv != tarval_bad && (tarval_ieee754_get_exact() || (get_irg_fp_model(current_ir_graph) & fp_strict_algebraic) == 0)) { ir_node *blk = get_nodes_block(n); - ir_node *c = new_r_Const(current_ir_graph, blk, mode, tv); + ir_node *c = new_Const(tv); ir_node *a = get_Quot_left(n); ir_node *m = new_rd_Mul(get_irn_dbg_info(n), current_ir_graph, blk, a, c, mode); ir_node *mem = get_Quot_mem(n); @@ -3505,8 +3512,8 @@ static ir_node *transform_node_Eor(ir_node *n) { if (a == b) { /* a ^ a = 0 */ - n = new_rd_Const(get_irn_dbg_info(n), current_ir_graph, get_nodes_block(n), - mode, get_mode_null(mode)); + n = new_rd_Const(get_irn_dbg_info(n), current_ir_graph, + get_mode_null(mode)); DBG_OPT_ALGSIM0(oldn, n, FS_OPT_EOR_A_A); } else if (mode == mode_b && is_Proj(a) && @@ -3519,7 +3526,7 @@ static ir_node *transform_node_Eor(ir_node *n) { DBG_OPT_ALGSIM0(oldn, n, FS_OPT_EOR_TO_NOT_BOOL); } else if (is_Const(b)) { if (is_Not(a)) { /* ~x ^ const -> x ^ ~const */ - ir_node *cnst = new_Const(mode, tarval_not(get_Const_tarval(b))); + ir_node *cnst = new_Const(tarval_not(get_Const_tarval(b))); ir_node *not_op = get_Not_op(a); dbg_info *dbg = get_irn_dbg_info(n); ir_graph *irg = current_ir_graph; @@ -3561,7 +3568,7 @@ static ir_node *transform_node_Not(ir_node *n) { if (is_Eor(a)) { ir_node *eor_b = get_Eor_right(a); if (is_Const(eor_b)) { /* ~(x ^ const) -> x ^ ~const */ - ir_node *cnst = new_Const(mode, tarval_not(get_Const_tarval(eor_b))); + ir_node *cnst = new_Const(tarval_not(get_Const_tarval(eor_b))); ir_node *eor_a = get_Eor_left(a); dbg_info *dbg = get_irn_dbg_info(n); ir_graph *irg = current_ir_graph; @@ -3577,7 +3584,7 @@ static ir_node *transform_node_Not(ir_node *n) { ir_graph *irg = current_ir_graph; ir_node *block = get_nodes_block(n); ir_node *add_l = get_Minus_op(a); - ir_node *add_r = new_rd_Const(dbg, irg, block, mode, get_mode_minus_one(mode)); + ir_node *add_r = new_rd_Const(dbg, irg, get_mode_minus_one(mode)); n = new_rd_Add(dbg, irg, block, add_l, add_r, mode); } else if (is_Add(a)) { ir_node *add_r = get_Add_right(a); @@ -3617,7 +3624,7 @@ static ir_node *transform_node_Minus(ir_node *n) { ir_node *op = get_Not_op(a); tarval *tv = get_mode_one(mode); ir_node *blk = get_nodes_block(n); - ir_node *c = new_r_Const(current_ir_graph, blk, mode, tv); + ir_node *c = new_Const(tv); n = new_rd_Add(get_irn_dbg_info(n), current_ir_graph, blk, op, c, mode); DBG_OPT_ALGSIM2(oldn, a, n, FS_OPT_MINUS_NOT); return n; @@ -3673,7 +3680,7 @@ static ir_node *transform_node_Minus(ir_node *n) { if (tv != tarval_bad) { tv = tarval_neg(tv); if (tv != tarval_bad) { - ir_node *cnst = new_Const(mode, tv); + ir_node *cnst = new_Const(tv); dbg_info *dbg = get_irn_dbg_info(a); ir_graph *irg = current_ir_graph; ir_node *block = get_nodes_block(a); @@ -3696,8 +3703,7 @@ static ir_node *transform_node_Cast(ir_node *n) { ir_type *tp = get_irn_type(n); if (is_Const(pred) && get_Const_type(pred) != tp) { - n = new_rd_Const_type(NULL, current_ir_graph, get_irn_n(pred, -1), get_irn_mode(pred), - get_Const_tarval(pred), tp); + n = new_rd_Const_type(NULL, current_ir_graph, get_Const_tarval(pred), tp); DBG_OPT_CSTEVAL(oldn, n); } else if (is_SymConst(pred) && get_SymConst_value_type(pred) != tp) { n = new_rd_SymConst_type(NULL, current_ir_graph, get_irn_n(pred, -1), get_irn_mode(pred), @@ -3864,7 +3870,7 @@ static ir_node *transform_node_Proj_Mod(ir_node *proj) { if (get_Mod_left(mod) == b) { /* a % a = 0 if a != 0 */ ir_mode *mode = get_irn_mode(proj); - ir_node *res = new_Const(mode, get_mode_null(mode)); + ir_node *res = new_Const(get_mode_null(mode)); DBG_OPT_CSTEVAL(mod, res); return res; @@ -3923,7 +3929,7 @@ static ir_node *transform_node_Proj_DivMod(ir_node *proj) { if (get_DivMod_left(divmod) == b) { /* a % a = 0 if a != 0 */ ir_mode *mode = get_irn_mode(proj); - ir_node *res = new_Const(mode, get_mode_null(mode)); + ir_node *res = new_Const(get_mode_null(mode)); DBG_OPT_CSTEVAL(divmod, res); return res; @@ -3948,7 +3954,7 @@ static ir_node *transform_node_Proj_Cond(ir_node *proj) { /* we have a constant switch */ long num = get_Proj_proj(proj); - if (num != get_Cond_defaultProj(n)) { /* we cannot optimize default Proj's yet */ + if (num != get_Cond_default_proj(n)) { /* we cannot optimize default Proj's yet */ if (get_tarval_long(tb) == num) { /* Do NOT create a jump here, or we will have 2 control flow ops * in a block. This case is optimized away in optimize_cf(). */ @@ -3969,7 +3975,7 @@ static ir_node *transform_node_Proj_Cond(ir_node *proj) { */ static ir_node *create_zero_const(ir_mode *mode) { tarval *tv = get_mode_null(mode); - ir_node *cnst = new_Const(mode, tv); + ir_node *cnst = new_Const(tv); return cnst; } @@ -4016,12 +4022,12 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) { /* we can evaluate some cases directly */ switch (proj_nr) { case pn_Cmp_False: - return new_Const(mode_b, get_tarval_b_false()); + return new_Const(get_tarval_b_false()); case pn_Cmp_True: - return new_Const(mode_b, get_tarval_b_true()); + return new_Const(get_tarval_b_true()); case pn_Cmp_Leg: if (!mode_is_float(get_irn_mode(left))) - return new_Const(mode_b, get_tarval_b_true()); + return new_Const(get_tarval_b_true()); break; default: break; @@ -4204,8 +4210,8 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) { tarval *mask = tarval_shl(c2, c1); tarval *value = tarval_shl(c3, c1); - left = new_rd_And(dbg, irg, block, get_Shr_left(ll), new_Const(mode, mask), mode); - right = new_Const(mode, value); + left = new_rd_And(dbg, irg, block, get_Shr_left(ll), new_Const(mask), mode); + right = new_Const(value); changed |= 1; } } @@ -4437,7 +4443,7 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) { if (mask != tv) { /* TODO: move to constant evaluation */ tv = proj_nr == pn_Cmp_Eq ? get_tarval_b_false() : get_tarval_b_true(); - c1 = new_Const(mode_b, tv); + c1 = new_Const(tv); DBG_OPT_CSTEVAL(proj, c1); return c1; } @@ -4474,7 +4480,7 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) { if (! tarval_is_null(get_Const_tarval(c1))) { /* TODO: move to constant evaluation */ tv = proj_nr == pn_Cmp_Eq ? get_tarval_b_false() : get_tarval_b_true(); - c1 = new_Const(mode_b, tv); + c1 = new_Const(tv); DBG_OPT_CSTEVAL(proj, c1); return c1; } @@ -4499,13 +4505,13 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) { if (tarval_and(tv, cmask) != tv) { /* condition not met */ tv = proj_nr == pn_Cmp_Eq ? get_tarval_b_false() : get_tarval_b_true(); - c1 = new_Const(mode_b, tv); + c1 = new_Const(tv); DBG_OPT_CSTEVAL(proj, c1); return c1; } sl = get_Shl_left(left); blk = get_nodes_block(n); - left = new_rd_And(get_irn_dbg_info(left), current_ir_graph, blk, sl, new_Const(mode, amask), mode); + left = new_rd_And(get_irn_dbg_info(left), current_ir_graph, blk, sl, new_Const(amask), mode); tv = tarval_shr(tv, tv1); changed |= 2; DBG_OPT_ALGSIM0(n, n, FS_OPT_CMP_SHF_TO_AND); @@ -4530,13 +4536,13 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) { if (tarval_and(tv, cmask) != tv) { /* condition not met */ tv = proj_nr == pn_Cmp_Eq ? get_tarval_b_false() : get_tarval_b_true(); - c1 = new_Const(mode_b, tv); + c1 = new_Const(tv); DBG_OPT_CSTEVAL(proj, c1); return c1; } sl = get_Shr_left(left); blk = get_nodes_block(n); - left = new_rd_And(get_irn_dbg_info(left), current_ir_graph, blk, sl, new_Const(mode, amask), mode); + left = new_rd_And(get_irn_dbg_info(left), current_ir_graph, blk, sl, new_Const(amask), mode); tv = tarval_shl(tv, tv1); changed |= 2; DBG_OPT_ALGSIM0(n, n, FS_OPT_CMP_SHF_TO_AND); @@ -4564,13 +4570,13 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) { if (!tarval_is_all_one(cond) && !tarval_is_null(cond)) { /* condition not met */ tv = proj_nr == pn_Cmp_Eq ? get_tarval_b_false() : get_tarval_b_true(); - c1 = new_Const(mode_b, tv); + c1 = new_Const(tv); DBG_OPT_CSTEVAL(proj, c1); return c1; } sl = get_Shrs_left(left); blk = get_nodes_block(n); - left = new_rd_And(get_irn_dbg_info(left), current_ir_graph, blk, sl, new_Const(mode, amask), mode); + left = new_rd_And(get_irn_dbg_info(left), current_ir_graph, blk, sl, new_Const(amask), mode); tv = tarval_shl(tv, tv1); changed |= 2; DBG_OPT_ALGSIM0(n, n, FS_OPT_CMP_SHF_TO_AND); @@ -4582,7 +4588,7 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) { } if (changed & 2) /* need a new Const */ - right = new_Const(mode, tv); + right = new_Const(tv); if ((proj_nr == pn_Cmp_Eq || proj_nr == pn_Cmp_Lg) && is_Const(right) && is_Const_null(right) && is_Proj(left)) { ir_node *op = get_Proj_pred(left); @@ -4601,7 +4607,7 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) { ir_mode *mode = get_irn_mode(v); tv = tarval_sub(tv, get_mode_one(mode), NULL); - left = new_rd_And(get_irn_dbg_info(op), current_ir_graph, blk, v, new_Const(mode, tv), mode); + left = new_rd_And(get_irn_dbg_info(op), current_ir_graph, blk, v, new_Const(tv), mode); changed |= 1; DBG_OPT_ALGSIM0(n, n, FS_OPT_CMP_MOD_TO_AND); } @@ -4866,9 +4872,9 @@ static ir_node *transform_node_Or_bf_store(ir_node *or) { block = get_irn_n(or, -1); new_and = new_r_And(current_ir_graph, block, - value, new_r_Const(current_ir_graph, block, mode, tarval_and(tv4, tv2)), mode); + value, new_Const(tarval_and(tv4, tv2)), mode); - new_const = new_r_Const(current_ir_graph, block, mode, tarval_or(tv3, tv1)); + new_const = new_Const(tarval_or(tv3, tv1)); set_Or_left(or, new_and); set_Or_right(or, new_const); @@ -5066,12 +5072,12 @@ static ir_node *transform_node_shift(ir_node *n) { ir_node *block = get_nodes_block(n); dbg_info *dbgi = get_irn_dbg_info(n); ir_mode *smode = get_irn_mode(right); - ir_node *cnst = new_Const(smode, new_tarval_from_long(get_mode_size_bits(mode) - 1, smode)); + ir_node *cnst = new_Const_long(smode, get_mode_size_bits(mode) - 1); return new_rd_Shrs(dbgi, irg, block, get_binop_left(left), cnst, mode); } - return new_Const(mode, get_mode_null(mode)); + return new_Const(get_mode_null(mode)); } } } else { @@ -5082,7 +5088,7 @@ static ir_node *transform_node_shift(ir_node *n) { block = get_nodes_block(n); in[0] = get_binop_left(left); - in[1] = new_r_Const(current_ir_graph, block, get_tarval_mode(res), res); + in[1] = new_Const(res); irn = new_ir_node(NULL, current_ir_graph, block, get_irn_op(n), mode, 2, in); @@ -5161,7 +5167,7 @@ static ir_node *transform_node_bitop_shift(ir_node *n) { } assert(get_tarval_mode(tv_shift) == mode); - new_const = new_Const(mode, tv_shift); + new_const = new_Const(tv_shift); if (op_left == op_And) { new_bitop = new_rd_And(dbgi, irg, block, new_shift, new_const, mode); @@ -5258,7 +5264,7 @@ static ir_node *transform_node_shl_shr(ir_node *n) { pnc = tarval_cmp(tv_shl, tv_shr); if (pnc == pn_Cmp_Lt || pnc == pn_Cmp_Eq) { tv_shift = tarval_sub(tv_shr, tv_shl, NULL); - new_const = new_Const(get_tarval_mode(tv_shift), tv_shift); + new_const = new_Const(tv_shift); if (need_shrs) { new_shift = new_rd_Shrs(dbgi, irg, block, x, new_const, mode); } else { @@ -5267,11 +5273,11 @@ static ir_node *transform_node_shl_shr(ir_node *n) { } else { assert(pnc == pn_Cmp_Gt); tv_shift = tarval_sub(tv_shl, tv_shr, NULL); - new_const = new_Const(get_tarval_mode(tv_shift), tv_shift); + new_const = new_Const(tv_shift); new_shift = new_rd_Shl(dbgi, irg, block, x, new_const, mode); } - new_const = new_Const(mode, tv_mask); + new_const = new_Const(tv_mask); new_and = new_rd_And(dbgi, irg, block, new_shift, new_const, mode); return new_and; @@ -5542,10 +5548,10 @@ static ir_node *transform_node_Mux(ir_node *n) { dbg_info *dbg = get_irn_dbg_info(n); ir_node *block = get_nodes_block(n); ir_graph *irg = current_ir_graph; - ir_node *t = new_Const(mode, tarval_sub(a, min, NULL)); - ir_node *f = new_Const(mode, tarval_sub(b, min, NULL)); + ir_node *t = new_Const(tarval_sub(a, min, NULL)); + ir_node *f = new_Const(tarval_sub(b, min, NULL)); n = new_rd_Mux(dbg, irg, block, sel, f, t, mode); - n = new_rd_Add(dbg, irg, block, n, new_Const(mode, min), mode); + n = new_rd_Add(dbg, irg, block, n, new_Const(min), mode); return n; } } @@ -5657,7 +5663,8 @@ static ir_node *transform_node_Mux(ir_node *n) { } } } - return arch_transform_node_Mux(n); + + return n; } /* transform_node_Mux */ /** @@ -5701,7 +5708,80 @@ static ir_node *transform_node_Sync(ir_node *n) { add_identities(current_ir_graph->value_table, n); return n; -} +} /* transform_node_Sync */ + +/** + * optimize a trampoline Call into a direct Call + */ +static ir_node *transform_node_Call(ir_node *call) { + ir_node *callee = get_Call_ptr(call); + ir_node *adr, *mem, *res, *bl, **in; + ir_type *ctp, *mtp, *tp; + ident *id; + dbg_info *db; + int i, n_res, n_param; + ir_variadicity var; + + if (! is_Proj(callee)) + return call; + callee = get_Proj_pred(callee); + if (! is_Builtin(callee)) + return call; + if (get_Builtin_kind(callee) != ir_bk_inner_trampoline) + return call; + + mem = get_Call_mem(call); + + if (skip_Proj(mem) == callee) { + /* memory is routed to the trampoline, skip */ + mem = get_Builtin_mem(callee); + } + + /* build a new call type */ + mtp = get_Call_type(call); + id = get_type_ident(mtp); + id = id_mangle(new_id_from_chars("T_", 2), id); + db = get_type_dbg_info(mtp); + + n_res = get_method_n_ress(mtp); + n_param = get_method_n_params(mtp); + ctp = new_d_type_method(id, n_param + 1, n_res, db); + + for (i = 0; i < n_res; ++i) + set_method_res_type(ctp, i, get_method_res_type(mtp, i)); + + NEW_ARR_A(ir_node *, in, n_param + 1); + + /* FIXME: we don't need a new pointer type in every step */ + tp = get_irg_frame_type(current_ir_graph); + id = id_mangle(get_type_ident(tp), new_id_from_chars("_ptr", 4)); + tp = new_type_pointer(id, tp, mode_P_data); + set_method_param_type(ctp, 0, tp); + + in[0] = get_Builtin_param(callee, 2); + for (i = 0; i < n_param; ++i) { + set_method_param_type(ctp, i + 1, get_method_param_type(mtp, i)); + in[i + 1] = get_Call_param(call, i); + } + var = get_method_variadicity(mtp); + set_method_variadicity(ctp, var); + if (var == variadicity_variadic) { + set_method_first_variadic_param_index(ctp, get_method_first_variadic_param_index(mtp) + 1); + } + /* When we resolve a trampoline, the function must be called by a this-call */ + set_method_calling_convention(ctp, get_method_calling_convention(mtp) | cc_this_call); + set_method_additional_properties(ctp, get_method_additional_properties(mtp)); + + adr = get_Builtin_param(callee, 1); + + db = get_irn_dbg_info(call); + bl = get_nodes_block(call); + + res = new_rd_Call(db, current_ir_graph, bl, mem, adr, n_param + 1, in, ctp); + if (get_irn_pinned(call) == op_pin_state_floats) + set_irn_pinned(res, op_pin_state_floats); + return res; +} /* transform_node_Call */ /** * Tries several [inplace] [optimizing] transformations and returns an @@ -5783,6 +5863,7 @@ static ir_op_ops *firm_set_default_transform_node(ir_opcode code, ir_op_ops *ops CASE(End); CASE(Mux); CASE(Sync); + CASE(Call); default: /* leave NULL */; } @@ -5921,7 +6002,7 @@ 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); return ma->exc.pin_state != mb->exc.pin_state || - ma->res_mode != mb->res_mode || + ma->resmode != mb->resmode || ma->no_remainder != mb->no_remainder; } /* node_cmp_attr_Div */ @@ -5930,7 +6011,7 @@ 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); return ma->exc.pin_state != mb->exc.pin_state || - ma->res_mode != mb->res_mode; + ma->resmode != mb->resmode; } /* node_cmp_attr_DivMod */ /** Compares the attributes of two Mod nodes. */ @@ -5938,7 +6019,7 @@ 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->res_mode != mb->res_mode; + ma->resmode != mb->resmode; } /* node_cmp_attr_Mod */ /** Compares the attributes of two Quot nodes. */ @@ -5946,14 +6027,24 @@ 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->res_mode != mb->res_mode; + ma->resmode != mb->resmode; } /* node_cmp_attr_Quot */ /** Compares the attributes of two Confirm nodes. */ static int node_cmp_attr_Confirm(ir_node *a, ir_node *b) { + /* no need to compare the bound, as this is a input */ return (get_Confirm_cmp(a) != get_Confirm_cmp(b)); } /* node_cmp_attr_Confirm */ +/** 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; +} /* node_cmp_attr_Builtin */ + /** Compares the attributes of two ASM nodes. */ static int node_cmp_attr_ASM(ir_node *a, ir_node *b) { int i, n; @@ -6000,6 +6091,14 @@ static int node_cmp_attr_ASM(ir_node *a, ir_node *b) { return 0; } /* node_cmp_attr_ASM */ +/** Compares the inexistent attributes of two Dummy nodes. */ +static int node_cmp_attr_Dummy(ir_node *a, ir_node *b) +{ + (void) a; + (void) b; + return 1; +} + /** * Set the default node attribute compare operation for an ir_op_ops. * @@ -6037,6 +6136,8 @@ static ir_op_ops *firm_set_default_node_cmp_attr(ir_opcode code, ir_op_ops *ops) CASE(Mod); CASE(Quot); CASE(Bound); + CASE(Builtin); + CASE(Dummy); /* FIXME CopyB */ default: /* leave NULL */; @@ -6349,7 +6450,10 @@ ir_node *optimize_node(ir_node *n) { /* neither constants nor Tuple values can be evaluated */ if (iro != iro_Const && (get_irn_mode(n) != mode_T)) { unsigned fp_model = get_irg_fp_model(current_ir_graph); - int old_fp_mode = tarval_enable_fp_ops((fp_model & fp_strict_algebraic) == 0); + int old_fp_mode = tarval_fp_ops_enabled(); + + tarval_enable_fp_ops(! (fp_model & fp_no_float_fold)); + /* try to evaluate */ tv = computed_value(n); if (tv != tarval_bad) { @@ -6382,7 +6486,7 @@ ir_node *optimize_node(ir_node *n) { /* evaluation was successful -- replace the node. */ irg_kill_node(current_ir_graph, n); - nw = new_Const(get_tarval_mode(tv), tv); + nw = new_Const(tv); if (old_tp && get_type_mode(old_tp) == get_tarval_mode(tv)) set_Const_type(nw, old_tp); @@ -6461,7 +6565,9 @@ ir_node *optimize_in_place_2(ir_node *n) { /* neither constants nor Tuple values can be evaluated */ if (iro != iro_Const && get_irn_mode(n) != mode_T) { unsigned fp_model = get_irg_fp_model(current_ir_graph); - int old_fp_mode = tarval_enable_fp_ops((fp_model & fp_strict_algebraic) == 0); + int old_fp_mode = tarval_fp_ops_enabled(); + + tarval_enable_fp_ops((fp_model & fp_strict_algebraic) == 0); /* try to evaluate */ tv = computed_value(n); if (tv != tarval_bad) { @@ -6475,7 +6581,7 @@ ir_node *optimize_in_place_2(ir_node *n) { for (i = 0; i < arity && !old_tp; ++i) old_tp = get_irn_type(get_irn_n(n, i)); - n = new_Const(get_tarval_mode(tv), tv); + n = new_Const(tv); if (old_tp && get_type_mode(old_tp) == get_tarval_mode(tv)) set_Const_type(n, old_tp);