3f248fea26b8f4993e44efeab255e4b5a24fcc4c
[libfirm] / ir / be / belive_t.h
1 /*
2  * Copyright (C) 1995-2007 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  * @version     $Id$
26  */
27 #ifndef FIRM_BE_BELIVE_T_H
28 #define FIRM_BE_BELIVE_T_H
29
30 #include "irgraph_t.h"
31 #include "irphase_t.h"
32 #include "irhooks.h"
33
34 #include "pset.h"
35 #include "bitset.h"
36
37 #include "belive.h"
38
39 #define USE_LIVE_CHK
40
41 #ifdef USE_LIVE_CHK
42 #include "irlivechk.h"
43 #endif
44
45 struct _be_lv_t {
46         ir_phase ph;
47         ir_graph *irg;
48         bitset_t *nodes;
49         hook_entry_t hook_info;
50 #ifdef USE_LIVE_CHK
51         lv_chk_t *lvc;
52 #endif
53 };
54
55 struct _be_lv_info_node_t {
56         unsigned idx;
57         unsigned flags;
58 };
59
60 struct _be_lv_info_head_t {
61         unsigned n_members;
62         unsigned n_size;
63 };
64
65 struct _be_lv_info_t {
66         union {
67                 struct _be_lv_info_head_t head;
68                 struct _be_lv_info_node_t node;
69         } u;
70 };
71
72 static INLINE int _be_lv_next_irn(const struct _be_lv_t *lv, const ir_node *bl, unsigned flags, int i)
73 {
74         struct _be_lv_info_t *arr = phase_get_irn_data(&lv->ph, bl);
75
76         if (arr) {
77                 int n_members = (int) arr[0].u.head.n_members;
78
79                 while(i < n_members) {
80                         if(arr[i + 1].u.node.flags & flags) {
81                                 return i;
82                         }
83                         ++i;
84                 }
85         }
86
87         return -1;
88 }
89
90 static INLINE ir_node *_be_lv_get_irn(const struct _be_lv_t *lv, const ir_node *bl, int i)
91 {
92         struct _be_lv_info_t *arr = phase_get_irn_data(&lv->ph, bl);
93         return get_idx_irn(lv->irg, arr[i + 1].u.node.idx);
94 }
95
96 struct _be_lv_info_node_t *be_lv_get(const struct _be_lv_t *li, const ir_node *bl, const ir_node *irn);
97
98 static INLINE int _be_is_live_xxx(const struct _be_lv_t *li, const ir_node *block, const ir_node *irn, unsigned flags)
99 {
100         if (li->nodes) {
101                 struct _be_lv_info_node_t *info = be_lv_get(li, block, irn);
102                 return info ? (info->flags & flags) != 0 : 0;
103         }
104
105 #ifdef USE_LIVE_CHK
106         else
107                 return (lv_chk_bl_xxx(li->lvc, block, irn) & flags) != 0;
108 #else
109         assert(li->nodes && "node sets must be computed");
110 #endif /* USE_LIVE_CHK */
111 }
112
113 #define be_lv_foreach(lv, bl, flags, i) \
114         for (i = _be_lv_next_irn(lv, bl, flags, 0); i >= 0; i = _be_lv_next_irn(lv, bl, flags, i + 1))
115
116
117 static INLINE pset *_be_lv_pset_put(const struct _be_lv_t *lv, const ir_node *block, int state, pset *s)
118 {
119         int i;
120         be_lv_foreach(lv, block, state, i)
121                 pset_insert_ptr(s, _be_lv_get_irn(lv, block, i));
122         return s;
123 }
124
125 #define be_lv_get_irn(lv, bl, i)      _be_lv_get_irn(lv, bl, i)
126 #define be_lv_pset_put_in(lv, bl, s)  _be_lv_pset_put(lv, bl, be_lv_state_in, s)
127 #define be_lv_pset_put_out(lv, bl, s) _be_lv_pset_put(lv, bl, be_lv_state_out, s)
128 #define be_lv_pset_put_end(lv, bl, s) _be_lv_pset_put(lv, bl, be_lv_state_end, s)
129
130 #define be_is_live_in(lv, bl, irn)    _be_is_live_xxx(lv, bl, irn, be_lv_state_in)
131 #define be_is_live_end(lv, bl, irn)   _be_is_live_xxx(lv, bl, irn, be_lv_state_end)
132 #define be_is_live_out(lv, bl, irn)   _be_is_live_xxx(lv, bl, irn, be_lv_state_out)
133
134 #define be_lv_has_info_about(lv, irn) bitset_is_set((lv)->nodes, get_irn_idx(irn))
135
136 #endif /* FIRM_BE_BELIVE_T_H */