206c5aca02974652f8d43b7e82ec08ddcb40ff92
[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 "be_t.h"
24 #include "beifg.h"
25 #include "bera.h"
26 #include "bearch.h"
27 #include "bechordal.h"
28 #include "beirgmod.h"
29
30 typedef struct _be_ra_chordal_opts_t be_ra_chordal_opts_t;
31
32 /** Defines an invalid register index. */
33 #define NO_COLOR (-1)
34
35 /**
36  * A liveness interval border.
37  */
38 typedef struct _border_t {
39         unsigned magic;                 /**< A magic number for checking. */
40         struct list_head list;          /**< list head for queuing. */
41         struct _border_t *other_end;    /**< The other end of the border. */
42         ir_node *irn;                   /**< The node. */
43         unsigned step;                  /**< The number equal to the interval border. */
44         unsigned pressure;              /**< The pressure at this interval border. (The border itself is counting). */
45         unsigned is_def : 1;            /**< Does this border denote a use or a def. */
46         unsigned is_real : 1;           /**< Is the def/use real? Or is it just inserted
47                                         at block beginnings or ends to ensure that inside
48                                         a block, each value has one begin and one end. */
49 } border_t;
50
51 /**
52  * Environment for each of the chordal register allocator phases
53  */
54 struct _be_chordal_env_t {
55         struct obstack obst;              /**< An obstack for temporary storage. */
56         be_ra_chordal_opts_t *opts;       /**< A pointer to the chordal ra options. */
57         const be_irg_t *birg;             /**< Back-end IRG session. */
58         dom_front_info_t *dom_front;      /**< Dominance frontiers. */
59         ir_graph *irg;                    /**< The graph under examination. */
60         const arch_register_class_t *cls; /**< The current register class. */
61         pmap *border_heads;               /**< Maps blocks to border heads. */
62         be_ifg_t *ifg;                    /**< The interference graph. */
63         void *data;                       /**< Some pointer, to which different phases can attach data to. */
64         DEBUG_ONLY(firm_dbg_module_t *dbg;) /**< Debug module for the chordal register allocator. */
65 };
66
67 static INLINE struct list_head *_get_block_border_head(const be_chordal_env_t *inf, ir_node *bl) {
68   return pmap_get(inf->border_heads, bl);
69 }
70
71 #define get_block_border_head(info, bl)     _get_block_border_head(info, bl)
72
73 #define foreach_border_head(head, pos)          list_for_each_entry_reverse(border_t, pos, head, list)
74 #define border_next(b)                      (list_entry((b)->list.next, border_t, list))
75 #define border_prev(b)                      (list_entry((b)->list.prev, border_t, list))
76
77 #define chordal_has_class(chordal_env, irn) \
78         arch_irn_consider_in_reg_alloc(chordal_env->birg->main_env->arch_env, chordal_env->cls, irn)
79
80 int nodes_interfere(const be_chordal_env_t *env, const ir_node *a, const ir_node *b);
81
82 void be_ra_chordal_color(be_chordal_env_t *chordal_env);
83
84 /**
85  * Check a register allocation obtained with the chordal register allocator.
86  * @param chordal_env The chordal environment.
87  */
88 void be_ra_chordal_check(be_chordal_env_t *chordal_env);
89
90 enum {
91         /* spill method */
92         BE_CH_SPILL_BELADY    = 1,
93         BE_CH_SPILL_ILP       = 2,
94
95         /* Dump flags */
96         BE_CH_DUMP_NONE       = (1 << 0),
97         BE_CH_DUMP_SPILL      = (1 << 1),
98         BE_CH_DUMP_LIVE       = (1 << 2),
99         BE_CH_DUMP_COLOR      = (1 << 3),
100         BE_CH_DUMP_COPYMIN    = (1 << 4),
101         BE_CH_DUMP_SSADESTR   = (1 << 5),
102         BE_CH_DUMP_TREE_INTV  = (1 << 6),
103         BE_CH_DUMP_CONSTR     = (1 << 7),
104         BE_CH_DUMP_LOWER      = (1 << 8),
105         BE_CH_DUMP_ALL        = 2 * BE_CH_DUMP_LOWER - 1,
106
107         /* copymin method */
108         BE_CH_COPYMIN_HEUR    = 1,
109         BE_CH_COPYMIN_ILP     = 2,
110
111         /* ifg flavor */
112         BE_CH_IFG_STD         = 1,
113         BE_CH_IFG_FAST        = 2,
114
115         /* lower perm options */
116         BE_CH_LOWER_PERM_SWAP   = (1 << 0),
117         BE_CH_LOWER_PERM_COPY   = (1 << 1),
118         BE_CH_LOWER_PERM_STAT   = (1 << 2)
119 };
120
121 struct _be_ra_chordal_opts_t {
122         int dump_flags;
123         int spill_method;
124         int copymin_method;
125         int ifg_flavor;
126         int lower_perm_opt;
127
128         char ilp_server[128];
129         char ilp_solver[128];
130 };
131
132
133 #endif /* _BECHORDAL_T_H */