Bugfixes, small improvements and movements.
authorDaniel Grund <grund@cs.uni-saarland.de>
Fri, 22 Apr 2005 15:18:25 +0000 (15:18 +0000)
committerDaniel Grund <grund@cs.uni-saarland.de>
Fri, 22 Apr 2005 15:18:25 +0000 (15:18 +0000)
13 files changed:
ir/be/Makefile.in
ir/be/bearch_obj.def
ir/be/becopyheur.c
ir/be/becopyilp.c
ir/be/becopyopt.c
ir/be/becopyopt.h
ir/be/becopyoptmain.c
ir/be/becopyoptmain.h
ir/be/becopystat.c
ir/be/becopystat.h
ir/be/bemain.c
ir/be/phistat.c [deleted file]
ir/be/phistat.h [deleted file]

index 9e2807f..59a5f5d 100644 (file)
@@ -21,7 +21,7 @@ SOURCES = $(INSTALL_HEADERS)
 
 SOURCES +=     Makefile.in besched.h belistsched.h belistsched.c \
        beutil.h bemain.c besched.c bemain.c belive.c belive.h benumb.h \
-       benumb_t.h benumb.c bechordal.c bera.c beutil.c phistat.c \
+       benumb_t.h benumb.c bechordal.c bera.c beutil.c \
        bera.h bechordalspill.c beasm_dump_globals.c beasm_asm_gnu.c \
        sp_matrix.c becopyoptmain.c becopyopt.c becopyheur.c \
        becopyilp.c becopystat.c bearch_firm.c
index 6b55d9a..aa6ce8a 100644 (file)
@@ -18,3 +18,4 @@ ARCH_OBJ(operand,                                     0)
 ARCH_OBJ(insn_format,                  1)
 ARCH_OBJ(insn,                                         0)
 ARCH_OBJ(isa,                                                  0)
+ARCH_OBJ(isa_if,                               0)
index a7c6d59..f69bb09 100644 (file)
@@ -10,8 +10,9 @@
  */
 
 #include "becopyopt.h"
+#include "becopystat.h"
 
-#define DEBUG_LVL 0 //SET_LEVEL_1
+#define DEBUG_LVL SET_LEVEL_1
 static firm_dbg_module_t *dbg = NULL;
 
 #define SLOTS_PINNED_GLOBAL 256
@@ -31,7 +32,7 @@ typedef struct _conflict_t {
 
 /**
  * If an irn is changed, the changes first get stored in a node_stat_t,
- * to allow undo of changes  (=drop new data) in case of conflicts.
+ * to allow undo of changes (=drop new data) in case of conflicts.
  */
 typedef struct _node_stat_t {
        const ir_node *irn;
@@ -527,9 +528,9 @@ void co_heur_opt(copy_opt_t *co) {
        firm_dbg_set_mask(dbg, DEBUG_LVL);
 
        pinned_global = pset_new_ptr(SLOTS_PINNED_GLOBAL);
-
        list_for_each_entry(unit_t, curr, &co->units, units)
-               ou_optimize(curr);
+               if (curr->node_count > 1)
+                       ou_optimize(curr);
 
        del_pset(pinned_global);
 }
index 7d6b1ec..84560cf 100644 (file)
@@ -14,6 +14,7 @@
  */
 
 #include "becopyopt.h"
+#include "becopystat.h"
 
 #define DUMP_MPS                       /**< dumps the problem in "CPLEX"-MPS format. NOT fixed-column-MPS. */
 #undef USE_SOS                         /**< uses Special Ordered Sets when using MPS */
 #define DELETE_FILES           /**< deletes all dumped files after use */
 
 /* CPLEX-account related stuff */
-#define SSH_USER_HOST_PATH "kb61@sp-smp.rz.uni-karlsruhe.de"
+#define SSH_USER_HOST "kb61@sp-smp.rz.uni-karlsruhe.de"
 #define SSH_PASSWD "!cplex90"
 #define EXPECT_FILENAME "runme" /** name of the expect-script */
 
-#define DEBUG_LVL 0 //SET_LEVEL_1
+#define DEBUG_LVL SET_LEVEL_1
 static firm_dbg_module_t *dbg = NULL;
 
 #define SLOTS_NUM2POS 256
@@ -369,20 +370,17 @@ static void pi_solve_ilp(problem_instance_t *pi) {
        /* write expect-file for copying problem to RZ */
        out = ffopen(EXPECT_FILENAME, "exp", "wt");
        fprintf(out, "#! /usr/bin/expect\n");
-       fprintf(out, "spawn scp %s.mps %s.mst %s.cmd %s:\n", pi->name, pi->name, pi->name, SSH_USER_HOST_PATH);
-       fprintf(out, "expect \":\"\n");
-       fprintf(out, "send \"%s\\n\"\n", SSH_PASSWD);
-       fprintf(out, "interact\n");
-
-       fprintf(out, "spawn ssh %s \"./cplex90 < %s.cmd\"\n", SSH_USER_HOST_PATH, pi->name);
-       fprintf(out, "expect \":\"\n");
-       fprintf(out, "send \"%s\\n\"\n", SSH_PASSWD);
-       fprintf(out, "interact\n");
-
-       fprintf(out, "spawn scp %s:%s.sol .\n", SSH_USER_HOST_PATH, pi->name);
-       fprintf(out, "expect \":\"\n");
-       fprintf(out, "send \"%s\\n\"\n", SSH_PASSWD);
-       fprintf(out, "interact\n");
+       fprintf(out, "spawn scp %s.mps %s.mst %s.cmd %s:\n", pi->name, pi->name, pi->name, SSH_USER_HOST); /* copy problem files */
+       fprintf(out, "expect \":\"\nsend \"%s\\n\"\ninteract\n", SSH_PASSWD);
+
+       fprintf(out, "spawn ssh %s \"./cplex90 < %s.cmd\"\n", SSH_USER_HOST, pi->name); /* solve */
+       fprintf(out, "expect \":\"\nsend \"%s\\n\"\ninteract\n", SSH_PASSWD);
+
+       fprintf(out, "spawn scp %s:%s.sol .\n", SSH_USER_HOST, pi->name); /*copy back solution */
+       fprintf(out, "expect \":\"\nsend \"%s\\n\"\ninteract\n", SSH_PASSWD);
+
+       fprintf(out, "spawn ssh %s ./dell\n", SSH_USER_HOST); /* clean files on server */
+       fprintf(out, "expect \":\"\nsend \"%s\\n\"\ninteract\n", SSH_PASSWD);
        fclose(out);
 
        /* call the expect script */
@@ -473,10 +471,10 @@ static void pi_collect_x_names(ir_node *block, void *env) {
 /**
  * Checks if all nodes in living are live_out in block block.
  */
-static INLINE int all_live_out(ir_node *block, pset *living) {
+static INLINE int all_live_in(ir_node *block, pset *living) {
        ir_node *n;
        for (n = pset_first(living); n; n = pset_next(living))
-               if (!is_live_out(block, n)) {
+               if (!is_live_in(block, n)) {
                        pset_break(living);
                        return 0;
                }
@@ -510,8 +508,8 @@ static void pi_clique_finder(ir_node *block, void *env) {
 
                        /* before shrinking the set, store the current 'maximum' clique;
                         * do NOT if clique is a single node
-                        * do NOT if all values are live_out */
-                       if (phase == growing && pset_count(living) >= 2 && !all_live_out(block, living)) {
+                        * do NOT if all values are live_in (in this case they were contained in a live-out clique elsewhere) */
+                       if (phase == growing && pset_count(living) >= 2 && !all_live_in(block, living)) {
                                ir_node *n;
                                for (n = pset_first(living); n; n = pset_next(living)) {
                                        int pos = pi_get_pos(pi, get_irn_graph_nr(n), pi->curr_color);
index 85a3334..f44fe42 100644 (file)
@@ -4,12 +4,14 @@
  */
 
 #include "becopyopt.h"
+#include "becopystat.h"
 
-#define DEBUG_LVL 0 //SET_LEVEL_1
+#define DEBUG_LVL SET_LEVEL_1
 static firm_dbg_module_t *dbg = NULL;
 
 //TODO external things
-#define is_optimizable(irn) (is_Phi(irn) || 0)
+#define is_curr_reg_class(irn) (co->isa->get_irn_reg_class(irn)==co->cls)
+#define is_optimizable(irn) (is_Phi(irn) || is_Copy(irn))
 
 /**
  * Builds an optimization unit for a given optimizable irn (root).
@@ -27,9 +29,11 @@ static void co_append_unit(copy_opt_t *co, const ir_node *root) {
                return;
        pset_insert_ptr(co->roots, root);
 
+       assert(is_curr_reg_class(root) && "node is in wrong register class!");
+
        /* init unit */
        arity = get_irn_arity(root);
-       unit = malloc(sizeof(*unit));
+       unit = calloc(1, sizeof(*unit));
        unit->interf = 0;
        unit->node_count = 1;
        unit->nodes = malloc((arity+1) * sizeof(*unit->nodes));
@@ -39,6 +43,7 @@ static void co_append_unit(copy_opt_t *co, const ir_node *root) {
        /* 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 (!values_interfere(root, arg)) {
                                DBG((dbg, LEVEL_1, "\t  Member: %n\n", arg));
@@ -50,13 +55,8 @@ static void co_append_unit(copy_opt_t *co, const ir_node *root) {
                }
        }
 
-       if (unit->node_count > 1) {
-               unit->nodes = realloc(unit->nodes, unit->node_count * sizeof(*unit->nodes));
-               list_add_tail(&unit->units, &co->units);
-       } else {
-               free(unit->nodes);
-               free(unit);
-       }
+       unit->nodes = realloc(unit->nodes, unit->node_count * sizeof(*unit->nodes));
+       list_add_tail(&unit->units, &co->units);
 }
 
 static void co_collect_in_block(ir_node *block, void *env) {
@@ -76,12 +76,14 @@ static void co_collect_units(copy_opt_t *co) {
        del_pset(co->roots);
 }
 
-copy_opt_t *new_copy_opt(ir_graph *irg) {
+copy_opt_t *new_copy_opt(ir_graph *irg, const arch_isa_if_t *isa, const arch_register_class_t *cls) {
        dbg = firm_dbg_register("ir.be.copyopt");
        firm_dbg_set_mask(dbg, DEBUG_LVL);
 
        copy_opt_t *co = calloc(1, sizeof(*co));
        co->irg = irg;
+       co->isa = isa;
+       co->cls = cls;
        INIT_LIST_HEAD(&co->units);
        co_collect_units(co);
        return co;
@@ -95,8 +97,20 @@ void free_copy_opt(copy_opt_t *co) {
        }
 }
 
+int co_get_copy_count(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_color(curr->nodes[0]);
+               res += curr->interf;
+               for (i=1; i<curr->node_count; ++i)
+                       if (root_col != get_irn_color(curr->nodes[i]))
+                               res++;
+       }
+       return res;
+}
+
 int co_get_lower_bound(copy_opt_t *co) {
-       //TODO Think if copy counting is this easy!
        int res = 0;
        unit_t *curr;
        list_for_each_entry(unit_t, curr, &co->units, units)
@@ -111,3 +125,40 @@ int co_get_interferer_count(copy_opt_t *co) {
                res += curr->interf;
        return res;
 }
+
+/**
+ * Needed for result checking
+ */
+static void co_collect_for_checker(ir_node *block, void *env) {
+       copy_opt_t *co = env;
+       struct list_head *head = &get_ra_block_info(block)->border_head;
+       border_t *curr;
+
+       list_for_each_entry_reverse(border_t, curr, head, list)
+               if (curr->is_def && curr->is_real && is_curr_reg_class(curr->irn))
+                       obstack_ptr_grow(&co->ob, curr->irn);
+}
+
+/**
+ * This O(n^2) checker checks, if two ifg-connected nodes have the same color.
+ */
+void co_check_allocation(copy_opt_t *co) {
+       ir_node **nodes, *n1, *n2;
+       int i, o;
+
+       obstack_init(&co->ob);
+       dom_tree_walk_irg(co->irg, co_collect_for_checker, NULL, co);
+       obstack_ptr_grow(&co->ob, NULL);
+
+       nodes = (ir_node **) obstack_finish(&co->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 have the same color.\n", n1, get_nodes_block(n1), n2, get_nodes_block(n2)));
+                               assert(0 && "Interfering values have the same color!");
+                       }
+       }
+       obstack_free(&co->ob, NULL);
+       DBG((dbg, 2, "The checker seems to be happy!\n"));
+}
index 509c28f..3cdc106 100644 (file)
@@ -36,6 +36,7 @@
 #include "belive_t.h"
 #include "bera_t.h"
 #include "bechordal_t.h"
+#include "bearch.h"
 
 /**
  * TODO external things
@@ -44,6 +45,7 @@
  */
 #define get_weight(n,m) 1
 #define is_possible_color(irn, col) 1
+#define is_Copy(irn) 0
 #define MAX_COLORS 32
 
 /**
@@ -64,16 +66,19 @@ typedef struct _unit_t {
  * Data representing the problem of copy minimization.
  */
 typedef struct _copy_opt_t {
-       ir_graph *irg;                          /**< the irg which is processed */
-       struct list_head units;         /**< all units to optimize in right oreder */
-       pset *roots;                            /**< used only temporary for detecting multiple appends */
+       ir_graph *irg;                                          /**< the irg to process */
+       const arch_isa_if_t *isa;
+       const arch_register_class_t *cls;       /**< the registerclass to optimize */
+       struct list_head units;                         /**< all units to optimize in right oreder */
+       pset *roots;                                            /**< used only temporary for detecting multiple appends */
+       struct obstack ob;
 } copy_opt_t;
 
 
 /**
  * Generate the problem. Collect all infos and optimizable nodes.
  */
-copy_opt_t *new_copy_opt(ir_graph *irg);
+copy_opt_t *new_copy_opt(ir_graph *irg, const arch_isa_if_t *isa, const arch_register_class_t *cls);
 
 /**
  * Free the space...
@@ -81,6 +86,12 @@ copy_opt_t *new_copy_opt(ir_graph *irg);
 void free_copy_opt(copy_opt_t *co);
 
 /**
+ * Returns the current number of copies needed
+ */
+int co_get_copy_count(copy_opt_t *co);
+
+/**
+ * IMPORTANT: Available only iff heuristic has run!
  * Returns a lower bound for the number of copies needed based on interfering
  * arguments and the size of a max indep. set (only ifg-edges) of the other args.
  */
@@ -102,4 +113,9 @@ void co_heur_opt(copy_opt_t *co);
  */
 void co_ilp_opt(copy_opt_t *co);
 
+/**
+ * Checks the register allocation for correctness
+ */
+void co_check_allocation(copy_opt_t *co);
+
 #endif
index 0ec5e24..bea9ec3 100644 (file)
  * - 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
  */
 
-#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
 
 #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);
-       DBG((dbg, 1, "The checker seems to be happy!\n"));
-}
-
 void be_copy_opt_init(void) {
        dbg = firm_dbg_register("ir.be.copyopt");
        firm_dbg_set_mask(dbg, DEBUG_LVL);
 }
 
-void be_copy_opt(ir_graph* irg) {
+void be_copy_opt(ir_graph* irg, const arch_isa_if_t *isa, const arch_register_class_t *cls) {
        copy_opt_t *co;
+       int lb, copies;
 
        DBG((dbg, LEVEL_1, "\nIRG: %s\n\n", get_entity_name(get_irg_entity(irg))));
-       check_results(irg);
-       co = new_copy_opt(irg);
+       co = new_copy_opt(irg, isa, cls);
+       co_check_allocation(co);
 
 #ifdef DO_STAT
-       irg_stat_t *stats = new_irg_stat(co);
-       irg_stat_count(stats, co, 0);
+       copies = co_get_copy_count(co);
+       curr_vals[I_COPIES_INIT] += copies;
+       DBG((dbg, 1, "Init copies: %3d\n", copies));
 #endif
 
 #ifdef DO_HEUR
        co_heur_opt(co);
-       check_results(irg);
+       co_check_allocation(co);
 #ifdef DO_STAT
-       irg_stat_count(stats, co, 1);
+       copies = co_get_copy_count(co);
+       curr_vals[I_COPIES_HEUR] += copies;
+       DBG((dbg, 1, "Heur copies: %3d\n", copies));
 #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);
+       copies = co_get_copy_count(co);
+//TODO remove checks and enable lb
+       assert(copies>=lb && "At least one computation of these two is boooogy");
+//     if (copies > lb) {
+               co_ilp_opt(co);
+               co_check_allocation(co);
+//     }
+       copies = co_get_copy_count(co);
+       assert(copies>=lb && "At least one computation of these two is boooogy");
 
 #ifdef DO_STAT
-       irg_stat_print(stats);
-       all_stat_dump();
+       copies = co_get_copy_count(co);
+       curr_vals[I_COPIES_HEUR] += copies;
+       DBG((dbg, 1, "Opt  copies: %3d\n", copies));
+#endif
 #endif
 
        free_copy_opt(co);
 }
-
-void be_copy_opt_done(ir_graph* irg) {
-}
index 671379d..c9f4962 100644 (file)
@@ -16,7 +16,6 @@
 #include "irgraph.h"
 
 void be_copy_opt_init(void);
-void be_copy_opt(ir_graph* irg);
-void be_copy_opt_done(ir_graph* irg);
+void be_copy_opt(ir_graph* irg, const arch_isa_if_t *isa, const arch_register_class_t *cls);
 
 #endif
index 7721164..1958f3d 100644 (file)
  * @author Daniel Grund
  * @date 19.04.2005
  */
-#include <stdlib.h>
-#include "list.h"
+#include <string.h>
+#include "phiclass_t.h"
 #include "irprog.h"
-#include "beutil.h"
+#include "becopyopt.h"
 #include "becopystat.h"
 
-struct _irg_stat_t {
-       struct list_head chain;
-       ir_graph *irg;
-       const char *irg_name;
-       int interferers, lb, max;
-       int copies[3];
-       //TODO double ilp_time;
-};
-
-typedef struct _all_stat_t {
-       const char *unit_name;
-       struct list_head irgs;
-} all_stat_t;
-
-static all_stat_t *all_stats = NULL;
-
-#define irg_list_entry(lh) list_entry(lh, irg_stat_t, chain)
-
-irg_stat_t *new_irg_stat(copy_opt_t *co) {
-       irg_stat_t *is, *curr;
-
-       if (!all_stats) {
-               all_stats = calloc(1, sizeof(*all_stats));
-               all_stats->unit_name = get_irp_prog_name();
-               INIT_LIST_HEAD(&all_stats->irgs);
-               is = calloc(1, sizeof(*is));
-               is->irg_name = "CUMULATIVE";
-               list_add_tail(&is->chain, &all_stats->irgs);
-       }
+#ifdef DO_STAT
+
+static pset *all_phi_nodes;
+static pset *all_phi_classes;
+static pset *all_copy_nodes;
+
+void stat_init(void) {
+       all_phi_nodes = pset_new_ptr_default();
+       all_phi_classes = pset_new_ptr_default();
+       all_copy_nodes = pset_new_ptr_default();
+       phi_class_init();
+}
+
+void stat_reset(void) {
+       int i;
+       for (i = 0; i < ASIZE; ++i)
+               curr_vals[i] = 0;
+}
+
+/**
+ * Collect general data
+ */
+static void stat_walker(ir_node *node, void *env) {
+       curr_vals[I_ALL_NODES]++; /* count all nodes */
+
+       if (is_Block(node)) /* count all blocks */
+               curr_vals[I_BLOCKS]++;
+
+       if (is_Phi(node)) /* collect phis */
+               pset_insert_ptr(all_phi_nodes, node);
 
-       /* look if we had this irg already */
-       list_for_each_entry(irg_stat_t, curr, &all_stats->irgs, chain)
-               if (curr->irg == co->irg)
-                       return curr;
-
-       /* else create a new entry */
-       is = calloc(1, sizeof(*is));
-       is->irg = co->irg;
-       is->irg_name = get_entity_name(get_irg_entity(co->irg));
-       list_add_tail(&is->chain, &all_stats->irgs);
-       return is;
+       if (is_Copy(node))
+               pset_insert_ptr(all_copy_nodes, node);
 }
 
-void irg_stat_count(irg_stat_t *is, copy_opt_t *co, int phase) {
-       unit_t *curr;
-       int max = 0, copies = 0;
-
-       list_for_each_entry(unit_t, curr, &co->units, units) {
-               int i;
-               max += curr->interf + curr->node_count - 1;
-               const ir_node *root = curr->nodes[0];
-               int root_color = get_irn_color(root);
-               copies += curr->interf;
-               for (i=1; i<curr->node_count; ++i) {
-                       const ir_node *arg = curr->nodes[i];
-                       if (root_color != get_irn_color(arg))
-                               copies++;
+/**
+ * Collect phi node data
+ */
+static void stat_phi_node(ir_node *phi) {
+       int arity, i;
+
+       /* count all phi phis */
+       curr_vals[I_PHI_CNT]++;
+
+       /* argument count */
+       arity = get_irn_arity(phi);
+       curr_vals[I_PHI_ARG_CNT] += arity;
+       if (arity > MAX_ARITY)
+               curr_vals[I_PHI_ARITY_E]++;
+       else
+               curr_vals[I_PHI_ARITY_S + arity]++;
+
+       /* type of argument {self, const, pred, glob} */
+       for (i = 0; i < arity; i++) {
+        ir_node *block_of_arg, *block_ith_pred;
+               ir_node *arg = get_irn_n(phi, i);
+
+               if (arg == phi) {
+                       curr_vals[I_PHI_ARG_SELF]++;
+                       continue;
                }
-       }
 
-       is->copies[phase] += copies;
-       if (phase == 0)
-               is->max += max;
-       if (phase == 1) {
-               is->interferers += co_get_interferer_count(co);
-               is->lb += co_get_lower_bound(co);
+               curr_vals[I_COPIES_MAX]++; /* if arg!=phi this is a possible copy */
+
+               if (values_interfere(phi, arg))
+                       curr_vals[I_COPIES_IF]++;
+
+               if (iro_Const == get_irn_opcode(arg)) {
+                       curr_vals[I_PHI_ARG_CONST]++;
+                       continue;
+               }
+
+               block_of_arg = get_nodes_block(arg);
+               block_ith_pred = get_nodes_block(get_irn_n(get_nodes_block(phi), i));
+               if (block_of_arg == block_ith_pred) {
+                       curr_vals[I_PHI_ARG_PRED]++;
+                       continue;
+               }
+
+               curr_vals[I_PHI_ARG_GLOB]++;
        }
 }
 
-void irg_stat_print(irg_stat_t *is) {
-       printf("Irg %s: %3d %3d %3d %3d %3d %3d", is->irg_name, is->interferers, is->lb, is->copies[0], is->copies[1], is->copies[2], is->max);
+/**
+ * Collect register-constrained node data
+ */
+//TODO stat_copy_node
+static void stat_copy_node(ir_node *root) {
+//     if (values_interfere(root, arg))
+//             curr_vals[I_COPIES_IF]++;
+}
+
+/**
+ * Collect phi class data
+ */
+static void stat_phi_class(pset *pc) {
+       int i, o, size, if_free;
+       ir_node **members, *p;
+
+       /* phi class count */
+       curr_vals[I_CLS_CNT]++;
+
+       /* phi class size */
+       size = pset_count(pc);
+       if (size > MAX_CLS_SIZE)
+               curr_vals[I_CLS_SIZE_E]++;
+       else
+               curr_vals[I_CLS_SIZE_S + size]++;
+
+       /* get an array of all members for double iterating */
+       members = malloc(size * sizeof(*members));
+       for (i = 0, p = pset_first(pc); p; p = pset_next(pc))
+               members[i++] = p;
+       assert(i == size);
+
+       /* determine interference of phi class members */
+       curr_vals[I_CLS_IF_MAX] += size*(size-1)/2;
+       if_free = 1;
+       for (i = 0; i < size-1; ++i)
+               for (o = i+1; o < size; ++o)
+                       if (values_interfere(members[i], members[o])) {
+                               if_free = 0;
+                               curr_vals[I_CLS_IF_CNT]++;
+                       }
+
+       /* Does this phi class have an inner interference? */
+       curr_vals[I_CLS_IF_FREE] += if_free;
+
+       free(members);
 }
 
-void all_stat_dump(void) {
-       FILE *out;
-       irg_stat_t *cuml, *curr;
-       /* Compute cumulative values */
-       cuml = irg_list_entry(all_stats->irgs.next);
-       cuml->interferers = 0;
-       cuml->lb = 0;
-       cuml->max = 0;
-       cuml->copies[0] = 0;
-       cuml->copies[1] = 0;
-       cuml->copies[2] = 0;
-       list_for_each_entry(irg_stat_t, curr, &all_stats->irgs, chain) {
-               int i = 0;
-               cuml->interferers += curr->interferers;
-               cuml->lb += curr->lb;
-               cuml->max += curr->max;
-               for (i=0; i<3; ++i)
-                       cuml->copies[i] += curr->copies[i];
+void stat_collect_irg(ir_graph *irg) {
+       ir_node *n;
+       pset *pc;
+
+       irg_walk_graph(irg, stat_walker, NULL, NULL);
+       curr_vals[I_BLOCKS] -= 2; /* substract 2 for start and end block */
+
+       all_phi_classes = phi_class_compute_by_phis(all_phi_nodes);
+
+       for (n = pset_first(all_phi_nodes); n; n = pset_next(all_phi_nodes))
+               stat_phi_node(n);
+
+       for (n = pset_first(all_copy_nodes); n; n = pset_next(all_copy_nodes))
+               stat_copy_node(n);
+
+       for (pc = pset_first(all_phi_classes); pc; pc = pset_next(all_phi_classes))
+               stat_phi_class(pc);
+
+}
+
+void stat_dump(ir_graph *irg) {
+       int i;
+       FILE *out = ffopen(get_entity_name(get_irg_entity(irg)), "stat", "wt");
+
+       fprintf(out, "%s\n", get_irp_prog_name());
+       for (i = 0; i < ASIZE; i++) {
+               if (i >= I_PHI_ARITY_S && i <= I_PHI_ARITY_E)
+                       fprintf(out, "%i %i\n", curr_vals[i], curr_vals[I_PHI_CNT]);
+               else if (i >= I_CLS_SIZE_S && i <= I_CLS_SIZE_E)
+                       fprintf(out, "%i %i\n", curr_vals[i], curr_vals[I_CLS_CNT]);
+               else
+                       fprintf(out, "%i\n", curr_vals[i]);
        }
 
-       /* dump to file */
-       out = ffopen(all_stats->unit_name, "stats", "wt");
-       list_for_each_entry(irg_stat_t, curr, &all_stats->irgs, chain)
-               fprintf(out, "%15s  %3d %3d %3d %3d %3d %3d", curr->irg_name, curr->interferers, curr->lb, curr->copies[0], curr->copies[1], curr->copies[2], curr->max);
+    fclose(out);
+}
+
+//TODO stat_dump_pretty
+void stat_dump_pretty(ir_graph *irg) {
+       int i;
+       FILE *out = ffopen(get_entity_name(get_irg_entity(irg)), "pretty", "wt");
+
+       fprintf(out, "\nPhi argument types\n");
+       fprintf(out, "Total     %4d\n", curr_vals[I_PHI_ARG_CNT]);
+       fprintf(out, "Constants %4d\n", curr_vals[I_PHI_ARG_CONST]);
+       fprintf(out, "CF-Pred   %4d\n", curr_vals[I_PHI_ARG_PRED]);
+       fprintf(out, "Others    %4d\n", curr_vals[I_PHI_ARG_GLOB]);
+
+       fprintf(out, "\nPhi class interference\n");
+       fprintf(out, "Blocks         %4d\n", curr_vals[I_BLOCKS]);
+       fprintf(out, "Phis           %4d\n", curr_vals[I_PHI_CNT]);
+
+       fprintf(out, "\nPhi arity\n");
+       for (i = I_PHI_ARITY_S; i<=I_PHI_ARITY_E; i++)
+               fprintf(out, "%2i %4d\n", i-I_PHI_ARITY_S, curr_vals[i]);
+
+       fprintf(out, "\nPhi class sizes\n");
+       for (i = I_CLS_SIZE_S; i<=I_CLS_SIZE_E; i++)
+               fprintf(out, "%2i %4d\n", i-I_CLS_SIZE_S, curr_vals[i]);
+
+       fprintf(out, "\n\nTotal nodes:    %4d\n", curr_vals[I_ALL_NODES]);
+
        fclose(out);
 }
+
+#endif
index 15fde49..517f428 100644 (file)
@@ -2,18 +2,77 @@
  * @author Daniel Grund
  * @date 11.04.2005
  */
+#define DO_STAT
+
+#ifdef DO_STAT
 
-//TODO
 #ifndef _BECOPYSTAT_H
 #define _BECOPYSTAT_H
 
-#include "becopyopt.h"
+#include "irgraph.h"
+
+#define MAX_ARITY 10
+#define MAX_CLS_SIZE 10
+#define MAX_PHASE 2
+/**
+ * For an explanation of these values see phi_stat_dump_pretty
+ */
+enum vals_t {
+       I_ALL_NODES = 0,
+       I_BLOCKS,
+
+       I_PHI_CNT,                      /* number of phi nodes */
+       I_PHI_ARG_CNT,          /* number of arguments of phis */
+       I_PHI_ARG_SELF,         /* number of arguments of phis being the phi itself */
+       I_PHI_ARG_CONST,        /* number of arguments of phis being consts */
+       I_PHI_ARG_PRED,         /* ... being defined in a cf-pred */
+       I_PHI_ARG_GLOB,         /* ... being defined elsewhere */
+       I_PHI_ARITY_S,
+       I_PHI_ARITY_E    = I_PHI_ARITY_S+MAX_ARITY,
+
+       I_CLS_CNT,                      /* number of phi classes */
+       I_CLS_IF_FREE,          /* number of pc having no interference */
+       I_CLS_IF_MAX,           /* number of possible interferences in all classes */
+       I_CLS_IF_CNT,           /* number of actual interferences in all classes */
+       I_CLS_SIZE_S,
+       I_CLS_SIZE_E = I_CLS_SIZE_S+MAX_CLS_SIZE,
 
-typedef struct _irg_stat_t irg_stat_t;
+       I_COPIES_MAX,           /* max number of copies possible */
+       I_COPIES_INIT,          /* !external set! number of copies in initial allocation */
+       I_COPIES_HEUR,          /* !external set! number of copies after heuristic */
+       I_COPIES_OPT,           /* !external set! number of copies after ilp */
+       I_COPIES_LB,            /* !external set! the lower bound used for number of copies */
+       I_COPIES_IF,            /* number of copies inevitable due to root-arg-interf */
 
-irg_stat_t *new_irg_stat(copy_opt_t *co);
-void irg_stat_count(irg_stat_t *is, copy_opt_t *co, int phase);
-void irg_stat_print(irg_stat_t *is);
-void all_stat_dump(void);
+       ASIZE
+};
 
+/**
+ * Holds current values. Values are added till next phi_stat_reset
+ */
+int curr_vals[ASIZE];
+
+void stat_init(void);
+
+/**
+ * Resets the array holding the data
+ */
+void stat_reset(void);
+
+/**
+ * Collect common irg data
+ */
+void stat_collect_irg(ir_graph *irg);
+
+/**
+ * Dumps the current contents of the internal values to a file.
+ */
+void stat_dump(ir_graph *irg);
+
+/**
+ * Dumps the current contents of the values array and annotations to a file.
+ */
+void stat_dump_pretty(ir_graph *irg);
+
+#endif
 #endif
index 08a4576..f9eccf3 100644 (file)
@@ -15,6 +15,7 @@
 #include "irprog.h"
 #include "irgraph.h"
 #include "irdump.h"
+#include "phiclass.h"
 
 #include "be_t.h"
 #include "bera_t.h"
 #include "bechordal.h"
 #include "bearch.h"
 #include "becopyoptmain.h"
+#include "becopystat.h"
 
 #include "beasm_dump_globals.h"
 #include "beasm_asm_gnu.h"
 
 #undef DUMP_ALLOCATED
-#undef DUMP_LOCALIZED
+#define DUMP_LOCALIZED
 
 #define N_PHASES 256
 
@@ -102,6 +104,9 @@ void be_init(void)
        be_numbering_init();
        be_ra_init();
        be_ra_chordal_init();
+#ifdef DO_STAT
+       stat_init();
+#endif
        be_copy_opt_init();
 }
 
@@ -111,11 +116,10 @@ extern arch_isa_if_t arch_isa_if_firm;
 static void be_main_loop(void)
 {
        int i, n;
-  const arch_isa_if_t *isa = &arch_isa_if_firm;
+       const arch_isa_if_t *isa = &arch_isa_if_firm;
 
        for(i = 0, n = get_irp_n_irgs(); i < n; ++i) {
-    int j, m;
-
+               int j, m;
                ir_graph *irg = get_irp_irg(i);
 
                localize_consts(irg);
@@ -125,36 +129,39 @@ static void be_main_loop(void)
 #endif
                be_numbering(irg);
 
-    /* Schedule the graphs. */
+               /* Schedule the graphs. */
                list_sched(irg, trivial_selector);
 
-    /* Liveness analysis */
-    be_liveness(irg);
+               /* Liveness analysis */
+               be_liveness(irg);
 
-    /*
-     * Perform the following for each register
-     * class.
-     */
-    for(j = 0, m = isa->get_n_reg_class(); j < m; ++j) {
-      const arch_register_class_t *cls = isa->get_reg_class(j);
+#ifdef DO_STAT
+               stat_reset();
+               stat_collect_irg(irg);
+#endif
+               /* Perform the following for each register class. */
+               for(j = 0, m = isa->get_n_reg_class(); j < m; ++j) {
+                       const arch_register_class_t *cls = isa->get_reg_class(j);
 
-      be_ra_chordal(irg, isa, cls);
+                       be_ra_chordal(irg, isa, cls);
 
 #ifdef DUMP_ALLOCATED
-      dump_allocated_irg(irg, "");
+                       dump_allocated_irg(irg, "");
 #endif
-      // be_copy_opt(irg);
-      be_ra_chordal_done(irg);
-    }
-
-    be_numbering_done(irg);
+                       be_copy_opt(irg, isa, cls);
+                       be_ra_chordal_done(irg);
+               }
+#ifdef DO_STAT
+               stat_dump(irg);
+#endif
+           be_numbering_done(irg);
        }
 }
 
 void be_main(int argc, const char *argv[])
 {
-  assembler_t *gnu_assembler;
-  FILE *asm_output_file;
+       assembler_t *gnu_assembler;
+       FILE *asm_output_file;
 
        be_main_loop();
        gnu_assembler = gnuasm_create_assembler();
diff --git a/ir/be/phistat.c b/ir/be/phistat.c
deleted file mode 100644 (file)
index 4cb3f6d..0000000
+++ /dev/null
@@ -1,288 +0,0 @@
-/**
- * @author Daniel Grund
- * @date 09.12.2004
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include "config.h"
-
-#include "irgraph.h"
-#include "irnode.h"
-#include "irgwalk.h"
-#include "irop.h"
-#include "irprog.h"
-#include "irmode_t.h"
-
-#include "bera.h"
-#include "phistat.h"
-
-#define MAX_ARITY 10
-#define MAX_CLS_SIZE 10
-
-/**
- * For an explanation of these values see phi_stat_dump_pretty
- */
-enum vals_t {
-       I_ARG         = 0,
-       I_CONST,
-       I_PRED,
-       I_GLOB,
-
-       I_SPACE1,
-       I_BLOCKS,
-       I_PHIS,
-       I_PHICLS,
-       I_PHICLSI,
-       I_PAIRS,
-       I_PAIRSI,
-       I_VALUES,
-       I_VALUESI,
-
-       I_SPACE2,
-       I_ARITY_S,
-       I_ARITY_E    = I_ARITY_S+MAX_ARITY,
-
-       I_SPACE3,
-       I_CLS_SIZE_S,
-       I_CLS_SIZE_E = I_CLS_SIZE_S+MAX_CLS_SIZE,
-       I_ALL_NODES,
-       ASIZE
-};
-
-/**
- * Holds current values. Values are added till next
- * phi_stat_reset
- */
-static int curr_vals[ASIZE];
-
-
-void phi_stat_reset(void) {
-       int i;
-
-       for (i = 0; i < ASIZE; ++i)
-               curr_vals[i] = 0;
-       curr_vals[I_SPACE1] = -1;
-       curr_vals[I_SPACE2] = -1;
-       curr_vals[I_SPACE3] = -1;
-}
-
-
-/**
- * Collect general data
- */
-static void stat_walker(ir_node *node, void *env) {
-       /* count all nodes */
-       curr_vals[I_ALL_NODES]++;
-
-       /* count all block nodes */
-       if (is_Block(node))
-               curr_vals[I_BLOCKS]++;
-}
-
-
-/**
- * Collect phi node data
- */
-static void phi_node_stat(ir_node *node) {
-       int arity, i;
-
-       /* count all phi nodes */
-       curr_vals[I_PHIS]++;
-
-       /* argument count */
-       arity = get_irn_arity(node);
-       curr_vals[I_ARG] += arity;
-       if (arity > MAX_ARITY)
-               curr_vals[I_ARITY_E]++;
-       else
-               curr_vals[I_ARITY_S + arity]++;
-
-       /* type of argument {const, pred, glob} */
-       for (i = 0; i < arity; i++) {
-        ir_node *block_of_arg, *block_ith_pred;
-               ir_node *arg = get_irn_n(node, i);
-
-               if (iro_Const == get_irn_opcode(arg)) {
-                       curr_vals[I_CONST]++;
-                       continue;
-               }
-
-               block_of_arg = get_nodes_block(arg);
-               block_ith_pred = get_nodes_block(get_irn_n(get_nodes_block(node), i));
-
-               if (block_of_arg == block_ith_pred) {
-                       curr_vals[I_PRED]++;
-                       continue;
-               }
-
-               curr_vals[I_GLOB]++;
-       }
-}
-
-
-/**
- * Collect phi class data
- */
-static void phi_class_stat(pset *pc) {
-       int i, o, size, doit, sth_interfered;
-       ir_node **members, *p;
-
-       /* phi class count */
-       curr_vals[I_PHICLS]++;
-
-       /* phi class size */
-       size = pset_count(pc);
-       if (size > MAX_CLS_SIZE)
-               curr_vals[I_CLS_SIZE_E]++;
-       else
-               curr_vals[I_CLS_SIZE_S + size]++;
-
-       /* get an array of all members for double iterating */
-       members = malloc(size * sizeof(*members));
-       for (i = 0, p = pset_first(pc); p; p = pset_next(pc))
-               members[i++] = p;
-       assert(i == size);
-
-       /* determine interference of phi class members */
-       curr_vals[I_VALUES] += size;
-       sth_interfered = 0;
-       for (i = 0; i < size-1; ++i) {
-               doit = 1;
-               for (o = i+1; o < size; ++o) {
-                       curr_vals[I_PAIRS]++;
-                       if (values_interfere(members[i], members[o])) {
-                               sth_interfered = 1;
-                               curr_vals[I_PAIRSI]++;
-                               if (doit) {
-                                       curr_vals[I_VALUESI]++;
-                                       doit = 0;
-                               }
-                       }
-               }
-       }
-
-       /* Does this phi class have an inner interference? */
-       curr_vals[I_PHICLSI] += sth_interfered;
-
-       free(members);
-}
-
-
-void phi_stat_collect(ir_graph *irg, pset *all_phi_nodes, pset *all_phi_classes) {
-       ir_node *n;
-       pset *pc;
-
-       irg_walk_graph(irg, stat_walker, NULL, NULL);
-       curr_vals[I_BLOCKS] -= 2;
-
-       for (n = pset_first(all_phi_nodes); n; n = pset_next(all_phi_nodes))
-               phi_node_stat(n);
-
-       for (pc = pset_first(all_phi_classes); pc; pc = pset_next(all_phi_classes))
-               phi_class_stat(pc);
-}
-
-
-/**
- * Dump statistic values in raw format
- */
-static void dump_file(char *filename, int stat[ASIZE]) {
-       FILE *file;
-       int i;
-
-       if (! (file = fopen(filename, "wt"))) {
-               fprintf(stderr, "Cannot open file for writing: %s\n", filename);
-               return;
-       }
-
-       for (i = 0; i < ASIZE; i++) {
-               if (i >= I_ARITY_S && i <= I_ARITY_E)
-                       fprintf(file, "%i %i\n", stat[i], stat[I_PHIS]);
-               else if (i >= I_CLS_SIZE_S && i <= I_CLS_SIZE_E)
-                       fprintf(file, "%i %i\n", stat[i], stat[I_PHICLS]);
-               else
-                       fprintf(file, "%i\n", stat[i]);
-       }
-
-    fclose(file);
-}
-
-
-void phi_stat_update(char *filename) {
-    int i;
-       FILE *all;
-       int vals[ASIZE];
-
-       if (!filename)
-               return;
-
-       /* read in */
-       all = fopen(filename, "rt");
-
-    if (all) {
-               for (i = 0; i < ASIZE; i++) {
-                       if (i >= I_ARITY_S && i <= I_ARITY_E)
-                               fscanf(all, "%i %i\n", &vals[i], &vals[I_PHIS]);
-                       else if (i >= I_CLS_SIZE_S && i <= I_CLS_SIZE_E)
-                               fscanf(all, "%i %i\n", &vals[i], &vals[I_PHICLS]);
-                       else
-                               fscanf(all, "%i\n", &vals[i]);
-               }
-           fclose(all);
-       } else {
-               for (i = 0; i < ASIZE; i++)
-                       vals[i] = 0;
-       }
-
-       /* add current values */
-       for (i = 0; i < ASIZE; i++)
-               vals[i] += curr_vals[i];
-
-       /* write out */
-       dump_file(filename, vals);
-}
-
-
-void phi_stat_dump(char *filename) {
-       if (filename)
-               dump_file(filename, curr_vals);
-}
-
-
-void phi_stat_dump_pretty(char *filename) {
-       int i;
-       FILE *out;
-
-       if (! (out = fopen(filename, "wt"))) {
-               fprintf(stderr, "Cannot open file for writing: %s\n", filename);
-               return;
-       }
-
-       fprintf(out, "\nPhi argument types\n");
-       fprintf(out, "Total     %4d\n", curr_vals[I_ARG]);
-       fprintf(out, "Constants %4d\n", curr_vals[I_CONST]);
-       fprintf(out, "CF-Pred   %4d\n", curr_vals[I_PRED]);
-       fprintf(out, "Others    %4d\n", curr_vals[I_GLOB]);
-
-       fprintf(out, "\nPhi class interference\n");
-       fprintf(out, "Blocks         %4d\n", curr_vals[I_BLOCKS]);
-       fprintf(out, "Phis           %4d\n", curr_vals[I_PHIS]);
-       fprintf(out, "Interf classes %4d of %4d\n", curr_vals[I_PHICLSI], curr_vals[I_PHICLS]);
-       fprintf(out, "Interf pairs   %4d of %4d\n", curr_vals[I_PAIRSI], curr_vals[I_PAIRS]);
-       fprintf(out, "Interf values  %4d of %4d\n", curr_vals[I_PAIRSI], curr_vals[I_VALUES]);
-
-       fprintf(out, "\nPhi arity\n");
-       for (i = I_ARITY_S; i<=I_ARITY_E; i++)
-               fprintf(out, "%2i %4d\n", i-I_ARITY_S, curr_vals[i]);
-
-       fprintf(out, "\nPhi class sizes\n");
-       for (i = I_CLS_SIZE_S; i<=I_CLS_SIZE_E; i++)
-               fprintf(out, "%2i %4d\n", i-I_CLS_SIZE_S, curr_vals[i]);
-
-       fprintf(out, "\n\nTotal nodes:    %4d\n", curr_vals[I_ALL_NODES]);
-
-       fclose(out);
-}
diff --git a/ir/be/phistat.h b/ir/be/phistat.h
deleted file mode 100644 (file)
index d700c86..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * @author Daniel Grund
- * @date 09.12.2004
- */
-
-#ifndef _PHISTAT_H
-#define _PHISTAT_H
-
-#include "pset.h"
-#include "irgraph.h"
-
-/**
- * Resets the array holding the data
- */
-void phi_stat_reset(void);
-
-/**
- * Collect all stat data
- */
-void phi_stat_collect(ir_graph *irg, pset *all_phi_nodes, pset *all_phi_classes);
-
-/**
- * Dumps the current contents of the internal values to a file.
- */
-void phi_stat_dump(char *filename);
-
-/**
- * Updates a cumulative file with the internal values.
- */
-void phi_stat_update(char *filename);
-
-/**
- * Dumps the current contents of the values array
- * and annotations to a file.
- */
-void phi_stat_dump_pretty(char *filename);
-
-#endif