* config/sh/sh.md (*movqi_pop): New insn pattern.
[official-gcc.git] / gcc / sparseset.h
blob3554ef6b35c866b5d3c3efe0921f921e23906eb5
1 /* SparseSet implementation.
2 Copyright (C) 2007 Free Software Foundation, Inc.
3 Contributed by Peter Bergner <bergner@vnet.ibm.com>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #ifndef GCC_SPARSESET_H
22 #define GCC_SPARSESET_H
24 #include <assert.h>
26 #define SPARSESET_ELT_BITS ((unsigned) HOST_BITS_PER_WIDEST_FAST_INT)
27 #define SPARSESET_ELT_TYPE unsigned int
29 /* Data Structure used for the SparseSet representation. */
31 typedef struct sparseset_def
33 SPARSESET_ELT_TYPE *dense; /* Dense array. */
34 SPARSESET_ELT_TYPE *sparse; /* Sparse array. */
35 SPARSESET_ELT_TYPE members; /* Number of elements. */
36 SPARSESET_ELT_TYPE size; /* Maximum number of elements. */
37 SPARSESET_ELT_TYPE iter; /* Iterator index. */
38 unsigned char iter_inc; /* Iteration increment amount. */
39 bool iterating;
40 SPARSESET_ELT_TYPE elms[2]; /* Combined dense and sparse arrays. */
41 } *sparseset;
43 #define sparseset_free(MAP) free(MAP)
44 extern sparseset sparseset_alloc (SPARSESET_ELT_TYPE n_elms);
45 extern void sparseset_clear_bit (sparseset, SPARSESET_ELT_TYPE);
46 extern void sparseset_copy (sparseset, sparseset);
47 extern void sparseset_and (sparseset, sparseset, sparseset);
48 extern void sparseset_and_compl (sparseset, sparseset, sparseset);
49 extern void sparseset_ior (sparseset, sparseset, sparseset);
50 extern bool sparseset_equal_p (sparseset, sparseset);
52 /* Operation: S = {}
53 Clear the set of all elements. */
55 static inline void
56 sparseset_clear (sparseset s)
58 s->members = 0;
59 s->iterating = false;
62 /* Return the number of elements currently in the set. */
64 static inline SPARSESET_ELT_TYPE
65 sparseset_cardinality (sparseset s)
67 return s->members;
70 /* Return the maximum number of elements this set can hold. */
72 static inline SPARSESET_ELT_TYPE
73 sparseset_size (sparseset s)
75 return s->size;
78 /* Return true if e is a member of the set S, otherwise return false. */
80 static inline bool
81 sparseset_bit_p (sparseset s, SPARSESET_ELT_TYPE e)
83 SPARSESET_ELT_TYPE idx;
85 gcc_assert (e < s->size);
87 idx = s->sparse[e];
89 return idx < s->members && s->dense[idx] == e;
92 /* Low level insertion routine not meant for use outside of sparseset.[ch].
93 Assumes E is valid and not already a member of the set S. */
95 static inline void
96 sparseset_insert_bit (sparseset s, SPARSESET_ELT_TYPE e, SPARSESET_ELT_TYPE idx)
98 s->sparse[e] = idx;
99 s->dense[idx] = e;
102 /* Operation: S = S + {e}
103 Insert E into the set S, if it isn't already a member. */
105 static inline void
106 sparseset_set_bit (sparseset s, SPARSESET_ELT_TYPE e)
108 if (!sparseset_bit_p (s, e))
109 sparseset_insert_bit (s, e, s->members++);
112 /* Return and remove an arbitrary element from the set S. */
114 static inline SPARSESET_ELT_TYPE
115 sparseset_pop (sparseset s)
117 SPARSESET_ELT_TYPE mem = s->members;
119 gcc_assert (mem != 0);
121 s->members = mem - 1;
122 return s->dense[mem];
125 static inline void
126 sparseset_iter_init (sparseset s)
128 s->iter = 0;
129 s->iter_inc = 1;
130 s->iterating = true;
133 static inline bool
134 sparseset_iter_p (sparseset s)
136 if (s->iterating && s->iter < s->members)
137 return true;
138 else
139 return s->iterating = false;
142 static inline SPARSESET_ELT_TYPE
143 sparseset_iter_elm (sparseset s)
145 return s->dense[s->iter];
148 static inline void
149 sparseset_iter_next (sparseset s)
151 s->iter += s->iter_inc;
152 s->iter_inc = 1;
155 #define EXECUTE_IF_SET_IN_SPARSESET(SPARSESET, ITER) \
156 for (sparseset_iter_init (SPARSESET); \
157 sparseset_iter_p (SPARSESET) \
158 && (((ITER) = sparseset_iter_elm (SPARSESET)) || 1); \
159 sparseset_iter_next (SPARSESET))
161 #endif /* GCC_SPARSESET_H */