aboutsummaryrefslogtreecommitdiff
path: root/gcc/bitmap.c
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2015-05-27 14:47:22 +0200
committerMartin Liska <marxin@gcc.gnu.org>2015-05-27 12:47:22 +0000
commit2d44c7dea7c8d2917eec28a5e08e8f405aad8c3e (patch)
tree4505b8171553fd7e780bb28532a4986cd72b6f4f /gcc/bitmap.c
parent151fbaac5c78c4e9b749fc9e916f78b0ba63b153 (diff)
downloadgcc-2d44c7dea7c8d2917eec28a5e08e8f405aad8c3e.zip
gcc-2d44c7dea7c8d2917eec28a5e08e8f405aad8c3e.tar.gz
gcc-2d44c7dea7c8d2917eec28a5e08e8f405aad8c3e.tar.bz2
New memory allocation statistics infrastructure.
* Makefile.in: Add additional dependencies related to memory report enhancement. * alloc-pool.c (allocate_pool_descriptor): Use new ctor. * bitmap.c (struct bitmap_descriptor_d): Remove. (struct loc): Likewise. (struct bitmap_desc_hasher): Likewise. (bitmap_desc_hasher::hash): Likewise. (bitmap_desc_hasher::equal): Likewise. (get_bitmap_descriptor): Likewise. (bitmap_register): User new memory descriptor API. (register_overhead): Likewise. (bitmap_find_bit): Register nsearches and search_iter statistics. (struct bitmap_output_info): Remove. (print_statistics): Likewise. (dump_bitmap_statistics): Use new memory descriptor. * bitmap.h (struct bitmap_usage): New class. * genmatch.c: Extend header file inclusion. * genpreds.c: Likewise. * ggc-common.c (struct ggc_usage): New class. (struct ggc_loc_desc_hasher): Remove. (ggc_loc_desc_hasher::hash): Likewise. (ggc_loc_desc_hasher::equal): Likewise. (struct ggc_ptr_hash_entry): Likewise. (struct ptr_hash_hasher): Likewise. (ptr_hash_hasher::hash): Likewise. (ptr_hash_hasher::equal): Likewise. (make_loc_descriptor): Likewise. (ggc_prune_ptr): Likewise. (dump_ggc_loc_statistics): Use new memory descriptor. (ggc_record_overhead): Likewise. (ggc_free_overhead): Likewise. (final_cmp_statistic): Remove. (cmp_statistic): Likewise. (ggc_add_statistics): Liekwise. (ggc_prune_overhead_list): Likewise. * hash-map-traits.h: New file. * hash-map.h (struct default_hashmap_traits): Move the traits to a separate header file. * hash-set.h: Pass memory statistics info to ctor. * hash-table.c (void dump_hash_table_loc_statistics): New function. * hash-table.h (hash_table::hash_table): Add new ctor arguments. (hash_table::~hash_table): Register memory release operation. (hash_table::alloc_entries): Handle memory allocation operation. (hash_table::expand): Likewise. * inchash.c (iterative_hash_hashval_t): Move implementation to header file. (iterative_hash_host_wide_int): Likewise. * inchash.h (class hash): Likewise. * mem-stats-traits.h: New file. * mem-stats.h: New file. (mem_location): Add new class. (mem_usage): Likewise. (mem_alloc_description): Likewise. * sese.c: Add new header file inclusision. * toplev.c (dump_memory_report): Add report for hash_table, hash_map and hash_set. * tree-sra.c: Add new header file inclusision. * vec.c (struct vec_descriptor): Remove. (hash_descriptor): Likewise. (struct vec_usage): Likewise. (struct ptr_hash_entry): Likewise. (hash_ptr): Likewise. (eq_ptr): Likewise. (vec_prefix::register_overhead): Use new memory descriptor API. (vec_prefix::release_overhead): Likewise. (add_statistics): Remove. (dump_vec_loc_statistics): Use new memory descriptor API. * vec.h (struct vec_prefix): Likewise. (va_heap::reserve): Likewise. (va_heap::release): Likewise. * emit-rtl.c (gen_raw_REG): Fix passing MEM_STAT. From-SVN: r223748
Diffstat (limited to 'gcc/bitmap.c')
-rw-r--r--gcc/bitmap.c178
1 files changed, 21 insertions, 157 deletions
diff --git a/gcc/bitmap.c b/gcc/bitmap.c
index 58f4432..5fc4654 100644
--- a/gcc/bitmap.c
+++ b/gcc/bitmap.c
@@ -25,112 +25,26 @@ along with GCC; see the file COPYING3. If not see
#include "bitmap.h"
#include "hash-table.h"
#include "vec.h"
+#include "inchash.h"
+#include "mem-stats.h"
+#include "hash-map.h"
-/* Store information about each particular bitmap, per allocation site. */
-struct bitmap_descriptor_d
-{
- int id;
- const char *function;
- const char *file;
- int line;
- int created;
- uint64_t allocated;
- uint64_t peak;
- uint64_t current;
- uint64_t nsearches;
- uint64_t 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 helpers. */
-
-struct loc
-{
- const char *file;
- const char *function;
- int line;
-};
-
-struct bitmap_desc_hasher : typed_noop_remove <bitmap_descriptor_d>
-{
- typedef bitmap_descriptor_d *value_type;
- typedef loc *compare_type;
- static inline hashval_t hash (const bitmap_descriptor_d *);
- static inline bool equal (const bitmap_descriptor_d *, const loc *);
-};
-
-inline hashval_t
-bitmap_desc_hasher::hash (const bitmap_descriptor_d *d)
-{
- return htab_hash_pointer (d->file) + d->line;
-}
-
-inline bool
-bitmap_desc_hasher::equal (const bitmap_descriptor_d *d, const loc *l)
-{
- return d->file == l->file && d->function == l->function && d->line == l->line;
-}
-
-/* Hashtable mapping bitmap names to descriptors. */
-static hash_table<bitmap_desc_hasher> *bitmap_desc_hash;
-
-/* For given file and line, return descriptor, create new if needed. */
-static bitmap_descriptor
-get_bitmap_descriptor (const char *file, int line, const char *function)
-{
- bitmap_descriptor_d **slot;
- struct loc loc;
-
- loc.file = file;
- loc.function = function;
- loc.line = line;
-
- if (!bitmap_desc_hash)
- bitmap_desc_hash = new hash_table<bitmap_desc_hasher> (10);
-
- slot
- = bitmap_desc_hash->find_slot_with_hash (&loc,
- htab_hash_pointer (file) + line,
- INSERT);
- if (*slot)
- return *slot;
-
- *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;
- return *slot;
-}
+/* Memory allocation statistics purpose instance. */
+mem_alloc_description<bitmap_usage> bitmap_mem_desc;
/* Register new bitmap. */
void
bitmap_register (bitmap b MEM_STAT_DECL)
{
- bitmap_descriptor desc = get_bitmap_descriptor (ALONE_FINAL_PASS_MEM_STAT);
- desc->created++;
- b->descriptor_id = desc->id;
+ bitmap_mem_desc.register_descriptor (b, BITMAP, false FINAL_PASS_MEM_STAT);
}
/* Account the overhead. */
static void
register_overhead (bitmap b, int amount)
{
- bitmap_descriptor desc = bitmap_descriptors[b->descriptor_id];
- desc->current += amount;
- if (amount > 0)
- desc->allocated += amount;
- if (desc->peak < desc->current)
- desc->peak = desc->current;
+ if (bitmap_mem_desc.contains_descriptor_for_instance (b))
+ bitmap_mem_desc.register_instance_overhead (amount, b);
}
/* Global data */
@@ -579,10 +493,14 @@ bitmap_find_bit (bitmap head, unsigned int bit)
&& head->first->next == NULL)
return NULL;
+ /* Usage can be NULL due to allocated bitmaps for which we do not
+ call initialize function. */
+ bitmap_usage *usage = bitmap_mem_desc.get_descriptor_for_instance (head);
+
/* This bitmap has more than one element, and we're going to look
through the elements list. Count that as a search. */
- if (GATHER_STATISTICS)
- bitmap_descriptors[head->descriptor_id]->nsearches++;
+ if (GATHER_STATISTICS && usage)
+ usage->m_nsearches++;
if (head->indx < indx)
/* INDX is beyond head->indx. Search from head->current
@@ -591,8 +509,8 @@ bitmap_find_bit (bitmap head, unsigned int bit)
element->next != 0 && element->indx < indx;
element = element->next)
{
- if (GATHER_STATISTICS)
- bitmap_descriptors[head->descriptor_id]->search_iter++;
+ if (GATHER_STATISTICS && usage)
+ usage->m_search_iter++;
}
else if (head->indx / 2 < indx)
@@ -602,8 +520,8 @@ bitmap_find_bit (bitmap head, unsigned int bit)
element->prev != 0 && element->indx > indx;
element = element->prev)
{
- if (GATHER_STATISTICS)
- bitmap_descriptors[head->descriptor_id]->search_iter++;
+ if (GATHER_STATISTICS && usage)
+ usage->m_search_iter++;
}
else
@@ -612,9 +530,9 @@ bitmap_find_bit (bitmap head, unsigned int bit)
for (element = head->first;
element->next != 0 && element->indx < indx;
element = element->next)
- if (GATHER_STATISTICS)
+ if (GATHER_STATISTICS && usage)
{
- bitmap_descriptors[head->descriptor_id]->search_iter++;
+ usage->m_search_iter++;
}
/* `element' is the nearest to the one we want. If it's not the one we
@@ -2157,68 +2075,14 @@ bitmap_print (FILE *file, const_bitmap head, const char *prefix,
fputs (suffix, file);
}
-
-/* Used to accumulate statistics about bitmap sizes. */
-struct bitmap_output_info
-{
- uint64_t size;
- uint64_t count;
-};
-
-/* Called via hash_table::traverse. Output bitmap descriptor pointed out by
- SLOT and update statistics. */
-int
-print_statistics (bitmap_descriptor_d **slot, bitmap_output_info *i)
-{
- bitmap_descriptor d = *slot;
- char s[4096];
-
- if (d->allocated)
- {
- const char *s1 = d->file;
- const char *s2;
- while ((s2 = strstr (s1, "gcc/")))
- s1 = s2 + 4;
- sprintf (s, "%s:%i (%s)", s1, d->line, d->function);
- s[41] = 0;
- fprintf (stderr,
- "%-41s %9u %15" PRId64" %15" PRId64" %15" PRId64
- " %10" PRId64" %10" PRId64"\n",
- s, d->created,
- d->allocated, d->peak, d->current,
- d->nsearches, d->search_iter);
- i->size += d->allocated;
- i->count += d->created;
- }
- return 1;
-}
-
/* Output per-bitmap memory usage statistics. */
void
dump_bitmap_statistics (void)
{
- struct bitmap_output_info info;
-
if (! GATHER_STATISTICS)
return;
- if (!bitmap_desc_hash)
- return;
-
- fprintf (stderr,
- "\n%-41s %9s %15s %15s %15s %10s %10s\n",
- "Bitmap", "Overall",
- "Allocated", "Peak", "Leak",
- "searched", "search_itr");
- fprintf (stderr, "---------------------------------------------------------------------------------\n");
- info.count = 0;
- info.size = 0;
- bitmap_desc_hash->traverse <bitmap_output_info *, print_statistics> (&info);
- fprintf (stderr, "---------------------------------------------------------------------------------\n");
- fprintf (stderr,
- "%-41s %9" PRId64" %15" PRId64"\n",
- "Total", info.count, info.size);
- fprintf (stderr, "---------------------------------------------------------------------------------\n");
+ bitmap_mem_desc.dump (BITMAP);
}
DEBUG_FUNCTION void