Assertion lower bound now. Will be removed...
[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         co = new_copy_opt(irg, isa, cls);
29         DBG((dbg, LEVEL_1, "\n\n    ===>  %s  <===\n\n", co->name));
30         co_check_allocation(co);
31
32 #ifdef DO_STAT
33         copies = co_get_copy_count(co);
34         curr_vals[I_COPIES_INIT] += copies;
35         DBG((dbg, 1, "Init copies: %3d\n", copies));
36 #endif
37
38 #ifdef DO_HEUR
39         co_heur_opt(co);
40         co_check_allocation(co);
41 #ifdef DO_STAT
42         copies = co_get_copy_count(co);
43         curr_vals[I_COPIES_HEUR] += copies;
44         DBG((dbg, 1, "Heur copies: %3d\n", copies));
45 #endif
46 #endif
47
48 #ifdef DO_ILP
49         lb = co_get_lower_bound(co);
50         copies = co_get_copy_count(co);
51 //TODO remove checks and enable lb
52         if (copies<lb)
53                 DBG((dbg, 0, "\n\nAt least one computation of these two is boooogy %d < %d\n\n", lb, copies));
54
55 //      if (copies > lb) {
56                 co_ilp_opt(co);
57                 co_check_allocation(co);
58 //      }
59         copies = co_get_copy_count(co);
60         assert(copies>=lb && "At least one computation of these two is boooogy");
61
62 #ifdef DO_STAT
63         copies = co_get_copy_count(co);
64         curr_vals[I_COPIES_HEUR] += copies;
65         DBG((dbg, 1, "Opt  copies: %3d\n", copies));
66 #endif
67 #endif
68
69         free_copy_opt(co);
70 }