Added new arch interface
[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 #ifdef HAVE_CONFIG_H
10 #include "config.h"
11 #endif
12
13 #include "becopyopt.h"
14 #include "becopystat.h"
15 #include "becopyoptmain.h"
16
17 #define DO_HEUR
18 #define DO_ILP
19
20 #define DEBUG_LVL SET_LEVEL_1
21 static firm_dbg_module_t *dbg = NULL;
22
23 void be_copy_opt_init(void) {
24         dbg = firm_dbg_register("ir.be.copyopt");
25         firm_dbg_set_mask(dbg, DEBUG_LVL);
26 }
27
28 void be_copy_opt(ir_graph* irg, const arch_isa_if_t *isa, const arch_register_class_t *cls) {
29         copy_opt_t *co;
30         int lb, copies;
31         co = new_copy_opt(irg, isa, cls);
32         DBG((dbg, LEVEL_1, "\n\n    ===>  %s  <===\n\n", co->name));
33         co_check_allocation(co);
34
35 #ifdef DO_STAT
36         copies = co_get_copy_count(co);
37         curr_vals[I_COPIES_INIT] += copies;
38         DBG((dbg, 1, "Init copies: %3d\n", copies));
39 #endif
40
41 #ifdef DO_HEUR
42         co_heur_opt(co);
43         co_check_allocation(co);
44 #ifdef DO_STAT
45         copies = co_get_copy_count(co);
46         curr_vals[I_COPIES_HEUR] += copies;
47         DBG((dbg, 1, "Heur copies: %3d\n", copies));
48 #endif
49 #endif
50
51 #ifdef DO_ILP
52         lb = co_get_lower_bound(co);
53         copies = co_get_copy_count(co);
54 //TODO remove checks and enable lb
55         if (copies<lb)
56                 DBG((dbg, 0, "\n\nAt least one computation of these two is boooogy %d < %d\n\n", lb, copies));
57
58 //      if (copies > lb) {
59                 co_ilp_opt(co);
60                 co_check_allocation(co);
61 //      }
62         copies = co_get_copy_count(co);
63         assert(copies>=lb && "At least one computation of these two is boooogy");
64
65 #ifdef DO_STAT
66         copies = co_get_copy_count(co);
67         curr_vals[I_COPIES_HEUR] += copies;
68         DBG((dbg, 1, "Opt  copies: %3d\n", copies));
69 #endif
70 #endif
71
72         free_copy_opt(co);
73 }