X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firarch.c;h=4b1ab6266eac9bb5e66267b42bc20f1dbf9ae63f;hb=4f92e524762e0febc361676111b3b5b79addd03a;hp=69cb96ff21f888d784775309d200e380e21e000c;hpb=a5e1011f6b967b00491c503c59753625fc74cb61;p=libfirm diff --git a/ir/ir/irarch.c b/ir/ir/irarch.c index 69cb96ff2..4b1ab6266 100644 --- a/ir/ir/irarch.c +++ b/ir/ir/irarch.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. + * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved. * * This file is part of libFirm. * @@ -197,7 +197,7 @@ static unsigned char *value_to_condensed(mul_env *env, ir_tarval *tv, int *pr) int bits = get_mode_size_bits(mode); char *bitstr = get_tarval_bitpattern(tv); int i, l, r; - unsigned char *R = obstack_alloc(&env->obst, bits); + unsigned char *R = (unsigned char*)obstack_alloc(&env->obst, bits); l = r = 0; for (i = 0; bitstr[i] != '\0'; ++i) { @@ -241,7 +241,7 @@ static int calculate_gain(unsigned char *R, int r) */ static unsigned char *complement_condensed(mul_env *env, unsigned char *R, int r, int gain, int *prs) { - unsigned char *value = obstack_alloc(&env->obst, env->bits); + unsigned char *value = (unsigned char*)obstack_alloc(&env->obst, env->bits); int i, l, j; unsigned char c; @@ -352,7 +352,7 @@ static instruction *decompose_mul(mul_env *env, unsigned char *R, int r, ir_tarv R1 = complement_condensed(env, R, r, gain, &r1); r2 = r - gain + 1; - R2 = obstack_alloc(&env->obst, r2); + R2 = (unsigned char*)obstack_alloc(&env->obst, r2); k = 1; for (i = 0; i < gain; ++i) { @@ -674,7 +674,7 @@ static struct ms magic(ir_tarval *d) int bits = get_mode_size_bits(u_mode); int p; ir_tarval *ad, *anc, *delta, *q1, *r1, *q2, *r2, *t; /* unsigned */ - pn_Cmp d_cmp, M_cmp; + ir_relation d_cmp, M_cmp; ir_tarval *bits_minus_1, *two_bits_1; @@ -703,7 +703,7 @@ static struct ms magic(ir_tarval *d) q1 = ADD(q1, q1); /* Update q1 = 2^p/|nc| */ r1 = ADD(r1, r1); /* Update r1 = rem(2^p, |nc|) */ - if (CMP(r1, anc) & pn_Cmp_Ge) { + if (CMP(r1, anc) & ir_relation_greater_equal) { q1 = ADD(q1, ONE(u_mode)); r1 = SUB(r1, anc); } @@ -711,17 +711,17 @@ static struct ms magic(ir_tarval *d) q2 = ADD(q2, q2); /* Update q2 = 2^p/|d| */ r2 = ADD(r2, r2); /* Update r2 = rem(2^p, |d|) */ - if (CMP(r2, ad) & pn_Cmp_Ge) { + if (CMP(r2, ad) & ir_relation_greater_equal) { q2 = ADD(q2, ONE(u_mode)); r2 = SUB(r2, ad); } delta = SUB(ad, r2); - } while (CMP(q1, delta) & pn_Cmp_Lt || (CMP(q1, delta) & pn_Cmp_Eq && CMP(r1, ZERO(u_mode)) & pn_Cmp_Eq)); + } while (CMP(q1, delta) & ir_relation_less || (CMP(q1, delta) & ir_relation_equal && CMP(r1, ZERO(u_mode)) & ir_relation_equal)); d_cmp = CMP(d, ZERO(mode)); - if (d_cmp & pn_Cmp_Ge) + if (d_cmp & ir_relation_greater_equal) mag.M = ADD(CNV(q2, mode), ONE(mode)); else mag.M = SUB(ZERO(mode), ADD(CNV(q2, mode), ONE(mode))); @@ -731,10 +731,10 @@ static struct ms magic(ir_tarval *d) mag.s = p - bits; /* need an add if d > 0 && M < 0 */ - mag.need_add = d_cmp & pn_Cmp_Gt && M_cmp & pn_Cmp_Lt; + mag.need_add = d_cmp & ir_relation_greater && M_cmp & ir_relation_less; /* need a sub if d < 0 && M > 0 */ - mag.need_sub = d_cmp & pn_Cmp_Lt && M_cmp & pn_Cmp_Gt; + mag.need_sub = d_cmp & ir_relation_less && M_cmp & ir_relation_greater; tarval_set_integer_overflow_mode(rem); @@ -782,7 +782,7 @@ static struct mu magicu(ir_tarval *d) do { ++p; - if (CMP(r1, SUB(nc, r1)) & pn_Cmp_Ge) { + if (CMP(r1, SUB(nc, r1)) & ir_relation_greater_equal) { q1 = ADD(ADD(q1, q1), ONE(mode)); r1 = SUB(ADD(r1, r1), nc); } @@ -791,15 +791,15 @@ static struct mu magicu(ir_tarval *d) r1 = ADD(r1, r1); } - if (CMP(ADD(r2, ONE(mode)), SUB(d, r2)) & pn_Cmp_Ge) { - if (CMP(q2, seven_ff) & pn_Cmp_Ge) + if (CMP(ADD(r2, ONE(mode)), SUB(d, r2)) & ir_relation_greater_equal) { + if (CMP(q2, seven_ff) & ir_relation_greater_equal) magu.need_add = 1; q2 = ADD(ADD(q2, q2), ONE(mode)); r2 = SUB(ADD(ADD(r2, r2), ONE(mode)), d); } else { - if (CMP(q2, two_bits_1) & pn_Cmp_Ge) + if (CMP(q2, two_bits_1) & ir_relation_greater_equal) magu.need_add = 1; q2 = ADD(q2, q2); @@ -807,7 +807,7 @@ static struct mu magicu(ir_tarval *d) } delta = SUB(SUB(d, ONE(mode)), r2); } while (p < 2*bits && - (CMP(q1, delta) & pn_Cmp_Lt || (CMP(q1, delta) & pn_Cmp_Eq && CMP(r1, ZERO(mode)) & pn_Cmp_Eq))); + (CMP(q1, delta) & ir_relation_less || (CMP(q1, delta) & ir_relation_equal && CMP(r1, ZERO(mode)) & ir_relation_equal))); magu.M = ADD(q2, ONE(mode)); /* Magic number */ magu.s = p - bits; /* and shift amount */ @@ -820,7 +820,7 @@ static struct mu magicu(ir_tarval *d) /** * Build the Mulh replacement code for n / tv. * - * Note that 'div' might be a mod or DivMod operation as well + * Note that 'div' might be a Mod operation as well */ static ir_node *replace_div_by_mulh(ir_node *div, ir_tarval *tv) { @@ -925,6 +925,11 @@ ir_node *arch_dep_replace_div_by_const(ir_node *irn) left = get_Div_left(irn); mode = get_irn_mode(left); + + /* can only handle integer Div's */ + if (!mode_is_int(mode)) + return irn; + block = get_irn_n(irn, -1); dbg = get_irn_dbg_info(irn); @@ -1088,111 +1093,3 @@ ir_node *arch_dep_replace_mod_by_const(ir_node *irn) return res; } - -/* Replace DivMods with Shifts and Add/Subs and Mulh. */ -void arch_dep_replace_divmod_by_const(ir_node **div, ir_node **mod, ir_node *irn) -{ - const ir_settings_arch_dep_t *params = be_get_backend_param()->dep_param; - *div = *mod = NULL; - - /* If the architecture dependent optimizations were not initialized - or this optimization was not enabled. */ - if (params == NULL || - ((opts & (arch_dep_div_by_const|arch_dep_mod_by_const)) != (arch_dep_div_by_const|arch_dep_mod_by_const))) - return; - - if (is_DivMod(irn)) { - ir_node *c = get_DivMod_right(irn); - ir_node *block, *left; - ir_mode *mode; - ir_tarval *tv, *ntv; - dbg_info *dbg; - int n, bits; - int k; - int n_flag = 0; - - if (! is_Const(c)) - return; - - tv = get_Const_tarval(c); - - /* check for division by zero */ - if (tarval_is_null(tv)) - return; - - left = get_DivMod_left(irn); - mode = get_irn_mode(left); - block = get_irn_n(irn, -1); - dbg = get_irn_dbg_info(irn); - - bits = get_mode_size_bits(mode); - n = (bits + 7) / 8; - - k = -1; - if (mode_is_signed(mode)) { - /* for signed divisions, the algorithm works for a / -2^k by negating the result */ - ntv = tarval_neg(tv); - n_flag = 1; - k = tv_ld2(ntv, n); - } - - if (k < 0) { - n_flag = 0; - k = tv_ld2(tv, n); - } - - if (k >= 0) { /* division by 2^k or -2^k */ - ir_graph *irg = get_irn_irg(irn); - if (mode_is_signed(mode)) { - ir_node *k_node, *c_k; - ir_node *curr = left; - - if (k != 1) { - k_node = new_r_Const_long(irg, mode_Iu, k - 1); - curr = new_rd_Shrs(dbg, block, left, k_node, mode); - } - - k_node = new_r_Const_long(irg, mode_Iu, bits - k); - curr = new_rd_Shr(dbg, block, curr, k_node, mode); - - curr = new_rd_Add(dbg, block, left, curr, mode); - - c_k = new_r_Const_long(irg, mode_Iu, k); - - *div = new_rd_Shrs(dbg, block, curr, c_k, mode); - - if (n_flag) { /* negate the div result */ - ir_node *k_node = new_r_Const(irg, get_mode_null(mode)); - *div = new_rd_Sub(dbg, block, k_node, *div, mode); - } - - k_node = new_r_Const_long(irg, mode, (-1) << k); - curr = new_rd_And(dbg, block, curr, k_node, mode); - - *mod = new_rd_Sub(dbg, block, left, curr, mode); - } else { /* unsigned case */ - ir_node *k_node = new_r_Const_long(irg, mode_Iu, k); - *div = new_rd_Shr(dbg, block, left, k_node, mode); - - k_node = new_r_Const_long(irg, mode, (1 << k) - 1); - *mod = new_rd_And(dbg, block, left, k_node, mode); - } - } else { - /* other constant */ - if (allow_Mulh(params, mode)) { - ir_node *t; - - *div = replace_div_by_mulh(irn, tv); - - t = new_rd_Mul(dbg, block, *div, c, mode); - - /* t = arch_dep_mul_to_shift(t); */ - - *mod = new_rd_Sub(dbg, block, left, t, mode); - } - } - } - - if (*div) - hook_arch_dep_replace_division_by_const(irn); -}