* gcc.dg/vect/pr24225.c: Add cleanup-coverage-files.
[official-gcc.git] / gcc / sbitmap.h
blob21c697451e2d482bd366dc84c73b17775a17651d
1 /* Simple bitmaps.
2 Copyright (C) 1999, 2000, 2002, 2003, 2004 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301, USA. */
21 #ifndef GCC_SBITMAP_H
22 #define GCC_SBITMAP_H
24 /* It's not clear yet whether using bitmap.[ch] will be a win.
25 It should be straightforward to convert so for now we keep things simple
26 while more important issues are dealt with. */
28 #define SBITMAP_ELT_BITS ((unsigned) HOST_BITS_PER_WIDEST_FAST_INT)
29 #define SBITMAP_ELT_TYPE unsigned HOST_WIDEST_FAST_INT
31 typedef struct simple_bitmap_def
33 unsigned int n_bits; /* Number of bits. */
34 unsigned int size; /* Size in elements. */
35 unsigned int bytes; /* Size in bytes. */
36 SBITMAP_ELT_TYPE elms[1]; /* The elements. */
37 } *sbitmap;
39 typedef SBITMAP_ELT_TYPE *sbitmap_ptr;
41 /* Return the set size needed for N elements. */
42 #define SBITMAP_SET_SIZE(N) (((N) + SBITMAP_ELT_BITS - 1) / SBITMAP_ELT_BITS)
44 /* Set bit number bitno in the bitmap. */
45 #define SET_BIT(BITMAP, BITNO) \
46 ((BITMAP)->elms [(BITNO) / SBITMAP_ELT_BITS] \
47 |= (SBITMAP_ELT_TYPE) 1 << (BITNO) % SBITMAP_ELT_BITS)
49 /* Test if bit number bitno in the bitmap is set. */
50 #define TEST_BIT(BITMAP, BITNO) \
51 ((BITMAP)->elms [(BITNO) / SBITMAP_ELT_BITS] >> (BITNO) % SBITMAP_ELT_BITS & 1)
53 /* Reset bit number bitno in the bitmap. */
54 #define RESET_BIT(BITMAP, BITNO) \
55 ((BITMAP)->elms [(BITNO) / SBITMAP_ELT_BITS] \
56 &= ~((SBITMAP_ELT_TYPE) 1 << (BITNO) % SBITMAP_ELT_BITS))
58 /* The iterator for sbitmap. */
59 typedef struct {
60 /* The pointer to the first word of the bitmap. */
61 SBITMAP_ELT_TYPE *ptr;
63 /* The size of the bitmap. */
64 unsigned int size;
66 /* The current word index. */
67 unsigned int word_num;
69 /* The current bit index (not modulo SBITMAP_ELT_BITS). */
70 unsigned int bit_num;
72 /* The words currently visited. */
73 SBITMAP_ELT_TYPE word;
74 } sbitmap_iterator;
76 /* Initialize the iterator I with sbitmap BMP and the initial index
77 MIN. */
79 static inline void
80 sbitmap_iter_init (sbitmap_iterator *i, sbitmap bmp, unsigned int min)
82 i->word_num = min / (unsigned int) SBITMAP_ELT_BITS;
83 i->bit_num = min;
84 i->size = bmp->size;
85 i->ptr = bmp->elms;
87 if (i->word_num >= i->size)
88 i->word = 0;
89 else
90 i->word = (i->ptr[i->word_num]
91 >> (i->bit_num % (unsigned int) SBITMAP_ELT_BITS));
94 /* Return true if we have more bits to visit, in which case *N is set
95 to the index of the bit to be visited. Otherwise, return
96 false. */
98 static inline bool
99 sbitmap_iter_cond (sbitmap_iterator *i, unsigned int *n)
101 /* Skip words that are zeros. */
102 for (; i->word == 0; i->word = i->ptr[i->word_num])
104 i->word_num++;
106 /* If we have reached the end, break. */
107 if (i->word_num >= i->size)
108 return false;
110 i->bit_num = i->word_num * SBITMAP_ELT_BITS;
113 /* Skip bits that are zero. */
114 for (; (i->word & 1) == 0; i->word >>= 1)
115 i->bit_num++;
117 *n = i->bit_num;
119 return true;
122 /* Advance to the next bit. */
124 static inline void
125 sbitmap_iter_next (sbitmap_iterator *i)
127 i->word >>= 1;
128 i->bit_num++;
131 /* Loop over all elements of SBITMAP, starting with MIN. In each
132 iteration, N is set to the index of the bit being visited. ITER is
133 an instance of sbitmap_iterator used to iterate the bitmap. */
135 #define EXECUTE_IF_SET_IN_SBITMAP(SBITMAP, MIN, N, ITER) \
136 for (sbitmap_iter_init (&(ITER), (SBITMAP), (MIN)); \
137 sbitmap_iter_cond (&(ITER), &(N)); \
138 sbitmap_iter_next (&(ITER)))
140 #define EXECUTE_IF_SET_IN_SBITMAP_REV(SBITMAP, N, CODE) \
141 do { \
142 unsigned int word_num_; \
143 unsigned int bit_num_; \
144 unsigned int size_ = (SBITMAP)->size; \
145 SBITMAP_ELT_TYPE *ptr_ = (SBITMAP)->elms; \
147 for (word_num_ = size_; word_num_ > 0; word_num_--) \
149 SBITMAP_ELT_TYPE word_ = ptr_[word_num_ - 1]; \
151 if (word_ != 0) \
152 for (bit_num_ = SBITMAP_ELT_BITS; bit_num_ > 0; bit_num_--) \
154 SBITMAP_ELT_TYPE _mask = (SBITMAP_ELT_TYPE)1 << (bit_num_ - 1);\
156 if ((word_ & _mask) != 0) \
158 word_ &= ~ _mask; \
159 (N) = (word_num_ - 1) * SBITMAP_ELT_BITS + bit_num_ - 1;\
160 CODE; \
161 if (word_ == 0) \
162 break; \
166 } while (0)
168 #define sbitmap_free(MAP) free(MAP)
169 #define sbitmap_vector_free(VEC) free(VEC)
171 struct int_list;
173 extern void dump_sbitmap (FILE *, sbitmap);
174 extern void dump_sbitmap_file (FILE *, sbitmap);
175 extern void dump_sbitmap_vector (FILE *, const char *, const char *, sbitmap *,
176 int);
177 extern sbitmap sbitmap_alloc (unsigned int);
178 extern sbitmap *sbitmap_vector_alloc (unsigned int, unsigned int);
179 extern sbitmap sbitmap_resize (sbitmap, unsigned int, int);
180 extern void sbitmap_copy (sbitmap, sbitmap);
181 extern int sbitmap_equal (sbitmap, sbitmap);
182 extern void sbitmap_zero (sbitmap);
183 extern void sbitmap_ones (sbitmap);
184 extern void sbitmap_vector_zero (sbitmap *, unsigned int);
185 extern void sbitmap_vector_ones (sbitmap *, unsigned int);
187 extern void sbitmap_union_of_diff (sbitmap, sbitmap, sbitmap, sbitmap);
188 extern bool sbitmap_union_of_diff_cg (sbitmap, sbitmap, sbitmap, sbitmap);
189 extern void sbitmap_difference (sbitmap, sbitmap, sbitmap);
190 extern void sbitmap_not (sbitmap, sbitmap);
191 extern void sbitmap_a_or_b_and_c (sbitmap, sbitmap, sbitmap, sbitmap);
192 extern bool sbitmap_a_or_b_and_c_cg (sbitmap, sbitmap, sbitmap, sbitmap);
193 extern void sbitmap_a_and_b_or_c (sbitmap, sbitmap, sbitmap, sbitmap);
194 extern bool sbitmap_a_and_b_or_c_cg (sbitmap, sbitmap, sbitmap, sbitmap);
195 extern bool sbitmap_any_common_bits (sbitmap, sbitmap);
196 extern void sbitmap_a_and_b (sbitmap, sbitmap, sbitmap);
197 extern bool sbitmap_a_and_b_cg (sbitmap, sbitmap, sbitmap);
198 extern void sbitmap_a_or_b (sbitmap, sbitmap, sbitmap);
199 extern bool sbitmap_a_or_b_cg (sbitmap, sbitmap, sbitmap);
200 extern void sbitmap_a_xor_b (sbitmap, sbitmap, sbitmap);
201 extern bool sbitmap_a_xor_b_cg (sbitmap, sbitmap, sbitmap);
202 extern bool sbitmap_a_subset_b_p (sbitmap, sbitmap);
204 extern int sbitmap_first_set_bit (sbitmap);
205 extern int sbitmap_last_set_bit (sbitmap);
207 extern void sbitmap_intersect_of_predsucc (sbitmap, sbitmap *, int,
208 struct int_list **);
209 #define sbitmap_intersect_of_predecessors sbitmap_intersect_of_predsucc
210 #define sbitmap_intersect_of_successors sbitmap_intersect_of_predsucc
212 extern void sbitmap_union_of_predsucc (sbitmap, sbitmap *, int,
213 struct int_list **);
214 #define sbitmap_union_of_predecessors sbitmap_union_of_predsucc
215 #define sbitmap_union_of_successors sbitmap_union_of_predsucc
217 /* Intersection and Union of preds/succs using the new flow graph
218 structure instead of the pred/succ arrays. */
220 extern void sbitmap_intersection_of_succs (sbitmap, sbitmap *, int);
221 extern void sbitmap_intersection_of_preds (sbitmap, sbitmap *, int);
222 extern void sbitmap_union_of_succs (sbitmap, sbitmap *, int);
223 extern void sbitmap_union_of_preds (sbitmap, sbitmap *, int);
225 extern void debug_sbitmap (sbitmap);
226 extern sbitmap sbitmap_realloc (sbitmap, unsigned int);
227 #endif /* ! GCC_SBITMAP_H */