2 Copyright (C) 1999, 2000, 2002, 2003, 2004, 2006, 2007, 2008, 2010
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 /* FIXME: sbitmap is just a data structure, but we define dataflow functions
28 here also. This is conditional on IN_GCC (see second #ifdef IN_GCC
30 For now, also only conditionally include basic-block.h, but we should
31 find a better place for the dataflow functions. Perhaps cfganal.c? */
32 #include "basic-block.h"
35 #if GCC_VERSION >= 3400
36 # if HOST_BITS_PER_WIDEST_FAST_INT == HOST_BITS_PER_LONG
37 # define do_popcount(x) __builtin_popcountl(x)
38 # elif HOST_BITS_PER_WIDEST_FAST_INT == HOST_BITS_PER_LONGLONG
39 # define do_popcount(x) __builtin_popcountll(x)
41 # error "internal error: sbitmap.h and hwint.h are inconsistent"
44 static unsigned long sbitmap_elt_popcount (SBITMAP_ELT_TYPE
);
45 # define do_popcount(x) sbitmap_elt_popcount((x))
48 typedef SBITMAP_ELT_TYPE
*sbitmap_ptr
;
49 typedef const SBITMAP_ELT_TYPE
*const_sbitmap_ptr
;
51 /* This macro controls debugging that is as expensive as the
52 operations it verifies. */
54 /* #define BITMAP_DEBUGGING */
55 #ifdef BITMAP_DEBUGGING
57 /* Verify the population count of sbitmap A matches the cached value,
58 if there is a cached value. */
61 sbitmap_verify_popcount (const_sbitmap a
)
64 unsigned int lastword
;
70 for (ix
= 0; ix
< lastword
; ix
++)
71 gcc_assert (a
->popcount
[ix
] == do_popcount (a
->elms
[ix
]));
75 /* Bitmap manipulation routines. */
77 /* Allocate a simple bitmap of N_ELMS bits. */
80 sbitmap_alloc (unsigned int n_elms
)
82 unsigned int bytes
, size
, amt
;
85 size
= SBITMAP_SET_SIZE (n_elms
);
86 bytes
= size
* sizeof (SBITMAP_ELT_TYPE
);
87 amt
= (sizeof (struct simple_bitmap_def
)
88 + bytes
- sizeof (SBITMAP_ELT_TYPE
));
89 bmap
= (sbitmap
) xmalloc (amt
);
90 bmap
->n_bits
= n_elms
;
92 bmap
->popcount
= NULL
;
96 /* Allocate a simple bitmap of N_ELMS bits, and a popcount array. */
99 sbitmap_alloc_with_popcount (unsigned int n_elms
)
101 sbitmap
const bmap
= sbitmap_alloc (n_elms
);
102 bmap
->popcount
= XNEWVEC (unsigned char, bmap
->size
);
106 /* Resize a simple bitmap BMAP to N_ELMS bits. If increasing the
107 size of BMAP, clear the new bits to zero if the DEF argument
108 is zero, and set them to one otherwise. */
111 sbitmap_resize (sbitmap bmap
, unsigned int n_elms
, int def
)
113 unsigned int bytes
, size
, amt
;
114 unsigned int last_bit
;
116 size
= SBITMAP_SET_SIZE (n_elms
);
117 bytes
= size
* sizeof (SBITMAP_ELT_TYPE
);
118 if (bytes
> SBITMAP_SIZE_BYTES (bmap
))
120 amt
= (sizeof (struct simple_bitmap_def
)
121 + bytes
- sizeof (SBITMAP_ELT_TYPE
));
122 bmap
= (sbitmap
) xrealloc (bmap
, amt
);
124 bmap
->popcount
= XRESIZEVEC (unsigned char, bmap
->popcount
, size
);
127 if (n_elms
> bmap
->n_bits
)
131 memset (bmap
->elms
+ bmap
->size
, -1,
132 bytes
- SBITMAP_SIZE_BYTES (bmap
));
134 /* Set the new bits if the original last element. */
135 last_bit
= bmap
->n_bits
% SBITMAP_ELT_BITS
;
137 bmap
->elms
[bmap
->size
- 1]
138 |= ~((SBITMAP_ELT_TYPE
)-1 >> (SBITMAP_ELT_BITS
- last_bit
));
140 /* Clear the unused bit in the new last element. */
141 last_bit
= n_elms
% SBITMAP_ELT_BITS
;
144 &= (SBITMAP_ELT_TYPE
)-1 >> (SBITMAP_ELT_BITS
- last_bit
);
148 memset (bmap
->elms
+ bmap
->size
, 0,
149 bytes
- SBITMAP_SIZE_BYTES (bmap
));
151 memset (bmap
->popcount
+ bmap
->size
, 0,
152 (size
* sizeof (unsigned char))
153 - (bmap
->size
* sizeof (unsigned char)));
157 else if (n_elms
< bmap
->n_bits
)
159 /* Clear the surplus bits in the last word. */
160 last_bit
= n_elms
% SBITMAP_ELT_BITS
;
164 &= (SBITMAP_ELT_TYPE
)-1 >> (SBITMAP_ELT_BITS
- last_bit
);
166 bmap
->popcount
[size
- 1] = do_popcount (bmap
->elms
[size
- 1]);
170 bmap
->n_bits
= n_elms
;
175 /* Re-allocate a simple bitmap of N_ELMS bits. New storage is uninitialized. */
178 sbitmap_realloc (sbitmap src
, unsigned int n_elms
)
180 unsigned int bytes
, size
, amt
;
183 size
= SBITMAP_SET_SIZE (n_elms
);
184 bytes
= size
* sizeof (SBITMAP_ELT_TYPE
);
185 amt
= (sizeof (struct simple_bitmap_def
)
186 + bytes
- sizeof (SBITMAP_ELT_TYPE
));
188 if (SBITMAP_SIZE_BYTES (src
) >= bytes
)
190 src
->n_bits
= n_elms
;
194 bmap
= (sbitmap
) xrealloc (src
, amt
);
195 bmap
->n_bits
= n_elms
;
200 /* Allocate a vector of N_VECS bitmaps of N_ELMS bits. */
203 sbitmap_vector_alloc (unsigned int n_vecs
, unsigned int n_elms
)
205 unsigned int i
, bytes
, offset
, elm_bytes
, size
, amt
, vector_bytes
;
206 sbitmap
*bitmap_vector
;
208 size
= SBITMAP_SET_SIZE (n_elms
);
209 bytes
= size
* sizeof (SBITMAP_ELT_TYPE
);
210 elm_bytes
= (sizeof (struct simple_bitmap_def
)
211 + bytes
- sizeof (SBITMAP_ELT_TYPE
));
212 vector_bytes
= n_vecs
* sizeof (sbitmap
*);
214 /* Round up `vector_bytes' to account for the alignment requirements
215 of an sbitmap. One could allocate the vector-table and set of sbitmaps
216 separately, but that requires maintaining two pointers or creating
217 a cover struct to hold both pointers (so our result is still just
218 one pointer). Neither is a bad idea, but this is simpler for now. */
220 /* Based on DEFAULT_ALIGNMENT computation in obstack.c. */
221 struct { char x
; SBITMAP_ELT_TYPE y
; } align
;
222 int alignment
= (char *) & align
.y
- & align
.x
;
223 vector_bytes
= (vector_bytes
+ alignment
- 1) & ~ (alignment
- 1);
226 amt
= vector_bytes
+ (n_vecs
* elm_bytes
);
227 bitmap_vector
= (sbitmap
*) xmalloc (amt
);
229 for (i
= 0, offset
= vector_bytes
; i
< n_vecs
; i
++, offset
+= elm_bytes
)
231 sbitmap b
= (sbitmap
) ((char *) bitmap_vector
+ offset
);
233 bitmap_vector
[i
] = b
;
239 return bitmap_vector
;
242 /* Copy sbitmap SRC to DST. */
245 sbitmap_copy (sbitmap dst
, const_sbitmap src
)
247 memcpy (dst
->elms
, src
->elms
, sizeof (SBITMAP_ELT_TYPE
) * dst
->size
);
249 memcpy (dst
->popcount
, src
->popcount
, sizeof (unsigned char) * dst
->size
);
252 /* Copy the first N elements of sbitmap SRC to DST. */
255 sbitmap_copy_n (sbitmap dst
, const_sbitmap src
, unsigned int n
)
257 memcpy (dst
->elms
, src
->elms
, sizeof (SBITMAP_ELT_TYPE
) * n
);
259 memcpy (dst
->popcount
, src
->popcount
, sizeof (unsigned char) * n
);
262 /* Determine if a == b. */
264 sbitmap_equal (const_sbitmap a
, const_sbitmap b
)
266 return !memcmp (a
->elms
, b
->elms
, sizeof (SBITMAP_ELT_TYPE
) * a
->size
);
269 /* Return true if the bitmap is empty. */
272 sbitmap_empty_p (const_sbitmap bmap
)
275 for (i
=0; i
<bmap
->size
; i
++)
282 /* Return false if any of the N bits are set in MAP starting at
286 sbitmap_range_empty_p (const_sbitmap bmap
, unsigned int start
, unsigned int n
)
288 unsigned int i
= start
/ SBITMAP_ELT_BITS
;
289 SBITMAP_ELT_TYPE elm
;
290 unsigned int shift
= start
% SBITMAP_ELT_BITS
;
292 gcc_assert (bmap
->n_bits
>= start
+ n
);
297 if (shift
+ n
<= SBITMAP_ELT_BITS
)
299 /* The bits are totally contained in a single element. */
300 if (shift
+ n
< SBITMAP_ELT_BITS
)
301 elm
&= ((1 << n
) - 1);
308 n
-= SBITMAP_ELT_BITS
- shift
;
311 /* Deal with full elts. */
312 while (n
>= SBITMAP_ELT_BITS
)
317 n
-= SBITMAP_ELT_BITS
;
320 /* The leftover bits. */
324 elm
&= ((1 << n
) - 1);
333 /* Zero all elements in a bitmap. */
336 sbitmap_zero (sbitmap bmap
)
338 memset (bmap
->elms
, 0, SBITMAP_SIZE_BYTES (bmap
));
340 memset (bmap
->popcount
, 0, bmap
->size
* sizeof (unsigned char));
343 /* Set all elements in a bitmap to ones. */
346 sbitmap_ones (sbitmap bmap
)
348 unsigned int last_bit
;
350 memset (bmap
->elms
, -1, SBITMAP_SIZE_BYTES (bmap
));
352 memset (bmap
->popcount
, -1, bmap
->size
* sizeof (unsigned char));
354 last_bit
= bmap
->n_bits
% SBITMAP_ELT_BITS
;
357 bmap
->elms
[bmap
->size
- 1]
358 = (SBITMAP_ELT_TYPE
)-1 >> (SBITMAP_ELT_BITS
- last_bit
);
360 bmap
->popcount
[bmap
->size
- 1]
361 = do_popcount (bmap
->elms
[bmap
->size
- 1]);
365 /* Zero a vector of N_VECS bitmaps. */
368 sbitmap_vector_zero (sbitmap
*bmap
, unsigned int n_vecs
)
372 for (i
= 0; i
< n_vecs
; i
++)
373 sbitmap_zero (bmap
[i
]);
376 /* Set a vector of N_VECS bitmaps to ones. */
379 sbitmap_vector_ones (sbitmap
*bmap
, unsigned int n_vecs
)
383 for (i
= 0; i
< n_vecs
; i
++)
384 sbitmap_ones (bmap
[i
]);
387 /* Set DST to be A union (B - C).
389 Returns true if any change is made. */
392 sbitmap_union_of_diff_cg (sbitmap dst
, const_sbitmap a
, const_sbitmap b
, const_sbitmap c
)
394 unsigned int i
, n
= dst
->size
;
395 sbitmap_ptr dstp
= dst
->elms
;
396 const_sbitmap_ptr ap
= a
->elms
;
397 const_sbitmap_ptr bp
= b
->elms
;
398 const_sbitmap_ptr cp
= c
->elms
;
399 SBITMAP_ELT_TYPE changed
= 0;
401 gcc_assert (!dst
->popcount
);
403 for (i
= 0; i
< n
; i
++)
405 const SBITMAP_ELT_TYPE tmp
= *ap
++ | (*bp
++ & ~*cp
++);
406 changed
|= *dstp
^ tmp
;
414 sbitmap_union_of_diff (sbitmap dst
, const_sbitmap a
, const_sbitmap b
, const_sbitmap c
)
416 unsigned int i
, n
= dst
->size
;
417 sbitmap_ptr dstp
= dst
->elms
;
418 const_sbitmap_ptr ap
= a
->elms
;
419 const_sbitmap_ptr bp
= b
->elms
;
420 const_sbitmap_ptr cp
= c
->elms
;
422 gcc_assert (!dst
->popcount
&& !a
->popcount
423 && !b
->popcount
&& !c
->popcount
);
425 for (i
= 0; i
< n
; i
++)
426 *dstp
++ = *ap
++ | (*bp
++ & ~*cp
++);
429 /* Set bitmap DST to the bitwise negation of the bitmap SRC. */
432 sbitmap_not (sbitmap dst
, const_sbitmap src
)
434 unsigned int i
, n
= dst
->size
;
435 sbitmap_ptr dstp
= dst
->elms
;
436 const_sbitmap_ptr srcp
= src
->elms
;
437 unsigned int last_bit
;
439 gcc_assert (!dst
->popcount
);
441 for (i
= 0; i
< n
; i
++)
444 /* Zero all bits past n_bits, by ANDing dst with sbitmap_ones. */
445 last_bit
= src
->n_bits
% SBITMAP_ELT_BITS
;
447 dst
->elms
[n
-1] = dst
->elms
[n
-1]
448 & ((SBITMAP_ELT_TYPE
)-1 >> (SBITMAP_ELT_BITS
- last_bit
));
451 /* Set the bits in DST to be the difference between the bits
452 in A and the bits in B. i.e. dst = a & (~b). */
455 sbitmap_difference (sbitmap dst
, const_sbitmap a
, const_sbitmap b
)
457 unsigned int i
, dst_size
= dst
->size
;
458 unsigned int min_size
= dst
->size
;
459 sbitmap_ptr dstp
= dst
->elms
;
460 const_sbitmap_ptr ap
= a
->elms
;
461 const_sbitmap_ptr bp
= b
->elms
;
463 gcc_assert (!dst
->popcount
);
465 /* A should be at least as large as DEST, to have a defined source. */
466 gcc_assert (a
->size
>= dst_size
);
467 /* If minuend is smaller, we simply pretend it to be zero bits, i.e.
468 only copy the subtrahend into dest. */
469 if (b
->size
< min_size
)
471 for (i
= 0; i
< min_size
; i
++)
472 *dstp
++ = *ap
++ & (~*bp
++);
473 /* Now fill the rest of dest from A, if B was too short.
474 This makes sense only when destination and A differ. */
475 if (dst
!= a
&& i
!= dst_size
)
476 for (; i
< dst_size
; i
++)
480 /* Return true if there are any bits set in A are also set in B.
481 Return false otherwise. */
484 sbitmap_any_common_bits (const_sbitmap a
, const_sbitmap b
)
486 const_sbitmap_ptr ap
= a
->elms
;
487 const_sbitmap_ptr bp
= b
->elms
;
490 n
= MIN (a
->size
, b
->size
);
491 for (i
= 0; i
< n
; i
++)
492 if ((*ap
++ & *bp
++) != 0)
498 /* Set DST to be (A and B).
499 Return nonzero if any change is made. */
502 sbitmap_a_and_b_cg (sbitmap dst
, const_sbitmap a
, const_sbitmap b
)
504 unsigned int i
, n
= dst
->size
;
505 sbitmap_ptr dstp
= dst
->elms
;
506 const_sbitmap_ptr ap
= a
->elms
;
507 const_sbitmap_ptr bp
= b
->elms
;
508 SBITMAP_ELT_TYPE changed
= 0;
510 gcc_assert (!dst
->popcount
);
512 for (i
= 0; i
< n
; i
++)
514 const SBITMAP_ELT_TYPE tmp
= *ap
++ & *bp
++;
515 changed
|= *dstp
^ tmp
;
523 sbitmap_a_and_b (sbitmap dst
, const_sbitmap a
, const_sbitmap b
)
525 unsigned int i
, n
= dst
->size
;
526 sbitmap_ptr dstp
= dst
->elms
;
527 const_sbitmap_ptr ap
= a
->elms
;
528 const_sbitmap_ptr bp
= b
->elms
;
529 bool has_popcount
= dst
->popcount
!= NULL
;
530 unsigned char *popcountp
= dst
->popcount
;
532 for (i
= 0; i
< n
; i
++)
534 const SBITMAP_ELT_TYPE tmp
= *ap
++ & *bp
++;
537 bool wordchanged
= (*dstp
^ tmp
) != 0;
539 *popcountp
= do_popcount (tmp
);
544 #ifdef BITMAP_DEBUGGING
546 sbitmap_verify_popcount (dst
);
550 /* Set DST to be (A xor B)).
551 Return nonzero if any change is made. */
554 sbitmap_a_xor_b_cg (sbitmap dst
, const_sbitmap a
, const_sbitmap b
)
556 unsigned int i
, n
= dst
->size
;
557 sbitmap_ptr dstp
= dst
->elms
;
558 const_sbitmap_ptr ap
= a
->elms
;
559 const_sbitmap_ptr bp
= b
->elms
;
560 SBITMAP_ELT_TYPE changed
= 0;
562 gcc_assert (!dst
->popcount
);
564 for (i
= 0; i
< n
; i
++)
566 const SBITMAP_ELT_TYPE tmp
= *ap
++ ^ *bp
++;
567 changed
|= *dstp
^ tmp
;
575 sbitmap_a_xor_b (sbitmap dst
, const_sbitmap a
, const_sbitmap b
)
577 unsigned int i
, n
= dst
->size
;
578 sbitmap_ptr dstp
= dst
->elms
;
579 const_sbitmap_ptr ap
= a
->elms
;
580 const_sbitmap_ptr bp
= b
->elms
;
581 bool has_popcount
= dst
->popcount
!= NULL
;
582 unsigned char *popcountp
= dst
->popcount
;
584 for (i
= 0; i
< n
; i
++)
586 const SBITMAP_ELT_TYPE tmp
= *ap
++ ^ *bp
++;
589 bool wordchanged
= (*dstp
^ tmp
) != 0;
591 *popcountp
= do_popcount (tmp
);
596 #ifdef BITMAP_DEBUGGING
598 sbitmap_verify_popcount (dst
);
602 /* Set DST to be (A or B)).
603 Return nonzero if any change is made. */
606 sbitmap_a_or_b_cg (sbitmap dst
, const_sbitmap a
, const_sbitmap b
)
608 unsigned int i
, n
= dst
->size
;
609 sbitmap_ptr dstp
= dst
->elms
;
610 const_sbitmap_ptr ap
= a
->elms
;
611 const_sbitmap_ptr bp
= b
->elms
;
612 SBITMAP_ELT_TYPE changed
= 0;
614 gcc_assert (!dst
->popcount
);
616 for (i
= 0; i
< n
; i
++)
618 const SBITMAP_ELT_TYPE tmp
= *ap
++ | *bp
++;
619 changed
|= *dstp
^ tmp
;
627 sbitmap_a_or_b (sbitmap dst
, const_sbitmap a
, const_sbitmap b
)
629 unsigned int i
, n
= dst
->size
;
630 sbitmap_ptr dstp
= dst
->elms
;
631 const_sbitmap_ptr ap
= a
->elms
;
632 const_sbitmap_ptr bp
= b
->elms
;
633 bool has_popcount
= dst
->popcount
!= NULL
;
634 unsigned char *popcountp
= dst
->popcount
;
636 for (i
= 0; i
< n
; i
++)
638 const SBITMAP_ELT_TYPE tmp
= *ap
++ | *bp
++;
641 bool wordchanged
= (*dstp
^ tmp
) != 0;
643 *popcountp
= do_popcount (tmp
);
648 #ifdef BITMAP_DEBUGGING
650 sbitmap_verify_popcount (dst
);
654 /* Return nonzero if A is a subset of B. */
657 sbitmap_a_subset_b_p (const_sbitmap a
, const_sbitmap b
)
659 unsigned int i
, n
= a
->size
;
660 const_sbitmap_ptr ap
, bp
;
662 for (ap
= a
->elms
, bp
= b
->elms
, i
= 0; i
< n
; i
++, ap
++, bp
++)
663 if ((*ap
| *bp
) != *bp
)
669 /* Set DST to be (A or (B and C)).
670 Return nonzero if any change is made. */
673 sbitmap_a_or_b_and_c_cg (sbitmap dst
, const_sbitmap a
, const_sbitmap b
, const_sbitmap c
)
675 unsigned int i
, n
= dst
->size
;
676 sbitmap_ptr dstp
= dst
->elms
;
677 const_sbitmap_ptr ap
= a
->elms
;
678 const_sbitmap_ptr bp
= b
->elms
;
679 const_sbitmap_ptr cp
= c
->elms
;
680 SBITMAP_ELT_TYPE changed
= 0;
682 gcc_assert (!dst
->popcount
);
684 for (i
= 0; i
< n
; i
++)
686 const SBITMAP_ELT_TYPE tmp
= *ap
++ | (*bp
++ & *cp
++);
687 changed
|= *dstp
^ tmp
;
695 sbitmap_a_or_b_and_c (sbitmap dst
, const_sbitmap a
, const_sbitmap b
, const_sbitmap c
)
697 unsigned int i
, n
= dst
->size
;
698 sbitmap_ptr dstp
= dst
->elms
;
699 const_sbitmap_ptr ap
= a
->elms
;
700 const_sbitmap_ptr bp
= b
->elms
;
701 const_sbitmap_ptr cp
= c
->elms
;
703 gcc_assert (!dst
->popcount
);
705 for (i
= 0; i
< n
; i
++)
706 *dstp
++ = *ap
++ | (*bp
++ & *cp
++);
709 /* Set DST to be (A and (B or C)).
710 Return nonzero if any change is made. */
713 sbitmap_a_and_b_or_c_cg (sbitmap dst
, const_sbitmap a
, const_sbitmap b
, const_sbitmap c
)
715 unsigned int i
, n
= dst
->size
;
716 sbitmap_ptr dstp
= dst
->elms
;
717 const_sbitmap_ptr ap
= a
->elms
;
718 const_sbitmap_ptr bp
= b
->elms
;
719 const_sbitmap_ptr cp
= c
->elms
;
720 SBITMAP_ELT_TYPE changed
= 0;
722 gcc_assert (!dst
->popcount
);
724 for (i
= 0; i
< n
; i
++)
726 const SBITMAP_ELT_TYPE tmp
= *ap
++ & (*bp
++ | *cp
++);
727 changed
|= *dstp
^ tmp
;
735 sbitmap_a_and_b_or_c (sbitmap dst
, const_sbitmap a
, const_sbitmap b
, const_sbitmap c
)
737 unsigned int i
, n
= dst
->size
;
738 sbitmap_ptr dstp
= dst
->elms
;
739 const_sbitmap_ptr ap
= a
->elms
;
740 const_sbitmap_ptr bp
= b
->elms
;
741 const_sbitmap_ptr cp
= c
->elms
;
743 for (i
= 0; i
< n
; i
++)
744 *dstp
++ = *ap
++ & (*bp
++ | *cp
++);
748 /* FIXME: depends on basic-block.h, see comment at start of this file.
750 Ironically, the comments before the functions below suggest they do
751 dataflow using the "new flow graph structures", but that's the *old*
752 new data structures. The functions receive basic block numbers and
753 use BASIC_BLOCK(idx) to get the basic block. They should receive
754 the basic block directly, *sigh*. */
756 /* Set the bitmap DST to the intersection of SRC of successors of
757 block number BB, using the new flow graph structures. */
760 sbitmap_intersection_of_succs (sbitmap dst
, sbitmap
*src
, int bb
)
762 basic_block b
= BASIC_BLOCK (bb
);
763 unsigned int set_size
= dst
->size
;
767 gcc_assert (!dst
->popcount
);
769 for (e
= NULL
, ix
= 0; ix
< EDGE_COUNT (b
->succs
); ix
++)
771 e
= EDGE_SUCC (b
, ix
);
772 if (e
->dest
== EXIT_BLOCK_PTR
)
775 sbitmap_copy (dst
, src
[e
->dest
->index
]);
782 for (++ix
; ix
< EDGE_COUNT (b
->succs
); ix
++)
787 e
= EDGE_SUCC (b
, ix
);
788 if (e
->dest
== EXIT_BLOCK_PTR
)
791 p
= src
[e
->dest
->index
]->elms
;
793 for (i
= 0; i
< set_size
; i
++)
798 /* Set the bitmap DST to the intersection of SRC of predecessors of
799 block number BB, using the new flow graph structures. */
802 sbitmap_intersection_of_preds (sbitmap dst
, sbitmap
*src
, int bb
)
804 basic_block b
= BASIC_BLOCK (bb
);
805 unsigned int set_size
= dst
->size
;
809 gcc_assert (!dst
->popcount
);
811 for (e
= NULL
, ix
= 0; ix
< EDGE_COUNT (b
->preds
); ix
++)
813 e
= EDGE_PRED (b
, ix
);
814 if (e
->src
== ENTRY_BLOCK_PTR
)
817 sbitmap_copy (dst
, src
[e
->src
->index
]);
824 for (++ix
; ix
< EDGE_COUNT (b
->preds
); ix
++)
829 e
= EDGE_PRED (b
, ix
);
830 if (e
->src
== ENTRY_BLOCK_PTR
)
833 p
= src
[e
->src
->index
]->elms
;
835 for (i
= 0; i
< set_size
; i
++)
840 /* Set the bitmap DST to the union of SRC of successors of
841 block number BB, using the new flow graph structures. */
844 sbitmap_union_of_succs (sbitmap dst
, sbitmap
*src
, int bb
)
846 basic_block b
= BASIC_BLOCK (bb
);
847 unsigned int set_size
= dst
->size
;
851 gcc_assert (!dst
->popcount
);
853 for (ix
= 0; ix
< EDGE_COUNT (b
->succs
); ix
++)
855 e
= EDGE_SUCC (b
, ix
);
856 if (e
->dest
== EXIT_BLOCK_PTR
)
859 sbitmap_copy (dst
, src
[e
->dest
->index
]);
863 if (ix
== EDGE_COUNT (b
->succs
))
866 for (ix
++; ix
< EDGE_COUNT (b
->succs
); ix
++)
871 e
= EDGE_SUCC (b
, ix
);
872 if (e
->dest
== EXIT_BLOCK_PTR
)
875 p
= src
[e
->dest
->index
]->elms
;
877 for (i
= 0; i
< set_size
; i
++)
882 /* Set the bitmap DST to the union of SRC of predecessors of
883 block number BB, using the new flow graph structures. */
886 sbitmap_union_of_preds (sbitmap dst
, sbitmap
*src
, int bb
)
888 basic_block b
= BASIC_BLOCK (bb
);
889 unsigned int set_size
= dst
->size
;
893 gcc_assert (!dst
->popcount
);
895 for (ix
= 0; ix
< EDGE_COUNT (b
->preds
); ix
++)
897 e
= EDGE_PRED (b
, ix
);
898 if (e
->src
== ENTRY_BLOCK_PTR
)
901 sbitmap_copy (dst
, src
[e
->src
->index
]);
905 if (ix
== EDGE_COUNT (b
->preds
))
908 for (ix
++; ix
< EDGE_COUNT (b
->preds
); ix
++)
913 e
= EDGE_PRED (b
, ix
);
914 if (e
->src
== ENTRY_BLOCK_PTR
)
917 p
= src
[e
->src
->index
]->elms
;
919 for (i
= 0; i
< set_size
; i
++)
925 /* Return number of first bit set in the bitmap, -1 if none. */
928 sbitmap_first_set_bit (const_sbitmap bmap
)
931 sbitmap_iterator sbi
;
933 EXECUTE_IF_SET_IN_SBITMAP (bmap
, 0, n
, sbi
)
938 /* Return number of last bit set in the bitmap, -1 if none. */
941 sbitmap_last_set_bit (const_sbitmap bmap
)
944 const SBITMAP_ELT_TYPE
*const ptr
= bmap
->elms
;
946 for (i
= bmap
->size
- 1; i
>= 0; i
--)
948 const SBITMAP_ELT_TYPE word
= ptr
[i
];
952 unsigned int index
= (i
+ 1) * SBITMAP_ELT_BITS
- 1;
953 SBITMAP_ELT_TYPE mask
954 = (SBITMAP_ELT_TYPE
) 1 << (SBITMAP_ELT_BITS
- 1);
958 if ((word
& mask
) != 0)
971 dump_sbitmap (FILE *file
, const_sbitmap bmap
)
973 unsigned int i
, n
, j
;
974 unsigned int set_size
= bmap
->size
;
975 unsigned int total_bits
= bmap
->n_bits
;
978 for (i
= n
= 0; i
< set_size
&& n
< total_bits
; i
++)
979 for (j
= 0; j
< SBITMAP_ELT_BITS
&& n
< total_bits
; j
++, n
++)
981 if (n
!= 0 && n
% 10 == 0)
985 (bmap
->elms
[i
] & ((SBITMAP_ELT_TYPE
) 1 << j
)) != 0);
988 fprintf (file
, "\n");
992 dump_sbitmap_file (FILE *file
, const_sbitmap bmap
)
996 fprintf (file
, "n_bits = %d, set = {", bmap
->n_bits
);
998 for (pos
= 30, i
= 0; i
< bmap
->n_bits
; i
++)
999 if (TEST_BIT (bmap
, i
))
1003 fprintf (file
, "\n ");
1007 fprintf (file
, "%d ", i
);
1008 pos
+= 2 + (i
>= 10) + (i
>= 100) + (i
>= 1000);
1011 fprintf (file
, "}\n");
1015 debug_sbitmap (const_sbitmap bmap
)
1017 dump_sbitmap_file (stderr
, bmap
);
1021 dump_sbitmap_vector (FILE *file
, const char *title
, const char *subtitle
,
1022 sbitmap
*bmaps
, int n_maps
)
1026 fprintf (file
, "%s\n", title
);
1027 for (bb
= 0; bb
< n_maps
; bb
++)
1029 fprintf (file
, "%s %d\n", subtitle
, bb
);
1030 dump_sbitmap (file
, bmaps
[bb
]);
1033 fprintf (file
, "\n");
1036 #if GCC_VERSION < 3400
1037 /* Table of number of set bits in a character, indexed by value of char. */
1038 static const unsigned char popcount_table
[] =
1040 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,
1041 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,
1042 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,
1043 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,
1044 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,
1045 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,
1046 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,
1047 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,
1050 /* Count the bits in an SBITMAP element A. */
1052 static unsigned long
1053 sbitmap_elt_popcount (SBITMAP_ELT_TYPE a
)
1055 unsigned long ret
= 0;
1061 /* Just do this the table way for now */
1062 for (i
= 0; i
< SBITMAP_ELT_BITS
; i
+= 8)
1063 ret
+= popcount_table
[(a
>> i
) & 0xff];
1068 /* Count the number of bits in SBITMAP a, up to bit MAXBIT. */
1071 sbitmap_popcount (const_sbitmap a
, unsigned long maxbit
)
1073 unsigned long count
= 0;
1075 unsigned int lastword
;
1080 if (maxbit
>= a
->n_bits
)
1083 /* Count the bits in the full word. */
1084 lastword
= MIN (a
->size
, SBITMAP_SET_SIZE (maxbit
+ 1) - 1);
1085 for (ix
= 0; ix
< lastword
; ix
++)
1089 count
+= a
->popcount
[ix
];
1090 #ifdef BITMAP_DEBUGGING
1091 gcc_assert (a
->popcount
[ix
] == do_popcount (a
->elms
[ix
]));
1095 count
+= do_popcount (a
->elms
[ix
]);
1098 /* Count the remaining bits. */
1099 if (lastword
< a
->size
)
1101 unsigned int bitindex
;
1102 SBITMAP_ELT_TYPE theword
= a
->elms
[lastword
];
1104 bitindex
= maxbit
% SBITMAP_ELT_BITS
;
1107 theword
&= (SBITMAP_ELT_TYPE
)-1 >> (SBITMAP_ELT_BITS
- bitindex
);
1108 count
+= do_popcount (theword
);