From: Michael Beck Date: Mon, 14 Jul 2008 21:21:38 +0000 (+0000) Subject: value_of() is now a simple wrapper around a function pointer. This allows phases... X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=0c8ec6efe050e425be99454315e4f58b0976a38a;p=libfirm value_of() is now a simple wrapper around a function pointer. This allows phases to have its own value_of semantic (needed for the combo algorithm for instance). set_value_of_func() can be used to set a new semantic or restore the default behavior. [r20462] --- diff --git a/ir/ir/iropt.c b/ir/ir/iropt.c index b9ca652b0..c07e4ff21 100644 --- a/ir/ir/iropt.c +++ b/ir/ir/iropt.c @@ -53,6 +53,25 @@ /* Make types visible to allow most efficient access */ #include "entity_t.h" +/** + * Returns the tarval of a Const node or tarval_bad for all other nodes. + */ +static tarval *default_value_of(const ir_node *n) { + if (is_Const(n)) + return get_Const_tarval(n); /* might return tarval_bad */ + else + return tarval_bad; +} + +value_of_func value_of_ptr = default_value_of; + +void set_value_of_func(value_of_func func) { + if (func != NULL) + value_of_ptr = func; + else + value_of_ptr = default_value_of; +} + /** * Return the value of a Constant. */ @@ -4693,6 +4712,7 @@ static ir_node *transform_node_shift(ir_node *n) { ir_node *left, *right; ir_mode *mode; tarval *tv1, *tv2, *res; + ir_node *in[2], *irn, *block; left = get_binop_left(n); @@ -4739,7 +4759,7 @@ static ir_node *transform_node_shift(ir_node *n) { } /* ok, we can replace it */ - ir_node *in[2], *irn, *block = get_irn_n(n, -1); + 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); diff --git a/ir/ir/iropt_t.h b/ir/ir/iropt_t.h index fc62fbbcd..5e95c801d 100644 --- a/ir/ir/iropt_t.h +++ b/ir/ir/iropt_t.h @@ -82,14 +82,28 @@ ir_node *optimize_node(ir_node *n); ir_node *optimize_in_place_2(ir_node *n); /** - * Returns the tarval of a Const node or tarval_bad for all other nodes. + * The value_of operation. + * This operation returns for every IR node an associated tarval if existing, + * returning tarval_bad otherwise. + * No calculations are done here, just a lookup. + */ +typedef tarval *(*value_of_func)(const ir_node *self); + +extern value_of_func value_of_ptr; + +/** + * Set a new value_of function. + * + * @param func the function, NULL restores the default behavior + */ +void set_value_of_func(value_of_func func); + +/** + * Returns the associated tarval of a node. */ static INLINE tarval * -value_of(ir_node *n) { - if ((n != NULL) && is_Const(n)) - return get_Const_tarval(n); /* might return tarval_bad */ - else - return tarval_bad; +value_of(const ir_node *n) { + return value_of_ptr(n); } /**