Commit 0c8ec6ef authored by Michael Beck's avatar Michael Beck
Browse files

value_of() is now a simple wrapper around a function pointer. This allows...

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]
parent 478f7b6c
......@@ -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);
......
......@@ -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);
}
/**
......
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