2 Copyright (C) 1999, 2000, 2002, 2003, 2004, 2006, 2007, 2008
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 3, 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 COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
27 #include "hard-reg-set.h"
29 #include "basic-block.h"
31 #if GCC_VERSION >= 3400
32 #if HOST_BITS_PER_WIDEST_FAST_INT == HOST_BITS_PER_LONG
33 #define do_popcount(x) __builtin_popcountl(x)
34 #elif HOST_BITS_PER_WIDEST_FAST_INT == HOST_BITS_PER_LONGLONG
35 #define do_popcount(x) __builtin_popcountll(x)
37 #error "internal error: sbitmap.h and hwint.h are inconsistent"
40 static unsigned long sbitmap_elt_popcount (SBITMAP_ELT_TYPE
);
41 #define do_popcount(x) sbitmap_elt_popcount((x))
44 /* This macro controls debugging that is as expensive as the
45 operations it verifies. */
47 /* #define BITMAP_DEBUGGING */
48 #ifdef BITMAP_DEBUGGING
50 /* Verify the population count of sbitmap A matches the cached value,
51 if there is a cached value. */
54 sbitmap_verify_popcount (const_sbitmap a
)
57 unsigned int lastword
;
63 for (ix
= 0; ix
< lastword
; ix
++)
64 gcc_assert (a
->popcount
[ix
] == do_popcount (a
->elms
[ix
]));
68 /* Bitmap manipulation routines. */
70 /* Allocate a simple bitmap of N_ELMS bits. */
73 sbitmap_alloc (unsigned int n_elms
)
75 unsigned int bytes
, size
, amt
;
78 size
= SBITMAP_SET_SIZE (n_elms
);
79 bytes
= size
* sizeof (SBITMAP_ELT_TYPE
);
80 amt
= (sizeof (struct simple_bitmap_def
)
81 + bytes
- sizeof (SBITMAP_ELT_TYPE
));
82 bmap
= (sbitmap
) xmalloc (amt
);
83 bmap
->n_bits
= n_elms
;
85 bmap
->popcount
= NULL
;
89 /* Allocate a simple bitmap of N_ELMS bits, and a popcount array. */
92 sbitmap_alloc_with_popcount (unsigned int n_elms
)
94 sbitmap
const bmap
= sbitmap_alloc (n_elms
);
95 bmap
->popcount
= XNEWVEC (unsigned char, bmap
->size
);
99 /* Resize a simple bitmap BMAP to N_ELMS bits. If increasing the
100 size of BMAP, clear the new bits to zero if the DEF argument
101 is zero, and set them to one otherwise. */
104 sbitmap_resize (sbitmap bmap
, unsigned int n_elms
, int def
)
106 unsigned int bytes
, size
, amt
;
107 unsigned int last_bit
;
109 size
= SBITMAP_SET_SIZE (n_elms
);
110 bytes
= size
* sizeof (SBITMAP_ELT_TYPE
);
111 if (bytes
> SBITMAP_SIZE_BYTES (bmap
))
113 amt
= (sizeof (struct simple_bitmap_def
)
114 + bytes
- sizeof (SBITMAP_ELT_TYPE
));
115 bmap
= (sbitmap
) xrealloc (bmap
, amt
);
117 bmap
->popcount
= XRESIZEVEC (unsigned char, bmap
->popcount
, size
);
120 if (n_elms
> bmap
->n_bits
)
124 memset (bmap
->elms
+ bmap
->size
, -1,
125 bytes
- SBITMAP_SIZE_BYTES (bmap
));
127 /* Set the new bits if the original last element. */
128 last_bit
= bmap
->n_bits
% SBITMAP_ELT_BITS
;
130 bmap
->elms
[bmap
->size
- 1]
131 |= ~((SBITMAP_ELT_TYPE
)-1 >> (SBITMAP_ELT_BITS
- last_bit
));
133 /* Clear the unused bit in the new last element. */
134 last_bit
= n_elms
% SBITMAP_ELT_BITS
;
137 &= (SBITMAP_ELT_TYPE
)-1 >> (SBITMAP_ELT_BITS
- last_bit
);
141 memset (bmap
->elms
+ bmap
->size
, 0,
142 bytes
- SBITMAP_SIZE_BYTES (bmap
));
144 memset (bmap
->popcount
+ bmap
->size
, 0,
145 (size
* sizeof (unsigned char))
146 - (bmap
->size
* sizeof (unsigned char)));
150 else if (n_elms
< bmap
->n_bits
)
152 /* Clear the surplus bits in the last word. */
153 last_bit
= n_elms
% SBITMAP_ELT_BITS
;
157 &= (SBITMAP_ELT_TYPE
)-1 >> (SBITMAP_ELT_BITS
- last_bit
);
159 bmap
->popcount
[size
- 1] = do_popcount (bmap
->elms
[size
- 1]);
163 bmap
->n_bits
= n_elms
;
168 /* Re-allocate a simple bitmap of N_ELMS bits. New storage is uninitialized. */
171 sbitmap_realloc (sbitmap src
, unsigned int n_elms
)
173 unsigned int bytes
, size
, amt
;
176 size
= SBITMAP_SET_SIZE (n_elms
);
177 bytes
= size
* sizeof (SBITMAP_ELT_TYPE
);
178 amt
= (sizeof (struct simple_bitmap_def
)
179 + bytes
- sizeof (SBITMAP_ELT_TYPE
));
181 if (SBITMAP_SIZE_BYTES (src
) >= bytes
)
183 src
->n_bits
= n_elms
;
187 bmap
= (sbitmap
) xrealloc (src
, amt
);
188 bmap
->n_bits
= n_elms
;
193 /* Allocate a vector of N_VECS bitmaps of N_ELMS bits. */
196 sbitmap_vector_alloc (unsigned int n_vecs
, unsigned int n_elms
)
198 unsigned int i
, bytes
, offset
, elm_bytes
, size
, amt
, vector_bytes
;
199 sbitmap
*bitmap_vector
;
201 size
= SBITMAP_SET_SIZE (n_elms
);
202 bytes
= size
* sizeof (SBITMAP_ELT_TYPE
);
203 elm_bytes
= (sizeof (struct simple_bitmap_def
)
204 + bytes
- sizeof (SBITMAP_ELT_TYPE
));
205 vector_bytes
= n_vecs
* sizeof (sbitmap
*);
207 /* Round up `vector_bytes' to account for the alignment requirements
208 of an sbitmap. One could allocate the vector-table and set of sbitmaps
209 separately, but that requires maintaining two pointers or creating
210 a cover struct to hold both pointers (so our result is still just
211 one pointer). Neither is a bad idea, but this is simpler for now. */
213 /* Based on DEFAULT_ALIGNMENT computation in obstack.c. */
214 struct { char x
; SBITMAP_ELT_TYPE y
; } align
;
215 int alignment
= (char *) & align
.y
- & align
.x
;
216 vector_bytes
= (vector_bytes
+ alignment
- 1) & ~ (alignment
- 1);
219 amt
= vector_bytes
+ (n_vecs
* elm_bytes
);
220 bitmap_vector
= (sbitmap
*) xmalloc (amt
);
222 for (i
= 0, offset
= vector_bytes
; i
< n_vecs
; i
++, offset
+= elm_bytes
)
224 sbitmap b
= (sbitmap
) ((char *) bitmap_vector
+ offset
);
226 bitmap_vector
[i
] = b
;
232 return bitmap_vector
;
235 /* Copy sbitmap SRC to DST. */
238 sbitmap_copy (sbitmap dst
, const_sbitmap src
)
240 memcpy (dst
->elms
, src
->elms
, sizeof (SBITMAP_ELT_TYPE
) * dst
->size
);
242 memcpy (dst
->popcount
, src
->popcount
, sizeof (unsigned char) * dst
->size
);
245 /* Copy the first N elements of sbitmap SRC to DST. */
248 sbitmap_copy_n (sbitmap dst
, const_sbitmap src
, unsigned int n
)
250 memcpy (dst
->elms
, src
->elms
, sizeof (SBITMAP_ELT_TYPE
) * n
);
252 memcpy (dst
->popcount
, src
->popcount
, sizeof (unsigned char) * n
);
255 /* Determine if a == b. */
257 sbitmap_equal (const_sbitmap a
, const_sbitmap b
)
259 return !memcmp (a
->elms
, b
->elms
, sizeof (SBITMAP_ELT_TYPE
) * a
->size
);
262 /* Return true if the bitmap is empty. */
265 sbitmap_empty_p (const_sbitmap bmap
)
268 for (i
=0; i
<bmap
->size
; i
++)
275 /* Return false if any of the N bits are set in MAP starting at
279 sbitmap_range_empty_p (const_sbitmap bmap
, unsigned int start
, unsigned int n
)
281 unsigned int i
= start
/ SBITMAP_ELT_BITS
;
282 SBITMAP_ELT_TYPE elm
;
283 unsigned int shift
= start
% SBITMAP_ELT_BITS
;
285 gcc_assert (bmap
->n_bits
>= start
+ n
);
290 if (shift
+ n
<= SBITMAP_ELT_BITS
)
292 /* The bits are totally contained in a single element. */
293 if (shift
+ n
< SBITMAP_ELT_BITS
)
294 elm
&= ((1 << n
) - 1);
301 n
-= SBITMAP_ELT_BITS
- shift
;
304 /* Deal with full elts. */
305 while (n
>= SBITMAP_ELT_BITS
)
310 n
-= SBITMAP_ELT_BITS
;
313 /* The leftover bits. */
317 elm
&= ((1 << n
) - 1);
326 /* Zero all elements in a bitmap. */
329 sbitmap_zero (sbitmap bmap
)
331 memset (bmap
->elms
, 0, SBITMAP_SIZE_BYTES (bmap
));
333 memset (bmap
->popcount
, 0, bmap
->size
* sizeof (unsigned char));
336 /* Set all elements in a bitmap to ones. */
339 sbitmap_ones (sbitmap bmap
)
341 unsigned int last_bit
;
343 memset (bmap
->elms
, -1, SBITMAP_SIZE_BYTES (bmap
));
345 memset (bmap
->popcount
, -1, bmap
->size
* sizeof (unsigned char));
347 last_bit
= bmap
->n_bits
% SBITMAP_ELT_BITS
;
350 bmap
->elms
[bmap
->size
- 1]
351 = (SBITMAP_ELT_TYPE
)-1 >> (SBITMAP_ELT_BITS
- last_bit
);
353 bmap
->popcount
[bmap
->size
- 1]
354 = do_popcount (bmap
->elms
[bmap
->size
- 1]);
358 /* Zero a vector of N_VECS bitmaps. */
361 sbitmap_vector_zero (sbitmap
*bmap
, unsigned int n_vecs
)
365 for (i
= 0; i
< n_vecs
; i
++)
366 sbitmap_zero (bmap
[i
]);
369 /* Set a vector of N_VECS bitmaps to ones. */
372 sbitmap_vector_ones (sbitmap
*bmap
, unsigned int n_vecs
)
376 for (i
= 0; i
< n_vecs
; i
++)
377 sbitmap_ones (bmap
[i
]);
380 /* Set DST to be A union (B - C).
382 Returns true if any change is made. */
385 sbitmap_union_of_diff_cg (sbitmap dst
, const_sbitmap a
, const_sbitmap b
, const_sbitmap c
)
387 unsigned int i
, n
= dst
->size
;
388 sbitmap_ptr dstp
= dst
->elms
;
389 const_sbitmap_ptr ap
= a
->elms
;
390 const_sbitmap_ptr bp
= b
->elms
;
391 const_sbitmap_ptr cp
= c
->elms
;
392 SBITMAP_ELT_TYPE changed
= 0;
394 gcc_assert (!dst
->popcount
);
396 for (i
= 0; i
< n
; i
++)
398 const SBITMAP_ELT_TYPE tmp
= *ap
++ | (*bp
++ & ~*cp
++);
399 changed
|= *dstp
^ tmp
;
407 sbitmap_union_of_diff (sbitmap dst
, const_sbitmap a
, const_sbitmap b
, const_sbitmap c
)
409 unsigned int i
, n
= dst
->size
;
410 sbitmap_ptr dstp
= dst
->elms
;
411 const_sbitmap_ptr ap
= a
->elms
;
412 const_sbitmap_ptr bp
= b
->elms
;
413 const_sbitmap_ptr cp
= c
->elms
;
415 gcc_assert (!dst
->popcount
&& !a
->popcount
416 && !b
->popcount
&& !c
->popcount
);
418 for (i
= 0; i
< n
; i
++)
419 *dstp
++ = *ap
++ | (*bp
++ & ~*cp
++);
422 /* Set bitmap DST to the bitwise negation of the bitmap SRC. */
425 sbitmap_not (sbitmap dst
, const_sbitmap src
)
427 unsigned int i
, n
= dst
->size
;
428 sbitmap_ptr dstp
= dst
->elms
;
429 const_sbitmap_ptr srcp
= src
->elms
;
430 unsigned int last_bit
;
432 gcc_assert (!dst
->popcount
);
434 for (i
= 0; i
< n
; i
++)
437 /* Zero all bits past n_bits, by ANDing dst with sbitmap_ones. */
438 last_bit
= src
->n_bits
% SBITMAP_ELT_BITS
;
440 dst
->elms
[n
-1] = dst
->elms
[n
-1]
441 & ((SBITMAP_ELT_TYPE
)-1 >> (SBITMAP_ELT_BITS
- last_bit
));
444 /* Set the bits in DST to be the difference between the bits
445 in A and the bits in B. i.e. dst = a & (~b). */
448 sbitmap_difference (sbitmap dst
, const_sbitmap a
, const_sbitmap b
)
450 unsigned int i
, dst_size
= dst
->size
;
451 unsigned int min_size
= dst
->size
;
452 sbitmap_ptr dstp
= dst
->elms
;
453 const_sbitmap_ptr ap
= a
->elms
;
454 const_sbitmap_ptr bp
= b
->elms
;
456 gcc_assert (!dst
->popcount
);
458 /* A should be at least as large as DEST, to have a defined source. */
459 gcc_assert (a
->size
>= dst_size
);
460 /* If minuend is smaller, we simply pretend it to be zero bits, i.e.
461 only copy the subtrahend into dest. */
462 if (b
->size
< min_size
)
464 for (i
= 0; i
< min_size
; i
++)
465 *dstp
++ = *ap
++ & (~*bp
++);
466 /* Now fill the rest of dest from A, if B was too short.
467 This makes sense only when destination and A differ. */
468 if (dst
!= a
&& i
!= dst_size
)
469 for (; i
< dst_size
; i
++)
473 /* Return true if there are any bits set in A are also set in B.
474 Return false otherwise. */
477 sbitmap_any_common_bits (const_sbitmap a
, const_sbitmap b
)
479 const_sbitmap_ptr ap
= a
->elms
;
480 const_sbitmap_ptr bp
= b
->elms
;
483 n
= MIN (a
->size
, b
->size
);
484 for (i
= 0; i
< n
; i
++)
485 if ((*ap
++ & *bp
++) != 0)
491 /* Set DST to be (A and B).
492 Return nonzero if any change is made. */
495 sbitmap_a_and_b_cg (sbitmap dst
, const_sbitmap a
, const_sbitmap b
)
497 unsigned int i
, n
= dst
->size
;
498 sbitmap_ptr dstp
= dst
->elms
;
499 const_sbitmap_ptr ap
= a
->elms
;
500 const_sbitmap_ptr bp
= b
->elms
;
501 SBITMAP_ELT_TYPE changed
= 0;
503 gcc_assert (!dst
->popcount
);
505 for (i
= 0; i
< n
; i
++)
507 const SBITMAP_ELT_TYPE tmp
= *ap
++ & *bp
++;
508 changed
|= *dstp
^ tmp
;
516 sbitmap_a_and_b (sbitmap dst
, const_sbitmap a
, const_sbitmap b
)
518 unsigned int i
, n
= dst
->size
;
519 sbitmap_ptr dstp
= dst
->elms
;
520 const_sbitmap_ptr ap
= a
->elms
;
521 const_sbitmap_ptr bp
= b
->elms
;
522 bool has_popcount
= dst
->popcount
!= NULL
;
523 unsigned char *popcountp
= dst
->popcount
;
525 for (i
= 0; i
< n
; i
++)
527 const SBITMAP_ELT_TYPE tmp
= *ap
++ & *bp
++;
530 bool wordchanged
= (*dstp
^ tmp
) != 0;
532 *popcountp
= do_popcount (tmp
);
537 #ifdef BITMAP_DEBUGGING
539 sbitmap_verify_popcount (dst
);
543 /* Set DST to be (A xor B)).
544 Return nonzero if any change is made. */
547 sbitmap_a_xor_b_cg (sbitmap dst
, const_sbitmap a
, const_sbitmap b
)
549 unsigned int i
, n
= dst
->size
;
550 sbitmap_ptr dstp
= dst
->elms
;
551 const_sbitmap_ptr ap
= a
->elms
;
552 const_sbitmap_ptr bp
= b
->elms
;
553 SBITMAP_ELT_TYPE changed
= 0;
555 gcc_assert (!dst
->popcount
);
557 for (i
= 0; i
< n
; i
++)
559 const SBITMAP_ELT_TYPE tmp
= *ap
++ ^ *bp
++;
560 changed
|= *dstp
^ tmp
;
568 sbitmap_a_xor_b (sbitmap dst
, const_sbitmap a
, const_sbitmap b
)
570 unsigned int i
, n
= dst
->size
;
571 sbitmap_ptr dstp
= dst
->elms
;
572 const_sbitmap_ptr ap
= a
->elms
;
573 const_sbitmap_ptr bp
= b
->elms
;
574 bool has_popcount
= dst
->popcount
!= NULL
;
575 unsigned char *popcountp
= dst
->popcount
;
577 for (i
= 0; i
< n
; i
++)
579 const SBITMAP_ELT_TYPE tmp
= *ap
++ ^ *bp
++;
582 bool wordchanged
= (*dstp
^ tmp
) != 0;
584 *popcountp
= do_popcount (tmp
);
589 #ifdef BITMAP_DEBUGGING
591 sbitmap_verify_popcount (dst
);
595 /* Set DST to be (A or B)).
596 Return nonzero if any change is made. */
599 sbitmap_a_or_b_cg (sbitmap dst
, const_sbitmap a
, const_sbitmap b
)
601 unsigned int i
, n
= dst
->size
;
602 sbitmap_ptr dstp
= dst
->elms
;
603 const_sbitmap_ptr ap
= a
->elms
;
604 const_sbitmap_ptr bp
= b
->elms
;
605 SBITMAP_ELT_TYPE changed
= 0;
607 gcc_assert (!dst
->popcount
);
609 for (i
= 0; i
< n
; i
++)
611 const SBITMAP_ELT_TYPE tmp
= *ap
++ | *bp
++;
612 changed
|= *dstp
^ tmp
;
620 sbitmap_a_or_b (sbitmap dst
, const_sbitmap a
, const_sbitmap b
)
622 unsigned int i
, n
= dst
->size
;
623 sbitmap_ptr dstp
= dst
->elms
;
624 const_sbitmap_ptr ap
= a
->elms
;
625 const_sbitmap_ptr bp
= b
->elms
;
626 bool has_popcount
= dst
->popcount
!= NULL
;
627 unsigned char *popcountp
= dst
->popcount
;
629 for (i
= 0; i
< n
; i
++)
631 const SBITMAP_ELT_TYPE tmp
= *ap
++ | *bp
++;
634 bool wordchanged
= (*dstp
^ tmp
) != 0;
636 *popcountp
= do_popcount (tmp
);
641 #ifdef BITMAP_DEBUGGING
643 sbitmap_verify_popcount (dst
);
647 /* Return nonzero if A is a subset of B. */
650 sbitmap_a_subset_b_p (const_sbitmap a
, const_sbitmap b
)
652 unsigned int i
, n
= a
->size
;
653 const_sbitmap_ptr ap
, bp
;
655 for (ap
= a
->elms
, bp
= b
->elms
, i
= 0; i
< n
; i
++, ap
++, bp
++)
656 if ((*ap
| *bp
) != *bp
)
662 /* Set DST to be (A or (B and C)).
663 Return nonzero if any change is made. */
666 sbitmap_a_or_b_and_c_cg (sbitmap dst
, const_sbitmap a
, const_sbitmap b
, const_sbitmap c
)
668 unsigned int i
, n
= dst
->size
;
669 sbitmap_ptr dstp
= dst
->elms
;
670 const_sbitmap_ptr ap
= a
->elms
;
671 const_sbitmap_ptr bp
= b
->elms
;
672 const_sbitmap_ptr cp
= c
->elms
;
673 SBITMAP_ELT_TYPE changed
= 0;
675 gcc_assert (!dst
->popcount
);
677 for (i
= 0; i
< n
; i
++)
679 const SBITMAP_ELT_TYPE tmp
= *ap
++ | (*bp
++ & *cp
++);
680 changed
|= *dstp
^ tmp
;
688 sbitmap_a_or_b_and_c (sbitmap dst
, const_sbitmap a
, const_sbitmap b
, const_sbitmap c
)
690 unsigned int i
, n
= dst
->size
;
691 sbitmap_ptr dstp
= dst
->elms
;
692 const_sbitmap_ptr ap
= a
->elms
;
693 const_sbitmap_ptr bp
= b
->elms
;
694 const_sbitmap_ptr cp
= c
->elms
;
696 gcc_assert (!dst
->popcount
);
698 for (i
= 0; i
< n
; i
++)
699 *dstp
++ = *ap
++ | (*bp
++ & *cp
++);
702 /* Set DST to be (A and (B or C)).
703 Return nonzero if any change is made. */
706 sbitmap_a_and_b_or_c_cg (sbitmap dst
, const_sbitmap a
, const_sbitmap b
, const_sbitmap c
)
708 unsigned int i
, n
= dst
->size
;
709 sbitmap_ptr dstp
= dst
->elms
;
710 const_sbitmap_ptr ap
= a
->elms
;
711 const_sbitmap_ptr bp
= b
->elms
;
712 const_sbitmap_ptr cp
= c
->elms
;
713 SBITMAP_ELT_TYPE changed
= 0;
715 gcc_assert (!dst
->popcount
);
717 for (i
= 0; i
< n
; i
++)
719 const SBITMAP_ELT_TYPE tmp
= *ap
++ & (*bp
++ | *cp
++);
720 changed
|= *dstp
^ tmp
;
728 sbitmap_a_and_b_or_c (sbitmap dst
, const_sbitmap a
, const_sbitmap b
, const_sbitmap c
)
730 unsigned int i
, n
= dst
->size
;
731 sbitmap_ptr dstp
= dst
->elms
;
732 const_sbitmap_ptr ap
= a
->elms
;
733 const_sbitmap_ptr bp
= b
->elms
;
734 const_sbitmap_ptr cp
= c
->elms
;
736 for (i
= 0; i
< n
; i
++)
737 *dstp
++ = *ap
++ & (*bp
++ | *cp
++);
741 /* Set the bitmap DST to the intersection of SRC of successors of
742 block number BB, using the new flow graph structures. */
745 sbitmap_intersection_of_succs (sbitmap dst
, sbitmap
*src
, int bb
)
747 basic_block b
= BASIC_BLOCK (bb
);
748 unsigned int set_size
= dst
->size
;
752 gcc_assert (!dst
->popcount
);
754 for (e
= NULL
, ix
= 0; ix
< EDGE_COUNT (b
->succs
); ix
++)
756 e
= EDGE_SUCC (b
, ix
);
757 if (e
->dest
== EXIT_BLOCK_PTR
)
760 sbitmap_copy (dst
, src
[e
->dest
->index
]);
767 for (++ix
; ix
< EDGE_COUNT (b
->succs
); ix
++)
772 e
= EDGE_SUCC (b
, ix
);
773 if (e
->dest
== EXIT_BLOCK_PTR
)
776 p
= src
[e
->dest
->index
]->elms
;
778 for (i
= 0; i
< set_size
; i
++)
783 /* Set the bitmap DST to the intersection of SRC of predecessors of
784 block number BB, using the new flow graph structures. */
787 sbitmap_intersection_of_preds (sbitmap dst
, sbitmap
*src
, int bb
)
789 basic_block b
= BASIC_BLOCK (bb
);
790 unsigned int set_size
= dst
->size
;
794 gcc_assert (!dst
->popcount
);
796 for (e
= NULL
, ix
= 0; ix
< EDGE_COUNT (b
->preds
); ix
++)
798 e
= EDGE_PRED (b
, ix
);
799 if (e
->src
== ENTRY_BLOCK_PTR
)
802 sbitmap_copy (dst
, src
[e
->src
->index
]);
809 for (++ix
; ix
< EDGE_COUNT (b
->preds
); ix
++)
814 e
= EDGE_PRED (b
, ix
);
815 if (e
->src
== ENTRY_BLOCK_PTR
)
818 p
= src
[e
->src
->index
]->elms
;
820 for (i
= 0; i
< set_size
; i
++)
825 /* Set the bitmap DST to the union of SRC of successors of
826 block number BB, using the new flow graph structures. */
829 sbitmap_union_of_succs (sbitmap dst
, sbitmap
*src
, int bb
)
831 basic_block b
= BASIC_BLOCK (bb
);
832 unsigned int set_size
= dst
->size
;
836 gcc_assert (!dst
->popcount
);
838 for (ix
= 0; ix
< EDGE_COUNT (b
->succs
); ix
++)
840 e
= EDGE_SUCC (b
, ix
);
841 if (e
->dest
== EXIT_BLOCK_PTR
)
844 sbitmap_copy (dst
, src
[e
->dest
->index
]);
848 if (ix
== EDGE_COUNT (b
->succs
))
851 for (ix
++; ix
< EDGE_COUNT (b
->succs
); ix
++)
856 e
= EDGE_SUCC (b
, ix
);
857 if (e
->dest
== EXIT_BLOCK_PTR
)
860 p
= src
[e
->dest
->index
]->elms
;
862 for (i
= 0; i
< set_size
; i
++)
867 /* Set the bitmap DST to the union of SRC of predecessors of
868 block number BB, using the new flow graph structures. */
871 sbitmap_union_of_preds (sbitmap dst
, sbitmap
*src
, int bb
)
873 basic_block b
= BASIC_BLOCK (bb
);
874 unsigned int set_size
= dst
->size
;
878 gcc_assert (!dst
->popcount
);
880 for (ix
= 0; ix
< EDGE_COUNT (b
->preds
); ix
++)
882 e
= EDGE_PRED (b
, ix
);
883 if (e
->src
== ENTRY_BLOCK_PTR
)
886 sbitmap_copy (dst
, src
[e
->src
->index
]);
890 if (ix
== EDGE_COUNT (b
->preds
))
893 for (ix
++; ix
< EDGE_COUNT (b
->preds
); ix
++)
898 e
= EDGE_PRED (b
, ix
);
899 if (e
->src
== ENTRY_BLOCK_PTR
)
902 p
= src
[e
->src
->index
]->elms
;
904 for (i
= 0; i
< set_size
; i
++)
910 /* Return number of first bit set in the bitmap, -1 if none. */
913 sbitmap_first_set_bit (const_sbitmap bmap
)
916 sbitmap_iterator sbi
;
918 EXECUTE_IF_SET_IN_SBITMAP (bmap
, 0, n
, sbi
)
923 /* Return number of last bit set in the bitmap, -1 if none. */
926 sbitmap_last_set_bit (const_sbitmap bmap
)
929 const SBITMAP_ELT_TYPE
*const ptr
= bmap
->elms
;
931 for (i
= bmap
->size
- 1; i
>= 0; i
--)
933 const SBITMAP_ELT_TYPE word
= ptr
[i
];
937 unsigned int index
= (i
+ 1) * SBITMAP_ELT_BITS
- 1;
938 SBITMAP_ELT_TYPE mask
939 = (SBITMAP_ELT_TYPE
) 1 << (SBITMAP_ELT_BITS
- 1);
943 if ((word
& mask
) != 0)
956 dump_sbitmap (FILE *file
, const_sbitmap bmap
)
958 unsigned int i
, n
, j
;
959 unsigned int set_size
= bmap
->size
;
960 unsigned int total_bits
= bmap
->n_bits
;
963 for (i
= n
= 0; i
< set_size
&& n
< total_bits
; i
++)
964 for (j
= 0; j
< SBITMAP_ELT_BITS
&& n
< total_bits
; j
++, n
++)
966 if (n
!= 0 && n
% 10 == 0)
970 (bmap
->elms
[i
] & ((SBITMAP_ELT_TYPE
) 1 << j
)) != 0);
973 fprintf (file
, "\n");
977 dump_sbitmap_file (FILE *file
, const_sbitmap bmap
)
981 fprintf (file
, "n_bits = %d, set = {", bmap
->n_bits
);
983 for (pos
= 30, i
= 0; i
< bmap
->n_bits
; i
++)
984 if (TEST_BIT (bmap
, i
))
988 fprintf (file
, "\n ");
992 fprintf (file
, "%d ", i
);
993 pos
+= 2 + (i
>= 10) + (i
>= 100) + (i
>= 1000);
996 fprintf (file
, "}\n");
1000 debug_sbitmap (const_sbitmap bmap
)
1002 dump_sbitmap_file (stderr
, bmap
);
1006 dump_sbitmap_vector (FILE *file
, const char *title
, const char *subtitle
,
1007 sbitmap
*bmaps
, int n_maps
)
1011 fprintf (file
, "%s\n", title
);
1012 for (bb
= 0; bb
< n_maps
; bb
++)
1014 fprintf (file
, "%s %d\n", subtitle
, bb
);
1015 dump_sbitmap (file
, bmaps
[bb
]);
1018 fprintf (file
, "\n");
1021 #if GCC_VERSION < 3400
1022 /* Table of number of set bits in a character, indexed by value of char. */
1023 static const unsigned char popcount_table
[] =
1025 0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
1026 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
1027 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
1028 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
1029 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
1030 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
1031 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
1032 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8,
1035 /* Count the bits in an SBITMAP element A. */
1037 static unsigned long
1038 sbitmap_elt_popcount (SBITMAP_ELT_TYPE a
)
1040 unsigned long ret
= 0;
1046 /* Just do this the table way for now */
1047 for (i
= 0; i
< SBITMAP_ELT_BITS
; i
+= 8)
1048 ret
+= popcount_table
[(a
>> i
) & 0xff];
1053 /* Count the number of bits in SBITMAP a, up to bit MAXBIT. */
1056 sbitmap_popcount (const_sbitmap a
, unsigned long maxbit
)
1058 unsigned long count
= 0;
1060 unsigned int lastword
;
1065 if (maxbit
>= a
->n_bits
)
1068 /* Count the bits in the full word. */
1069 lastword
= MIN (a
->size
, SBITMAP_SET_SIZE (maxbit
+ 1) - 1);
1070 for (ix
= 0; ix
< lastword
; ix
++)
1074 count
+= a
->popcount
[ix
];
1075 #ifdef BITMAP_DEBUGGING
1076 gcc_assert (a
->popcount
[ix
] == do_popcount (a
->elms
[ix
]));
1080 count
+= do_popcount (a
->elms
[ix
]);
1083 /* Count the remaining bits. */
1084 if (lastword
< a
->size
)
1086 unsigned int bitindex
;
1087 SBITMAP_ELT_TYPE theword
= a
->elms
[lastword
];
1089 bitindex
= maxbit
% SBITMAP_ELT_BITS
;
1092 theword
&= (SBITMAP_ELT_TYPE
)-1 >> (SBITMAP_ELT_BITS
- bitindex
);
1093 count
+= do_popcount (theword
);