move load mode shrinking into ldst phase
[libfirm] / ir / opt / loop.c
index 8e7fae7..2a4de53 100644 (file)
@@ -44,7 +44,6 @@
 #include "beutil.h"
 #include "irpass.h"
 #include "irdom.h"
-#include "opt_manage.h"
 
 #include <math.h>
 #include "irbackedge_t.h"
@@ -292,7 +291,6 @@ static void get_loop_info(ir_node *node, void *env)
 
                /* Find the loops head/the blocks with cfpred outside of the loop */
                if (is_Block(node)) {
-                       const ir_edge_t *edge;
                        unsigned outs_n = 0;
 
                        /* Count innerloop branches */
@@ -439,8 +437,6 @@ static void construct_ssa(ir_node *orig_block, ir_node *orig_val,
 {
        ir_graph *irg;
        ir_mode *mode;
-       const ir_edge_t *edge;
-       const ir_edge_t *next;
 
        assert(orig_block && orig_val && second_block && second_val &&
                        "no parameter of construct_ssa may be NULL");
@@ -461,7 +457,7 @@ static void construct_ssa(ir_node *orig_block, ir_node *orig_val,
        ssa_second_def       = second_val;
 
        /* Only fix the users of the first, i.e. the original node */
-       foreach_out_edge_safe(orig_val, edge, next) {
+       foreach_out_edge_safe(orig_val, edge) {
                ir_node *user = get_edge_src_irn(edge);
                int j = get_edge_src_pos(edge);
                ir_node *user_block = get_nodes_block(user);
@@ -495,7 +491,7 @@ static void set_unroll_copy(ir_node *n, int nr, ir_node *cp)
        unrolling_node_info *info;
        assert(nr != 0 && "0 reserved");
 
-       info = (unrolling_node_info*)ir_nodemap_get(&map, n);
+       info = ir_nodemap_get(unrolling_node_info, &map, n);
        if (! info) {
                ir_node **arr = NEW_ARR_D(ir_node*, &obst, unroll_nr);
                memset(arr, 0, unroll_nr * sizeof(ir_node*));
@@ -514,7 +510,7 @@ static void set_unroll_copy(ir_node *n, int nr, ir_node *cp)
 static ir_node *get_unroll_copy(ir_node *n, int nr)
 {
        ir_node             *cp;
-       unrolling_node_info *info = (unrolling_node_info *)ir_nodemap_get(&map, n);
+       unrolling_node_info *info = ir_nodemap_get(unrolling_node_info, &map, n);
        if (! info)
                return NULL;
 
@@ -534,7 +530,7 @@ static void set_inversion_copy(ir_node *n, ir_node *cp)
 /* Getter of copy of n for inversion */
 static ir_node *get_inversion_copy(ir_node *n)
 {
-       ir_node *cp = (ir_node *)ir_nodemap_get(&map, n);
+       ir_node *cp = ir_nodemap_get(ir_node, &map, n);
        return cp;
 }
 
@@ -590,6 +586,8 @@ static void extend_irn(ir_node *n, ir_node *newnode, bool new_is_backedge)
                                set_backedge(n, i);
                }
        }
+       free(ins);
+       free(bes);
 }
 
 /* Extends a block by a copy of its pred at pos,
@@ -929,7 +927,6 @@ static void get_head_outs(ir_node *node, void *env)
  */
 static void find_condition_chain(ir_node *block)
 {
-       const    ir_edge_t *edge;
        bool     mark     = false;
        bool     has_be   = false;
        bool     jmp_only = true;
@@ -1353,8 +1350,8 @@ static void loop_inversion(ir_graph *irg)
                DEL_ARR_F(cur_head_outs);
 
                /* Duplicated blocks changed doms */
-               clear_irg_state(irg, IR_GRAPH_STATE_CONSISTENT_DOMINANCE
-                                  | IR_GRAPH_STATE_CONSISTENT_LOOPINFO);
+               clear_irg_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_DOMINANCE
+                                  | IR_GRAPH_PROPERTY_CONSISTENT_LOOPINFO);
 
                ++stats.inverted;
        }
@@ -2060,7 +2057,7 @@ static ir_node *is_simple_loop(void)
        if (!is_Cmp(cmp))
                return NULL;
 
-       DB((dbg, LEVEL_5, "projection is %s\n", get_relation_string(get_Proj_proj(projx))));
+       DB((dbg, LEVEL_5, "projection is %s\n", get_relation_string(get_Cmp_relation(cmp))));
 
        switch(get_Proj_proj(projx)) {
                case pn_Cond_false:
@@ -2574,7 +2571,7 @@ static void unroll_loop(void)
                else
                        ++stats.invariant_unroll;
 
-               clear_irg_state(current_ir_graph, IR_GRAPH_STATE_CONSISTENT_DOMINANCE);
+               clear_irg_properties(current_ir_graph, IR_GRAPH_PROPERTY_CONSISTENT_DOMINANCE);
 
                DEL_ARR_F(loop_entries);
                obstack_free(&obst, NULL);
@@ -2678,6 +2675,11 @@ void loop_optimization(ir_graph *irg)
        size_t   i;
        size_t   n_elements;
 
+       assure_irg_properties(irg,
+               IR_GRAPH_PROPERTY_CONSISTENT_OUT_EDGES
+               | IR_GRAPH_PROPERTY_CONSISTENT_OUTS
+               | IR_GRAPH_PROPERTY_CONSISTENT_LOOPINFO);
+
        set_loop_params();
 
        /* Reset stats for this procedure */
@@ -2724,56 +2726,28 @@ void loop_optimization(ir_graph *irg)
 
        DEL_ARR_F(loops);
        ir_free_resources(irg, IR_RESOURCE_IRN_LINK | IR_RESOURCE_PHI_LIST);
+
+       confirm_irg_properties(irg, IR_GRAPH_PROPERTIES_NONE);
 }
 
-static ir_graph_state_t perform_loop_unrolling(ir_graph *irg)
+void do_loop_unrolling(ir_graph *irg)
 {
        loop_op = loop_op_unrolling;
        loop_optimization(irg);
-       return 0;
 }
 
-static ir_graph_state_t perform_loop_inversion(ir_graph *irg)
+void do_loop_inversion(ir_graph *irg)
 {
        loop_op = loop_op_inversion;
        loop_optimization(irg);
-       return 0;
 }
 
-static ir_graph_state_t perform_loop_peeling(ir_graph *irg)
+void do_loop_peeling(ir_graph *irg)
 {
        loop_op = loop_op_peeling;
        loop_optimization(irg);
-       return 0;
 }
 
-static optdesc_t opt_unroll_loops = {
-       "unroll-loops",
-       IR_GRAPH_STATE_CONSISTENT_OUT_EDGES | IR_GRAPH_STATE_CONSISTENT_OUTS | IR_GRAPH_STATE_CONSISTENT_LOOPINFO,
-       perform_loop_unrolling,
-};
-
-static optdesc_t opt_invert_loops = {
-       "invert-loops",
-       IR_GRAPH_STATE_CONSISTENT_OUT_EDGES | IR_GRAPH_STATE_CONSISTENT_OUTS | IR_GRAPH_STATE_CONSISTENT_LOOPINFO,
-       perform_loop_inversion,
-};
-
-static optdesc_t opt_peel_loops = {
-       "peel-loops",
-       IR_GRAPH_STATE_CONSISTENT_OUT_EDGES | IR_GRAPH_STATE_CONSISTENT_OUTS | IR_GRAPH_STATE_CONSISTENT_LOOPINFO,
-       perform_loop_peeling,
-};
-
-void do_loop_unrolling(ir_graph *irg)
-{ perform_irg_optimization(irg, &opt_unroll_loops); }
-
-void do_loop_inversion(ir_graph *irg)
-{ perform_irg_optimization(irg, &opt_invert_loops); }
-
-void do_loop_peeling(ir_graph *irg)
-{ perform_irg_optimization(irg, &opt_peel_loops); }
-
 ir_graph_pass_t *loop_inversion_pass(const char *name)
 {
        return def_graph_pass(name ? name : "loop_inversion", do_loop_inversion);