simplify and cleanup execfreq API
[libfirm] / ir / opt / scalar_replace.c
index d10e291..414ed26 100644 (file)
@@ -21,7 +21,6 @@
  * @file
  * @brief   Scalar replacement of compounds.
  * @author  Beyhan Veliev, Michael Beck
- * @version $Id$
  */
 #include "config.h"
 
@@ -43,7 +42,7 @@
 #include "irgmod.h"
 #include "irnode_t.h"
 #include "irpass.h"
-#include "irtools.h"
+#include "util.h"
 #include "xmalloc.h"
 #include "debug.h"
 #include "error.h"
@@ -79,7 +78,10 @@ typedef struct path_t {
 } path_t;
 
 /** The size of a path in bytes. */
-#define PATH_SIZE(p)  (sizeof(*(p)) + sizeof((p)->path[0]) * ((p)->path_len - 1))
+static size_t path_size(path_t *p)
+{
+       return sizeof(*p) + sizeof(p->path[0]) * (p->path_len-1);
+}
 
 typedef struct scalars_t {
        ir_entity *ent;              /**< A entity for scalar replacement. */
@@ -170,7 +172,6 @@ static bool check_load_store_mode(ir_mode *mode, ir_mode *ent_mode)
        if (ent_mode != mode) {
                if (ent_mode == NULL ||
                    get_mode_size_bits(ent_mode) != get_mode_size_bits(mode) ||
-                   get_mode_sort(ent_mode) != get_mode_sort(mode) ||
                    get_mode_arithmetic(ent_mode) != irma_twos_complement ||
                    get_mode_arithmetic(mode) != irma_twos_complement)
                        return false;
@@ -365,7 +366,7 @@ static int find_possible_replacements(ir_graph *irg)
                        ir_node  *args;
                        int      j;
 
-                       assure_irg_outs(inner_irg);
+                       assure_irg_properties(inner_irg, IR_GRAPH_PROPERTY_CONSISTENT_OUTS);
                        args = get_irg_args(inner_irg);
                        for (j = get_irn_n_outs(args) - 1; j >= 0; --j) {
                                ir_node *arg = get_irn_out(args, j);
@@ -496,7 +497,7 @@ static unsigned allocate_value_numbers(pset *sels, ir_entity *ent, unsigned vnum
                pset_insert_ptr(sels, sel);
 
                key  = find_path(sel, 0);
-               path = (path_t*)set_find(pathes, key, PATH_SIZE(key), path_hash(key));
+               path = set_find(path_t, pathes, key, path_size(key), path_hash(key));
 
                if (path) {
                        set_vnum(sel, path->vnum);
@@ -504,7 +505,7 @@ static unsigned allocate_value_numbers(pset *sels, ir_entity *ent, unsigned vnum
                } else {
                        key->vnum = vnum++;
 
-                       set_insert(pathes, key, PATH_SIZE(key), path_hash(key));
+                       (void)set_insert(path_t, pathes, key, path_size(key), path_hash(key));
 
                        set_vnum(sel, key->vnum);
                        DB((dbg, SET_LEVEL_3, "  %+F represents value %u\n", sel, key->vnum));
@@ -675,20 +676,20 @@ static void do_scalar_replacements(ir_graph *irg, pset *sels, unsigned nvals,
  *
  * @param irg  The current ir graph.
  */
-int scalar_replacement_opt(ir_graph *irg)
+void scalar_replacement_opt(ir_graph *irg)
 {
        unsigned  nvals;
        int       i;
-       scalars_t key, *value;
+       scalars_t key;
        ir_node   *irg_frame;
        ir_mode   **modes;
        set       *set_ent;
        pset      *sels;
        ir_type   *ent_type, *frame_tp;
-       int       res = 0;
 
-       /* Call algorithm that computes the out edges */
-       assure_irg_outs(irg);
+       assure_irg_properties(irg,
+               IR_GRAPH_PROPERTY_NO_UNREACHABLE_CODE
+               | IR_GRAPH_PROPERTY_CONSISTENT_OUTS);
 
        /* we use the link field to store the VNUM */
        ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK);
@@ -713,8 +714,9 @@ int scalar_replacement_opt(ir_graph *irg)
                                ir_entity *ent = get_Sel_entity(succ);
 
                                /* we are only interested in entities on the frame, NOT
-                                  on the value type */
-                               if (get_entity_owner(ent) != frame_tp)
+                                  parameters */
+                               if (get_entity_owner(ent) != frame_tp
+                                   || is_parameter_entity(ent))
                                        continue;
 
                                if (get_entity_link(ent) == NULL || get_entity_link(ent) == ADDRESS_TAKEN)
@@ -723,7 +725,7 @@ int scalar_replacement_opt(ir_graph *irg)
                                ent_type = get_entity_type(ent);
 
                                key.ent       = ent;
-                               set_insert(set_ent, &key, sizeof(key), HASH_PTR(key.ent));
+                               (void)set_insert(scalars_t, set_ent, &key, sizeof(key), hash_ptr(key.ent));
 
 #ifdef DEBUG_libfirm
                                if (is_Array_type(ent_type)) {
@@ -747,7 +749,7 @@ int scalar_replacement_opt(ir_graph *irg)
                if (nvals > 0) {
                        do_scalar_replacements(irg, sels, nvals, modes);
 
-                       foreach_set(set_ent, scalars_t*, value) {
+                       foreach_set(set_ent, scalars_t, value) {
                                free_entity(value->ent);
                        }
 
@@ -756,7 +758,6 @@ int scalar_replacement_opt(ir_graph *irg)
                         * neither changed control flow, cf-backedges should be still
                         * consistent.
                         */
-                       res = 1;
                }
                del_pset(sels);
                del_set(set_ent);
@@ -766,13 +767,12 @@ int scalar_replacement_opt(ir_graph *irg)
        ir_free_resources(irg, IR_RESOURCE_IRN_LINK);
        irp_free_resources(irp, IRP_RESOURCE_ENTITY_LINK);
 
-       return res;
+       confirm_irg_properties(irg, IR_GRAPH_PROPERTIES_NONE);
 }
 
 ir_graph_pass_t *scalar_replacement_opt_pass(const char *name)
 {
-       return def_graph_pass_ret(name ? name : "scalar_rep",
-                                 scalar_replacement_opt);
+       return def_graph_pass(name ? name : "scalar_rep", scalar_replacement_opt);
 }
 
 void firm_init_scalar_replace(void)