2 * Main file for the optimization reducing the copies needed for:
4 * - register-constrained nodes
6 * Contains a simple checker for this optimization.
7 * By request some statistics are collected too.
21 #include "becopyoptmain.h"
22 #include "becopyopt.h"
23 #include "becopystat.h"
29 #define DEBUG_LVL SET_LEVEL_1
30 static firm_dbg_module_t *dbg = NULL;
33 * Needed for result checking
35 static void allocatable_collector(ir_node *node, void *env) {
36 struct obstack *obst = env;
37 if (!is_Block(node) && is_allocatable_irn(node))
38 obstack_ptr_grow(obst, node);
42 * This O(n^2) checker checks, if two ifg-connected nodes have the same color.
44 static void check_results(ir_graph *irg) {
46 ir_node **nodes, *n1, *n2;
50 irg_walk_graph(irg, allocatable_collector, NULL, &ob);
51 obstack_ptr_grow(&ob, NULL);
52 nodes = (ir_node **) obstack_finish(&ob);
53 for (i = 0, n1 = nodes[i]; n1; n1 = nodes[++i]) {
54 assert(! (is_allocatable_irn(n1) && get_irn_color(n1) == NO_COLOR));
55 for (o = i+1, n2 = nodes[o]; n2; n2 = nodes[++o])
56 if (phi_ops_interfere(n1, n2) && get_irn_color(n1) == get_irn_color(n2)) {
57 DBG((dbg, 0, "Error: %n in %n and %n in %n\n", n1, get_nodes_block(n1), n2, get_nodes_block(n2)));
58 assert(0 && "Interfering values have the same color!");
61 obstack_free(&ob, NULL);
62 DBG((dbg, 1, "The checker seems to be happy!\n"));
65 void be_copy_opt_init(void) {
66 dbg = firm_dbg_register("ir.be.copyopt");
67 firm_dbg_set_mask(dbg, DEBUG_LVL);
70 void be_copy_opt(ir_graph* irg) {
73 DBG((dbg, LEVEL_1, "\nIRG: %s\n\n", get_entity_name(get_irg_entity(irg))));
75 co = new_copy_opt(irg);
78 irg_stat_t *stats = new_irg_stat(co);
79 irg_stat_count(stats, co, 0);
86 irg_stat_count(stats, co, 1);
94 irg_stat_count(stats, co, 2);
99 irg_stat_print(stats);
106 void be_copy_opt_done(ir_graph* irg) {