Lots of changes: Removed all file for phi-opt. Generic approach is now
[libfirm] / ir / be / becopystat.c
1 /**
2  * @author Daniel Grund
3  * @date 19.04.2005
4  */
5 #include "beutil.h"
6 #include "becopystat.h"
7 #include "list.h"
8
9 struct _irg_stat_t {
10         struct list_head chain;
11         ir_graph *irg;
12         const char *irg_name;
13         int interferers, lb, max;
14         int copies[3];
15 };
16
17 typedef struct _all_stat_t {
18         char *unit_name;
19         struct list_head irgs;
20 } all_stat_t;
21
22 static all_stat_t *all_stats = NULL;
23
24 #define irg_list_entry(lh) list_entry(lh, irg_stat_t, chain)
25
26 irg_stat_t *new_irg_stat(copy_opt_t *co) {
27         irg_stat_t *is, *curr;
28
29         if (!all_stats) {
30                 all_stats = calloc(1, sizeof(*all_stats));
31                 //TODO all_stats->unit_name = ??? */
32                 INIT_LIST_HEAD(&all_stats->irgs);
33                 is = calloc(1, sizeof(*is));
34                 is->irg_name = "CUMULATIVE";
35                 list_add_tail(&is->chain, &all_stats->irgs);
36         }
37
38         /* look if we had this irg already */
39         list_for_each_entry(irg_stat_t, curr, &all_stats->irgs, chain)
40                 if (curr->irg == co->irg)
41                         return curr;
42
43         /* else create a new entry */
44         is = calloc(1, sizeof(*is));
45         is->irg = co->irg;
46         is->irg_name = get_entity_name(get_irg_entity(co->irg));
47         list_add_tail(&is->chain, &all_stats->irgs);
48         return is;
49 }
50
51 void irg_stat_count(irg_stat_t *is, copy_opt_t *co, int phase) {
52         unit_t *curr;
53         int max = 0, copies = 0;
54
55         list_for_each_entry(unit_t, curr, &co->units, units) {
56                 int i;
57                 max += curr->interf + curr->node_count - 1;
58                 const ir_node *root = curr->nodes[0];
59                 int root_color = get_irn_color(root);
60                 copies += curr->interf;
61                 for (i=1; i<curr->node_count; ++i) {
62                         const ir_node *arg = curr->nodes[i];
63                         if (root_color != get_irn_color(arg))
64                                 copies++;
65                 }
66         }
67
68         is->copies[phase] += copies;
69         if (phase == 0)
70                 is->max += max;
71         if (phase == 1) {
72                 is->interferers += co_get_interferer_count(co);
73                 is->lb += co_get_lower_bound(co);
74         }
75 }
76
77 void irg_stat_print(irg_stat_t *is) {
78         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);
79 }
80
81 void all_stat_dump(void) {
82         FILE *out;
83         irg_stat_t *cuml, *curr;
84         /* Compute cumulative values */
85         cuml = irg_list_entry(all_stats->irgs.next);
86         cuml->interferers = 0;
87         cuml->lb = 0;
88         cuml->max = 0;
89         cuml->copies[0] = 0;
90         cuml->copies[1] = 0;
91         cuml->copies[2] = 0;
92         list_for_each_entry(irg_stat_t, curr, &all_stats->irgs, chain) {
93                 int i = 0;
94                 cuml->interferers += curr->interferers;
95                 cuml->lb += curr->lb;
96                 cuml->max += curr->max;
97                 for (i=0; i<3; ++i)
98                         cuml->copies[i] += curr->copies[i];
99         }
100
101         /* dump to file */
102         out = ffopen(all_stats->unit_name, "stats", "wt");
103         list_for_each_entry(irg_stat_t, curr, &all_stats->irgs, chain)
104                 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);
105         fclose(out);
106 }