Fixed some bugs
[libfirm] / ir / be / bechordal_t.h
1
2 /**
3  * Internal datastructures for the chordal register allocator.
4  * @author Sebastian Hack
5  * @date 25.1.2005
6  */
7
8 #ifndef _BECHORDAL_T_H
9 #define _BECHORDAL_T_H
10
11 #include "firm_types.h"
12 #include "firm_config.h"
13
14 #include <stdlib.h>
15
16 #include "bitset.h"
17 #include "list.h"
18 #include "obst.h"
19 #include "pset.h"
20 #include "pmap.h"
21 #include "set.h"
22
23 #include "execfreq.h"
24
25 #include "be_t.h"
26 #include "beifg.h"
27 #include "bera.h"
28 #include "bearch.h"
29 #include "bechordal.h"
30 #include "beirgmod.h"
31 #include "belive.h"
32
33 typedef struct _be_ra_chordal_opts_t be_ra_chordal_opts_t;
34
35 /** Defines an invalid register index. */
36 #define NO_COLOR (-1)
37
38 /**
39  * A liveness interval border.
40  */
41 typedef struct _border_t {
42         unsigned magic;                 /**< A magic number for checking. */
43         struct list_head list;          /**< list head for queuing. */
44         struct _border_t *other_end;    /**< The other end of the border. */
45         ir_node *irn;                   /**< The node. */
46         unsigned step;                  /**< The number equal to the interval border. */
47         unsigned pressure;              /**< The pressure at this interval border. (The border itself is counting). */
48         unsigned is_def : 1;            /**< Does this border denote a use or a def. */
49         unsigned is_real : 1;           /**< Is the def/use real? Or is it just inserted
50                                         at block beginnings or ends to ensure that inside
51                                         a block, each value has one begin and one end. */
52 } border_t;
53
54 /**
55  * Environment for each of the chordal register allocator phases
56  */
57 struct _be_chordal_env_t {
58         struct obstack obst;                /**< An obstack for temporary storage. */
59         be_ra_chordal_opts_t *opts;         /**< A pointer to the chordal ra options. */
60         const be_irg_t *birg;               /**< Back-end IRG session. */
61         dom_front_info_t *dom_front;        /**< Dominance frontiers. */
62         ir_graph *irg;                      /**< The graph under examination. */
63         const arch_register_class_t *cls;   /**< The current register class. */
64         exec_freq_t *exec_freq;             /**< Adam's execution frequencies. */
65         be_lv_t *lv;                        /**< Liveness information. */
66         pmap *border_heads;                 /**< Maps blocks to border heads. */
67         be_ifg_t *ifg;                      /**< The interference graph. */
68         void *data;                         /**< Some pointer, to which different phases can attach data to. */
69         bitset_t *ignore_colors;            /**< A set of colors which shall be ignored in register allocation. */
70         DEBUG_ONLY(firm_dbg_module_t *dbg;) /**< Debug module for the chordal register allocator. */
71 };
72
73 static INLINE struct list_head *_get_block_border_head(const be_chordal_env_t *inf, ir_node *bl) {
74   return pmap_get(inf->border_heads, bl);
75 }
76
77 #define get_block_border_head(info, bl)     _get_block_border_head(info, bl)
78
79 #define foreach_border_head(head, pos)          list_for_each_entry_reverse(border_t, pos, head, list)
80 #define border_next(b)                      (list_entry((b)->list.next, border_t, list))
81 #define border_prev(b)                      (list_entry((b)->list.prev, border_t, list))
82
83 #define chordal_has_class(chordal_env, irn) \
84         arch_irn_consider_in_reg_alloc(chordal_env->birg->main_env->arch_env, chordal_env->cls, irn)
85
86 int nodes_interfere(const be_chordal_env_t *env, const ir_node *a, const ir_node *b);
87
88 void be_ra_chordal_color(be_chordal_env_t *chordal_env);
89
90 /**
91  * Check a register allocation obtained with the chordal register allocator.
92  * @param chordal_env The chordal environment.
93  */
94 void be_ra_chordal_check(be_chordal_env_t *chordal_env);
95
96 enum {
97         /* spill method */
98         BE_CH_SPILL_BELADY    = 1,
99         BE_CH_SPILL_MORGAN    = 2,
100         BE_CH_SPILL_REMAT     = 3,
101
102         /* Dump flags */
103         BE_CH_DUMP_NONE       = (1 << 0),
104         BE_CH_DUMP_SPILL      = (1 << 1),
105         BE_CH_DUMP_LIVE       = (1 << 2),
106         BE_CH_DUMP_COLOR      = (1 << 3),
107         BE_CH_DUMP_COPYMIN    = (1 << 4),
108         BE_CH_DUMP_SSADESTR   = (1 << 5),
109         BE_CH_DUMP_TREE_INTV  = (1 << 6),
110         BE_CH_DUMP_CONSTR     = (1 << 7),
111         BE_CH_DUMP_LOWER      = (1 << 8),
112         BE_CH_DUMP_APPEL      = (1 << 9),
113         BE_CH_DUMP_ALL        = 2 * BE_CH_DUMP_LOWER - 1,
114
115         /* copymin method */
116         BE_CH_COPYMIN_NONE      = 0,
117         BE_CH_COPYMIN_HEUR1     = 1,
118         BE_CH_COPYMIN_HEUR2     = 2,
119         BE_CH_COPYMIN_HEUR3     = 3,
120         BE_CH_COPYMIN_STAT      = 4,
121         BE_CH_COPYMIN_ILP       = 5,
122         BE_CH_COPYMIN_PARK_MOON = 6,
123
124         /* ifg flavor */
125         BE_CH_IFG_STD     = 1,
126         BE_CH_IFG_FAST    = 2,
127         BE_CH_IFG_CLIQUE  = 3,
128         BE_CH_IFG_POINTER = 4,
129         BE_CH_IFG_LIST    = 5,
130         BE_CH_IFG_CHECK   = 6,
131
132         /* lower perm options */
133         BE_CH_LOWER_PERM_SWAP   = 1,
134         BE_CH_LOWER_PERM_COPY   = 2,
135
136         /* verify options */
137         BE_CH_VRFY_OFF    = 1,
138         BE_CH_VRFY_WARN   = 2,
139         BE_CH_VRFY_ASSERT = 3,
140 };
141
142 struct _be_ra_chordal_opts_t {
143         int dump_flags;
144         int spill_method;
145         int copymin_method;
146         int ifg_flavor;
147         int lower_perm_opt;
148         int vrfy_option;
149
150         char ilp_server[128];
151         char ilp_solver[128];
152 };
153
154 /**
155  * Open a file whose name is composed from the graph's name and the current register class.
156  * @note The name of the file will be prefix(ifg_name)_(reg_class_name).suffix
157  * @param prefix The file name's prefix.
158  * @param suffix The file name's ending (the . is inserted automatically).
159  * @return       A text file opened for writing.
160  */
161 FILE *be_chordal_open(const be_chordal_env_t *env, const char *prefix, const char *suffix);
162
163 void be_pre_spill_prepare_constr(be_chordal_env_t *cenv);
164
165 #endif /* _BECHORDAL_T_H */