Added optimization for empty Q-lines. Adapted to use the isa-stuff. Last
[libfirm] / ir / be / becopyopt.h
1 /**
2  * Header for copy optimization problem. Analysis and set up of the problem.
3  * @author Daniel Grund
4  * @date 12.04.2005
5  */
6
7 #ifndef _BECOPYOPT_H
8 #define _BECOPYOPT_H
9
10 #ifdef HAVE_CONFIG_H
11 #include "config.h"
12 #endif
13
14 #include <stdlib.h>
15 #include <stdio.h>
16 #include <alloca.h>
17 #include <sys/types.h>
18 #include <sys/stat.h>
19
20 #include "debug.h"
21 #include "obst.h"
22 #include "list.h"
23 #include "set.h"
24 #include "pset.h"
25 #include "bitset.h"
26 #include "sp_matrix.h"
27
28 #include "irgraph.h"
29 #include "irgwalk.h"
30 #include "irnode.h"
31 #include "irdom.h"
32 #include "irouts.h"
33
34 #include "beutil.h"
35 #include "benumb_t.h"
36 #include "belive_t.h"
37 #include "bera_t.h"
38 #include "bechordal_t.h"
39 #include "bearch.h"
40
41 /**
42  * TODO external things
43  * define get_weight to sth representing the _gain_ if node n and m
44  * have the same color. Must return values MIN_WEIGHT <= . <= MAX_WEIGHT.
45  */
46 #define get_weight(n,m) 1
47 #define is_possible_color(irn, col) 1
48 #define is_Copy(irn) 0
49 #define MAX_COLORS 32
50
51 /**
52  * A single unit of optimization. Lots of these form a copy-opt problem
53  */
54 typedef struct _unit_t {
55         struct list_head units;         /**< chain for all units */
56         int interf;                                     /**< number of nodes dropped due to interference */
57         int node_count;                         /**< size of the nodes array */
58         const ir_node **nodes;          /**< [0] is the root-node, others are non interfering args of it. */
59
60         /* for heuristic */
61         int mis_size;                           /**< size of a mis considering only ifg (not coloring conflicts) */
62         struct list_head queue;         /**< list of (mis/color) sorted by size of mis */
63 } unit_t;
64
65 /**
66  * Data representing the problem of copy minimization.
67  */
68 typedef struct _copy_opt_t {
69         ir_graph *irg;                                          /**< the irg to process */
70         const arch_isa_if_t *isa;
71         const arch_register_class_t *cls;       /**< the registerclass to optimize */
72         struct list_head units;                         /**< all units to optimize in right oreder */
73         pset *roots;                                            /**< used only temporary for detecting multiple appends */
74         struct obstack ob;
75 } copy_opt_t;
76
77
78 /**
79  * Generate the problem. Collect all infos and optimizable nodes.
80  */
81 copy_opt_t *new_copy_opt(ir_graph *irg, const arch_isa_if_t *isa, const arch_register_class_t *cls);
82
83 /**
84  * Free the space...
85  */
86 void free_copy_opt(copy_opt_t *co);
87
88 /**
89  * Returns the current number of copies needed
90  */
91 int co_get_copy_count(copy_opt_t *co);
92
93 /**
94  * IMPORTANT: Available only iff heuristic has run!
95  * Returns a lower bound for the number of copies needed based on interfering
96  * arguments and the size of a max indep. set (only ifg-edges) of the other args.
97  */
98 int co_get_lower_bound(copy_opt_t *co);
99
100 /**
101  * Returns the number of arguments interfering with their root node. This also
102  * is a (worse) lower bound for the number of copies needed.
103  */
104 int co_get_interferer_count(copy_opt_t *co);
105
106 /**
107  * Solves the problem using a heuristic approach
108  */
109 void co_heur_opt(copy_opt_t *co);
110
111 /**
112  * Solves the problem using mixed integer programming
113  */
114 void co_ilp_opt(copy_opt_t *co);
115
116 /**
117  * Checks the register allocation for correctness
118  */
119 void co_check_allocation(copy_opt_t *co);
120
121 #endif