1 /* Functions to support general ended bitmaps.
2 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2003, 2004
3 Free Software Foundation, Inc.
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 2, or (at your option) any later
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
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include "coretypes.h"
33 bitmap_element bitmap_zero_bits
; /* An element of all zero bits. */
34 bitmap_obstack bitmap_default_obstack
; /* The default bitmap obstack. */
35 static GTY((deletable
)) bitmap_element
*bitmap_ggc_free
; /* Freelist of
38 static void bitmap_elem_to_freelist (bitmap
, bitmap_element
*);
39 static void bitmap_element_free (bitmap
, bitmap_element
*);
40 static bitmap_element
*bitmap_element_allocate (bitmap
);
41 static int bitmap_element_zerop (bitmap_element
*);
42 static void bitmap_element_link (bitmap
, bitmap_element
*);
43 static bitmap_element
*bitmap_elt_insert_after (bitmap
, bitmap_element
*);
44 static void bitmap_elt_clear_from (bitmap
, bitmap_element
*);
45 static bitmap_element
*bitmap_find_bit (bitmap
, unsigned int);
48 /* Add ELEM to the appropriate freelist. */
50 bitmap_elem_to_freelist (bitmap head
, bitmap_element
*elt
)
52 bitmap_obstack
*bit_obstack
= head
->obstack
;
56 elt
->next
= bit_obstack
->elements
;
57 bit_obstack
->elements
= elt
;
61 elt
->next
= bitmap_ggc_free
;
62 bitmap_ggc_free
= elt
;
66 /* Free a bitmap element. Since these are allocated off the
67 bitmap_obstack, "free" actually means "put onto the freelist". */
70 bitmap_element_free (bitmap head
, bitmap_element
*elt
)
72 bitmap_element
*next
= elt
->next
;
73 bitmap_element
*prev
= elt
->prev
;
81 if (head
->first
== elt
)
84 /* Since the first thing we try is to insert before current,
85 make current the next entry in preference to the previous. */
86 if (head
->current
== elt
)
88 head
->current
= next
!= 0 ? next
: prev
;
90 head
->indx
= head
->current
->indx
;
92 bitmap_elem_to_freelist (head
, elt
);
95 /* Allocate a bitmap element. The bits are cleared, but nothing else is. */
97 static inline bitmap_element
*
98 bitmap_element_allocate (bitmap head
)
100 bitmap_element
*element
;
101 bitmap_obstack
*bit_obstack
= head
->obstack
;
105 element
= bit_obstack
->elements
;
108 bit_obstack
->elements
= element
->next
;
110 element
= XOBNEW (&bit_obstack
->obstack
, bitmap_element
);
114 element
= bitmap_ggc_free
;
116 bitmap_ggc_free
= element
->next
;
118 element
= GGC_NEW (bitmap_element
);
121 memset (element
->bits
, 0, sizeof (element
->bits
));
126 /* Remove ELT and all following elements from bitmap HEAD. */
129 bitmap_elt_clear_from (bitmap head
, bitmap_element
*elt
)
131 bitmap_element
*next
;
136 bitmap_element_free (head
, elt
);
141 /* Clear a bitmap by freeing the linked list. */
144 bitmap_clear (bitmap head
)
146 bitmap_element
*element
, *next
;
148 for (element
= head
->first
; element
!= 0; element
= next
)
150 next
= element
->next
;
151 bitmap_elem_to_freelist (head
, element
);
154 head
->first
= head
->current
= 0;
157 /* Initialize a bitmap obstack. If BIT_OBSTACK is NULL, initialize
158 the default bitmap obstack. */
161 bitmap_obstack_initialize (bitmap_obstack
*bit_obstack
)
164 bit_obstack
= &bitmap_default_obstack
;
166 #if !defined(__GNUC__) || (__GNUC__ < 2)
167 #define __alignof__(type) 0
170 bit_obstack
->elements
= NULL
;
171 bit_obstack
->heads
= NULL
;
172 obstack_specify_allocation (&bit_obstack
->obstack
, OBSTACK_CHUNK_SIZE
,
173 __alignof__ (bitmap_element
),
178 /* Release the memory from a bitmap obstack. If BIT_OBSTACK is NULL,
179 release the default bitmap obstack. */
182 bitmap_obstack_release (bitmap_obstack
*bit_obstack
)
185 bit_obstack
= &bitmap_default_obstack
;
187 bit_obstack
->elements
= NULL
;
188 bit_obstack
->heads
= NULL
;
189 obstack_free (&bit_obstack
->obstack
, NULL
);
192 /* Create a new bitmap on an obstack. If BIT_OBSTACK is NULL, create
193 it on the default bitmap obstack. */
196 bitmap_obstack_alloc (bitmap_obstack
*bit_obstack
)
201 bit_obstack
= &bitmap_default_obstack
;
202 map
= bit_obstack
->heads
;
204 bit_obstack
->heads
= (void *)map
->first
;
206 map
= XOBNEW (&bit_obstack
->obstack
, bitmap_head
);
207 bitmap_initialize (map
, bit_obstack
);
212 /* Create a new GCd bitmap. */
215 bitmap_gc_alloc (void)
219 map
= GGC_NEW (struct bitmap_head_def
);
220 bitmap_initialize (map
, NULL
);
225 /* Release an obstack allocated bitmap. */
228 bitmap_obstack_free (bitmap map
)
233 map
->first
= (void *)map
->obstack
->heads
;
234 map
->obstack
->heads
= map
;
239 /* Return nonzero if all bits in an element are zero. */
242 bitmap_element_zerop (bitmap_element
*element
)
244 #if BITMAP_ELEMENT_WORDS == 2
245 return (element
->bits
[0] | element
->bits
[1]) == 0;
249 for (i
= 0; i
< BITMAP_ELEMENT_WORDS
; i
++)
250 if (element
->bits
[i
] != 0)
257 /* Link the bitmap element into the current bitmap linked list. */
260 bitmap_element_link (bitmap head
, bitmap_element
*element
)
262 unsigned int indx
= element
->indx
;
265 /* If this is the first and only element, set it in. */
266 if (head
->first
== 0)
268 element
->next
= element
->prev
= 0;
269 head
->first
= element
;
272 /* If this index is less than that of the current element, it goes someplace
273 before the current element. */
274 else if (indx
< head
->indx
)
276 for (ptr
= head
->current
;
277 ptr
->prev
!= 0 && ptr
->prev
->indx
> indx
;
282 ptr
->prev
->next
= element
;
284 head
->first
= element
;
286 element
->prev
= ptr
->prev
;
291 /* Otherwise, it must go someplace after the current element. */
294 for (ptr
= head
->current
;
295 ptr
->next
!= 0 && ptr
->next
->indx
< indx
;
300 ptr
->next
->prev
= element
;
302 element
->next
= ptr
->next
;
307 /* Set up so this is the first element searched. */
308 head
->current
= element
;
312 /* Insert a new uninitialized element into bitmap HEAD after element
313 ELT. If ELT is NULL, insert the element at the start. Return the
316 static bitmap_element
*
317 bitmap_elt_insert_after (bitmap head
, bitmap_element
*elt
)
319 bitmap_element
*node
= bitmap_element_allocate (head
);
324 head
->current
= node
;
325 node
->next
= head
->first
;
327 node
->next
->prev
= node
;
333 gcc_assert (head
->current
);
334 node
->next
= elt
->next
;
336 node
->next
->prev
= node
;
343 /* Copy a bitmap to another bitmap. */
346 bitmap_copy (bitmap to
, bitmap from
)
348 bitmap_element
*from_ptr
, *to_ptr
= 0;
349 #if BITMAP_ELEMENT_WORDS != 2
355 /* Copy elements in forward direction one at a time. */
356 for (from_ptr
= from
->first
; from_ptr
; from_ptr
= from_ptr
->next
)
358 bitmap_element
*to_elt
= bitmap_element_allocate (to
);
360 to_elt
->indx
= from_ptr
->indx
;
362 #if BITMAP_ELEMENT_WORDS == 2
363 to_elt
->bits
[0] = from_ptr
->bits
[0];
364 to_elt
->bits
[1] = from_ptr
->bits
[1];
366 for (i
= 0; i
< BITMAP_ELEMENT_WORDS
; i
++)
367 to_elt
->bits
[i
] = from_ptr
->bits
[i
];
370 /* Here we have a special case of bitmap_element_link, for the case
371 where we know the links are being entered in sequence. */
374 to
->first
= to
->current
= to_elt
;
375 to
->indx
= from_ptr
->indx
;
376 to_elt
->next
= to_elt
->prev
= 0;
380 to_elt
->prev
= to_ptr
;
382 to_ptr
->next
= to_elt
;
389 /* Find a bitmap element that would hold a bitmap's bit.
390 Update the `current' field even if we can't find an element that
391 would hold the bitmap's bit to make eventual allocation
394 static inline bitmap_element
*
395 bitmap_find_bit (bitmap head
, unsigned int bit
)
397 bitmap_element
*element
;
398 unsigned int indx
= bit
/ BITMAP_ELEMENT_ALL_BITS
;
400 if (head
->current
== 0
401 || head
->indx
== indx
)
402 return head
->current
;
404 if (head
->indx
< indx
)
405 /* INDX is beyond head->indx. Search from head->current
407 for (element
= head
->current
;
408 element
->next
!= 0 && element
->indx
< indx
;
409 element
= element
->next
)
412 else if (head
->indx
/ 2 < indx
)
413 /* INDX is less than head->indx and closer to head->indx than to
414 0. Search from head->current backward. */
415 for (element
= head
->current
;
416 element
->prev
!= 0 && element
->indx
> indx
;
417 element
= element
->prev
)
421 /* INDX is less than head->indx and closer to 0 than to
422 head->indx. Search from head->first forward. */
423 for (element
= head
->first
;
424 element
->next
!= 0 && element
->indx
< indx
;
425 element
= element
->next
)
428 /* `element' is the nearest to the one we want. If it's not the one we
429 want, the one we want doesn't exist. */
430 head
->current
= element
;
431 head
->indx
= element
->indx
;
432 if (element
!= 0 && element
->indx
!= indx
)
438 /* Clear a single bit in a bitmap. */
441 bitmap_clear_bit (bitmap head
, int bit
)
443 bitmap_element
*ptr
= bitmap_find_bit (head
, bit
);
447 unsigned bit_num
= bit
% BITMAP_WORD_BITS
;
448 unsigned word_num
= bit
/ BITMAP_WORD_BITS
% BITMAP_ELEMENT_WORDS
;
449 ptr
->bits
[word_num
] &= ~ (((BITMAP_WORD
) 1) << bit_num
);
451 /* If we cleared the entire word, free up the element. */
452 if (bitmap_element_zerop (ptr
))
453 bitmap_element_free (head
, ptr
);
457 /* Set a single bit in a bitmap. */
460 bitmap_set_bit (bitmap head
, int bit
)
462 bitmap_element
*ptr
= bitmap_find_bit (head
, bit
);
463 unsigned word_num
= bit
/ BITMAP_WORD_BITS
% BITMAP_ELEMENT_WORDS
;
464 unsigned bit_num
= bit
% BITMAP_WORD_BITS
;
465 BITMAP_WORD bit_val
= ((BITMAP_WORD
) 1) << bit_num
;
469 ptr
= bitmap_element_allocate (head
);
470 ptr
->indx
= bit
/ BITMAP_ELEMENT_ALL_BITS
;
471 ptr
->bits
[word_num
] = bit_val
;
472 bitmap_element_link (head
, ptr
);
475 ptr
->bits
[word_num
] |= bit_val
;
478 /* Return whether a bit is set within a bitmap. */
481 bitmap_bit_p (bitmap head
, int bit
)
487 ptr
= bitmap_find_bit (head
, bit
);
491 bit_num
= bit
% BITMAP_WORD_BITS
;
492 word_num
= bit
/ BITMAP_WORD_BITS
% BITMAP_ELEMENT_WORDS
;
494 return (ptr
->bits
[word_num
] >> bit_num
) & 1;
497 /* Return the bit number of the first set bit in the bitmap. The
498 bitmap must be non-empty. */
501 bitmap_first_set_bit (bitmap a
)
503 bitmap_element
*elt
= a
->first
;
509 bit_no
= elt
->indx
* BITMAP_ELEMENT_ALL_BITS
;
510 for (ix
= 0; ix
!= BITMAP_ELEMENT_WORDS
; ix
++)
512 word
= elt
->bits
[ix
];
518 bit_no
+= ix
* BITMAP_WORD_BITS
;
520 #if GCC_VERSION >= 3004
521 gcc_assert (sizeof(long) == sizeof (word
));
522 bit_no
+= __builtin_ctzl (word
);
524 /* Binary search for the first set bit. */
525 #if BITMAP_WORD_BITS > 64
526 #error "Fill out the table."
528 #if BITMAP_WORD_BITS > 32
529 if (!(word
& 0xffffffff))
530 word
>>= 32, bit_no
+= 32;
532 if (!(word
& 0xffff))
533 word
>>= 16, bit_no
+= 16;
535 word
>>= 8, bit_no
+= 8;
537 word
>>= 4, bit_no
+= 4;
539 word
>>= 2, bit_no
+= 2;
541 word
>>= 1, bit_no
+= 1;
543 gcc_assert (word
& 1);
552 bitmap_and (bitmap dst
, bitmap a
, bitmap b
)
554 bitmap_element
*dst_elt
= dst
->first
;
555 bitmap_element
*a_elt
= a
->first
;
556 bitmap_element
*b_elt
= b
->first
;
557 bitmap_element
*dst_prev
= NULL
;
559 gcc_assert (dst
!= a
&& dst
!= b
&& a
!= b
);
560 while (a_elt
&& b_elt
)
562 if (a_elt
->indx
< b_elt
->indx
)
564 else if (b_elt
->indx
< a_elt
->indx
)
568 /* Matching elts, generate A & B. */
573 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
575 dst_elt
->indx
= a_elt
->indx
;
576 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
578 BITMAP_WORD r
= a_elt
->bits
[ix
] & b_elt
->bits
[ix
];
580 dst_elt
->bits
[ix
] = r
;
586 dst_elt
= dst_elt
->next
;
592 bitmap_elt_clear_from (dst
, dst_elt
);
593 gcc_assert (!dst
->current
== !dst
->first
);
595 dst
->indx
= dst
->current
->indx
;
601 bitmap_and_into (bitmap a
, bitmap b
)
603 bitmap_element
*a_elt
= a
->first
;
604 bitmap_element
*b_elt
= b
->first
;
605 bitmap_element
*next
;
608 while (a_elt
&& b_elt
)
610 if (a_elt
->indx
< b_elt
->indx
)
613 bitmap_element_free (a
, a_elt
);
616 else if (b_elt
->indx
< a_elt
->indx
)
620 /* Matching elts, generate A &= B. */
624 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
626 BITMAP_WORD r
= a_elt
->bits
[ix
] & b_elt
->bits
[ix
];
633 bitmap_element_free (a
, a_elt
);
638 bitmap_elt_clear_from (a
, a_elt
);
639 gcc_assert (!a
->current
== !a
->first
);
640 gcc_assert (!a
->current
|| a
->indx
== a
->current
->indx
);
646 bitmap_and_compl (bitmap dst
, bitmap a
, bitmap b
)
648 bitmap_element
*dst_elt
= dst
->first
;
649 bitmap_element
*a_elt
= a
->first
;
650 bitmap_element
*b_elt
= b
->first
;
651 bitmap_element
*dst_prev
= NULL
;
653 gcc_assert (dst
!= a
&& dst
!= b
&& a
!= b
);
657 if (!b_elt
|| a_elt
->indx
< b_elt
->indx
)
661 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
663 dst_elt
->indx
= a_elt
->indx
;
664 memcpy (dst_elt
->bits
, a_elt
->bits
, sizeof (dst_elt
->bits
));
666 dst_elt
= dst_elt
->next
;
669 else if (b_elt
->indx
< a_elt
->indx
)
673 /* Matching elts, generate A & ~B. */
678 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
680 dst_elt
->indx
= a_elt
->indx
;
681 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
683 BITMAP_WORD r
= a_elt
->bits
[ix
] & ~b_elt
->bits
[ix
];
685 dst_elt
->bits
[ix
] = r
;
691 dst_elt
= dst_elt
->next
;
697 bitmap_elt_clear_from (dst
, dst_elt
);
698 gcc_assert (!dst
->current
== !dst
->first
);
700 dst
->indx
= dst
->current
->indx
;
706 bitmap_and_compl_into (bitmap a
, bitmap b
)
708 bitmap_element
*a_elt
= a
->first
;
709 bitmap_element
*b_elt
= b
->first
;
710 bitmap_element
*next
;
713 while (a_elt
&& b_elt
)
715 if (a_elt
->indx
< b_elt
->indx
)
717 else if (b_elt
->indx
< a_elt
->indx
)
721 /* Matching elts, generate A &= ~B. */
725 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
727 BITMAP_WORD r
= a_elt
->bits
[ix
] & ~b_elt
->bits
[ix
];
734 bitmap_element_free (a
, a_elt
);
739 gcc_assert (!a
->current
== !a
->first
);
740 gcc_assert (!a
->current
|| a
->indx
== a
->current
->indx
);
743 /* DST = A | B. Return true if DST changes. */
746 bitmap_ior (bitmap dst
, bitmap a
, bitmap b
)
748 bitmap_element
*dst_elt
= dst
->first
;
749 bitmap_element
*a_elt
= a
->first
;
750 bitmap_element
*b_elt
= b
->first
;
751 bitmap_element
*dst_prev
= NULL
;
752 bool changed
= false;
754 gcc_assert (dst
!= a
&& dst
!= b
&& a
!= b
);
755 while (a_elt
|| b_elt
)
757 if (a_elt
&& b_elt
&& a_elt
->indx
== b_elt
->indx
)
759 /* Matching elts, generate A | B. */
762 if (!changed
&& dst_elt
&& dst_elt
->indx
== a_elt
->indx
)
764 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
766 BITMAP_WORD r
= a_elt
->bits
[ix
] | b_elt
->bits
[ix
];
768 if (r
!= dst_elt
->bits
[ix
])
770 dst_elt
->bits
[ix
] = r
;
779 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
780 dst_elt
->indx
= a_elt
->indx
;
781 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
783 BITMAP_WORD r
= a_elt
->bits
[ix
] | b_elt
->bits
[ix
];
785 dst_elt
->bits
[ix
] = r
;
791 dst_elt
= dst_elt
->next
;
795 /* Copy a single element. */
798 if (!b_elt
|| (a_elt
&& a_elt
->indx
< b_elt
->indx
))
809 if (!changed
&& dst_elt
&& dst_elt
->indx
== src
->indx
)
813 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
814 if (src
->bits
[ix
] != dst_elt
->bits
[ix
])
816 dst_elt
->bits
[ix
] = src
->bits
[ix
];
824 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
825 dst_elt
->indx
= src
->indx
;
826 memcpy (dst_elt
->bits
, src
->bits
, sizeof (dst_elt
->bits
));
830 dst_elt
= dst_elt
->next
;
837 bitmap_elt_clear_from (dst
, dst_elt
);
839 gcc_assert (!dst
->current
== !dst
->first
);
841 dst
->indx
= dst
->current
->indx
;
845 /* A |= B. Return true if A changes. */
848 bitmap_ior_into (bitmap a
, bitmap b
)
850 bitmap_element
*a_elt
= a
->first
;
851 bitmap_element
*b_elt
= b
->first
;
852 bitmap_element
*a_prev
= NULL
;
853 bool changed
= false;
858 if (!a_elt
|| b_elt
->indx
< a_elt
->indx
)
861 bitmap_element
*dst
= bitmap_elt_insert_after (a
, a_prev
);
863 dst
->indx
= b_elt
->indx
;
864 memcpy (dst
->bits
, b_elt
->bits
, sizeof (dst
->bits
));
869 else if (a_elt
->indx
< b_elt
->indx
)
876 /* Matching elts, generate A |= B. */
880 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
882 BITMAP_WORD r
= a_elt
->bits
[ix
] | b_elt
->bits
[ix
];
887 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
889 BITMAP_WORD r
= a_elt
->bits
[ix
] | b_elt
->bits
[ix
];
891 if (a_elt
->bits
[ix
] != r
)
902 gcc_assert (!a
->current
== !a
->first
);
904 a
->indx
= a
->current
->indx
;
911 bitmap_xor (bitmap dst
, bitmap a
, bitmap b
)
913 bitmap_element
*dst_elt
= dst
->first
;
914 bitmap_element
*a_elt
= a
->first
;
915 bitmap_element
*b_elt
= b
->first
;
916 bitmap_element
*dst_prev
= NULL
;
918 gcc_assert (dst
!= a
&& dst
!= b
&& a
!= b
);
919 while (a_elt
|| b_elt
)
921 if (a_elt
&& b_elt
&& a_elt
->indx
== b_elt
->indx
)
923 /* Matching elts, generate A ^ B. */
928 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
930 dst_elt
->indx
= a_elt
->indx
;
931 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
933 BITMAP_WORD r
= a_elt
->bits
[ix
] ^ b_elt
->bits
[ix
];
936 dst_elt
->bits
[ix
] = r
;
943 dst_elt
= dst_elt
->next
;
948 /* Copy a single element. */
951 if (!b_elt
|| (a_elt
&& a_elt
->indx
< b_elt
->indx
))
963 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
965 dst_elt
->indx
= src
->indx
;
966 memcpy (dst_elt
->bits
, src
->bits
, sizeof (dst_elt
->bits
));
968 dst_elt
= dst_elt
->next
;
971 bitmap_elt_clear_from (dst
, dst_elt
);
972 gcc_assert (!dst
->current
== !dst
->first
);
974 dst
->indx
= dst
->current
->indx
;
980 bitmap_xor_into (bitmap a
, bitmap b
)
982 bitmap_element
*a_elt
= a
->first
;
983 bitmap_element
*b_elt
= b
->first
;
984 bitmap_element
*a_prev
= NULL
;
989 if (!a_elt
|| b_elt
->indx
< a_elt
->indx
)
992 bitmap_element
*dst
= bitmap_elt_insert_after (a
, a_prev
);
994 dst
->indx
= b_elt
->indx
;
995 memcpy (dst
->bits
, b_elt
->bits
, sizeof (dst
->bits
));
999 else if (a_elt
->indx
< b_elt
->indx
)
1002 a_elt
= a_elt
->next
;
1006 /* Matching elts, generate A ^= B. */
1008 BITMAP_WORD ior
= 0;
1009 bitmap_element
*next
= a_elt
->next
;
1011 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
1013 BITMAP_WORD r
= a_elt
->bits
[ix
] ^ b_elt
->bits
[ix
];
1016 a_elt
->bits
[ix
] = r
;
1018 b_elt
= b_elt
->next
;
1022 bitmap_element_free (a
, a_elt
);
1026 gcc_assert (!a
->current
== !a
->first
);
1028 a
->indx
= a
->current
->indx
;
1031 /* Return true if two bitmaps are identical.
1032 We do not bother with a check for pointer equality, as that never
1033 occurs in practice. */
1036 bitmap_equal_p (bitmap a
, bitmap b
)
1038 bitmap_element
*a_elt
;
1039 bitmap_element
*b_elt
;
1042 for (a_elt
= a
->first
, b_elt
= b
->first
;
1044 a_elt
= a_elt
->next
, b_elt
= b_elt
->next
)
1046 if (a_elt
->indx
!= b_elt
->indx
)
1048 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
1049 if (a_elt
->bits
[ix
] != b_elt
->bits
[ix
])
1052 return !a_elt
&& !b_elt
;
1055 /* Return true if A AND B is not empty. */
1058 bitmap_intersect_p (bitmap a
, bitmap b
)
1060 bitmap_element
*a_elt
;
1061 bitmap_element
*b_elt
;
1064 for (a_elt
= a
->first
, b_elt
= b
->first
;
1067 if (a_elt
->indx
< b_elt
->indx
)
1068 a_elt
= a_elt
->next
;
1069 else if (b_elt
->indx
< a_elt
->indx
)
1070 b_elt
= b_elt
->next
;
1073 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
1074 if (a_elt
->bits
[ix
] & b_elt
->bits
[ix
])
1076 a_elt
= a_elt
->next
;
1077 b_elt
= b_elt
->next
;
1083 /* Return true if A AND NOT B is not empty. */
1086 bitmap_intersect_compl_p (bitmap a
, bitmap b
)
1088 bitmap_element
*a_elt
;
1089 bitmap_element
*b_elt
;
1091 for (a_elt
= a
->first
, b_elt
= b
->first
;
1094 if (a_elt
->indx
< b_elt
->indx
)
1096 else if (b_elt
->indx
< a_elt
->indx
)
1097 b_elt
= b_elt
->next
;
1100 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
1101 if (a_elt
->bits
[ix
] & ~b_elt
->bits
[ix
])
1103 a_elt
= a_elt
->next
;
1104 b_elt
= b_elt
->next
;
1107 return a_elt
!= NULL
;
1111 /* DST = A | (FROM1 & ~FROM2). Return true if DST changes. */
1114 bitmap_ior_and_compl (bitmap dst
, bitmap a
, bitmap from1
, bitmap from2
)
1119 bitmap_initialize (&tmp
, &bitmap_default_obstack
);
1120 bitmap_and_compl (&tmp
, from1
, from2
);
1121 changed
= bitmap_ior (dst
, a
, &tmp
);
1122 bitmap_clear (&tmp
);
1127 /* A |= (FROM1 & ~FROM2). Return true if A changes. */
1130 bitmap_ior_and_compl_into (bitmap a
, bitmap from1
, bitmap from2
)
1135 bitmap_initialize (&tmp
, &bitmap_default_obstack
);
1136 bitmap_and_compl (&tmp
, from1
, from2
);
1137 changed
= bitmap_ior_into (a
, &tmp
);
1138 bitmap_clear (&tmp
);
1143 /* Debugging function to print out the contents of a bitmap. */
1146 debug_bitmap_file (FILE *file
, bitmap head
)
1148 bitmap_element
*ptr
;
1150 fprintf (file
, "\nfirst = " HOST_PTR_PRINTF
1151 " current = " HOST_PTR_PRINTF
" indx = %u\n",
1152 (void *) head
->first
, (void *) head
->current
, head
->indx
);
1154 for (ptr
= head
->first
; ptr
; ptr
= ptr
->next
)
1156 unsigned int i
, j
, col
= 26;
1158 fprintf (file
, "\t" HOST_PTR_PRINTF
" next = " HOST_PTR_PRINTF
1159 " prev = " HOST_PTR_PRINTF
" indx = %u\n\t\tbits = {",
1160 (void*) ptr
, (void*) ptr
->next
, (void*) ptr
->prev
, ptr
->indx
);
1162 for (i
= 0; i
< BITMAP_ELEMENT_WORDS
; i
++)
1163 for (j
= 0; j
< BITMAP_WORD_BITS
; j
++)
1164 if ((ptr
->bits
[i
] >> j
) & 1)
1168 fprintf (file
, "\n\t\t\t");
1172 fprintf (file
, " %u", (ptr
->indx
* BITMAP_ELEMENT_ALL_BITS
1173 + i
* BITMAP_WORD_BITS
+ j
));
1177 fprintf (file
, " }\n");
1181 /* Function to be called from the debugger to print the contents
1185 debug_bitmap (bitmap head
)
1187 debug_bitmap_file (stdout
, head
);
1190 /* Function to print out the contents of a bitmap. Unlike debug_bitmap_file,
1191 it does not print anything but the bits. */
1194 bitmap_print (FILE *file
, bitmap head
, const char *prefix
, const char *suffix
)
1196 const char *comma
= "";
1200 fputs (prefix
, file
);
1201 EXECUTE_IF_SET_IN_BITMAP (head
, 0, i
, bi
)
1203 fprintf (file
, "%s%d", comma
, i
);
1206 fputs (suffix
, file
);
1209 #include "gt-bitmap.h"