Commit bdacbd77 authored by Christoph Mallon's avatar Christoph Mallon
Browse files

Remove classify_tarval(). Use tarval_is_null(), tarval_is_one() and tarval_is_all_one() instead.

[r15837]
parent 1f9cb48e
......@@ -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)
......
......@@ -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.
......
......@@ -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 */
......
......@@ -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);
}
/**
......
......@@ -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);
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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))) {
......
......@@ -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.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment