Added register allocator.
[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_H
8 #define _BERA_H
9
10 #include "firm_config.h"
11
12 /**
13  * Register allocation data for a node.
14  */
15 typedef struct _ra_info_t {
16         int pressure;                                                   /**< Register pressure at this node. */
17         int color;                                                              /**< The color assigned to this node. */
18         int sim_live_phi_n;                             /**< The number of simulatenously live phi operand.
19                                                                                                                         This is only used if the ir node occurs as an
20                                                                                                                         operand to a phi function. */
21         int *sim_live_phi;                              /**< The array of simultaneously live nodes. Same restrictions
22                                                                                                                         like @c sim_live_phi hold here. */
23 } ra_info_t;
24
25 #define get_irn_ra_info(irn) get_irn_data(irn, ra_info_t, ra_irn_data_offset)
26 #define get_ra_info_irn(inf) get_irn_data_base(inf, ra_irn_data_offset)
27
28 extern size_t ra_irn_data_offset;
29
30 extern size_t ra_irg_data_offset;
31
32 #define get_irg_ra_link(irg) (*(get_irg_data(irg, void *, ra_irg_data_offset)))
33 #define set_irg_ra_link(irg,ptr) (*(get_irg_data(irg, void *, ra_irg_data_offset)) = ptr)
34
35 /**
36  * Initialize the register allocation framework.
37  */
38 void be_ra_init(void);
39
40 /**
41  * The 'no color' color. The register allocator should use this value,
42  * if a color cannot be assigned at some point.
43  */
44 #define NO_COLOR (-1)
45
46 /**
47  * Check, if a color is valid.
48  * @param col The color.
49  * @return 1, if the color is ok, 0 if the color is illegal.
50  */
51 #define is_color(col) ((col) != NO_COLOR)
52
53 static INLINE int __get_irn_color(const ir_node *irn)
54 {
55         return get_irn_ra_info(irn)->color;
56 }
57
58 static INLINE void __set_irn_color(const ir_node *irn, int color)
59 {
60         get_irn_ra_info(irn)->color = color;
61 }
62
63 static INLINE int __is_allocatable_irn(const ir_node *irn)
64 {
65         return mode_is_datab(get_irn_mode(irn));
66 }
67
68 #define get_irn_color(irn)                                                              __get_irn_color(irn)
69 #define set_irn_color(irn,col)                                          __set_irn_color(irn, col)
70 #define is_allocatable_irn(irn)                                         __is_allocatable_irn(irn)
71
72 #endif