ia32: we cannot fold ia32_mode_E reloads
[libfirm] / ir / be / belive_t.h
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5
6 /**
7  * @file
8  * @brief       Internal headers for liveness analysis.
9  * @author      Sebastian Hack
10  * @date        06.12.2004
11  */
12 #ifndef FIRM_BE_BELIVE_T_H
13 #define FIRM_BE_BELIVE_T_H
14
15 #include <stdbool.h>
16 #include "irnodehashmap.h"
17 #include "irhooks.h"
18 #include "irlivechk.h"
19 #include "belive.h"
20 #include "bearch.h"
21
22 #define be_is_live_in(lv, bl, irn)    _be_is_live_xxx(lv, bl, irn, be_lv_state_in)
23 #define be_is_live_end(lv, bl, irn)   _be_is_live_xxx(lv, bl, irn, be_lv_state_end)
24 #define be_is_live_out(lv, bl, irn)   _be_is_live_xxx(lv, bl, irn, be_lv_state_out)
25
26 struct be_lv_t {
27         ir_nodehashmap_t map;
28         struct obstack   obst;
29         bool             sets_valid;
30         ir_graph        *irg;
31         lv_chk_t        *lvc;
32 };
33
34 typedef struct be_lv_info_node_t be_lv_info_node_t;
35 struct be_lv_info_node_t {
36         ir_node *node;
37         unsigned flags;
38 };
39
40 struct be_lv_info_head_t {
41         unsigned n_members;
42         unsigned n_size;
43 };
44
45 union be_lv_info_t {
46         struct be_lv_info_head_t head;
47         struct be_lv_info_node_t node;
48 };
49
50 be_lv_info_node_t *be_lv_get(const be_lv_t *li, const ir_node *block,
51                              const ir_node *irn);
52
53 static inline unsigned _be_is_live_xxx(const be_lv_t *li, const ir_node *block,
54                                        const ir_node *irn, unsigned flags)
55 {
56         unsigned res;
57
58         if (li->sets_valid) {
59                 be_lv_info_node_t *info = be_lv_get(li, block, irn);
60                 res = info != NULL ? (info->flags & flags) != 0 : 0;
61         } else {
62                 res = (lv_chk_bl_xxx(li->lvc, block, irn) & flags) != 0;
63         }
64
65         return res;
66 }
67
68 typedef struct lv_iterator_t
69 {
70         be_lv_info_t *info;
71         size_t        i;
72 } lv_iterator_t;
73
74 static inline lv_iterator_t be_lv_iteration_begin(const be_lv_t *lv,
75         const ir_node *block)
76 {
77         lv_iterator_t res;
78         res.info  = ir_nodehashmap_get(be_lv_info_t, &lv->map, block);
79         res.i     = res.info != NULL ? res.info[0].head.n_members : 0;
80         return res;
81 }
82
83 static inline ir_node *be_lv_iteration_next(lv_iterator_t *iterator, be_lv_state_t flags)
84 {
85         while (iterator->i != 0) {
86                 const be_lv_info_t *info = iterator->info + iterator->i--;
87                 if (info->node.flags & flags)
88                         return info->node.node;
89         }
90         return NULL;
91 }
92
93 static inline ir_node *be_lv_iteration_cls_next(lv_iterator_t *iterator, be_lv_state_t flags, const arch_register_class_t *cls)
94 {
95         while (iterator->i != 0) {
96                 const be_lv_info_t *info = iterator->info + iterator->i--;
97                 if (!(info->node.flags & flags))
98                         continue;
99
100                 ir_node *node = info->node.node;
101                 ir_mode *mode = get_irn_mode(node);
102                 if (!mode_is_datab(mode))
103                         continue;
104                 if (!arch_irn_consider_in_reg_alloc(cls, node))
105                         continue;
106                 return node;
107         }
108         return NULL;
109 }
110
111 #define be_lv_foreach(lv, block, flags, node) \
112         for (bool once = true; once;) \
113                 for (lv_iterator_t iter = be_lv_iteration_begin((lv), (block)); once; once = false) \
114                         for (ir_node *node; (node = be_lv_iteration_next(&iter, (flags))) != NULL;)
115
116 #define be_lv_foreach_cls(lv, block, flags, cls, node) \
117         for (bool once = true; once;) \
118                 for (lv_iterator_t iter = be_lv_iteration_begin((lv), (block)); once; once = false) \
119                         for (ir_node *node; (node = be_lv_iteration_cls_next(&iter, (flags), (cls))) != NULL;)
120
121 #endif