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