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
);
229 /* Create a new bitmap on an obstack. If BIT_OBSTACK is NULL, create
230 it on the default bitmap obstack. */
233 bitmap_obstack_alloc (bitmap_obstack
*bit_obstack
)
238 bit_obstack
= &bitmap_default_obstack
;
239 map
= bit_obstack
->heads
;
241 bit_obstack
->heads
= (void *)map
->first
;
243 map
= XOBNEW (&bit_obstack
->obstack
, bitmap_head
);
244 bitmap_initialize (map
, bit_obstack
);
249 /* Create a new GCd bitmap. */
252 bitmap_gc_alloc (void)
256 map
= GGC_NEW (struct bitmap_head_def
);
257 bitmap_initialize (map
, NULL
);
262 /* Release an obstack allocated bitmap. */
265 bitmap_obstack_free (bitmap map
)
270 map
->first
= (void *)map
->obstack
->heads
;
271 map
->obstack
->heads
= map
;
276 /* Return nonzero if all bits in an element are zero. */
279 bitmap_element_zerop (bitmap_element
*element
)
281 #if BITMAP_ELEMENT_WORDS == 2
282 return (element
->bits
[0] | element
->bits
[1]) == 0;
286 for (i
= 0; i
< BITMAP_ELEMENT_WORDS
; i
++)
287 if (element
->bits
[i
] != 0)
294 /* Link the bitmap element into the current bitmap linked list. */
297 bitmap_element_link (bitmap head
, bitmap_element
*element
)
299 unsigned int indx
= element
->indx
;
302 /* If this is the first and only element, set it in. */
303 if (head
->first
== 0)
305 element
->next
= element
->prev
= 0;
306 head
->first
= element
;
309 /* If this index is less than that of the current element, it goes someplace
310 before the current element. */
311 else if (indx
< head
->indx
)
313 for (ptr
= head
->current
;
314 ptr
->prev
!= 0 && ptr
->prev
->indx
> indx
;
319 ptr
->prev
->next
= element
;
321 head
->first
= element
;
323 element
->prev
= ptr
->prev
;
328 /* Otherwise, it must go someplace after the current element. */
331 for (ptr
= head
->current
;
332 ptr
->next
!= 0 && ptr
->next
->indx
< indx
;
337 ptr
->next
->prev
= element
;
339 element
->next
= ptr
->next
;
344 /* Set up so this is the first element searched. */
345 head
->current
= element
;
349 /* Insert a new uninitialized element into bitmap HEAD after element
350 ELT. If ELT is NULL, insert the element at the start. Return the
353 static bitmap_element
*
354 bitmap_elt_insert_after (bitmap head
, bitmap_element
*elt
)
356 bitmap_element
*node
= bitmap_element_allocate (head
);
361 head
->current
= node
;
362 node
->next
= head
->first
;
364 node
->next
->prev
= node
;
370 gcc_assert (head
->current
);
371 node
->next
= elt
->next
;
373 node
->next
->prev
= node
;
380 /* Copy a bitmap to another bitmap. */
383 bitmap_copy (bitmap to
, bitmap from
)
385 bitmap_element
*from_ptr
, *to_ptr
= 0;
389 /* Copy elements in forward direction one at a time. */
390 for (from_ptr
= from
->first
; from_ptr
; from_ptr
= from_ptr
->next
)
392 bitmap_element
*to_elt
= bitmap_element_allocate (to
);
394 to_elt
->indx
= from_ptr
->indx
;
395 memcpy (to_elt
->bits
, from_ptr
->bits
, sizeof (to_elt
->bits
));
397 /* Here we have a special case of bitmap_element_link, for the case
398 where we know the links are being entered in sequence. */
401 to
->first
= to
->current
= to_elt
;
402 to
->indx
= from_ptr
->indx
;
403 to_elt
->next
= to_elt
->prev
= 0;
407 to_elt
->prev
= to_ptr
;
409 to_ptr
->next
= to_elt
;
416 /* Find a bitmap element that would hold a bitmap's bit.
417 Update the `current' field even if we can't find an element that
418 would hold the bitmap's bit to make eventual allocation
421 static inline bitmap_element
*
422 bitmap_find_bit (bitmap head
, unsigned int bit
)
424 bitmap_element
*element
;
425 unsigned int indx
= bit
/ BITMAP_ELEMENT_ALL_BITS
;
427 if (head
->current
== 0
428 || head
->indx
== indx
)
429 return head
->current
;
431 if (head
->indx
< indx
)
432 /* INDX is beyond head->indx. Search from head->current
434 for (element
= head
->current
;
435 element
->next
!= 0 && element
->indx
< indx
;
436 element
= element
->next
)
439 else if (head
->indx
/ 2 < indx
)
440 /* INDX is less than head->indx and closer to head->indx than to
441 0. Search from head->current backward. */
442 for (element
= head
->current
;
443 element
->prev
!= 0 && element
->indx
> indx
;
444 element
= element
->prev
)
448 /* INDX is less than head->indx and closer to 0 than to
449 head->indx. Search from head->first forward. */
450 for (element
= head
->first
;
451 element
->next
!= 0 && element
->indx
< indx
;
452 element
= element
->next
)
455 /* `element' is the nearest to the one we want. If it's not the one we
456 want, the one we want doesn't exist. */
457 head
->current
= element
;
458 head
->indx
= element
->indx
;
459 if (element
!= 0 && element
->indx
!= indx
)
465 /* Clear a single bit in a bitmap. */
468 bitmap_clear_bit (bitmap head
, int bit
)
470 bitmap_element
*ptr
= bitmap_find_bit (head
, bit
);
474 unsigned bit_num
= bit
% BITMAP_WORD_BITS
;
475 unsigned word_num
= bit
/ BITMAP_WORD_BITS
% BITMAP_ELEMENT_WORDS
;
476 ptr
->bits
[word_num
] &= ~ (((BITMAP_WORD
) 1) << bit_num
);
478 /* If we cleared the entire word, free up the element. */
479 if (bitmap_element_zerop (ptr
))
480 bitmap_element_free (head
, ptr
);
484 /* Set a single bit in a bitmap. */
487 bitmap_set_bit (bitmap head
, int bit
)
489 bitmap_element
*ptr
= bitmap_find_bit (head
, bit
);
490 unsigned word_num
= bit
/ BITMAP_WORD_BITS
% BITMAP_ELEMENT_WORDS
;
491 unsigned bit_num
= bit
% BITMAP_WORD_BITS
;
492 BITMAP_WORD bit_val
= ((BITMAP_WORD
) 1) << bit_num
;
496 ptr
= bitmap_element_allocate (head
);
497 ptr
->indx
= bit
/ BITMAP_ELEMENT_ALL_BITS
;
498 ptr
->bits
[word_num
] = bit_val
;
499 bitmap_element_link (head
, ptr
);
502 ptr
->bits
[word_num
] |= bit_val
;
505 /* Return whether a bit is set within a bitmap. */
508 bitmap_bit_p (bitmap head
, int bit
)
514 ptr
= bitmap_find_bit (head
, bit
);
518 bit_num
= bit
% BITMAP_WORD_BITS
;
519 word_num
= bit
/ BITMAP_WORD_BITS
% BITMAP_ELEMENT_WORDS
;
521 return (ptr
->bits
[word_num
] >> bit_num
) & 1;
524 /* Return the bit number of the first set bit in the bitmap. The
525 bitmap must be non-empty. */
528 bitmap_first_set_bit (bitmap a
)
530 bitmap_element
*elt
= a
->first
;
536 bit_no
= elt
->indx
* BITMAP_ELEMENT_ALL_BITS
;
537 for (ix
= 0; ix
!= BITMAP_ELEMENT_WORDS
; ix
++)
539 word
= elt
->bits
[ix
];
545 bit_no
+= ix
* BITMAP_WORD_BITS
;
547 #if GCC_VERSION >= 3004
548 gcc_assert (sizeof(long) == sizeof (word
));
549 bit_no
+= __builtin_ctzl (word
);
551 /* Binary search for the first set bit. */
552 #if BITMAP_WORD_BITS > 64
553 #error "Fill out the table."
555 #if BITMAP_WORD_BITS > 32
556 if (!(word
& 0xffffffff))
557 word
>>= 32, bit_no
+= 32;
559 if (!(word
& 0xffff))
560 word
>>= 16, bit_no
+= 16;
562 word
>>= 8, bit_no
+= 8;
564 word
>>= 4, bit_no
+= 4;
566 word
>>= 2, bit_no
+= 2;
568 word
>>= 1, bit_no
+= 1;
570 gcc_assert (word
& 1);
579 bitmap_and (bitmap dst
, bitmap a
, bitmap b
)
581 bitmap_element
*dst_elt
= dst
->first
;
582 bitmap_element
*a_elt
= a
->first
;
583 bitmap_element
*b_elt
= b
->first
;
584 bitmap_element
*dst_prev
= NULL
;
586 gcc_assert (dst
!= a
&& dst
!= b
);
590 bitmap_copy (dst
, a
);
594 while (a_elt
&& b_elt
)
596 if (a_elt
->indx
< b_elt
->indx
)
598 else if (b_elt
->indx
< a_elt
->indx
)
602 /* Matching elts, generate A & B. */
607 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
609 dst_elt
->indx
= a_elt
->indx
;
610 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
612 BITMAP_WORD r
= a_elt
->bits
[ix
] & b_elt
->bits
[ix
];
614 dst_elt
->bits
[ix
] = r
;
620 dst_elt
= dst_elt
->next
;
626 bitmap_elt_clear_from (dst
, dst_elt
);
627 gcc_assert (!dst
->current
== !dst
->first
);
629 dst
->indx
= dst
->current
->indx
;
635 bitmap_and_into (bitmap a
, bitmap b
)
637 bitmap_element
*a_elt
= a
->first
;
638 bitmap_element
*b_elt
= b
->first
;
639 bitmap_element
*next
;
644 while (a_elt
&& b_elt
)
646 if (a_elt
->indx
< b_elt
->indx
)
649 bitmap_element_free (a
, a_elt
);
652 else if (b_elt
->indx
< a_elt
->indx
)
656 /* Matching elts, generate A &= B. */
660 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
662 BITMAP_WORD r
= a_elt
->bits
[ix
] & b_elt
->bits
[ix
];
669 bitmap_element_free (a
, a_elt
);
674 bitmap_elt_clear_from (a
, a_elt
);
675 gcc_assert (!a
->current
== !a
->first
);
676 gcc_assert (!a
->current
|| a
->indx
== a
->current
->indx
);
682 bitmap_and_compl (bitmap dst
, bitmap a
, bitmap b
)
684 bitmap_element
*dst_elt
= dst
->first
;
685 bitmap_element
*a_elt
= a
->first
;
686 bitmap_element
*b_elt
= b
->first
;
687 bitmap_element
*dst_prev
= NULL
;
689 gcc_assert (dst
!= a
&& dst
!= b
);
699 if (!b_elt
|| a_elt
->indx
< b_elt
->indx
)
703 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
705 dst_elt
->indx
= a_elt
->indx
;
706 memcpy (dst_elt
->bits
, a_elt
->bits
, sizeof (dst_elt
->bits
));
708 dst_elt
= dst_elt
->next
;
711 else if (b_elt
->indx
< a_elt
->indx
)
715 /* Matching elts, generate A & ~B. */
720 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
722 dst_elt
->indx
= a_elt
->indx
;
723 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
725 BITMAP_WORD r
= a_elt
->bits
[ix
] & ~b_elt
->bits
[ix
];
727 dst_elt
->bits
[ix
] = r
;
733 dst_elt
= dst_elt
->next
;
739 bitmap_elt_clear_from (dst
, dst_elt
);
740 gcc_assert (!dst
->current
== !dst
->first
);
742 dst
->indx
= dst
->current
->indx
;
745 /* A &= ~B. Returns true if A changes */
748 bitmap_and_compl_into (bitmap a
, bitmap b
)
750 bitmap_element
*a_elt
= a
->first
;
751 bitmap_element
*b_elt
= b
->first
;
752 bitmap_element
*next
;
753 BITMAP_WORD changed
= 0;
757 if (bitmap_empty_p (a
))
766 while (a_elt
&& b_elt
)
768 if (a_elt
->indx
< b_elt
->indx
)
770 else if (b_elt
->indx
< a_elt
->indx
)
774 /* Matching elts, generate A &= ~B. */
778 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
780 BITMAP_WORD cleared
= a_elt
->bits
[ix
] & b_elt
->bits
[ix
];
781 BITMAP_WORD r
= a_elt
->bits
[ix
] ^ cleared
;
789 bitmap_element_free (a
, a_elt
);
794 gcc_assert (!a
->current
== !a
->first
);
795 gcc_assert (!a
->current
|| a
->indx
== a
->current
->indx
);
799 /* DST = A | B. Return true if DST changes. */
802 bitmap_ior (bitmap dst
, bitmap a
, bitmap b
)
804 bitmap_element
*dst_elt
= dst
->first
;
805 bitmap_element
*a_elt
= a
->first
;
806 bitmap_element
*b_elt
= b
->first
;
807 bitmap_element
*dst_prev
= NULL
;
808 bool changed
= false;
810 gcc_assert (dst
!= a
&& dst
!= b
);
812 while (a_elt
|| b_elt
)
814 if (a_elt
&& b_elt
&& a_elt
->indx
== b_elt
->indx
)
816 /* Matching elts, generate A | B. */
819 if (!changed
&& dst_elt
&& dst_elt
->indx
== a_elt
->indx
)
821 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
823 BITMAP_WORD r
= a_elt
->bits
[ix
] | b_elt
->bits
[ix
];
825 if (r
!= dst_elt
->bits
[ix
])
827 dst_elt
->bits
[ix
] = r
;
836 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
837 dst_elt
->indx
= a_elt
->indx
;
838 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
840 BITMAP_WORD r
= a_elt
->bits
[ix
] | b_elt
->bits
[ix
];
842 dst_elt
->bits
[ix
] = r
;
848 dst_elt
= dst_elt
->next
;
852 /* Copy a single element. */
855 if (!b_elt
|| (a_elt
&& a_elt
->indx
< b_elt
->indx
))
866 if (!changed
&& dst_elt
&& dst_elt
->indx
== src
->indx
)
870 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
871 if (src
->bits
[ix
] != dst_elt
->bits
[ix
])
873 dst_elt
->bits
[ix
] = src
->bits
[ix
];
881 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
882 dst_elt
->indx
= src
->indx
;
883 memcpy (dst_elt
->bits
, src
->bits
, sizeof (dst_elt
->bits
));
887 dst_elt
= dst_elt
->next
;
894 bitmap_elt_clear_from (dst
, dst_elt
);
896 gcc_assert (!dst
->current
== !dst
->first
);
898 dst
->indx
= dst
->current
->indx
;
902 /* A |= B. Return true if A changes. */
905 bitmap_ior_into (bitmap a
, bitmap b
)
907 bitmap_element
*a_elt
= a
->first
;
908 bitmap_element
*b_elt
= b
->first
;
909 bitmap_element
*a_prev
= NULL
;
910 bool changed
= false;
917 if (!a_elt
|| b_elt
->indx
< a_elt
->indx
)
920 bitmap_element
*dst
= bitmap_elt_insert_after (a
, a_prev
);
922 dst
->indx
= b_elt
->indx
;
923 memcpy (dst
->bits
, b_elt
->bits
, sizeof (dst
->bits
));
928 else if (a_elt
->indx
< b_elt
->indx
)
935 /* Matching elts, generate A |= B. */
939 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
941 BITMAP_WORD r
= a_elt
->bits
[ix
] | b_elt
->bits
[ix
];
946 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
948 BITMAP_WORD r
= a_elt
->bits
[ix
] | b_elt
->bits
[ix
];
950 if (a_elt
->bits
[ix
] != r
)
961 gcc_assert (!a
->current
== !a
->first
);
963 a
->indx
= a
->current
->indx
;
970 bitmap_xor (bitmap dst
, bitmap a
, bitmap b
)
972 bitmap_element
*dst_elt
= dst
->first
;
973 bitmap_element
*a_elt
= a
->first
;
974 bitmap_element
*b_elt
= b
->first
;
975 bitmap_element
*dst_prev
= NULL
;
977 gcc_assert (dst
!= a
&& dst
!= b
);
984 while (a_elt
|| b_elt
)
986 if (a_elt
&& b_elt
&& a_elt
->indx
== b_elt
->indx
)
988 /* Matching elts, generate A ^ B. */
993 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
995 dst_elt
->indx
= a_elt
->indx
;
996 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
998 BITMAP_WORD r
= a_elt
->bits
[ix
] ^ b_elt
->bits
[ix
];
1001 dst_elt
->bits
[ix
] = r
;
1003 a_elt
= a_elt
->next
;
1004 b_elt
= b_elt
->next
;
1008 dst_elt
= dst_elt
->next
;
1013 /* Copy a single element. */
1014 bitmap_element
*src
;
1016 if (!b_elt
|| (a_elt
&& a_elt
->indx
< b_elt
->indx
))
1019 a_elt
= a_elt
->next
;
1024 b_elt
= b_elt
->next
;
1028 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
1030 dst_elt
->indx
= src
->indx
;
1031 memcpy (dst_elt
->bits
, src
->bits
, sizeof (dst_elt
->bits
));
1033 dst_elt
= dst_elt
->next
;
1036 bitmap_elt_clear_from (dst
, dst_elt
);
1037 gcc_assert (!dst
->current
== !dst
->first
);
1039 dst
->indx
= dst
->current
->indx
;
1045 bitmap_xor_into (bitmap a
, bitmap b
)
1047 bitmap_element
*a_elt
= a
->first
;
1048 bitmap_element
*b_elt
= b
->first
;
1049 bitmap_element
*a_prev
= NULL
;
1059 if (!a_elt
|| b_elt
->indx
< a_elt
->indx
)
1062 bitmap_element
*dst
= bitmap_elt_insert_after (a
, a_prev
);
1064 dst
->indx
= b_elt
->indx
;
1065 memcpy (dst
->bits
, b_elt
->bits
, sizeof (dst
->bits
));
1067 b_elt
= b_elt
->next
;
1069 else if (a_elt
->indx
< b_elt
->indx
)
1072 a_elt
= a_elt
->next
;
1076 /* Matching elts, generate A ^= B. */
1078 BITMAP_WORD ior
= 0;
1079 bitmap_element
*next
= a_elt
->next
;
1081 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
1083 BITMAP_WORD r
= a_elt
->bits
[ix
] ^ b_elt
->bits
[ix
];
1086 a_elt
->bits
[ix
] = r
;
1088 b_elt
= b_elt
->next
;
1092 bitmap_element_free (a
, a_elt
);
1096 gcc_assert (!a
->current
== !a
->first
);
1098 a
->indx
= a
->current
->indx
;
1101 /* Return true if two bitmaps are identical.
1102 We do not bother with a check for pointer equality, as that never
1103 occurs in practice. */
1106 bitmap_equal_p (bitmap a
, bitmap b
)
1108 bitmap_element
*a_elt
;
1109 bitmap_element
*b_elt
;
1112 for (a_elt
= a
->first
, b_elt
= b
->first
;
1114 a_elt
= a_elt
->next
, b_elt
= b_elt
->next
)
1116 if (a_elt
->indx
!= b_elt
->indx
)
1118 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
1119 if (a_elt
->bits
[ix
] != b_elt
->bits
[ix
])
1122 return !a_elt
&& !b_elt
;
1125 /* Return true if A AND B is not empty. */
1128 bitmap_intersect_p (bitmap a
, bitmap b
)
1130 bitmap_element
*a_elt
;
1131 bitmap_element
*b_elt
;
1134 for (a_elt
= a
->first
, b_elt
= b
->first
;
1137 if (a_elt
->indx
< b_elt
->indx
)
1138 a_elt
= a_elt
->next
;
1139 else if (b_elt
->indx
< a_elt
->indx
)
1140 b_elt
= b_elt
->next
;
1143 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
1144 if (a_elt
->bits
[ix
] & b_elt
->bits
[ix
])
1146 a_elt
= a_elt
->next
;
1147 b_elt
= b_elt
->next
;
1153 /* Return true if A AND NOT B is not empty. */
1156 bitmap_intersect_compl_p (bitmap a
, bitmap b
)
1158 bitmap_element
*a_elt
;
1159 bitmap_element
*b_elt
;
1161 for (a_elt
= a
->first
, b_elt
= b
->first
;
1164 if (a_elt
->indx
< b_elt
->indx
)
1166 else if (b_elt
->indx
< a_elt
->indx
)
1167 b_elt
= b_elt
->next
;
1170 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
1171 if (a_elt
->bits
[ix
] & ~b_elt
->bits
[ix
])
1173 a_elt
= a_elt
->next
;
1174 b_elt
= b_elt
->next
;
1177 return a_elt
!= NULL
;
1181 /* DST = A | (FROM1 & ~FROM2). Return true if DST changes. */
1184 bitmap_ior_and_compl (bitmap dst
, bitmap a
, bitmap from1
, bitmap from2
)
1189 bitmap_initialize (&tmp
, &bitmap_default_obstack
);
1190 bitmap_and_compl (&tmp
, from1
, from2
);
1191 changed
= bitmap_ior (dst
, a
, &tmp
);
1192 bitmap_clear (&tmp
);
1197 /* A |= (FROM1 & ~FROM2). Return true if A changes. */
1200 bitmap_ior_and_compl_into (bitmap a
, bitmap from1
, bitmap from2
)
1205 bitmap_initialize (&tmp
, &bitmap_default_obstack
);
1206 bitmap_and_compl (&tmp
, from1
, from2
);
1207 changed
= bitmap_ior_into (a
, &tmp
);
1208 bitmap_clear (&tmp
);
1213 /* Debugging function to print out the contents of a bitmap. */
1216 debug_bitmap_file (FILE *file
, bitmap head
)
1218 bitmap_element
*ptr
;
1220 fprintf (file
, "\nfirst = %p current = %p indx = %u\n",
1221 (void *) head
->first
, (void *) head
->current
, head
->indx
);
1223 for (ptr
= head
->first
; ptr
; ptr
= ptr
->next
)
1225 unsigned int i
, j
, col
= 26;
1227 fprintf (file
, "\t%p next = %p prev = %p indx = %u\n\t\tbits = {",
1228 (void*) ptr
, (void*) ptr
->next
, (void*) ptr
->prev
, ptr
->indx
);
1230 for (i
= 0; i
< BITMAP_ELEMENT_WORDS
; i
++)
1231 for (j
= 0; j
< BITMAP_WORD_BITS
; j
++)
1232 if ((ptr
->bits
[i
] >> j
) & 1)
1236 fprintf (file
, "\n\t\t\t");
1240 fprintf (file
, " %u", (ptr
->indx
* BITMAP_ELEMENT_ALL_BITS
1241 + i
* BITMAP_WORD_BITS
+ j
));
1245 fprintf (file
, " }\n");
1249 /* Function to be called from the debugger to print the contents
1253 debug_bitmap (bitmap head
)
1255 debug_bitmap_file (stdout
, head
);
1258 /* Function to print out the contents of a bitmap. Unlike debug_bitmap_file,
1259 it does not print anything but the bits. */
1262 bitmap_print (FILE *file
, bitmap head
, const char *prefix
, const char *suffix
)
1264 const char *comma
= "";
1268 fputs (prefix
, file
);
1269 EXECUTE_IF_SET_IN_BITMAP (head
, 0, i
, bi
)
1271 fprintf (file
, "%s%d", comma
, i
);
1274 fputs (suffix
, file
);
1277 #include "gt-bitmap.h"