fix irio not working correctly anymore after MacroBlocks were removed
[libfirm] / ir / opt / opt_ldst.c
index 9b0c2ef..dcf7513 100644 (file)
@@ -45,7 +45,7 @@
 #include "irpass.h"
 
 /* maximum number of output Proj's */
-#define MAX_PROJ (pn_Load_max > pn_Store_max ? pn_Load_max : pn_Store_max)
+#define MAX_PROJ ((long)pn_Load_max > (long)pn_Store_max ? (long)pn_Load_max : (long)pn_Store_max)
 
 /**
  * Mapping an address to an dense ID.
@@ -158,7 +158,8 @@ static void dump_block_list(ldst_env *env)
                for (op = entry->memop_forward; op != NULL; op = op->next) {
                        if (i == 0) {
                                DB((dbg, LEVEL_2, "\n\t"));
-                       }                       DB((dbg, LEVEL_2, "%+F", op->node));
+                       }
+                       DB((dbg, LEVEL_2, "%+F", op->node));
                        if ((op->flags & FLAG_KILL_ALL) == FLAG_KILL_ALL)
                                DB((dbg, LEVEL_2, "X"));
                        else if (op->flags & FLAG_KILL_ALL)
@@ -215,14 +216,14 @@ static block_t *get_block_entry(const ir_node *block)
 {
        assert(is_Block(block));
 
-       return get_irn_link(block);
+       return (block_t*)get_irn_link(block);
 }  /* get_block_entry */
 
 /** Get the memop entry for a memory operation node */
 static memop_t *get_irn_memop(const ir_node *irn)
 {
        assert(! is_Block(irn));
-       return get_irn_link(irn);
+       return (memop_t*)get_irn_link(irn);
 }  /* get_irn_memop */
 
 /**
@@ -311,7 +312,7 @@ restart:
                goto restart;
        }
 
-       entry = ir_nodemap_get(&env.adr_map, adr);
+       entry = (address_entry*)ir_nodemap_get(&env.adr_map, adr);
 
        if (entry == NULL) {
                /* new address */
@@ -560,10 +561,10 @@ static ir_entity *find_constant_entity(ir_node *ptr)
                                int i, n;
 
                                for (i = 0, n = get_Sel_n_indexs(ptr); i < n; ++i) {
-                                       ir_node *bound;
-                                       tarval *tlower, *tupper;
-                                       ir_node *index = get_Sel_index(ptr, i);
-                                       tarval *tv     = computed_value(index);
+                                       ir_node   *bound;
+                                       ir_tarval *tlower, *tupper;
+                                       ir_node   *index = get_Sel_index(ptr, i);
+                                       ir_tarval *tv     = computed_value(index);
 
                                        /* check if the index is constant */
                                        if (tv == tarval_bad)
@@ -609,7 +610,7 @@ static ir_entity *find_constant_entity(ir_node *ptr)
                        ir_node *l = get_Sub_left(ptr);
                        ir_node *r = get_Sub_right(ptr);
 
-                       if (get_irn_mode(l) == get_irn_mode(ptr) &&     is_Const(r))
+                       if (get_irn_mode(l) == get_irn_mode(ptr) && is_Const(r))
                                ptr = l;
                        else
                                return NULL;
@@ -644,7 +645,7 @@ static compound_graph_path *rec_get_accessed_path(ir_node *ptr, int depth)
        compound_graph_path *res = NULL;
        ir_entity           *root, *field, *ent;
        int                 path_len, pos, idx;
-       tarval              *tv;
+       ir_tarval           *tv;
        ir_type             *tp;
 
        if (is_SymConst(ptr)) {
@@ -672,17 +673,19 @@ static compound_graph_path *rec_get_accessed_path(ir_node *ptr, int depth)
                        set_compound_graph_path_array_index(res, pos, get_Sel_array_index_long(ptr, 0));
                }
        } else if (is_Add(ptr)) {
-               ir_node *l    = get_Add_left(ptr);
-               ir_node *r    = get_Add_right(ptr);
-               ir_mode *mode = get_irn_mode(ptr);
-               tarval  *tmp;
-
-               if (is_Const(r) && get_irn_mode(l) == mode) {
-                       ptr = l;
-                       tv  = get_Const_tarval(r);
-               } else {
-                       ptr = r;
-                       tv  = get_Const_tarval(l);
+               ir_mode   *mode;
+               ir_tarval *tmp;
+
+               {
+                       ir_node *l = get_Add_left(ptr);
+                       ir_node *r = get_Add_right(ptr);
+                       if (is_Const(r) && get_irn_mode(l) == get_irn_mode(ptr)) {
+                               ptr = l;
+                               tv  = get_Const_tarval(r);
+                       } else {
+                               ptr = r;
+                               tv  = get_Const_tarval(l);
+                       }
                }
 ptr_arith:
                mode = get_tarval_mode(tv);
@@ -696,9 +699,9 @@ ptr_arith:
                }
                idx = 0;
                for (ent = field;;) {
-                       unsigned size;
-                       tarval   *sz, *tv_index, *tlower, *tupper;
-                       ir_node  *bound;
+                       unsigned  size;
+                       ir_tarval *sz, *tv_index, *tlower, *tupper;
+                       ir_node   *bound;
 
                        tp = get_entity_type(ent);
                        if (! is_Array_type(tp))
@@ -747,9 +750,9 @@ ptr_arith:
                pos      = path_len - depth - idx;
 
                for (ent = field;;) {
-                       unsigned size;
-                       tarval   *sz, *tv_index;
-                       long     index;
+                       unsigned   size;
+                       ir_tarval *sz, *tv_index;
+                       long       index;
 
                        tp = get_entity_type(ent);
                        if (! is_Array_type(tp))
@@ -804,7 +807,7 @@ static ir_node *rec_find_compound_ent_value(ir_node *ptr, path_entry *next)
        path_entry       entry, *p;
        ir_entity        *ent, *field;
        ir_initializer_t *initializer;
-       tarval           *tv;
+       ir_tarval        *tv;
        ir_type          *tp;
        unsigned         n;
 
@@ -875,17 +878,19 @@ static ir_node *rec_find_compound_ent_value(ir_node *ptr, path_entry *next)
                }
                return rec_find_compound_ent_value(get_Sel_ptr(ptr), &entry);
        }  else if (is_Add(ptr)) {
-               ir_node  *l = get_Add_left(ptr);
-               ir_node  *r = get_Add_right(ptr);
-               ir_mode  *mode;
+               ir_mode *mode;
                unsigned pos;
 
-               if (is_Const(r)) {
-                       ptr = l;
-                       tv  = get_Const_tarval(r);
-               } else {
-                       ptr = r;
-                       tv  = get_Const_tarval(l);
+               {
+                       ir_node *l = get_Add_left(ptr);
+                       ir_node *r = get_Add_right(ptr);
+                       if (is_Const(r)) {
+                               ptr = l;
+                               tv  = get_Const_tarval(r);
+                       } else {
+                               ptr = r;
+                               tv  = get_Const_tarval(l);
+                       }
                }
 ptr_arith:
                mode = get_tarval_mode(tv);
@@ -916,10 +921,10 @@ ptr_arith:
                /* fill them up */
                pos = 0;
                for (ent = field;;) {
-                       unsigned size;
-                       tarval   *sz, *tv_index, *tlower, *tupper;
-                       long     index;
-                       ir_node  *bound;
+                       unsigned  size;
+                       ir_tarval *sz, *tv_index, *tlower, *tupper;
+                       long      index;
+                       ir_node   *bound;
 
                        tp = get_entity_type(ent);
                        if (! is_Array_type(tp))
@@ -1059,7 +1064,8 @@ static void update_Load_memop(memop_t *m)
 
                /* no exception, clear the m fields as it might be checked later again */
                if (m->projs[pn_Load_X_except]) {
-                       exchange(m->projs[pn_Load_X_except], new_Bad());
+                       ir_graph *irg = get_irn_irg(ptr);
+                       exchange(m->projs[pn_Load_X_except], new_r_Bad(irg));
                        m->projs[pn_Load_X_except] = NULL;
                        m->flags &= ~FLAG_EXCEPTION;
                        env.changed = 1;
@@ -1245,7 +1251,8 @@ static void collect_memops(ir_node *irn, void *ctx)
        (void) ctx;
        if (is_Proj(irn)) {
                /* we can safely ignore ProjM's except the initial memory */
-               if (irn != get_irg_initial_mem(current_ir_graph))
+               ir_graph *irg = get_irn_irg(irn);
+               if (irn != get_irg_initial_mem(irg))
                        return;
        }
 
@@ -1378,7 +1385,7 @@ static void kill_memops(const value_t *value)
        for (pos = rbitset_next(env.curr_set, 0, 1); pos < end; pos = rbitset_next(env.curr_set, pos + 1, 1)) {
                memop_t *op = env.curr_id_2_memop[pos];
 
-               if (ir_no_alias != get_alias_relation(current_ir_graph, value->address, value->mode,
+               if (ir_no_alias != get_alias_relation(value->address, value->mode,
                                                          op->value.address, op->value.mode)) {
                        rbitset_clear(env.curr_set, pos);
                        env.curr_id_2_memop[pos] = NULL;
@@ -1690,7 +1697,7 @@ static int backward_antic(block_t *bl)
        }
 
        memcpy(bl->id_2_memop_antic, env.curr_id_2_memop, env.rbs_size * sizeof(env.curr_id_2_memop[0]));
-       if (! rbitset_equal(bl->anticL_in, env.curr_set, env.rbs_size)) {
+       if (! rbitsets_equal(bl->anticL_in, env.curr_set, env.rbs_size)) {
                /* changed */
                rbitset_copy(bl->anticL_in, env.curr_set, env.rbs_size);
                dump_curr(bl, "AnticL_in*");
@@ -1740,7 +1747,8 @@ static void replace_load(memop_t *op)
        }
        proj = op->projs[pn_Load_X_except];
        if (proj != NULL) {
-               exchange(proj, new_Bad());
+               ir_graph *irg = get_irn_irg(load);
+               exchange(proj, new_r_Bad(irg));
        }
        proj = op->projs[pn_Load_X_regular];
        if (proj != NULL) {
@@ -1766,7 +1774,8 @@ static void remove_store(memop_t *op)
        }
        proj = op->projs[pn_Store_X_except];
        if (proj != NULL) {
-               exchange(proj, new_Bad());
+               ir_graph *irg = get_irn_irg(store);
+               exchange(proj, new_r_Bad(irg));
        }
        proj = op->projs[pn_Store_X_regular];
        if (proj != NULL) {
@@ -2166,7 +2175,7 @@ static int insert_Load(block_t *bl)
        /* always update the map after gen/kill, as values might have been changed due to RAR/WAR/WAW */
        memcpy(bl->id_2_memop_avail, env.curr_id_2_memop, env.rbs_size * sizeof(env.curr_id_2_memop[0]));
 
-       if (!rbitset_equal(bl->avail_out, env.curr_set, env.rbs_size)) {
+       if (!rbitsets_equal(bl->avail_out, env.curr_set, env.rbs_size)) {
                /* the avail set has changed */
                rbitset_copy(bl->avail_out, env.curr_set, env.rbs_size);
                dump_curr(bl, "Avail_out*");
@@ -2302,21 +2311,15 @@ static void kill_unreachable_blocks(ir_graph *irg)
 
 int opt_ldst(ir_graph *irg)
 {
-       block_t  *bl;
-       ir_graph *rem = current_ir_graph;
-
-       current_ir_graph = irg;
+       block_t *bl;
 
        FIRM_DBG_REGISTER(dbg, "firm.opt.ldst");
-//     firm_dbg_set_mask(dbg, -1);
 
        DB((dbg, LEVEL_1, "\nDoing Load/Store optimization on %+F\n", irg));
 
        /* we need landing pads */
        remove_critical_cf_edges(irg);
 
-//     dump_ir_block_graph(irg, "-XXX");
-
        if (get_opt_alias_analysis()) {
                assure_irg_entity_usage_computed(irg);
                assure_irp_globals_entity_usage_computed();
@@ -2417,7 +2420,6 @@ int opt_ldst(ir_graph *irg)
                memset(bl->id_2_memop_antic, 0, env.rbs_size * sizeof(bl->id_2_memop_antic[0]));
        }
 
-//     dump_block_list(&env);
        (void) dump_block_list;
 
        calcAvail();
@@ -2442,13 +2444,10 @@ end:
        ir_nodemap_destroy(&env.adr_map);
        obstack_free(&env.obst, NULL);
 
-//     dump_ir_block_graph(irg, "-YYY");
-
 #ifdef DEBUG_libfirm
        DEL_ARR_F(env.id_2_address);
 #endif
 
-       current_ir_graph = rem;
        return env.changed != 0;
 }  /* opt_ldst */