trverify: cleanup, check irg.entity == entity.irg
[libfirm] / ir / opt / scalar_replace.c
index c5f2a75..9506551 100644 (file)
@@ -21,7 +21,6 @@
  * @file
  * @brief   Scalar replacement of compounds.
  * @author  Beyhan Veliev, Michael Beck
- * @version $Id$
  */
 #include "config.h"
 
 #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"
+#include "opt_manage.h"
 
 static unsigned get_vnum(const ir_node *node)
 {
@@ -173,7 +173,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;
@@ -678,7 +677,7 @@ 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)
+static ir_graph_state_t do_scalar_replacement(ir_graph *irg)
 {
        unsigned  nvals;
        int       i;
@@ -688,10 +687,6 @@ int scalar_replacement_opt(ir_graph *irg)
        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);
 
        /* we use the link field to store the VNUM */
        ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK);
@@ -727,7 +722,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));
+                               set_insert(set_ent, &key, sizeof(key), hash_ptr(key.ent));
 
 #ifdef DEBUG_libfirm
                                if (is_Array_type(ent_type)) {
@@ -760,7 +755,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);
@@ -770,7 +764,19 @@ 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;
+       return 0;
+}
+
+static optdesc_t opt_scalar_rep = {
+       "scalar-replace",
+       IR_GRAPH_STATE_NO_UNREACHABLE_CODE | IR_GRAPH_STATE_CONSISTENT_OUTS,
+       do_scalar_replacement,
+};
+
+int scalar_replacement_opt(ir_graph *irg)
+{
+       perform_irg_optimization(irg, &opt_scalar_rep);
+       return 1;
 }
 
 ir_graph_pass_t *scalar_replacement_opt_pass(const char *name)