Added new arch interface
[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         ir_node *spill_location;  /**< Spill location node of the node.
20                                                                                                                         If NULL, the node is not spilled. */
21         int pressure;                                                   /**< Register pressure at this node. */
22         int color;                                                              /**< The color assigned to this node. */
23 } ra_node_info_t;
24
25 typedef struct _ra_block_info_t {
26         bitset_t *used_colors;                                  /**< A bitmask containing all colors used in the block. */
27         struct list_head border_head;           /**< A list head to enqueue the borders. */
28 } ra_block_info_t;
29
30 /**
31  * Register allocation data for a node.
32  */
33 typedef struct _ra_info_t {
34         union {
35                 ra_node_info_t node;
36                 ra_block_info_t block;
37         } v;
38 } ra_info_t;
39
40 #define get_ra_irn_info(irn) get_irn_data(irn, ra_info_t, ra_irn_data_offset)
41 #define get_ra_info_irn(inf) get_irn_data_base(inf, ra_irn_data_offset)
42
43 #define get_ra_node_info(the_node)              (&get_ra_irn_info(the_node)->v.node)
44 #define get_ra_block_info(the_block)    (&get_ra_irn_info(the_block)->v.block)
45
46 #define get_block_border_head(bl)     (&get_ra_block_info(bl)->border_head)
47
48 extern size_t ra_irn_data_offset;
49
50 extern size_t ra_irg_data_offset;
51
52 #define get_irg_ra_link(irg) (*(get_irg_data(irg, void *, ra_irg_data_offset)))
53 #define set_irg_ra_link(irg,ptr) (*(get_irg_data(irg, void *, ra_irg_data_offset)) = ptr)
54
55 /**
56  * Initialize the register allocation framework.
57  */
58 void be_ra_init(void);
59
60 /**
61  * The 'no color' color. The register allocator should use this value,
62  * if a color cannot be assigned at some point.
63  */
64 #define NO_COLOR (-1)
65
66 /**
67  * Check, if a color is valid.
68  * @param col The color.
69  * @return 1, if the color is ok, 0 if the color is illegal.
70  */
71 #define is_color(col) ((col) != NO_COLOR)
72
73 static INLINE int _get_irn_color(const ir_node *irn)
74 {
75         assert(!is_Block(irn) && "No block allowed here");
76         return get_ra_node_info(irn)->color;
77 }
78
79 static INLINE void _set_irn_color(const ir_node *irn, int color)
80 {
81         assert(!is_Block(irn) && "No block allowed here");
82         get_ra_node_info(irn)->color = color;
83 }
84
85 static INLINE int _is_allocatable_irn(const ir_node *irn)
86 {
87         assert(!is_Block(irn) && "No block allowed here");
88         return mode_is_datab(get_irn_mode(irn));
89 }
90
91 #define get_irn_color(irn)                                                              _get_irn_color(irn)
92 #define set_irn_color(irn,col)                                          _set_irn_color(irn, col)
93 #define is_allocatable_irn(irn)                                         _is_allocatable_irn(irn)
94
95 static INLINE struct list_head *_get_block_border_head(ir_node *block)
96 {
97         return &get_ra_block_info(block)->border_head;
98 }
99
100 /**
101  * Check, if two phi operands interfere.
102  * @param a A node which is operand to a phi function.
103  * @param b Another node which is operand to a phi function.
104  * @return 1, if @p a and @p b interfere, 0 if not.
105  */
106 int phi_ops_interfere(const ir_node *a, const ir_node *b);
107
108 #endif /* BERA_T_H */