*** empty log message ***
[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
13 #include "bera.h"
14
15 #define DBG_BERA "firm.be.ra"
16
17 typedef struct _ra_node_info_t {
18         int pressure;                                                   /**< Register pressure at this node. */
19         int color;                                                              /**< The color assigned to this node. */
20 } ra_node_info_t;
21
22 typedef struct _ra_block_info_t {
23         bitset_t *used_colors;          /**< A bitmask containing all colors used in the block. */
24 } ra_block_info_t;
25
26 /**
27  * Register allocation data for a node.
28  */
29 typedef struct _ra_info_t {
30         union {
31                 ra_node_info_t node;
32                 ra_block_info_t block;
33         } v;
34 } ra_info_t;
35
36 #define get_ra_irn_info(irn) get_irn_data(irn, ra_info_t, ra_irn_data_offset)
37 #define get_ra_info_irn(inf) get_irn_data_base(inf, ra_irn_data_offset)
38
39 #define get_ra_node_info(the_node)              (&get_ra_irn_info(the_node)->v.node)
40 #define get_ra_block_info(the_block)    (&get_ra_irn_info(the_block)->v.block)
41
42 extern size_t ra_irn_data_offset;
43
44 extern size_t ra_irg_data_offset;
45
46 #define get_irg_ra_link(irg) (*(get_irg_data(irg, void *, ra_irg_data_offset)))
47 #define set_irg_ra_link(irg,ptr) (*(get_irg_data(irg, void *, ra_irg_data_offset)) = ptr)
48
49 /**
50  * Initialize the register allocation framework.
51  */
52 void be_ra_init(void);
53
54 /**
55  * The 'no color' color. The register allocator should use this value,
56  * if a color cannot be assigned at some point.
57  */
58 #define NO_COLOR (-1)
59
60 /**
61  * Check, if a color is valid.
62  * @param col The color.
63  * @return 1, if the color is ok, 0 if the color is illegal.
64  */
65 #define is_color(col) ((col) != NO_COLOR)
66
67 static INLINE int __get_irn_color(const ir_node *irn)
68 {
69         assert(!is_Block(irn) && "No block allowed here");
70         return get_ra_node_info(irn)->color;
71 }
72
73 static INLINE void __set_irn_color(const ir_node *irn, int color)
74 {
75         assert(!is_Block(irn) && "No block allowed here");
76         get_ra_node_info(irn)->color = color;
77 }
78
79 static INLINE int __is_allocatable_irn(const ir_node *irn)
80 {
81         assert(!is_Block(irn) && "No block allowed here");
82         return mode_is_datab(get_irn_mode(irn));
83 }
84
85 #define get_irn_color(irn)                                                              __get_irn_color(irn)
86 #define set_irn_color(irn,col)                                          __set_irn_color(irn, col)
87 #define is_allocatable_irn(irn)                                         __is_allocatable_irn(irn)
88
89 #endif /* BERA_T_H */