tb = value_of(b);
if ((ta != tarval_bad) && (tb != tarval_bad)) {
- return tarval_eor (ta, tb);
+ return tarval_eor(ta, tb);
}
return tarval_bad;
} /* computed_value_Eor */
tarval *tb = value_of(b);
if ((ta != tarval_bad) && (tb != tarval_bad)) {
- return tarval_shl (ta, tb);
+ return tarval_shl(ta, tb);
}
return tarval_bad;
} /* computed_value_Shl */
tarval *tb = value_of(b);
if ((ta != tarval_bad) && (tb != tarval_bad)) {
- return tarval_shr (ta, tb);
+ return tarval_shr(ta, tb);
}
return tarval_bad;
} /* computed_value_Shr */
tarval *tb = value_of(b);
if ((ta != tarval_bad) && (tb != tarval_bad)) {
- return tarval_shrs (ta, tb);
+ return tarval_shrs(ta, tb);
}
return tarval_bad;
} /* computed_value_Shrs */
static tarval *computed_value_Confirm(const ir_node *n) {
/*
* Beware: we might produce Phi(Confirm(x == true), Confirm(x == false)).
- * Do NOT optimize them away (CondEval wants them), so wait until
+ * Do NOT optimize them away (jump threading wants them), so wait until
* remove_confirm is activated.
*/
if (get_opt_remove_confirm()) {
DBG_OPT_ALGSIM0(oldn, proj, FS_OPT_NOP);
break;
- case pn_CopyB_M_except:
case pn_CopyB_X_except:
DBG_OPT_EXC_REM(proj);
proj = get_irg_bad(current_ir_graph);
typedef tarval *(*tarval_sub_type)(tarval *a, tarval *b, ir_mode *mode);
typedef tarval *(*tarval_binop_type)(tarval *a, tarval *b);
+/**
+ * in reality eval_func should be tarval (*eval_func)() but incomplete
+ * declarations are bad style and generate noisy warnings
+ */
+typedef void (*eval_func)(void);
+
/**
* Wrapper for the tarval binop evaluation, tarval_sub has one more parameter.
*/
-static tarval *do_eval(tarval *(*eval)(), tarval *a, tarval *b, ir_mode *mode) {
- if (eval == tarval_sub) {
+static tarval *do_eval(eval_func eval, tarval *a, tarval *b, ir_mode *mode)
+{
+ if (eval == (eval_func) tarval_sub) {
tarval_sub_type func = (tarval_sub_type)eval;
return func(a, b, mode);
*
* @return a new Phi node if the conversion was successful, NULL else
*/
-static ir_node *apply_binop_on_phi(ir_node *phi, tarval *other, tarval *(*eval)(), ir_mode *mode, int left) {
+static ir_node *apply_binop_on_phi(ir_node *phi, tarval *other, eval_func eval, ir_mode *mode, int left) {
tarval *tv;
void **res;
ir_node *pred;
*
* @return a new Phi node if the conversion was successful, NULL else
*/
-static ir_node *apply_binop_on_2_phis(ir_node *a, ir_node *b, tarval *(*eval)(), ir_mode *mode) {
+static ir_node *apply_binop_on_2_phis(ir_node *a, ir_node *b, eval_func eval, ir_mode *mode) {
tarval *tv_l, *tv_r, *tv;
void **res;
ir_node *pred;
}
}
- HANDLE_BINOP_PHI(tarval_add, a, b, c, mode);
+ HANDLE_BINOP_PHI((eval_func) tarval_add, a, b, c, mode);
/* for FP these optimizations are only allowed if fp_strict_algebraic is disabled */
if (mode_is_float(mode) && (get_irg_fp_model(current_ir_graph) & fp_strict_algebraic))
}
restart:
- HANDLE_BINOP_PHI(tarval_sub, a, b, c, mode);
+ HANDLE_BINOP_PHI((eval_func) tarval_sub, a, b, c, mode);
/* for FP these optimizations are only allowed if fp_strict_algebraic is disabled */
if (mode_is_float(mode) && (get_irg_fp_model(current_ir_graph) & fp_strict_algebraic))
if (mode != get_irn_mode(a))
return transform_node_Mul2n(n, mode);
- HANDLE_BINOP_PHI(tarval_mul, a, b, c, mode);
+ HANDLE_BINOP_PHI((eval_func) tarval_mul, a, b, c, mode);
if (mode_is_signed(mode)) {
ir_node *r = NULL;
DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_MUL_MINUS);
return n;
}
+ } else if (is_Shl(a)) {
+ ir_node *const shl_l = get_Shl_left(a);
+ if (is_Const(shl_l) && is_Const_one(shl_l)) {
+ /* (1 << x) * b -> b << x */
+ dbg_info *const dbgi = get_irn_dbg_info(n);
+ ir_node *const block = get_nodes_block(n);
+ ir_node *const shl_r = get_Shl_right(a);
+ n = new_rd_Shl(dbgi, block, b, shl_r, mode);
+ // TODO add me DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_MUL_SHIFT);
+ return n;
+ }
+ } else if (is_Shl(b)) {
+ ir_node *const shl_l = get_Shl_left(b);
+ if (is_Const(shl_l) && is_Const_one(shl_l)) {
+ /* a * (1 << x) -> a << x */
+ dbg_info *const dbgi = get_irn_dbg_info(n);
+ ir_node *const block = get_nodes_block(n);
+ ir_node *const shl_r = get_Shl_right(b);
+ n = new_rd_Shl(dbgi, block, a, shl_r, mode);
+ // TODO add me DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_MUL_SHIFT);
+ return n;
+ }
}
if (get_mode_arithmetic(mode) == irma_ieee754) {
if (is_Const(a)) {
if (is_Const(b) && is_const_Phi(a)) {
/* check for Div(Phi, Const) */
- value = apply_binop_on_phi(a, get_Const_tarval(b), tarval_div, mode, 0);
+ value = apply_binop_on_phi(a, get_Const_tarval(b), (eval_func) tarval_div, mode, 0);
if (value) {
DBG_OPT_ALGSIM0(n, value, FS_OPT_CONST_PHI);
goto make_tuple;
}
else if (is_Const(a) && is_const_Phi(b)) {
/* check for Div(Const, Phi) */
- value = apply_binop_on_phi(b, get_Const_tarval(a), tarval_div, mode, 1);
+ value = apply_binop_on_phi(b, get_Const_tarval(a), (eval_func) tarval_div, mode, 1);
if (value) {
DBG_OPT_ALGSIM0(n, value, FS_OPT_CONST_PHI);
goto make_tuple;
}
else if (is_const_Phi(a) && is_const_Phi(b)) {
/* check for Div(Phi, Phi) */
- value = apply_binop_on_2_phis(a, b, tarval_div, mode);
+ value = apply_binop_on_2_phis(a, b, (eval_func) tarval_div, mode);
if (value) {
DBG_OPT_ALGSIM0(n, value, FS_OPT_CONST_PHI);
goto make_tuple;
if (is_Const(b) && is_const_Phi(a)) {
/* check for Div(Phi, Const) */
- value = apply_binop_on_phi(a, get_Const_tarval(b), tarval_mod, mode, 0);
+ value = apply_binop_on_phi(a, get_Const_tarval(b), (eval_func) tarval_mod, mode, 0);
if (value) {
DBG_OPT_ALGSIM0(n, value, FS_OPT_CONST_PHI);
goto make_tuple;
}
else if (is_Const(a) && is_const_Phi(b)) {
/* check for Div(Const, Phi) */
- value = apply_binop_on_phi(b, get_Const_tarval(a), tarval_mod, mode, 1);
+ value = apply_binop_on_phi(b, get_Const_tarval(a), (eval_func) tarval_mod, mode, 1);
if (value) {
DBG_OPT_ALGSIM0(n, value, FS_OPT_CONST_PHI);
goto make_tuple;
}
else if (is_const_Phi(a) && is_const_Phi(b)) {
/* check for Div(Phi, Phi) */
- value = apply_binop_on_2_phis(a, b, tarval_mod, mode);
+ value = apply_binop_on_2_phis(a, b, (eval_func) tarval_mod, mode);
if (value) {
DBG_OPT_ALGSIM0(n, value, FS_OPT_CONST_PHI);
goto make_tuple;
if (is_Const(b) && is_const_Phi(a)) {
/* check for Div(Phi, Const) */
- va = apply_binop_on_phi(a, get_Const_tarval(b), tarval_div, mode, 0);
- vb = apply_binop_on_phi(a, get_Const_tarval(b), tarval_mod, mode, 0);
+ va = apply_binop_on_phi(a, get_Const_tarval(b), (eval_func) tarval_div, mode, 0);
+ vb = apply_binop_on_phi(a, get_Const_tarval(b), (eval_func) tarval_mod, mode, 0);
if (va && vb) {
DBG_OPT_ALGSIM0(n, va, FS_OPT_CONST_PHI);
DBG_OPT_ALGSIM0(n, vb, FS_OPT_CONST_PHI);
}
else if (is_Const(a) && is_const_Phi(b)) {
/* check for Div(Const, Phi) */
- va = apply_binop_on_phi(b, get_Const_tarval(a), tarval_div, mode, 1);
- vb = apply_binop_on_phi(b, get_Const_tarval(a), tarval_mod, mode, 1);
+ va = apply_binop_on_phi(b, get_Const_tarval(a), (eval_func) tarval_div, mode, 1);
+ vb = apply_binop_on_phi(b, get_Const_tarval(a), (eval_func) tarval_mod, mode, 1);
if (va && vb) {
DBG_OPT_ALGSIM0(n, va, FS_OPT_CONST_PHI);
DBG_OPT_ALGSIM0(n, vb, FS_OPT_CONST_PHI);
}
else if (is_const_Phi(a) && is_const_Phi(b)) {
/* check for Div(Phi, Phi) */
- va = apply_binop_on_2_phis(a, b, tarval_div, mode);
- vb = apply_binop_on_2_phis(a, b, tarval_mod, mode);
+ va = apply_binop_on_2_phis(a, b, (eval_func) tarval_div, mode);
+ vb = apply_binop_on_2_phis(a, b, (eval_func) tarval_mod, mode);
if (va && vb) {
DBG_OPT_ALGSIM0(n, va, FS_OPT_CONST_PHI);
DBG_OPT_ALGSIM0(n, vb, FS_OPT_CONST_PHI);
n = trans_func(n);
n = new_r_Conv(blk, n, get_irn_mode(oldn));
- DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_SHIFT_AND);
+ DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_CONV);
return n;
}
}
ir_mode *mode;
mode = get_irn_mode(n);
- HANDLE_BINOP_PHI(tarval_and, a, b, c, mode);
+ HANDLE_BINOP_PHI((eval_func) tarval_and, a, b, c, mode);
/* we can evaluate 2 Projs of the same Cmp */
if (mode == mode_b && is_Proj(a) && is_Proj(b)) {
ir_node *b = get_Eor_right(n);
ir_mode *mode = get_irn_mode(n);
- HANDLE_BINOP_PHI(tarval_eor, a, b, c, mode);
+ HANDLE_BINOP_PHI((eval_func) tarval_eor, a, b, c, mode);
/* we can evaluate 2 Projs of the same Cmp */
if (mode == mode_b && is_Proj(a) && is_Proj(b)) {
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) &&
- is_Const(b) && is_Const_one(b) &&
- is_Cmp(get_Proj_pred(a))) {
- /* The Eor negates a Cmp. The Cmp has the negated result anyways! */
- n = new_r_Proj(get_nodes_block(n), 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 (is_Const(b)) {
if (is_Not(a)) { /* ~x ^ const -> x ^ ~const */
ir_node *cnst = new_Const(tarval_not(get_Const_tarval(b)));
DBG_OPT_EXC_REM(proj);
proj = new_r_Jmp(get_nodes_block(copyb));
break;
- case pn_CopyB_M_except:
case pn_CopyB_X_except:
DBG_OPT_EXC_REM(proj);
proj = get_irg_bad(get_irn_irg(proj));
ir_node *new_and, *new_const, *block;
ir_mode *mode = get_irn_mode(or);
- tarval *tv1, *tv2, *tv3, *tv4, *tv, *n_tv4, *n_tv2;
+ tarval *tv1, *tv2, *tv3, *tv4, *tv;
while (1) {
get_comm_Binop_Ops(or, &and, &c1);
return or;
}
- n_tv4 = tarval_not(tv4);
- if (tv3 != tarval_and(tv3, n_tv4)) {
+ if (tv3 != tarval_andnot(tv3, tv4)) {
/* bit in the or_mask is outside the and_mask */
return or;
}
- n_tv2 = tarval_not(tv2);
- if (tv1 != tarval_and(tv1, n_tv2)) {
+ if (tv1 != tarval_andnot(tv1, tv2)) {
/* bit in the or_mask is outside the and_mask */
return or;
}
}
mode = get_irn_mode(n);
- HANDLE_BINOP_PHI(tarval_or, a, b, c, mode);
+ HANDLE_BINOP_PHI((eval_func) tarval_or, a, b, c, mode);
n = transform_node_Or_bf_store(n);
n = transform_node_Or_Rotl(n);
/* shifting too much */
if (!(tarval_cmp(res, modulo) & pn_Cmp_Lt)) {
if (is_Shrs(n)) {
- ir_graph *irg = get_irn_irg(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 *right = get_Shr_right(n);
ir_mode *mode = get_irn_mode(n);
- HANDLE_BINOP_PHI(tarval_shr, left, right, c, mode);
+ HANDLE_BINOP_PHI((eval_func) tarval_shr, left, right, c, mode);
n = transform_node_shift(n);
if (is_Shr(n))
ir_node *b = get_Shrs_right(n);
ir_mode *mode = get_irn_mode(n);
- HANDLE_BINOP_PHI(tarval_shrs, a, b, c, mode);
+ HANDLE_BINOP_PHI((eval_func) tarval_shrs, a, b, c, mode);
n = transform_node_shift(n);
if (is_Shrs(n))
ir_node *b = get_Shl_right(n);
ir_mode *mode = get_irn_mode(n);
- HANDLE_BINOP_PHI(tarval_shl, a, b, c, mode);
+ HANDLE_BINOP_PHI((eval_func) tarval_shl, a, b, c, mode);
n = transform_node_shift(n);
if (is_Shl(n))
ir_node *b = get_Rotl_right(n);
ir_mode *mode = get_irn_mode(n);
- HANDLE_BINOP_PHI(tarval_rotl, a, b, c, mode);
+ HANDLE_BINOP_PHI((eval_func) tarval_rotl, a, b, c, mode);
n = transform_node_shift(n);
if (is_Rotl(n))
ir_node *callee = get_Call_ptr(call);
ir_node *adr, *mem, *res, *bl, **in;
ir_type *ctp, *mtp, *tp;
- ident *id;
+ type_dbg_info *tdb;
dbg_info *db;
int i, n_res, n_param;
ir_variadicity var;
/* 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);
+ tdb = 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);
+ ctp = new_d_type_method(n_param + 1, n_res, tdb);
for (i = 0; i < n_res; ++i)
set_method_res_type(ctp, i, get_method_res_type(mtp, i));
/* 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);
+ tp = new_type_pointer(tp);
set_method_param_type(ctp, 0, tp);
in[0] = get_Builtin_param(callee, 2);
/** Compares the attributes of two Call nodes. */
static int node_cmp_attr_Call(ir_node *a, ir_node *b) {
- return get_irn_call_attr(a) != get_irn_call_attr(b);
+ const call_attr *pa = get_irn_call_attr(a);
+ const call_attr *pb = get_irn_call_attr(b);
+ return (pa->type != pb->type)
+ || (pa->tail_call != pb->tail_call);
} /* node_cmp_attr_Call */
/** Compares the attributes of two Sel nodes. */
* node could be found
*/
ir_node *identify_remember(pset *value_table, ir_node *n) {
- ir_node *o = NULL;
+ ir_node *nn = NULL;
if (!value_table) return n;
ir_normalize_node(n);
/* lookup or insert in hash table with given hash key. */
- o = pset_insert(value_table, n, ir_node_hash(n));
+ nn = pset_insert(value_table, n, ir_node_hash(n));
+
+ if (nn != n) {
+ update_known_irn(nn, n);
- if (o != n) {
- update_known_irn(o, n);
+ /* n is reachable again */
+ edges_node_revival(nn, get_irn_irg(nn));
}
- return o;
+ return nn;
} /* identify_remember */
/**