Adapted to new liveness
[libfirm] / ir / be / belive_t.h
1 /**
2  * Internal headers for liveness analysis.
3  * @author Sebastian Hack
4  * @date 6.12.2004
5  */
6
7 #ifndef _BELIVE_T_H
8 #define _BELIVE_T_H
9
10 #include "firm_config.h"
11
12 #include "irgraph_t.h"
13 #include "iredges_t.h"
14 #include "irphase_t.h"
15 #include "irhooks.h"
16
17 #include "pset.h"
18 #include "set.h"
19 #include "list.h"
20 #include "hashptr.h"
21 #include "bitset.h"
22
23 #include "belive.h"
24
25 struct _be_lv_t {
26         phase_t ph;
27         ir_graph *irg;
28         bitset_t *nodes;
29         hook_entry_t hook_info;
30         firm_dbg_module_t *dbg;
31 };
32
33 struct _be_lv_info_node_t {
34         unsigned idx;
35         unsigned flags;
36 };
37
38 struct _be_lv_info_head_t {
39         unsigned n_members;
40         unsigned n_size;
41 };
42
43 struct _be_lv_info_t {
44         union {
45                 struct _be_lv_info_head_t head;
46                 struct _be_lv_info_node_t node;
47         } u;
48 };
49
50 static INLINE int _be_lv_next_irn(const struct _be_lv_t *lv, const ir_node *bl, unsigned flags, int i)
51 {
52         struct _be_lv_info_t *arr     = phase_get_irn_data(&lv->ph, bl);
53         if(arr) {
54                 int n_members = (int) arr[0].u.head.n_members;
55
56                 while(i < n_members) {
57                         if(arr[i + 1].u.node.flags & flags) {
58                                 return i;
59                         }
60                         ++i;
61                 }
62         }
63
64         return -1;
65 }
66
67 static INLINE ir_node * _be_lv_get_irn(const struct _be_lv_t *lv, const ir_node *bl, int i)
68 {
69         struct _be_lv_info_t *arr     = phase_get_irn_data(&lv->ph, bl);
70         return get_idx_irn(lv->irg, arr[i + 1].u.node.idx);
71 }
72
73 struct _be_lv_info_node_t *be_lv_get(const struct _be_lv_t *li, const ir_node *bl, const ir_node *irn);
74
75 static INLINE int _be_is_live_xxx(const struct _be_lv_t *li, const ir_node *block, const ir_node *irn, unsigned flags)
76 {
77         struct _be_lv_info_node_t *info = be_lv_get(li, block, irn);
78         return info ? (info->flags & flags) != 0 : 0;
79 }
80
81 #define be_lv_foreach(lv, bl, flags, i) \
82         for(i = _be_lv_next_irn(lv, bl, flags, 0); i >= 0; i = _be_lv_next_irn(lv, bl, flags, i + 1))
83
84
85 static INLINE pset *_be_lv_pset_put(struct _be_lv_t *lv, const ir_node *block, int state, pset *s)
86 {
87         int i;
88         be_lv_foreach(lv, block, state, i)
89                 pset_insert_ptr(s, _be_lv_get_irn(lv, block, i));
90         return s;
91 }
92
93 #define be_lv_get_irn(lv, bl, i)      _be_lv_get_irn(lv, bl, i)
94 #define be_lv_pset_put_in(lv, bl, s)  _be_lv_pset_put(lv, bl, be_lv_state_in, s)
95 #define be_lv_pset_put_out(lv, bl, s) _be_lv_pset_put(lv, bl, be_lv_state_out, s)
96 #define be_lv_pset_put_end(lv, bl, s) _be_lv_pset_put(lv, bl, be_lv_state_end, s)
97
98 #define be_is_live_in(lv, bl, irn)    _be_is_live_xxx(lv, bl, irn, be_lv_state_in)
99 #define be_is_live_end(lv, bl, irn)   _be_is_live_xxx(lv, bl, irn, be_lv_state_end)
100 #define be_is_live_out(lv, bl, irn)   _be_is_live_xxx(lv, bl, irn, be_lv_state_out)
101
102 #define be_lv_has_info_about(lv, irn) bitset_is_set((lv)->nodes, get_irn_idx(irn))
103
104 #endif