summaryrefslogtreecommitdiff
path: root/gcc/hash-table.h
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/hash-table.h
parent151fbaac5c78c4e9b749fc9e916f78b0ba63b153 (diff)
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/hash-table.h')
-rw-r--r--gcc/hash-table.h51
1 files changed, 45 insertions, 6 deletions
diff --git a/gcc/hash-table.h b/gcc/hash-table.h
index f6375d1ec71..74c3722bbf3 100644
--- a/gcc/hash-table.h
+++ b/gcc/hash-table.h
@@ -199,6 +199,7 @@ along with GCC; see the file COPYING3. If not see
#include "ggc.h"
#include "hashtab.h"
#include <new>
+#include "mem-stats-traits.h"
template<typename, typename, typename> class hash_map;
template<typename, typename> class hash_set;
@@ -551,6 +552,8 @@ struct mark_empty_helper<Type *, Traits, false>
}
};
+class mem_usage;
+
/* User-facing hash table type.
The table stores elements of type Descriptor::value_type.
@@ -583,16 +586,18 @@ class hash_table
typedef typename Descriptor::compare_type compare_type;
public:
- explicit hash_table (size_t, bool ggc = false CXX_MEM_STAT_INFO);
+ explicit hash_table (size_t, bool ggc = false, bool gather_mem_stats = true,
+ mem_alloc_origin origin = HASH_TABLE
+ CXX_MEM_STAT_INFO);
~hash_table ();
/* Create a hash_table in gc memory. */
static hash_table *
- create_ggc (size_t n)
+ create_ggc (size_t n CXX_MEM_STAT_INFO)
{
hash_table *table = ggc_alloc<hash_table> ();
- new (table) hash_table (n, true);
+ new (table) hash_table (n, true, true, HASH_TABLE PASS_MEM_STAT);
return table;
}
@@ -759,19 +764,40 @@ private:
/* if m_entries is stored in ggc memory. */
bool m_ggc;
+
+ /* If we should gather memory statistics for the table. */
+ bool m_gather_mem_stats;
};
+/* As mem-stats.h heavily utilizes hash maps (hash tables), we have to include
+ mem-stats.h after hash_table declaration. */
+
+#include "mem-stats.h"
+#include "hash-map.h"
+#include "vec.h"
+
+extern mem_alloc_description<mem_usage> hash_table_usage;
+
+/* Support function for statistics. */
+extern void dump_hash_table_loc_statistics (void);
+
template<typename Descriptor, template<typename Type> class Allocator>
-hash_table<Descriptor, Allocator>::hash_table (size_t size, bool ggc
- MEM_STAT_DECL) :
+hash_table<Descriptor, Allocator>::hash_table (size_t size, bool ggc, bool
+ gather_mem_stats,
+ mem_alloc_origin origin
+ MEM_STAT_DECL) :
m_n_elements (0), m_n_deleted (0), m_searches (0), m_collisions (0),
- m_ggc (ggc)
+ m_ggc (ggc), m_gather_mem_stats (gather_mem_stats)
{
unsigned int size_prime_index;
size_prime_index = hash_table_higher_prime_index (size);
size = prime_tab[size_prime_index].prime;
+ if (m_gather_mem_stats)
+ hash_table_usage.register_descriptor (this, origin, ggc
+ FINAL_PASS_MEM_STAT);
+
m_entries = alloc_entries (size PASS_MEM_STAT);
m_size = size;
m_size_prime_index = size_prime_index;
@@ -788,6 +814,11 @@ hash_table<Descriptor, Allocator>::~hash_table ()
Allocator <value_type> ::data_free (m_entries);
else
ggc_free (m_entries);
+
+ if (m_gather_mem_stats)
+ hash_table_usage.release_instance_overhead (this,
+ sizeof (value_type) * m_size,
+ true);
}
/* This function returns an array of empty hash table elements. */
@@ -798,6 +829,9 @@ hash_table<Descriptor, Allocator>::alloc_entries (size_t n MEM_STAT_DECL) const
{
value_type *nentries;
+ if (m_gather_mem_stats)
+ hash_table_usage.register_instance_overhead (sizeof (value_type) * n, this);
+
if (!m_ggc)
nentries = Allocator <value_type> ::data_alloc (n);
else
@@ -881,6 +915,11 @@ hash_table<Descriptor, Allocator>::expand ()
}
value_type *nentries = alloc_entries (nsize);
+
+ if (m_gather_mem_stats)
+ hash_table_usage.release_instance_overhead (this, sizeof (value_type)
+ * osize);
+
m_entries = nentries;
m_size = nsize;
m_size_prime_index = nindex;