make opcode list global
[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 "be_types.h"
30 #include "irgraph_t.h"
31 #include "irnodehashmap.h"
32 #include "irhooks.h"
33 #include "dfs.h"
34 #include "statev.h"
35
36 #include "pset.h"
37 #include "bitset.h"
38
39 #include "belive.h"
40
41 #define USE_LIVE_CHK
42
43 #ifdef USE_LIVE_CHK
44 #include "irlivechk.h"
45 #endif
46
47 struct be_lv_t {
48         ir_nodehashmap_t map;
49         struct obstack   obst;
50         ir_graph        *irg;
51         dfs_t           *dfs;
52         bitset_t        *nodes;
53         hook_entry_t     hook_info;
54 #ifdef USE_LIVE_CHK
55         lv_chk_t        *lvc;
56 #endif
57 };
58
59 typedef struct be_lv_info_node_t be_lv_info_node_t;
60 struct be_lv_info_node_t {
61         unsigned idx;
62         unsigned flags;
63 };
64
65 struct be_lv_info_head_t {
66         unsigned n_members;
67         unsigned n_size;
68 };
69
70 union be_lv_info_t {
71         struct be_lv_info_head_t head;
72         struct be_lv_info_node_t node;
73 };
74
75 static inline int _be_lv_next_irn(const be_lv_t *lv, const ir_node *block,
76                                   unsigned flags, int i)
77 {
78         be_lv_info_t *arr = (be_lv_info_t*)ir_nodehashmap_get(&lv->map, block);
79         if (arr != NULL) {
80                 int n_members = (int) arr[0].head.n_members;
81                 while(i < n_members) {
82                         if(arr[i + 1].node.flags & flags) {
83                                 return i;
84                         }
85                         ++i;
86                 }
87         }
88
89         return -1;
90 }
91
92 static inline ir_node *_be_lv_get_irn(const be_lv_t *lv, const ir_node *block,
93                                       int i)
94 {
95         be_lv_info_t *arr = (be_lv_info_t*)ir_nodehashmap_get(&lv->map, block);
96         return get_idx_irn(lv->irg, arr[i + 1].node.idx);
97 }
98
99 be_lv_info_node_t *be_lv_get(const be_lv_t *li, const ir_node *block,
100                              const ir_node *irn);
101
102 static inline unsigned _be_is_live_xxx(const be_lv_t *li, const ir_node *block,
103                                        const ir_node *irn, unsigned flags)
104 {
105         unsigned res;
106
107         if (li->nodes != NULL) {
108                 be_lv_info_node_t *info = be_lv_get(li, block, irn);
109                 res = info != NULL ? (info->flags & flags) != 0 : 0;
110         }
111
112 #ifdef USE_LIVE_CHK
113         else
114                 res = (lv_chk_bl_xxx(li->lvc, block, irn) & flags) != 0;
115 #endif
116
117         return res;
118 }
119
120 #define be_lv_foreach(lv, bl, flags, i) \
121         for (i = _be_lv_next_irn(lv, bl, flags, 0); i >= 0; i = _be_lv_next_irn(lv, bl, flags, i + 1))
122
123
124 static inline pset *_be_lv_pset_put(const be_lv_t *lv, const ir_node *block,
125                                     int state, pset *s)
126 {
127         int i;
128         be_lv_foreach(lv, block, state, i)
129                 pset_insert_ptr(s, _be_lv_get_irn(lv, block, i));
130         return s;
131 }
132
133 #define be_lv_get_irn(lv, bl, i)      _be_lv_get_irn(lv, bl, i)
134 #define be_lv_pset_put_in(lv, bl, s)  _be_lv_pset_put(lv, bl, be_lv_state_in, s)
135 #define be_lv_pset_put_out(lv, bl, s) _be_lv_pset_put(lv, bl, be_lv_state_out, s)
136 #define be_lv_pset_put_end(lv, bl, s) _be_lv_pset_put(lv, bl, be_lv_state_end, s)
137
138 #define be_is_live_in(lv, bl, irn)    _be_is_live_xxx(lv, bl, irn, be_lv_state_in)
139 #define be_is_live_end(lv, bl, irn)   _be_is_live_xxx(lv, bl, irn, be_lv_state_end)
140 #define be_is_live_out(lv, bl, irn)   _be_is_live_xxx(lv, bl, irn, be_lv_state_out)
141
142 #define be_lv_has_info_about(lv, irn) bitset_is_set((lv)->nodes, get_irn_idx(irn))
143
144 #endif