belive: Remove unused (and partially broken) macros.
[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 #include "belive.h"
37
38 struct be_lv_t {
39         ir_nodehashmap_t map;
40         struct obstack   obst;
41         bool             sets_valid;
42         ir_graph        *irg;
43         hook_entry_t     hook_info;
44         lv_chk_t        *lvc;
45 };
46
47 typedef struct be_lv_info_node_t be_lv_info_node_t;
48 struct be_lv_info_node_t {
49         unsigned idx;
50         unsigned flags;
51 };
52
53 struct be_lv_info_head_t {
54         unsigned n_members;
55         unsigned n_size;
56 };
57
58 union be_lv_info_t {
59         struct be_lv_info_head_t head;
60         struct be_lv_info_node_t node;
61 };
62
63 be_lv_info_node_t *be_lv_get(const be_lv_t *li, const ir_node *block,
64                              const ir_node *irn);
65
66 static inline unsigned _be_is_live_xxx(const be_lv_t *li, const ir_node *block,
67                                        const ir_node *irn, unsigned flags)
68 {
69         unsigned res;
70
71         if (li->sets_valid) {
72                 be_lv_info_node_t *info = be_lv_get(li, block, irn);
73                 res = info != NULL ? (info->flags & flags) != 0 : 0;
74         } else {
75                 res = (lv_chk_bl_xxx(li->lvc, block, irn) & flags) != 0;
76         }
77
78         return res;
79 }
80
81 typedef struct lv_iterator_t
82 {
83         be_lv_info_t *info;
84         ir_graph     *irg;
85         be_lv_state_t flags;
86         size_t        i;
87 } lv_iterator_t;
88
89 static inline lv_iterator_t be_lv_iteration_begin(const be_lv_t *lv,
90         const ir_node *block, be_lv_state_t flags)
91 {
92         lv_iterator_t res;
93         res.info  = ir_nodehashmap_get(be_lv_info_t, &lv->map, block);
94         res.irg   = get_Block_irg(block);
95         res.flags = flags;
96         res.i     = res.info != NULL ? res.info[0].head.n_members : 0;
97         return res;
98 }
99
100 static inline ir_node *be_lv_iteration_next(lv_iterator_t *iterator)
101 {
102         while (iterator->i != 0) {
103                 const be_lv_info_t *info = iterator->info + iterator->i--;
104                 if (info->node.flags & iterator->flags)
105                         return get_idx_irn(iterator->irg, info->node.idx);
106         }
107         return NULL;
108 }
109
110 #define be_lv_foreach(lv, block, flags, node) \
111         for (bool once = true; once;) \
112                 for (lv_iterator_t iter = be_lv_iteration_begin((lv), (block), (flags)); once; once = false) \
113                         for (ir_node *node; (node = be_lv_iteration_next(&iter)) != NULL;)
114
115 #define be_is_live_in(lv, bl, irn)    _be_is_live_xxx(lv, bl, irn, be_lv_state_in)
116 #define be_is_live_end(lv, bl, irn)   _be_is_live_xxx(lv, bl, irn, be_lv_state_end)
117 #define be_is_live_out(lv, bl, irn)   _be_is_live_xxx(lv, bl, irn, be_lv_state_out)
118
119 #endif