Write and read FIRM profiling information in little-endian format.
[libfirm] / ir / ir / irnodehashmap.h
1 /*
2  * Copyright (C) 1995-2008 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 nodemap. This should be preferred over a simple pset, because it
25  *            tries to guarantee deterministic behavior. (and is faster)
26  */
27 #ifndef _FIRM_IRNODEHASHMAP_H_
28 #define _FIRM_IRNODEHASHMAP_H_
29
30 #include "irnode.h"
31
32 typedef struct ir_nodehashmap_entry_t {
33         ir_node *node;
34         void    *data;
35 } ir_nodehashmap_entry_t;
36
37 #define HashSet          ir_nodehashmap_t
38 #define HashSetIterator  ir_nodehashmap_iterator_t
39 #define ValueType        ir_nodehashmap_entry_t
40 #define DO_REHASH
41 #include "hashset.h"
42 #undef DO_REHASH
43 #undef ValueType
44 #undef HashSetIterator
45 #undef HashSet
46
47 typedef struct ir_nodehashmap_t           ir_nodehashmap_t;
48 typedef struct ir_nodehashmap_iterator_t  ir_nodehashmap_iterator_t;
49
50 /**
51  * Initializes a nodehashmap with default size.
52  *
53  * @param nodehashmap      Pointer to allocated space for the nodehashmap
54  */
55 void ir_nodehashmap_init(ir_nodehashmap_t *nodehashmap);
56
57 /**
58  * Initializes a nodehashmap
59  *
60  * @param nodehashmap         Pointer to allocated space for the nodehashmap
61  * @param expected_elements   Number of elements expected in the nodehashmap
62  *                            (roughly)
63  */
64 void ir_nodehashmap_init_size(ir_nodehashmap_t *nodehashmap,
65                               size_t expected_elements);
66
67 /**
68  * Destroys a nodehashmap and frees the memory allocated for hashtable. The
69  * memory of the nodehashmap itself is not freed.
70  *
71  * @param nodehashmap   Pointer to the nodehashmap
72  */
73 void ir_nodehashmap_destroy(ir_nodehashmap_t *nodehashmap);
74
75 /**
76  * Inserts a node into a nodehashmap.
77  *
78  * @param nodehashmap  Pointer to the nodehashmap
79  * @param node         node to insert into the nodehashmap
80  * @param data         data to associate with the node
81  */
82 void ir_nodehashmap_insert(ir_nodehashmap_t *nodehashmap, ir_node *node,
83                            void *data);
84
85 /**
86  * Removes a node from a nodehashmap. Does nothing if the nodehashmap doesn't
87  * contain the node.
88  *
89  * @param nodehashmap  Pointer to the nodehashmap
90  * @param node         Node to remove from the nodehashmap
91  */
92 void ir_nodehashmap_remove(ir_nodehashmap_t *nodehashmap, const ir_node *node);
93
94 /**
95  * Tests whether a nodehashmap contains a specific node
96  *
97  * @param nodehashmap   Pointer to the nodehashmap
98  * @param node          The pointer to find
99  * @returns             the associated data of the node or NULL
100  */
101 void *ir_nodehashmap_get(const ir_nodehashmap_t *nodehashmap,
102                          const ir_node *node);
103
104 /**
105  * Returns the number of pointers contained in the nodehashmap
106  *
107  * @param nodehashmap   Pointer to the nodehashmap
108  * @returns             Number of pointers contained in the nodehashmap
109  */
110 size_t ir_nodehashmap_size(const ir_nodehashmap_t *nodehashmap);
111
112 /**
113  * Initializes a nodehashmap iterator. Sets the iterator before the first
114  * element in the nodehashmap.
115  *
116  * @param iterator   Pointer to already allocated iterator memory
117  * @param nodehashmap       Pointer to the nodehashmap
118  */
119 void ir_nodehashmap_iterator_init(ir_nodehashmap_iterator_t *iterator,
120                                   const ir_nodehashmap_t *nodehashmap);
121
122 /**
123  * Advances the iterator and returns the current element or NULL if all elements
124  * in the nodehashmap have been processed.
125  * @attention It is not allowed to use nodehashmap_insert or nodehashmap_remove
126  * while iterating over a nodehashmap.
127  *
128  * @param iterator  Pointer to the nodehashmap iterator.
129  * @returns         Next element in the nodehashmap or NULL
130  */
131 ir_nodehashmap_entry_t ir_nodehashmap_iterator_next(
132                 ir_nodehashmap_iterator_t *iterator);
133
134 /**
135  * Removes the element the iterator currently points to
136  *
137  * @param nodehashmap  Pointer to the nodehashmap
138  * @param iterator     Pointer to the nodehashmap iterator.
139  */
140 void ir_nodehashmap_remove_iterator(ir_nodehashmap_t *nodehashmap,
141                                     const ir_nodehashmap_iterator_t *iterator);
142
143 #define foreach_ir_nodehashmap(nodehashmap, entry, iter)                  \
144         for (ir_nodehashmap_iterator_init(&iter, nodehashmap),                \
145                 entry = ir_nodehashmap_iterator_next(&iter);                      \
146                 entry.node != NULL; entry = ir_nodehashmap_iterator_next(&iter))
147
148 #endif