From bdacbd77db4138f76e06dde1f0098edfa25e1aa9 Mon Sep 17 00:00:00 2001 From: Christoph Mallon Date: Mon, 17 Sep 2007 14:51:21 +0000 Subject: [PATCH] Remove classify_tarval(). Use tarval_is_null(), tarval_is_one() and tarval_is_all_one() instead. [r15837] --- include/libfirm/old_fctnames.h | 1 - include/libfirm/tv.h | 18 +++------- ir/ana/irmemory.c | 2 +- ir/be/ia32/ia32_transform.c | 2 +- ir/ir/irarch.c | 6 ++-- ir/ir/irnode_t.h | 10 ++++-- ir/ir/iropt.c | 63 ++++++++++++++-------------------- ir/opt/opt_confirms.c | 2 +- ir/tv/tv.c | 38 ++++++-------------- 9 files changed, 55 insertions(+), 87 deletions(-) diff --git a/include/libfirm/old_fctnames.h b/include/libfirm/old_fctnames.h index 7f057d603..1ea447565 100644 --- a/include/libfirm/old_fctnames.h +++ b/include/libfirm/old_fctnames.h @@ -141,7 +141,6 @@ typedef ir_type type; #define tarval_get_mode_output_option(X) get_tarval_mode_output_option(X) #define tarval_bitpattern(X) get_tarval_bitpattern(X) #define tarval_sub_bits(X, Y) get_tarval_sub_bits(X, Y) -#define tarval_classify(X) classify_tarval(X) #define get_tarval_P_void() get_tarval_null(mode_P) #define tarval_P_void get_tarval_null(mode_P) diff --git a/include/libfirm/tv.h b/include/libfirm/tv.h index 466488276..9fc65133c 100644 --- a/include/libfirm/tv.h +++ b/include/libfirm/tv.h @@ -250,6 +250,11 @@ int tarval_is_null(tarval *a); */ int tarval_is_one(tarval *a); +/* + * returns non-zero if all bits in the tarval are set + */ +int tarval_is_all_one(tarval *tv); + /** The 'bad' tarval. */ extern tarval *tarval_bad; /** Returns the 'bad tarval. */ @@ -566,19 +571,6 @@ typedef enum _tarval_classification_t { TV_CLASSIFY_OTHER = 2 /**< all other tarvals */ } tarval_classification_t; -/** - * Identifying tarvals values for algebraic simplifications. - * - * @param tv the tarval - * - * @return - * - TV_CLASSIFY_NULL for additive neutral or the NULL tarval for reference modes, - * - TV_CLASSIFY_ONE for multiplicative neutral, - * - TV_CLASSIFY_ALL_ONE for bitwise-and neutral - * - TV_CLASSIFY_OTHER else - */ -tarval_classification_t classify_tarval(tarval *tv); - /** * Returns non-zero if a given (integer) tarval has only one single bit * set. diff --git a/ir/ana/irmemory.c b/ir/ana/irmemory.c index 99b5849f6..ebbc6d4d4 100644 --- a/ir/ana/irmemory.c +++ b/ir/ana/irmemory.c @@ -98,7 +98,7 @@ static ir_alias_relation check_const(ir_node *cns, int size) { tarval *tv_size; if (size == 0) - return classify_tarval(tv) != TV_CLASSIFY_NULL ? no_alias : may_alias; + return tarval_is_null(tv) ? may_alias : no_alias; tv_size = new_tarval_from_long(size, get_tarval_mode(tv)); return tarval_cmp(tv_size, tv) & (pn_Cmp_Eq|pn_Cmp_Lt) ? no_alias : may_alias; } /* check_const */ diff --git a/ir/be/ia32/ia32_transform.c b/ir/be/ia32/ia32_transform.c index 99e6b0f15..e2dd36956 100644 --- a/ir/be/ia32/ia32_transform.c +++ b/ir/be/ia32/ia32_transform.c @@ -248,7 +248,7 @@ static int is_Const_Minus_1(ir_node *node) { tv = get_Const_tarval(node); tv = tarval_neg(tv); - return classify_tarval(tv) == CNST_ONE; + return tarval_is_one(tv); } /** diff --git a/ir/ir/irarch.c b/ir/ir/irarch.c index f34d19317..2431931a6 100644 --- a/ir/ir/irarch.c +++ b/ir/ir/irarch.c @@ -897,7 +897,7 @@ ir_node *arch_dep_replace_div_by_const(ir_node *irn) { tv = get_Const_tarval(c); /* check for division by zero */ - if (classify_tarval(tv) == TV_CLASSIFY_NULL) + if (tarval_is_null(tv)) return irn; left = get_Div_left(irn); @@ -988,7 +988,7 @@ ir_node *arch_dep_replace_mod_by_const(ir_node *irn) { tv = get_Const_tarval(c); /* check for division by zero */ - if (classify_tarval(tv) == TV_CLASSIFY_NULL) + if (tarval_is_null(tv)) return irn; left = get_Mod_left(irn); @@ -1082,7 +1082,7 @@ void arch_dep_replace_divmod_by_const(ir_node **div, ir_node **mod, ir_node *irn tv = get_Const_tarval(c); /* check for division by zero */ - if (classify_tarval(tv) == TV_CLASSIFY_NULL) + if (tarval_is_null(tv)) return; left = get_DivMod_left(irn); diff --git a/ir/ir/irnode_t.h b/ir/ir/irnode_t.h index fac2641f9..13bd5d1ec 100644 --- a/ir/ir/irnode_t.h +++ b/ir/ir/irnode_t.h @@ -772,9 +772,13 @@ static INLINE cnst_classify_t _classify_Const(ir_node *node) { op = _get_irn_op(node); - if (op == op_Const) - return classify_tarval(_get_Const_tarval(node)); - else if(op == op_SymConst) + if (op == op_Const) { + tarval *tv = _get_Const_tarval(node); + if (tarval_is_null(tv)) return TV_CLASSIFY_NULL; + if (tarval_is_one(tv)) return TV_CLASSIFY_ONE; + if (tarval_is_all_one(tv)) return TV_CLASSIFY_ALL_ONE; + return TV_CLASSIFY_OTHER; + } else if(op == op_SymConst) return CNST_SYMCONST; return CNST_NO_CONST; diff --git a/ir/ir/iropt.c b/ir/ir/iropt.c index 26299c0c2..609ef0b1f 100644 --- a/ir/ir/iropt.c +++ b/ir/ir/iropt.c @@ -145,8 +145,7 @@ static tarval *computed_value_Carry(ir_node *n) { tarval_add(ta, tb); return tarval_carry() ? get_mode_one(m) : get_mode_null(m); } else { - if ( (classify_tarval(ta) == TV_CLASSIFY_NULL) - || (classify_tarval(tb) == TV_CLASSIFY_NULL)) + if (tarval_is_null(ta) || tarval_is_null(tb)) return get_mode_null(m); } return tarval_bad; @@ -166,7 +165,7 @@ static tarval *computed_value_Borrow(ir_node *n) { if ((ta != tarval_bad) && (tb != tarval_bad)) { return tarval_cmp(ta, tb) == pn_Cmp_Lt ? get_mode_one(m) : get_mode_null(m); - } else if (classify_tarval(ta) == TV_CLASSIFY_NULL) { + } else if (tarval_is_null(ta)) { return get_mode_null(m); } return tarval_bad; @@ -310,12 +309,8 @@ static tarval *computed_value_And(ir_node *n) { if ((ta != tarval_bad) && (tb != tarval_bad)) { return tarval_and (ta, tb); } else { - tarval *v; - - if ( (classify_tarval ((v = ta)) == TV_CLASSIFY_NULL) - || (classify_tarval ((v = tb)) == TV_CLASSIFY_NULL)) { - return v; - } + if (tarval_is_null(ta)) return ta; + if (tarval_is_null(tb)) return tb; } return tarval_bad; } /* computed_value_And */ @@ -334,11 +329,8 @@ static tarval *computed_value_Or(ir_node *n) { if ((ta != tarval_bad) && (tb != tarval_bad)) { return tarval_or (ta, tb); } else { - tarval *v; - if ( (classify_tarval ((v = ta)) == TV_CLASSIFY_ALL_ONE) - || (classify_tarval ((v = tb)) == TV_CLASSIFY_ALL_ONE)) { - return v; - } + if (tarval_is_all_one(ta)) return ta; + if (tarval_is_all_one(tb)) return tb; } return tarval_bad; } /* computed_value_Or */ @@ -859,12 +851,10 @@ static ir_node *equivalent_node_neutral_zero(ir_node *n) * which happens in this rare construction: NULL + 3. * Then, a Conv would be needed which we cannot include here. */ - if (classify_tarval (tv) == TV_CLASSIFY_NULL) { - if (get_irn_mode(on) == get_irn_mode(n)) { - n = on; + if (tarval_is_null(tv) && get_irn_mode(on) == get_irn_mode(n)) { + n = on; - DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_NEUTRAL_0); - } + DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_NEUTRAL_0); } return n; @@ -935,7 +925,7 @@ static ir_node *equivalent_node_left_zero(ir_node *n) { ir_node *a = get_binop_left(n); ir_node *b = get_binop_right(n); - if (classify_tarval(value_of(b)) == TV_CLASSIFY_NULL) { + if (tarval_is_null(value_of(b))) { n = a; DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_NEUTRAL_0); @@ -969,7 +959,7 @@ static ir_node *equivalent_node_Sub(ir_node *n) { b = get_Sub_right(n); /* Beware: modes might be different */ - if (classify_tarval(value_of(b)) == TV_CLASSIFY_NULL) { + if (tarval_is_null(value_of(b))) { ir_node *a = get_Sub_left(n); if (mode == get_irn_mode(a)) { n = a; @@ -1020,10 +1010,10 @@ static ir_node *equivalent_node_Mul(ir_node *n) { ir_node *b = get_Mul_right(n); /* Mul is commutative and has again an other neutral element. */ - if (classify_tarval(value_of(a)) == TV_CLASSIFY_ONE) { + if (tarval_is_one(value_of(a))) { n = b; DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_NEUTRAL_1); - } else if (classify_tarval(value_of(b)) == TV_CLASSIFY_ONE) { + } else if (tarval_is_one(value_of(b))) { n = a; DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_NEUTRAL_1); } @@ -1039,7 +1029,7 @@ static ir_node *equivalent_node_Div(ir_node *n) { ir_node *b = get_Div_right(n); /* Div is not commutative. */ - if (classify_tarval(value_of(b)) == TV_CLASSIFY_ONE) { /* div(x, 1) == x */ + if (tarval_is_one(value_of(b))) { /* div(x, 1) == x */ /* Turn Div into a tuple (mem, bad, a) */ ir_node *mem = get_Div_mem(n); ir_node *blk = get_irn_n(n, -1); @@ -1060,7 +1050,7 @@ static ir_node *equivalent_node_Quot(ir_node *n) { ir_node *b = get_Quot_right(n); /* Div is not commutative. */ - if (classify_tarval(value_of(b)) == TV_CLASSIFY_ONE) { /* Quot(x, 1) == x */ + if (tarval_is_one(value_of(b))) { /* Quot(x, 1) == x */ /* Turn Quot into a tuple (mem, jmp, bad, a) */ ir_node *mem = get_Quot_mem(n); ir_node *blk = get_irn_n(n, -1); @@ -1080,7 +1070,7 @@ static ir_node *equivalent_node_DivMod(ir_node *n) { ir_node *b = get_DivMod_right(n); /* Div is not commutative. */ - if (classify_tarval(value_of(b)) == TV_CLASSIFY_ONE) { /* div(x, 1) == x */ + if (tarval_is_one(value_of(b))) { /* div(x, 1) == x */ /* Turn DivMod into a tuple (mem, jmp, bad, a, 0) */ ir_node *a = get_DivMod_left(n); ir_node *mem = get_Div_mem(n); @@ -1109,10 +1099,10 @@ static ir_node *equivalent_node_Or(ir_node *n) { if (a == b) { n = a; /* Or has it's own neutral element */ DBG_OPT_ALGSIM0(oldn, n, FS_OPT_OR); - } else if (classify_tarval(value_of(a)) == TV_CLASSIFY_NULL) { + } else if (tarval_is_null(value_of(a))) { n = b; DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_OR); - } else if (classify_tarval(value_of(b)) == TV_CLASSIFY_NULL) { + } else if (tarval_is_null(value_of(b))) { n = a; DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_OR); } @@ -1134,12 +1124,12 @@ static ir_node *equivalent_node_And(ir_node *n) { DBG_OPT_ALGSIM0(oldn, n, FS_OPT_AND); return n; } - if (classify_tarval(value_of(a)) == TV_CLASSIFY_ALL_ONE) { + if (tarval_is_all_one(value_of(a))) { n = b; DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_AND); return n; } - if (classify_tarval(value_of(b)) == TV_CLASSIFY_ALL_ONE) { + if (tarval_is_all_one(value_of(b))) { n = a; DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_AND); return n; @@ -3059,15 +3049,14 @@ static ir_node *transform_node_Eor(ir_node *n) { } else if ((mode == mode_b) && (get_irn_op(a) == op_Proj) && (get_irn_mode(a) == mode_b) - && (classify_tarval (value_of(b)) == TV_CLASSIFY_ONE) + && tarval_is_one(value_of(b)) && (get_irn_op(get_Proj_pred(a)) == op_Cmp)) { /* The Eor negates a Cmp. The Cmp has the negated result anyways! */ n = new_r_Proj(current_ir_graph, get_irn_n(n, -1), get_Proj_pred(a), mode_b, get_negated_pnc(get_Proj_proj(a), mode)); DBG_OPT_ALGSIM0(oldn, n, FS_OPT_EOR_TO_NOT_BOOL); - } else if ((mode == mode_b) - && (classify_tarval (value_of(b)) == TV_CLASSIFY_ONE)) { + } else if (mode == mode_b && tarval_is_one(value_of(b))) { /* The Eor is a Not. Replace it by a Not. */ /* ????!!!Extend to bitfield 1111111. */ n = new_r_Not(current_ir_graph, get_irn_n(n, -1), a, mode_b); @@ -3647,7 +3636,7 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) { if (proj_nr == pn_Cmp_Eq || proj_nr == pn_Cmp_Lg) { /* a-b == 0 ==> a == b, a-b != 0 ==> a != b */ - if (classify_tarval(tv) == TV_CLASSIFY_NULL && is_Sub(left)) { + if (tarval_is_null(tv) && is_Sub(left)) { right =get_Sub_right(left); left = get_Sub_left(left); @@ -3897,8 +3886,8 @@ static ir_node *transform_node_Or_bf_store(ir_node *or) { tv2 = get_Const_tarval(c2); tv = tarval_or(tv1, tv2); - if (classify_tarval(tv) == TV_CLASSIFY_ALL_ONE) { - /* the AND does NOT clear a bit with isn't set be the OR */ + if (tarval_is_all_one(tv)) { + /* the AND does NOT clear a bit with isn't set by the OR */ set_Or_left(or, or_l); set_Or_right(or, c1); @@ -3926,7 +3915,7 @@ static ir_node *transform_node_Or_bf_store(ir_node *or) { tv4 = get_Const_tarval(c4); tv = tarval_or(tv4, tv2); - if (classify_tarval(tv) != TV_CLASSIFY_ALL_ONE) { + if (!tarval_is_all_one(tv)) { /* have at least one 0 at the same bit position */ return or; } diff --git a/ir/opt/opt_confirms.c b/ir/opt/opt_confirms.c index 44ba41c8b..53052a3ed 100644 --- a/ir/opt/opt_confirms.c +++ b/ir/opt/opt_confirms.c @@ -186,7 +186,7 @@ int value_not_null(ir_node *n, ir_node **confirm) { if (op == op_Const) { tarval *tv = get_Const_tarval(n); - if (tv != tarval_bad && classify_tarval(tv) != TV_CLASSIFY_NULL) + if (tv != tarval_bad && !tarval_is_null(tv)) return 1; } else { for (; is_Confirm(n); n = skip_Cast(get_Confirm_value(n))) { diff --git a/ir/tv/tv.c b/ir/tv/tv.c index 766f92f43..f13d52c85 100644 --- a/ir/tv/tv.c +++ b/ir/tv/tv.c @@ -741,18 +741,24 @@ int tarval_is_negative(tarval *a) { * test if null, 1 means 'yes' */ int tarval_is_null(tarval *a) { - ir_mode *m = get_tarval_mode(a); - - return a == get_tarval_null(m); + return + a != tarval_bad && + a == get_tarval_null(get_tarval_mode(a)); } /* * test if one, 1 means 'yes' */ int tarval_is_one(tarval *a) { - ir_mode *m = get_tarval_mode(a); + return + a != tarval_bad && + a == get_tarval_one(get_tarval_mode(a)); +} - return a == get_tarval_one(m); +int tarval_is_all_one(tarval *tv) { + return + tv != tarval_bad && + tv == get_mode_all_one(get_tarval_mode(tv)); } /* @@ -1571,28 +1577,6 @@ const tarval_mode_info *get_tarval_mode_output_option(ir_mode *mode) { return mode->tv_priv; } -/* - * Identifying tarvals values for algebraic simplifications. - * - * Returns: - * - TV_CLASSIFY_NULL for additive neutral or the NULL tarval for reference modes, - * - TV_CLASSIFY_ONE for multiplicative neutral, - * - TV_CLASSIFY_ALL_ONE for bitwise-and neutral - * - TV_CLASSIFY_OTHER else - */ -tarval_classification_t classify_tarval(tarval *tv) { - if (!tv || tv == tarval_bad) return TV_CLASSIFY_OTHER; - - if (tv == get_mode_null(tv->mode)) - return TV_CLASSIFY_NULL; - else if (tv == get_mode_one(tv->mode)) - return TV_CLASSIFY_ONE; - else if (tv == get_mode_all_one(tv->mode)) - return TV_CLASSIFY_ALL_ONE; - - return TV_CLASSIFY_OTHER; -} - /* * Returns non-zero if a given (integer) tarval has only one single bit * set. -- 2.20.1