diff mbox

[03/13] store the bitmap_head within the auto_bitmap

Message ID 20170509205242.2237-4-tbsaunde+gcc@tbsaunde.org
State New
Headers show

Commit Message

tbsaunde+gcc@tbsaunde.org May 9, 2017, 8:52 p.m. UTC
From: Trevor Saunders <tbsaunde+gcc@tbsaunde.org>

This gets rid of one allocation per bitmap.  Often the bitmap_head is
now on the stack, when it isn't its part of some other struct on the
heap instead of being refered to by that struct.  On 64 bit platforms
this will increase the size of such structs by 24 bytes, but its an over
all win since we don't need an 8 byte pointer pointing at the
bitmap_head.  Given that the auto_bitmap owns the bitmap_head anyway we
know there would never be a place where two auto_bitmaps would refer to
the same bitmap_head object.

gcc/ChangeLog:

2017-05-07  Trevor Saunders  <tbsaunde+gcc@tbsaunde.org>

	* bitmap.h (class auto_bitmap): Change type of m_bits to
bitmap_head, and adjust ctor / dtor and member operators.
---
 gcc/bitmap.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Richard Biener May 10, 2017, 8:15 a.m. UTC | #1
On Tue, May 9, 2017 at 10:52 PM,  <tbsaunde+gcc@tbsaunde.org> wrote:
> From: Trevor Saunders <tbsaunde+gcc@tbsaunde.org>
>
> This gets rid of one allocation per bitmap.  Often the bitmap_head is
> now on the stack, when it isn't its part of some other struct on the
> heap instead of being refered to by that struct.  On 64 bit platforms
> this will increase the size of such structs by 24 bytes, but its an over
> all win since we don't need an 8 byte pointer pointing at the
> bitmap_head.  Given that the auto_bitmap owns the bitmap_head anyway we
> know there would never be a place where two auto_bitmaps would refer to
> the same bitmap_head object.

Ok.

Richard.

> gcc/ChangeLog:
>
> 2017-05-07  Trevor Saunders  <tbsaunde+gcc@tbsaunde.org>
>
>         * bitmap.h (class auto_bitmap): Change type of m_bits to
> bitmap_head, and adjust ctor / dtor and member operators.
> ---
>  gcc/bitmap.h | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/gcc/bitmap.h b/gcc/bitmap.h
> index 7508239cff9..49aec001cb0 100644
> --- a/gcc/bitmap.h
> +++ b/gcc/bitmap.h
> @@ -823,10 +823,10 @@ bmp_iter_and_compl (bitmap_iterator *bi, unsigned *bit_no)
>  class auto_bitmap
>  {
>   public:
> -  auto_bitmap () { bits = BITMAP_ALLOC (NULL); }
> -  ~auto_bitmap () { BITMAP_FREE (bits); }
> +  auto_bitmap () { bitmap_initialize (&m_bits, &bitmap_default_obstack); }
> +  ~auto_bitmap () { bitmap_clear (&m_bits); }
>    // Allow calling bitmap functions on our bitmap.
> -  operator bitmap () { return bits; }
> +  operator bitmap () { return &m_bits; }
>
>   private:
>    // Prevent making a copy that references our bitmap.
> @@ -837,7 +837,7 @@ class auto_bitmap
>    auto_bitmap &operator = (auto_bitmap &&);
>  #endif
>
> -  bitmap bits;
> +  bitmap_head m_bits;
>  };
>
>  #endif /* GCC_BITMAP_H */
> --
> 2.11.0
>
diff mbox

Patch

diff --git a/gcc/bitmap.h b/gcc/bitmap.h
index 7508239cff9..49aec001cb0 100644
--- a/gcc/bitmap.h
+++ b/gcc/bitmap.h
@@ -823,10 +823,10 @@  bmp_iter_and_compl (bitmap_iterator *bi, unsigned *bit_no)
 class auto_bitmap
 {
  public:
-  auto_bitmap () { bits = BITMAP_ALLOC (NULL); }
-  ~auto_bitmap () { BITMAP_FREE (bits); }
+  auto_bitmap () { bitmap_initialize (&m_bits, &bitmap_default_obstack); }
+  ~auto_bitmap () { bitmap_clear (&m_bits); }
   // Allow calling bitmap functions on our bitmap.
-  operator bitmap () { return bits; }
+  operator bitmap () { return &m_bits; }
 
  private:
   // Prevent making a copy that references our bitmap.
@@ -837,7 +837,7 @@  class auto_bitmap
   auto_bitmap &operator = (auto_bitmap &&);
 #endif
 
-  bitmap bits;
+  bitmap_head m_bits;
 };
 
 #endif /* GCC_BITMAP_H */