#ifdef HAVE_ALLOCA_H
#include <alloca.h>
#endif
+#ifdef HAVE_MALLOC_H
+#include <malloc.h>
+#endif
#include "irprog.h"
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;
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);
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);
}
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);
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;
}
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!");
}
}