Added call to eliminate_phi_interferences. Enabled phi-destruction.
[libfirm] / ir / be / becopyoptmain.c
index 463dd95..a648064 100644 (file)
 /**
+ * Author:      Daniel Grund
+ * Date:               11.04.2005
+ * Copyright:   (c) Universitaet Karlsruhe
+ * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
+
  * Main file for the optimization reducing the copies needed for:
  * - phi coalescing
  * - register-constrained nodes
- *
- * Contains a simple checker for this optimization.
- * By request some statistics are collected too.
- *
- * @author Daniel Grund
- * @date 11.04.2005
  */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 
 #include "debug.h"
-#include "list.h"
-#include "obst.h"
-#include "irgraph.h"
-#include "irnode.h"
-#include "irgwalk.h"
-
-#include "bera_t.h"
-#include "becopyoptmain.h"
 #include "becopyopt.h"
 #include "becopystat.h"
+#include "becopyoptmain.h"
 
 #define DO_HEUR
-#define DO_ILP
-#undef DO_STAT
+#undef DO_ILP
 
 #define DEBUG_LVL SET_LEVEL_1
 static firm_dbg_module_t *dbg = NULL;
 
-/**
- * Needed for result checking
- */
-static void allocatable_collector(ir_node *node, void *env) {
-       struct obstack *obst = env;
-       if (!is_Block(node) && is_allocatable_irn(node))
-               obstack_ptr_grow(obst, node);
-}
-
-/**
- * This O(n^2) checker checks, if two ifg-connected nodes have the same color.
- */
-static void check_results(ir_graph *irg) {
-       struct obstack ob;
-       ir_node **nodes, *n1, *n2;
-       int i, o;
-
-       obstack_init(&ob);
-       irg_walk_graph(irg, allocatable_collector, NULL, &ob);
-       obstack_ptr_grow(&ob, NULL);
-       nodes = (ir_node **) obstack_finish(&ob);
-       for (i = 0, n1 = nodes[i]; n1; n1 = nodes[++i]) {
-               assert(! (is_allocatable_irn(n1) && get_irn_color(n1) == NO_COLOR));
-               for (o = i+1, n2 = nodes[o]; n2; n2 = nodes[++o])
-                       if (phi_ops_interfere(n1, n2) && get_irn_color(n1) == get_irn_color(n2)) {
-                               DBG((dbg, 0, "Error: %n in %n  and  %n in %n\n", n1, get_nodes_block(n1), n2, get_nodes_block(n2)));
-                               assert(0 && "Interfering values have the same color!");
-                       }
-       }
-       obstack_free(&ob, NULL);
-}
-
 void be_copy_opt_init(void) {
-       dbg = firm_dbg_register("ir.be.copyopt");
-       firm_dbg_set_mask(dbg, DEBUG_LVL);
+       dbg = firm_dbg_register("ir.be.copyoptmain");
+       firm_dbg_set_mask(dbg, LEVEL_1);
 }
 
-void be_copy_opt(ir_graph* irg) {
+void be_copy_opt(be_chordal_env_t *chordal_env) {
        copy_opt_t *co;
+       int lb, copy_costs;
 
-       check_results(irg);
-       co = new_copy_opt(irg);
+       co = new_copy_opt(chordal_env, get_costs_loop_depth);
+       DBG((dbg, LEVEL_1, "===>  %s  <===\n", co->name));
 
 #ifdef DO_STAT
-       irg_stat_t *stats = new_irg_stat(co);
-       irg_stat_count(stats, co, 0);
+       copy_costs = co_get_copy_costs(co);
+       curr_vals[I_COPIES_INIT] += copy_costs;
+       DBG((dbg, LEVEL_1, "Init costs: %3d\n", copy_costs));
 #endif
 
 #ifdef DO_HEUR
        co_heur_opt(co);
-       check_results(irg);
+       be_ra_chordal_check(chordal_env);
 #ifdef DO_STAT
-       irg_stat_count(stats, co, 1);
+       copy_costs = co_get_copy_costs(co);
+       curr_vals[I_COPIES_HEUR] += copy_costs;
+       DBG((dbg, LEVEL_1, "Heur costs: %3d\n", copy_costs));
 #endif
 #endif
 
 #ifdef DO_ILP
-       co_ilp_opt(co);
-       check_results(irg);
-#ifdef DO_STAT
-       irg_stat_count(stats, co, 2);
-#endif
-#endif
+       lb = co_get_lower_bound(co);
+       copy_costs = co_get_copy_costs(co);
+       assert(copy_costs>=lb && "At least one computation of these two is boooogy");
+
+       if (copy_costs > lb) {
+               co_ilp_opt(co);
+               be_ra_chordal_check(chordal_env);
+       }
 
 #ifdef DO_STAT
-       irg_stat_print(stats);
-       all_stat_dump();
+       copy_costs = co_get_copy_costs(co);
+       curr_vals[I_COPIES_OPT] += copy_costs;
+       DBG((dbg, LEVEL_1, "Opt  costs: %3d\n", copy_costs));
+       assert(copy_costs>=lb && "At least one computation of these two is boooogy");
+#endif
 #endif
 
        free_copy_opt(co);
 }
-
-void be_copy_opt_done(ir_graph* irg) {
-}