be_Return nodes now have an attribute telling the number of "real" return values
[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(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 #define new_nodeset(slots) new_pset(pset_default_ptr_cmp, (slots))
29
30 /**
31  * Deletes a nodeset.
32  *
33  * @param nset   the nodeset
34  *
35  * @note
36  *    This does NOT delete the elements of this node set, just it's pointers!
37  */
38 #define del_nodeset(nset) del_pset(nset)
39
40 /**
41  * Returns the number of nodes in a nodeset.
42  *
43  * @param nset   the nodeset
44  */
45 #define nodeset_count(nset) pset_count(nset)
46
47 /**
48  * Searches a node in a node set.
49  *
50  * @param nset  the pset to search in
51  * @param key   the node to search
52  *
53  * @return
54  *    the pointer of the found node in the nodeset or NULL if it was not found
55  */
56 #define nodeset_find(nset, key)  (ir_node *)pset_find((nset), (key), nodeset_hash(key))
57
58 /**
59  * Inserts a node into a pset.
60  *
61  * @param nset  the nodeset to insert in
62  * @param key   a pointer to the element to be inserted
63  *
64  * @return a pointer to the inserted element
65  *
66  * @note
67  *    It is not possible to insert an element more than once. If an element
68  *    that should be inserted is already in the set, this functions does
69  *    nothing but returning its already existing set_entry.
70  */
71 #define nodeset_insert(nset, key) (ir_node *)pset_insert((nset), (key), nodeset_hash(key))
72
73 /**
74  * Removes a node from a nodeset.
75  *
76  * @param nset  the nodeset to delete in
77  * @param key   a pointer to the element to be deleted
78  *
79  * @return
80  *    the pointer to the removed element
81  *
82  * @remark
83  *    The current implementation did not allow to remove non-existing elements.
84  *    @@@ so, does it do now?
85  *    Further, it is allowed to remove elements during an iteration
86  *    including the current one.
87  */
88 #define nodeset_remove(nset, key)  (ir_node *)pset_remove((nset), (key), nodeset_hash(key))
89
90 /**
91  * Returns the first node of a nodeset.
92  *
93  * @param nset  the nodeset to iterate
94  *
95  * @return a node or NULL if the set is empty
96  */
97 #define nodeset_first(nset)  (ir_node *)pset_first(nset)
98
99 /**
100  * Returns the next node of a nodeset.
101  *
102  * @param nset  the nodeset to iterate
103  *
104  * @return a node or NULL if the iteration is finished
105  */
106 #define nodeset_next(nset)  (ir_node *)pset_next(nset)
107
108 /**
109  * Breaks the iteration of a set. Must be called before
110  * the next nodeset_first() call if the iteration was NOT
111  * finished.
112  *
113  * @param nset  the nodeset
114  */
115 #define nodeset_break(nset)  pset_break(nset)
116
117 #endif /* _BENODESETS_H */