assert that in and out entities of memperms have the same size, we produce such buggy...
[libfirm] / ir / be / benodesets.h
1 /**
2  * A lightweight wrapper around pset to store IR nodes.
3  * In some algorithms we want a more deterministic behavior
4  * which the pset_ptr did not guarantee due to it's hash function
5  */
6 #ifndef _BENODESETS_H
7 #define _BENODESETS_H
8
9 #include "firm_types.h"
10 #include "pset.h"
11
12 typedef struct pset nodeset;
13
14 /**
15  * Calculates a hash value for a node.
16  */
17 unsigned nodeset_hash(const ir_node *n);
18
19 /**
20  * Creates a new nodeset.
21  *
22  * @param slots   Initial number of collision chains.  I.e., #slots
23  *                different keys can be hashed without collisions.
24  *
25  * @returns
26  *    created nodeset
27  */
28 static INLINE nodeset *new_nodeset(int slots)
29 {
30         return new_pset(pset_default_ptr_cmp, slots);
31 }
32
33 /*
34  * Define some convenience macros.
35  */
36 #define new_nodeset_default()    new_nodeset(64)
37
38 /**
39  * Deletes a nodeset.
40  *
41  * @param nset   the nodeset
42  *
43  * @note
44  *    This does NOT delete the elements of this node set, just it's pointers!
45  */
46 static INLINE void del_nodeset(nodeset *nset)
47 {
48         del_pset(nset);
49 }
50
51 /**
52  * Returns the number of nodes in a nodeset.
53  *
54  * @param nset   the nodeset
55  */
56 static INLINE int nodeset_count(nodeset *nset)
57 {
58         return pset_count(nset);
59 }
60
61 /**
62  * Searches a node in a node set.
63  *
64  * @param nset  the pset to search in
65  * @param key   the node to search
66  *
67  * @return
68  *    the pointer of the found node in the nodeset or NULL if it was not found
69  */
70 static INLINE ir_node *nodeset_find(nodeset *nset, ir_node *key)
71 {
72         return (ir_node *) pset_find(nset, key, nodeset_hash(key));
73 }
74
75 /**
76  * Inserts a node into a pset.
77  *
78  * @param nset  the nodeset to insert in
79  * @param key   a pointer to the element to be inserted
80  *
81  * @return a pointer to the inserted element
82  *
83  * @note
84  *    It is not possible to insert an element more than once. If an element
85  *    that should be inserted is already in the set, this functions does
86  *    nothing but returning its already existing set_entry.
87  */
88 static INLINE ir_node *nodeset_insert(nodeset *nset, ir_node *key)
89 {
90         return (ir_node *) pset_insert(nset, key, nodeset_hash(key));
91 }
92
93 /**
94  * Removes a node from a nodeset.
95  *
96  * @param nset  the nodeset to delete in
97  * @param key   a pointer to the element to be deleted
98  *
99  * @return
100  *    the pointer to the removed element
101  *
102  * @remark
103  *    The current implementation did not allow to remove non-existing elements.
104  *    @@@ so, does it do now?
105  *    Further, it is allowed to remove elements during an iteration
106  *    including the current one.
107  */
108 static INLINE ir_node *nodeset_remove(nodeset *nset, ir_node *key)
109 {
110         return (ir_node *) pset_remove(nset, key, nodeset_hash(key));
111 }
112
113 /**
114  * Returns the first node of a nodeset.
115  *
116  * @param nset  the nodeset to iterate
117  *
118  * @return a node or NULL if the set is empty
119  */
120 static INLINE ir_node *nodeset_first(nodeset *nset)
121 {
122         return (ir_node *) pset_first(nset);
123 }
124
125 /**
126  * Returns the next node of a nodeset.
127  *
128  * @param nset  the nodeset to iterate
129  *
130  * @return a node or NULL if the iteration is finished
131  */
132 static INLINE ir_node *nodeset_next(nodeset *nset)
133 {
134         return (ir_node *) pset_next(nset);
135 }
136
137 /**
138  * Breaks the iteration of a set. Must be called before
139  * the next nodeset_first() call if the iteration was NOT
140  * finished.
141  *
142  * @param nset  the nodeset
143  */
144 static INLINE void nodeset_break(nodeset *nset)
145 {
146         pset_break(nset);
147 }
148
149 /**
150  * Iterate over a node set.
151  *
152  * @param nset  the nodeset
153  * @param irn   the iterator node
154  */
155 #define foreach_nodeset(nset, irn)      for (irn = nodeset_first(nset); irn; irn = nodeset_next(nset))
156
157 #endif /* _BENODESETS_H */