OSDN Git Service

PR c++/27292
[pf3gnuchains/gcc-fork.git] / gcc / bitmap.c
index 68b8429..f69fd27 100644 (file)
@@ -1,5 +1,5 @@
 /* Functions to support general ended bitmaps.
-   Copyright (C) 1997, 1998, 1999, 2000, 2001, 2003, 2004
+   Copyright (C) 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -16,8 +16,8 @@ for more details.
 
 You should have received a copy of the GNU General Public License
 along with GCC; see the file COPYING.  If not, write to the Free
-Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.  */
+Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301, USA.  */
 
 #include "config.h"
 #include "system.h"
@@ -29,16 +29,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "ggc.h"
 #include "bitmap.h"
 
-/* Obstack to allocate bitmap elements from.  */
-\f
-#ifndef INLINE
-#ifndef __GNUC__
-#define INLINE
-#else
-#define INLINE __inline__
-#endif
-#endif
-
 /* Global data */
 bitmap_element bitmap_zero_bits;  /* An element of all zero bits.  */
 bitmap_obstack bitmap_default_obstack;    /* The default bitmap obstack.  */
@@ -50,25 +40,26 @@ 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_elt_insert_after (bitmap, bitmap_element *);
+static bitmap_element *bitmap_elt_insert_after (bitmap, bitmap_element *, unsigned int);
 static void bitmap_elt_clear_from (bitmap, bitmap_element *);
 static bitmap_element *bitmap_find_bit (bitmap, unsigned int);
 \f
 
 /* Add ELEM to the appropriate freelist.  */
-static INLINE void
+static inline void
 bitmap_elem_to_freelist (bitmap head, bitmap_element *elt)
 {
   bitmap_obstack *bit_obstack = head->obstack;
   
+  elt->next = NULL;
   if (bit_obstack)
     {
-      elt->next = bit_obstack->elements;
+      elt->prev = bit_obstack->elements;
       bit_obstack->elements = elt;
     }
   else
     {
-      elt->next = bitmap_ggc_free;
+      elt->prev = bitmap_ggc_free;
       bitmap_ggc_free = elt;
     }
 }
@@ -76,7 +67,7 @@ bitmap_elem_to_freelist (bitmap head, bitmap_element *elt)
 /* Free a bitmap element.  Since these are allocated off the
    bitmap_obstack, "free" actually means "put onto the freelist".  */
 
-static INLINE void
+static inline void
 bitmap_element_free (bitmap head, bitmap_element *elt)
 {
   bitmap_element *next = elt->next;
@@ -98,13 +89,15 @@ bitmap_element_free (bitmap head, bitmap_element *elt)
       head->current = next != 0 ? next : prev;
       if (head->current)
        head->indx = head->current->indx;
+      else 
+       head->indx = 0;
     }
   bitmap_elem_to_freelist (head, elt);
 }
 \f
 /* Allocate a bitmap element.  The bits are cleared, but nothing else is.  */
 
-static INLINE bitmap_element *
+static inline bitmap_element *
 bitmap_element_allocate (bitmap head)
 {
   bitmap_element *element;
@@ -115,7 +108,16 @@ bitmap_element_allocate (bitmap head)
       element = bit_obstack->elements;
       
       if (element)
-       bit_obstack->elements = element->next;
+       /* Use up the inner list first before looking at the next
+          element of the outer list.  */
+       if (element->next)
+         {
+           bit_obstack->elements = element->next;
+           bit_obstack->elements->prev = element->prev;
+         }
+       else
+         /*  Inner list was just a singleton.  */
+         bit_obstack->elements = element->prev;
       else
        element = XOBNEW (&bit_obstack->obstack, bitmap_element);
     }
@@ -123,7 +125,16 @@ bitmap_element_allocate (bitmap head)
     {
       element = bitmap_ggc_free;
       if (element)
-       bitmap_ggc_free = element->next;
+       /* Use up the inner list first before looking at the next
+          element of the outer list.  */
+       if (element->next)
+         {
+           bitmap_ggc_free = element->next;
+           bitmap_ggc_free->prev = element->prev;
+         }
+       else
+         /*  Inner list was just a singleton.  */
+         bitmap_ggc_free = element->prev;
       else
        element = GGC_NEW (bitmap_element);
     }
@@ -138,30 +149,48 @@ bitmap_element_allocate (bitmap head)
 void
 bitmap_elt_clear_from (bitmap head, bitmap_element *elt)
 {
-  bitmap_element *next;
+  bitmap_element *prev;
+  bitmap_obstack *bit_obstack = head->obstack;
+
+  if (!elt) return;
+
+  prev = elt->prev;
+  if (prev)
+    {
+      prev->next = NULL;
+      if (head->current->indx > prev->indx)
+       {
+         head->current = prev;
+         head->indx = prev->indx;
+       }
+    } 
+  else
+    {
+      head->first = NULL;
+      head->current = NULL;
+      head->indx = 0;
+    }
 
-  while (elt)
+  /* Put the entire list onto the free list in one operation. */ 
+  if (bit_obstack)
     {
-      next = elt->next;
-      bitmap_element_free (head, elt);
-      elt = next;
+      elt->prev = bit_obstack->elements; 
+      bit_obstack->elements = elt;
+    }
+  else
+    {
+      elt->prev = bitmap_ggc_free;
+      bitmap_ggc_free = elt;
     }
 }
 
 /* Clear a bitmap by freeing the linked list.  */
 
-INLINE void
+inline void
 bitmap_clear (bitmap head)
 {
-  bitmap_element *element, *next;
-
-  for (element = head->first; element != 0; element = next)
-    {
-      next = element->next;
-      bitmap_elem_to_freelist (head, element);
-    }
-
-  head->first = head->current = 0;
+  if (head->first)
+    bitmap_elt_clear_from (head, head->first);
 }
 \f
 /* Initialize a bitmap obstack.  If BIT_OBSTACK is NULL, initialize
@@ -232,43 +261,23 @@ bitmap_gc_alloc (void)
   return map;
 }
 
-/* Create a new malloced bitmap.  Elements will be allocated from the
-   default bitmap obstack.  */
-
-bitmap
-bitmap_malloc_alloc (void)
-{
-  bitmap map;
-
-  map = xmalloc (sizeof (bitmap_head));
-  bitmap_initialize (map, &bitmap_default_obstack);
-
-  return map;
-}
-
 /* Release an obstack allocated bitmap.  */
 
 void
 bitmap_obstack_free (bitmap map)
 {
-  bitmap_clear (map);
-  map->first = (void *)map->obstack->heads;
-  map->obstack->heads = map;
-}
-
-/* Release a malloc allocated bitmap.  */
-
-void
-bitmap_malloc_free (bitmap map)
-{
-  bitmap_clear (map);
-  free (map);
+  if (map)
+    {
+      bitmap_clear (map);
+      map->first = (void *)map->obstack->heads;
+      map->obstack->heads = map;
+    }
 }
 
 \f
 /* Return nonzero if all bits in an element are zero.  */
 
-static INLINE int
+static inline int
 bitmap_element_zerop (bitmap_element *element)
 {
 #if BITMAP_ELEMENT_WORDS == 2
@@ -286,7 +295,7 @@ bitmap_element_zerop (bitmap_element *element)
 \f
 /* Link the bitmap element into the current bitmap linked list.  */
 
-static INLINE void
+static inline void
 bitmap_element_link (bitmap head, bitmap_element *element)
 {
   unsigned int indx = element->indx;
@@ -344,14 +353,18 @@ bitmap_element_link (bitmap head, bitmap_element *element)
    new element.  */
 
 static bitmap_element *
-bitmap_elt_insert_after (bitmap head, bitmap_element *elt)
+bitmap_elt_insert_after (bitmap head, bitmap_element *elt, unsigned int indx)
 {
   bitmap_element *node = bitmap_element_allocate (head);
+  node->indx = indx;
 
   if (!elt)
     {
       if (!head->current)
-       head->current = node;
+       {
+         head->current = node;
+         head->indx = indx;
+       }
       node->next = head->first;
       if (node->next)
        node->next->prev = node;
@@ -376,9 +389,6 @@ void
 bitmap_copy (bitmap to, bitmap from)
 {
   bitmap_element *from_ptr, *to_ptr = 0;
-#if BITMAP_ELEMENT_WORDS != 2
-  unsigned i;
-#endif
 
   bitmap_clear (to);
 
@@ -388,14 +398,7 @@ bitmap_copy (bitmap to, bitmap from)
       bitmap_element *to_elt = bitmap_element_allocate (to);
 
       to_elt->indx = from_ptr->indx;
-
-#if BITMAP_ELEMENT_WORDS == 2
-      to_elt->bits[0] = from_ptr->bits[0];
-      to_elt->bits[1] = from_ptr->bits[1];
-#else
-      for (i = 0; i < BITMAP_ELEMENT_WORDS; i++)
-       to_elt->bits[i] = from_ptr->bits[i];
-#endif
+      memcpy (to_elt->bits, from_ptr->bits, sizeof (to_elt->bits));
 
       /* Here we have a special case of bitmap_element_link, for the case
         where we know the links are being entered in sequence.  */
@@ -421,7 +424,7 @@ bitmap_copy (bitmap to, bitmap from)
    would hold the bitmap's bit to make eventual allocation
    faster.  */
 
-static INLINE bitmap_element *
+static inline bitmap_element *
 bitmap_find_bit (bitmap head, unsigned int bit)
 {
   bitmap_element *element;
@@ -431,14 +434,26 @@ bitmap_find_bit (bitmap head, unsigned int bit)
       || head->indx == indx)
     return head->current;
 
-  if (head->indx > indx)
+  if (head->indx < indx)
+    /* INDX is beyond head->indx.  Search from head->current
+       forward.  */
+    for (element = head->current;
+        element->next != 0 && element->indx < indx;
+        element = element->next)
+      ;
+
+  else if (head->indx / 2 < indx)
+    /* INDX is less than head->indx and closer to head->indx than to
+       0.  Search from head->current backward.  */
     for (element = head->current;
         element->prev != 0 && element->indx > indx;
         element = element->prev)
       ;
 
   else
-    for (element = head->current;
+    /* INDX is less than head->indx and closer to 0 than to
+       head->indx.  Search from head->first forward.  */
+    for (element = head->first;
         element->next != 0 && element->indx < indx;
         element = element->next)
       ;
@@ -512,6 +527,59 @@ bitmap_bit_p (bitmap head, int bit)
   return (ptr->bits[word_num] >> bit_num) & 1;
 }
 \f
+#if GCC_VERSION < 3400
+/* Table of number of set bits in a character, indexed by value of char.  */
+static 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,
+    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,
+    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,
+    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,
+    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,
+    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,
+    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,
+};
+
+static unsigned long
+bitmap_popcount (BITMAP_WORD a)
+{
+  unsigned long ret = 0;
+  unsigned i;
+
+  /* Just do this the table way for now  */
+  for (i = 0; i < BITMAP_WORD_BITS; i+= 8)
+    ret += popcount_table[(a >> i) & 0xff];
+  return ret;
+}
+#endif
+/* Count the number of bits set in the bitmap, and return it.  */
+
+unsigned long
+bitmap_count_bits (bitmap a)
+{
+  unsigned long count = 0;
+  bitmap_element *elt;
+  unsigned ix;
+
+  for (elt = a->first; elt; elt = elt->next)
+    {
+      for (ix = 0; ix != BITMAP_ELEMENT_WORDS; ix++)
+       {
+#if GCC_VERSION >= 3400
+         /* Note that popcountl matches BITMAP_WORD in type, so the actual size
+        of BITMAP_WORD is not material.  */
+         count += __builtin_popcountl (elt->bits[ix]);
+#else
+         count += bitmap_popcount (elt->bits[ix]);       
+#endif
+       }
+    }
+  return count;
+}
+      
+
+
 /* Return the bit number of the first set bit in the bitmap.  The
    bitmap must be non-empty.  */
 
@@ -574,7 +642,14 @@ bitmap_and (bitmap dst, bitmap a, bitmap b)
   bitmap_element *b_elt = b->first;
   bitmap_element *dst_prev = NULL;
 
-  gcc_assert (dst != a && dst != b && a != b);
+  gcc_assert (dst != a && dst != b);
+
+  if (a == b)
+    {
+      bitmap_copy (dst, a);
+      return;
+    }
+
   while (a_elt && b_elt)
     {
       if (a_elt->indx < b_elt->indx)
@@ -588,9 +663,9 @@ bitmap_and (bitmap dst, bitmap a, bitmap b)
          BITMAP_WORD ior = 0;
 
          if (!dst_elt)
-           dst_elt = bitmap_elt_insert_after (dst, dst_prev);
-         
-         dst_elt->indx = a_elt->indx;
+           dst_elt = bitmap_elt_insert_after (dst, dst_prev, a_elt->indx);
+         else 
+           dst_elt->indx = a_elt->indx;
          for (ix = BITMAP_ELEMENT_WORDS; ix--;)
            {
              BITMAP_WORD r = a_elt->bits[ix] & b_elt->bits[ix];
@@ -622,7 +697,9 @@ bitmap_and_into (bitmap a, bitmap b)
   bitmap_element *b_elt = b->first;
   bitmap_element *next;
 
-  gcc_assert (a != b);
+  if (a == b) 
+    return;
+
   while (a_elt && b_elt)
     {
       if (a_elt->indx < b_elt->indx)
@@ -668,17 +745,23 @@ bitmap_and_compl (bitmap dst, bitmap a, bitmap b)
   bitmap_element *b_elt = b->first;
   bitmap_element *dst_prev = NULL;
 
-  gcc_assert (dst != a && dst != b && a != b);
+  gcc_assert (dst != a && dst != b);
   
+  if (a == b)
+    {
+      bitmap_clear (dst);
+      return;
+    }
+
   while (a_elt)
     {
       if (!b_elt || a_elt->indx < b_elt->indx)
        {
          /* Copy a_elt.  */
          if (!dst_elt)
-           dst_elt = bitmap_elt_insert_after (dst, dst_prev);
-         
-         dst_elt->indx = a_elt->indx;
+           dst_elt = bitmap_elt_insert_after (dst, dst_prev, a_elt->indx);
+         else
+           dst_elt->indx = a_elt->indx;
          memcpy (dst_elt->bits, a_elt->bits, sizeof (dst_elt->bits));
          dst_prev = dst_elt;
          dst_elt = dst_elt->next;
@@ -693,9 +776,9 @@ bitmap_and_compl (bitmap dst, bitmap a, bitmap b)
          BITMAP_WORD ior = 0;
 
          if (!dst_elt)
-           dst_elt = bitmap_elt_insert_after (dst, dst_prev);
-         
-         dst_elt->indx = a_elt->indx;
+           dst_elt = bitmap_elt_insert_after (dst, dst_prev, a_elt->indx);
+         else 
+           dst_elt->indx = a_elt->indx;
          for (ix = BITMAP_ELEMENT_WORDS; ix--;)
            {
              BITMAP_WORD r = a_elt->bits[ix] & ~b_elt->bits[ix];
@@ -718,16 +801,27 @@ bitmap_and_compl (bitmap dst, bitmap a, bitmap b)
     dst->indx = dst->current->indx;
 }
 
-/* A &= ~B */
+/* A &= ~B. Returns true if A changes */
 
-void
+bool
 bitmap_and_compl_into (bitmap a, bitmap b)
 {
   bitmap_element *a_elt = a->first;
   bitmap_element *b_elt = b->first;
   bitmap_element *next;
+  BITMAP_WORD changed = 0;
+
+  if (a == b)
+    {
+      if (bitmap_empty_p (a))
+       return false;
+      else
+       {
+         bitmap_clear (a);
+         return true;
+       }
+    }
 
-  gcc_assert (a != b);
   while (a_elt && b_elt)
     {
       if (a_elt->indx < b_elt->indx)
@@ -742,9 +836,11 @@ bitmap_and_compl_into (bitmap a, bitmap b)
 
          for (ix = BITMAP_ELEMENT_WORDS; ix--;)
            {
-             BITMAP_WORD r = a_elt->bits[ix] & ~b_elt->bits[ix];
+             BITMAP_WORD cleared = a_elt->bits[ix] & b_elt->bits[ix];
+             BITMAP_WORD r = a_elt->bits[ix] ^ cleared;
 
              a_elt->bits[ix] = r;
+             changed |= cleared;
              ior |= r;
            }
          next = a_elt->next;
@@ -756,6 +852,196 @@ bitmap_and_compl_into (bitmap a, bitmap b)
     }
   gcc_assert (!a->current == !a->first);
   gcc_assert (!a->current || a->indx == a->current->indx);
+  return changed != 0;
+}
+
+/* Clear COUNT bits from START in HEAD.  */
+void
+bitmap_clear_range (bitmap head, unsigned int start, unsigned int count)
+{
+  unsigned int first_index = start / BITMAP_ELEMENT_ALL_BITS;
+  unsigned int end_bit_plus1 = start + count;
+  unsigned int end_bit = end_bit_plus1 - 1;
+  unsigned int last_index = (end_bit) / BITMAP_ELEMENT_ALL_BITS;
+  bitmap_element *elt = bitmap_find_bit (head, start);
+
+  /* If bitmap_find_bit returns zero, the current is the closest block
+     to the result.  If the current is less than first index, find the
+     next one.  Otherwise, just set elt to be current.  */
+  if (!elt)
+    { 
+      if (head->current)
+       {
+         if (head->indx < first_index)
+           {
+             elt = head->current->next;
+             if (!elt)
+               return;
+           }
+         else 
+           elt = head->current;
+       }
+      else
+       return;
+    }
+
+  while (elt && (elt->indx <= last_index))
+    {
+      bitmap_element * next_elt = elt->next;
+      unsigned elt_start_bit = (elt->indx) * BITMAP_ELEMENT_ALL_BITS;
+      unsigned elt_end_bit_plus1 = elt_start_bit + BITMAP_ELEMENT_ALL_BITS;
+
+
+      if (elt_start_bit >= start && elt_end_bit_plus1 <= end_bit_plus1)
+       /* Get rid of the entire elt and go to the next one.  */
+       bitmap_element_free (head, elt);
+      else 
+       {
+         /* Going to have to knock out some bits in this elt.  */
+         unsigned int first_word_to_mod; 
+         BITMAP_WORD first_mask; 
+         unsigned int last_word_to_mod;
+         BITMAP_WORD last_mask;
+         unsigned int i;
+         bool clear = true;
+
+         if (elt_start_bit <= start)
+           {
+             /* The first bit to turn off is somewhere inside this
+                elt.  */
+             first_word_to_mod = (start - elt_start_bit) / BITMAP_WORD_BITS;
+
+             /* This mask should have 1s in all bits >= start position. */
+             first_mask = 
+               (((BITMAP_WORD) 1) << ((start % BITMAP_WORD_BITS))) - 1;
+             first_mask = ~first_mask;
+           }
+         else
+           {
+             /* The first bit to turn off is below this start of this elt.  */
+             first_word_to_mod = 0;
+             first_mask = 0;
+             first_mask = ~first_mask;
+           }         
+           
+         if (elt_end_bit_plus1 <= end_bit_plus1)
+           {
+             /* The last bit to turn off is beyond this elt.  */
+             last_word_to_mod = BITMAP_ELEMENT_WORDS - 1;
+             last_mask = 0;
+             last_mask = ~last_mask;
+           }
+         else
+           {
+             /* The last bit to turn off is inside to this elt.  */
+             last_word_to_mod = 
+               (end_bit_plus1 - elt_start_bit) / BITMAP_WORD_BITS;
+
+             /* The last mask should have 1s below the end bit.  */
+             last_mask = 
+               (((BITMAP_WORD) 1) << (((end_bit_plus1) % BITMAP_WORD_BITS))) - 1;
+           }
+
+
+         if (first_word_to_mod == last_word_to_mod)
+           {
+             BITMAP_WORD mask = first_mask & last_mask;
+             elt->bits[first_word_to_mod] &= ~mask;
+           }
+         else
+           {
+             elt->bits[first_word_to_mod] &= ~first_mask;
+             for (i = first_word_to_mod + 1; i < last_word_to_mod; i++)
+               elt->bits[i] = 0;
+             elt->bits[last_word_to_mod] &= ~last_mask;
+           }
+         for (i = 0; i < BITMAP_ELEMENT_WORDS; i++)
+           if (elt->bits[i])
+             {
+               clear = false;
+               break;
+             }
+         /* Check to see if there are any bits left.  */
+         if (clear)
+           bitmap_element_free (head, elt);
+       }
+      elt = next_elt;
+    }
+  
+  if (elt)
+    {
+      head->current = elt;
+      head->indx = head->current->indx;
+    }
+}
+
+/* A = ~A & B. */
+
+void
+bitmap_compl_and_into (bitmap a, bitmap b)
+{
+  bitmap_element *a_elt = a->first;
+  bitmap_element *b_elt = b->first;
+  bitmap_element *a_prev = NULL;
+  bitmap_element *next;
+
+  gcc_assert (a != b);
+
+  if (bitmap_empty_p (a))
+    {
+      bitmap_copy (a, b);
+      return;
+    }
+  if (bitmap_empty_p (b))
+    {
+      bitmap_clear (a);
+      return;
+    }
+
+  while (a_elt || b_elt)
+    {
+      if (!b_elt || (a_elt && a_elt->indx < b_elt->indx))
+       {
+         /* A is before B.  Remove A */
+         next = a_elt->next;
+         a_prev = a_elt->prev;
+         bitmap_element_free (a, a_elt);
+         a_elt = next;
+       }
+      else if (!a_elt || b_elt->indx < a_elt->indx)
+       {
+         /* B is before A.  Copy B. */
+         next = bitmap_elt_insert_after (a, a_prev, b_elt->indx);
+         memcpy (next->bits, b_elt->bits, sizeof (next->bits));
+         a_prev = next;
+         b_elt = b_elt->next;
+       }
+      else
+       {
+         /* Matching elts, generate A = ~A & B.  */
+         unsigned ix;
+         BITMAP_WORD ior = 0;
+
+         for (ix = BITMAP_ELEMENT_WORDS; ix--;)
+           {
+             BITMAP_WORD cleared = a_elt->bits[ix] & b_elt->bits[ix];
+             BITMAP_WORD r = b_elt->bits[ix] ^ cleared;
+
+             a_elt->bits[ix] = r;
+             ior |= r;
+           }
+         next = a_elt->next;
+         if (!ior)
+           bitmap_element_free (a, a_elt);
+         else
+           a_prev = a_elt;
+         a_elt = next;
+         b_elt = b_elt->next;
+       }
+    }
+  gcc_assert (!a->current == !a->first);
+  gcc_assert (!a->current || a->indx == a->current->indx);
+  return;
 }
 
 /* DST = A | B.  Return true if DST changes.  */
@@ -769,7 +1055,8 @@ bitmap_ior (bitmap dst, bitmap a, bitmap b)
   bitmap_element *dst_prev = NULL;
   bool changed = false;  
 
-  gcc_assert (dst != a && dst != b && a != b);
+  gcc_assert (dst != a && dst != b);
+
   while (a_elt || b_elt)
     {
       if (a_elt && b_elt && a_elt->indx == b_elt->indx)
@@ -794,8 +1081,9 @@ bitmap_ior (bitmap dst, bitmap a, bitmap b)
            {
              changed = true;
              if (!dst_elt)
-               dst_elt = bitmap_elt_insert_after (dst, dst_prev);
-             dst_elt->indx = a_elt->indx;
+               dst_elt = bitmap_elt_insert_after (dst, dst_prev, a_elt->indx);
+             else 
+               dst_elt->indx = a_elt->indx;
              for (ix = BITMAP_ELEMENT_WORDS; ix--;)
                {
                  BITMAP_WORD r = a_elt->bits[ix] | b_elt->bits[ix];
@@ -839,8 +1127,9 @@ bitmap_ior (bitmap dst, bitmap a, bitmap b)
            {
              changed = true;
              if (!dst_elt)
-               dst_elt = bitmap_elt_insert_after (dst, dst_prev);
-             dst_elt->indx = src->indx;
+               dst_elt = bitmap_elt_insert_after (dst, dst_prev, src->indx);
+             else 
+               dst_elt->indx = src->indx;
              memcpy (dst_elt->bits, src->bits, sizeof (dst_elt->bits));
            }
          
@@ -870,15 +1159,15 @@ bitmap_ior_into (bitmap a, bitmap b)
   bitmap_element *a_prev = NULL;
   bool changed = false;
 
-  gcc_assert (a != b);
+  if (a == b)
+    return false;
+
   while (b_elt)
     {
       if (!a_elt || b_elt->indx < a_elt->indx)
        {
          /* Copy b_elt.  */
-         bitmap_element *dst = bitmap_elt_insert_after (a, a_prev);
-         
-         dst->indx = b_elt->indx;
+         bitmap_element *dst = bitmap_elt_insert_after (a, a_prev, b_elt->indx);
          memcpy (dst->bits, b_elt->bits, sizeof (dst->bits));
          a_prev = dst;
          b_elt = b_elt->next;
@@ -933,7 +1222,13 @@ bitmap_xor (bitmap dst, bitmap a, bitmap b)
   bitmap_element *b_elt = b->first;
   bitmap_element *dst_prev = NULL;
 
-  gcc_assert (dst != a && dst != b && a != b);
+  gcc_assert (dst != a && dst != b);
+  if (a == b)
+    {
+      bitmap_clear (dst);
+      return;
+    }
+
   while (a_elt || b_elt)
     {
       if (a_elt && b_elt && a_elt->indx == b_elt->indx)
@@ -943,9 +1238,9 @@ bitmap_xor (bitmap dst, bitmap a, bitmap b)
          BITMAP_WORD ior = 0;
 
          if (!dst_elt)
-           dst_elt = bitmap_elt_insert_after (dst, dst_prev);
-         
-         dst_elt->indx = a_elt->indx;
+           dst_elt = bitmap_elt_insert_after (dst, dst_prev, a_elt->indx);
+         else
+           dst_elt->indx = a_elt->indx;
          for (ix = BITMAP_ELEMENT_WORDS; ix--;)
            {
              BITMAP_WORD r = a_elt->bits[ix] ^ b_elt->bits[ix];
@@ -978,9 +1273,9 @@ bitmap_xor (bitmap dst, bitmap a, bitmap b)
            }
 
          if (!dst_elt)
-           dst_elt = bitmap_elt_insert_after (dst, dst_prev);
-         
-         dst_elt->indx = src->indx;
+           dst_elt = bitmap_elt_insert_after (dst, dst_prev, src->indx);
+         else 
+           dst_elt->indx = src->indx;
          memcpy (dst_elt->bits, src->bits, sizeof (dst_elt->bits));
          dst_prev = dst_elt;
          dst_elt = dst_elt->next;
@@ -1001,15 +1296,18 @@ bitmap_xor_into (bitmap a, bitmap b)
   bitmap_element *b_elt = b->first;
   bitmap_element *a_prev = NULL;
 
-  gcc_assert (a != b);
+  if (a == b)
+    {
+      bitmap_clear (a);
+      return;
+    }
+
   while (b_elt)
     {
       if (!a_elt || b_elt->indx < a_elt->indx)
        {
          /* Copy b_elt.  */
-         bitmap_element *dst = bitmap_elt_insert_after (a, a_prev);
-         
-         dst->indx = b_elt->indx;
+         bitmap_element *dst = bitmap_elt_insert_after (a, a_prev, b_elt->indx);
          memcpy (dst->bits, b_elt->bits, sizeof (dst->bits));
          a_prev = dst;
          b_elt = b_elt->next;
@@ -1165,16 +1463,14 @@ debug_bitmap_file (FILE *file, bitmap head)
 {
   bitmap_element *ptr;
 
-  fprintf (file, "\nfirst = " HOST_PTR_PRINTF
-          " current = " HOST_PTR_PRINTF " indx = %u\n",
+  fprintf (file, "\nfirst = %p current = %p indx = %u\n",
           (void *) head->first, (void *) head->current, head->indx);
 
   for (ptr = head->first; ptr; ptr = ptr->next)
     {
       unsigned int i, j, col = 26;
 
-      fprintf (file, "\t" HOST_PTR_PRINTF " next = " HOST_PTR_PRINTF
-              " prev = " HOST_PTR_PRINTF " indx = %u\n\t\tbits = {",
+      fprintf (file, "\t%p next = %p prev = %p indx = %u\n\t\tbits = {",
               (void*) ptr, (void*) ptr->next, (void*) ptr->prev, ptr->indx);
 
       for (i = 0; i < BITMAP_ELEMENT_WORDS; i++)