/* Simple bitmaps.
- Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
This file is part of GCC.
#include "config.h"
#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
#include "rtl.h"
#include "flags.h"
#include "hard-reg-set.h"
return bmap;
}
+/* Resize a simple bitmap BMAP to N_ELMS bits. If increasing the
+ size of BMAP, clear the new bits to zero if the DEF argument
+ is zero, and set them to one otherwise. */
+
+sbitmap
+sbitmap_resize (bmap, n_elms, def)
+ sbitmap bmap;
+ unsigned int n_elms;
+ int def;
+{
+ unsigned int bytes, size, amt;
+ unsigned int last_bit;
+
+ size = SBITMAP_SET_SIZE (n_elms);
+ bytes = size * sizeof (SBITMAP_ELT_TYPE);
+ if (bytes > bmap->bytes)
+ {
+ amt = (sizeof (struct simple_bitmap_def)
+ + bytes - sizeof (SBITMAP_ELT_TYPE));
+ bmap = (sbitmap) xrealloc ((PTR) bmap, amt);
+ }
+
+ if (n_elms > bmap->n_bits)
+ {
+ if (def)
+ {
+ memset ((PTR) (bmap->elms + bmap->size), -1, bytes - bmap->bytes);
+
+ /* Set the new bits if the original last element. */
+ last_bit = bmap->n_bits % SBITMAP_ELT_BITS;
+ if (last_bit)
+ bmap->elms[bmap->size - 1]
+ |= ~((SBITMAP_ELT_TYPE)-1 >> (SBITMAP_ELT_BITS - last_bit));
+
+ /* Clear the unused bit in the new last element. */
+ last_bit = n_elms % SBITMAP_ELT_BITS;
+ if (last_bit)
+ bmap->elms[size - 1]
+ &= (SBITMAP_ELT_TYPE)-1 >> (SBITMAP_ELT_BITS - last_bit);
+ }
+ else
+ memset ((PTR) (bmap->elms + bmap->size), 0, bytes - bmap->bytes);
+ }
+ else if (n_elms < bmap->n_bits)
+ {
+ /* Clear the surplus bits in the last word. */
+ last_bit = n_elms % SBITMAP_ELT_BITS;
+ if (last_bit)
+ bmap->elms[size - 1]
+ &= (SBITMAP_ELT_TYPE)-1 >> (SBITMAP_ELT_BITS - last_bit);
+ }
+
+ bmap->n_bits = n_elms;
+ bmap->size = size;
+ bmap->bytes = bytes;
+ return bmap;
+}
+
/* Allocate a vector of N_VECS bitmaps of N_ELMS bits. */
sbitmap *
sbitmap_difference (dst, a, b)
sbitmap dst, a, b;
{
- unsigned int i, n = dst->size;
+ unsigned int i, dst_size = dst->size;
+ unsigned int min_size = dst->size;
sbitmap_ptr dstp = dst->elms;
sbitmap_ptr ap = a->elms;
sbitmap_ptr bp = b->elms;
-
- for (i = 0; i < n; i++)
- *dstp++ = *ap++ & ~*bp++;
+
+ /* A should be at least as large as DEST, to have a defined source. */
+ if (a->size < dst_size)
+ abort ();
+ /* If minuend is smaller, we simply pretend it to be zero bits, i.e.
+ only copy the subtrahend into dest. */
+ if (b->size < min_size)
+ min_size = b->size;
+ for (i = 0; i < min_size; i++)
+ *dstp++ = *ap++ & (~*bp++);
+ /* Now fill the rest of dest from A, if B was too short.
+ This makes sense only when destination and A differ. */
+ if (dst != a && i != dst_size)
+ for (; i < dst_size; i++)
+ *dstp++ = *ap++;
}
/* Set DST to be (A and B).
- Return non-zero if any change is made. */
+ Return nonzero if any change is made. */
bool
sbitmap_a_and_b_cg (dst, a, b)
}
/* Set DST to be (A xor B)).
- Return non-zero if any change is made. */
+ Return nonzero if any change is made. */
bool
sbitmap_a_xor_b_cg (dst, a, b)
}
/* Set DST to be (A or B)).
- Return non-zero if any change is made. */
+ Return nonzero if any change is made. */
bool
sbitmap_a_or_b_cg (dst, a, b)
*dstp++ = *ap++ | *bp++;
}
-/* Return non-zero if A is a subset of B. */
+/* Return nonzero if A is a subset of B. */
bool
sbitmap_a_subset_b_p (a, b)
}
/* Set DST to be (A or (B and C)).
- Return non-zero if any change is made. */
+ Return nonzero if any change is made. */
bool
sbitmap_a_or_b_and_c_cg (dst, a, b, c)
}
/* Set DST to be (A and (B or C)).
- Return non-zero if any change is made. */
+ Return nonzero if any change is made. */
bool
sbitmap_a_and_b_or_c_cg (dst, a, b, c)
}
void
-debug_sbitmap (bmap)
+dump_sbitmap_file (file, bmap)
+ FILE *file;
sbitmap bmap;
{
unsigned int i, pos;
- fprintf (stderr, "n_bits = %d, set = {", bmap->n_bits);
+ fprintf (file, "n_bits = %d, set = {", bmap->n_bits);
for (pos = 30, i = 0; i < bmap->n_bits; i++)
if (TEST_BIT (bmap, i))
{
if (pos > 70)
{
- fprintf (stderr, "\n");
+ fprintf (file, "\n ");
pos = 0;
}
- fprintf (stderr, "%d ", i);
- pos += 1 + (i >= 10) + (i >= 100);
+ fprintf (file, "%d ", i);
+ pos += 2 + (i >= 10) + (i >= 100) + (i >= 1000);
}
- fprintf (stderr, "}\n");
+ fprintf (file, "}\n");
+}
+
+void
+debug_sbitmap (bmap)
+ sbitmap bmap;
+{
+ dump_sbitmap_file (stderr, bmap);
}
void