X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=gcc%2Fbitmap.c;h=ebbb6ee805ff4d8380b3e33fd5317e291aac6476;hb=047e31217cbb6af2c833f5dc47d96c72940eae02;hp=e2b58c0e0c8d97b46b5ef1c02402acff887ba9f6;hpb=0df5e59734aa131dfabcc4a11a51ef278b6d2b55;p=pf3gnuchains%2Fgcc-fork.git diff --git a/gcc/bitmap.c b/gcc/bitmap.c index e2b58c0e0c8..ebbb6ee805f 100644 --- a/gcc/bitmap.c +++ b/gcc/bitmap.c @@ -1,5 +1,6 @@ /* Functions to support general ended bitmaps. - Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. + Copyright (C) 1997, 1998, 1999, 2000, 2001, 2003 + Free Software Foundation, Inc. This file is part of GCC. @@ -20,6 +21,8 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "config.h" #include "system.h" +#include "coretypes.h" +#include "tm.h" #include "rtl.h" #include "flags.h" #include "obstack.h" @@ -41,20 +44,18 @@ static int bitmap_obstack_init = FALSE; /* Global data */ bitmap_element bitmap_zero_bits; /* An element of all zero bits. */ static bitmap_element *bitmap_free; /* Freelist of bitmap elements. */ -static GTY((deletable (""))) bitmap_element *bitmap_ggc_free; - -static void bitmap_elem_to_freelist PARAMS ((bitmap, bitmap_element *)); -static void bitmap_element_free PARAMS ((bitmap, bitmap_element *)); -static bitmap_element *bitmap_element_allocate PARAMS ((bitmap)); -static int bitmap_element_zerop PARAMS ((bitmap_element *)); -static void bitmap_element_link PARAMS ((bitmap, bitmap_element *)); -static bitmap_element *bitmap_find_bit PARAMS ((bitmap, unsigned int)); +static GTY((deletable)) bitmap_element *bitmap_ggc_free; + +static void bitmap_elem_to_freelist (bitmap, bitmap_element *); +static void bitmap_element_free (bitmap, bitmap_element *); +static bitmap_element *bitmap_element_allocate (bitmap); +static int bitmap_element_zerop (bitmap_element *); +static void bitmap_element_link (bitmap, bitmap_element *); +static bitmap_element *bitmap_find_bit (bitmap, unsigned int); /* Add ELEM to the appropriate freelist. */ static INLINE void -bitmap_elem_to_freelist (head, elt) - bitmap head; - bitmap_element *elt; +bitmap_elem_to_freelist (bitmap head, bitmap_element *elt) { if (head->using_obstack) { @@ -72,9 +73,7 @@ bitmap_elem_to_freelist (head, elt) bitmap_obstack, "free" actually means "put onto the freelist". */ static INLINE void -bitmap_element_free (head, elt) - bitmap head; - bitmap_element *elt; +bitmap_element_free (bitmap head, bitmap_element *elt) { bitmap_element *next = elt->next; bitmap_element *prev = elt->prev; @@ -102,8 +101,7 @@ bitmap_element_free (head, elt) /* Allocate a bitmap element. The bits are cleared, but nothing else is. */ static INLINE bitmap_element * -bitmap_element_allocate (head) - bitmap head; +bitmap_element_allocate (bitmap head) { bitmap_element *element; @@ -122,31 +120,18 @@ bitmap_element_allocate (head) if (!bitmap_obstack_init) { bitmap_obstack_init = TRUE; - - /* Let particular systems override the size of a chunk. */ -#ifndef OBSTACK_CHUNK_SIZE -#define OBSTACK_CHUNK_SIZE 0 -#endif - /* Let them override the alloc and free routines too. */ -#ifndef OBSTACK_CHUNK_ALLOC -#define OBSTACK_CHUNK_ALLOC xmalloc -#endif -#ifndef OBSTACK_CHUNK_FREE -#define OBSTACK_CHUNK_FREE free -#endif - + #if !defined(__GNUC__) || (__GNUC__ < 2) #define __alignof__(type) 0 #endif - + obstack_specify_allocation (&bitmap_obstack, OBSTACK_CHUNK_SIZE, __alignof__ (bitmap_element), - (void *(*) PARAMS ((long))) OBSTACK_CHUNK_ALLOC, - (void (*) PARAMS ((void *))) OBSTACK_CHUNK_FREE); + obstack_chunk_alloc, + obstack_chunk_free); } - - element = (bitmap_element *) obstack_alloc (&bitmap_obstack, - sizeof (bitmap_element)); + + element = obstack_alloc (&bitmap_obstack, sizeof (bitmap_element)); } } else @@ -168,7 +153,7 @@ bitmap_element_allocate (head) /* Release any memory allocated by bitmaps. */ void -bitmap_release_memory () +bitmap_release_memory (void) { bitmap_free = 0; if (bitmap_obstack_init) @@ -181,8 +166,7 @@ bitmap_release_memory () /* Return nonzero if all bits in an element are zero. */ static INLINE int -bitmap_element_zerop (element) - bitmap_element *element; +bitmap_element_zerop (bitmap_element *element) { #if BITMAP_ELEMENT_WORDS == 2 return (element->bits[0] | element->bits[1]) == 0; @@ -200,9 +184,7 @@ bitmap_element_zerop (element) /* Link the bitmap element into the current bitmap linked list. */ static INLINE void -bitmap_element_link (head, element) - bitmap head; - bitmap_element *element; +bitmap_element_link (bitmap head, bitmap_element *element) { unsigned int indx = element->indx; bitmap_element *ptr; @@ -257,8 +239,7 @@ bitmap_element_link (head, element) /* Clear a bitmap by freeing the linked list. */ INLINE void -bitmap_clear (head) - bitmap head; +bitmap_clear (bitmap head) { bitmap_element *element, *next; @@ -274,9 +255,7 @@ bitmap_clear (head) /* Copy a bitmap to another bitmap. */ void -bitmap_copy (to, from) - bitmap to; - bitmap from; +bitmap_copy (bitmap to, bitmap from) { bitmap_element *from_ptr, *to_ptr = 0; #if BITMAP_ELEMENT_WORDS != 2 @@ -285,7 +264,7 @@ bitmap_copy (to, from) bitmap_clear (to); - /* Copy elements in forward direction one at a time */ + /* Copy elements in forward direction one at a time. */ for (from_ptr = from->first; from_ptr; from_ptr = from_ptr->next) { bitmap_element *to_elt = bitmap_element_allocate (to); @@ -325,12 +304,10 @@ bitmap_copy (to, from) faster. */ static INLINE bitmap_element * -bitmap_find_bit (head, bit) - bitmap head; - unsigned int bit; +bitmap_find_bit (bitmap head, unsigned int bit) { bitmap_element *element; - unsigned HOST_WIDE_INT indx = bit / BITMAP_ELEMENT_ALL_BITS; + unsigned int indx = bit / BITMAP_ELEMENT_ALL_BITS; if (head->current == 0 || head->indx == indx) @@ -361,20 +338,17 @@ bitmap_find_bit (head, bit) /* Clear a single bit in a bitmap. */ void -bitmap_clear_bit (head, bit) - bitmap head; - int bit; +bitmap_clear_bit (bitmap head, int bit) { bitmap_element *ptr = bitmap_find_bit (head, bit); if (ptr != 0) { - unsigned bit_num = bit % (unsigned) HOST_BITS_PER_WIDE_INT; - unsigned word_num = ((bit / (unsigned) HOST_BITS_PER_WIDE_INT) - % BITMAP_ELEMENT_WORDS); - ptr->bits[word_num] &= ~ (((unsigned HOST_WIDE_INT) 1) << bit_num); + unsigned bit_num = bit % BITMAP_WORD_BITS; + unsigned word_num = bit / BITMAP_WORD_BITS % BITMAP_ELEMENT_WORDS; + ptr->bits[word_num] &= ~ (((BITMAP_WORD) 1) << bit_num); - /* If we cleared the entire word, free up the element */ + /* If we cleared the entire word, free up the element. */ if (bitmap_element_zerop (ptr)) bitmap_element_free (head, ptr); } @@ -383,15 +357,12 @@ bitmap_clear_bit (head, bit) /* Set a single bit in a bitmap. */ void -bitmap_set_bit (head, bit) - bitmap head; - int bit; +bitmap_set_bit (bitmap head, int bit) { bitmap_element *ptr = bitmap_find_bit (head, bit); - unsigned word_num - = ((bit / (unsigned) HOST_BITS_PER_WIDE_INT) % BITMAP_ELEMENT_WORDS); - unsigned bit_num = bit % (unsigned) HOST_BITS_PER_WIDE_INT; - unsigned HOST_WIDE_INT bit_val = ((unsigned HOST_WIDE_INT) 1) << bit_num; + unsigned word_num = bit / BITMAP_WORD_BITS % BITMAP_ELEMENT_WORDS; + unsigned bit_num = bit % BITMAP_WORD_BITS; + BITMAP_WORD bit_val = ((BITMAP_WORD) 1) << bit_num; if (ptr == 0) { @@ -407,9 +378,7 @@ bitmap_set_bit (head, bit) /* Return whether a bit is set within a bitmap. */ int -bitmap_bit_p (head, bit) - bitmap head; - int bit; +bitmap_bit_p (bitmap head, int bit) { bitmap_element *ptr; unsigned bit_num; @@ -419,9 +388,8 @@ bitmap_bit_p (head, bit) if (ptr == 0) return 0; - bit_num = bit % (unsigned) HOST_BITS_PER_WIDE_INT; - word_num - = ((bit / (unsigned) HOST_BITS_PER_WIDE_INT) % BITMAP_ELEMENT_WORDS); + bit_num = bit % BITMAP_WORD_BITS; + word_num = bit / BITMAP_WORD_BITS % BITMAP_ELEMENT_WORDS; return (ptr->bits[word_num] >> bit_num) & 1; } @@ -430,11 +398,10 @@ bitmap_bit_p (head, bit) if the bitmap is empty. */ int -bitmap_first_set_bit (a) - bitmap a; +bitmap_first_set_bit (bitmap a) { bitmap_element *ptr = a->first; - unsigned HOST_WIDE_INT word; + BITMAP_WORD word; unsigned word_num, bit_num; if (ptr == NULL) @@ -447,7 +414,9 @@ bitmap_first_set_bit (a) #else for (word_num = 0; word_num < BITMAP_ELEMENT_WORDS; ++word_num) if ((word = ptr->bits[word_num]) != 0) - break; + goto word_found; + abort (); + word_found: #endif /* Binary search for the first set bit. */ @@ -456,10 +425,10 @@ bitmap_first_set_bit (a) bit_num = 0; word = word & -word; -#if HOST_BITS_PER_WIDE_INT > 64 +#if nBITMAP_WORD_BITS > 64 #error "Fill out the table." #endif -#if HOST_BITS_PER_WIDE_INT > 32 +#if nBITMAP_WORD_BITS > 32 if ((word & 0xffffffff) == 0) word >>= 32, bit_num += 32; #endif @@ -475,7 +444,7 @@ bitmap_first_set_bit (a) bit_num += 1; return (ptr->indx * BITMAP_ELEMENT_ALL_BITS - + word_num * HOST_BITS_PER_WIDE_INT + + word_num * BITMAP_WORD_BITS + bit_num); } @@ -483,11 +452,10 @@ bitmap_first_set_bit (a) if the bitmap is empty. */ int -bitmap_last_set_bit (a) - bitmap a; +bitmap_last_set_bit (bitmap a) { bitmap_element *ptr = a->first; - unsigned HOST_WIDE_INT word; + BITMAP_WORD word; unsigned word_num, bit_num; if (ptr == NULL) @@ -503,17 +471,19 @@ bitmap_last_set_bit (a) #else for (word_num = BITMAP_ELEMENT_WORDS; word_num-- > 0; ) if ((word = ptr->bits[word_num]) != 0) - break; + goto word_found; + abort (); + word_found: #endif /* Binary search for the last set bit. */ bit_num = 0; -#if HOST_BITS_PER_WIDE_INT > 64 +#if nBITMAP_WORD_BITS > 64 #error "Fill out the table." #endif -#if HOST_BITS_PER_WIDE_INT > 32 - if (word & ~ (unsigned HOST_WIDE_INT) 0xffffffff) +#if nBITMAP_WORD_BITS > 32 + if (word & ~(BITMAP_WORD)0xffffffff) word >>= 32, bit_num += 32; #endif if (word & 0xffff0000) @@ -528,7 +498,7 @@ bitmap_last_set_bit (a) bit_num += 1; return (ptr->indx * BITMAP_ELEMENT_ALL_BITS - + word_num * HOST_BITS_PER_WIDE_INT + + word_num * BITMAP_WORD_BITS + bit_num); } @@ -536,11 +506,8 @@ bitmap_last_set_bit (a) a specific bit manipulation. Return true if TO changes. */ int -bitmap_operation (to, from1, from2, operation) - bitmap to; - bitmap from1; - bitmap from2; - enum bitmap_bits operation; +bitmap_operation (bitmap to, bitmap from1, bitmap from2, + enum bitmap_bits operation) { #define HIGHEST_INDEX (unsigned int) ~0 @@ -558,7 +525,7 @@ bitmap_operation (to, from1, from2, operation) #if BITMAP_ELEMENT_WORDS == 2 #define DOIT(OP) \ do { \ - unsigned HOST_WIDE_INT t0, t1, f10, f11, f20, f21; \ + BITMAP_WORD t0, t1, f10, f11, f20, f21; \ f10 = from1_tmp->bits[0]; \ f20 = from2_tmp->bits[0]; \ t0 = f10 OP f20; \ @@ -573,7 +540,7 @@ bitmap_operation (to, from1, from2, operation) #else #define DOIT(OP) \ do { \ - unsigned HOST_WIDE_INT t, f1, f2; \ + BITMAP_WORD t, f1, f2; \ int i; \ for (i = 0; i < BITMAP_ELEMENT_WORDS; ++i) \ { \ @@ -699,14 +666,12 @@ bitmap_operation (to, from1, from2, operation) /* Return true if two bitmaps are identical. */ int -bitmap_equal_p (a, b) - bitmap a; - bitmap b; +bitmap_equal_p (bitmap a, bitmap b) { bitmap_head c; int ret; - memset (&c, 0, sizeof (c)); + memset (&c, 0, sizeof (c)); ret = ! bitmap_operation (&c, a, b, BITMAP_XOR); bitmap_clear (&c); @@ -717,10 +682,7 @@ bitmap_equal_p (a, b) bitmap FROM2. */ void -bitmap_ior_and_compl (to, from1, from2) - bitmap to; - bitmap from1; - bitmap from2; +bitmap_ior_and_compl (bitmap to, bitmap from1, bitmap from2) { bitmap_head tmp; @@ -733,11 +695,7 @@ bitmap_ior_and_compl (to, from1, from2) } int -bitmap_union_of_diff (dst, a, b, c) - bitmap dst; - bitmap a; - bitmap b; - bitmap c; +bitmap_union_of_diff (bitmap dst, bitmap a, bitmap b, bitmap c) { bitmap_head tmp; int changed; @@ -755,13 +713,11 @@ bitmap_union_of_diff (dst, a, b, c) /* Initialize a bitmap header. */ bitmap -bitmap_initialize (head, using_obstack) - bitmap head; - int using_obstack; +bitmap_initialize (bitmap head, int using_obstack) { if (head == NULL && ! using_obstack) head = ggc_alloc (sizeof (*head)); - + head->first = head->current = 0; head->using_obstack = using_obstack; @@ -771,32 +727,24 @@ bitmap_initialize (head, using_obstack) /* Debugging function to print out the contents of a bitmap. */ void -debug_bitmap_file (file, head) - FILE *file; - bitmap head; +debug_bitmap_file (FILE *file, bitmap head) { bitmap_element *ptr; - fprintf (file, "\nfirst = "); - fprintf (file, HOST_PTR_PRINTF, (PTR) head->first); - fprintf (file, " current = "); - fprintf (file, HOST_PTR_PRINTF, (PTR) head->current); - fprintf (file, " indx = %u\n", head->indx); + fprintf (file, "\nfirst = " HOST_PTR_PRINTF + " current = " HOST_PTR_PRINTF " indx = %u\n", + (void *) head->first, (void *) head->current, head->indx); for (ptr = head->first; ptr; ptr = ptr->next) { - int i, j, col = 26; + unsigned int i, j, col = 26; - fprintf (file, "\t"); - fprintf (file, HOST_PTR_PRINTF, (PTR) ptr); - fprintf (file, " next = "); - fprintf (file, HOST_PTR_PRINTF, (PTR) ptr->next); - fprintf (file, " prev = "); - fprintf (file, HOST_PTR_PRINTF, (PTR) ptr->prev); - fprintf (file, " indx = %u\n\t\tbits = {", ptr->indx); + fprintf (file, "\t" HOST_PTR_PRINTF " next = " HOST_PTR_PRINTF + " prev = " HOST_PTR_PRINTF " indx = %u\n\t\tbits = {", + (void*) ptr, (void*) ptr->next, (void*) ptr->prev, ptr->indx); for (i = 0; i < BITMAP_ELEMENT_WORDS; i++) - for (j = 0; j < HOST_BITS_PER_WIDE_INT; j++) + for (j = 0; j < BITMAP_WORD_BITS; j++) if ((ptr->bits[i] >> j) & 1) { if (col > 70) @@ -806,7 +754,7 @@ debug_bitmap_file (file, head) } fprintf (file, " %u", (ptr->indx * BITMAP_ELEMENT_ALL_BITS - + i * HOST_BITS_PER_WIDE_INT + j)); + + i * BITMAP_WORD_BITS + j)); col += 4; } @@ -818,8 +766,7 @@ debug_bitmap_file (file, head) of a bitmap. */ void -debug_bitmap (head) - bitmap head; +debug_bitmap (bitmap head) { debug_bitmap_file (stdout, head); } @@ -828,11 +775,7 @@ debug_bitmap (head) it does not print anything but the bits. */ void -bitmap_print (file, head, prefix, suffix) - FILE *file; - bitmap head; - const char *prefix; - const char *suffix; +bitmap_print (FILE *file, bitmap head, const char *prefix, const char *suffix) { const char *comma = ""; int i;