From b60db1bae78b40ecca246f787e5661d1de779f3a Mon Sep 17 00:00:00 2001
From: Kenneth Zadeck <zadeck@naturalbridge.com>
Date: Mon, 21 Apr 2008 20:15:38 +0000
Subject: [PATCH] sbitmap.c (sbitmap_range_empty_p): New function.

2008-04-24  Kenneth Zadeck <zadeck@naturalbridge.com>
	* sbitmap.c (sbitmap_range_empty_p): New function.
	* sbitmap.h (sbitmap_range_empty_p): New function.
	* bitmap.h: Now includes obstack.h.

From-SVN: r134529
---
 gcc/ChangeLog |  6 ++++++
 gcc/bitmap.h  |  1 +
 gcc/sbitmap.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 gcc/sbitmap.h |  3 ++-
 4 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index ed1c788617f9..8b6363a613fb 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2008-04-24  Kenneth Zadeck <zadeck@naturalbridge.com>
+	* sbitmap.c (sbitmap_range_empty_p): New function.
+	* sbitmap.h (sbitmap_range_empty_p): New function.
+	* bitmap.h: Now includes obstack.h.  
+
+
 2008-04-24  Richard Sandiford  <rsandifo@nildram.co.uk>
 	    Kenneth Zadeck <zadeck@naturalbridge.com>
 
diff --git a/gcc/bitmap.h b/gcc/bitmap.h
index 0b6ed731922d..2a3b0b4baf8c 100644
--- a/gcc/bitmap.h
+++ b/gcc/bitmap.h
@@ -22,6 +22,7 @@ along with GCC; see the file COPYING3.  If not see
 #define GCC_BITMAP_H
 #include "hashtab.h"
 #include "statistics.h"
+#include "obstack.h"
 
 /* Fundamental storage type for bitmap.  */
 
diff --git a/gcc/sbitmap.c b/gcc/sbitmap.c
index d8b8d6c1ff50..cab4ec0e0ed4 100644
--- a/gcc/sbitmap.c
+++ b/gcc/sbitmap.c
@@ -1,5 +1,5 @@
 /* Simple bitmaps.
-   Copyright (C) 1999, 2000, 2002, 2003, 2004, 2006, 2007
+   Copyright (C) 1999, 2000, 2002, 2003, 2004, 2006, 2007, 2008
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -273,6 +273,57 @@ sbitmap_empty_p (const_sbitmap bmap)
   return true;
 }
 
+/* Return false if any of the N bits are set in MAP starting at
+   START.  */
+
+bool 
+sbitmap_range_empty_p (const_sbitmap bmap, unsigned int start, unsigned int n)
+{
+  unsigned int i = start / SBITMAP_ELT_BITS;
+  SBITMAP_ELT_TYPE elm;
+  unsigned int shift = start % SBITMAP_ELT_BITS;
+
+  gcc_assert (bmap->n_bits >= start + n);
+
+  elm = bmap->elms[i];
+  elm = elm >> shift;
+
+  if (shift + n <= SBITMAP_ELT_BITS)
+    {
+      /* The bits are totally contained in a single element.  */
+      if (shift + n < SBITMAP_ELT_BITS)
+        elm &= ((1 << n) - 1);
+      return (elm == 0);
+    }
+
+  if (elm) 
+    return false;
+
+  n -= SBITMAP_ELT_BITS - shift;
+  i++;
+
+  /* Deal with full elts.  */
+  while (n >= SBITMAP_ELT_BITS)
+    {
+      if (bmap->elms[i])
+	return false;
+      i++;
+      n -= SBITMAP_ELT_BITS;
+    }
+
+  /* The leftover bits.  */
+  if (n)
+    {
+      elm = bmap->elms[i];
+      elm &= ((1 << n) - 1);
+      return (elm == 0);
+    }  
+
+  return true;
+}
+
+
+
 /* Zero all elements in a bitmap.  */
 
 void
diff --git a/gcc/sbitmap.h b/gcc/sbitmap.h
index 3736341e2511..7e2bc7076777 100644
--- a/gcc/sbitmap.h
+++ b/gcc/sbitmap.h
@@ -1,5 +1,5 @@
 /* Simple bitmaps.
-   Copyright (C) 1999, 2000, 2002, 2003, 2004, 2006, 2007 
+   Copyright (C) 1999, 2000, 2002, 2003, 2004, 2006, 2007, 2008
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -219,6 +219,7 @@ extern void sbitmap_copy (sbitmap, const_sbitmap);
 extern void sbitmap_copy_n (sbitmap, const_sbitmap, unsigned int);
 extern int sbitmap_equal (const_sbitmap, const_sbitmap);
 extern bool sbitmap_empty_p (const_sbitmap);
+extern bool sbitmap_range_empty_p (const_sbitmap, unsigned int, unsigned int);
 extern void sbitmap_zero (sbitmap);
 extern void sbitmap_ones (sbitmap);
 extern void sbitmap_vector_zero (sbitmap *, unsigned int);
-- 
GitLab