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"
32 /* Obstack to allocate bitmap elements from. */
38 #define INLINE __inline__
43 bitmap_element bitmap_zero_bits
; /* An element of all zero bits. */
44 bitmap_obstack bitmap_default_obstack
; /* The default bitmap obstack. */
45 static GTY((deletable
)) bitmap_element
*bitmap_ggc_free
; /* Freelist of
48 static void bitmap_elem_to_freelist (bitmap
, bitmap_element
*);
49 static void bitmap_element_free (bitmap
, bitmap_element
*);
50 static bitmap_element
*bitmap_element_allocate (bitmap
);
51 static int bitmap_element_zerop (bitmap_element
*);
52 static void bitmap_element_link (bitmap
, bitmap_element
*);
53 static bitmap_element
*bitmap_elt_insert_after (bitmap
, bitmap_element
*);
54 static void bitmap_elt_clear_from (bitmap
, bitmap_element
*);
55 static bitmap_element
*bitmap_find_bit (bitmap
, unsigned int);
58 /* Add ELEM to the appropriate freelist. */
60 bitmap_elem_to_freelist (bitmap head
, bitmap_element
*elt
)
62 bitmap_obstack
*bit_obstack
= head
->obstack
;
66 elt
->next
= bit_obstack
->elements
;
67 bit_obstack
->elements
= elt
;
71 elt
->next
= bitmap_ggc_free
;
72 bitmap_ggc_free
= elt
;
76 /* Free a bitmap element. Since these are allocated off the
77 bitmap_obstack, "free" actually means "put onto the freelist". */
80 bitmap_element_free (bitmap head
, bitmap_element
*elt
)
82 bitmap_element
*next
= elt
->next
;
83 bitmap_element
*prev
= elt
->prev
;
91 if (head
->first
== elt
)
94 /* Since the first thing we try is to insert before current,
95 make current the next entry in preference to the previous. */
96 if (head
->current
== elt
)
98 head
->current
= next
!= 0 ? next
: prev
;
100 head
->indx
= head
->current
->indx
;
102 bitmap_elem_to_freelist (head
, elt
);
105 /* Allocate a bitmap element. The bits are cleared, but nothing else is. */
107 static INLINE bitmap_element
*
108 bitmap_element_allocate (bitmap head
)
110 bitmap_element
*element
;
111 bitmap_obstack
*bit_obstack
= head
->obstack
;
115 element
= bit_obstack
->elements
;
118 bit_obstack
->elements
= element
->next
;
120 element
= XOBNEW (&bit_obstack
->obstack
, bitmap_element
);
124 element
= bitmap_ggc_free
;
126 bitmap_ggc_free
= element
->next
;
128 element
= GGC_NEW (bitmap_element
);
131 memset (element
->bits
, 0, sizeof (element
->bits
));
136 /* Remove ELT and all following elements from bitmap HEAD. */
139 bitmap_elt_clear_from (bitmap head
, bitmap_element
*elt
)
141 bitmap_element
*next
;
146 bitmap_element_free (head
, elt
);
151 /* Clear a bitmap by freeing the linked list. */
154 bitmap_clear (bitmap head
)
156 bitmap_element
*element
, *next
;
158 for (element
= head
->first
; element
!= 0; element
= next
)
160 next
= element
->next
;
161 bitmap_elem_to_freelist (head
, element
);
164 head
->first
= head
->current
= 0;
167 /* Initialize a bitmap obstack. If BIT_OBSTACK is NULL, initialize
168 the default bitmap obstack. */
171 bitmap_obstack_initialize (bitmap_obstack
*bit_obstack
)
174 bit_obstack
= &bitmap_default_obstack
;
176 #if !defined(__GNUC__) || (__GNUC__ < 2)
177 #define __alignof__(type) 0
180 bit_obstack
->elements
= NULL
;
181 bit_obstack
->heads
= NULL
;
182 obstack_specify_allocation (&bit_obstack
->obstack
, OBSTACK_CHUNK_SIZE
,
183 __alignof__ (bitmap_element
),
188 /* Release the memory from a bitmap obstack. If BIT_OBSTACK is NULL,
189 release the default bitmap obstack. */
192 bitmap_obstack_release (bitmap_obstack
*bit_obstack
)
195 bit_obstack
= &bitmap_default_obstack
;
197 bit_obstack
->elements
= NULL
;
198 bit_obstack
->heads
= NULL
;
199 obstack_free (&bit_obstack
->obstack
, NULL
);
202 /* Create a new bitmap on an obstack. If BIT_OBSTACK is NULL, create
203 it on the default bitmap obstack. */
206 bitmap_obstack_alloc (bitmap_obstack
*bit_obstack
)
211 bit_obstack
= &bitmap_default_obstack
;
212 map
= bit_obstack
->heads
;
214 bit_obstack
->heads
= (void *)map
->first
;
216 map
= XOBNEW (&bit_obstack
->obstack
, bitmap_head
);
217 bitmap_initialize (map
, bit_obstack
);
222 /* Create a new GCd bitmap. */
225 bitmap_gc_alloc (void)
229 map
= GGC_NEW (struct bitmap_head_def
);
230 bitmap_initialize (map
, NULL
);
235 /* Create a new malloced bitmap. Elements will be allocated from the
236 default bitmap obstack. */
239 bitmap_malloc_alloc (void)
243 map
= xmalloc (sizeof (bitmap_head
));
244 bitmap_initialize (map
, &bitmap_default_obstack
);
249 /* Release an obstack allocated bitmap. */
252 bitmap_obstack_free (bitmap map
)
255 map
->first
= (void *)map
->obstack
->heads
;
256 map
->obstack
->heads
= map
;
259 /* Release a malloc allocated bitmap. */
262 bitmap_malloc_free (bitmap map
)
269 /* Return nonzero if all bits in an element are zero. */
272 bitmap_element_zerop (bitmap_element
*element
)
274 #if BITMAP_ELEMENT_WORDS == 2
275 return (element
->bits
[0] | element
->bits
[1]) == 0;
279 for (i
= 0; i
< BITMAP_ELEMENT_WORDS
; i
++)
280 if (element
->bits
[i
] != 0)
287 /* Link the bitmap element into the current bitmap linked list. */
290 bitmap_element_link (bitmap head
, bitmap_element
*element
)
292 unsigned int indx
= element
->indx
;
295 /* If this is the first and only element, set it in. */
296 if (head
->first
== 0)
298 element
->next
= element
->prev
= 0;
299 head
->first
= element
;
302 /* If this index is less than that of the current element, it goes someplace
303 before the current element. */
304 else if (indx
< head
->indx
)
306 for (ptr
= head
->current
;
307 ptr
->prev
!= 0 && ptr
->prev
->indx
> indx
;
312 ptr
->prev
->next
= element
;
314 head
->first
= element
;
316 element
->prev
= ptr
->prev
;
321 /* Otherwise, it must go someplace after the current element. */
324 for (ptr
= head
->current
;
325 ptr
->next
!= 0 && ptr
->next
->indx
< indx
;
330 ptr
->next
->prev
= element
;
332 element
->next
= ptr
->next
;
337 /* Set up so this is the first element searched. */
338 head
->current
= element
;
342 /* Insert a new uninitialized element into bitmap HEAD after element
343 ELT. If ELT is NULL, insert the element at the start. Return the
346 static bitmap_element
*
347 bitmap_elt_insert_after (bitmap head
, bitmap_element
*elt
)
349 bitmap_element
*node
= bitmap_element_allocate (head
);
354 head
->current
= node
;
355 node
->next
= head
->first
;
357 node
->next
->prev
= node
;
363 gcc_assert (head
->current
);
364 node
->next
= elt
->next
;
366 node
->next
->prev
= node
;
373 /* Copy a bitmap to another bitmap. */
376 bitmap_copy (bitmap to
, bitmap from
)
378 bitmap_element
*from_ptr
, *to_ptr
= 0;
379 #if BITMAP_ELEMENT_WORDS != 2
385 /* Copy elements in forward direction one at a time. */
386 for (from_ptr
= from
->first
; from_ptr
; from_ptr
= from_ptr
->next
)
388 bitmap_element
*to_elt
= bitmap_element_allocate (to
);
390 to_elt
->indx
= from_ptr
->indx
;
392 #if BITMAP_ELEMENT_WORDS == 2
393 to_elt
->bits
[0] = from_ptr
->bits
[0];
394 to_elt
->bits
[1] = from_ptr
->bits
[1];
396 for (i
= 0; i
< BITMAP_ELEMENT_WORDS
; i
++)
397 to_elt
->bits
[i
] = from_ptr
->bits
[i
];
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 for (element
= head
->current
;
436 element
->prev
!= 0 && element
->indx
> indx
;
437 element
= element
->prev
)
441 for (element
= head
->current
;
442 element
->next
!= 0 && element
->indx
< indx
;
443 element
= element
->next
)
446 /* `element' is the nearest to the one we want. If it's not the one we
447 want, the one we want doesn't exist. */
448 head
->current
= element
;
449 head
->indx
= element
->indx
;
450 if (element
!= 0 && element
->indx
!= indx
)
456 /* Clear a single bit in a bitmap. */
459 bitmap_clear_bit (bitmap head
, int bit
)
461 bitmap_element
*ptr
= bitmap_find_bit (head
, bit
);
465 unsigned bit_num
= bit
% BITMAP_WORD_BITS
;
466 unsigned word_num
= bit
/ BITMAP_WORD_BITS
% BITMAP_ELEMENT_WORDS
;
467 ptr
->bits
[word_num
] &= ~ (((BITMAP_WORD
) 1) << bit_num
);
469 /* If we cleared the entire word, free up the element. */
470 if (bitmap_element_zerop (ptr
))
471 bitmap_element_free (head
, ptr
);
475 /* Set a single bit in a bitmap. */
478 bitmap_set_bit (bitmap head
, int bit
)
480 bitmap_element
*ptr
= bitmap_find_bit (head
, bit
);
481 unsigned word_num
= bit
/ BITMAP_WORD_BITS
% BITMAP_ELEMENT_WORDS
;
482 unsigned bit_num
= bit
% BITMAP_WORD_BITS
;
483 BITMAP_WORD bit_val
= ((BITMAP_WORD
) 1) << bit_num
;
487 ptr
= bitmap_element_allocate (head
);
488 ptr
->indx
= bit
/ BITMAP_ELEMENT_ALL_BITS
;
489 ptr
->bits
[word_num
] = bit_val
;
490 bitmap_element_link (head
, ptr
);
493 ptr
->bits
[word_num
] |= bit_val
;
496 /* Return whether a bit is set within a bitmap. */
499 bitmap_bit_p (bitmap head
, int bit
)
505 ptr
= bitmap_find_bit (head
, bit
);
509 bit_num
= bit
% BITMAP_WORD_BITS
;
510 word_num
= bit
/ BITMAP_WORD_BITS
% BITMAP_ELEMENT_WORDS
;
512 return (ptr
->bits
[word_num
] >> bit_num
) & 1;
515 /* Return the bit number of the first set bit in the bitmap. The
516 bitmap must be non-empty. */
519 bitmap_first_set_bit (bitmap a
)
521 bitmap_element
*elt
= a
->first
;
527 bit_no
= elt
->indx
* BITMAP_ELEMENT_ALL_BITS
;
528 for (ix
= 0; ix
!= BITMAP_ELEMENT_WORDS
; ix
++)
530 word
= elt
->bits
[ix
];
536 bit_no
+= ix
* BITMAP_WORD_BITS
;
538 #if GCC_VERSION >= 3004
539 gcc_assert (sizeof(long) == sizeof (word
));
540 bit_no
+= __builtin_ctzl (word
);
542 /* Binary search for the first set bit. */
543 #if BITMAP_WORD_BITS > 64
544 #error "Fill out the table."
546 #if BITMAP_WORD_BITS > 32
547 if (!(word
& 0xffffffff))
548 word
>>= 32, bit_no
+= 32;
550 if (!(word
& 0xffff))
551 word
>>= 16, bit_no
+= 16;
553 word
>>= 8, bit_no
+= 8;
555 word
>>= 4, bit_no
+= 4;
557 word
>>= 2, bit_no
+= 2;
559 word
>>= 1, bit_no
+= 1;
561 gcc_assert (word
& 1);
570 bitmap_and (bitmap dst
, bitmap a
, bitmap b
)
572 bitmap_element
*dst_elt
= dst
->first
;
573 bitmap_element
*a_elt
= a
->first
;
574 bitmap_element
*b_elt
= b
->first
;
575 bitmap_element
*dst_prev
= NULL
;
577 gcc_assert (dst
!= a
&& dst
!= b
&& a
!= b
);
578 while (a_elt
&& b_elt
)
580 if (a_elt
->indx
< b_elt
->indx
)
582 else if (b_elt
->indx
< a_elt
->indx
)
586 /* Matching elts, generate A & B. */
591 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
593 dst_elt
->indx
= a_elt
->indx
;
594 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
596 BITMAP_WORD r
= a_elt
->bits
[ix
] & b_elt
->bits
[ix
];
598 dst_elt
->bits
[ix
] = r
;
604 dst_elt
= dst_elt
->next
;
610 bitmap_elt_clear_from (dst
, dst_elt
);
611 gcc_assert (!dst
->current
== !dst
->first
);
613 dst
->indx
= dst
->current
->indx
;
619 bitmap_and_into (bitmap a
, bitmap b
)
621 bitmap_element
*a_elt
= a
->first
;
622 bitmap_element
*b_elt
= b
->first
;
623 bitmap_element
*next
;
626 while (a_elt
&& b_elt
)
628 if (a_elt
->indx
< b_elt
->indx
)
631 bitmap_element_free (a
, a_elt
);
634 else if (b_elt
->indx
< a_elt
->indx
)
638 /* Matching elts, generate A &= B. */
642 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
644 BITMAP_WORD r
= a_elt
->bits
[ix
] & b_elt
->bits
[ix
];
651 bitmap_element_free (a
, a_elt
);
656 bitmap_elt_clear_from (a
, a_elt
);
657 gcc_assert (!a
->current
== !a
->first
);
658 gcc_assert (!a
->current
|| a
->indx
== a
->current
->indx
);
664 bitmap_and_compl (bitmap dst
, bitmap a
, bitmap b
)
666 bitmap_element
*dst_elt
= dst
->first
;
667 bitmap_element
*a_elt
= a
->first
;
668 bitmap_element
*b_elt
= b
->first
;
669 bitmap_element
*dst_prev
= NULL
;
671 gcc_assert (dst
!= a
&& dst
!= b
&& a
!= b
);
675 if (!b_elt
|| a_elt
->indx
< b_elt
->indx
)
679 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
681 dst_elt
->indx
= a_elt
->indx
;
682 memcpy (dst_elt
->bits
, a_elt
->bits
, sizeof (dst_elt
->bits
));
684 dst_elt
= dst_elt
->next
;
687 else if (b_elt
->indx
< a_elt
->indx
)
691 /* Matching elts, generate A & ~B. */
696 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
698 dst_elt
->indx
= a_elt
->indx
;
699 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
701 BITMAP_WORD r
= a_elt
->bits
[ix
] & ~b_elt
->bits
[ix
];
703 dst_elt
->bits
[ix
] = r
;
709 dst_elt
= dst_elt
->next
;
715 bitmap_elt_clear_from (dst
, dst_elt
);
716 gcc_assert (!dst
->current
== !dst
->first
);
718 dst
->indx
= dst
->current
->indx
;
724 bitmap_and_compl_into (bitmap a
, bitmap b
)
726 bitmap_element
*a_elt
= a
->first
;
727 bitmap_element
*b_elt
= b
->first
;
728 bitmap_element
*next
;
731 while (a_elt
&& b_elt
)
733 if (a_elt
->indx
< b_elt
->indx
)
735 else if (b_elt
->indx
< a_elt
->indx
)
739 /* Matching elts, generate A &= ~B. */
743 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
745 BITMAP_WORD r
= a_elt
->bits
[ix
] & ~b_elt
->bits
[ix
];
752 bitmap_element_free (a
, a_elt
);
757 gcc_assert (!a
->current
== !a
->first
);
758 gcc_assert (!a
->current
|| a
->indx
== a
->current
->indx
);
761 /* DST = A | B. Return true if DST changes. */
764 bitmap_ior (bitmap dst
, bitmap a
, bitmap b
)
766 bitmap_element
*dst_elt
= dst
->first
;
767 bitmap_element
*a_elt
= a
->first
;
768 bitmap_element
*b_elt
= b
->first
;
769 bitmap_element
*dst_prev
= NULL
;
770 bool changed
= false;
772 gcc_assert (dst
!= a
&& dst
!= b
&& a
!= b
);
773 while (a_elt
|| b_elt
)
775 if (a_elt
&& b_elt
&& a_elt
->indx
== b_elt
->indx
)
777 /* Matching elts, generate A | B. */
780 if (!changed
&& dst_elt
&& dst_elt
->indx
== a_elt
->indx
)
782 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
784 BITMAP_WORD r
= a_elt
->bits
[ix
] | b_elt
->bits
[ix
];
786 if (r
!= dst_elt
->bits
[ix
])
788 dst_elt
->bits
[ix
] = r
;
797 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
798 dst_elt
->indx
= a_elt
->indx
;
799 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
801 BITMAP_WORD r
= a_elt
->bits
[ix
] | b_elt
->bits
[ix
];
803 dst_elt
->bits
[ix
] = r
;
809 dst_elt
= dst_elt
->next
;
813 /* Copy a single element. */
816 if (!b_elt
|| (a_elt
&& a_elt
->indx
< b_elt
->indx
))
827 if (!changed
&& dst_elt
&& dst_elt
->indx
== src
->indx
)
831 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
832 if (src
->bits
[ix
] != dst_elt
->bits
[ix
])
834 dst_elt
->bits
[ix
] = src
->bits
[ix
];
842 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
843 dst_elt
->indx
= src
->indx
;
844 memcpy (dst_elt
->bits
, src
->bits
, sizeof (dst_elt
->bits
));
848 dst_elt
= dst_elt
->next
;
855 bitmap_elt_clear_from (dst
, dst_elt
);
857 gcc_assert (!dst
->current
== !dst
->first
);
859 dst
->indx
= dst
->current
->indx
;
863 /* A |= B. Return true if A changes. */
866 bitmap_ior_into (bitmap a
, bitmap b
)
868 bitmap_element
*a_elt
= a
->first
;
869 bitmap_element
*b_elt
= b
->first
;
870 bitmap_element
*a_prev
= NULL
;
871 bool changed
= false;
876 if (!a_elt
|| b_elt
->indx
< a_elt
->indx
)
879 bitmap_element
*dst
= bitmap_elt_insert_after (a
, a_prev
);
881 dst
->indx
= b_elt
->indx
;
882 memcpy (dst
->bits
, b_elt
->bits
, sizeof (dst
->bits
));
887 else if (a_elt
->indx
< b_elt
->indx
)
894 /* Matching elts, generate A |= B. */
898 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
900 BITMAP_WORD r
= a_elt
->bits
[ix
] | b_elt
->bits
[ix
];
905 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
907 BITMAP_WORD r
= a_elt
->bits
[ix
] | b_elt
->bits
[ix
];
909 if (a_elt
->bits
[ix
] != r
)
920 gcc_assert (!a
->current
== !a
->first
);
922 a
->indx
= a
->current
->indx
;
929 bitmap_xor (bitmap dst
, bitmap a
, bitmap b
)
931 bitmap_element
*dst_elt
= dst
->first
;
932 bitmap_element
*a_elt
= a
->first
;
933 bitmap_element
*b_elt
= b
->first
;
934 bitmap_element
*dst_prev
= NULL
;
936 gcc_assert (dst
!= a
&& dst
!= b
&& a
!= b
);
937 while (a_elt
|| b_elt
)
939 if (a_elt
&& b_elt
&& a_elt
->indx
== b_elt
->indx
)
941 /* Matching elts, generate A ^ B. */
946 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
948 dst_elt
->indx
= a_elt
->indx
;
949 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
951 BITMAP_WORD r
= a_elt
->bits
[ix
] ^ b_elt
->bits
[ix
];
954 dst_elt
->bits
[ix
] = r
;
961 dst_elt
= dst_elt
->next
;
966 /* Copy a single element. */
969 if (!b_elt
|| (a_elt
&& a_elt
->indx
< b_elt
->indx
))
981 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
983 dst_elt
->indx
= src
->indx
;
984 memcpy (dst_elt
->bits
, src
->bits
, sizeof (dst_elt
->bits
));
986 dst_elt
= dst_elt
->next
;
989 bitmap_elt_clear_from (dst
, dst_elt
);
990 gcc_assert (!dst
->current
== !dst
->first
);
992 dst
->indx
= dst
->current
->indx
;
998 bitmap_xor_into (bitmap a
, bitmap b
)
1000 bitmap_element
*a_elt
= a
->first
;
1001 bitmap_element
*b_elt
= b
->first
;
1002 bitmap_element
*a_prev
= NULL
;
1004 gcc_assert (a
!= b
);
1007 if (!a_elt
|| b_elt
->indx
< a_elt
->indx
)
1010 bitmap_element
*dst
= bitmap_elt_insert_after (a
, a_prev
);
1012 dst
->indx
= b_elt
->indx
;
1013 memcpy (dst
->bits
, b_elt
->bits
, sizeof (dst
->bits
));
1015 b_elt
= b_elt
->next
;
1017 else if (a_elt
->indx
< b_elt
->indx
)
1020 a_elt
= a_elt
->next
;
1024 /* Matching elts, generate A ^= B. */
1026 BITMAP_WORD ior
= 0;
1027 bitmap_element
*next
= a_elt
->next
;
1029 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
1031 BITMAP_WORD r
= a_elt
->bits
[ix
] ^ b_elt
->bits
[ix
];
1034 a_elt
->bits
[ix
] = r
;
1036 b_elt
= b_elt
->next
;
1040 bitmap_element_free (a
, a_elt
);
1044 gcc_assert (!a
->current
== !a
->first
);
1046 a
->indx
= a
->current
->indx
;
1049 /* Return true if two bitmaps are identical.
1050 We do not bother with a check for pointer equality, as that never
1051 occurs in practice. */
1054 bitmap_equal_p (bitmap a
, bitmap b
)
1056 bitmap_element
*a_elt
;
1057 bitmap_element
*b_elt
;
1060 for (a_elt
= a
->first
, b_elt
= b
->first
;
1062 a_elt
= a_elt
->next
, b_elt
= b_elt
->next
)
1064 if (a_elt
->indx
!= b_elt
->indx
)
1066 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
1067 if (a_elt
->bits
[ix
] != b_elt
->bits
[ix
])
1070 return !a_elt
&& !b_elt
;
1073 /* Return true if A AND B is not empty. */
1076 bitmap_intersect_p (bitmap a
, bitmap b
)
1078 bitmap_element
*a_elt
;
1079 bitmap_element
*b_elt
;
1082 for (a_elt
= a
->first
, b_elt
= b
->first
;
1085 if (a_elt
->indx
< b_elt
->indx
)
1086 a_elt
= a_elt
->next
;
1087 else if (b_elt
->indx
< a_elt
->indx
)
1088 b_elt
= b_elt
->next
;
1091 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
1092 if (a_elt
->bits
[ix
] & b_elt
->bits
[ix
])
1094 a_elt
= a_elt
->next
;
1095 b_elt
= b_elt
->next
;
1101 /* Return true if A AND NOT B is not empty. */
1104 bitmap_intersect_compl_p (bitmap a
, bitmap b
)
1106 bitmap_element
*a_elt
;
1107 bitmap_element
*b_elt
;
1109 for (a_elt
= a
->first
, b_elt
= b
->first
;
1112 if (a_elt
->indx
< b_elt
->indx
)
1114 else if (b_elt
->indx
< a_elt
->indx
)
1115 b_elt
= b_elt
->next
;
1118 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
1119 if (a_elt
->bits
[ix
] & ~b_elt
->bits
[ix
])
1121 a_elt
= a_elt
->next
;
1122 b_elt
= b_elt
->next
;
1125 return a_elt
!= NULL
;
1129 /* DST = A | (FROM1 & ~FROM2). Return true if DST changes. */
1132 bitmap_ior_and_compl (bitmap dst
, bitmap a
, bitmap from1
, bitmap from2
)
1137 bitmap_initialize (&tmp
, &bitmap_default_obstack
);
1138 bitmap_and_compl (&tmp
, from1
, from2
);
1139 changed
= bitmap_ior (dst
, a
, &tmp
);
1140 bitmap_clear (&tmp
);
1145 /* A |= (FROM1 & ~FROM2). Return true if A changes. */
1148 bitmap_ior_and_compl_into (bitmap a
, bitmap from1
, bitmap from2
)
1153 bitmap_initialize (&tmp
, &bitmap_default_obstack
);
1154 bitmap_and_compl (&tmp
, from1
, from2
);
1155 changed
= bitmap_ior_into (a
, &tmp
);
1156 bitmap_clear (&tmp
);
1161 /* Debugging function to print out the contents of a bitmap. */
1164 debug_bitmap_file (FILE *file
, bitmap head
)
1166 bitmap_element
*ptr
;
1168 fprintf (file
, "\nfirst = " HOST_PTR_PRINTF
1169 " current = " HOST_PTR_PRINTF
" indx = %u\n",
1170 (void *) head
->first
, (void *) head
->current
, head
->indx
);
1172 for (ptr
= head
->first
; ptr
; ptr
= ptr
->next
)
1174 unsigned int i
, j
, col
= 26;
1176 fprintf (file
, "\t" HOST_PTR_PRINTF
" next = " HOST_PTR_PRINTF
1177 " prev = " HOST_PTR_PRINTF
" indx = %u\n\t\tbits = {",
1178 (void*) ptr
, (void*) ptr
->next
, (void*) ptr
->prev
, ptr
->indx
);
1180 for (i
= 0; i
< BITMAP_ELEMENT_WORDS
; i
++)
1181 for (j
= 0; j
< BITMAP_WORD_BITS
; j
++)
1182 if ((ptr
->bits
[i
] >> j
) & 1)
1186 fprintf (file
, "\n\t\t\t");
1190 fprintf (file
, " %u", (ptr
->indx
* BITMAP_ELEMENT_ALL_BITS
1191 + i
* BITMAP_WORD_BITS
+ j
));
1195 fprintf (file
, " }\n");
1199 /* Function to be called from the debugger to print the contents
1203 debug_bitmap (bitmap head
)
1205 debug_bitmap_file (stdout
, head
);
1208 /* Function to print out the contents of a bitmap. Unlike debug_bitmap_file,
1209 it does not print anything but the bits. */
1212 bitmap_print (FILE *file
, bitmap head
, const char *prefix
, const char *suffix
)
1214 const char *comma
= "";
1218 fputs (prefix
, file
);
1219 EXECUTE_IF_SET_IN_BITMAP (head
, 0, i
, bi
)
1221 fprintf (file
, "%s%d", comma
, i
);
1224 fputs (suffix
, file
);
1227 #include "gt-bitmap.h"