Commit 7664eeb7 by Martin Liska Committed by Martin Liska

Fix bitmap registration of overheads.

2019-05-07  Martin Liska  <mliska@suse.cz>

	* bitmap.c (bitmap_register): Come up with
	alloc_descriptor_max_uid and assign it for
	a new bitmap.
	(register_overhead): Use get_descriptor as
	a descriptor.
	(release_overhead): New.
	(bitmap_elem_to_freelist): Call it.
	(bitmap_elt_clear_from): Likewise.
	(bitmap_obstack_free): Likewise.
	(bitmap_move): Sensitively release memory.
	* bitmap.h (struct GTY): Add alloc_descriptor and padding.
	(bitmap_initialize): Initialize alloc_descriptor to zero.
	* tree-ssa-pre.c (do_hoist_insertion): Use bitmap_move.

From-SVN: r270942
parent 9f708a84
2019-05-07 Martin Liska <mliska@suse.cz>
* bitmap.c (bitmap_register): Come up with
alloc_descriptor_max_uid and assign it for
a new bitmap.
(register_overhead): Use get_descriptor as
a descriptor.
(release_overhead): New.
(bitmap_elem_to_freelist): Call it.
(bitmap_elt_clear_from): Likewise.
(bitmap_obstack_free): Likewise.
(bitmap_move): Sensitively release memory.
* bitmap.h (struct GTY): Add alloc_descriptor and padding.
(bitmap_initialize): Initialize alloc_descriptor to zero.
* tree-ssa-pre.c (do_hoist_insertion): Use bitmap_move.
2019-05-07 Richard Biener <rguenther@suse.de> 2019-05-07 Richard Biener <rguenther@suse.de>
* tree-vect-slp.c (vect_build_slp_tree_2): Bump size whenever * tree-vect-slp.c (vect_build_slp_tree_2): Bump size whenever
......
...@@ -36,18 +36,33 @@ static bitmap_element *bitmap_tree_listify_from (bitmap, bitmap_element *); ...@@ -36,18 +36,33 @@ static bitmap_element *bitmap_tree_listify_from (bitmap, bitmap_element *);
void void
bitmap_register (bitmap b MEM_STAT_DECL) bitmap_register (bitmap b MEM_STAT_DECL)
{ {
bitmap_mem_desc.register_descriptor (b, BITMAP_ORIGIN, false static unsigned alloc_descriptor_max_uid = 1;
FINAL_PASS_MEM_STAT); gcc_assert (b->alloc_descriptor == 0);
b->alloc_descriptor = alloc_descriptor_max_uid++;
bitmap_mem_desc.register_descriptor (b->get_descriptor (), BITMAP_ORIGIN,
false FINAL_PASS_MEM_STAT);
} }
/* Account the overhead. */ /* Account the overhead. */
static void static void
register_overhead (bitmap b, size_t amount) register_overhead (bitmap b, size_t amount)
{ {
if (bitmap_mem_desc.contains_descriptor_for_instance (b)) unsigned *d = b->get_descriptor ();
bitmap_mem_desc.register_instance_overhead (amount, b); if (bitmap_mem_desc.contains_descriptor_for_instance (d))
bitmap_mem_desc.register_instance_overhead (amount, d);
}
/* Release the overhead. */
static void
release_overhead (bitmap b, size_t amount, bool remove_from_map)
{
unsigned *d = b->get_descriptor ();
if (bitmap_mem_desc.contains_descriptor_for_instance (d))
bitmap_mem_desc.release_instance_overhead (d, amount, remove_from_map);
} }
/* Global data */ /* Global data */
bitmap_element bitmap_zero_bits; /* An element of all zero bits. */ bitmap_element bitmap_zero_bits; /* An element of all zero bits. */
bitmap_obstack bitmap_default_obstack; /* The default bitmap obstack. */ bitmap_obstack bitmap_default_obstack; /* The default bitmap obstack. */
...@@ -65,7 +80,7 @@ bitmap_elem_to_freelist (bitmap head, bitmap_element *elt) ...@@ -65,7 +80,7 @@ bitmap_elem_to_freelist (bitmap head, bitmap_element *elt)
bitmap_obstack *bit_obstack = head->obstack; bitmap_obstack *bit_obstack = head->obstack;
if (GATHER_STATISTICS) if (GATHER_STATISTICS)
register_overhead (head, -((int)sizeof (bitmap_element))); release_overhead (head, sizeof (bitmap_element), false);
elt->next = NULL; elt->next = NULL;
elt->indx = -1; elt->indx = -1;
...@@ -153,7 +168,7 @@ bitmap_elt_clear_from (bitmap head, bitmap_element *elt) ...@@ -153,7 +168,7 @@ bitmap_elt_clear_from (bitmap head, bitmap_element *elt)
int n = 0; int n = 0;
for (prev = elt; prev; prev = prev->next) for (prev = elt; prev; prev = prev->next)
n++; n++;
register_overhead (head, -sizeof (bitmap_element) * n); release_overhead (head, sizeof (bitmap_element) * n, false);
} }
prev = elt->prev; prev = elt->prev;
...@@ -798,7 +813,7 @@ bitmap_obstack_free (bitmap map) ...@@ -798,7 +813,7 @@ bitmap_obstack_free (bitmap map)
map->first = (bitmap_element *) map->obstack->heads; map->first = (bitmap_element *) map->obstack->heads;
if (GATHER_STATISTICS) if (GATHER_STATISTICS)
register_overhead (map, -((int)sizeof (bitmap_head))); release_overhead (map, sizeof (bitmap_head), true);
map->obstack->heads = map; map->obstack->heads = map;
} }
...@@ -872,16 +887,18 @@ bitmap_move (bitmap to, bitmap from) ...@@ -872,16 +887,18 @@ bitmap_move (bitmap to, bitmap from)
bitmap_clear (to); bitmap_clear (to);
*to = *from; size_t sz = 0;
if (GATHER_STATISTICS) if (GATHER_STATISTICS)
{ {
size_t sz = 0;
for (bitmap_element *e = to->first; e; e = e->next) for (bitmap_element *e = to->first; e; e = e->next)
sz += sizeof (bitmap_element); sz += sizeof (bitmap_element);
register_overhead (to, sz); register_overhead (to, sz);
register_overhead (from, -sz);
} }
*to = *from;
if (GATHER_STATISTICS)
release_overhead (from, sz, false);
} }
/* Clear a single bit in a bitmap. Return true if the bit changed. */ /* Clear a single bit in a bitmap. Return true if the bit changed. */
......
...@@ -325,14 +325,18 @@ struct GTY(()) bitmap_head { ...@@ -325,14 +325,18 @@ struct GTY(()) bitmap_head {
static bitmap_obstack crashme; static bitmap_obstack crashme;
/* Poison obstack to not make it not a valid initialized GC bitmap. */ /* Poison obstack to not make it not a valid initialized GC bitmap. */
CONSTEXPR bitmap_head() CONSTEXPR bitmap_head()
: indx(0), tree_form(false), first(NULL), current(NULL), : indx (0), tree_form (false), padding (0), alloc_descriptor (0), first (NULL),
obstack (&crashme) current (NULL), obstack (&crashme)
{} {}
/* Index of last element looked at. */ /* Index of last element looked at. */
unsigned int indx; unsigned int indx;
/* False if the bitmap is in list form; true if the bitmap is in tree form. /* False if the bitmap is in list form; true if the bitmap is in tree form.
Bitmap iterators only work on bitmaps in list form. */ Bitmap iterators only work on bitmaps in list form. */
bool tree_form; unsigned tree_form: 1;
/* Next integer is shifted, so padding is needed. */
unsigned padding: 2;
/* Bitmap UID used for memory allocation statistics. */
unsigned alloc_descriptor: 29;
/* In list form, the first element in the linked list; /* In list form, the first element in the linked list;
in tree form, the root of the tree. */ in tree form, the root of the tree. */
bitmap_element *first; bitmap_element *first;
...@@ -340,7 +344,17 @@ struct GTY(()) bitmap_head { ...@@ -340,7 +344,17 @@ struct GTY(()) bitmap_head {
bitmap_element * GTY((skip(""))) current; bitmap_element * GTY((skip(""))) current;
/* Obstack to allocate elements from. If NULL, then use GGC allocation. */ /* Obstack to allocate elements from. If NULL, then use GGC allocation. */
bitmap_obstack * GTY((skip(""))) obstack; bitmap_obstack * GTY((skip(""))) obstack;
/* Dump bitmap. */
void dump (); void dump ();
/* Get bitmap descriptor UID casted to an unsigned integer pointer.
Shift the descriptor because pointer_hash<Type>::hash is
doing >> 3 shift operation. */
unsigned *get_descriptor ()
{
return (unsigned *)(ptrdiff_t)(alloc_descriptor << 3);
}
}; };
/* Global data */ /* Global data */
...@@ -441,6 +455,8 @@ bitmap_initialize (bitmap head, bitmap_obstack *obstack CXX_MEM_STAT_INFO) ...@@ -441,6 +455,8 @@ bitmap_initialize (bitmap head, bitmap_obstack *obstack CXX_MEM_STAT_INFO)
{ {
head->first = head->current = NULL; head->first = head->current = NULL;
head->indx = head->tree_form = 0; head->indx = head->tree_form = 0;
head->padding = 0;
head->alloc_descriptor = 0;
head->obstack = obstack; head->obstack = obstack;
if (GATHER_STATISTICS) if (GATHER_STATISTICS)
bitmap_register (head PASS_MEM_STAT); bitmap_register (head PASS_MEM_STAT);
......
...@@ -3533,7 +3533,7 @@ do_hoist_insertion (basic_block block) ...@@ -3533,7 +3533,7 @@ do_hoist_insertion (basic_block block)
return false; return false;
/* Hack hoitable_set in-place so we can use sorted_array_from_bitmap_set. */ /* Hack hoitable_set in-place so we can use sorted_array_from_bitmap_set. */
hoistable_set.values = availout_in_some; bitmap_move (&hoistable_set.values, &availout_in_some);
hoistable_set.expressions = ANTIC_IN (block)->expressions; hoistable_set.expressions = ANTIC_IN (block)->expressions;
/* Now finally construct the topological-ordered expression set. */ /* Now finally construct the topological-ordered expression set. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment