1 /* Functions to support general ended bitmaps.
2 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005
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, 51 Franklin Street, Fifth Floor, 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
;
57 elt
->prev
= bit_obstack
->elements
;
58 bit_obstack
->elements
= elt
;
62 elt
->prev
= bitmap_ggc_free
;
63 bitmap_ggc_free
= elt
;
67 /* Free a bitmap element. Since these are allocated off the
68 bitmap_obstack, "free" actually means "put onto the freelist". */
71 bitmap_element_free (bitmap head
, bitmap_element
*elt
)
73 bitmap_element
*next
= elt
->next
;
74 bitmap_element
*prev
= elt
->prev
;
82 if (head
->first
== elt
)
85 /* Since the first thing we try is to insert before current,
86 make current the next entry in preference to the previous. */
87 if (head
->current
== elt
)
89 head
->current
= next
!= 0 ? next
: prev
;
91 head
->indx
= head
->current
->indx
;
93 bitmap_elem_to_freelist (head
, elt
);
96 /* Allocate a bitmap element. The bits are cleared, but nothing else is. */
98 static inline bitmap_element
*
99 bitmap_element_allocate (bitmap head
)
101 bitmap_element
*element
;
102 bitmap_obstack
*bit_obstack
= head
->obstack
;
106 element
= bit_obstack
->elements
;
109 /* Use up the inner list first before looking at the next
110 element of the outer list. */
113 bit_obstack
->elements
= element
->next
;
114 bit_obstack
->elements
->prev
= element
->prev
;
117 /* Inner list was just a singleton. */
118 bit_obstack
->elements
= element
->prev
;
120 element
= XOBNEW (&bit_obstack
->obstack
, bitmap_element
);
124 element
= bitmap_ggc_free
;
126 /* Use up the inner list first before looking at the next
127 element of the outer list. */
130 bitmap_ggc_free
= element
->next
;
131 bitmap_ggc_free
->prev
= element
->prev
;
134 /* Inner list was just a singleton. */
135 bitmap_ggc_free
= element
->prev
;
137 element
= GGC_NEW (bitmap_element
);
140 memset (element
->bits
, 0, sizeof (element
->bits
));
145 /* Remove ELT and all following elements from bitmap HEAD. */
148 bitmap_elt_clear_from (bitmap head
, bitmap_element
*elt
)
150 bitmap_element
*prev
;
151 bitmap_obstack
*bit_obstack
= head
->obstack
;
159 if (head
->current
->indx
> prev
->indx
)
161 head
->current
= prev
;
162 head
->indx
= prev
->indx
;
168 head
->current
= NULL
;
172 /* Put the entire list onto the free list in one operation. */
175 elt
->prev
= bit_obstack
->elements
;
176 bit_obstack
->elements
= elt
;
180 elt
->prev
= bitmap_ggc_free
;
181 bitmap_ggc_free
= elt
;
185 /* Clear a bitmap by freeing the linked list. */
188 bitmap_clear (bitmap head
)
191 bitmap_elt_clear_from (head
, head
->first
);
194 /* Initialize a bitmap obstack. If BIT_OBSTACK is NULL, initialize
195 the default bitmap obstack. */
198 bitmap_obstack_initialize (bitmap_obstack
*bit_obstack
)
201 bit_obstack
= &bitmap_default_obstack
;
203 #if !defined(__GNUC__) || (__GNUC__ < 2)
204 #define __alignof__(type) 0
207 bit_obstack
->elements
= NULL
;
208 bit_obstack
->heads
= NULL
;
209 obstack_specify_allocation (&bit_obstack
->obstack
, OBSTACK_CHUNK_SIZE
,
210 __alignof__ (bitmap_element
),
215 /* Release the memory from a bitmap obstack. If BIT_OBSTACK is NULL,
216 release the default bitmap obstack. */
219 bitmap_obstack_release (bitmap_obstack
*bit_obstack
)
222 bit_obstack
= &bitmap_default_obstack
;
224 bit_obstack
->elements
= NULL
;
225 bit_obstack
->heads
= NULL
;
226 obstack_free (&bit_obstack
->obstack
, NULL
);
227 #ifdef ENABLE_CHECKING
228 memset (&bit_obstack
->obstack
, 0xab, sizeof (*&bit_obstack
->obstack
));
232 /* Create a new bitmap on an obstack. If BIT_OBSTACK is NULL, create
233 it on the default bitmap obstack. */
236 bitmap_obstack_alloc (bitmap_obstack
*bit_obstack
)
241 bit_obstack
= &bitmap_default_obstack
;
242 map
= bit_obstack
->heads
;
244 bit_obstack
->heads
= (void *)map
->first
;
246 map
= XOBNEW (&bit_obstack
->obstack
, bitmap_head
);
247 bitmap_initialize (map
, bit_obstack
);
252 /* Create a new GCd bitmap. */
255 bitmap_gc_alloc (void)
259 map
= GGC_NEW (struct bitmap_head_def
);
260 bitmap_initialize (map
, NULL
);
265 /* Release an obstack allocated bitmap. */
268 bitmap_obstack_free (bitmap map
)
273 map
->first
= (void *)map
->obstack
->heads
;
274 map
->obstack
->heads
= map
;
279 /* Return nonzero if all bits in an element are zero. */
282 bitmap_element_zerop (bitmap_element
*element
)
284 #if BITMAP_ELEMENT_WORDS == 2
285 return (element
->bits
[0] | element
->bits
[1]) == 0;
289 for (i
= 0; i
< BITMAP_ELEMENT_WORDS
; i
++)
290 if (element
->bits
[i
] != 0)
297 /* Link the bitmap element into the current bitmap linked list. */
300 bitmap_element_link (bitmap head
, bitmap_element
*element
)
302 unsigned int indx
= element
->indx
;
305 /* If this is the first and only element, set it in. */
306 if (head
->first
== 0)
308 element
->next
= element
->prev
= 0;
309 head
->first
= element
;
312 /* If this index is less than that of the current element, it goes someplace
313 before the current element. */
314 else if (indx
< head
->indx
)
316 for (ptr
= head
->current
;
317 ptr
->prev
!= 0 && ptr
->prev
->indx
> indx
;
322 ptr
->prev
->next
= element
;
324 head
->first
= element
;
326 element
->prev
= ptr
->prev
;
331 /* Otherwise, it must go someplace after the current element. */
334 for (ptr
= head
->current
;
335 ptr
->next
!= 0 && ptr
->next
->indx
< indx
;
340 ptr
->next
->prev
= element
;
342 element
->next
= ptr
->next
;
347 /* Set up so this is the first element searched. */
348 head
->current
= element
;
352 /* Insert a new uninitialized element into bitmap HEAD after element
353 ELT. If ELT is NULL, insert the element at the start. Return the
356 static bitmap_element
*
357 bitmap_elt_insert_after (bitmap head
, bitmap_element
*elt
)
359 bitmap_element
*node
= bitmap_element_allocate (head
);
364 head
->current
= node
;
365 node
->next
= head
->first
;
367 node
->next
->prev
= node
;
373 gcc_assert (head
->current
);
374 node
->next
= elt
->next
;
376 node
->next
->prev
= node
;
383 /* Copy a bitmap to another bitmap. */
386 bitmap_copy (bitmap to
, bitmap from
)
388 bitmap_element
*from_ptr
, *to_ptr
= 0;
392 /* Copy elements in forward direction one at a time. */
393 for (from_ptr
= from
->first
; from_ptr
; from_ptr
= from_ptr
->next
)
395 bitmap_element
*to_elt
= bitmap_element_allocate (to
);
397 to_elt
->indx
= from_ptr
->indx
;
398 memcpy (to_elt
->bits
, from_ptr
->bits
, sizeof (to_elt
->bits
));
400 /* Here we have a special case of bitmap_element_link, for the case
401 where we know the links are being entered in sequence. */
404 to
->first
= to
->current
= to_elt
;
405 to
->indx
= from_ptr
->indx
;
406 to_elt
->next
= to_elt
->prev
= 0;
410 to_elt
->prev
= to_ptr
;
412 to_ptr
->next
= to_elt
;
419 /* Find a bitmap element that would hold a bitmap's bit.
420 Update the `current' field even if we can't find an element that
421 would hold the bitmap's bit to make eventual allocation
424 static inline bitmap_element
*
425 bitmap_find_bit (bitmap head
, unsigned int bit
)
427 bitmap_element
*element
;
428 unsigned int indx
= bit
/ BITMAP_ELEMENT_ALL_BITS
;
430 if (head
->current
== 0
431 || head
->indx
== indx
)
432 return head
->current
;
434 if (head
->indx
< indx
)
435 /* INDX is beyond head->indx. Search from head->current
437 for (element
= head
->current
;
438 element
->next
!= 0 && element
->indx
< indx
;
439 element
= element
->next
)
442 else if (head
->indx
/ 2 < indx
)
443 /* INDX is less than head->indx and closer to head->indx than to
444 0. Search from head->current backward. */
445 for (element
= head
->current
;
446 element
->prev
!= 0 && element
->indx
> indx
;
447 element
= element
->prev
)
451 /* INDX is less than head->indx and closer to 0 than to
452 head->indx. Search from head->first forward. */
453 for (element
= head
->first
;
454 element
->next
!= 0 && element
->indx
< indx
;
455 element
= element
->next
)
458 /* `element' is the nearest to the one we want. If it's not the one we
459 want, the one we want doesn't exist. */
460 head
->current
= element
;
461 head
->indx
= element
->indx
;
462 if (element
!= 0 && element
->indx
!= indx
)
468 /* Clear a single bit in a bitmap. */
471 bitmap_clear_bit (bitmap head
, int bit
)
473 bitmap_element
*ptr
= bitmap_find_bit (head
, bit
);
477 unsigned bit_num
= bit
% BITMAP_WORD_BITS
;
478 unsigned word_num
= bit
/ BITMAP_WORD_BITS
% BITMAP_ELEMENT_WORDS
;
479 ptr
->bits
[word_num
] &= ~ (((BITMAP_WORD
) 1) << bit_num
);
481 /* If we cleared the entire word, free up the element. */
482 if (bitmap_element_zerop (ptr
))
483 bitmap_element_free (head
, ptr
);
487 /* Set a single bit in a bitmap. */
490 bitmap_set_bit (bitmap head
, int bit
)
492 bitmap_element
*ptr
= bitmap_find_bit (head
, bit
);
493 unsigned word_num
= bit
/ BITMAP_WORD_BITS
% BITMAP_ELEMENT_WORDS
;
494 unsigned bit_num
= bit
% BITMAP_WORD_BITS
;
495 BITMAP_WORD bit_val
= ((BITMAP_WORD
) 1) << bit_num
;
499 ptr
= bitmap_element_allocate (head
);
500 ptr
->indx
= bit
/ BITMAP_ELEMENT_ALL_BITS
;
501 ptr
->bits
[word_num
] = bit_val
;
502 bitmap_element_link (head
, ptr
);
505 ptr
->bits
[word_num
] |= bit_val
;
508 /* Return whether a bit is set within a bitmap. */
511 bitmap_bit_p (bitmap head
, int bit
)
517 ptr
= bitmap_find_bit (head
, bit
);
521 bit_num
= bit
% BITMAP_WORD_BITS
;
522 word_num
= bit
/ BITMAP_WORD_BITS
% BITMAP_ELEMENT_WORDS
;
524 return (ptr
->bits
[word_num
] >> bit_num
) & 1;
527 /* Return the bit number of the first set bit in the bitmap. The
528 bitmap must be non-empty. */
531 bitmap_first_set_bit (bitmap a
)
533 bitmap_element
*elt
= a
->first
;
539 bit_no
= elt
->indx
* BITMAP_ELEMENT_ALL_BITS
;
540 for (ix
= 0; ix
!= BITMAP_ELEMENT_WORDS
; ix
++)
542 word
= elt
->bits
[ix
];
548 bit_no
+= ix
* BITMAP_WORD_BITS
;
550 #if GCC_VERSION >= 3004
551 gcc_assert (sizeof(long) == sizeof (word
));
552 bit_no
+= __builtin_ctzl (word
);
554 /* Binary search for the first set bit. */
555 #if BITMAP_WORD_BITS > 64
556 #error "Fill out the table."
558 #if BITMAP_WORD_BITS > 32
559 if (!(word
& 0xffffffff))
560 word
>>= 32, bit_no
+= 32;
562 if (!(word
& 0xffff))
563 word
>>= 16, bit_no
+= 16;
565 word
>>= 8, bit_no
+= 8;
567 word
>>= 4, bit_no
+= 4;
569 word
>>= 2, bit_no
+= 2;
571 word
>>= 1, bit_no
+= 1;
573 gcc_assert (word
& 1);
582 bitmap_and (bitmap dst
, bitmap a
, bitmap b
)
584 bitmap_element
*dst_elt
= dst
->first
;
585 bitmap_element
*a_elt
= a
->first
;
586 bitmap_element
*b_elt
= b
->first
;
587 bitmap_element
*dst_prev
= NULL
;
589 gcc_assert (dst
!= a
&& dst
!= b
);
593 bitmap_copy (dst
, a
);
597 while (a_elt
&& b_elt
)
599 if (a_elt
->indx
< b_elt
->indx
)
601 else if (b_elt
->indx
< a_elt
->indx
)
605 /* Matching elts, generate A & B. */
610 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
612 dst_elt
->indx
= a_elt
->indx
;
613 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
615 BITMAP_WORD r
= a_elt
->bits
[ix
] & b_elt
->bits
[ix
];
617 dst_elt
->bits
[ix
] = r
;
623 dst_elt
= dst_elt
->next
;
629 bitmap_elt_clear_from (dst
, dst_elt
);
630 gcc_assert (!dst
->current
== !dst
->first
);
632 dst
->indx
= dst
->current
->indx
;
638 bitmap_and_into (bitmap a
, bitmap b
)
640 bitmap_element
*a_elt
= a
->first
;
641 bitmap_element
*b_elt
= b
->first
;
642 bitmap_element
*next
;
647 while (a_elt
&& b_elt
)
649 if (a_elt
->indx
< b_elt
->indx
)
652 bitmap_element_free (a
, a_elt
);
655 else if (b_elt
->indx
< a_elt
->indx
)
659 /* Matching elts, generate A &= B. */
663 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
665 BITMAP_WORD r
= a_elt
->bits
[ix
] & b_elt
->bits
[ix
];
672 bitmap_element_free (a
, a_elt
);
677 bitmap_elt_clear_from (a
, a_elt
);
678 gcc_assert (!a
->current
== !a
->first
);
679 gcc_assert (!a
->current
|| a
->indx
== a
->current
->indx
);
685 bitmap_and_compl (bitmap dst
, bitmap a
, bitmap b
)
687 bitmap_element
*dst_elt
= dst
->first
;
688 bitmap_element
*a_elt
= a
->first
;
689 bitmap_element
*b_elt
= b
->first
;
690 bitmap_element
*dst_prev
= NULL
;
692 gcc_assert (dst
!= a
&& dst
!= b
);
702 if (!b_elt
|| a_elt
->indx
< b_elt
->indx
)
706 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
708 dst_elt
->indx
= a_elt
->indx
;
709 memcpy (dst_elt
->bits
, a_elt
->bits
, sizeof (dst_elt
->bits
));
711 dst_elt
= dst_elt
->next
;
714 else if (b_elt
->indx
< a_elt
->indx
)
718 /* Matching elts, generate A & ~B. */
723 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
725 dst_elt
->indx
= a_elt
->indx
;
726 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
728 BITMAP_WORD r
= a_elt
->bits
[ix
] & ~b_elt
->bits
[ix
];
730 dst_elt
->bits
[ix
] = r
;
736 dst_elt
= dst_elt
->next
;
742 bitmap_elt_clear_from (dst
, dst_elt
);
743 gcc_assert (!dst
->current
== !dst
->first
);
745 dst
->indx
= dst
->current
->indx
;
748 /* A &= ~B. Returns true if A changes */
751 bitmap_and_compl_into (bitmap a
, bitmap b
)
753 bitmap_element
*a_elt
= a
->first
;
754 bitmap_element
*b_elt
= b
->first
;
755 bitmap_element
*next
;
756 BITMAP_WORD changed
= 0;
760 if (bitmap_empty_p (a
))
769 while (a_elt
&& b_elt
)
771 if (a_elt
->indx
< b_elt
->indx
)
773 else if (b_elt
->indx
< a_elt
->indx
)
777 /* Matching elts, generate A &= ~B. */
781 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
783 BITMAP_WORD cleared
= a_elt
->bits
[ix
] & b_elt
->bits
[ix
];
784 BITMAP_WORD r
= a_elt
->bits
[ix
] ^ cleared
;
792 bitmap_element_free (a
, a_elt
);
797 gcc_assert (!a
->current
== !a
->first
);
798 gcc_assert (!a
->current
|| a
->indx
== a
->current
->indx
);
802 /* DST = A | B. Return true if DST changes. */
805 bitmap_ior (bitmap dst
, bitmap a
, bitmap b
)
807 bitmap_element
*dst_elt
= dst
->first
;
808 bitmap_element
*a_elt
= a
->first
;
809 bitmap_element
*b_elt
= b
->first
;
810 bitmap_element
*dst_prev
= NULL
;
811 bool changed
= false;
813 gcc_assert (dst
!= a
&& dst
!= b
);
815 while (a_elt
|| b_elt
)
817 if (a_elt
&& b_elt
&& a_elt
->indx
== b_elt
->indx
)
819 /* Matching elts, generate A | B. */
822 if (!changed
&& dst_elt
&& dst_elt
->indx
== a_elt
->indx
)
824 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
826 BITMAP_WORD r
= a_elt
->bits
[ix
] | b_elt
->bits
[ix
];
828 if (r
!= dst_elt
->bits
[ix
])
830 dst_elt
->bits
[ix
] = r
;
839 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
840 dst_elt
->indx
= a_elt
->indx
;
841 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
843 BITMAP_WORD r
= a_elt
->bits
[ix
] | b_elt
->bits
[ix
];
845 dst_elt
->bits
[ix
] = r
;
851 dst_elt
= dst_elt
->next
;
855 /* Copy a single element. */
858 if (!b_elt
|| (a_elt
&& a_elt
->indx
< b_elt
->indx
))
869 if (!changed
&& dst_elt
&& dst_elt
->indx
== src
->indx
)
873 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
874 if (src
->bits
[ix
] != dst_elt
->bits
[ix
])
876 dst_elt
->bits
[ix
] = src
->bits
[ix
];
884 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
885 dst_elt
->indx
= src
->indx
;
886 memcpy (dst_elt
->bits
, src
->bits
, sizeof (dst_elt
->bits
));
890 dst_elt
= dst_elt
->next
;
897 bitmap_elt_clear_from (dst
, dst_elt
);
899 gcc_assert (!dst
->current
== !dst
->first
);
901 dst
->indx
= dst
->current
->indx
;
905 /* A |= B. Return true if A changes. */
908 bitmap_ior_into (bitmap a
, bitmap b
)
910 bitmap_element
*a_elt
= a
->first
;
911 bitmap_element
*b_elt
= b
->first
;
912 bitmap_element
*a_prev
= NULL
;
913 bool changed
= false;
920 if (!a_elt
|| b_elt
->indx
< a_elt
->indx
)
923 bitmap_element
*dst
= bitmap_elt_insert_after (a
, a_prev
);
925 dst
->indx
= b_elt
->indx
;
926 memcpy (dst
->bits
, b_elt
->bits
, sizeof (dst
->bits
));
931 else if (a_elt
->indx
< b_elt
->indx
)
938 /* Matching elts, generate A |= B. */
942 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
944 BITMAP_WORD r
= a_elt
->bits
[ix
] | b_elt
->bits
[ix
];
949 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
951 BITMAP_WORD r
= a_elt
->bits
[ix
] | b_elt
->bits
[ix
];
953 if (a_elt
->bits
[ix
] != r
)
964 gcc_assert (!a
->current
== !a
->first
);
966 a
->indx
= a
->current
->indx
;
973 bitmap_xor (bitmap dst
, bitmap a
, bitmap b
)
975 bitmap_element
*dst_elt
= dst
->first
;
976 bitmap_element
*a_elt
= a
->first
;
977 bitmap_element
*b_elt
= b
->first
;
978 bitmap_element
*dst_prev
= NULL
;
980 gcc_assert (dst
!= a
&& dst
!= b
);
987 while (a_elt
|| b_elt
)
989 if (a_elt
&& b_elt
&& a_elt
->indx
== b_elt
->indx
)
991 /* Matching elts, generate A ^ B. */
996 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
998 dst_elt
->indx
= a_elt
->indx
;
999 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
1001 BITMAP_WORD r
= a_elt
->bits
[ix
] ^ b_elt
->bits
[ix
];
1004 dst_elt
->bits
[ix
] = r
;
1006 a_elt
= a_elt
->next
;
1007 b_elt
= b_elt
->next
;
1011 dst_elt
= dst_elt
->next
;
1016 /* Copy a single element. */
1017 bitmap_element
*src
;
1019 if (!b_elt
|| (a_elt
&& a_elt
->indx
< b_elt
->indx
))
1022 a_elt
= a_elt
->next
;
1027 b_elt
= b_elt
->next
;
1031 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
1033 dst_elt
->indx
= src
->indx
;
1034 memcpy (dst_elt
->bits
, src
->bits
, sizeof (dst_elt
->bits
));
1036 dst_elt
= dst_elt
->next
;
1039 bitmap_elt_clear_from (dst
, dst_elt
);
1040 gcc_assert (!dst
->current
== !dst
->first
);
1042 dst
->indx
= dst
->current
->indx
;
1048 bitmap_xor_into (bitmap a
, bitmap b
)
1050 bitmap_element
*a_elt
= a
->first
;
1051 bitmap_element
*b_elt
= b
->first
;
1052 bitmap_element
*a_prev
= NULL
;
1062 if (!a_elt
|| b_elt
->indx
< a_elt
->indx
)
1065 bitmap_element
*dst
= bitmap_elt_insert_after (a
, a_prev
);
1067 dst
->indx
= b_elt
->indx
;
1068 memcpy (dst
->bits
, b_elt
->bits
, sizeof (dst
->bits
));
1070 b_elt
= b_elt
->next
;
1072 else if (a_elt
->indx
< b_elt
->indx
)
1075 a_elt
= a_elt
->next
;
1079 /* Matching elts, generate A ^= B. */
1081 BITMAP_WORD ior
= 0;
1082 bitmap_element
*next
= a_elt
->next
;
1084 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
1086 BITMAP_WORD r
= a_elt
->bits
[ix
] ^ b_elt
->bits
[ix
];
1089 a_elt
->bits
[ix
] = r
;
1091 b_elt
= b_elt
->next
;
1095 bitmap_element_free (a
, a_elt
);
1099 gcc_assert (!a
->current
== !a
->first
);
1101 a
->indx
= a
->current
->indx
;
1104 /* Return true if two bitmaps are identical.
1105 We do not bother with a check for pointer equality, as that never
1106 occurs in practice. */
1109 bitmap_equal_p (bitmap a
, bitmap b
)
1111 bitmap_element
*a_elt
;
1112 bitmap_element
*b_elt
;
1115 for (a_elt
= a
->first
, b_elt
= b
->first
;
1117 a_elt
= a_elt
->next
, b_elt
= b_elt
->next
)
1119 if (a_elt
->indx
!= b_elt
->indx
)
1121 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
1122 if (a_elt
->bits
[ix
] != b_elt
->bits
[ix
])
1125 return !a_elt
&& !b_elt
;
1128 /* Return true if A AND B is not empty. */
1131 bitmap_intersect_p (bitmap a
, bitmap b
)
1133 bitmap_element
*a_elt
;
1134 bitmap_element
*b_elt
;
1137 for (a_elt
= a
->first
, b_elt
= b
->first
;
1140 if (a_elt
->indx
< b_elt
->indx
)
1141 a_elt
= a_elt
->next
;
1142 else if (b_elt
->indx
< a_elt
->indx
)
1143 b_elt
= b_elt
->next
;
1146 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
1147 if (a_elt
->bits
[ix
] & b_elt
->bits
[ix
])
1149 a_elt
= a_elt
->next
;
1150 b_elt
= b_elt
->next
;
1156 /* Return true if A AND NOT B is not empty. */
1159 bitmap_intersect_compl_p (bitmap a
, bitmap b
)
1161 bitmap_element
*a_elt
;
1162 bitmap_element
*b_elt
;
1164 for (a_elt
= a
->first
, b_elt
= b
->first
;
1167 if (a_elt
->indx
< b_elt
->indx
)
1169 else if (b_elt
->indx
< a_elt
->indx
)
1170 b_elt
= b_elt
->next
;
1173 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
1174 if (a_elt
->bits
[ix
] & ~b_elt
->bits
[ix
])
1176 a_elt
= a_elt
->next
;
1177 b_elt
= b_elt
->next
;
1180 return a_elt
!= NULL
;
1184 /* DST = A | (FROM1 & ~FROM2). Return true if DST changes. */
1187 bitmap_ior_and_compl (bitmap dst
, bitmap a
, bitmap from1
, bitmap from2
)
1192 bitmap_initialize (&tmp
, &bitmap_default_obstack
);
1193 bitmap_and_compl (&tmp
, from1
, from2
);
1194 changed
= bitmap_ior (dst
, a
, &tmp
);
1195 bitmap_clear (&tmp
);
1200 /* A |= (FROM1 & ~FROM2). Return true if A changes. */
1203 bitmap_ior_and_compl_into (bitmap a
, bitmap from1
, bitmap from2
)
1208 bitmap_initialize (&tmp
, &bitmap_default_obstack
);
1209 bitmap_and_compl (&tmp
, from1
, from2
);
1210 changed
= bitmap_ior_into (a
, &tmp
);
1211 bitmap_clear (&tmp
);
1216 /* Debugging function to print out the contents of a bitmap. */
1219 debug_bitmap_file (FILE *file
, bitmap head
)
1221 bitmap_element
*ptr
;
1223 fprintf (file
, "\nfirst = %p current = %p indx = %u\n",
1224 (void *) head
->first
, (void *) head
->current
, head
->indx
);
1226 for (ptr
= head
->first
; ptr
; ptr
= ptr
->next
)
1228 unsigned int i
, j
, col
= 26;
1230 fprintf (file
, "\t%p next = %p prev = %p indx = %u\n\t\tbits = {",
1231 (void*) ptr
, (void*) ptr
->next
, (void*) ptr
->prev
, ptr
->indx
);
1233 for (i
= 0; i
< BITMAP_ELEMENT_WORDS
; i
++)
1234 for (j
= 0; j
< BITMAP_WORD_BITS
; j
++)
1235 if ((ptr
->bits
[i
] >> j
) & 1)
1239 fprintf (file
, "\n\t\t\t");
1243 fprintf (file
, " %u", (ptr
->indx
* BITMAP_ELEMENT_ALL_BITS
1244 + i
* BITMAP_WORD_BITS
+ j
));
1248 fprintf (file
, " }\n");
1252 /* Function to be called from the debugger to print the contents
1256 debug_bitmap (bitmap head
)
1258 debug_bitmap_file (stdout
, head
);
1261 /* Function to print out the contents of a bitmap. Unlike debug_bitmap_file,
1262 it does not print anything but the bits. */
1265 bitmap_print (FILE *file
, bitmap head
, const char *prefix
, const char *suffix
)
1267 const char *comma
= "";
1271 fputs (prefix
, file
);
1272 EXECUTE_IF_SET_IN_BITMAP (head
, 0, i
, bi
)
1274 fprintf (file
, "%s%d", comma
, i
);
1277 fputs (suffix
, file
);
1280 #include "gt-bitmap.h"