belive: cleanup livness assure/invalidate API
[libfirm] / ir / be / belive_t.h
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief       Internal headers for liveness analysis.
23  * @author      Sebastian Hack
24  * @date        06.12.2004
25  */
26 #ifndef FIRM_BE_BELIVE_T_H
27 #define FIRM_BE_BELIVE_T_H
28
29 #include <stdbool.h>
30 #include "be_types.h"
31 #include "irgraph_t.h"
32 #include "irnodehashmap.h"
33 #include "irhooks.h"
34 #include "irlivechk.h"
35 #include "statev.h"
36
37 #include "pset.h"
38 #include "bitset.h"
39
40 #include "belive.h"
41
42 struct be_lv_t {
43         ir_nodehashmap_t map;
44         struct obstack   obst;
45         bool             sets_valid;
46         ir_graph        *irg;
47         bitset_t        *nodes;
48         hook_entry_t     hook_info;
49         lv_chk_t        *lvc;
50 };
51
52 typedef struct be_lv_info_node_t be_lv_info_node_t;
53 struct be_lv_info_node_t {
54         unsigned idx;
55         unsigned flags;
56 };
57
58 struct be_lv_info_head_t {
59         unsigned n_members;
60         unsigned n_size;
61 };
62
63 union be_lv_info_t {
64         struct be_lv_info_head_t head;
65         struct be_lv_info_node_t node;
66 };
67
68 static inline int _be_lv_next_irn(const be_lv_t *lv, const ir_node *block,
69                                   unsigned flags, int i)
70 {
71         be_lv_info_t *arr = (be_lv_info_t*)ir_nodehashmap_get(&lv->map, block);
72         if (arr != NULL) {
73                 int n_members = (int) arr[0].head.n_members;
74                 while(i < n_members) {
75                         if(arr[i + 1].node.flags & flags) {
76                                 return i;
77                         }
78                         ++i;
79                 }
80         }
81
82         return -1;
83 }
84
85 static inline ir_node *_be_lv_get_irn(const be_lv_t *lv, const ir_node *block,
86                                       int i)
87 {
88         be_lv_info_t *arr = (be_lv_info_t*)ir_nodehashmap_get(&lv->map, block);
89         return get_idx_irn(lv->irg, arr[i + 1].node.idx);
90 }
91
92 be_lv_info_node_t *be_lv_get(const be_lv_t *li, const ir_node *block,
93                              const ir_node *irn);
94
95 static inline unsigned _be_is_live_xxx(const be_lv_t *li, const ir_node *block,
96                                        const ir_node *irn, unsigned flags)
97 {
98         unsigned res;
99
100         if (li->sets_valid) {
101                 be_lv_info_node_t *info = be_lv_get(li, block, irn);
102                 res = info != NULL ? (info->flags & flags) != 0 : 0;
103         } else {
104                 res = (lv_chk_bl_xxx(li->lvc, block, irn) & flags) != 0;
105         }
106
107         return res;
108 }
109
110 #define be_lv_foreach(lv, bl, flags, i) \
111         for (i = _be_lv_next_irn(lv, bl, flags, 0); i >= 0; i = _be_lv_next_irn(lv, bl, flags, i + 1))
112
113
114 static inline pset *_be_lv_pset_put(const be_lv_t *lv, const ir_node *block,
115                                     int state, pset *s)
116 {
117         int i;
118         be_lv_foreach(lv, block, state, i)
119                 pset_insert_ptr(s, _be_lv_get_irn(lv, block, i));
120         return s;
121 }
122
123 #define be_lv_get_irn(lv, bl, i)      _be_lv_get_irn(lv, bl, i)
124 #define be_lv_pset_put_in(lv, bl, s)  _be_lv_pset_put(lv, bl, be_lv_state_in, s)
125 #define be_lv_pset_put_out(lv, bl, s) _be_lv_pset_put(lv, bl, be_lv_state_out, s)
126 #define be_lv_pset_put_end(lv, bl, s) _be_lv_pset_put(lv, bl, be_lv_state_end, s)
127
128 #define be_is_live_in(lv, bl, irn)    _be_is_live_xxx(lv, bl, irn, be_lv_state_in)
129 #define be_is_live_end(lv, bl, irn)   _be_is_live_xxx(lv, bl, irn, be_lv_state_end)
130 #define be_is_live_out(lv, bl, irn)   _be_is_live_xxx(lv, bl, irn, be_lv_state_out)
131
132 #define be_lv_has_info_about(lv, irn) bitset_is_set((lv)->nodes, get_irn_idx(irn))
133
134 #endif