typo fixed
[libfirm] / ir / be / becopyopt.c
index 0c40454..667bf90 100644 (file)
@@ -10,6 +10,9 @@
 #ifdef HAVE_ALLOCA_H
 #include <alloca.h>
 #endif
+#ifdef HAVE_MALLOC_H
+#include <malloc.h>
+#endif
 
 #include "irprog.h"
 
@@ -103,7 +106,7 @@ conflict_found:
 static void co_append_unit(copy_opt_t *co, ir_node *root) {
        int i, arity;
        unit_t *unit;
-       DBG((dbg, LEVEL_1, "\t  Root: %n\n", root));
+       DBG((dbg, LEVEL_1, "\t  Root: %n %N\n", root, root));
        /* check if we encountered this root earlier */
        if (pset_find_ptr(co->roots, root))
                return;
@@ -122,20 +125,28 @@ static void co_append_unit(copy_opt_t *co, ir_node *root) {
        INIT_LIST_HEAD(&unit->queue);
 
        /* check all args */
-       for (i=0; i<arity; ++i) {
-               ir_node *arg = get_irn_n(root, i);
-               assert(is_curr_reg_class(arg) && "Argument not in same register class.");
-               if (arg != root) {
-                       if (!nodes_interfere(co->chordal_env, root, arg)) {
-                               DBG((dbg, LEVEL_1, "\t  Member: %n\n", arg));
-                               if (is_optimizable(arg))
-                                       co_append_unit(co, arg);
-                               unit->nodes[unit->node_count++] = arg;
-                       } else
-                               unit->interf++;
+       if (is_Phi(root)) {
+               for (i=0; i<arity; ++i) {
+                       ir_node *arg = get_irn_n(root, i);
+                       assert(is_curr_reg_class(arg) && "Argument not in same register class.");
+                       if (arg != root) {
+                               if (!nodes_interfere(co->chordal_env, root, arg)) {
+                                       DBG((dbg, LEVEL_1, "\t   Member: %n %N\n", arg, arg));
+                                       if (is_optimizable(co->chordal_env->arch_env, arg))
+                                               co_append_unit(co, arg);
+                                       unit->nodes[unit->node_count++] = arg;
+                               } else
+                                       unit->interf++;
+                       }
                }
-       }
-       unit->nodes = xrealloc(unit->nodes, unit->node_count * sizeof(*unit->nodes));
+               unit->nodes = xrealloc(unit->nodes, unit->node_count * sizeof(*unit->nodes));
+       } else if (is_Copy(co->chordal_env->arch_env, root)) {
+               assert(!nodes_interfere(co->chordal_env, root, get_Copy_src(root)));
+               unit->nodes[unit->node_count++] = get_Copy_src(root);
+               unit->nodes = xrealloc(unit->nodes, 2 * sizeof(*unit->nodes));
+       } else
+               assert(0 && "This is not an optimizable node!");
+
        list_add_tail(&unit->units, &co->units);
        /* Init ifg_mis_size to node_count. So get_lower_bound returns correct results. */
        unit->ifg_mis_size = get_ifg_mis_size(unit);
@@ -147,7 +158,7 @@ static void co_collect_in_block(ir_node *block, void *env) {
        border_t *curr;
 
        list_for_each_entry_reverse(border_t, curr, head, list)
-               if (curr->is_def && curr->is_real && is_optimizable(curr->irn))
+               if (curr->is_def && curr->is_real && is_optimizable(co->chordal_env->arch_env, curr->irn))
                        co_append_unit(co, curr->irn);
 }
 
@@ -174,9 +185,11 @@ copy_opt_t *new_copy_opt(be_chordal_env_t *chordal_env) {
        s3 = chordal_env->cls->name;
        len = strlen(s1) + strlen(s2) + strlen(s3) + 5;
        co->name = xmalloc(len);
-       if (!strcmp(co->name, DEBUG_IRG))
-               firm_dbg_set_mask(dbg, -1);
        snprintf(co->name, len, "%s__%s__%s", s1, s2, s3);
+       if (!strcmp(co->name, DEBUG_IRG))
+               firm_dbg_set_mask(dbg, DEBUG_LVL_CO);
+       else
+               firm_dbg_set_mask(dbg, DEBUG_LVL);
 
        INIT_LIST_HEAD(&co->units);
        co_collect_units(co);
@@ -196,22 +209,24 @@ int is_optimizable_arg(const copy_opt_t *co, ir_node *irn) {
        int i, max;
        for(i=0, max=get_irn_n_outs(irn); i<max; ++i) {
                ir_node *n = get_irn_out(irn, i);
-               if (is_optimizable(n) && (irn == n || !nodes_interfere(co->chordal_env, irn, n)))
+               if ((is_Phi(n) || is_Perm(co->chordal_env->arch_env, n)) && (irn == n || !nodes_interfere(co->chordal_env, irn, n)))
                        return 1;
        }
        return 0;
 }
 
-
 int co_get_copy_count(const copy_opt_t *co) {
        int i, res = 0;
        unit_t *curr;
        list_for_each_entry(unit_t, curr, &co->units, units) {
                int root_col = get_irn_col(co, curr->nodes[0]);
                res += curr->interf;
+               DBG((dbg, LEVEL_1, "%n %N has %d intf\n", curr->nodes[0], curr->nodes[0], curr->interf));
                for (i=1; i<curr->node_count; ++i)
-                       if (root_col != get_irn_col(co, curr->nodes[i]))
+                       if (root_col != get_irn_col(co, curr->nodes[i])) {
+                               DBG((dbg, LEVEL_1, "  %n %N\n", curr->nodes[i], curr->nodes[i]));
                                res++;
+                       }
        }
        return res;
 }
@@ -265,7 +280,7 @@ void co_check_allocation(copy_opt_t *co) {
                for (o = i+1, n2 = nodes[o]; n2; n2 = nodes[++o])
                        if (nodes_interfere(co->chordal_env, n1, n2)
           && get_irn_col(co, n1) == get_irn_col(co, n2)) {
-                               DBG((dbg, 0, "Error: %n %d  and  %n %d have the same color %d.\n", n1, get_irn_graph_nr(n1), n2, get_irn_graph_nr(n2), get_irn_col(co, n1)));
+                               DBG((dbg, 0, "Error in graph %s: %n %d  and  %n %d have the same color %d.\n", co->name, n1, get_irn_graph_nr(n1), n2, get_irn_graph_nr(n2), get_irn_col(co, n1)));
                                assert(0 && "Interfering values have the same color!");
                        }
        }