aboutsummaryrefslogtreecommitdiff
path: root/gcc/sbitmap.c
diff options
context:
space:
mode:
authorLawrence Crowl <crowl@google.com>2012-10-30 00:02:55 +0000
committerLawrence Crowl <crowl@gcc.gnu.org>2012-10-30 00:02:55 +0000
commitf61e445a74b138a2071a0af9f55c2d6e45fe2d5d (patch)
tree1ab800d2373b19aaee52a26a91b2c67b2657101e /gcc/sbitmap.c
parent880661a48b6e2f3f4b3c05860d3c9737b2a1dcc8 (diff)
downloadgcc-f61e445a74b138a2071a0af9f55c2d6e45fe2d5d.zip
gcc-f61e445a74b138a2071a0af9f55c2d6e45fe2d5d.tar.gz
gcc-f61e445a74b138a2071a0af9f55c2d6e45fe2d5d.tar.bz2
This patch implements the unification of the *bitmap interfaces as discussed.
Essentially, we rename ebitmap and sbitmap functions to use the same names as the bitmap functions. This rename works because we can now overload on the bitmap type. Some macros now become inline functions to enable that overloading. The sbitmap non-bool returning bitwise operations have been merged with the bool versions. Sometimes this merge involved modifying the non-bool version to compute the bool value, and sometimes modifying bool version to add additional work from the non-bool version. The redundant routines have been removed. The allocation functions have not been renamed, because we often do not have an argument on which to overload. The cardinality functions have not been renamed, because they have different parameters, and are thus not interchangable. The iteration functions have not been renamed, because they are functionally different. Tested on x86_64, contrib/config-list.mk testing passed. Index: gcc/ChangeLog 2012-10-29 Lawrence Crowl <crowl@google.com> * sbitmap.h (sbitmap_copy): Rename bitmap_copy. (sbitmap_copy_n): Rename bitmap_copy_n. (sbitmap_equal): Rename bitmap_equal_p. (sbitmap_empty_p): Rename bitmap_empty_p. (sbitmap_range_empty_p): Rename bitmap_range_empty_p. (sbitmap_zero): Rename bitmap_clear. (sbitmap_ones): Rename bitmap_ones. (sbitmap_vector_zero): Rename bitmap_vector_clear. (sbitmap_vector_ones): Rename bitmap_vector_ones. (sbitmap_not): Rename bitmap_not. (sbitmap_a_and_b_cg): Commented out. (sbitmap_a_and_b): Rename bitmap_and. Add bool return. (sbitmap_difference): Rename bitmap_and_compl. (sbitmap_a_or_b_cg): Commented out. (sbitmap_a_or_b): Rename bitmap_xor. Add bool return. (sbitmap_a_xor_b_cg): Commented out. (sbitmap_a_xor_b): Rename bitmap_xor. Add bool return. (sbitmap_a_and_b_or_c_cg): Rename bitmap_and_or. (sbitmap_a_and_b_or_c): Commented out. (sbitmap_a_or_b_and_c_cg): Rename bitmap_or_and. (sbitmap_a_or_b_and_c): Commented out. (sbitmap_union_of_diff_cg): Rename bitmap_ior_and_compl. (sbitmap_union_of_diff): Commented out. (dump_sbitmap): Rename dump_bitmap. (dump_sbitmap_file): Rename dump_bitmap_file. (debug_sbitmap): Rename debug_bitmap. (dump_sbitmap_vector): Rename dump_bitmap_vector. (sbitmap_first_set_bit): Rename bitmap_first_set_bit. (sbitmap_last_set_bit): Rename bitmap_last_set_bit. (sbitmap_a_subset_b_p): Rename bitmap_subset_p. (sbitmap_any_common_bits): Rename bitmap_intersect_p. (#define sbitmap_free): Reimplement as inline function. (#define sbitmap_vector_free): Reimplement as inline function. * bitmap.h (#define bitmap_zero): Remove as redundant. (#define bitmap_empty_p): Reimplement as inline function. (#define dump_bitmap): Reimplement as inline function. From-SVN: r192969
Diffstat (limited to 'gcc/sbitmap.c')
-rw-r--r--gcc/sbitmap.c188
1 files changed, 48 insertions, 140 deletions
diff --git a/gcc/sbitmap.c b/gcc/sbitmap.c
index 6aac459..737b0cd 100644
--- a/gcc/sbitmap.c
+++ b/gcc/sbitmap.c
@@ -238,7 +238,7 @@ sbitmap_vector_alloc (unsigned int n_vecs, unsigned int n_elms)
/* Copy sbitmap SRC to DST. */
void
-sbitmap_copy (sbitmap dst, const_sbitmap src)
+bitmap_copy (sbitmap dst, const_sbitmap src)
{
memcpy (dst->elms, src->elms, sizeof (SBITMAP_ELT_TYPE) * dst->size);
if (dst->popcount)
@@ -248,7 +248,7 @@ sbitmap_copy (sbitmap dst, const_sbitmap src)
/* Copy the first N elements of sbitmap SRC to DST. */
void
-sbitmap_copy_n (sbitmap dst, const_sbitmap src, unsigned int n)
+bitmap_copy_n (sbitmap dst, const_sbitmap src, unsigned int n)
{
memcpy (dst->elms, src->elms, sizeof (SBITMAP_ELT_TYPE) * n);
if (dst->popcount)
@@ -257,7 +257,7 @@ sbitmap_copy_n (sbitmap dst, const_sbitmap src, unsigned int n)
/* Determine if a == b. */
int
-sbitmap_equal (const_sbitmap a, const_sbitmap b)
+bitmap_equal_p (const_sbitmap a, const_sbitmap b)
{
return !memcmp (a->elms, b->elms, sizeof (SBITMAP_ELT_TYPE) * a->size);
}
@@ -265,7 +265,7 @@ sbitmap_equal (const_sbitmap a, const_sbitmap b)
/* Return true if the bitmap is empty. */
bool
-sbitmap_empty_p (const_sbitmap bmap)
+bitmap_empty_p (const_sbitmap bmap)
{
unsigned int i;
for (i=0; i<bmap->size; i++)
@@ -279,7 +279,7 @@ sbitmap_empty_p (const_sbitmap bmap)
START. */
bool
-sbitmap_range_empty_p (const_sbitmap bmap, unsigned int start, unsigned int n)
+bitmap_range_empty_p (const_sbitmap bmap, unsigned int start, unsigned int n)
{
unsigned int i = start / SBITMAP_ELT_BITS;
SBITMAP_ELT_TYPE elm;
@@ -329,7 +329,7 @@ sbitmap_range_empty_p (const_sbitmap bmap, unsigned int start, unsigned int n)
/* Zero all elements in a bitmap. */
void
-sbitmap_zero (sbitmap bmap)
+bitmap_clear (sbitmap bmap)
{
memset (bmap->elms, 0, SBITMAP_SIZE_BYTES (bmap));
if (bmap->popcount)
@@ -339,7 +339,7 @@ sbitmap_zero (sbitmap bmap)
/* Set all elements in a bitmap to ones. */
void
-sbitmap_ones (sbitmap bmap)
+bitmap_ones (sbitmap bmap)
{
unsigned int last_bit;
@@ -361,23 +361,23 @@ sbitmap_ones (sbitmap bmap)
/* Zero a vector of N_VECS bitmaps. */
void
-sbitmap_vector_zero (sbitmap *bmap, unsigned int n_vecs)
+bitmap_vector_clear (sbitmap *bmap, unsigned int n_vecs)
{
unsigned int i;
for (i = 0; i < n_vecs; i++)
- sbitmap_zero (bmap[i]);
+ bitmap_clear (bmap[i]);
}
/* Set a vector of N_VECS bitmaps to ones. */
void
-sbitmap_vector_ones (sbitmap *bmap, unsigned int n_vecs)
+bitmap_vector_ones (sbitmap *bmap, unsigned int n_vecs)
{
unsigned int i;
for (i = 0; i < n_vecs; i++)
- sbitmap_ones (bmap[i]);
+ bitmap_ones (bmap[i]);
}
/* Set DST to be A union (B - C).
@@ -385,7 +385,7 @@ sbitmap_vector_ones (sbitmap *bmap, unsigned int n_vecs)
Returns true if any change is made. */
bool
-sbitmap_union_of_diff_cg (sbitmap dst, const_sbitmap a, const_sbitmap b, const_sbitmap c)
+bitmap_ior_and_compl (sbitmap dst, const_sbitmap a, const_sbitmap b, const_sbitmap c)
{
unsigned int i, n = dst->size;
sbitmap_ptr dstp = dst->elms;
@@ -406,26 +406,10 @@ sbitmap_union_of_diff_cg (sbitmap dst, const_sbitmap a, const_sbitmap b, const_s
return changed != 0;
}
-void
-sbitmap_union_of_diff (sbitmap dst, const_sbitmap a, const_sbitmap b, const_sbitmap c)
-{
- unsigned int i, n = dst->size;
- sbitmap_ptr dstp = dst->elms;
- const_sbitmap_ptr ap = a->elms;
- const_sbitmap_ptr bp = b->elms;
- const_sbitmap_ptr cp = c->elms;
-
- gcc_assert (!dst->popcount && !a->popcount
- && !b->popcount && !c->popcount);
-
- for (i = 0; i < n; i++)
- *dstp++ = *ap++ | (*bp++ & ~*cp++);
-}
-
/* Set bitmap DST to the bitwise negation of the bitmap SRC. */
void
-sbitmap_not (sbitmap dst, const_sbitmap src)
+bitmap_not (sbitmap dst, const_sbitmap src)
{
unsigned int i, n = dst->size;
sbitmap_ptr dstp = dst->elms;
@@ -437,7 +421,7 @@ sbitmap_not (sbitmap dst, const_sbitmap src)
for (i = 0; i < n; i++)
*dstp++ = ~*srcp++;
- /* Zero all bits past n_bits, by ANDing dst with sbitmap_ones. */
+ /* Zero all bits past n_bits, by ANDing dst with bitmap_ones. */
last_bit = src->n_bits % SBITMAP_ELT_BITS;
if (last_bit)
dst->elms[n-1] = dst->elms[n-1]
@@ -448,7 +432,7 @@ sbitmap_not (sbitmap dst, const_sbitmap src)
in A and the bits in B. i.e. dst = a & (~b). */
void
-sbitmap_difference (sbitmap dst, const_sbitmap a, const_sbitmap b)
+bitmap_and_compl (sbitmap dst, const_sbitmap a, const_sbitmap b)
{
unsigned int i, dst_size = dst->size;
unsigned int min_size = dst->size;
@@ -477,7 +461,7 @@ sbitmap_difference (sbitmap dst, const_sbitmap a, const_sbitmap b)
Return false otherwise. */
bool
-sbitmap_any_common_bits (const_sbitmap a, const_sbitmap b)
+bitmap_intersect_p (const_sbitmap a, const_sbitmap b)
{
const_sbitmap_ptr ap = a->elms;
const_sbitmap_ptr bp = b->elms;
@@ -495,28 +479,7 @@ sbitmap_any_common_bits (const_sbitmap a, const_sbitmap b)
Return nonzero if any change is made. */
bool
-sbitmap_a_and_b_cg (sbitmap dst, const_sbitmap a, const_sbitmap b)
-{
- unsigned int i, n = dst->size;
- sbitmap_ptr dstp = dst->elms;
- const_sbitmap_ptr ap = a->elms;
- const_sbitmap_ptr bp = b->elms;
- SBITMAP_ELT_TYPE changed = 0;
-
- gcc_assert (!dst->popcount);
-
- for (i = 0; i < n; i++)
- {
- const SBITMAP_ELT_TYPE tmp = *ap++ & *bp++;
- changed |= *dstp ^ tmp;
- *dstp++ = tmp;
- }
-
- return changed != 0;
-}
-
-void
-sbitmap_a_and_b (sbitmap dst, const_sbitmap a, const_sbitmap b)
+bitmap_and (sbitmap dst, const_sbitmap a, const_sbitmap b)
{
unsigned int i, n = dst->size;
sbitmap_ptr dstp = dst->elms;
@@ -524,6 +487,7 @@ sbitmap_a_and_b (sbitmap dst, const_sbitmap a, const_sbitmap b)
const_sbitmap_ptr bp = b->elms;
bool has_popcount = dst->popcount != NULL;
unsigned char *popcountp = dst->popcount;
+ bool anychange = false;
for (i = 0; i < n; i++)
{
@@ -532,7 +496,10 @@ sbitmap_a_and_b (sbitmap dst, const_sbitmap a, const_sbitmap b)
{
bool wordchanged = (*dstp ^ tmp) != 0;
if (wordchanged)
- *popcountp = do_popcount (tmp);
+ {
+ *popcountp = do_popcount (tmp);
+ anychange = true;
+ }
popcountp++;
}
*dstp++ = tmp;
@@ -541,34 +508,14 @@ sbitmap_a_and_b (sbitmap dst, const_sbitmap a, const_sbitmap b)
if (has_popcount)
sbitmap_verify_popcount (dst);
#endif
+ return anychange;
}
/* Set DST to be (A xor B)).
Return nonzero if any change is made. */
bool
-sbitmap_a_xor_b_cg (sbitmap dst, const_sbitmap a, const_sbitmap b)
-{
- unsigned int i, n = dst->size;
- sbitmap_ptr dstp = dst->elms;
- const_sbitmap_ptr ap = a->elms;
- const_sbitmap_ptr bp = b->elms;
- SBITMAP_ELT_TYPE changed = 0;
-
- gcc_assert (!dst->popcount);
-
- for (i = 0; i < n; i++)
- {
- const SBITMAP_ELT_TYPE tmp = *ap++ ^ *bp++;
- changed |= *dstp ^ tmp;
- *dstp++ = tmp;
- }
-
- return changed != 0;
-}
-
-void
-sbitmap_a_xor_b (sbitmap dst, const_sbitmap a, const_sbitmap b)
+bitmap_xor (sbitmap dst, const_sbitmap a, const_sbitmap b)
{
unsigned int i, n = dst->size;
sbitmap_ptr dstp = dst->elms;
@@ -576,6 +523,7 @@ sbitmap_a_xor_b (sbitmap dst, const_sbitmap a, const_sbitmap b)
const_sbitmap_ptr bp = b->elms;
bool has_popcount = dst->popcount != NULL;
unsigned char *popcountp = dst->popcount;
+ bool anychange = false;
for (i = 0; i < n; i++)
{
@@ -584,7 +532,10 @@ sbitmap_a_xor_b (sbitmap dst, const_sbitmap a, const_sbitmap b)
{
bool wordchanged = (*dstp ^ tmp) != 0;
if (wordchanged)
- *popcountp = do_popcount (tmp);
+ {
+ *popcountp = do_popcount (tmp);
+ anychange = true;
+ }
popcountp++;
}
*dstp++ = tmp;
@@ -593,34 +544,14 @@ sbitmap_a_xor_b (sbitmap dst, const_sbitmap a, const_sbitmap b)
if (has_popcount)
sbitmap_verify_popcount (dst);
#endif
+ return anychange;
}
/* Set DST to be (A or B)).
Return nonzero if any change is made. */
bool
-sbitmap_a_or_b_cg (sbitmap dst, const_sbitmap a, const_sbitmap b)
-{
- unsigned int i, n = dst->size;
- sbitmap_ptr dstp = dst->elms;
- const_sbitmap_ptr ap = a->elms;
- const_sbitmap_ptr bp = b->elms;
- SBITMAP_ELT_TYPE changed = 0;
-
- gcc_assert (!dst->popcount);
-
- for (i = 0; i < n; i++)
- {
- const SBITMAP_ELT_TYPE tmp = *ap++ | *bp++;
- changed |= *dstp ^ tmp;
- *dstp++ = tmp;
- }
-
- return changed != 0;
-}
-
-void
-sbitmap_a_or_b (sbitmap dst, const_sbitmap a, const_sbitmap b)
+bitmap_ior (sbitmap dst, const_sbitmap a, const_sbitmap b)
{
unsigned int i, n = dst->size;
sbitmap_ptr dstp = dst->elms;
@@ -628,6 +559,7 @@ sbitmap_a_or_b (sbitmap dst, const_sbitmap a, const_sbitmap b)
const_sbitmap_ptr bp = b->elms;
bool has_popcount = dst->popcount != NULL;
unsigned char *popcountp = dst->popcount;
+ bool anychange = false;
for (i = 0; i < n; i++)
{
@@ -636,7 +568,10 @@ sbitmap_a_or_b (sbitmap dst, const_sbitmap a, const_sbitmap b)
{
bool wordchanged = (*dstp ^ tmp) != 0;
if (wordchanged)
- *popcountp = do_popcount (tmp);
+ {
+ *popcountp = do_popcount (tmp);
+ anychange = true;
+ }
popcountp++;
}
*dstp++ = tmp;
@@ -645,12 +580,13 @@ sbitmap_a_or_b (sbitmap dst, const_sbitmap a, const_sbitmap b)
if (has_popcount)
sbitmap_verify_popcount (dst);
#endif
+ return anychange;
}
/* Return nonzero if A is a subset of B. */
bool
-sbitmap_a_subset_b_p (const_sbitmap a, const_sbitmap b)
+bitmap_subset_p (const_sbitmap a, const_sbitmap b)
{
unsigned int i, n = a->size;
const_sbitmap_ptr ap, bp;
@@ -666,7 +602,7 @@ sbitmap_a_subset_b_p (const_sbitmap a, const_sbitmap b)
Return nonzero if any change is made. */
bool
-sbitmap_a_or_b_and_c_cg (sbitmap dst, const_sbitmap a, const_sbitmap b, const_sbitmap c)
+bitmap_or_and (sbitmap dst, const_sbitmap a, const_sbitmap b, const_sbitmap c)
{
unsigned int i, n = dst->size;
sbitmap_ptr dstp = dst->elms;
@@ -687,26 +623,11 @@ sbitmap_a_or_b_and_c_cg (sbitmap dst, const_sbitmap a, const_sbitmap b, const_sb
return changed != 0;
}
-void
-sbitmap_a_or_b_and_c (sbitmap dst, const_sbitmap a, const_sbitmap b, const_sbitmap c)
-{
- unsigned int i, n = dst->size;
- sbitmap_ptr dstp = dst->elms;
- const_sbitmap_ptr ap = a->elms;
- const_sbitmap_ptr bp = b->elms;
- const_sbitmap_ptr cp = c->elms;
-
- gcc_assert (!dst->popcount);
-
- for (i = 0; i < n; i++)
- *dstp++ = *ap++ | (*bp++ & *cp++);
-}
-
/* Set DST to be (A and (B or C)).
Return nonzero if any change is made. */
bool
-sbitmap_a_and_b_or_c_cg (sbitmap dst, const_sbitmap a, const_sbitmap b, const_sbitmap c)
+bitmap_and_or (sbitmap dst, const_sbitmap a, const_sbitmap b, const_sbitmap c)
{
unsigned int i, n = dst->size;
sbitmap_ptr dstp = dst->elms;
@@ -727,23 +648,10 @@ sbitmap_a_and_b_or_c_cg (sbitmap dst, const_sbitmap a, const_sbitmap b, const_sb
return changed != 0;
}
-void
-sbitmap_a_and_b_or_c (sbitmap dst, const_sbitmap a, const_sbitmap b, const_sbitmap c)
-{
- unsigned int i, n = dst->size;
- sbitmap_ptr dstp = dst->elms;
- const_sbitmap_ptr ap = a->elms;
- const_sbitmap_ptr bp = b->elms;
- const_sbitmap_ptr cp = c->elms;
-
- for (i = 0; i < n; i++)
- *dstp++ = *ap++ & (*bp++ | *cp++);
-}
-
/* Return number of first bit set in the bitmap, -1 if none. */
int
-sbitmap_first_set_bit (const_sbitmap bmap)
+bitmap_first_set_bit (const_sbitmap bmap)
{
unsigned int n = 0;
sbitmap_iterator sbi;
@@ -756,7 +664,7 @@ sbitmap_first_set_bit (const_sbitmap bmap)
/* Return number of last bit set in the bitmap, -1 if none. */
int
-sbitmap_last_set_bit (const_sbitmap bmap)
+bitmap_last_set_bit (const_sbitmap bmap)
{
int i;
const SBITMAP_ELT_TYPE *const ptr = bmap->elms;
@@ -786,7 +694,7 @@ sbitmap_last_set_bit (const_sbitmap bmap)
}
void
-dump_sbitmap (FILE *file, const_sbitmap bmap)
+dump_bitmap (FILE *file, const_sbitmap bmap)
{
unsigned int i, n, j;
unsigned int set_size = bmap->size;
@@ -807,7 +715,7 @@ dump_sbitmap (FILE *file, const_sbitmap bmap)
}
void
-dump_sbitmap_file (FILE *file, const_sbitmap bmap)
+dump_bitmap_file (FILE *file, const_sbitmap bmap)
{
unsigned int i, pos;
@@ -830,13 +738,13 @@ dump_sbitmap_file (FILE *file, const_sbitmap bmap)
}
DEBUG_FUNCTION void
-debug_sbitmap (const_sbitmap bmap)
+debug_bitmap (const_sbitmap bmap)
{
- dump_sbitmap_file (stderr, bmap);
+ dump_bitmap_file (stderr, bmap);
}
void
-dump_sbitmap_vector (FILE *file, const char *title, const char *subtitle,
+dump_bitmap_vector (FILE *file, const char *title, const char *subtitle,
sbitmap *bmaps, int n_maps)
{
int i;
@@ -845,7 +753,7 @@ dump_sbitmap_vector (FILE *file, const char *title, const char *subtitle,
for (i = 0; i < n_maps; i++)
{
fprintf (file, "%s %d\n", subtitle, i);
- dump_sbitmap (file, bmaps[i]);
+ dump_bitmap (file, bmaps[i]);
}
fprintf (file, "\n");