+ if (!changed && dst_elt && dst_elt->indx == a_elt->indx)
+ {
+ for (ix = 0; ix < BITMAP_ELEMENT_WORDS; ix++)
+ {
+ BITMAP_WORD r = a_elt->bits[ix] | b_elt->bits[ix];
+ if (r != dst_elt->bits[ix])
+ {
+ dst_elt->bits[ix] = r;
+ changed = true;
+ }
+ }
+ }
+ else
+ {
+ changed = true;
+ if (!dst_elt)
+ dst_elt = bitmap_elt_insert_after (dst, dst_prev, a_elt->indx);
+ else
+ dst_elt->indx = a_elt->indx;
+ for (ix = 0; ix < BITMAP_ELEMENT_WORDS; ix++)
+ {
+ BITMAP_WORD r = a_elt->bits[ix] | b_elt->bits[ix];
+ dst_elt->bits[ix] = r;
+ }
+ }
+ }
+ else
+ {
+ /* Copy a single element. */
+ const bitmap_element *src;
+
+ if (!b_elt || (a_elt && a_elt->indx < b_elt->indx))
+ src = a_elt;
+ else
+ src = b_elt;
+
+ gcc_checking_assert (src);
+ changed = bitmap_elt_copy (dst, dst_elt, dst_prev, src, changed);
+ }
+ return changed;
+}
+
+
+/* DST = A | B. Return true if DST changes. */
+
+bool
+bitmap_ior (bitmap dst, const_bitmap a, const_bitmap b)
+{
+ bitmap_element *dst_elt = dst->first;
+ const bitmap_element *a_elt = a->first;
+ const bitmap_element *b_elt = b->first;
+ bitmap_element *dst_prev = NULL;
+ bitmap_element **dst_prev_pnext = &dst->first;
+ bool changed = false;
+
+ gcc_assert (dst != a && dst != b);
+
+ while (a_elt || b_elt)
+ {
+ changed = bitmap_elt_ior (dst, dst_elt, dst_prev, a_elt, b_elt, changed);
+
+ if (a_elt && b_elt && a_elt->indx == b_elt->indx)
+ {
+ a_elt = a_elt->next;
+ b_elt = b_elt->next;
+ }
+ else
+ {
+ if (a_elt && (!b_elt || a_elt->indx <= b_elt->indx))
+ a_elt = a_elt->next;
+ else if (b_elt && (!a_elt || b_elt->indx <= a_elt->indx))
+ b_elt = b_elt->next;
+ }
+
+ dst_prev = *dst_prev_pnext;
+ dst_prev_pnext = &dst_prev->next;
+ dst_elt = *dst_prev_pnext;
+ }
+
+ if (dst_elt)
+ {
+ changed = true;
+ bitmap_elt_clear_from (dst, dst_elt);
+ }
+ gcc_checking_assert (!dst->current == !dst->first);
+ if (dst->current)
+ dst->indx = dst->current->indx;
+ return changed;
+}
+
+/* A |= B. Return true if A changes. */
+
+bool
+bitmap_ior_into (bitmap a, const_bitmap b)
+{
+ bitmap_element *a_elt = a->first;
+ const bitmap_element *b_elt = b->first;
+ bitmap_element *a_prev = NULL;
+ bitmap_element **a_prev_pnext = &a->first;
+ bool changed = false;
+
+ if (a == b)
+ return false;
+
+ while (b_elt)
+ {
+ /* If A lags behind B, just advance it. */
+ if (!a_elt || a_elt->indx == b_elt->indx)
+ {
+ changed = bitmap_elt_ior (a, a_elt, a_prev, a_elt, b_elt, changed);
+ b_elt = b_elt->next;
+ }
+ else if (a_elt->indx > b_elt->indx)
+ {
+ changed = bitmap_elt_copy (a, NULL, a_prev, b_elt, changed);
+ b_elt = b_elt->next;
+ }
+
+ a_prev = *a_prev_pnext;
+ a_prev_pnext = &a_prev->next;
+ a_elt = *a_prev_pnext;
+ }
+
+ gcc_checking_assert (!a->current == !a->first);
+ if (a->current)
+ a->indx = a->current->indx;
+ return changed;
+}
+
+/* DST = A ^ B */
+
+void
+bitmap_xor (bitmap dst, const_bitmap a, const_bitmap b)
+{
+ bitmap_element *dst_elt = dst->first;
+ const bitmap_element *a_elt = a->first;
+ const bitmap_element *b_elt = b->first;
+ bitmap_element *dst_prev = NULL;
+
+ 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)
+ {
+ /* Matching elts, generate A ^ B. */
+ unsigned ix;
+ BITMAP_WORD ior = 0;
+
+ if (!dst_elt)
+ dst_elt = bitmap_elt_insert_after (dst, dst_prev, a_elt->indx);
+ else
+ dst_elt->indx = a_elt->indx;
+ for (ix = 0; ix < BITMAP_ELEMENT_WORDS; ix++)
+ {
+ BITMAP_WORD r = a_elt->bits[ix] ^ b_elt->bits[ix];
+
+ ior |= r;
+ dst_elt->bits[ix] = r;
+ }
+ a_elt = a_elt->next;
+ b_elt = b_elt->next;
+ if (ior)
+ {
+ dst_prev = dst_elt;
+ dst_elt = dst_elt->next;
+ }
+ }
+ else
+ {
+ /* Copy a single element. */
+ const bitmap_element *src;
+
+ if (!b_elt || (a_elt && a_elt->indx < b_elt->indx))
+ {
+ src = a_elt;
+ a_elt = a_elt->next;
+ }
+ else
+ {
+ src = b_elt;
+ b_elt = b_elt->next;
+ }
+
+ if (!dst_elt)
+ 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;
+ }
+ }
+ /* Ensure that dst->current is valid. */
+ dst->current = dst->first;
+ bitmap_elt_clear_from (dst, dst_elt);
+ gcc_checking_assert (!dst->current == !dst->first);
+ if (dst->current)
+ dst->indx = dst->current->indx;
+}
+
+/* A ^= B */
+
+void
+bitmap_xor_into (bitmap a, const_bitmap b)
+{
+ bitmap_element *a_elt = a->first;
+ const bitmap_element *b_elt = b->first;
+ bitmap_element *a_prev = NULL;
+
+ 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, b_elt->indx);
+ memcpy (dst->bits, b_elt->bits, sizeof (dst->bits));
+ a_prev = dst;
+ b_elt = b_elt->next;
+ }
+ else if (a_elt->indx < b_elt->indx)
+ {
+ a_prev = a_elt;
+ a_elt = a_elt->next;
+ }
+ else
+ {
+ /* Matching elts, generate A ^= B. */
+ unsigned ix;
+ BITMAP_WORD ior = 0;
+ bitmap_element *next = a_elt->next;
+
+ for (ix = 0; ix < BITMAP_ELEMENT_WORDS; ix++)
+ {
+ BITMAP_WORD r = a_elt->bits[ix] ^ b_elt->bits[ix];
+
+ ior |= r;
+ a_elt->bits[ix] = r;
+ }
+ b_elt = b_elt->next;
+ if (ior)
+ a_prev = a_elt;
+ else
+ bitmap_element_free (a, a_elt);
+ a_elt = next;
+ }
+ }
+ gcc_checking_assert (!a->current == !a->first);
+ if (a->current)
+ a->indx = a->current->indx;
+}
+
+/* Return true if two bitmaps are identical.
+ We do not bother with a check for pointer equality, as that never
+ occurs in practice. */
+
+bool
+bitmap_equal_p (const_bitmap a, const_bitmap b)
+{
+ const bitmap_element *a_elt;
+ const bitmap_element *b_elt;
+ unsigned ix;
+
+ for (a_elt = a->first, b_elt = b->first;
+ a_elt && b_elt;
+ a_elt = a_elt->next, b_elt = b_elt->next)
+ {
+ if (a_elt->indx != b_elt->indx)
+ return false;
+ for (ix = 0; ix < BITMAP_ELEMENT_WORDS; ix++)
+ if (a_elt->bits[ix] != b_elt->bits[ix])
+ return false;
+ }
+ return !a_elt && !b_elt;
+}
+
+/* Return true if A AND B is not empty. */
+
+bool
+bitmap_intersect_p (const_bitmap a, const_bitmap b)
+{
+ const bitmap_element *a_elt;
+ const bitmap_element *b_elt;
+ unsigned ix;
+
+ for (a_elt = a->first, b_elt = b->first;
+ a_elt && b_elt;)
+ {
+ if (a_elt->indx < b_elt->indx)
+ a_elt = a_elt->next;
+ else if (b_elt->indx < a_elt->indx)
+ b_elt = b_elt->next;
+ else
+ {
+ for (ix = 0; ix < BITMAP_ELEMENT_WORDS; ix++)
+ if (a_elt->bits[ix] & b_elt->bits[ix])
+ return true;
+ a_elt = a_elt->next;
+ b_elt = b_elt->next;
+ }
+ }
+ return false;
+}
+
+/* Return true if A AND NOT B is not empty. */
+
+bool
+bitmap_intersect_compl_p (const_bitmap a, const_bitmap b)
+{
+ const bitmap_element *a_elt;
+ const bitmap_element *b_elt;
+ unsigned ix;
+ for (a_elt = a->first, b_elt = b->first;
+ a_elt && b_elt;)
+ {
+ if (a_elt->indx < b_elt->indx)
+ return true;
+ else if (b_elt->indx < a_elt->indx)
+ b_elt = b_elt->next;
+ else
+ {
+ for (ix = 0; ix < BITMAP_ELEMENT_WORDS; ix++)
+ if (a_elt->bits[ix] & ~b_elt->bits[ix])
+ return true;
+ a_elt = a_elt->next;
+ b_elt = b_elt->next;
+ }
+ }
+ return a_elt != NULL;
+}
+
+\f
+/* DST = A | (FROM1 & ~FROM2). Return true if DST changes. */
+
+bool
+bitmap_ior_and_compl (bitmap dst, const_bitmap a, const_bitmap b, const_bitmap kill)
+{
+ bool changed = false;
+
+ bitmap_element *dst_elt = dst->first;
+ const bitmap_element *a_elt = a->first;
+ const bitmap_element *b_elt = b->first;
+ const bitmap_element *kill_elt = kill->first;
+ bitmap_element *dst_prev = NULL;
+ bitmap_element **dst_prev_pnext = &dst->first;
+
+ gcc_assert (dst != a && dst != b && dst != kill);
+
+ /* Special cases. We don't bother checking for bitmap_equal_p (b, kill). */
+ if (b == kill || bitmap_empty_p (b))
+ {
+ changed = !bitmap_equal_p (dst, a);
+ if (changed)
+ bitmap_copy (dst, a);
+ return changed;
+ }
+ if (bitmap_empty_p (kill))
+ return bitmap_ior (dst, a, b);
+ if (bitmap_empty_p (a))
+ return bitmap_and_compl (dst, b, kill);
+
+ while (a_elt || b_elt)
+ {
+ bool new_element = false;
+
+ if (b_elt)
+ while (kill_elt && kill_elt->indx < b_elt->indx)
+ kill_elt = kill_elt->next;
+
+ if (b_elt && kill_elt && kill_elt->indx == b_elt->indx
+ && (!a_elt || a_elt->indx >= b_elt->indx))
+ {
+ bitmap_element tmp_elt;
+ unsigned ix;
+
+ BITMAP_WORD ior = 0;
+ tmp_elt.indx = b_elt->indx;
+ for (ix = 0; ix < BITMAP_ELEMENT_WORDS; ix++)
+ {
+ BITMAP_WORD r = b_elt->bits[ix] & ~kill_elt->bits[ix];
+ ior |= r;
+ tmp_elt.bits[ix] = r;
+ }
+
+ if (ior)
+ {
+ changed = bitmap_elt_ior (dst, dst_elt, dst_prev,
+ a_elt, &tmp_elt, changed);
+ new_element = true;
+ if (a_elt && a_elt->indx == b_elt->indx)
+ a_elt = a_elt->next;
+ }
+
+ b_elt = b_elt->next;
+ kill_elt = kill_elt->next;
+ }
+ else
+ {
+ changed = bitmap_elt_ior (dst, dst_elt, dst_prev,
+ a_elt, b_elt, changed);
+ new_element = true;
+
+ if (a_elt && b_elt && a_elt->indx == b_elt->indx)
+ {
+ a_elt = a_elt->next;
+ b_elt = b_elt->next;
+ }
+ else
+ {
+ if (a_elt && (!b_elt || a_elt->indx <= b_elt->indx))
+ a_elt = a_elt->next;
+ else if (b_elt && (!a_elt || b_elt->indx <= a_elt->indx))
+ b_elt = b_elt->next;
+ }
+ }
+
+ if (new_element)
+ {
+ dst_prev = *dst_prev_pnext;
+ dst_prev_pnext = &dst_prev->next;
+ dst_elt = *dst_prev_pnext;
+ }
+ }
+
+ if (dst_elt)
+ {
+ changed = true;
+ bitmap_elt_clear_from (dst, dst_elt);
+ }
+ gcc_checking_assert (!dst->current == !dst->first);
+ if (dst->current)
+ dst->indx = dst->current->indx;
+
+ return changed;
+}
+
+/* A |= (FROM1 & ~FROM2). Return true if A changes. */
+
+bool
+bitmap_ior_and_compl_into (bitmap a, const_bitmap from1, const_bitmap from2)
+{
+ bitmap_head tmp;
+ bool changed;
+
+ bitmap_initialize (&tmp, &bitmap_default_obstack);
+ bitmap_and_compl (&tmp, from1, from2);
+ changed = bitmap_ior_into (a, &tmp);
+ bitmap_clear (&tmp);
+
+ return changed;
+}
+
+/* A |= (B & C). Return true if A changes. */
+
+bool
+bitmap_ior_and_into (bitmap a, const_bitmap b, const_bitmap c)
+{
+ bitmap_element *a_elt = a->first;
+ const bitmap_element *b_elt = b->first;
+ const bitmap_element *c_elt = c->first;
+ bitmap_element and_elt;
+ bitmap_element *a_prev = NULL;
+ bitmap_element **a_prev_pnext = &a->first;
+ bool changed = false;
+ unsigned ix;
+
+ if (b == c)
+ return bitmap_ior_into (a, b);
+ if (bitmap_empty_p (b) || bitmap_empty_p (c))
+ return false;
+
+ and_elt.indx = -1;
+ while (b_elt && c_elt)
+ {
+ BITMAP_WORD overall;
+
+ /* Find a common item of B and C. */
+ while (b_elt->indx != c_elt->indx)
+ {
+ if (b_elt->indx < c_elt->indx)
+ {
+ b_elt = b_elt->next;
+ if (!b_elt)
+ goto done;
+ }
+ else
+ {
+ c_elt = c_elt->next;
+ if (!c_elt)
+ goto done;
+ }
+ }
+
+ overall = 0;
+ and_elt.indx = b_elt->indx;
+ for (ix = 0; ix < BITMAP_ELEMENT_WORDS; ix++)
+ {
+ and_elt.bits[ix] = b_elt->bits[ix] & c_elt->bits[ix];
+ overall |= and_elt.bits[ix];
+ }
+
+ b_elt = b_elt->next;
+ c_elt = c_elt->next;
+ if (!overall)
+ continue;
+
+ /* Now find a place to insert AND_ELT. */
+ do
+ {
+ ix = a_elt ? a_elt->indx : and_elt.indx;
+ if (ix == and_elt.indx)
+ changed = bitmap_elt_ior (a, a_elt, a_prev, a_elt, &and_elt, changed);
+ else if (ix > and_elt.indx)
+ changed = bitmap_elt_copy (a, NULL, a_prev, &and_elt, changed);
+
+ a_prev = *a_prev_pnext;
+ a_prev_pnext = &a_prev->next;
+ a_elt = *a_prev_pnext;
+
+ /* If A lagged behind B/C, we advanced it so loop once more. */
+ }
+ while (ix < and_elt.indx);
+ }
+
+ done:
+ gcc_checking_assert (!a->current == !a->first);
+ if (a->current)
+ a->indx = a->current->indx;
+ return changed;