This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Use const_bitmap in GCC sources


This patch makes use of "const_bitmap" in GCC sources.  It relies on a
patch previously posted here:
http://gcc.gnu.org/ml/gcc-patches/2006-08/msg00383.html

I came across one nit.  There is a function prototyped as extern int
bitmap_bit_p(bitmap, int) which will "return true if a register is set
in a register set."

I think one might rightfully expect that this query-type function
doesn't modify its arguments and it could have it's bitmap constified.
But it turns out that it calls bitmap_find_bit() which is documented
to modify the supplied bitmap.  So I left bitmap_bit_p() as non-const,
but IMHO, this is a misleading API uncovered through my audit.  At
least now that everything else in this module is constified, it
becomes more obvious to the caller that the supplied parameter may be
changed.

Bootstrapped on sparc-sun-solaris2.10, no regressions.

Preapproved by Mark and awaiting stage2.

		--Kaveh




2006-07-28  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* bitmap.c (bitmap_copy, popcount_table, bitmap_count_bits,
	bitmap_first_set_bit, bitmap_and, bitmap_and_into,
	bitmap_and_compl, bitmap_and_compl_into, bitmap_compl_and_into,
	bitmap_ior, bitmap_ior_into, bitmap_xor, bitmap_xor_into,
	bitmap_equal_p, bitmap_intersect_p, bitmap_intersect_compl_p,
	bitmap_ior_and_compl, bitmap_ior_and_compl_into,
	debug_bitmap_file, debug_bitmap, bitmap_print): Constify.

	* bitmap.h (bitmap_copy, bitmap_equal_p, bitmap_intersect_p,
	bitmap_intersect_compl_p, bitmap_count_bits, bitmap_and,
	bitmap_and_into, bitmap_and_compl, bitmap_and_compl_into,
	bitmap_compl_and_into, bitmap_ior, bitmap_ior_into, bitmap_xor,
	bitmap_xor_into, bitmap_ior_and_compl, bitmap_ior_and_compl_into,
	debug_bitmap, debug_bitmap_file, bitmap_print,
	bitmap_first_set_bit, bmp_iter_set_init, bmp_iter_and_init,
	bmp_iter_and_compl_init): Likewise.
	
diff -rup orig/egcc-SVN20060805/gcc/bitmap.c egcc-SVN20060805/gcc/bitmap.c
--- orig/egcc-SVN20060805/gcc/bitmap.c	2006-05-18 20:00:47.000000000 -0400
+++ egcc-SVN20060805/gcc/bitmap.c	2006-08-06 11:06:47.910493331 -0400
@@ -386,7 +386,7 @@ bitmap_elt_insert_after (bitmap head, bi
 /* Copy a bitmap to another bitmap.  */
 
 void
-bitmap_copy (bitmap to, bitmap from)
+bitmap_copy (bitmap to, const_bitmap from)
 {
   bitmap_element *from_ptr, *to_ptr = 0;
 
@@ -529,7 +529,7 @@ bitmap_bit_p (bitmap head, int bit)
 
 #if GCC_VERSION < 3400
 /* Table of number of set bits in a character, indexed by value of char.  */
-static unsigned char popcount_table[] =
+static const unsigned char popcount_table[] =
 {
     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,
     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,
@@ -556,7 +556,7 @@ bitmap_popcount (BITMAP_WORD a)
 /* Count the number of bits set in the bitmap, and return it.  */
 
 unsigned long
-bitmap_count_bits (bitmap a)
+bitmap_count_bits (const_bitmap a)
 {
   unsigned long count = 0;
   bitmap_element *elt;
@@ -584,7 +584,7 @@ bitmap_count_bits (bitmap a)
    bitmap must be non-empty.  */
 
 unsigned
-bitmap_first_set_bit (bitmap a)
+bitmap_first_set_bit (const_bitmap a)
 {
   bitmap_element *elt = a->first;
   unsigned bit_no;
@@ -635,7 +635,7 @@ bitmap_first_set_bit (bitmap a)
 /* DST = A & B.  */
 
 void
-bitmap_and (bitmap dst, bitmap a, bitmap b)
+bitmap_and (bitmap dst, const_bitmap a, const_bitmap b)
 {
   bitmap_element *dst_elt = dst->first;
   bitmap_element *a_elt = a->first;
@@ -691,7 +691,7 @@ bitmap_and (bitmap dst, bitmap a, bitmap
 /* A &= B.  */
 
 void
-bitmap_and_into (bitmap a, bitmap b)
+bitmap_and_into (bitmap a, const_bitmap b)
 {
   bitmap_element *a_elt = a->first;
   bitmap_element *b_elt = b->first;
@@ -738,7 +738,7 @@ bitmap_and_into (bitmap a, bitmap b)
 /* DST = A & ~B  */
 
 void
-bitmap_and_compl (bitmap dst, bitmap a, bitmap b)
+bitmap_and_compl (bitmap dst, const_bitmap a, const_bitmap b)
 {
   bitmap_element *dst_elt = dst->first;
   bitmap_element *a_elt = a->first;
@@ -804,7 +804,7 @@ bitmap_and_compl (bitmap dst, bitmap a, 
 /* A &= ~B. Returns true if A changes */
 
 bool
-bitmap_and_compl_into (bitmap a, bitmap b)
+bitmap_and_compl_into (bitmap a, const_bitmap b)
 {
   bitmap_element *a_elt = a->first;
   bitmap_element *b_elt = b->first;
@@ -978,7 +978,7 @@ bitmap_clear_range (bitmap head, unsigne
 /* A = ~A & B. */
 
 void
-bitmap_compl_and_into (bitmap a, bitmap b)
+bitmap_compl_and_into (bitmap a, const_bitmap b)
 {
   bitmap_element *a_elt = a->first;
   bitmap_element *b_elt = b->first;
@@ -1047,7 +1047,7 @@ bitmap_compl_and_into (bitmap a, bitmap 
 /* DST = A | B.  Return true if DST changes.  */
 
 bool
-bitmap_ior (bitmap dst, bitmap a, bitmap b)
+bitmap_ior (bitmap dst, const_bitmap a, const_bitmap b)
 {
   bitmap_element *dst_elt = dst->first;
   bitmap_element *a_elt = a->first;
@@ -1152,7 +1152,7 @@ bitmap_ior (bitmap dst, bitmap a, bitmap
 /* A |= B.  Return true if A changes.  */
 
 bool
-bitmap_ior_into (bitmap a, bitmap b)
+bitmap_ior_into (bitmap a, const_bitmap b)
 {
   bitmap_element *a_elt = a->first;
   bitmap_element *b_elt = b->first;
@@ -1215,7 +1215,7 @@ bitmap_ior_into (bitmap a, bitmap b)
 /* DST = A ^ B  */
 
 void
-bitmap_xor (bitmap dst, bitmap a, bitmap b)
+bitmap_xor (bitmap dst, const_bitmap a, const_bitmap b)
 {
   bitmap_element *dst_elt = dst->first;
   bitmap_element *a_elt = a->first;
@@ -1290,7 +1290,7 @@ bitmap_xor (bitmap dst, bitmap a, bitmap
 /* A ^= B */
 
 void
-bitmap_xor_into (bitmap a, bitmap b)
+bitmap_xor_into (bitmap a, const_bitmap b)
 {
   bitmap_element *a_elt = a->first;
   bitmap_element *b_elt = b->first;
@@ -1349,7 +1349,7 @@ bitmap_xor_into (bitmap a, bitmap b)
    occurs in practice.  */
 
 bool
-bitmap_equal_p (bitmap a, bitmap b)
+bitmap_equal_p (const_bitmap a, const_bitmap b)
 {
   bitmap_element *a_elt;
   bitmap_element *b_elt;
@@ -1371,7 +1371,7 @@ bitmap_equal_p (bitmap a, bitmap b)
 /* Return true if A AND B is not empty.  */
 
 bool
-bitmap_intersect_p (bitmap a, bitmap b)
+bitmap_intersect_p (const_bitmap a, const_bitmap b)
 {
   bitmap_element *a_elt;
   bitmap_element *b_elt;
@@ -1399,7 +1399,7 @@ bitmap_intersect_p (bitmap a, bitmap b)
 /* Return true if A AND NOT B is not empty.  */
 
 bool
-bitmap_intersect_compl_p (bitmap a, bitmap b)
+bitmap_intersect_compl_p (const_bitmap a, const_bitmap b)
 {
   bitmap_element *a_elt;
   bitmap_element *b_elt;
@@ -1427,7 +1427,7 @@ bitmap_intersect_compl_p (bitmap a, bitm
 /* DST = A | (FROM1 & ~FROM2).  Return true if DST changes.  */
 
 bool
-bitmap_ior_and_compl (bitmap dst, bitmap a, bitmap from1, bitmap from2)
+bitmap_ior_and_compl (bitmap dst, const_bitmap a, const_bitmap from1, const_bitmap from2)
 {
   bitmap_head tmp;
   bool changed;
@@ -1443,7 +1443,7 @@ bitmap_ior_and_compl (bitmap dst, bitmap
 /* A |= (FROM1 & ~FROM2).  Return true if A changes.  */
 
 bool
-bitmap_ior_and_compl_into (bitmap a, bitmap from1, bitmap from2)
+bitmap_ior_and_compl_into (bitmap a, const_bitmap from1, const_bitmap from2)
 {
   bitmap_head tmp;
   bool changed;
@@ -1459,7 +1459,7 @@ bitmap_ior_and_compl_into (bitmap a, bit
 /* Debugging function to print out the contents of a bitmap.  */
 
 void
-debug_bitmap_file (FILE *file, bitmap head)
+debug_bitmap_file (FILE *file, const_bitmap head)
 {
   bitmap_element *ptr;
 
@@ -1496,7 +1496,7 @@ debug_bitmap_file (FILE *file, bitmap he
    of a bitmap.  */
 
 void
-debug_bitmap (bitmap head)
+debug_bitmap (const_bitmap head)
 {
   debug_bitmap_file (stdout, head);
 }
@@ -1505,7 +1505,7 @@ debug_bitmap (bitmap head)
    it does not print anything but the bits.  */
 
 void
-bitmap_print (FILE *file, bitmap head, const char *prefix, const char *suffix)
+bitmap_print (FILE *file, const_bitmap head, const char *prefix, const char *suffix)
 {
   const char *comma = "";
   unsigned i;
diff -rup orig/egcc-SVN20060805/gcc/bitmap.h egcc-SVN20060805/gcc/bitmap.h
--- orig/egcc-SVN20060805/gcc/bitmap.h	2006-05-18 20:00:48.000000000 -0400
+++ egcc-SVN20060805/gcc/bitmap.h	2006-08-06 11:06:47.912194077 -0400
@@ -85,44 +85,44 @@ extern bitmap_obstack bitmap_default_obs
 extern void bitmap_clear (bitmap);
 
 /* Copy a bitmap to another bitmap.  */
-extern void bitmap_copy (bitmap, bitmap);
+extern void bitmap_copy (bitmap, const_bitmap);
 
 /* True if two bitmaps are identical.  */
-extern bool bitmap_equal_p (bitmap, bitmap);
+extern bool bitmap_equal_p (const_bitmap, const_bitmap);
 
 /* True if the bitmaps intersect (their AND is non-empty).  */
-extern bool bitmap_intersect_p (bitmap, bitmap);
+extern bool bitmap_intersect_p (const_bitmap, const_bitmap);
 
 /* True if the complement of the second intersects the first (their
    AND_COMPL is non-empty).  */
-extern bool bitmap_intersect_compl_p (bitmap, bitmap);
+extern bool bitmap_intersect_compl_p (const_bitmap, const_bitmap);
 
 /* True if MAP is an empty bitmap.  */
 #define bitmap_empty_p(MAP) (!(MAP)->first)
 
 /* Count the number of bits set in the bitmap.  */
-extern unsigned long bitmap_count_bits (bitmap);
+extern unsigned long bitmap_count_bits (const_bitmap);
 
 /* Boolean operations on bitmaps.  The _into variants are two operand
    versions that modify the first source operand.  The other variants
    are three operand versions that to not destroy the source bitmaps.
    The operations supported are &, & ~, |, ^.  */
-extern void bitmap_and (bitmap, bitmap, bitmap);
-extern void bitmap_and_into (bitmap, bitmap);
-extern void bitmap_and_compl (bitmap, bitmap, bitmap);
-extern bool bitmap_and_compl_into (bitmap, bitmap);
+extern void bitmap_and (bitmap, const_bitmap, const_bitmap);
+extern void bitmap_and_into (bitmap, const_bitmap);
+extern void bitmap_and_compl (bitmap, const_bitmap, const_bitmap);
+extern bool bitmap_and_compl_into (bitmap, const_bitmap);
 #define bitmap_compl_and(DST, A, B) bitmap_and_compl (DST, B, A)
-extern void bitmap_compl_and_into (bitmap, bitmap);
+extern void bitmap_compl_and_into (bitmap, const_bitmap);
 extern void bitmap_clear_range (bitmap, unsigned int, unsigned int);
-extern bool bitmap_ior (bitmap, bitmap, bitmap);
-extern bool bitmap_ior_into (bitmap, bitmap);
-extern void bitmap_xor (bitmap, bitmap, bitmap);
-extern void bitmap_xor_into (bitmap, bitmap);
+extern bool bitmap_ior (bitmap, const_bitmap, const_bitmap);
+extern bool bitmap_ior_into (bitmap, const_bitmap);
+extern void bitmap_xor (bitmap, const_bitmap, const_bitmap);
+extern void bitmap_xor_into (bitmap, const_bitmap);
 
 /* DST = A | (B & ~C).  Return true if DST changes.  */
-extern bool bitmap_ior_and_compl (bitmap DST, bitmap A, bitmap B, bitmap C);
+extern bool bitmap_ior_and_compl (bitmap DST, const_bitmap A, const_bitmap B, const_bitmap C);
 /* A |= (B & ~C).  Return true if A changes.  */
-extern bool bitmap_ior_and_compl_into (bitmap DST, bitmap B, bitmap C);
+extern bool bitmap_ior_and_compl_into (bitmap DST, const_bitmap B, const_bitmap C);
 
 /* Clear a single register in a register set.  */
 extern void bitmap_clear_bit (bitmap, int);
@@ -134,11 +134,11 @@ extern void bitmap_set_bit (bitmap, int)
 extern int bitmap_bit_p (bitmap, int);
 
 /* Debug functions to print a bitmap linked list.  */
-extern void debug_bitmap (bitmap);
-extern void debug_bitmap_file (FILE *, bitmap);
+extern void debug_bitmap (const_bitmap);
+extern void debug_bitmap_file (FILE *, const_bitmap);
 
 /* Print a bitmap.  */
-extern void bitmap_print (FILE *, bitmap, const char *, const char *);
+extern void bitmap_print (FILE *, const_bitmap, const char *, const char *);
 
 /* Initialize and release a bitmap obstack.  */
 extern void bitmap_obstack_initialize (bitmap_obstack *);
@@ -162,7 +162,7 @@ extern void bitmap_obstack_free (bitmap)
 /* A few compatibility/functions macros for compatibility with sbitmaps */
 #define dump_bitmap(file, bitmap) bitmap_print (file, bitmap, "", "\n")
 #define bitmap_zero(a) bitmap_clear (a)
-extern unsigned bitmap_first_set_bit (bitmap);
+extern unsigned bitmap_first_set_bit (const_bitmap);
 
 /* Allocate a bitmap from a bit obstack.  */
 #define BITMAP_ALLOC(OBSTACK) bitmap_obstack_alloc (OBSTACK)
@@ -197,7 +197,7 @@ typedef struct
    iterate from.  */
 
 static inline void
-bmp_iter_set_init (bitmap_iterator *bi, bitmap map,
+bmp_iter_set_init (bitmap_iterator *bi, const_bitmap map,
 		   unsigned start_bit, unsigned *bit_no)
 {
   bi->elt1 = map->first;
@@ -239,7 +239,7 @@ bmp_iter_set_init (bitmap_iterator *bi, 
    bitmaps.  START_BIT is the bit to commence from.  */
 
 static inline void
-bmp_iter_and_init (bitmap_iterator *bi, bitmap map1, bitmap map2,
+bmp_iter_and_init (bitmap_iterator *bi, const_bitmap map1, const_bitmap map2,
 		   unsigned start_bit, unsigned *bit_no)
 {
   bi->elt1 = map1->first;
@@ -307,7 +307,7 @@ bmp_iter_and_init (bitmap_iterator *bi, 
    */
 
 static inline void
-bmp_iter_and_compl_init (bitmap_iterator *bi, bitmap map1, bitmap map2,
+bmp_iter_and_compl_init (bitmap_iterator *bi, const_bitmap map1, const_bitmap map2,
 			 unsigned start_bit, unsigned *bit_no)
 {
   bi->elt1 = map1->first;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]