becopyheur2: Cache the admissible registers eagerly.
[libfirm] / ir / ir / irnodehashmap.h
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5
6 /**
7  * @file
8  * @author    Matthias Braun
9  * @date      30.03.2007
10  * @brief     A nodemap. This should be preferred over a simple pset, because it
11  *            tries to guarantee deterministic behavior. (and is faster)
12  */
13 #ifndef _FIRM_IRNODEHASHMAP_H_
14 #define _FIRM_IRNODEHASHMAP_H_
15
16 #include "irnode.h"
17
18 typedef struct ir_nodehashmap_entry_t {
19         ir_node *node;
20         void    *data;
21 } ir_nodehashmap_entry_t;
22
23 #define HashSet          ir_nodehashmap_t
24 #define HashSetIterator  ir_nodehashmap_iterator_t
25 #define ValueType        ir_nodehashmap_entry_t
26 #define DO_REHASH
27 #include "hashset.h"
28 #undef DO_REHASH
29 #undef ValueType
30 #undef HashSetIterator
31 #undef HashSet
32
33 typedef struct ir_nodehashmap_t           ir_nodehashmap_t;
34 typedef struct ir_nodehashmap_iterator_t  ir_nodehashmap_iterator_t;
35
36 /**
37  * Initializes a nodehashmap with default size.
38  *
39  * @param nodehashmap      Pointer to allocated space for the nodehashmap
40  */
41 void ir_nodehashmap_init(ir_nodehashmap_t *nodehashmap);
42
43 /**
44  * Initializes a nodehashmap
45  *
46  * @param nodehashmap         Pointer to allocated space for the nodehashmap
47  * @param expected_elements   Number of elements expected in the nodehashmap
48  *                            (roughly)
49  */
50 void ir_nodehashmap_init_size(ir_nodehashmap_t *nodehashmap,
51                               size_t expected_elements);
52
53 /**
54  * Destroys a nodehashmap and frees the memory allocated for hashtable. The
55  * memory of the nodehashmap itself is not freed.
56  *
57  * @param nodehashmap   Pointer to the nodehashmap
58  */
59 void ir_nodehashmap_destroy(ir_nodehashmap_t *nodehashmap);
60
61 /**
62  * Inserts a node into a nodehashmap.
63  *
64  * @param nodehashmap  Pointer to the nodehashmap
65  * @param node         node to insert into the nodehashmap
66  * @param data         data to associate with the node
67  */
68 void ir_nodehashmap_insert(ir_nodehashmap_t *nodehashmap, ir_node *node,
69                            void *data);
70
71 /**
72  * Removes a node from a nodehashmap. Does nothing if the nodehashmap doesn't
73  * contain the node.
74  *
75  * @param nodehashmap  Pointer to the nodehashmap
76  * @param node         Node to remove from the nodehashmap
77  */
78 void ir_nodehashmap_remove(ir_nodehashmap_t *nodehashmap, const ir_node *node);
79
80 /**
81  * Tests whether a nodehashmap contains a specific node
82  *
83  * @param nodehashmap   Pointer to the nodehashmap
84  * @param node          The pointer to find
85  * @returns             the associated data of the node or NULL
86  */
87 void *ir_nodehashmap_get(const ir_nodehashmap_t *nodehashmap,
88                          const ir_node *node);
89
90 #define ir_nodehashmap_get(type, self, node) ((type*)ir_nodehashmap_get((self), (node)))
91
92 /**
93  * Returns the number of pointers contained in the nodehashmap
94  *
95  * @param nodehashmap   Pointer to the nodehashmap
96  * @returns             Number of pointers contained in the nodehashmap
97  */
98 size_t ir_nodehashmap_size(const ir_nodehashmap_t *nodehashmap);
99
100 /**
101  * Initializes a nodehashmap iterator. Sets the iterator before the first
102  * element in the nodehashmap.
103  *
104  * @param iterator   Pointer to already allocated iterator memory
105  * @param nodehashmap       Pointer to the nodehashmap
106  */
107 void ir_nodehashmap_iterator_init(ir_nodehashmap_iterator_t *iterator,
108                                   const ir_nodehashmap_t *nodehashmap);
109
110 /**
111  * Advances the iterator and returns the current element or NULL if all elements
112  * in the nodehashmap have been processed.
113  * @attention It is not allowed to use nodehashmap_insert or nodehashmap_remove
114  * while iterating over a nodehashmap.
115  *
116  * @param iterator  Pointer to the nodehashmap iterator.
117  * @returns         Next element in the nodehashmap or NULL
118  */
119 ir_nodehashmap_entry_t ir_nodehashmap_iterator_next(
120                 ir_nodehashmap_iterator_t *iterator);
121
122 /**
123  * Removes the element the iterator currently points to
124  *
125  * @param nodehashmap  Pointer to the nodehashmap
126  * @param iterator     Pointer to the nodehashmap iterator.
127  */
128 void ir_nodehashmap_remove_iterator(ir_nodehashmap_t *nodehashmap,
129                                     const ir_nodehashmap_iterator_t *iterator);
130
131 #define foreach_ir_nodehashmap(nodehashmap, entry, iter)                  \
132         for (ir_nodehashmap_iterator_init(&iter, nodehashmap),                \
133                 entry = ir_nodehashmap_iterator_next(&iter);                      \
134                 entry.node != NULL; entry = ir_nodehashmap_iterator_next(&iter))
135
136 #endif