public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch] Make bitmap_head smaller again
@ 2012-12-12 17:43 Steven Bosscher
  2012-12-13  9:38 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Steven Bosscher @ 2012-12-12 17:43 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 416 bytes --]

Hello,

This patch fixes a regression in the size of bitmap_head that resulted
from the removal of all the #ifdef GATHER_STATISTICS tests.

Instead of a pointer to a descriptor, this patch gives each bitmap an
integer that is the index of the bitmap_descriptor.

Bootstrapped&tested on powerpc64-unknown-linux-gnu, and built on the
same platform with memory statistics gathering enabled.
OK for trunk?

Ciao!
Steven

[-- Attachment #2: smaller_bitmap_head.diff --]
[-- Type: application/octet-stream, Size: 7578 bytes --]

	* bitmap.c (struct bitmap_descriptor): Remove forward declaration.
	(struct bitmap_head_def): Remove desc pointer.  Add descriptor_id
	field.  Reorder fields for pointer alignment.
	* bitmap.c: Include vec.h.
	(struct bitmap_descriptor): Rename to bitmap_descriptor_d.
	(bitmap_descriptor): New typedef, pointer to bitmap_descriptor_d.
	Update all struct bitmap_descriptor references.
	(next_bitmap_desc_id): New running index for bitmap desciptors.
	(bitmap_descriptors): Vec of all bitmap descriptors by descriptor id.
	(hash_descriptor, eq_descriptor): Update for struct bitmap_descriptor
	change.
	(bitmap_descriptor): Rename function to get_bitmap_descriptor.
	Stuff newly allocated bitmap descriptor into bitmap_descriptors.
	Set the bitmap descriptor id.
	(bitmap_register): Lookup bitmap desciptor and store its ID in
	the passed bitmap.
	(register_overhead): Likewise.
	(bitmap_find_bit): Lookup descriptor by id in bitmap_descriptors.
	(print_statistics): Update for struct bitmap_descriptor change.

Index: bitmap.h
===================================================================
--- bitmap.h	(revision 194444)
+++ bitmap.h	(working copy)
@@ -174,20 +174,18 @@ typedef struct GTY((chain_next ("%h.next"), chain_
   BITMAP_WORD bits[BITMAP_ELEMENT_WORDS]; /* Bits that are set.  */
 } bitmap_element;
 
-struct bitmap_descriptor;
-/* Head of bitmap linked list.  gengtype ignores ifdefs, but for
-   statistics we need to add a bitmap descriptor pointer.  As it is
-   not collected, we can just GTY((skip(""))) it.  Likewise current
-   points to something already pointed to by the chain started by first,
-   no need to walk it again.  */
+/* Head of bitmap linked list.  The 'current' member points to something
+   already pointed to by the chain started by first, so GTY((skip)) it.  */
 
 typedef struct GTY(()) bitmap_head_def {
+  unsigned int indx;			/* Index of last element looked at.  */
+  unsigned int descriptor_id;		/* Unique identifier for the allocation
+					   site of this bitmap, for detailed
+					   statistics gathering.  */
   bitmap_element *first;		/* First element in linked list.  */
   bitmap_element * GTY((skip(""))) current; /* Last element looked at.  */
-  unsigned int indx;			/* Index of last element looked at.  */
   bitmap_obstack *obstack;		/* Obstack to allocate elements from.
 					   If NULL, then use GGC allocation.  */
-  struct bitmap_descriptor GTY((skip(""))) *desc;
 } bitmap_head;
 
 /* Global data */
Index: bitmap.c
===================================================================
--- bitmap.c	(revision 194444)
+++ bitmap.c	(working copy)
@@ -24,10 +24,12 @@ along with GCC; see the file COPYING3.  If not see
 #include "ggc.h"
 #include "bitmap.h"
 #include "hashtab.h"
+#include "vec.h"
 
-/* Store information about each particular bitmap.  */
-struct bitmap_descriptor
+/* Store information about each particular bitmap, per allocation site.  */
+struct bitmap_descriptor_d
 {
+  int id;
   const char *function;
   const char *file;
   int line;
@@ -39,6 +41,15 @@ along with GCC; see the file COPYING3.  If not see
   int search_iter;
 };
 
+typedef struct bitmap_descriptor_d *bitmap_descriptor;
+typedef const struct bitmap_descriptor_d *const_bitmap_descriptor;
+
+/* Next available unique id number for bitmap desciptors.  */
+static int next_bitmap_desc_id = 0;
+
+/* Vector mapping descriptor ids to descriptors.  */
+static vec<bitmap_descriptor> bitmap_descriptors;
+
 /* Hashtable mapping bitmap names to descriptors.  */
 static htab_t bitmap_desc_hash;
 
@@ -46,8 +57,7 @@ static htab_t bitmap_desc_hash;
 static hashval_t
 hash_descriptor (const void *p)
 {
-  const struct bitmap_descriptor *const d =
-    (const struct bitmap_descriptor *) p;
+  const_bitmap_descriptor d = (const_bitmap_descriptor) p;
   return htab_hash_pointer (d->file) + d->line;
 }
 struct loc
@@ -59,17 +69,16 @@ struct loc
 static int
 eq_descriptor (const void *p1, const void *p2)
 {
-  const struct bitmap_descriptor *const d =
-    (const struct bitmap_descriptor *) p1;
+  const_bitmap_descriptor d = (const_bitmap_descriptor) p1;
   const struct loc *const l = (const struct loc *) p2;
   return d->file == l->file && d->function == l->function && d->line == l->line;
 }
 
 /* For given file and line, return descriptor, create new if needed.  */
-static struct bitmap_descriptor *
-bitmap_descriptor (const char *file, int line, const char *function)
+static bitmap_descriptor
+get_bitmap_descriptor (const char *file, int line, const char *function)
 {
-  struct bitmap_descriptor **slot;
+  bitmap_descriptor *slot;
   struct loc loc;
 
   loc.file = file;
@@ -79,13 +88,16 @@ eq_descriptor (const void *p1, const void *p2)
   if (!bitmap_desc_hash)
     bitmap_desc_hash = htab_create (10, hash_descriptor, eq_descriptor, NULL);
 
-  slot = (struct bitmap_descriptor **)
+  slot = (bitmap_descriptor *)
     htab_find_slot_with_hash (bitmap_desc_hash, &loc,
 			      htab_hash_pointer (file) + line,
 			      INSERT);
   if (*slot)
     return *slot;
-  *slot = XCNEW (struct bitmap_descriptor);
+
+  *slot = XCNEW (struct bitmap_descriptor_d);
+  bitmap_descriptors.safe_push (*slot);
+  (*slot)->id = next_bitmap_desc_id++;
   (*slot)->file = file;
   (*slot)->function = function;
   (*slot)->line = line;
@@ -96,20 +108,22 @@ eq_descriptor (const void *p1, const void *p2)
 void
 bitmap_register (bitmap b MEM_STAT_DECL)
 {
-  b->desc = bitmap_descriptor (ALONE_FINAL_PASS_MEM_STAT);
-  b->desc->created++;
+  bitmap_descriptor desc = get_bitmap_descriptor (ALONE_FINAL_PASS_MEM_STAT);
+  desc->created++;
+  b->descriptor_id = desc->id;
 }
 
 /* Account the overhead.  */
 static void
 register_overhead (bitmap b, int amount)
 {
-  b->desc->current += amount;
+  bitmap_descriptor desc = bitmap_descriptors[b->descriptor_id];
+  desc->current += amount;
   if (amount > 0)
-    b->desc->allocated += amount;
-  gcc_assert (b->desc->current >= 0);
-  if (b->desc->peak < b->desc->current)
-    b->desc->peak = b->desc->current;
+    desc->allocated += amount;
+  gcc_assert (desc->current >= 0);
+  if (desc->peak < desc->current)
+    desc->peak = desc->current;
 }
 
 /* Global data */
@@ -556,7 +570,7 @@ bitmap_find_bit (bitmap head, unsigned int bit)
     return head->current;
 
   if (GATHER_STATISTICS)
-    head->desc->nsearches++;
+    bitmap_descriptors[head->descriptor_id]->nsearches++;
 
   if (head->indx < indx)
     /* INDX is beyond head->indx.  Search from head->current
@@ -566,7 +580,7 @@ bitmap_find_bit (bitmap head, unsigned int bit)
 	 element = element->next)
       {
 	if (GATHER_STATISTICS)
-	  head->desc->search_iter++;
+	  bitmap_descriptors[head->descriptor_id]->search_iter++;
       }
 
   else if (head->indx / 2 < indx)
@@ -577,7 +591,7 @@ bitmap_find_bit (bitmap head, unsigned int bit)
 	 element = element->prev)
       {
 	if (GATHER_STATISTICS)
-	  head->desc->search_iter++;
+	  bitmap_descriptors[head->descriptor_id]->search_iter++;
       }
 
   else
@@ -588,7 +602,7 @@ bitmap_find_bit (bitmap head, unsigned int bit)
 	 element = element->next)
       if (GATHER_STATISTICS)
 	{
-	  head->desc->search_iter++;
+	  bitmap_descriptors[head->descriptor_id]->search_iter++;
 	}
 
   /* `element' is the nearest to the one we want.  If it's not the one we
@@ -2127,7 +2141,7 @@ struct output_info
 static int
 print_statistics (void **slot, void *b)
 {
-  struct bitmap_descriptor *d = (struct bitmap_descriptor *) *slot;
+  bitmap_descriptor d = (bitmap_descriptor) *slot;
   struct output_info *i = (struct output_info *) b;
   char s[4096];
 

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [patch] Make bitmap_head smaller again
  2012-12-12 17:43 [patch] Make bitmap_head smaller again Steven Bosscher
@ 2012-12-13  9:38 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2012-12-13  9:38 UTC (permalink / raw)
  To: Steven Bosscher; +Cc: GCC Patches

On Wed, Dec 12, 2012 at 6:43 PM, Steven Bosscher <stevenb.gcc@gmail.com> wrote:
> Hello,
>
> This patch fixes a regression in the size of bitmap_head that resulted
> from the removal of all the #ifdef GATHER_STATISTICS tests.
>
> Instead of a pointer to a descriptor, this patch gives each bitmap an
> integer that is the index of the bitmap_descriptor.
>
> Bootstrapped&tested on powerpc64-unknown-linux-gnu, and built on the
> same platform with memory statistics gathering enabled.
> OK for trunk?

Ok.

Thanks,
Richard.

> Ciao!
> Steven

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-12-13  9:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-12 17:43 [patch] Make bitmap_head smaller again Steven Bosscher
2012-12-13  9:38 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).