normalize some bittest constructs
[libfirm] / ir / opt / opt_ldst.c
index b704abe..ac55061 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
+ * Copyright (C) 1995-2011 University of Karlsruhe.  All right reserved.
  *
  * This file is part of libFirm.
  *
@@ -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.
@@ -125,7 +125,7 @@ typedef struct ldst_env_t {
        memop_t         **curr_id_2_memop; /**< current map of address ids to memops */
        unsigned        curr_adr_id;       /**< number for address mapping */
        unsigned        n_mem_ops;         /**< number of memory operations (Loads/Stores) */
-       unsigned        rbs_size;          /**< size of all bitsets in bytes */
+       size_t          rbs_size;          /**< size of all bitsets in bytes */
        int             max_cfg_preds;     /**< maximum number of block cfg predecessors */
        int             changed;           /**< Flags for changed graph state */
 #ifdef DEBUG_libfirm
@@ -180,9 +180,9 @@ static void dump_block_list(ldst_env *env)
  */
 static void dump_curr(block_t *bl, const char *s)
 {
-       unsigned end = env.rbs_size - 1;
-       unsigned pos;
-       int      i;
+       size_t end = env.rbs_size - 1;
+       size_t pos;
+       int    i;
 
        DB((dbg, LEVEL_2, "%s[%+F] = {", s, bl->block));
        i = 0;
@@ -216,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 */
 
 /**
@@ -312,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 */
@@ -561,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)
@@ -645,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)) {
@@ -673,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);
@@ -697,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))
@@ -748,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))
@@ -805,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;
 
@@ -876,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);
@@ -917,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))
@@ -1197,7 +1201,7 @@ static void update_Call_memop(memop_t *m)
 }  /* update_Call_memop */
 
 /**
- * Update a memop for a Div/Mod/Quot/DivMod.
+ * Update a memop for a Div/Mod.
  *
  * @param m  the memop
  */
@@ -1247,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;
        }
 
@@ -1286,8 +1291,6 @@ static void collect_memops(ir_node *irn, void *ctx)
                        /* we can those to find the memory edge */
                        break;
                case iro_Div:
-               case iro_DivMod:
-               case iro_Quot:
                case iro_Mod:
                        update_DivOp_memop(op);
                        break;
@@ -1374,13 +1377,13 @@ static void kill_all(void)
  */
 static void kill_memops(const value_t *value)
 {
-       unsigned end = env.rbs_size - 1;
-       unsigned pos;
+       size_t end = env.rbs_size - 1;
+       size_t pos;
 
        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;
@@ -1596,8 +1599,8 @@ static int backward_antic(block_t *bl)
                ir_node  *succ    = get_Block_cfg_out(block, 0);
                block_t  *succ_bl = get_block_entry(succ);
                int      pred_pos = get_Block_cfgpred_pos(succ, block);
-               unsigned end      = env.rbs_size - 1;
-               unsigned pos;
+               size_t   end      = env.rbs_size - 1;
+               size_t   pos;
 
                kill_all();
 
@@ -1935,8 +1938,7 @@ static int insert_Load(block_t *bl)
 {
        ir_node  *block = bl->block;
        int      i, n = get_Block_n_cfgpreds(block);
-       unsigned end = env.rbs_size - 1;
-       unsigned pos;
+       size_t   end = env.rbs_size - 1;
 
        DB((dbg, LEVEL_3, "processing %+F\n", block));
 
@@ -1947,7 +1949,7 @@ static int insert_Load(block_t *bl)
 
        if (n > 1) {
                ir_node **ins;
-               int     pos;
+               size_t    pos;
 
                NEW_ARR_A(ir_node *, ins, n);
 
@@ -1974,9 +1976,9 @@ static int insert_Load(block_t *bl)
                }
                /*
                 * Ensure that all values are in the map: build Phi's if necessary:
-                * Note: the last bit is the sentinel and ALWAYS set, so start with -2.
+                * Note: the last bit is the sentinel and ALWAYS set, so end with -2.
                 */
-               for (pos = env.rbs_size - 2; pos >= 0; --pos) {
+               for (pos = 0; pos < env.rbs_size - 1; ++pos) {
                        if (! rbitset_is_set(env.curr_set, pos))
                                env.curr_id_2_memop[pos] = NULL;
                        else {
@@ -2040,6 +2042,8 @@ static int insert_Load(block_t *bl)
        }
 
        if (n > 1) {
+               size_t pos;
+
                /* check for partly redundant values */
                for (pos = rbitset_next(bl->anticL_in, 0, 1);
                     pos < end;
@@ -2306,10 +2310,7 @@ 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");
 
@@ -2446,7 +2447,6 @@ end:
        DEL_ARR_F(env.id_2_address);
 #endif
 
-       current_ir_graph = rem;
        return env.changed != 0;
 }  /* opt_ldst */