Add is_Conv().
[libfirm] / ir / ir / irnodeset.h
1 /*
2  * Copyright (C) 1995-2007 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  * @author    Matthias Braun
23  * @date      30.03.2007
24  * @brief     A nodeset. This should be prefered over a simple pset, because it
25  *            tries to guarantee deterministic behavior. (and is faster)
26  * @version   $Id$
27  * @note      Actually the bits to make the behaviour deterministic are not
28  *            implemented yet...
29  */
30 #ifndef _FIRM_IRNODESET_H_
31 #define _FIRM_IRNODESET_H_
32
33 #include "irnode.h"
34 #include "xmalloc.h"
35
36 #define HashSet          ir_nodeset_t
37 #define HashSetIterator  ir_nodeset_iterator_t
38 #define ValueType        ir_node*
39 #define DO_REHASH
40 #include "hashset.h"
41 #undef DO_REHASH
42 #undef ValueType
43 #undef HashSetIterator
44 #undef HashSet
45
46 /**
47  * Initializes a nodeset with default size.
48  *
49  * @param nodeset      Pointer to allocated space for the nodeset
50  */
51 void ir_nodeset_init(ir_nodeset_t *nodeset);
52
53 /**
54  * Initializes a nodeset
55  *
56  * @param nodeset             Pointer to allocated space for the nodeset
57  * @param expected_elements   Number of elements expected in the nodeset (roughly)
58  */
59 void ir_nodeset_init_size(ir_nodeset_t *nodeset, size_t expected_elements);
60
61 /**
62  * Destroys a nodeset and frees the memory allocated for hashtable. The memory of
63  * the nodeset itself is not freed.
64  *
65  * @param nodeset   Pointer to the nodeset
66  */
67 void ir_nodeset_destroy(ir_nodeset_t *nodeset);
68
69 /**
70  * Allocates memory for a nodeset and initializes the set.
71  *
72  * @param expected_elements   Number of elements expected in the nodeset (roughly)
73  * @return The initialized nodeset
74  */
75 static INLINE ir_nodeset_t *ir_nodeset_new(size_t expected_elements) {
76         ir_nodeset_t *res = xmalloc(sizeof(*res));
77         ir_nodeset_init_size(res, expected_elements);
78         return res;
79 }
80
81 /**
82  * Destroys a nodeset and frees the memory of the nodeset itself.
83  */
84 static INLINE void ir_nodeset_del(ir_nodeset_t *nodeset) {
85         ir_nodeset_destroy(nodeset);
86         xfree(nodeset);
87 }
88
89 /**
90  * Inserts a node into a nodeset.
91  *
92  * @param nodeset   Pointer to the nodeset
93  * @param node      node to insert into the nodeset
94  * @returns         1 if the element has been inserted,
95  *                  0 if it was already there
96  */
97 int ir_nodeset_insert(ir_nodeset_t *nodeset, ir_node *node);
98
99 /**
100  * Removes a node from a nodeset. Does nothing if the nodeset doesn't contain
101  * the node.
102  *
103  * @param nodeset  Pointer to the nodeset
104  * @param node     Node to remove from the nodeset
105  */
106 void ir_nodeset_remove(ir_nodeset_t *nodeset, const ir_node *node);
107
108 /**
109  * Tests whether a nodeset contains a specific node
110  *
111  * @param nodeset   Pointer to the nodeset
112  * @param node      The pointer to find
113  * @returns         1 if nodeset contains the node, 0 else
114  */
115 int ir_nodeset_contains(const ir_nodeset_t *nodeset, const ir_node *node);
116
117 /**
118  * Returns the number of pointers contained in the nodeset
119  *
120  * @param nodeset   Pointer to the nodeset
121  * @returns       Number of pointers contained in the nodeset
122  */
123 size_t ir_nodeset_size(const ir_nodeset_t *nodeset);
124
125 /**
126  * Initializes a nodeset iterator. Sets the iterator before the first element in
127  * the nodeset.
128  *
129  * @param iterator   Pointer to already allocated iterator memory
130  * @param nodeset       Pointer to the nodeset
131  */
132 void ir_nodeset_iterator_init(ir_nodeset_iterator_t *iterator,
133                               const ir_nodeset_t *nodeset);
134
135 /**
136  * Advances the iterator and returns the current element or NULL if all elements
137  * in the nodeset have been processed.
138  * @attention It is not allowed to use nodeset_insert or nodeset_remove while
139  *            iterating over a nodeset.
140  *
141  * @param iterator  Pointer to the nodeset iterator.
142  * @returns         Next element in the nodeset or NULL
143  */
144 ir_node *ir_nodeset_iterator_next(ir_nodeset_iterator_t *iterator);
145
146 /**
147  * Removes the element the iterator currently points to
148  *
149  * @param nodeset   Pointer to the nodeset
150  * @param iterator  Pointer to the nodeset iterator.
151  */
152 void ir_nodeset_remove_iterator(ir_nodeset_t *nodeset,
153                                 const ir_nodeset_iterator_t *iterator);
154
155 #define foreach_ir_nodeset(nodeset, irn, iter) \
156         for(ir_nodeset_iterator_init(&iter, nodeset), \
157         irn = ir_nodeset_iterator_next(&iter);    \
158                 irn != NULL; irn = ir_nodeset_iterator_next(&iter))
159
160 #endif