]>
Commit | Line | Data |
---|---|---|
096ab9ea | 1 | /* Functions to support general ended bitmaps. |
f30278e8 | 2 | Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 |
3ef42a0c | 3 | Free Software Foundation, Inc. |
096ab9ea | 4 | |
1322177d | 5 | This file is part of GCC. |
096ab9ea | 6 | |
1322177d LB |
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 2, or (at your option) any later | |
10 | version. | |
096ab9ea | 11 | |
1322177d LB |
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. | |
096ab9ea RK |
16 | |
17 | You should have received a copy of the GNU General Public License | |
1322177d LB |
18 | along with GCC; see the file COPYING. If not, write to the Free |
19 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
20 | 02111-1307, USA. */ | |
096ab9ea | 21 | |
88657302 | 22 | #ifndef GCC_BITMAP_H |
ca7fd9cd | 23 | #define GCC_BITMAP_H |
a05924f9 | 24 | |
72e42e26 SB |
25 | /* Fundamental storage type for bitmap. */ |
26 | ||
72e42e26 | 27 | typedef unsigned long BITMAP_WORD; |
65a6f342 NS |
28 | /* BITMAP_WORD_BITS needs to be unsigned, but cannot contain casts as |
29 | it is used in preprocessor directives -- hence the 1u. */ | |
30 | #define BITMAP_WORD_BITS (CHAR_BIT * SIZEOF_LONG * 1u) | |
72e42e26 | 31 | |
096ab9ea RK |
32 | /* Number of words to use for each element in the linked list. */ |
33 | ||
34 | #ifndef BITMAP_ELEMENT_WORDS | |
65a6f342 | 35 | #define BITMAP_ELEMENT_WORDS ((128 + BITMAP_WORD_BITS - 1) / BITMAP_WORD_BITS) |
096ab9ea RK |
36 | #endif |
37 | ||
65a6f342 | 38 | /* Number of bits in each actual element of a bitmap. */ |
096ab9ea | 39 | |
65a6f342 | 40 | #define BITMAP_ELEMENT_ALL_BITS (BITMAP_ELEMENT_WORDS * BITMAP_WORD_BITS) |
096ab9ea RK |
41 | |
42 | /* Bitmap set element. We use a linked list to hold only the bits that | |
43 | are set. This allows for use to grow the bitset dynamically without | |
44 | having to realloc and copy a giant bit array. The `prev' field is | |
45 | undefined for an element on the free list. */ | |
46 | ||
e2500fed | 47 | typedef struct bitmap_element_def GTY(()) |
096ab9ea | 48 | { |
eebedaa5 KH |
49 | struct bitmap_element_def *next; /* Next element. */ |
50 | struct bitmap_element_def *prev; /* Previous element. */ | |
51 | unsigned int indx; /* regno/BITMAP_ELEMENT_ALL_BITS. */ | |
72e42e26 | 52 | BITMAP_WORD bits[BITMAP_ELEMENT_WORDS]; /* Bits that are set. */ |
096ab9ea RK |
53 | } bitmap_element; |
54 | ||
55 | /* Head of bitmap linked list. */ | |
e2500fed | 56 | typedef struct bitmap_head_def GTY(()) { |
eebedaa5 KH |
57 | bitmap_element *first; /* First element in linked list. */ |
58 | bitmap_element *current; /* Last element looked at. */ | |
59 | unsigned int indx; /* Index of last element looked at. */ | |
e2500fed GK |
60 | int using_obstack; /* Are we using an obstack or ggc for |
61 | allocation? */ | |
62 | } bitmap_head; | |
63 | typedef struct bitmap_head_def *bitmap; | |
096ab9ea | 64 | |
096ab9ea | 65 | /* Global data */ |
ae0ed63a | 66 | extern bitmap_element bitmap_zero_bits; /* Zero bitmap element */ |
096ab9ea RK |
67 | |
68 | /* Clear a bitmap by freeing up the linked list. */ | |
4682ae04 | 69 | extern void bitmap_clear (bitmap); |
096ab9ea | 70 | |
eebedaa5 | 71 | /* Copy a bitmap to another bitmap. */ |
4682ae04 | 72 | extern void bitmap_copy (bitmap, bitmap); |
096ab9ea | 73 | |
8229306b | 74 | /* True if two bitmaps are identical. */ |
55994078 | 75 | extern bool bitmap_equal_p (bitmap, bitmap); |
8229306b | 76 | |
55994078 NS |
77 | /* True if the bitmaps intersect (their AND is non-empty). */ |
78 | extern bool bitmap_intersect_p (bitmap, bitmap); | |
79 | ||
80 | /* True if the complement of the second intersects the first (their | |
81 | AND_COMPL is non-empty). */ | |
82 | extern bool bitmap_intersect_compl_p (bitmap, bitmap); | |
83 | ||
84 | /* True if MAP is an empty bitmap. */ | |
eb59b8de NS |
85 | #define bitmap_empty_p(MAP) (!(MAP)->first) |
86 | ||
88c4f655 NS |
87 | /* Boolean operations on bitmaps. The _into variants are two operand |
88 | versions that modify the first source operand. The other variants | |
89 | are three operand versions that to not destroy the source bitmaps. | |
90 | The operations supported are &, & ~, |, ^. */ | |
91 | extern void bitmap_and (bitmap, bitmap, bitmap); | |
92 | extern void bitmap_and_into (bitmap, bitmap); | |
93 | extern void bitmap_and_compl (bitmap, bitmap, bitmap); | |
94 | extern void bitmap_and_compl_into (bitmap, bitmap); | |
95 | extern bool bitmap_ior (bitmap, bitmap, bitmap); | |
96 | extern bool bitmap_ior_into (bitmap, bitmap); | |
97 | extern void bitmap_xor (bitmap, bitmap, bitmap); | |
98 | extern void bitmap_xor_into (bitmap, bitmap); | |
99 | ||
100 | /* DST = A | (B & ~C). Return true if DST changes. */ | |
101 | extern bool bitmap_ior_and_compl (bitmap DST, bitmap A, bitmap B, bitmap C); | |
102 | /* A |= (B & ~C). Return true if A changes. */ | |
103 | extern bool bitmap_ior_and_compl_into (bitmap DST, bitmap B, bitmap C); | |
096ab9ea RK |
104 | |
105 | /* Clear a single register in a register set. */ | |
4682ae04 | 106 | extern void bitmap_clear_bit (bitmap, int); |
096ab9ea RK |
107 | |
108 | /* Set a single register in a register set. */ | |
4682ae04 | 109 | extern void bitmap_set_bit (bitmap, int); |
096ab9ea RK |
110 | |
111 | /* Return true if a register is set in a register set. */ | |
4682ae04 | 112 | extern int bitmap_bit_p (bitmap, int); |
096ab9ea RK |
113 | |
114 | /* Debug functions to print a bitmap linked list. */ | |
4682ae04 AJ |
115 | extern void debug_bitmap (bitmap); |
116 | extern void debug_bitmap_file (FILE *, bitmap); | |
096ab9ea | 117 | |
f9da5064 | 118 | /* Print a bitmap. */ |
4682ae04 | 119 | extern void bitmap_print (FILE *, bitmap, const char *, const char *); |
22fa5b8a | 120 | |
e2500fed GK |
121 | /* Initialize a bitmap header. If HEAD is NULL, a new header will be |
122 | allocated. USING_OBSTACK indicates how elements should be allocated. */ | |
4682ae04 | 123 | extern bitmap bitmap_initialize (bitmap head, int using_obstack); |
096ab9ea | 124 | |
e2500fed | 125 | /* Release all memory used by the bitmap obstack. */ |
4682ae04 | 126 | extern void bitmap_release_memory (void); |
096ab9ea | 127 | |
ea193996 DB |
128 | /* A few compatibility/functions macros for compatibility with sbitmaps */ |
129 | #define dump_bitmap(file, bitmap) bitmap_print (file, bitmap, "", "\n") | |
130 | #define bitmap_zero(a) bitmap_clear (a) | |
65a6f342 | 131 | extern unsigned bitmap_first_set_bit (bitmap); |
ea193996 | 132 | |
096ab9ea RK |
133 | /* Allocate a bitmap with oballoc. */ |
134 | #define BITMAP_OBSTACK_ALLOC(OBSTACK) \ | |
703ad42b | 135 | bitmap_initialize (obstack_alloc (OBSTACK, sizeof (bitmap_head)), 1) |
e2500fed GK |
136 | |
137 | /* Allocate a bitmap with ggc_alloc. */ | |
138 | #define BITMAP_GGC_ALLOC() \ | |
139 | bitmap_initialize (NULL, 0) | |
ca7fd9cd | 140 | |
67289ea6 MM |
141 | /* Allocate a bitmap with xmalloc. */ |
142 | #define BITMAP_XMALLOC() \ | |
703ad42b | 143 | bitmap_initialize (xmalloc (sizeof (bitmap_head)), 1) |
67289ea6 | 144 | |
096ab9ea | 145 | /* Do any cleanup needed on a bitmap when it is no longer used. */ |
e7749837 RH |
146 | #define BITMAP_FREE(BITMAP) \ |
147 | do { \ | |
148 | if (BITMAP) \ | |
149 | { \ | |
150 | bitmap_clear (BITMAP); \ | |
151 | (BITMAP) = 0; \ | |
152 | } \ | |
153 | } while (0) | |
154 | ||
155 | /* Do any cleanup needed on an xmalloced bitmap when it is no longer used. */ | |
156 | #define BITMAP_XFREE(BITMAP) \ | |
157 | do { \ | |
158 | if (BITMAP) \ | |
159 | { \ | |
160 | bitmap_clear (BITMAP); \ | |
161 | free (BITMAP); \ | |
162 | (BITMAP) = 0; \ | |
163 | } \ | |
096ab9ea RK |
164 | } while (0) |
165 | ||
166 | /* Do any one-time initializations needed for bitmaps. */ | |
167 | #define BITMAP_INIT_ONCE() | |
168 | ||
87c476a2 | 169 | /* Iterator for bitmaps. */ |
096ab9ea | 170 | |
87c476a2 ZD |
171 | typedef struct |
172 | { | |
e90ea8cb NS |
173 | /* Pointer to the current bitmap element. */ |
174 | bitmap_element *elt1; | |
175 | ||
176 | /* Pointer to 2nd bitmap element when two are involved. */ | |
177 | bitmap_element *elt2; | |
178 | ||
179 | /* Word within the current element. */ | |
180 | unsigned word_no; | |
181 | ||
87c476a2 ZD |
182 | /* Contents of the actually processed word. When finding next bit |
183 | it is shifted right, so that the actual bit is always the least | |
184 | significant bit of ACTUAL. */ | |
e90ea8cb | 185 | BITMAP_WORD bits; |
87c476a2 ZD |
186 | } bitmap_iterator; |
187 | ||
e90ea8cb NS |
188 | /* Initialize a single bitmap iterator. START_BIT is the first bit to |
189 | iterate from. */ | |
87c476a2 | 190 | |
e90ea8cb NS |
191 | static inline void |
192 | bmp_iter_set_init (bitmap_iterator *bi, bitmap map, | |
193 | unsigned start_bit, unsigned *bit_no) | |
87c476a2 | 194 | { |
e90ea8cb NS |
195 | bi->elt1 = map->first; |
196 | bi->elt2 = NULL; | |
197 | ||
198 | /* Advance elt1 until it is not before the block containing start_bit. */ | |
199 | while (1) | |
87c476a2 | 200 | { |
e90ea8cb NS |
201 | if (!bi->elt1) |
202 | { | |
203 | bi->elt1 = &bitmap_zero_bits; | |
204 | break; | |
205 | } | |
206 | ||
207 | if (bi->elt1->indx >= start_bit / BITMAP_ELEMENT_ALL_BITS) | |
208 | break; | |
209 | bi->elt1 = bi->elt1->next; | |
87c476a2 ZD |
210 | } |
211 | ||
e90ea8cb NS |
212 | /* We might have gone past the start bit, so reinitialize it. */ |
213 | if (bi->elt1->indx != start_bit / BITMAP_ELEMENT_ALL_BITS) | |
214 | start_bit = bi->elt1->indx * BITMAP_ELEMENT_ALL_BITS; | |
215 | ||
216 | /* Initialize for what is now start_bit. */ | |
217 | bi->word_no = start_bit / BITMAP_WORD_BITS % BITMAP_ELEMENT_WORDS; | |
218 | bi->bits = bi->elt1->bits[bi->word_no]; | |
219 | bi->bits >>= start_bit % BITMAP_WORD_BITS; | |
220 | ||
221 | /* If this word is zero, we must make sure we're not pointing at the | |
222 | first bit, otherwise our incrementing to the next word boundary | |
223 | will fail. It won't matter if this increment moves us into the | |
224 | next word. */ | |
225 | start_bit += !bi->bits; | |
226 | ||
227 | *bit_no = start_bit; | |
87c476a2 ZD |
228 | } |
229 | ||
e90ea8cb NS |
230 | /* Initialize an iterator to iterate over the intersection of two |
231 | bitmaps. START_BIT is the bit to commence from. */ | |
87c476a2 | 232 | |
e90ea8cb NS |
233 | static inline void |
234 | bmp_iter_and_init (bitmap_iterator *bi, bitmap map1, bitmap map2, | |
235 | unsigned start_bit, unsigned *bit_no) | |
87c476a2 | 236 | { |
e90ea8cb NS |
237 | bi->elt1 = map1->first; |
238 | bi->elt2 = map2->first; | |
87c476a2 | 239 | |
e90ea8cb NS |
240 | /* Advance elt1 until it is not before the block containing |
241 | start_bit. */ | |
87c476a2 ZD |
242 | while (1) |
243 | { | |
e90ea8cb | 244 | if (!bi->elt1) |
87c476a2 | 245 | { |
e90ea8cb NS |
246 | bi->elt2 = NULL; |
247 | break; | |
87c476a2 | 248 | } |
e90ea8cb NS |
249 | |
250 | if (bi->elt1->indx >= start_bit / BITMAP_ELEMENT_ALL_BITS) | |
251 | break; | |
252 | bi->elt1 = bi->elt1->next; | |
87c476a2 | 253 | } |
e90ea8cb NS |
254 | |
255 | /* Advance elt2 until it is not before elt1. */ | |
256 | while (1) | |
87c476a2 | 257 | { |
e90ea8cb NS |
258 | if (!bi->elt2) |
259 | { | |
260 | bi->elt1 = bi->elt2 = &bitmap_zero_bits; | |
261 | break; | |
262 | } | |
263 | ||
264 | if (bi->elt2->indx >= bi->elt1->indx) | |
265 | break; | |
266 | bi->elt2 = bi->elt2->next; | |
87c476a2 ZD |
267 | } |
268 | ||
e90ea8cb NS |
269 | /* If we're at the same index, then we have some intersecting bits. */ |
270 | if (bi->elt1->indx == bi->elt2->indx) | |
87c476a2 | 271 | { |
e90ea8cb NS |
272 | /* We might have advanced beyond the start_bit, so reinitialize |
273 | for that. */ | |
274 | if (bi->elt1->indx != start_bit / BITMAP_ELEMENT_ALL_BITS) | |
275 | start_bit = bi->elt1->indx * BITMAP_ELEMENT_ALL_BITS; | |
276 | ||
277 | bi->word_no = start_bit / BITMAP_WORD_BITS % BITMAP_ELEMENT_WORDS; | |
278 | bi->bits = bi->elt1->bits[bi->word_no] & bi->elt2->bits[bi->word_no]; | |
279 | bi->bits >>= start_bit % BITMAP_WORD_BITS; | |
87c476a2 ZD |
280 | } |
281 | else | |
282 | { | |
e90ea8cb NS |
283 | /* Otherwise we must immediately advance elt1, so initialize for |
284 | that. */ | |
285 | bi->word_no = BITMAP_ELEMENT_WORDS - 1; | |
286 | bi->bits = 0; | |
87c476a2 | 287 | } |
e90ea8cb NS |
288 | |
289 | /* If this word is zero, we must make sure we're not pointing at the | |
290 | first bit, otherwise our incrementing to the next word boundary | |
291 | will fail. It won't matter if this increment moves us into the | |
292 | next word. */ | |
293 | start_bit += !bi->bits; | |
294 | ||
295 | *bit_no = start_bit; | |
87c476a2 ZD |
296 | } |
297 | ||
e90ea8cb NS |
298 | /* Initialize an iterator to iterate over the bits in MAP1 & ~MAP2. |
299 | */ | |
87c476a2 | 300 | |
e90ea8cb NS |
301 | static inline void |
302 | bmp_iter_and_compl_init (bitmap_iterator *bi, bitmap map1, bitmap map2, | |
303 | unsigned start_bit, unsigned *bit_no) | |
87c476a2 | 304 | { |
e90ea8cb NS |
305 | bi->elt1 = map1->first; |
306 | bi->elt2 = map2->first; | |
87c476a2 | 307 | |
e90ea8cb | 308 | /* Advance elt1 until it is not before the block containing start_bit. */ |
87c476a2 ZD |
309 | while (1) |
310 | { | |
e90ea8cb | 311 | if (!bi->elt1) |
87c476a2 | 312 | { |
e90ea8cb NS |
313 | bi->elt1 = &bitmap_zero_bits; |
314 | break; | |
87c476a2 | 315 | } |
e90ea8cb NS |
316 | |
317 | if (bi->elt1->indx >= start_bit / BITMAP_ELEMENT_ALL_BITS) | |
318 | break; | |
319 | bi->elt1 = bi->elt1->next; | |
87c476a2 | 320 | } |
e90ea8cb NS |
321 | |
322 | /* Advance elt2 until it is not before elt1. */ | |
323 | while (bi->elt2 && bi->elt2->indx < bi->elt1->indx) | |
324 | bi->elt2 = bi->elt2->next; | |
325 | ||
326 | /* We might have advanced beyond the start_bit, so reinitialize for | |
327 | that. */ | |
328 | if (bi->elt1->indx != start_bit / BITMAP_ELEMENT_ALL_BITS) | |
329 | start_bit = bi->elt1->indx * BITMAP_ELEMENT_ALL_BITS; | |
330 | ||
331 | bi->word_no = start_bit / BITMAP_WORD_BITS % BITMAP_ELEMENT_WORDS; | |
332 | bi->bits = bi->elt1->bits[bi->word_no]; | |
333 | if (bi->elt2 && bi->elt1->indx == bi->elt2->indx) | |
334 | bi->bits &= ~bi->elt2->bits[bi->word_no]; | |
335 | bi->bits >>= start_bit % BITMAP_WORD_BITS; | |
336 | ||
337 | /* If this word is zero, we must make sure we're not pointing at the | |
338 | first bit, otherwise our incrementing to the next word boundary | |
339 | will fail. It won't matter if this increment moves us into the | |
340 | next word. */ | |
341 | start_bit += !bi->bits; | |
342 | ||
343 | *bit_no = start_bit; | |
87c476a2 ZD |
344 | } |
345 | ||
e90ea8cb | 346 | /* Advance to the next bit in BI. We don't advance to the next |
d46aed51 | 347 | nonzero bit yet. */ |
87c476a2 | 348 | |
e90ea8cb NS |
349 | static inline void |
350 | bmp_iter_next (bitmap_iterator *bi, unsigned *bit_no) | |
87c476a2 | 351 | { |
e90ea8cb NS |
352 | bi->bits >>= 1; |
353 | *bit_no += 1; | |
354 | } | |
87c476a2 | 355 | |
d46aed51 | 356 | /* Advance to the next nonzero bit of a single bitmap, we will have |
e90ea8cb NS |
357 | already advanced past the just iterated bit. Return true if there |
358 | is a bit to iterate. */ | |
87c476a2 | 359 | |
e90ea8cb NS |
360 | static inline bool |
361 | bmp_iter_set (bitmap_iterator *bi, unsigned *bit_no) | |
362 | { | |
d46aed51 | 363 | /* If our current word is nonzero, it contains the bit we want. */ |
e90ea8cb | 364 | if (bi->bits) |
87c476a2 | 365 | { |
e90ea8cb NS |
366 | next_bit: |
367 | while (!(bi->bits & 1)) | |
368 | { | |
369 | bi->bits >>= 1; | |
370 | *bit_no += 1; | |
371 | } | |
372 | return true; | |
87c476a2 ZD |
373 | } |
374 | ||
e90ea8cb NS |
375 | /* Round up to the word boundary. We might have just iterated past |
376 | the end of the last word, hence the -1. It is not possible for | |
377 | bit_no to point at the beginning of the now last word. */ | |
378 | *bit_no = ((*bit_no + BITMAP_WORD_BITS - 1) | |
379 | / BITMAP_WORD_BITS * BITMAP_WORD_BITS); | |
380 | bi->word_no++; | |
87c476a2 | 381 | |
e90ea8cb | 382 | while (1) |
87c476a2 | 383 | { |
d46aed51 | 384 | /* Find the next nonzero word in this elt. */ |
e90ea8cb NS |
385 | while (bi->word_no != BITMAP_ELEMENT_WORDS) |
386 | { | |
387 | bi->bits = bi->elt1->bits[bi->word_no]; | |
388 | if (bi->bits) | |
389 | goto next_bit; | |
390 | *bit_no += BITMAP_WORD_BITS; | |
391 | bi->word_no++; | |
392 | } | |
393 | ||
394 | /* Advance to the next element. */ | |
395 | bi->elt1 = bi->elt1->next; | |
396 | if (!bi->elt1) | |
397 | return false; | |
398 | *bit_no = bi->elt1->indx * BITMAP_ELEMENT_ALL_BITS; | |
399 | bi->word_no = 0; | |
87c476a2 | 400 | } |
87c476a2 ZD |
401 | } |
402 | ||
d46aed51 KH |
403 | /* Advance to the next nonzero bit of an intersecting pair of |
404 | bitmaps. We will have already advanced past the just iterated bit. | |
e90ea8cb | 405 | Return true if there is a bit to iterate. */ |
87c476a2 | 406 | |
e90ea8cb NS |
407 | static inline bool |
408 | bmp_iter_and (bitmap_iterator *bi, unsigned *bit_no) | |
87c476a2 | 409 | { |
d46aed51 | 410 | /* If our current word is nonzero, it contains the bit we want. */ |
e90ea8cb NS |
411 | if (bi->bits) |
412 | { | |
413 | next_bit: | |
414 | while (!(bi->bits & 1)) | |
415 | { | |
416 | bi->bits >>= 1; | |
417 | *bit_no += 1; | |
418 | } | |
419 | return true; | |
420 | } | |
87c476a2 | 421 | |
e90ea8cb NS |
422 | /* Round up to the word boundary. We might have just iterated past |
423 | the end of the last word, hence the -1. It is not possible for | |
424 | bit_no to point at the beginning of the now last word. */ | |
425 | *bit_no = ((*bit_no + BITMAP_WORD_BITS - 1) | |
426 | / BITMAP_WORD_BITS * BITMAP_WORD_BITS); | |
427 | bi->word_no++; | |
428 | ||
87c476a2 ZD |
429 | while (1) |
430 | { | |
d46aed51 | 431 | /* Find the next nonzero word in this elt. */ |
e90ea8cb | 432 | while (bi->word_no != BITMAP_ELEMENT_WORDS) |
87c476a2 | 433 | { |
e90ea8cb NS |
434 | bi->bits = bi->elt1->bits[bi->word_no] & bi->elt2->bits[bi->word_no]; |
435 | if (bi->bits) | |
436 | goto next_bit; | |
437 | *bit_no += BITMAP_WORD_BITS; | |
438 | bi->word_no++; | |
87c476a2 | 439 | } |
e90ea8cb NS |
440 | |
441 | /* Advance to the next identical element. */ | |
87c476a2 ZD |
442 | do |
443 | { | |
e90ea8cb NS |
444 | /* Advance elt1 while it is less than elt2. We always want |
445 | to advance one elt. */ | |
446 | do | |
87c476a2 | 447 | { |
e90ea8cb NS |
448 | bi->elt1 = bi->elt1->next; |
449 | if (!bi->elt1) | |
450 | return false; | |
451 | } | |
452 | while (bi->elt1->indx < bi->elt2->indx); | |
453 | ||
454 | /* Advance elt2 to be no less than elt1. This might not | |
455 | advance. */ | |
456 | while (bi->elt2->indx < bi->elt1->indx) | |
457 | { | |
458 | bi->elt2 = bi->elt2->next; | |
459 | if (!bi->elt2) | |
460 | return false; | |
87c476a2 ZD |
461 | } |
462 | } | |
e90ea8cb NS |
463 | while (bi->elt1->indx != bi->elt2->indx); |
464 | ||
465 | *bit_no = bi->elt1->indx * BITMAP_ELEMENT_ALL_BITS; | |
466 | bi->word_no = 0; | |
87c476a2 ZD |
467 | } |
468 | } | |
469 | ||
d46aed51 | 470 | /* Advance to the next nonzero bit in the intersection of |
e90ea8cb NS |
471 | complemented bitmaps. We will have already advanced past the just |
472 | iterated bit. */ | |
87c476a2 | 473 | |
e90ea8cb NS |
474 | static inline bool |
475 | bmp_iter_and_compl (bitmap_iterator *bi, unsigned *bit_no) | |
87c476a2 | 476 | { |
d46aed51 | 477 | /* If our current word is nonzero, it contains the bit we want. */ |
e90ea8cb | 478 | if (bi->bits) |
87c476a2 | 479 | { |
e90ea8cb NS |
480 | next_bit: |
481 | while (!(bi->bits & 1)) | |
87c476a2 | 482 | { |
e90ea8cb NS |
483 | bi->bits >>= 1; |
484 | *bit_no += 1; | |
87c476a2 | 485 | } |
e90ea8cb | 486 | return true; |
87c476a2 ZD |
487 | } |
488 | ||
e90ea8cb NS |
489 | /* Round up to the word boundary. We might have just iterated past |
490 | the end of the last word, hence the -1. It is not possible for | |
491 | bit_no to point at the beginning of the now last word. */ | |
492 | *bit_no = ((*bit_no + BITMAP_WORD_BITS - 1) | |
493 | / BITMAP_WORD_BITS * BITMAP_WORD_BITS); | |
494 | bi->word_no++; | |
87c476a2 | 495 | |
e90ea8cb | 496 | while (1) |
87c476a2 | 497 | { |
d46aed51 | 498 | /* Find the next nonzero word in this elt. */ |
e90ea8cb NS |
499 | while (bi->word_no != BITMAP_ELEMENT_WORDS) |
500 | { | |
501 | bi->bits = bi->elt1->bits[bi->word_no]; | |
502 | if (bi->elt2 && bi->elt2->indx == bi->elt1->indx) | |
503 | bi->bits &= ~bi->elt2->bits[bi->word_no]; | |
504 | if (bi->bits) | |
505 | goto next_bit; | |
506 | *bit_no += BITMAP_WORD_BITS; | |
507 | bi->word_no++; | |
508 | } | |
509 | ||
510 | /* Advance to the next element of elt1. */ | |
511 | bi->elt1 = bi->elt1->next; | |
512 | if (!bi->elt1) | |
513 | return false; | |
514 | ||
515 | /* Advance elt2 until it is no less than elt1. */ | |
516 | while (bi->elt2 && bi->elt2->indx < bi->elt1->indx) | |
517 | bi->elt2 = bi->elt2->next; | |
518 | ||
519 | *bit_no = bi->elt1->indx * BITMAP_ELEMENT_ALL_BITS; | |
520 | bi->word_no = 0; | |
87c476a2 | 521 | } |
87c476a2 ZD |
522 | } |
523 | ||
e90ea8cb NS |
524 | /* Loop over all bits set in BITMAP, starting with MIN and setting |
525 | BITNUM to the bit number. ITER is a bitmap iterator. BITNUM | |
526 | should be treated as a read-only variable as it contains loop | |
527 | state. */ | |
87c476a2 | 528 | |
e90ea8cb NS |
529 | #define EXECUTE_IF_SET_IN_BITMAP(BITMAP, MIN, BITNUM, ITER) \ |
530 | for (bmp_iter_set_init (&(ITER), (BITMAP), (MIN), &(BITNUM)); \ | |
531 | bmp_iter_set (&(ITER), &(BITNUM)); \ | |
532 | bmp_iter_next (&(ITER), &(BITNUM))) | |
533 | ||
534 | /* Loop over all the bits set in BITMAP1 & BITMAP2, starting with MIN | |
535 | and setting BITNUM to the bit number. ITER is a bitmap iterator. | |
536 | BITNUM should be treated as a read-only variable as it contains | |
537 | loop state. */ | |
538 | ||
539 | #define EXECUTE_IF_AND_IN_BITMAP(BITMAP1, BITMAP2, MIN, BITNUM, ITER) \ | |
540 | for (bmp_iter_and_init (&(ITER), (BITMAP1), (BITMAP2), (MIN), \ | |
541 | &(BITNUM)); \ | |
542 | bmp_iter_and (&(ITER), &(BITNUM)); \ | |
543 | bmp_iter_next (&(ITER), &(BITNUM))) | |
544 | ||
545 | /* Loop over all the bits set in BITMAP1 & ~BITMAP2, starting with MIN | |
546 | and setting BITNUM to the bit number. ITER is a bitmap iterator. | |
547 | BITNUM should be treated as a read-only variable as it contains | |
548 | loop state. */ | |
549 | ||
550 | #define EXECUTE_IF_AND_COMPL_IN_BITMAP(BITMAP1, BITMAP2, MIN, BITNUM, ITER) \ | |
551 | for (bmp_iter_and_compl_init (&(ITER), (BITMAP1), (BITMAP2), (MIN), \ | |
552 | &(BITNUM)); \ | |
553 | bmp_iter_and_compl (&(ITER), &(BITNUM)); \ | |
554 | bmp_iter_next (&(ITER), &(BITNUM))) | |
a05924f9 | 555 | |
88657302 | 556 | #endif /* GCC_BITMAP_H */ |