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]

[PATCH] Make bitmap_set_bit and bitmap_clear_bit return if the bit changed



This lets us simplify some code and apply the do-not-write if nothing will change optimization in the general code.

Bootstrap & regtest running, any objections to that change?

Thanks,
Richard.

2008-07-01 Richard Guenther <rguenther@suse.de>

	* bitmap.h (bitmap_set_bit): Return bool.
	(bitmap_clear_bit): Likewise.
	* bitmap.c (bitmap_set_bit): Return if the bit changed.  Only
	write to the bitmap if it would.
	(bitmap_clear_bit): Likewise.
	* tree-ssa-structalias.c (add_implicit_graph_edge): Use
	bitmap_set_bit return value.
	(add_pred_graph_edge): Likewise.
	(add_graph_edge): Likewise.
	(do_sd_constraint): Likewise.
	(do_ds_constraint): Likewise.

Index: trunk/gcc/tree-ssa-structalias.c
===================================================================
*** trunk.orig/gcc/tree-ssa-structalias.c	2008-07-01 17:25:27.000000000 +0200
--- trunk/gcc/tree-ssa-structalias.c	2008-07-01 17:26:03.000000000 +0200
*************** add_implicit_graph_edge (constraint_grap
*** 904,914 ****
    if (!graph->implicit_preds[to])
      graph->implicit_preds[to] = BITMAP_ALLOC (&predbitmap_obstack);

!   if (!bitmap_bit_p (graph->implicit_preds[to], from))
!     {
!       stats.num_implicit_edges++;
!       bitmap_set_bit (graph->implicit_preds[to], from);
!     }
  }

  /* Add a predecessor graph edge to GRAPH, going from TO to FROM if
--- 904,911 ----
    if (!graph->implicit_preds[to])
      graph->implicit_preds[to] = BITMAP_ALLOC (&predbitmap_obstack);

!   if (bitmap_set_bit (graph->implicit_preds[to], from))
!     stats.num_implicit_edges++;
  }

  /* Add a predecessor graph edge to GRAPH, going from TO to FROM if
*************** add_pred_graph_edge (constraint_graph_t
*** 921,928 ****
  {
    if (!graph->preds[to])
      graph->preds[to] = BITMAP_ALLOC (&predbitmap_obstack);
!   if (!bitmap_bit_p (graph->preds[to], from))
!     bitmap_set_bit (graph->preds[to], from);
  }

  /* Add a graph edge to GRAPH, going from FROM to TO if
--- 918,924 ----
  {
    if (!graph->preds[to])
      graph->preds[to] = BITMAP_ALLOC (&predbitmap_obstack);
!   bitmap_set_bit (graph->preds[to], from);
  }

  /* Add a graph edge to GRAPH, going from FROM to TO if
*************** add_graph_edge (constraint_graph_t graph
*** 943,954 ****

        if (!graph->succs[from])
  	graph->succs[from] = BITMAP_ALLOC (&pta_obstack);
!       if (!bitmap_bit_p (graph->succs[from], to))
  	{
  	  r = true;
  	  if (to < FIRST_REF_NODE && from < FIRST_REF_NODE)
  	    stats.num_edges++;
- 	  bitmap_set_bit (graph->succs[from], to);
  	}
        return r;
      }
--- 939,949 ----

        if (!graph->succs[from])
  	graph->succs[from] = BITMAP_ALLOC (&pta_obstack);
!       if (bitmap_set_bit (graph->succs[from], to))
  	{
  	  r = true;
  	  if (to < FIRST_REF_NODE && from < FIRST_REF_NODE)
  	    stats.num_edges++;
  	}
        return r;
      }
*************** do_sd_constraint (constraint_graph_t gra
*** 1407,1415 ****

   if (bitmap_bit_p (delta, anything_id))
     {
!      flag = !bitmap_bit_p (sol, anything_id);
!      if (flag)
!        bitmap_set_bit (sol, anything_id);
       goto done;
     }

--- 1402,1408 ----

   if (bitmap_bit_p (delta, anything_id))
     {
!      flag |= bitmap_set_bit (sol, anything_id);
       goto done;
     }

*************** do_sd_constraint (constraint_graph_t gra
*** 1436,1448 ****
  	  /* Merging the solution from ESCAPED needlessly increases
  	     the set.  Use ESCAPED as representative instead.
  	     Same for CALLUSED.  */
! 	  else if ((get_varinfo (t)->id == escaped_id
! 		    || get_varinfo (t)->id == callused_id)
! 		   && !bitmap_bit_p (sol, get_varinfo (t)->id))
! 	    {
! 	      bitmap_set_bit (sol, get_varinfo (t)->id);
! 	      flag = true;
! 	    }
  	  else if (add_graph_edge (graph, lhs, t))
  	    flag |= bitmap_ior_into (sol, get_varinfo (t)->solution);
  	}
--- 1429,1437 ----
  	  /* Merging the solution from ESCAPED needlessly increases
  	     the set.  Use ESCAPED as representative instead.
  	     Same for CALLUSED.  */
! 	  else if (get_varinfo (t)->id == escaped_id
! 		   || get_varinfo (t)->id == callused_id)
! 	    flag |= bitmap_set_bit (sol, get_varinfo (t)->id);
  	  else if (add_graph_edge (graph, lhs, t))
  	    flag |= bitmap_ior_into (sol, get_varinfo (t)->solution);
  	}
*************** do_ds_constraint (constraint_t c, bitmap
*** 1486,1499 ****
  	   continue;
  	 t = find (v->id);

! 	 if (!bitmap_bit_p (get_varinfo (t)->solution, anything_id))
  	   {
! 	     bitmap_set_bit (get_varinfo (t)->solution, anything_id);
! 	     if (!TEST_BIT (changed, t))
! 	       {
! 		 SET_BIT (changed, t);
! 		 changed_count++;
! 	       }
  	   }
         }
       return;
--- 1475,1485 ----
  	   continue;
  	 t = find (v->id);

! 	 if (bitmap_set_bit (get_varinfo (t)->solution, anything_id)
! 	     && !TEST_BIT (changed, t))
  	   {
! 	     SET_BIT (changed, t);
! 	     changed_count++;
  	   }
         }
       return;
Index: trunk/gcc/bitmap.c
===================================================================
*** trunk.orig/gcc/bitmap.c	2008-07-01 17:25:27.000000000 +0200
--- trunk/gcc/bitmap.c	2008-07-01 17:25:39.000000000 +0200
*************** bitmap_find_bit (bitmap head, unsigned i
*** 595,603 ****
    return element;
  }

! /* Clear a single bit in a bitmap. */

! void
  bitmap_clear_bit (bitmap head, int bit)
  {
    bitmap_element *const ptr = bitmap_find_bit (head, bit);
--- 595,603 ----
    return element;
  }

! /* Clear a single bit in a bitmap. Return true if the bit changed. */

! bool
  bitmap_clear_bit (bitmap head, int bit)
  {
    bitmap_element *const ptr = bitmap_find_bit (head, bit);
*************** bitmap_clear_bit (bitmap head, int bit)
*** 606,622 ****
      {
        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 (bitmap_element_zerop (ptr))
  	bitmap_element_free (head, ptr);
      }
  }

! /* Set a single bit in a bitmap. */

! void
  bitmap_set_bit (bitmap head, int bit)
  {
    bitmap_element *ptr = bitmap_find_bit (head, bit);
--- 606,629 ----
      {
        unsigned bit_num  = bit % BITMAP_WORD_BITS;
        unsigned word_num = bit / BITMAP_WORD_BITS % BITMAP_ELEMENT_WORDS;
!       BITMAP_WORD bit_val = ((BITMAP_WORD) 1) << bit_num;
!       bool res = (ptr->bits[word_num] & bit_val) != 0;
!       if (res)
! 	ptr->bits[word_num] &= ~bit_val;

/* If we cleared the entire word, free up the element. */
if (bitmap_element_zerop (ptr))
bitmap_element_free (head, ptr);
+ + return res;
}
+ + return false;
}


! /* Set a single bit in a bitmap. Return true if the bit changed. */

! bool
  bitmap_set_bit (bitmap head, int bit)
  {
    bitmap_element *ptr = bitmap_find_bit (head, bit);
*************** bitmap_set_bit (bitmap head, int bit)
*** 630,638 ****
        ptr->indx = bit / BITMAP_ELEMENT_ALL_BITS;
        ptr->bits[word_num] = bit_val;
        bitmap_element_link (head, ptr);
      }
    else
!     ptr->bits[word_num] |= bit_val;
  }

  /* Return whether a bit is set within a bitmap.  */
--- 637,651 ----
        ptr->indx = bit / BITMAP_ELEMENT_ALL_BITS;
        ptr->bits[word_num] = bit_val;
        bitmap_element_link (head, ptr);
+       return true;
      }
    else
!     {
!       bool res = (ptr->bits[word_num] & bit_val) == 0;
!       if (res)
! 	ptr->bits[word_num] |= bit_val;
!       return res;
!     }
  }

  /* Return whether a bit is set within a bitmap.  */
Index: trunk/gcc/bitmap.h
===================================================================
*** trunk.orig/gcc/bitmap.h	2008-07-01 17:25:27.000000000 +0200
--- trunk/gcc/bitmap.h	2008-07-01 17:25:39.000000000 +0200
*************** extern bool bitmap_ior_and_compl (bitmap
*** 136,146 ****
  /* A |= (B & ~C).  Return true if A changes.  */
  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);

! /* Set a single register in a register set.  */
! extern void bitmap_set_bit (bitmap, int);

  /* Return true if a register is set in a register set.  */
  extern int bitmap_bit_p (bitmap, int);
--- 136,146 ----
  /* A |= (B & ~C).  Return true if A changes.  */
  extern bool bitmap_ior_and_compl_into (bitmap DST, const_bitmap B, const_bitmap C);

! /* Clear a single bit in a bitmap.  Return true if the bit changed.  */
! extern bool bitmap_clear_bit (bitmap, int);

! /* Set a single bit in a bitmap.  Return true if the bit changed.  */
! extern bool bitmap_set_bit (bitmap, int);

  /* Return true if a register is set in a register set.  */
  extern int bitmap_bit_p (bitmap, int);


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