Remove the unused facility to register space /in front of/ a node.
[libfirm] / ir / ir / irnodemap.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   A nodemap. This variant is a thin wrapper around an ARR_F which
23  *          uses node-indices for access. It is preferable over ir_nodehashmap
24  *          if the info is dense (i.e. something is mapped for most nodes in
25  *          the graph)
26  * @author  Matthias Braun
27  */
28 #ifndef FIRM_IRNODEMAP_H
29 #define FIRM_IRNODEMAP_H
30
31 #include "firm_types.h"
32 #include "irgraph_t.h"
33 #include "array.h"
34
35 typedef struct ir_nodemap ir_nodemap;
36
37 /**
38  * Allocate and initialize a new nodemap object
39  *
40  * @param irg           The graph the nodemap will run on.
41  * @return              A new nodemap object.
42  */
43 static inline void ir_nodemap_init(ir_nodemap *nodemap, const ir_graph *irg)
44 {
45         unsigned max_idx = get_irg_last_idx(irg) + 32;
46         nodemap->data = NEW_ARR_F(void*, max_idx);
47         memset(nodemap->data, 0, max_idx * sizeof(nodemap->data[0]));
48 }
49
50 /**
51  * frees all internal memory used by the nodemap but does not free the
52  * nodemap struct itself.
53  */
54 static inline void ir_nodemap_destroy(ir_nodemap *nodemap)
55 {
56         DEL_ARR_F(nodemap->data);
57         nodemap->data = NULL;
58 }
59
60 /**
61  * Insert a mapping from @p node to @p data.
62  */
63 static inline void ir_nodemap_insert(ir_nodemap *nodemap, const ir_node *node,
64                                      void *data)
65 {
66         unsigned idx = get_irn_idx(node);
67         size_t   len = ARR_LEN(nodemap->data);
68         if (idx >= len) {
69                 ARR_RESIZE(void*, nodemap->data, idx+1);
70                 memset(nodemap->data + len, 0, (idx-len) * sizeof(nodemap->data[0]));
71         }
72         nodemap->data[idx] = data;
73 }
74
75 /**
76  * Insert a mapping from @p node to @p data (fast version).
77  *
78  * @attention You must only use this version if you can be sure that the nodemap
79  * already has enough space to store the mapping. This is the case if @p node
80  * already existed at nodemap_init() time or ir_nodemap_insert() has been used
81  * for this node)
82  */
83 static inline void ir_nodemap_insert_fast(ir_nodemap *nodemap,
84                                           const ir_node *node, void *data)
85 {
86         unsigned idx = get_irn_idx(node);
87         nodemap->data[idx] = data;
88 }
89
90 /**
91  * Removed mapping for @p node.
92  *
93  * This is really a shorthand form for ir_nodemap_insert(nodemap, node, NULL);
94  */
95 static inline void ir_nodemap_remove(ir_nodemap *nodemap, const ir_node *node)
96 {
97         ir_nodemap_insert(nodemap, node, NULL);
98 }
99
100 /**
101  * Get mapping for @p node. Returns NULL if nothing is mapped.
102  */
103 static inline void *ir_nodemap_get(const ir_nodemap *nodemap,
104                                    const ir_node *node)
105 {
106         unsigned idx = get_irn_idx(node);
107         if (idx >= ARR_LEN(nodemap->data))
108                 return NULL;
109         return nodemap->data[idx];
110 }
111
112 #define ir_nodemap_get(type, nodemap, node) ((type*)ir_nodemap_get(nodemap, node))
113
114 /**
115  * Get mapping for @p node (fast version). Returns NULL if nothing is mapped.
116  *
117  * @attention You must only use this function if you can be sure that the
118  * nodemap has enough space to potentially contain the mapping. This is the
119  * case if @p node already existed at nodemap_init() time or ir_nodemap_insert()
120  * has been used for this node)
121  */
122 static inline void *ir_nodemap_get_fast(const ir_nodemap *nodemap,
123                                         const ir_node *node)
124 {
125         unsigned idx = get_irn_idx(node);
126         return nodemap->data[idx];
127 }
128
129 #endif