Added access for border_head of block.
[libfirm] / ir / be / bera_t.h
1 /**
2  * Internal register allocation facility.
3  * @author Sebastian Hack
4  * @date 8.12.2004
5  */
6
7 #ifndef _BERA_T_H
8 #define _BERA_T_H
9
10 #include "firm_config.h"
11 #include "bitset.h"
12 #include "list.h"
13
14 #include "bera.h"
15
16 #define DBG_BERA "firm.be.ra"
17
18 typedef struct _ra_node_info_t {
19         int pressure;                                                   /**< Register pressure at this node. */
20         int color;                                                              /**< The color assigned to this node. */
21 } ra_node_info_t;
22
23 typedef struct _ra_block_info_t {
24         bitset_t *used_colors;                                  /**< A bitmask containing all colors used in the block. */
25         struct list_head border_head;           /**< A list head to enqueue the borders. */
26 } ra_block_info_t;
27
28 /**
29  * Register allocation data for a node.
30  */
31 typedef struct _ra_info_t {
32         union {
33                 ra_node_info_t node;
34                 ra_block_info_t block;
35         } v;
36 } ra_info_t;
37
38 #define get_ra_irn_info(irn) get_irn_data(irn, ra_info_t, ra_irn_data_offset)
39 #define get_ra_info_irn(inf) get_irn_data_base(inf, ra_irn_data_offset)
40
41 #define get_ra_node_info(the_node)              (&get_ra_irn_info(the_node)->v.node)
42 #define get_ra_block_info(the_block)    (&get_ra_irn_info(the_block)->v.block)
43
44 extern size_t ra_irn_data_offset;
45
46 extern size_t ra_irg_data_offset;
47
48 #define get_irg_ra_link(irg) (*(get_irg_data(irg, void *, ra_irg_data_offset)))
49 #define set_irg_ra_link(irg,ptr) (*(get_irg_data(irg, void *, ra_irg_data_offset)) = ptr)
50
51 /**
52  * Initialize the register allocation framework.
53  */
54 void be_ra_init(void);
55
56 /**
57  * The 'no color' color. The register allocator should use this value,
58  * if a color cannot be assigned at some point.
59  */
60 #define NO_COLOR (-1)
61
62 /**
63  * Check, if a color is valid.
64  * @param col The color.
65  * @return 1, if the color is ok, 0 if the color is illegal.
66  */
67 #define is_color(col) ((col) != NO_COLOR)
68
69 static INLINE int _get_irn_color(const ir_node *irn)
70 {
71         assert(!is_Block(irn) && "No block allowed here");
72         return get_ra_node_info(irn)->color;
73 }
74
75 static INLINE void _set_irn_color(const ir_node *irn, int color)
76 {
77         assert(!is_Block(irn) && "No block allowed here");
78         get_ra_node_info(irn)->color = color;
79 }
80
81 static INLINE int _is_allocatable_irn(const ir_node *irn)
82 {
83         assert(!is_Block(irn) && "No block allowed here");
84         return mode_is_datab(get_irn_mode(irn));
85 }
86
87 #define get_irn_color(irn)                                                              _get_irn_color(irn)
88 #define set_irn_color(irn,col)                                          _set_irn_color(irn, col)
89 #define is_allocatable_irn(irn)                                         _is_allocatable_irn(irn)
90
91 static INLINE struct list_head *_get_block_border_head(ir_node *block)
92 {
93         return &get_ra_block_info(block)->border_head;
94 }
95
96 /**
97  * Check, if two phi operands interfere.
98  * @param a A node which is operand to a phi function.
99  * @param b Another node which is operand to a phi function.
100  * @return 1, if @p a and @p b interfere, 0 if not.
101  */
102 int phi_ops_interfere(const ir_node *a, const ir_node *b);
103
104 #endif /* BERA_T_H */