cleanup: Remove unnecessary #include "beirg.h".
[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_t.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         hook_entry_t     hook_info;
48         lv_chk_t        *lvc;
49 };
50
51 typedef struct be_lv_info_node_t be_lv_info_node_t;
52 struct be_lv_info_node_t {
53         unsigned idx;
54         unsigned flags;
55 };
56
57 struct be_lv_info_head_t {
58         unsigned n_members;
59         unsigned n_size;
60 };
61
62 union be_lv_info_t {
63         struct be_lv_info_head_t head;
64         struct be_lv_info_node_t node;
65 };
66
67 be_lv_info_node_t *be_lv_get(const be_lv_t *li, const ir_node *block,
68                              const ir_node *irn);
69
70 static inline unsigned _be_is_live_xxx(const be_lv_t *li, const ir_node *block,
71                                        const ir_node *irn, unsigned flags)
72 {
73         unsigned res;
74
75         if (li->sets_valid) {
76                 be_lv_info_node_t *info = be_lv_get(li, block, irn);
77                 res = info != NULL ? (info->flags & flags) != 0 : 0;
78         } else {
79                 res = (lv_chk_bl_xxx(li->lvc, block, irn) & flags) != 0;
80         }
81
82         return res;
83 }
84
85 typedef struct lv_iterator_t
86 {
87         be_lv_info_t *info;
88         ir_graph     *irg;
89         be_lv_state_t flags;
90         size_t        i;
91 } lv_iterator_t;
92
93 static inline lv_iterator_t be_lv_iteration_begin(const be_lv_t *lv,
94         const ir_node *block, be_lv_state_t flags)
95 {
96         lv_iterator_t res;
97         res.info  = ir_nodehashmap_get(be_lv_info_t, &lv->map, block);
98         res.irg   = get_Block_irg(block);
99         res.flags = flags;
100         res.i     = res.info != NULL ? res.info[0].head.n_members : 0;
101         return res;
102 }
103
104 static inline ir_node *be_lv_iteration_next(lv_iterator_t *iterator)
105 {
106         while (iterator->i != 0) {
107                 const be_lv_info_t *info = iterator->info + iterator->i--;
108                 if (info->node.flags & iterator->flags)
109                         return get_idx_irn(iterator->irg, info->node.idx);
110         }
111         return NULL;
112 }
113
114 #define be_lv_foreach(lv, block, flags, node) \
115         for (bool once = true; once;) \
116                 for (lv_iterator_t iter = be_lv_iteration_begin((lv), (block), (flags)); once; once = false) \
117                         for (ir_node *node; (node = be_lv_iteration_next(&iter)) != NULL;)
118
119 static inline pset *_be_lv_pset_put(const be_lv_t *lv, const ir_node *block,
120                                     int state, pset *s)
121 {
122         be_lv_foreach(lv, block, state, node)
123                 pset_insert_ptr(s, node);
124         return s;
125 }
126
127 #define be_lv_get_irn(lv, bl, i)      _be_lv_get_irn(lv, bl, i)
128 #define be_lv_pset_put_in(lv, bl, s)  _be_lv_pset_put(lv, bl, be_lv_state_in, s)
129 #define be_lv_pset_put_out(lv, bl, s) _be_lv_pset_put(lv, bl, be_lv_state_out, s)
130 #define be_lv_pset_put_end(lv, bl, s) _be_lv_pset_put(lv, bl, be_lv_state_end, s)
131
132 #define be_is_live_in(lv, bl, irn)    _be_is_live_xxx(lv, bl, irn, be_lv_state_in)
133 #define be_is_live_end(lv, bl, irn)   _be_is_live_xxx(lv, bl, irn, be_lv_state_end)
134 #define be_is_live_out(lv, bl, irn)   _be_is_live_xxx(lv, bl, irn, be_lv_state_out)
135
136 #define be_lv_has_info_about(lv, irn) bitset_is_set((lv)->nodes, get_irn_idx(irn))
137
138 #endif