Fixed several bug and introduced some others
[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 <stdlib.h>
12
13 #include "bitset.h"
14 #include "list.h"
15 #include "obst.h"
16 #include "pset.h"
17 #include "pmap.h"
18 #include "set.h"
19
20 #include "irnode.h"
21 #include "irgraph.h"
22 #include "bechordal.h"
23
24 /** Defines an invalid register index. */
25 #define NO_COLOR (-1)
26
27 #define BUILD_GRAPH
28
29 #define DBG_CHORDAL "firm.be.ra.chordal"
30
31 /**
32  * A liveness interval border.
33  */
34 typedef struct _border_t {
35         unsigned magic;                                                         /**< A magic number for checking. */
36         struct list_head list;                          /**< list head for queuing. */
37         struct _border_t *other_end;    /**< The other end of the border. */
38         ir_node *irn;                                                 /**< The node. */
39         unsigned step;                                                          /**< The number equal to the interval border. */
40         unsigned pressure;                                              /**< The pressure at this interval border.
41                                                                                                                                         (The border itself is counting). */
42         unsigned is_def : 1;                                    /**< Does this border denote a use or a def. */
43         unsigned is_real : 1;                                   /**< Is the def/use real? Or is it just inserted
44                                                                                                                                         at block beginnings or ends to ensure that inside
45                                                                                                                                         a block, each value has one begin and one end. */
46 } border_t;
47
48 /**
49  * Environment for each of the chordal register allocator phases
50  */
51 struct _be_chordal_env_t {
52         struct obstack obst;    /**< An obstack for temporary storage. */
53   pmap *border_heads;   /**< Maps blocks to border heads. */
54   ir_graph *irg;        /**< The graph the reg alloc is running on. */
55
56 #ifdef BUILD_GRAPH
57         set *nodes;                                             /**< The interference graph nodes. */
58         set *edges;                                             /**< The interference graph edges. */
59 #endif
60
61         bitset_t *live;                         /**< A liveness bitset. */
62         bitset_t *colors;                       /**< The color mask. */
63         bitset_t *in_colors;    /**< Colors used by live in values. */
64         int colors_n;                                   /**< The number of colors. */
65   const arch_env_t *arch_env;         /**< The arch interface environment. */
66   const arch_register_class_t *cls;   /**< The current register class. */
67   void *data;           /**< Some pointer, to which different
68                           phases can attach data to. */
69 };
70
71 static INLINE struct list_head *
72 _get_block_border_head(const be_chordal_env_t *inf, ir_node *bl)
73 {
74   return pmap_get(inf->border_heads, bl);
75 }
76
77 #define get_block_border_head(info, bl)     _get_block_border_head(info, bl)
78
79 int nodes_interfere(const be_chordal_env_t *env, const ir_node *a, const ir_node *b);
80
81 #ifdef BUILD_GRAPH
82 typedef struct _if_node_t {
83         int nnr;
84         pset *neighb;
85 } if_node_t;
86
87 typedef struct _if_edge_t {
88         int src, tgt;
89 } if_edge_t;
90
91 set *be_ra_get_ifg_edges(const be_chordal_env_t *env);
92 set *be_ra_get_ifg_nodes(const be_chordal_env_t *env);
93 int ifg_has_edge(const be_chordal_env_t *env, const if_node_t *n1, const if_node_t* n2);
94
95 #define ifn_get_degree(ifnode) pset_count(ifnode->neighb)
96 #define foreach_neighb(ifnode, curr) \
97                         for(curr=pset_first(ifnode->neighb); curr; curr=pset_next(ifnode->neighb))
98 #endif
99
100 extern void be_ra_chordal_spill(be_chordal_env_t *env);
101
102 #endif /* _BECHORDAL_T_H */