/**
* @file
- * @brief analyze graph to provide value range information
- * @author Jonas Fietz
- * @version $Id$
+ * @brief analyze graph to provide value range information
+ * @author Jonas Fietz
+ * @version $Id$
*/
#include "config.h"
#include "irop.h"
#include "pdeq.h"
#include "irphase_t.h"
+#include "bitset.h"
#include "debug.h"
-static char v;
-static void *VISITED = &v;
+DEBUG_ONLY(static firm_dbg_module_t *dbg);
-struct vrp_env_t {
- waitq *workqueue;
- DEBUG_ONLY(firm_dbg_module_t *dbg);
-};
+typedef struct vrp_env_t {
+ waitq *workqueue;
+ bitset_t *visited;
+} vrp_env_t;
static vrp_attr *get_vrp_attr(const ir_node *node)
{
static int vrp_update_node(ir_node *node)
{
- tarval *new_bits_set = get_tarval_bad();
- tarval *new_bits_not_set = get_tarval_bad();
- tarval *new_range_bottom = get_tarval_bad();
- tarval *new_range_top = get_tarval_bad();
+ ir_tarval *new_bits_set = get_tarval_bad();
+ ir_tarval *new_bits_not_set = get_tarval_bad();
+ ir_tarval *new_range_bottom = get_tarval_bad();
+ ir_tarval *new_range_top = get_tarval_bad();
enum range_types new_range_type = VRP_UNDEFINED;
int something_changed = 0;
vrp_attr *vrp;
switch (get_irn_opcode(node)) {
case iro_Const: {
- tarval *tv = get_Const_tarval(node);
+ ir_tarval *tv = get_Const_tarval(node);
new_bits_set = tv;
new_bits_not_set = tv;
new_range_bottom = tv;
case iro_Add: {
int overflow_top, overflow_bottom;
- tarval *new_top, *new_bottom;
+ ir_tarval *new_top, *new_bottom;
const vrp_attr *vrp_left, *vrp_right;
vrp_left = get_vrp_attr(get_Add_left(node));
vrp_right = get_vrp_attr(get_Add_right(node));
case iro_Sub: {
int overflow_top, overflow_bottom;
- tarval *new_top, *new_bottom;
+ ir_tarval *new_top, *new_bottom;
const vrp_attr *vrp_left, *vrp_right;
vrp_left = get_vrp_attr(get_Sub_left(node));
vrp_right = get_vrp_attr(get_Sub_right(node));
/* We can only compute this if the right value is a constant*/
if (is_Const(right)) {
- tarval *bits_set, *bits_not_set;
+ ir_tarval *bits_set, *bits_not_set;
bits_set = tarval_rotl(vrp_left->bits_set, get_Const_tarval(right));
bits_not_set = tarval_rotl(vrp_left->bits_not_set, get_Const_tarval(right));
}
static void vrp_first_pass(ir_node *n, void *e)
{
- ir_node *succ;
int i;
- struct vrp_env_t *env = e;
+ vrp_env_t *env = (vrp_env_t*) e;
if (is_Block(n))
return;
- set_irn_link(n, VISITED);
+ bitset_set(env->visited, get_irn_idx(n));
vrp_update_node(n);
assure_irg_outs(get_current_ir_graph());
for (i = get_irn_n_outs(n) - 1; i >=0; --i) {
- succ = get_irn_out(n, i);
- if (get_irn_link(succ) == VISITED) {
+ ir_node *succ = get_irn_out(n, i);
+ if (bitset_is_set(env->visited, get_irn_idx(succ))) {
/* we found a loop*/
waitq_put(env->workqueue, succ);
}
{
ir_mode *mode;
vrp_attr *vrp;
- struct vrp_env_t *env = phase->priv;
- DBG((env->dbg, LEVEL_2, "initialized node nr: %d\n", get_irn_node_nr(n)));
- vrp = phase_alloc(phase, sizeof(vrp_attr));
+ DBG((dbg, LEVEL_2, "initialized node nr: %d\n", get_irn_node_nr(n)));
+ vrp = (vrp_attr*) phase_alloc(phase, sizeof(vrp_attr));
memset(vrp, 0, sizeof(vrp_attr));
/* Initialize the vrp information to default */
{
ir_node *succ, *node;
int i;
- struct vrp_env_t *env;
+ vrp_env_t *env;
ir_phase *phase;
+ FIRM_DBG_REGISTER(dbg, "ir.ana.vrp");
+
assure_irg_outs(irg); /* ensure that out edges are consistent*/
phase = irg_get_phase(irg, PHASE_VRP);
if (phase == NULL) {
/* this is our first run */
phase = new_phase(irg, vrp_init_node);
irg_register_phase(irg, PHASE_VRP, phase);
- env = phase_alloc(phase, sizeof(*env));
- FIRM_DBG_REGISTER(env->dbg, "ir.ana.vrp");
+ env = (vrp_env_t*) phase_alloc(phase, sizeof(*env));
phase->priv = env;
} else {
- env = phase->priv;
+ env = (vrp_env_t*) phase->priv;
}
env->workqueue = new_waitq();
+ env->visited = bitset_malloc(get_irg_last_idx(irg));
irg_walk_graph(irg, NULL, vrp_first_pass, env);
+ bitset_free(env->visited);
/* while there are entries in the worklist, continue*/
while (!waitq_empty(env->workqueue)) {
- node = waitq_get(env->workqueue);
+ node = (ir_node*) waitq_get(env->workqueue);
if (vrp_update_node(node)) {
/* if something changed, add successors to worklist*/
del_waitq(env->workqueue);
}
-
ir_graph_pass_t *set_vrp_pass(const char *name)
{
return def_graph_pass(name ? name : "set_vrp", set_vrp_data);
return NULL;
}
- vrp = phase_get_irn_data(phase, node);
+ vrp = (vrp_attr*) phase_get_irn_data(phase, node);
if (vrp && vrp->valid) {
return vrp;
}
+
return NULL;
}