Bugfixes, small improvements and movements.
[libfirm] / ir / be / becopyoptmain.c
1 /**
2  * Main file for the optimization reducing the copies needed for:
3  * - phi coalescing
4  * - register-constrained nodes
5  *
6  * @author Daniel Grund
7  * @date 11.04.2005
8  */
9
10 #include "becopyopt.h"
11 #include "becopystat.h"
12 #include "becopyoptmain.h"
13
14 #define DO_HEUR
15 #define DO_ILP
16
17 #define DEBUG_LVL SET_LEVEL_1
18 static firm_dbg_module_t *dbg = NULL;
19
20 void be_copy_opt_init(void) {
21         dbg = firm_dbg_register("ir.be.copyopt");
22         firm_dbg_set_mask(dbg, DEBUG_LVL);
23 }
24
25 void be_copy_opt(ir_graph* irg, const arch_isa_if_t *isa, const arch_register_class_t *cls) {
26         copy_opt_t *co;
27         int lb, copies;
28
29         DBG((dbg, LEVEL_1, "\nIRG: %s\n\n", get_entity_name(get_irg_entity(irg))));
30         co = new_copy_opt(irg, isa, cls);
31         co_check_allocation(co);
32
33 #ifdef DO_STAT
34         copies = co_get_copy_count(co);
35         curr_vals[I_COPIES_INIT] += copies;
36         DBG((dbg, 1, "Init copies: %3d\n", copies));
37 #endif
38
39 #ifdef DO_HEUR
40         co_heur_opt(co);
41         co_check_allocation(co);
42 #ifdef DO_STAT
43         copies = co_get_copy_count(co);
44         curr_vals[I_COPIES_HEUR] += copies;
45         DBG((dbg, 1, "Heur copies: %3d\n", copies));
46 #endif
47 #endif
48
49 #ifdef DO_ILP
50         lb = co_get_lower_bound(co);
51         copies = co_get_copy_count(co);
52 //TODO remove checks and enable lb
53         assert(copies>=lb && "At least one computation of these two is boooogy");
54 //      if (copies > lb) {
55                 co_ilp_opt(co);
56                 co_check_allocation(co);
57 //      }
58         copies = co_get_copy_count(co);
59         assert(copies>=lb && "At least one computation of these two is boooogy");
60
61 #ifdef DO_STAT
62         copies = co_get_copy_count(co);
63         curr_vals[I_COPIES_HEUR] += copies;
64         DBG((dbg, 1, "Opt  copies: %3d\n", copies));
65 #endif
66 #endif
67
68         free_copy_opt(co);
69 }