2 * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
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.
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.
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
22 * @brief A lightweight wrapper around pset to store IR nodes.
23 * @author Michael Beck
26 * In some algorithms we want a more deterministic behavior
27 * which the pset_ptr did not guarantee due to it's hash function
29 #ifndef FIRM_BE_BENODESETS_H
30 #define FIRM_BE_BENODESETS_H
35 typedef struct pset nodeset;
38 * Calculates a hash value for a node.
40 unsigned nodeset_hash(const ir_node *n);
43 * Creates a new nodeset.
45 * @param slots Initial number of collision chains. I.e., #slots
46 * different keys can be hashed without collisions.
51 static INLINE nodeset *new_nodeset(int slots)
53 return new_pset(pset_default_ptr_cmp, slots);
57 * Define some convenience macros.
59 #define new_nodeset_default() new_nodeset(64)
64 * @param nset the nodeset
67 * This does NOT delete the elements of this node set, just it's pointers!
69 static INLINE void del_nodeset(nodeset *nset)
75 * Returns the number of nodes in a nodeset.
77 * @param nset the nodeset
79 static INLINE int nodeset_count(nodeset *nset)
81 return pset_count(nset);
85 * Searches a node in a node set.
87 * @param nset the pset to search in
88 * @param key the node to search
91 * the pointer of the found node in the nodeset or NULL if it was not found
93 static INLINE ir_node *nodeset_find(nodeset *nset, ir_node *key)
95 return (ir_node *) pset_find(nset, key, nodeset_hash(key));
99 * Inserts a node into a pset.
101 * @param nset the nodeset to insert in
102 * @param key a pointer to the element to be inserted
104 * @return a pointer to the inserted element
107 * It is not possible to insert an element more than once. If an element
108 * that should be inserted is already in the set, this functions does
109 * nothing but returning its already existing set_entry.
111 static INLINE ir_node *nodeset_insert(nodeset *nset, ir_node *key)
113 return (ir_node *) pset_insert(nset, key, nodeset_hash(key));
117 * Removes a node from a nodeset.
119 * @param nset the nodeset to delete in
120 * @param key a pointer to the element to be deleted
123 * the pointer to the removed element
126 * The current implementation did not allow to remove non-existing elements.
127 * @@@ so, does it do now?
128 * Further, it is allowed to remove elements during an iteration
129 * including the current one.
131 static INLINE ir_node *nodeset_remove(nodeset *nset, ir_node *key)
133 return (ir_node *) pset_remove(nset, key, nodeset_hash(key));
137 * Returns the first node of a nodeset.
139 * @param nset the nodeset to iterate
141 * @return a node or NULL if the set is empty
143 static INLINE ir_node *nodeset_first(nodeset *nset)
145 return (ir_node *) pset_first(nset);
149 * Returns the next node of a nodeset.
151 * @param nset the nodeset to iterate
153 * @return a node or NULL if the iteration is finished
155 static INLINE ir_node *nodeset_next(nodeset *nset)
157 return (ir_node *) pset_next(nset);
161 * Breaks the iteration of a set. Must be called before
162 * the next nodeset_first() call if the iteration was NOT
165 * @param nset the nodeset
167 static INLINE void nodeset_break(nodeset *nset)
173 * Iterate over a node set.
175 * @param nset the nodeset
176 * @param irn the iterator node
178 #define foreach_nodeset(nset, irn) for (irn = nodeset_first(nset); irn; irn = nodeset_next(nset))
180 #endif /* FIRM_BE_BENODESETS_H */