value_of() is now a simple wrapper around a function pointer. This allows phases...
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Mon, 14 Jul 2008 21:21:38 +0000 (21:21 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Mon, 14 Jul 2008 21:21:38 +0000 (21:21 +0000)
set_value_of_func() can be used to set a new semantic or restore the default behavior.

[r20462]

ir/ir/iropt.c
ir/ir/iropt_t.h

index b9ca652..c07e4ff 100644 (file)
 /* 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);
index fc62fbb..5e95c80 100644 (file)
@@ -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);
 }
 
 /**