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. */
33 static struct obstack bitmap_obstack
;
34 static int bitmap_obstack_init
= FALSE
;
40 #define INLINE __inline__
45 bitmap_element bitmap_zero_bits
; /* An element of all zero bits. */
46 static bitmap_element
*bitmap_free
; /* Freelist of bitmap elements. */
47 static GTY((deletable
)) bitmap_element
*bitmap_ggc_free
;
49 static void bitmap_elem_to_freelist (bitmap
, bitmap_element
*);
50 static void bitmap_element_free (bitmap
, bitmap_element
*);
51 static bitmap_element
*bitmap_element_allocate (bitmap
);
52 static int bitmap_element_zerop (bitmap_element
*);
53 static void bitmap_element_link (bitmap
, bitmap_element
*);
54 static bitmap_element
*bitmap_elt_insert_after (bitmap
, bitmap_element
*);
55 static void bitmap_elt_clear_from (bitmap
, bitmap_element
*);
56 static bitmap_element
*bitmap_find_bit (bitmap
, unsigned int);
59 /* Add ELEM to the appropriate freelist. */
61 bitmap_elem_to_freelist (bitmap head
, bitmap_element
*elt
)
63 if (head
->using_obstack
)
65 elt
->next
= bitmap_free
;
70 elt
->next
= bitmap_ggc_free
;
71 bitmap_ggc_free
= elt
;
75 /* Free a bitmap element. Since these are allocated off the
76 bitmap_obstack, "free" actually means "put onto the freelist". */
79 bitmap_element_free (bitmap head
, bitmap_element
*elt
)
81 bitmap_element
*next
= elt
->next
;
82 bitmap_element
*prev
= elt
->prev
;
90 if (head
->first
== elt
)
93 /* Since the first thing we try is to insert before current,
94 make current the next entry in preference to the previous. */
95 if (head
->current
== elt
)
97 head
->current
= next
!= 0 ? next
: prev
;
99 head
->indx
= head
->current
->indx
;
101 bitmap_elem_to_freelist (head
, elt
);
104 /* Allocate a bitmap element. The bits are cleared, but nothing else is. */
106 static INLINE bitmap_element
*
107 bitmap_element_allocate (bitmap head
)
109 bitmap_element
*element
;
111 if (head
->using_obstack
)
113 if (bitmap_free
!= 0)
115 element
= bitmap_free
;
116 bitmap_free
= element
->next
;
120 /* We can't use gcc_obstack_init to initialize the obstack since
121 print-rtl.c now calls bitmap functions, and bitmap is linked
122 into the gen* functions. */
123 if (!bitmap_obstack_init
)
125 bitmap_obstack_init
= TRUE
;
127 #if !defined(__GNUC__) || (__GNUC__ < 2)
128 #define __alignof__(type) 0
131 obstack_specify_allocation (&bitmap_obstack
, OBSTACK_CHUNK_SIZE
,
132 __alignof__ (bitmap_element
),
137 element
= XOBNEW (&bitmap_obstack
, bitmap_element
);
142 if (bitmap_ggc_free
!= NULL
)
144 element
= bitmap_ggc_free
;
145 bitmap_ggc_free
= element
->next
;
148 element
= GGC_NEW (bitmap_element
);
151 memset (element
->bits
, 0, sizeof (element
->bits
));
156 /* Release any memory allocated by bitmaps. */
159 bitmap_release_memory (void)
162 if (bitmap_obstack_init
)
164 bitmap_obstack_init
= FALSE
;
165 obstack_free (&bitmap_obstack
, NULL
);
169 /* Return nonzero if all bits in an element are zero. */
172 bitmap_element_zerop (bitmap_element
*element
)
174 #if BITMAP_ELEMENT_WORDS == 2
175 return (element
->bits
[0] | element
->bits
[1]) == 0;
179 for (i
= 0; i
< BITMAP_ELEMENT_WORDS
; i
++)
180 if (element
->bits
[i
] != 0)
187 /* Link the bitmap element into the current bitmap linked list. */
190 bitmap_element_link (bitmap head
, bitmap_element
*element
)
192 unsigned int indx
= element
->indx
;
195 /* If this is the first and only element, set it in. */
196 if (head
->first
== 0)
198 element
->next
= element
->prev
= 0;
199 head
->first
= element
;
202 /* If this index is less than that of the current element, it goes someplace
203 before the current element. */
204 else if (indx
< head
->indx
)
206 for (ptr
= head
->current
;
207 ptr
->prev
!= 0 && ptr
->prev
->indx
> indx
;
212 ptr
->prev
->next
= element
;
214 head
->first
= element
;
216 element
->prev
= ptr
->prev
;
221 /* Otherwise, it must go someplace after the current element. */
224 for (ptr
= head
->current
;
225 ptr
->next
!= 0 && ptr
->next
->indx
< indx
;
230 ptr
->next
->prev
= element
;
232 element
->next
= ptr
->next
;
237 /* Set up so this is the first element searched. */
238 head
->current
= element
;
242 /* Insert a new uninitialized element into bitmap HEAD after element
243 ELT. If ELT is NULL, insert the element at the start. Return the
246 static bitmap_element
*
247 bitmap_elt_insert_after (bitmap head
, bitmap_element
*elt
)
249 bitmap_element
*node
= bitmap_element_allocate (head
);
254 head
->current
= node
;
255 node
->next
= head
->first
;
257 node
->next
->prev
= node
;
263 gcc_assert (head
->current
);
264 node
->next
= elt
->next
;
266 node
->next
->prev
= node
;
273 /* Remove ELT and all following elements from bitmap HEAD. */
276 bitmap_elt_clear_from (bitmap head
, bitmap_element
*elt
)
278 bitmap_element
*next
;
283 bitmap_element_free (head
, elt
);
289 /* Clear a bitmap by freeing the linked list. */
292 bitmap_clear (bitmap head
)
294 bitmap_element
*element
, *next
;
296 for (element
= head
->first
; element
!= 0; element
= next
)
298 next
= element
->next
;
299 bitmap_elem_to_freelist (head
, element
);
302 head
->first
= head
->current
= 0;
305 /* Copy a bitmap to another bitmap. */
308 bitmap_copy (bitmap to
, bitmap from
)
310 bitmap_element
*from_ptr
, *to_ptr
= 0;
311 #if BITMAP_ELEMENT_WORDS != 2
317 /* Copy elements in forward direction one at a time. */
318 for (from_ptr
= from
->first
; from_ptr
; from_ptr
= from_ptr
->next
)
320 bitmap_element
*to_elt
= bitmap_element_allocate (to
);
322 to_elt
->indx
= from_ptr
->indx
;
324 #if BITMAP_ELEMENT_WORDS == 2
325 to_elt
->bits
[0] = from_ptr
->bits
[0];
326 to_elt
->bits
[1] = from_ptr
->bits
[1];
328 for (i
= 0; i
< BITMAP_ELEMENT_WORDS
; i
++)
329 to_elt
->bits
[i
] = from_ptr
->bits
[i
];
332 /* Here we have a special case of bitmap_element_link, for the case
333 where we know the links are being entered in sequence. */
336 to
->first
= to
->current
= to_elt
;
337 to
->indx
= from_ptr
->indx
;
338 to_elt
->next
= to_elt
->prev
= 0;
342 to_elt
->prev
= to_ptr
;
344 to_ptr
->next
= to_elt
;
351 /* Find a bitmap element that would hold a bitmap's bit.
352 Update the `current' field even if we can't find an element that
353 would hold the bitmap's bit to make eventual allocation
356 static INLINE bitmap_element
*
357 bitmap_find_bit (bitmap head
, unsigned int bit
)
359 bitmap_element
*element
;
360 unsigned int indx
= bit
/ BITMAP_ELEMENT_ALL_BITS
;
362 if (head
->current
== 0
363 || head
->indx
== indx
)
364 return head
->current
;
366 if (head
->indx
> indx
)
367 for (element
= head
->current
;
368 element
->prev
!= 0 && element
->indx
> indx
;
369 element
= element
->prev
)
373 for (element
= head
->current
;
374 element
->next
!= 0 && element
->indx
< indx
;
375 element
= element
->next
)
378 /* `element' is the nearest to the one we want. If it's not the one we
379 want, the one we want doesn't exist. */
380 head
->current
= element
;
381 head
->indx
= element
->indx
;
382 if (element
!= 0 && element
->indx
!= indx
)
388 /* Clear a single bit in a bitmap. */
391 bitmap_clear_bit (bitmap head
, int bit
)
393 bitmap_element
*ptr
= bitmap_find_bit (head
, bit
);
397 unsigned bit_num
= bit
% BITMAP_WORD_BITS
;
398 unsigned word_num
= bit
/ BITMAP_WORD_BITS
% BITMAP_ELEMENT_WORDS
;
399 ptr
->bits
[word_num
] &= ~ (((BITMAP_WORD
) 1) << bit_num
);
401 /* If we cleared the entire word, free up the element. */
402 if (bitmap_element_zerop (ptr
))
403 bitmap_element_free (head
, ptr
);
407 /* Set a single bit in a bitmap. */
410 bitmap_set_bit (bitmap head
, int bit
)
412 bitmap_element
*ptr
= bitmap_find_bit (head
, bit
);
413 unsigned word_num
= bit
/ BITMAP_WORD_BITS
% BITMAP_ELEMENT_WORDS
;
414 unsigned bit_num
= bit
% BITMAP_WORD_BITS
;
415 BITMAP_WORD bit_val
= ((BITMAP_WORD
) 1) << bit_num
;
419 ptr
= bitmap_element_allocate (head
);
420 ptr
->indx
= bit
/ BITMAP_ELEMENT_ALL_BITS
;
421 ptr
->bits
[word_num
] = bit_val
;
422 bitmap_element_link (head
, ptr
);
425 ptr
->bits
[word_num
] |= bit_val
;
428 /* Return whether a bit is set within a bitmap. */
431 bitmap_bit_p (bitmap head
, int bit
)
437 ptr
= bitmap_find_bit (head
, bit
);
441 bit_num
= bit
% BITMAP_WORD_BITS
;
442 word_num
= bit
/ BITMAP_WORD_BITS
% BITMAP_ELEMENT_WORDS
;
444 return (ptr
->bits
[word_num
] >> bit_num
) & 1;
447 /* Return the bit number of the first set bit in the bitmap. The
448 bitmap must be non-empty. */
451 bitmap_first_set_bit (bitmap a
)
453 bitmap_element
*elt
= a
->first
;
459 bit_no
= elt
->indx
* BITMAP_ELEMENT_ALL_BITS
;
460 for (ix
= 0; ix
!= BITMAP_ELEMENT_WORDS
; ix
++)
462 word
= elt
->bits
[ix
];
468 bit_no
+= ix
* BITMAP_WORD_BITS
;
470 #if GCC_VERSION >= 3004
471 gcc_assert (sizeof(long) == sizeof (word
));
472 bit_no
+= __builtin_ctzl (word
);
474 /* Binary search for the first set bit. */
475 #if BITMAP_WORD_BITS > 64
476 #error "Fill out the table."
478 #if BITMAP_WORD_BITS > 32
479 if (!(word
& 0xffffffff))
480 word
>>= 32, bit_no
+= 32;
482 if (!(word
& 0xffff))
483 word
>>= 16, bit_no
+= 16;
485 word
>>= 8, bit_no
+= 8;
487 word
>>= 4, bit_no
+= 4;
489 word
>>= 2, bit_no
+= 2;
491 word
>>= 1, bit_no
+= 1;
493 gcc_assert (word
& 1);
502 bitmap_and (bitmap dst
, bitmap a
, bitmap b
)
504 bitmap_element
*dst_elt
= dst
->first
;
505 bitmap_element
*a_elt
= a
->first
;
506 bitmap_element
*b_elt
= b
->first
;
507 bitmap_element
*dst_prev
= NULL
;
509 gcc_assert (dst
!= a
&& dst
!= b
&& a
!= b
);
510 while (a_elt
&& b_elt
)
512 if (a_elt
->indx
< b_elt
->indx
)
514 else if (b_elt
->indx
< a_elt
->indx
)
518 /* Matching elts, generate A & B. */
523 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
525 dst_elt
->indx
= a_elt
->indx
;
526 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
528 BITMAP_WORD r
= a_elt
->bits
[ix
] & b_elt
->bits
[ix
];
530 dst_elt
->bits
[ix
] = r
;
536 dst_elt
= dst_elt
->next
;
542 bitmap_elt_clear_from (dst
, dst_elt
);
543 gcc_assert (!dst
->current
== !dst
->first
);
545 dst
->indx
= dst
->current
->indx
;
551 bitmap_and_into (bitmap a
, bitmap b
)
553 bitmap_element
*a_elt
= a
->first
;
554 bitmap_element
*b_elt
= b
->first
;
555 bitmap_element
*next
;
558 while (a_elt
&& b_elt
)
560 if (a_elt
->indx
< b_elt
->indx
)
563 bitmap_element_free (a
, a_elt
);
566 else if (b_elt
->indx
< a_elt
->indx
)
570 /* Matching elts, generate A &= B. */
574 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
576 BITMAP_WORD r
= a_elt
->bits
[ix
] & b_elt
->bits
[ix
];
583 bitmap_element_free (a
, a_elt
);
588 bitmap_elt_clear_from (a
, a_elt
);
589 gcc_assert (!a
->current
== !a
->first
);
590 gcc_assert (!a
->current
|| a
->indx
== a
->current
->indx
);
596 bitmap_and_compl (bitmap dst
, bitmap a
, bitmap b
)
598 bitmap_element
*dst_elt
= dst
->first
;
599 bitmap_element
*a_elt
= a
->first
;
600 bitmap_element
*b_elt
= b
->first
;
601 bitmap_element
*dst_prev
= NULL
;
603 gcc_assert (dst
!= a
&& dst
!= b
&& a
!= b
);
607 if (!b_elt
|| a_elt
->indx
< b_elt
->indx
)
611 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
613 dst_elt
->indx
= a_elt
->indx
;
614 memcpy (dst_elt
->bits
, a_elt
->bits
, sizeof (dst_elt
->bits
));
616 dst_elt
= dst_elt
->next
;
619 else if (b_elt
->indx
< a_elt
->indx
)
623 /* Matching elts, generate A & ~B. */
628 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
630 dst_elt
->indx
= a_elt
->indx
;
631 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
633 BITMAP_WORD r
= a_elt
->bits
[ix
] & ~b_elt
->bits
[ix
];
635 dst_elt
->bits
[ix
] = r
;
641 dst_elt
= dst_elt
->next
;
647 bitmap_elt_clear_from (dst
, dst_elt
);
648 gcc_assert (!dst
->current
== !dst
->first
);
650 dst
->indx
= dst
->current
->indx
;
656 bitmap_and_compl_into (bitmap a
, bitmap b
)
658 bitmap_element
*a_elt
= a
->first
;
659 bitmap_element
*b_elt
= b
->first
;
660 bitmap_element
*next
;
663 while (a_elt
&& b_elt
)
665 if (a_elt
->indx
< b_elt
->indx
)
667 else if (b_elt
->indx
< a_elt
->indx
)
671 /* Matching elts, generate A &= ~B. */
675 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
677 BITMAP_WORD r
= a_elt
->bits
[ix
] & ~b_elt
->bits
[ix
];
684 bitmap_element_free (a
, a_elt
);
689 gcc_assert (!a
->current
== !a
->first
);
690 gcc_assert (!a
->current
|| a
->indx
== a
->current
->indx
);
693 /* DST = A | B. Return true if DST changes. */
696 bitmap_ior (bitmap dst
, bitmap a
, bitmap b
)
698 bitmap_element
*dst_elt
= dst
->first
;
699 bitmap_element
*a_elt
= a
->first
;
700 bitmap_element
*b_elt
= b
->first
;
701 bitmap_element
*dst_prev
= NULL
;
702 bool changed
= false;
704 gcc_assert (dst
!= a
&& dst
!= b
&& a
!= b
);
705 while (a_elt
|| b_elt
)
707 if (a_elt
&& b_elt
&& a_elt
->indx
== b_elt
->indx
)
709 /* Matching elts, generate A | B. */
712 if (!changed
&& dst_elt
&& dst_elt
->indx
== a_elt
->indx
)
714 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
716 BITMAP_WORD r
= a_elt
->bits
[ix
] | b_elt
->bits
[ix
];
718 if (r
!= dst_elt
->bits
[ix
])
720 dst_elt
->bits
[ix
] = r
;
729 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
730 dst_elt
->indx
= a_elt
->indx
;
731 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
733 BITMAP_WORD r
= a_elt
->bits
[ix
] | b_elt
->bits
[ix
];
735 dst_elt
->bits
[ix
] = r
;
741 dst_elt
= dst_elt
->next
;
745 /* Copy a single element. */
748 if (!b_elt
|| (a_elt
&& a_elt
->indx
< b_elt
->indx
))
759 if (!changed
&& dst_elt
&& dst_elt
->indx
== src
->indx
)
763 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
764 if (src
->bits
[ix
] != dst_elt
->bits
[ix
])
766 dst_elt
->bits
[ix
] = src
->bits
[ix
];
774 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
775 dst_elt
->indx
= src
->indx
;
776 memcpy (dst_elt
->bits
, src
->bits
, sizeof (dst_elt
->bits
));
780 dst_elt
= dst_elt
->next
;
787 bitmap_elt_clear_from (dst
, dst_elt
);
789 gcc_assert (!dst
->current
== !dst
->first
);
791 dst
->indx
= dst
->current
->indx
;
795 /* A |= B. Return true if A changes. */
798 bitmap_ior_into (bitmap a
, bitmap b
)
800 bitmap_element
*a_elt
= a
->first
;
801 bitmap_element
*b_elt
= b
->first
;
802 bitmap_element
*a_prev
= NULL
;
803 bool changed
= false;
808 if (!a_elt
|| b_elt
->indx
< a_elt
->indx
)
811 bitmap_element
*dst
= bitmap_elt_insert_after (a
, a_prev
);
813 dst
->indx
= b_elt
->indx
;
814 memcpy (dst
->bits
, b_elt
->bits
, sizeof (dst
->bits
));
819 else if (a_elt
->indx
< b_elt
->indx
)
826 /* Matching elts, generate A |= B. */
830 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
832 BITMAP_WORD r
= a_elt
->bits
[ix
] | b_elt
->bits
[ix
];
837 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
839 BITMAP_WORD r
= a_elt
->bits
[ix
] | b_elt
->bits
[ix
];
841 if (a_elt
->bits
[ix
] != r
)
852 gcc_assert (!a
->current
== !a
->first
);
854 a
->indx
= a
->current
->indx
;
861 bitmap_xor (bitmap dst
, bitmap a
, bitmap b
)
863 bitmap_element
*dst_elt
= dst
->first
;
864 bitmap_element
*a_elt
= a
->first
;
865 bitmap_element
*b_elt
= b
->first
;
866 bitmap_element
*dst_prev
= NULL
;
868 gcc_assert (dst
!= a
&& dst
!= b
&& a
!= b
);
869 while (a_elt
|| b_elt
)
871 if (a_elt
&& b_elt
&& a_elt
->indx
== b_elt
->indx
)
873 /* Matching elts, generate A ^ B. */
878 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
880 dst_elt
->indx
= a_elt
->indx
;
881 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
883 BITMAP_WORD r
= a_elt
->bits
[ix
] ^ b_elt
->bits
[ix
];
886 dst_elt
->bits
[ix
] = r
;
893 dst_elt
= dst_elt
->next
;
898 /* Copy a single element. */
901 if (!b_elt
|| (a_elt
&& a_elt
->indx
< b_elt
->indx
))
913 dst_elt
= bitmap_elt_insert_after (dst
, dst_prev
);
915 dst_elt
->indx
= src
->indx
;
916 memcpy (dst_elt
->bits
, src
->bits
, sizeof (dst_elt
->bits
));
918 dst_elt
= dst_elt
->next
;
921 bitmap_elt_clear_from (dst
, dst_elt
);
922 gcc_assert (!dst
->current
== !dst
->first
);
924 dst
->indx
= dst
->current
->indx
;
930 bitmap_xor_into (bitmap a
, bitmap b
)
932 bitmap_element
*a_elt
= a
->first
;
933 bitmap_element
*b_elt
= b
->first
;
934 bitmap_element
*a_prev
= NULL
;
939 if (!a_elt
|| b_elt
->indx
< a_elt
->indx
)
942 bitmap_element
*dst
= bitmap_elt_insert_after (a
, a_prev
);
944 dst
->indx
= b_elt
->indx
;
945 memcpy (dst
->bits
, b_elt
->bits
, sizeof (dst
->bits
));
949 else if (a_elt
->indx
< b_elt
->indx
)
956 /* Matching elts, generate A ^= B. */
959 bitmap_element
*next
= a_elt
->next
;
961 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
963 BITMAP_WORD r
= a_elt
->bits
[ix
] ^ b_elt
->bits
[ix
];
972 bitmap_element_free (a
, a_elt
);
976 gcc_assert (!a
->current
== !a
->first
);
978 a
->indx
= a
->current
->indx
;
981 /* Return true if two bitmaps are identical.
982 We do not bother with a check for pointer equality, as that never
983 occurs in practice. */
986 bitmap_equal_p (bitmap a
, bitmap b
)
988 bitmap_element
*a_elt
;
989 bitmap_element
*b_elt
;
992 for (a_elt
= a
->first
, b_elt
= b
->first
;
994 a_elt
= a_elt
->next
, b_elt
= b_elt
->next
)
996 if (a_elt
->indx
!= b_elt
->indx
)
998 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
999 if (a_elt
->bits
[ix
] != b_elt
->bits
[ix
])
1002 return !a_elt
&& !b_elt
;
1005 /* Return true if A AND B is not empty. */
1008 bitmap_intersect_p (bitmap a
, bitmap b
)
1010 bitmap_element
*a_elt
;
1011 bitmap_element
*b_elt
;
1014 for (a_elt
= a
->first
, b_elt
= b
->first
;
1017 if (a_elt
->indx
< b_elt
->indx
)
1018 a_elt
= a_elt
->next
;
1019 else if (b_elt
->indx
< a_elt
->indx
)
1020 b_elt
= b_elt
->next
;
1023 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
1024 if (a_elt
->bits
[ix
] & b_elt
->bits
[ix
])
1026 a_elt
= a_elt
->next
;
1027 b_elt
= b_elt
->next
;
1033 /* Return true if A AND NOT B is not empty. */
1036 bitmap_intersect_compl_p (bitmap a
, bitmap b
)
1038 bitmap_element
*a_elt
;
1039 bitmap_element
*b_elt
;
1041 for (a_elt
= a
->first
, b_elt
= b
->first
;
1044 if (a_elt
->indx
< b_elt
->indx
)
1046 else if (b_elt
->indx
< a_elt
->indx
)
1047 b_elt
= b_elt
->next
;
1050 for (ix
= BITMAP_ELEMENT_WORDS
; ix
--;)
1051 if (a_elt
->bits
[ix
] & ~b_elt
->bits
[ix
])
1053 a_elt
= a_elt
->next
;
1054 b_elt
= b_elt
->next
;
1057 return a_elt
!= NULL
;
1061 /* DST = A | (FROM1 & ~FROM2). Return true if DST changes. */
1064 bitmap_ior_and_compl (bitmap dst
, bitmap a
, bitmap from1
, bitmap from2
)
1069 tmp
.first
= tmp
.current
= 0;
1070 tmp
.using_obstack
= 0;
1071 bitmap_and_compl (&tmp
, from1
, from2
);
1072 changed
= bitmap_ior (dst
, a
, &tmp
);
1073 bitmap_clear (&tmp
);
1078 /* A |= (FROM1 & ~FROM2). Return true if A changes. */
1081 bitmap_ior_and_compl_into (bitmap a
, bitmap from1
, bitmap from2
)
1086 tmp
.first
= tmp
.current
= 0;
1087 tmp
.using_obstack
= 0;
1088 bitmap_and_compl (&tmp
, from1
, from2
);
1089 changed
= bitmap_ior_into (a
, &tmp
);
1090 bitmap_clear (&tmp
);
1095 /* Initialize a bitmap header. */
1098 bitmap_initialize (bitmap head
, int using_obstack
)
1100 if (head
== NULL
&& ! using_obstack
)
1101 head
= GGC_NEW (struct bitmap_head_def
);
1103 head
->first
= head
->current
= 0;
1104 head
->using_obstack
= using_obstack
;
1109 /* Debugging function to print out the contents of a bitmap. */
1112 debug_bitmap_file (FILE *file
, bitmap head
)
1114 bitmap_element
*ptr
;
1116 fprintf (file
, "\nfirst = " HOST_PTR_PRINTF
1117 " current = " HOST_PTR_PRINTF
" indx = %u\n",
1118 (void *) head
->first
, (void *) head
->current
, head
->indx
);
1120 for (ptr
= head
->first
; ptr
; ptr
= ptr
->next
)
1122 unsigned int i
, j
, col
= 26;
1124 fprintf (file
, "\t" HOST_PTR_PRINTF
" next = " HOST_PTR_PRINTF
1125 " prev = " HOST_PTR_PRINTF
" indx = %u\n\t\tbits = {",
1126 (void*) ptr
, (void*) ptr
->next
, (void*) ptr
->prev
, ptr
->indx
);
1128 for (i
= 0; i
< BITMAP_ELEMENT_WORDS
; i
++)
1129 for (j
= 0; j
< BITMAP_WORD_BITS
; j
++)
1130 if ((ptr
->bits
[i
] >> j
) & 1)
1134 fprintf (file
, "\n\t\t\t");
1138 fprintf (file
, " %u", (ptr
->indx
* BITMAP_ELEMENT_ALL_BITS
1139 + i
* BITMAP_WORD_BITS
+ j
));
1143 fprintf (file
, " }\n");
1147 /* Function to be called from the debugger to print the contents
1151 debug_bitmap (bitmap head
)
1153 debug_bitmap_file (stdout
, head
);
1156 /* Function to print out the contents of a bitmap. Unlike debug_bitmap_file,
1157 it does not print anything but the bits. */
1160 bitmap_print (FILE *file
, bitmap head
, const char *prefix
, const char *suffix
)
1162 const char *comma
= "";
1166 fputs (prefix
, file
);
1167 EXECUTE_IF_SET_IN_BITMAP (head
, 0, i
, bi
)
1169 fprintf (file
, "%s%d", comma
, i
);
1172 fputs (suffix
, file
);
1175 #include "gt-bitmap.h"