]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/bitmap.c
altivec-2.c: Remove test for invalid vector type V2DF.
[thirdparty/gcc.git] / gcc / bitmap.c
CommitLineData
096ab9ea 1/* Functions to support general ended bitmaps.
ae0ed63a 2 Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
096ab9ea 3
1322177d 4This file is part of GCC.
096ab9ea 5
1322177d
LB
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 2, or (at your option) any later
9version.
096ab9ea 10
1322177d
LB
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
096ab9ea
RK
15
16You should have received a copy of the GNU General Public License
1322177d
LB
17along with GCC; see the file COPYING. If not, write to the Free
18Software Foundation, 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
096ab9ea 20
096ab9ea 21#include "config.h"
670ee920 22#include "system.h"
096ab9ea
RK
23#include "rtl.h"
24#include "flags.h"
25#include "obstack.h"
efc9bd41 26#include "bitmap.h"
096ab9ea 27
22fa5b8a
MM
28/* Obstack to allocate bitmap elements from. */
29static struct obstack bitmap_obstack;
30static int bitmap_obstack_init = FALSE;
096ab9ea
RK
31\f
32#ifndef INLINE
33#ifndef __GNUC__
34#define INLINE
35#else
36#define INLINE __inline__
37#endif
38#endif
39
40/* Global data */
ec5c56db
KH
41bitmap_element bitmap_zero_bits; /* An element of all zero bits. */
42static bitmap_element *bitmap_free; /* Freelist of bitmap elements. */
096ab9ea 43
3d994c6b
KG
44static void bitmap_element_free PARAMS ((bitmap, bitmap_element *));
45static bitmap_element *bitmap_element_allocate PARAMS ((void));
46static int bitmap_element_zerop PARAMS ((bitmap_element *));
47static void bitmap_element_link PARAMS ((bitmap, bitmap_element *));
48static bitmap_element *bitmap_find_bit PARAMS ((bitmap, unsigned int));
096ab9ea 49\f
a615c28a
RH
50/* Free a bitmap element. Since these are allocated off the
51 bitmap_obstack, "free" actually means "put onto the freelist". */
096ab9ea
RK
52
53static INLINE void
54bitmap_element_free (head, elt)
55 bitmap head;
56 bitmap_element *elt;
57{
58 bitmap_element *next = elt->next;
59 bitmap_element *prev = elt->prev;
60
61 if (prev)
62 prev->next = next;
63
64 if (next)
65 next->prev = prev;
66
67 if (head->first == elt)
68 head->first = next;
69
70 /* Since the first thing we try is to insert before current,
71 make current the next entry in preference to the previous. */
72 if (head->current == elt)
87a2e7a8
DB
73 {
74 head->current = next != 0 ? next : prev;
75 if (head->current)
76 head->indx = head->current->indx;
77 }
096ab9ea
RK
78
79 elt->next = bitmap_free;
80 bitmap_free = elt;
81}
82\f
83/* Allocate a bitmap element. The bits are cleared, but nothing else is. */
84
85static INLINE bitmap_element *
56c5d8bf 86bitmap_element_allocate ()
096ab9ea
RK
87{
88 bitmap_element *element;
096ab9ea
RK
89
90 if (bitmap_free != 0)
91 {
92 element = bitmap_free;
93 bitmap_free = element->next;
94 }
95 else
22fa5b8a
MM
96 {
97 /* We can't use gcc_obstack_init to initialize the obstack since
98 print-rtl.c now calls bitmap functions, and bitmap is linked
99 into the gen* functions. */
100 if (!bitmap_obstack_init)
101 {
102 bitmap_obstack_init = TRUE;
103
104 /* Let particular systems override the size of a chunk. */
105#ifndef OBSTACK_CHUNK_SIZE
106#define OBSTACK_CHUNK_SIZE 0
107#endif
108 /* Let them override the alloc and free routines too. */
109#ifndef OBSTACK_CHUNK_ALLOC
110#define OBSTACK_CHUNK_ALLOC xmalloc
111#endif
112#ifndef OBSTACK_CHUNK_FREE
113#define OBSTACK_CHUNK_FREE free
114#endif
115
116#if !defined(__GNUC__) || (__GNUC__ < 2)
117#define __alignof__(type) 0
118#endif
119
120 obstack_specify_allocation (&bitmap_obstack, OBSTACK_CHUNK_SIZE,
121 __alignof__ (bitmap_element),
93868d11
KG
122 (void *(*) PARAMS ((long))) OBSTACK_CHUNK_ALLOC,
123 (void (*) PARAMS ((void *))) OBSTACK_CHUNK_FREE);
22fa5b8a
MM
124 }
125
126 element = (bitmap_element *) obstack_alloc (&bitmap_obstack,
127 sizeof (bitmap_element));
128 }
096ab9ea 129
a615c28a 130 memset (element->bits, 0, sizeof (element->bits));
096ab9ea
RK
131
132 return element;
133}
134
87e08c69
RH
135/* Release any memory allocated by bitmaps. */
136
137void
138bitmap_release_memory ()
139{
140 bitmap_free = 0;
141 if (bitmap_obstack_init)
142 {
143 bitmap_obstack_init = FALSE;
144 obstack_free (&bitmap_obstack, NULL);
145 }
146}
147
096ab9ea
RK
148/* Return nonzero if all bits in an element are zero. */
149
150static INLINE int
151bitmap_element_zerop (element)
152 bitmap_element *element;
153{
154#if BITMAP_ELEMENT_WORDS == 2
155 return (element->bits[0] | element->bits[1]) == 0;
156#else
157 int i;
158
159 for (i = 0; i < BITMAP_ELEMENT_WORDS; i++)
160 if (element->bits[i] != 0)
161 return 0;
162
163 return 1;
164#endif
165}
166\f
167/* Link the bitmap element into the current bitmap linked list. */
168
169static INLINE void
170bitmap_element_link (head, element)
171 bitmap head;
172 bitmap_element *element;
173{
174 unsigned int indx = element->indx;
175 bitmap_element *ptr;
176
177 /* If this is the first and only element, set it in. */
178 if (head->first == 0)
179 {
180 element->next = element->prev = 0;
181 head->first = element;
182 }
183
184 /* If this index is less than that of the current element, it goes someplace
185 before the current element. */
186 else if (indx < head->indx)
187 {
188 for (ptr = head->current;
189 ptr->prev != 0 && ptr->prev->indx > indx;
190 ptr = ptr->prev)
191 ;
192
193 if (ptr->prev)
194 ptr->prev->next = element;
195 else
196 head->first = element;
197
198 element->prev = ptr->prev;
199 element->next = ptr;
200 ptr->prev = element;
201 }
202
203 /* Otherwise, it must go someplace after the current element. */
204 else
205 {
206 for (ptr = head->current;
207 ptr->next != 0 && ptr->next->indx < indx;
208 ptr = ptr->next)
209 ;
210
211 if (ptr->next)
212 ptr->next->prev = element;
213
214 element->next = ptr->next;
215 element->prev = ptr;
216 ptr->next = element;
217 }
218
219 /* Set up so this is the first element searched. */
220 head->current = element;
221 head->indx = indx;
222}
223\f
224/* Clear a bitmap by freeing the linked list. */
225
1d300e19 226INLINE void
096ab9ea
RK
227bitmap_clear (head)
228 bitmap head;
229{
230 bitmap_element *element, *next;
231
232 for (element = head->first; element != 0; element = next)
233 {
234 next = element->next;
235 element->next = bitmap_free;
236 bitmap_free = element;
237 }
238
ca7fd9cd 239 head->first = head->current = 0;
096ab9ea
RK
240}
241\f
a615c28a 242/* Copy a bitmap to another bitmap. */
096ab9ea
RK
243
244void
245bitmap_copy (to, from)
246 bitmap to;
247 bitmap from;
248{
249 bitmap_element *from_ptr, *to_ptr = 0;
29a82058 250#if BITMAP_ELEMENT_WORDS != 2
096ab9ea 251 int i;
29a82058 252#endif
096ab9ea
RK
253
254 bitmap_clear (to);
255
256 /* Copy elements in forward direction one at a time */
257 for (from_ptr = from->first; from_ptr; from_ptr = from_ptr->next)
258 {
56c5d8bf 259 bitmap_element *to_elt = bitmap_element_allocate ();
096ab9ea
RK
260
261 to_elt->indx = from_ptr->indx;
262
263#if BITMAP_ELEMENT_WORDS == 2
264 to_elt->bits[0] = from_ptr->bits[0];
265 to_elt->bits[1] = from_ptr->bits[1];
266#else
267 for (i = 0; i < BITMAP_ELEMENT_WORDS; i++)
268 to_elt->bits[i] = from_ptr->bits[i];
269#endif
270
271 /* Here we have a special case of bitmap_element_link, for the case
272 where we know the links are being entered in sequence. */
273 if (to_ptr == 0)
274 {
275 to->first = to->current = to_elt;
276 to->indx = from_ptr->indx;
277 to_elt->next = to_elt->prev = 0;
278 }
279 else
280 {
281 to_elt->prev = to_ptr;
282 to_elt->next = 0;
283 to_ptr->next = to_elt;
284 }
285
286 to_ptr = to_elt;
287 }
288}
289\f
290/* Find a bitmap element that would hold a bitmap's bit.
291 Update the `current' field even if we can't find an element that
292 would hold the bitmap's bit to make eventual allocation
293 faster. */
294
295static INLINE bitmap_element *
296bitmap_find_bit (head, bit)
297 bitmap head;
298 unsigned int bit;
299{
300 bitmap_element *element;
301 unsigned HOST_WIDE_INT indx = bit / BITMAP_ELEMENT_ALL_BITS;
302
279be7c8
RE
303 if (head->current == 0
304 || head->indx == indx)
305 return head->current;
096ab9ea
RK
306
307 if (head->indx > indx)
308 for (element = head->current;
309 element->prev != 0 && element->indx > indx;
310 element = element->prev)
311 ;
312
313 else
314 for (element = head->current;
315 element->next != 0 && element->indx < indx;
316 element = element->next)
317 ;
318
319 /* `element' is the nearest to the one we want. If it's not the one we
320 want, the one we want doesn't exist. */
321 head->current = element;
322 head->indx = element->indx;
323 if (element != 0 && element->indx != indx)
324 element = 0;
325
326 return element;
327}
328\f
329/* Clear a single bit in a bitmap. */
330
331void
332bitmap_clear_bit (head, bit)
333 bitmap head;
334 int bit;
335{
336 bitmap_element *ptr = bitmap_find_bit (head, bit);
337
338 if (ptr != 0)
339 {
340 unsigned bit_num = bit % (unsigned) HOST_BITS_PER_WIDE_INT;
341 unsigned word_num = ((bit / (unsigned) HOST_BITS_PER_WIDE_INT)
342 % BITMAP_ELEMENT_WORDS);
343 ptr->bits[word_num] &= ~ (((unsigned HOST_WIDE_INT) 1) << bit_num);
344
345 /* If we cleared the entire word, free up the element */
346 if (bitmap_element_zerop (ptr))
347 bitmap_element_free (head, ptr);
348 }
349}
350
096ab9ea
RK
351/* Set a single bit in a bitmap. */
352
353void
354bitmap_set_bit (head, bit)
355 bitmap head;
356 int bit;
357{
358 bitmap_element *ptr = bitmap_find_bit (head, bit);
359 unsigned word_num
360 = ((bit / (unsigned) HOST_BITS_PER_WIDE_INT) % BITMAP_ELEMENT_WORDS);
361 unsigned bit_num = bit % (unsigned) HOST_BITS_PER_WIDE_INT;
362 unsigned HOST_WIDE_INT bit_val = ((unsigned HOST_WIDE_INT) 1) << bit_num;
363
364 if (ptr == 0)
365 {
56c5d8bf 366 ptr = bitmap_element_allocate ();
096ab9ea
RK
367 ptr->indx = bit / BITMAP_ELEMENT_ALL_BITS;
368 ptr->bits[word_num] = bit_val;
369 bitmap_element_link (head, ptr);
370 }
371 else
372 ptr->bits[word_num] |= bit_val;
373}
a615c28a 374
096ab9ea
RK
375/* Return whether a bit is set within a bitmap. */
376
377int
378bitmap_bit_p (head, bit)
379 bitmap head;
380 int bit;
381{
382 bitmap_element *ptr;
383 unsigned bit_num;
384 unsigned word_num;
385
386 ptr = bitmap_find_bit (head, bit);
387 if (ptr == 0)
388 return 0;
389
390 bit_num = bit % (unsigned) HOST_BITS_PER_WIDE_INT;
391 word_num
392 = ((bit / (unsigned) HOST_BITS_PER_WIDE_INT) % BITMAP_ELEMENT_WORDS);
393
8229306b 394 return (ptr->bits[word_num] >> bit_num) & 1;
096ab9ea
RK
395}
396\f
a615c28a
RH
397/* Return the bit number of the first set bit in the bitmap, or -1
398 if the bitmap is empty. */
87e08c69 399
ca7fd9cd 400int
87e08c69
RH
401bitmap_first_set_bit (a)
402 bitmap a;
403{
404 bitmap_element *ptr = a->first;
405 unsigned HOST_WIDE_INT word;
406 unsigned word_num, bit_num;
407
408 if (ptr == NULL)
409 return -1;
410
411#if BITMAP_ELEMENT_WORDS == 2
412 word_num = 0, word = ptr->bits[0];
413 if (word == 0)
414 word_num = 1, word = ptr->bits[1];
415#else
416 for (word_num = 0; word_num < BITMAP_ELEMENT_WORDS; ++word_num)
417 if ((word = ptr->bits[word_num]) != 0)
418 break;
419#endif
420
421 /* Binary search for the first set bit. */
422 /* ??? It'd be nice to know if ffs or ffsl was available. */
423
424 bit_num = 0;
425 word = word & -word;
426
427#if HOST_BITS_PER_WIDE_INT > 64
428 #error "Fill out the table."
429#endif
430#if HOST_BITS_PER_WIDE_INT > 32
431 if ((word & 0xffffffff) == 0)
432 word >>= 32, bit_num += 32;
433#endif
434 if ((word & 0xffff) == 0)
435 word >>= 16, bit_num += 16;
436 if ((word & 0xff) == 0)
437 word >>= 8, bit_num += 8;
438 if (word & 0xf0)
439 bit_num += 4;
440 if (word & 0xcc)
441 bit_num += 2;
442 if (word & 0xaa)
443 bit_num += 1;
444
445 return (ptr->indx * BITMAP_ELEMENT_ALL_BITS
446 + word_num * HOST_BITS_PER_WIDE_INT
447 + bit_num);
448}
449
a615c28a
RH
450/* Return the bit number of the last set bit in the bitmap, or -1
451 if the bitmap is empty. */
452
ca7fd9cd 453int
87e08c69
RH
454bitmap_last_set_bit (a)
455 bitmap a;
456{
457 bitmap_element *ptr = a->first;
458 unsigned HOST_WIDE_INT word;
459 unsigned word_num, bit_num;
460
461 if (ptr == NULL)
462 return -1;
463
464 while (ptr->next != NULL)
465 ptr = ptr->next;
466
467#if BITMAP_ELEMENT_WORDS == 2
468 word_num = 1, word = ptr->bits[1];
469 if (word == 0)
470 word_num = 0, word = ptr->bits[0];
471#else
472 for (word_num = BITMAP_ELEMENT_WORDS; word_num-- > 0; )
473 if ((word = ptr->bits[word_num]) != 0)
474 break;
475#endif
476
477 /* Binary search for the last set bit. */
478
479 bit_num = 0;
480#if HOST_BITS_PER_WIDE_INT > 64
481 #error "Fill out the table."
482#endif
483#if HOST_BITS_PER_WIDE_INT > 32
484 if (word & ~ (unsigned HOST_WIDE_INT) 0xffffffff)
485 word >>= 32, bit_num += 32;
486#endif
487 if (word & 0xffff0000)
488 word >>= 16, bit_num += 16;
489 if (word & 0xff00)
490 word >>= 8, bit_num += 8;
491 if (word & 0xf0)
492 word >>= 4, bit_num += 4;
493 if (word & 0xc)
494 word >>= 2, bit_num += 2;
495 if (word & 0x2)
a615c28a 496 bit_num += 1;
87e08c69
RH
497
498 return (ptr->indx * BITMAP_ELEMENT_ALL_BITS
499 + word_num * HOST_BITS_PER_WIDE_INT
500 + bit_num);
501}
502\f
8229306b
RH
503/* Store in bitmap TO the result of combining bitmap FROM1 and FROM2 using
504 a specific bit manipulation. Return true if TO changes. */
096ab9ea 505
8229306b 506int
096ab9ea
RK
507bitmap_operation (to, from1, from2, operation)
508 bitmap to;
509 bitmap from1;
510 bitmap from2;
511 enum bitmap_bits operation;
512{
c8d8ed65
RK
513#define HIGHEST_INDEX (unsigned int) ~0
514
096ab9ea
RK
515 bitmap_element *from1_ptr = from1->first;
516 bitmap_element *from2_ptr = from2->first;
c8d8ed65
RK
517 unsigned int indx1 = (from1_ptr) ? from1_ptr->indx : HIGHEST_INDEX;
518 unsigned int indx2 = (from2_ptr) ? from2_ptr->indx : HIGHEST_INDEX;
8229306b 519 bitmap_element *to_ptr = to->first;
096ab9ea
RK
520 bitmap_element *from1_tmp;
521 bitmap_element *from2_tmp;
8229306b 522 bitmap_element *to_tmp;
096ab9ea 523 unsigned int indx;
8229306b
RH
524 int changed = 0;
525
526#if BITMAP_ELEMENT_WORDS == 2
527#define DOIT(OP) \
528 do { \
529 unsigned HOST_WIDE_INT t0, t1, f10, f11, f20, f21; \
530 f10 = from1_tmp->bits[0]; \
531 f20 = from2_tmp->bits[0]; \
532 t0 = f10 OP f20; \
533 changed |= (t0 != to_tmp->bits[0]); \
534 f11 = from1_tmp->bits[1]; \
535 f21 = from2_tmp->bits[1]; \
536 t1 = f11 OP f21; \
537 changed |= (t1 != to_tmp->bits[1]); \
538 to_tmp->bits[0] = t0; \
539 to_tmp->bits[1] = t1; \
540 } while (0)
541#else
542#define DOIT(OP) \
543 do { \
544 unsigned HOST_WIDE_INT t, f1, f2; \
545 int i; \
546 for (i = 0; i < BITMAP_ELEMENT_WORDS; ++i) \
547 { \
548 f1 = from1_tmp->bits[i]; \
549 f2 = from2_tmp->bits[i]; \
550 t = f1 OP f2; \
551 changed |= (t != to_tmp->bits[i]); \
552 to_tmp->bits[i] = t; \
553 } \
554 } while (0)
29a82058 555#endif
096ab9ea 556
8229306b 557 to->first = to->current = 0;
096ab9ea
RK
558
559 while (from1_ptr != 0 || from2_ptr != 0)
560 {
561 /* Figure out whether we need to substitute zero elements for
562 missing links. */
563 if (indx1 == indx2)
564 {
565 indx = indx1;
566 from1_tmp = from1_ptr;
567 from2_tmp = from2_ptr;
568 from1_ptr = from1_ptr->next;
c8d8ed65 569 indx1 = (from1_ptr) ? from1_ptr->indx : HIGHEST_INDEX;
096ab9ea 570 from2_ptr = from2_ptr->next;
c8d8ed65 571 indx2 = (from2_ptr) ? from2_ptr->indx : HIGHEST_INDEX;
096ab9ea
RK
572 }
573 else if (indx1 < indx2)
574 {
575 indx = indx1;
576 from1_tmp = from1_ptr;
ae0ed63a 577 from2_tmp = &bitmap_zero_bits;
096ab9ea 578 from1_ptr = from1_ptr->next;
c8d8ed65 579 indx1 = (from1_ptr) ? from1_ptr->indx : HIGHEST_INDEX;
096ab9ea
RK
580 }
581 else
582 {
583 indx = indx2;
ae0ed63a 584 from1_tmp = &bitmap_zero_bits;
096ab9ea
RK
585 from2_tmp = from2_ptr;
586 from2_ptr = from2_ptr->next;
c8d8ed65 587 indx2 = (from2_ptr) ? from2_ptr->indx : HIGHEST_INDEX;
096ab9ea
RK
588 }
589
8229306b 590 /* Find the appropriate element from TO. Begin by discarding
ec5c56db 591 elements that we've skipped. */
8229306b
RH
592 while (to_ptr && to_ptr->indx < indx)
593 {
594 changed = 1;
595 to_tmp = to_ptr;
596 to_ptr = to_ptr->next;
b9a73e32 597 to_tmp->next = bitmap_free;
8229306b
RH
598 bitmap_free = to_tmp;
599 }
600 if (to_ptr && to_ptr->indx == indx)
601 {
602 to_tmp = to_ptr;
603 to_ptr = to_ptr->next;
604 }
605 else
606 to_tmp = bitmap_element_allocate ();
096ab9ea
RK
607
608 /* Do the operation, and if any bits are set, link it into the
609 linked list. */
610 switch (operation)
611 {
612 default:
613 abort ();
614
615 case BITMAP_AND:
8229306b 616 DOIT (&);
096ab9ea
RK
617 break;
618
619 case BITMAP_AND_COMPL:
8229306b 620 DOIT (&~);
096ab9ea
RK
621 break;
622
623 case BITMAP_IOR:
8229306b
RH
624 DOIT (|);
625 break;
ea193996
DB
626 case BITMAP_IOR_COMPL:
627 DOIT (|~);
628 break;
8229306b
RH
629 case BITMAP_XOR:
630 DOIT (^);
096ab9ea
RK
631 break;
632 }
633
8229306b 634 if (! bitmap_element_zerop (to_tmp))
096ab9ea 635 {
8229306b
RH
636 to_tmp->indx = indx;
637 bitmap_element_link (to, to_tmp);
b9a73e32
JM
638 }
639 else
640 {
641 to_tmp->next = bitmap_free;
642 bitmap_free = to_tmp;
096ab9ea
RK
643 }
644 }
645
8229306b
RH
646 /* If we have elements of TO left over, free the lot. */
647 if (to_ptr)
096ab9ea 648 {
8229306b
RH
649 changed = 1;
650 for (to_tmp = to_ptr; to_tmp->next ; to_tmp = to_tmp->next)
651 continue;
652 to_tmp->next = bitmap_free;
096ab9ea
RK
653 bitmap_free = to_ptr;
654 }
655
8229306b
RH
656#undef DOIT
657
658 return changed;
659}
660
661/* Return true if two bitmaps are identical. */
662
663int
664bitmap_equal_p (a, b)
665 bitmap a;
666 bitmap b;
667{
668 bitmap_head c;
669 int ret;
670
671 c.first = c.current = 0;
672 ret = ! bitmap_operation (&c, a, b, BITMAP_XOR);
673 bitmap_clear (&c);
674
675 return ret;
096ab9ea
RK
676}
677\f
678/* Or into bitmap TO bitmap FROM1 and'ed with the complement of
ec5c56db 679 bitmap FROM2. */
096ab9ea
RK
680
681void
682bitmap_ior_and_compl (to, from1, from2)
683 bitmap to;
684 bitmap from1;
685 bitmap from2;
686{
687 bitmap_head tmp;
688
689 tmp.first = tmp.current = 0;
690
691 bitmap_operation (&tmp, from1, from2, BITMAP_AND_COMPL);
692 bitmap_operation (to, to, &tmp, BITMAP_IOR);
693 bitmap_clear (&tmp);
694}
87e08c69
RH
695
696int
697bitmap_union_of_diff (dst, a, b, c)
698 bitmap dst;
699 bitmap a;
700 bitmap b;
701 bitmap c;
702{
703 bitmap_head tmp;
704 int changed;
705
706 tmp.first = tmp.current = 0;
707
708 bitmap_operation (&tmp, b, c, BITMAP_AND_COMPL);
709 changed = bitmap_operation (dst, &tmp, a, BITMAP_IOR);
710 bitmap_clear (&tmp);
711
712 return changed;
713}
096ab9ea
RK
714\f
715/* Initialize a bitmap header. */
716
717bitmap
718bitmap_initialize (head)
719 bitmap head;
720{
721 head->first = head->current = 0;
722
723 return head;
724}
725\f
726/* Debugging function to print out the contents of a bitmap. */
727
728void
bfd38496 729debug_bitmap_file (file, head)
096ab9ea
RK
730 FILE *file;
731 bitmap head;
732{
733 bitmap_element *ptr;
734
735 fprintf (file, "\nfirst = ");
683eb0e9 736 fprintf (file, HOST_PTR_PRINTF, (PTR) head->first);
096ab9ea 737 fprintf (file, " current = ");
683eb0e9 738 fprintf (file, HOST_PTR_PRINTF, (PTR) head->current);
096ab9ea
RK
739 fprintf (file, " indx = %u\n", head->indx);
740
741 for (ptr = head->first; ptr; ptr = ptr->next)
742 {
743 int i, j, col = 26;
744
745 fprintf (file, "\t");
683eb0e9 746 fprintf (file, HOST_PTR_PRINTF, (PTR) ptr);
096ab9ea 747 fprintf (file, " next = ");
683eb0e9 748 fprintf (file, HOST_PTR_PRINTF, (PTR) ptr->next);
096ab9ea 749 fprintf (file, " prev = ");
683eb0e9 750 fprintf (file, HOST_PTR_PRINTF, (PTR) ptr->prev);
096ab9ea
RK
751 fprintf (file, " indx = %u\n\t\tbits = {", ptr->indx);
752
753 for (i = 0; i < BITMAP_ELEMENT_WORDS; i++)
754 for (j = 0; j < HOST_BITS_PER_WIDE_INT; j++)
8229306b 755 if ((ptr->bits[i] >> j) & 1)
096ab9ea
RK
756 {
757 if (col > 70)
758 {
759 fprintf (file, "\n\t\t\t");
760 col = 24;
761 }
762
763 fprintf (file, " %u", (ptr->indx * BITMAP_ELEMENT_ALL_BITS
764 + i * HOST_BITS_PER_WIDE_INT + j));
765 col += 4;
766 }
767
768 fprintf (file, " }\n");
769 }
770}
a615c28a 771
096ab9ea
RK
772/* Function to be called from the debugger to print the contents
773 of a bitmap. */
774
775void
776debug_bitmap (head)
777 bitmap head;
778{
bfd38496 779 debug_bitmap_file (stdout, head);
096ab9ea 780}
a615c28a 781
bfd38496 782/* Function to print out the contents of a bitmap. Unlike debug_bitmap_file,
22fa5b8a
MM
783 it does not print anything but the bits. */
784
785void
786bitmap_print (file, head, prefix, suffix)
787 FILE *file;
788 bitmap head;
5d5993dd
KG
789 const char *prefix;
790 const char *suffix;
22fa5b8a 791{
5d5993dd 792 const char *comma = "";
22fa5b8a
MM
793 int i;
794
795 fputs (prefix, file);
796 EXECUTE_IF_SET_IN_BITMAP (head, 0, i,
797 {
798 fprintf (file, "%s%d", comma, i);
799 comma = ", ";
800 });
801 fputs (suffix, file);
802}