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
));
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
= xmalloc (bmap
->size
* sizeof (unsigned char));
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
= xrealloc (bmap
, amt
);
117 bmap
->popcount
= xrealloc (bmap
->popcount
,
118 size
* sizeof (unsigned char));
121 if (n_elms
> bmap
->n_bits
)
125 memset (bmap
->elms
+ bmap
->size
, -1,
126 bytes
- SBITMAP_SIZE_BYTES (bmap
));
128 /* Set the new bits if the original last element. */
129 last_bit
= bmap
->n_bits
% SBITMAP_ELT_BITS
;
131 bmap
->elms
[bmap
->size
- 1]
132 |= ~((SBITMAP_ELT_TYPE
)-1 >> (SBITMAP_ELT_BITS
- last_bit
));
134 /* Clear the unused bit in the new last element. */
135 last_bit
= n_elms
% SBITMAP_ELT_BITS
;
138 &= (SBITMAP_ELT_TYPE
)-1 >> (SBITMAP_ELT_BITS
- last_bit
);
142 memset (bmap
->elms
+ bmap
->size
, 0,
143 bytes
- SBITMAP_SIZE_BYTES (bmap
));
145 memset (bmap
->popcount
+ bmap
->size
, 0,
146 (size
* sizeof (unsigned char))
147 - (bmap
->size
* sizeof (unsigned char)));
151 else if (n_elms
< bmap
->n_bits
)
153 /* Clear the surplus bits in the last word. */
154 last_bit
= n_elms
% SBITMAP_ELT_BITS
;
158 &= (SBITMAP_ELT_TYPE
)-1 >> (SBITMAP_ELT_BITS
- last_bit
);
160 bmap
->popcount
[size
- 1] = do_popcount (bmap
->elms
[size
- 1]);
164 bmap
->n_bits
= n_elms
;
169 /* Re-allocate a simple bitmap of N_ELMS bits. New storage is uninitialized. */
172 sbitmap_realloc (sbitmap src
, unsigned int n_elms
)
174 unsigned int bytes
, size
, amt
;
177 size
= SBITMAP_SET_SIZE (n_elms
);
178 bytes
= size
* sizeof (SBITMAP_ELT_TYPE
);
179 amt
= (sizeof (struct simple_bitmap_def
)
180 + bytes
- sizeof (SBITMAP_ELT_TYPE
));
182 if (SBITMAP_SIZE_BYTES (src
) >= bytes
)
184 src
->n_bits
= n_elms
;
188 bmap
= (sbitmap
) xrealloc (src
, amt
);
189 bmap
->n_bits
= n_elms
;
194 /* Allocate a vector of N_VECS bitmaps of N_ELMS bits. */
197 sbitmap_vector_alloc (unsigned int n_vecs
, unsigned int n_elms
)
199 unsigned int i
, bytes
, offset
, elm_bytes
, size
, amt
, vector_bytes
;
200 sbitmap
*bitmap_vector
;
202 size
= SBITMAP_SET_SIZE (n_elms
);
203 bytes
= size
* sizeof (SBITMAP_ELT_TYPE
);
204 elm_bytes
= (sizeof (struct simple_bitmap_def
)
205 + bytes
- sizeof (SBITMAP_ELT_TYPE
));
206 vector_bytes
= n_vecs
* sizeof (sbitmap
*);
208 /* Round up `vector_bytes' to account for the alignment requirements
209 of an sbitmap. One could allocate the vector-table and set of sbitmaps
210 separately, but that requires maintaining two pointers or creating
211 a cover struct to hold both pointers (so our result is still just
212 one pointer). Neither is a bad idea, but this is simpler for now. */
214 /* Based on DEFAULT_ALIGNMENT computation in obstack.c. */
215 struct { char x
; SBITMAP_ELT_TYPE y
; } align
;
216 int alignment
= (char *) & align
.y
- & align
.x
;
217 vector_bytes
= (vector_bytes
+ alignment
- 1) & ~ (alignment
- 1);
220 amt
= vector_bytes
+ (n_vecs
* elm_bytes
);
221 bitmap_vector
= xmalloc (amt
);
223 for (i
= 0, offset
= vector_bytes
; i
< n_vecs
; i
++, offset
+= elm_bytes
)
225 sbitmap b
= (sbitmap
) ((char *) bitmap_vector
+ offset
);
227 bitmap_vector
[i
] = b
;
233 return bitmap_vector
;
236 /* Copy sbitmap SRC to DST. */
239 sbitmap_copy (sbitmap dst
, const_sbitmap src
)
241 memcpy (dst
->elms
, src
->elms
, sizeof (SBITMAP_ELT_TYPE
) * dst
->size
);
243 memcpy (dst
->popcount
, src
->popcount
, sizeof (unsigned char) * dst
->size
);
246 /* Copy the first N elements of sbitmap SRC to DST. */
249 sbitmap_copy_n (sbitmap dst
, const_sbitmap src
, unsigned int n
)
251 memcpy (dst
->elms
, src
->elms
, sizeof (SBITMAP_ELT_TYPE
) * n
);
253 memcpy (dst
->popcount
, src
->popcount
, sizeof (unsigned char) * n
);
256 /* Determine if a == b. */
258 sbitmap_equal (const_sbitmap a
, const_sbitmap b
)
260 return !memcmp (a
->elms
, b
->elms
, sizeof (SBITMAP_ELT_TYPE
) * a
->size
);
263 /* Return true if the bitmap is empty. */
266 sbitmap_empty_p (const_sbitmap bmap
)
269 for (i
=0; i
<bmap
->size
; i
++)
276 /* Return false if any of the N bits are set in MAP starting at
280 sbitmap_range_empty_p (const_sbitmap bmap
, unsigned int start
, unsigned int n
)
282 unsigned int i
= start
/ SBITMAP_ELT_BITS
;
283 SBITMAP_ELT_TYPE elm
;
284 unsigned int shift
= start
% SBITMAP_ELT_BITS
;
286 gcc_assert (bmap
->n_bits
>= start
+ n
);
291 if (shift
+ n
<= SBITMAP_ELT_BITS
)
293 /* The bits are totally contained in a single element. */
294 if (shift
+ n
< SBITMAP_ELT_BITS
)
295 elm
&= ((1 << n
) - 1);
302 n
-= SBITMAP_ELT_BITS
- shift
;
305 /* Deal with full elts. */
306 while (n
>= SBITMAP_ELT_BITS
)
311 n
-= SBITMAP_ELT_BITS
;
314 /* The leftover bits. */
318 elm
&= ((1 << n
) - 1);
327 /* Zero all elements in a bitmap. */
330 sbitmap_zero (sbitmap bmap
)
332 memset (bmap
->elms
, 0, SBITMAP_SIZE_BYTES (bmap
));
334 memset (bmap
->popcount
, 0, bmap
->size
* sizeof (unsigned char));
337 /* Set all elements in a bitmap to ones. */
340 sbitmap_ones (sbitmap bmap
)
342 unsigned int last_bit
;
344 memset (bmap
->elms
, -1, SBITMAP_SIZE_BYTES (bmap
));
346 memset (bmap
->popcount
, -1, bmap
->size
* sizeof (unsigned char));
348 last_bit
= bmap
->n_bits
% SBITMAP_ELT_BITS
;
351 bmap
->elms
[bmap
->size
- 1]
352 = (SBITMAP_ELT_TYPE
)-1 >> (SBITMAP_ELT_BITS
- last_bit
);
354 bmap
->popcount
[bmap
->size
- 1]
355 = do_popcount (bmap
->elms
[bmap
->size
- 1]);
359 /* Zero a vector of N_VECS bitmaps. */
362 sbitmap_vector_zero (sbitmap
*bmap
, unsigned int n_vecs
)
366 for (i
= 0; i
< n_vecs
; i
++)
367 sbitmap_zero (bmap
[i
]);
370 /* Set a vector of N_VECS bitmaps to ones. */
373 sbitmap_vector_ones (sbitmap
*bmap
, unsigned int n_vecs
)
377 for (i
= 0; i
< n_vecs
; i
++)
378 sbitmap_ones (bmap
[i
]);
381 /* Set DST to be A union (B - C).
383 Returns true if any change is made. */
386 sbitmap_union_of_diff_cg (sbitmap dst
, const_sbitmap a
, const_sbitmap b
, const_sbitmap c
)
388 unsigned int i
, n
= dst
->size
;
389 sbitmap_ptr dstp
= dst
->elms
;
390 const_sbitmap_ptr ap
= a
->elms
;
391 const_sbitmap_ptr bp
= b
->elms
;
392 const_sbitmap_ptr cp
= c
->elms
;
393 SBITMAP_ELT_TYPE changed
= 0;
395 gcc_assert (!dst
->popcount
);
397 for (i
= 0; i
< n
; i
++)
399 const SBITMAP_ELT_TYPE tmp
= *ap
++ | (*bp
++ & ~*cp
++);
400 changed
|= *dstp
^ tmp
;
408 sbitmap_union_of_diff (sbitmap dst
, const_sbitmap a
, const_sbitmap b
, const_sbitmap c
)
410 unsigned int i
, n
= dst
->size
;
411 sbitmap_ptr dstp
= dst
->elms
;
412 const_sbitmap_ptr ap
= a
->elms
;
413 const_sbitmap_ptr bp
= b
->elms
;
414 const_sbitmap_ptr cp
= c
->elms
;
416 gcc_assert (!dst
->popcount
&& !a
->popcount
417 && !b
->popcount
&& !c
->popcount
);
419 for (i
= 0; i
< n
; i
++)
420 *dstp
++ = *ap
++ | (*bp
++ & ~*cp
++);
423 /* Set bitmap DST to the bitwise negation of the bitmap SRC. */
426 sbitmap_not (sbitmap dst
, const_sbitmap src
)
428 unsigned int i
, n
= dst
->size
;
429 sbitmap_ptr dstp
= dst
->elms
;
430 const_sbitmap_ptr srcp
= src
->elms
;
431 unsigned int last_bit
;
433 gcc_assert (!dst
->popcount
);
435 for (i
= 0; i
< n
; i
++)
438 /* Zero all bits past n_bits, by ANDing dst with sbitmap_ones. */
439 last_bit
= src
->n_bits
% SBITMAP_ELT_BITS
;
441 dst
->elms
[n
-1] = dst
->elms
[n
-1]
442 & ((SBITMAP_ELT_TYPE
)-1 >> (SBITMAP_ELT_BITS
- last_bit
));
445 /* Set the bits in DST to be the difference between the bits
446 in A and the bits in B. i.e. dst = a & (~b). */
449 sbitmap_difference (sbitmap dst
, const_sbitmap a
, const_sbitmap b
)
451 unsigned int i
, dst_size
= dst
->size
;
452 unsigned int min_size
= dst
->size
;
453 sbitmap_ptr dstp
= dst
->elms
;
454 const_sbitmap_ptr ap
= a
->elms
;
455 const_sbitmap_ptr bp
= b
->elms
;
457 gcc_assert (!dst
->popcount
);
459 /* A should be at least as large as DEST, to have a defined source. */
460 gcc_assert (a
->size
>= dst_size
);
461 /* If minuend is smaller, we simply pretend it to be zero bits, i.e.
462 only copy the subtrahend into dest. */
463 if (b
->size
< min_size
)
465 for (i
= 0; i
< min_size
; i
++)
466 *dstp
++ = *ap
++ & (~*bp
++);
467 /* Now fill the rest of dest from A, if B was too short.
468 This makes sense only when destination and A differ. */
469 if (dst
!= a
&& i
!= dst_size
)
470 for (; i
< dst_size
; i
++)
474 /* Return true if there are any bits set in A are also set in B.
475 Return false otherwise. */
478 sbitmap_any_common_bits (const_sbitmap a
, const_sbitmap b
)
480 const_sbitmap_ptr ap
= a
->elms
;
481 const_sbitmap_ptr bp
= b
->elms
;
484 n
= MIN (a
->size
, b
->size
);
485 for (i
= 0; i
< n
; i
++)
486 if ((*ap
++ & *bp
++) != 0)
492 /* Set DST to be (A and B).
493 Return nonzero if any change is made. */
496 sbitmap_a_and_b_cg (sbitmap dst
, const_sbitmap a
, const_sbitmap b
)
498 unsigned int i
, n
= dst
->size
;
499 sbitmap_ptr dstp
= dst
->elms
;
500 const_sbitmap_ptr ap
= a
->elms
;
501 const_sbitmap_ptr bp
= b
->elms
;
502 SBITMAP_ELT_TYPE changed
= 0;
504 gcc_assert (!dst
->popcount
);
506 for (i
= 0; i
< n
; i
++)
508 const SBITMAP_ELT_TYPE tmp
= *ap
++ & *bp
++;
509 changed
|= *dstp
^ tmp
;
517 sbitmap_a_and_b (sbitmap dst
, const_sbitmap a
, const_sbitmap b
)
519 unsigned int i
, n
= dst
->size
;
520 sbitmap_ptr dstp
= dst
->elms
;
521 const_sbitmap_ptr ap
= a
->elms
;
522 const_sbitmap_ptr bp
= b
->elms
;
523 bool has_popcount
= dst
->popcount
!= NULL
;
524 unsigned char *popcountp
= dst
->popcount
;
526 for (i
= 0; i
< n
; i
++)
528 const SBITMAP_ELT_TYPE tmp
= *ap
++ & *bp
++;
531 bool wordchanged
= (*dstp
^ tmp
) != 0;
533 *popcountp
= do_popcount (tmp
);
538 #ifdef BITMAP_DEBUGGING
540 sbitmap_verify_popcount (dst
);
544 /* Set DST to be (A xor B)).
545 Return nonzero if any change is made. */
548 sbitmap_a_xor_b_cg (sbitmap dst
, const_sbitmap a
, const_sbitmap b
)
550 unsigned int i
, n
= dst
->size
;
551 sbitmap_ptr dstp
= dst
->elms
;
552 const_sbitmap_ptr ap
= a
->elms
;
553 const_sbitmap_ptr bp
= b
->elms
;
554 SBITMAP_ELT_TYPE changed
= 0;
556 gcc_assert (!dst
->popcount
);
558 for (i
= 0; i
< n
; i
++)
560 const SBITMAP_ELT_TYPE tmp
= *ap
++ ^ *bp
++;
561 changed
|= *dstp
^ tmp
;
569 sbitmap_a_xor_b (sbitmap dst
, const_sbitmap a
, const_sbitmap b
)
571 unsigned int i
, n
= dst
->size
;
572 sbitmap_ptr dstp
= dst
->elms
;
573 const_sbitmap_ptr ap
= a
->elms
;
574 const_sbitmap_ptr bp
= b
->elms
;
575 bool has_popcount
= dst
->popcount
!= NULL
;
576 unsigned char *popcountp
= dst
->popcount
;
578 for (i
= 0; i
< n
; i
++)
580 const SBITMAP_ELT_TYPE tmp
= *ap
++ ^ *bp
++;
583 bool wordchanged
= (*dstp
^ tmp
) != 0;
585 *popcountp
= do_popcount (tmp
);
590 #ifdef BITMAP_DEBUGGING
592 sbitmap_verify_popcount (dst
);
596 /* Set DST to be (A or B)).
597 Return nonzero if any change is made. */
600 sbitmap_a_or_b_cg (sbitmap dst
, const_sbitmap a
, const_sbitmap b
)
602 unsigned int i
, n
= dst
->size
;
603 sbitmap_ptr dstp
= dst
->elms
;
604 const_sbitmap_ptr ap
= a
->elms
;
605 const_sbitmap_ptr bp
= b
->elms
;
606 SBITMAP_ELT_TYPE changed
= 0;
608 gcc_assert (!dst
->popcount
);
610 for (i
= 0; i
< n
; i
++)
612 const SBITMAP_ELT_TYPE tmp
= *ap
++ | *bp
++;
613 changed
|= *dstp
^ tmp
;
621 sbitmap_a_or_b (sbitmap dst
, const_sbitmap a
, const_sbitmap b
)
623 unsigned int i
, n
= dst
->size
;
624 sbitmap_ptr dstp
= dst
->elms
;
625 const_sbitmap_ptr ap
= a
->elms
;
626 const_sbitmap_ptr bp
= b
->elms
;
627 bool has_popcount
= dst
->popcount
!= NULL
;
628 unsigned char *popcountp
= dst
->popcount
;
630 for (i
= 0; i
< n
; i
++)
632 const SBITMAP_ELT_TYPE tmp
= *ap
++ | *bp
++;
635 bool wordchanged
= (*dstp
^ tmp
) != 0;
637 *popcountp
= do_popcount (tmp
);
642 #ifdef BITMAP_DEBUGGING
644 sbitmap_verify_popcount (dst
);
648 /* Return nonzero if A is a subset of B. */
651 sbitmap_a_subset_b_p (const_sbitmap a
, const_sbitmap b
)
653 unsigned int i
, n
= a
->size
;
654 const_sbitmap_ptr ap
, bp
;
656 for (ap
= a
->elms
, bp
= b
->elms
, i
= 0; i
< n
; i
++, ap
++, bp
++)
657 if ((*ap
| *bp
) != *bp
)
663 /* Set DST to be (A or (B and C)).
664 Return nonzero if any change is made. */
667 sbitmap_a_or_b_and_c_cg (sbitmap dst
, const_sbitmap a
, const_sbitmap b
, const_sbitmap c
)
669 unsigned int i
, n
= dst
->size
;
670 sbitmap_ptr dstp
= dst
->elms
;
671 const_sbitmap_ptr ap
= a
->elms
;
672 const_sbitmap_ptr bp
= b
->elms
;
673 const_sbitmap_ptr cp
= c
->elms
;
674 SBITMAP_ELT_TYPE changed
= 0;
676 gcc_assert (!dst
->popcount
);
678 for (i
= 0; i
< n
; i
++)
680 const SBITMAP_ELT_TYPE tmp
= *ap
++ | (*bp
++ & *cp
++);
681 changed
|= *dstp
^ tmp
;
689 sbitmap_a_or_b_and_c (sbitmap dst
, const_sbitmap a
, const_sbitmap b
, const_sbitmap c
)
691 unsigned int i
, n
= dst
->size
;
692 sbitmap_ptr dstp
= dst
->elms
;
693 const_sbitmap_ptr ap
= a
->elms
;
694 const_sbitmap_ptr bp
= b
->elms
;
695 const_sbitmap_ptr cp
= c
->elms
;
697 gcc_assert (!dst
->popcount
);
699 for (i
= 0; i
< n
; i
++)
700 *dstp
++ = *ap
++ | (*bp
++ & *cp
++);
703 /* Set DST to be (A and (B or C)).
704 Return nonzero if any change is made. */
707 sbitmap_a_and_b_or_c_cg (sbitmap dst
, const_sbitmap a
, const_sbitmap b
, const_sbitmap c
)
709 unsigned int i
, n
= dst
->size
;
710 sbitmap_ptr dstp
= dst
->elms
;
711 const_sbitmap_ptr ap
= a
->elms
;
712 const_sbitmap_ptr bp
= b
->elms
;
713 const_sbitmap_ptr cp
= c
->elms
;
714 SBITMAP_ELT_TYPE changed
= 0;
716 gcc_assert (!dst
->popcount
);
718 for (i
= 0; i
< n
; i
++)
720 const SBITMAP_ELT_TYPE tmp
= *ap
++ & (*bp
++ | *cp
++);
721 changed
|= *dstp
^ tmp
;
729 sbitmap_a_and_b_or_c (sbitmap dst
, const_sbitmap a
, const_sbitmap b
, const_sbitmap c
)
731 unsigned int i
, n
= dst
->size
;
732 sbitmap_ptr dstp
= dst
->elms
;
733 const_sbitmap_ptr ap
= a
->elms
;
734 const_sbitmap_ptr bp
= b
->elms
;
735 const_sbitmap_ptr cp
= c
->elms
;
737 for (i
= 0; i
< n
; i
++)
738 *dstp
++ = *ap
++ & (*bp
++ | *cp
++);
742 /* Set the bitmap DST to the intersection of SRC of successors of
743 block number BB, using the new flow graph structures. */
746 sbitmap_intersection_of_succs (sbitmap dst
, sbitmap
*src
, int bb
)
748 basic_block b
= BASIC_BLOCK (bb
);
749 unsigned int set_size
= dst
->size
;
753 gcc_assert (!dst
->popcount
);
755 for (e
= NULL
, ix
= 0; ix
< EDGE_COUNT (b
->succs
); ix
++)
757 e
= EDGE_SUCC (b
, ix
);
758 if (e
->dest
== EXIT_BLOCK_PTR
)
761 sbitmap_copy (dst
, src
[e
->dest
->index
]);
768 for (++ix
; ix
< EDGE_COUNT (b
->succs
); ix
++)
773 e
= EDGE_SUCC (b
, ix
);
774 if (e
->dest
== EXIT_BLOCK_PTR
)
777 p
= src
[e
->dest
->index
]->elms
;
779 for (i
= 0; i
< set_size
; i
++)
784 /* Set the bitmap DST to the intersection of SRC of predecessors of
785 block number BB, using the new flow graph structures. */
788 sbitmap_intersection_of_preds (sbitmap dst
, sbitmap
*src
, int bb
)
790 basic_block b
= BASIC_BLOCK (bb
);
791 unsigned int set_size
= dst
->size
;
795 gcc_assert (!dst
->popcount
);
797 for (e
= NULL
, ix
= 0; ix
< EDGE_COUNT (b
->preds
); ix
++)
799 e
= EDGE_PRED (b
, ix
);
800 if (e
->src
== ENTRY_BLOCK_PTR
)
803 sbitmap_copy (dst
, src
[e
->src
->index
]);
810 for (++ix
; ix
< EDGE_COUNT (b
->preds
); ix
++)
815 e
= EDGE_PRED (b
, ix
);
816 if (e
->src
== ENTRY_BLOCK_PTR
)
819 p
= src
[e
->src
->index
]->elms
;
821 for (i
= 0; i
< set_size
; i
++)
826 /* Set the bitmap DST to the union of SRC of successors of
827 block number BB, using the new flow graph structures. */
830 sbitmap_union_of_succs (sbitmap dst
, sbitmap
*src
, int bb
)
832 basic_block b
= BASIC_BLOCK (bb
);
833 unsigned int set_size
= dst
->size
;
837 gcc_assert (!dst
->popcount
);
839 for (ix
= 0; ix
< EDGE_COUNT (b
->succs
); ix
++)
841 e
= EDGE_SUCC (b
, ix
);
842 if (e
->dest
== EXIT_BLOCK_PTR
)
845 sbitmap_copy (dst
, src
[e
->dest
->index
]);
849 if (ix
== EDGE_COUNT (b
->succs
))
852 for (ix
++; ix
< EDGE_COUNT (b
->succs
); ix
++)
857 e
= EDGE_SUCC (b
, ix
);
858 if (e
->dest
== EXIT_BLOCK_PTR
)
861 p
= src
[e
->dest
->index
]->elms
;
863 for (i
= 0; i
< set_size
; i
++)
868 /* Set the bitmap DST to the union of SRC of predecessors of
869 block number BB, using the new flow graph structures. */
872 sbitmap_union_of_preds (sbitmap dst
, sbitmap
*src
, int bb
)
874 basic_block b
= BASIC_BLOCK (bb
);
875 unsigned int set_size
= dst
->size
;
879 gcc_assert (!dst
->popcount
);
881 for (ix
= 0; ix
< EDGE_COUNT (b
->preds
); ix
++)
883 e
= EDGE_PRED (b
, ix
);
884 if (e
->src
== ENTRY_BLOCK_PTR
)
887 sbitmap_copy (dst
, src
[e
->src
->index
]);
891 if (ix
== EDGE_COUNT (b
->preds
))
894 for (ix
++; ix
< EDGE_COUNT (b
->preds
); ix
++)
899 e
= EDGE_PRED (b
, ix
);
900 if (e
->src
== ENTRY_BLOCK_PTR
)
903 p
= src
[e
->src
->index
]->elms
;
905 for (i
= 0; i
< set_size
; i
++)
911 /* Return number of first bit set in the bitmap, -1 if none. */
914 sbitmap_first_set_bit (const_sbitmap bmap
)
917 sbitmap_iterator sbi
;
919 EXECUTE_IF_SET_IN_SBITMAP (bmap
, 0, n
, sbi
)
924 /* Return number of last bit set in the bitmap, -1 if none. */
927 sbitmap_last_set_bit (const_sbitmap bmap
)
930 const SBITMAP_ELT_TYPE
*const ptr
= bmap
->elms
;
932 for (i
= bmap
->size
- 1; i
>= 0; i
--)
934 const SBITMAP_ELT_TYPE word
= ptr
[i
];
938 unsigned int index
= (i
+ 1) * SBITMAP_ELT_BITS
- 1;
939 SBITMAP_ELT_TYPE mask
940 = (SBITMAP_ELT_TYPE
) 1 << (SBITMAP_ELT_BITS
- 1);
944 if ((word
& mask
) != 0)
957 dump_sbitmap (FILE *file
, const_sbitmap bmap
)
959 unsigned int i
, n
, j
;
960 unsigned int set_size
= bmap
->size
;
961 unsigned int total_bits
= bmap
->n_bits
;
964 for (i
= n
= 0; i
< set_size
&& n
< total_bits
; i
++)
965 for (j
= 0; j
< SBITMAP_ELT_BITS
&& n
< total_bits
; j
++, n
++)
967 if (n
!= 0 && n
% 10 == 0)
971 (bmap
->elms
[i
] & ((SBITMAP_ELT_TYPE
) 1 << j
)) != 0);
974 fprintf (file
, "\n");
978 dump_sbitmap_file (FILE *file
, const_sbitmap bmap
)
982 fprintf (file
, "n_bits = %d, set = {", bmap
->n_bits
);
984 for (pos
= 30, i
= 0; i
< bmap
->n_bits
; i
++)
985 if (TEST_BIT (bmap
, i
))
989 fprintf (file
, "\n ");
993 fprintf (file
, "%d ", i
);
994 pos
+= 2 + (i
>= 10) + (i
>= 100) + (i
>= 1000);
997 fprintf (file
, "}\n");
1001 debug_sbitmap (const_sbitmap bmap
)
1003 dump_sbitmap_file (stderr
, bmap
);
1007 dump_sbitmap_vector (FILE *file
, const char *title
, const char *subtitle
,
1008 sbitmap
*bmaps
, int n_maps
)
1012 fprintf (file
, "%s\n", title
);
1013 for (bb
= 0; bb
< n_maps
; bb
++)
1015 fprintf (file
, "%s %d\n", subtitle
, bb
);
1016 dump_sbitmap (file
, bmaps
[bb
]);
1019 fprintf (file
, "\n");
1022 #if GCC_VERSION < 3400
1023 /* Table of number of set bits in a character, indexed by value of char. */
1024 static const unsigned char popcount_table
[] =
1026 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,
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 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,
1029 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,
1030 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,
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 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,
1033 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,
1036 /* Count the bits in an SBITMAP element A. */
1038 static unsigned long
1039 sbitmap_elt_popcount (SBITMAP_ELT_TYPE a
)
1041 unsigned long ret
= 0;
1047 /* Just do this the table way for now */
1048 for (i
= 0; i
< SBITMAP_ELT_BITS
; i
+= 8)
1049 ret
+= popcount_table
[(a
>> i
) & 0xff];
1054 /* Count the number of bits in SBITMAP a, up to bit MAXBIT. */
1057 sbitmap_popcount (const_sbitmap a
, unsigned long maxbit
)
1059 unsigned long count
= 0;
1061 unsigned int lastword
;
1066 if (maxbit
>= a
->n_bits
)
1069 /* Count the bits in the full word. */
1070 lastword
= MIN (a
->size
, SBITMAP_SET_SIZE (maxbit
+ 1) - 1);
1071 for (ix
= 0; ix
< lastword
; ix
++)
1075 count
+= a
->popcount
[ix
];
1076 #ifdef BITMAP_DEBUGGING
1077 gcc_assert (a
->popcount
[ix
] == do_popcount (a
->elms
[ix
]));
1081 count
+= do_popcount (a
->elms
[ix
]);
1084 /* Count the remaining bits. */
1085 if (lastword
< a
->size
)
1087 unsigned int bitindex
;
1088 SBITMAP_ELT_TYPE theword
= a
->elms
[lastword
];
1090 bitindex
= maxbit
% SBITMAP_ELT_BITS
;
1093 theword
&= (SBITMAP_ELT_TYPE
)-1 >> (SBITMAP_ELT_BITS
- bitindex
);
1094 count
+= do_popcount (theword
);