Commit 677cb11d by Richard Sandiford Committed by Richard Sandiford

Optimise hash_table::empty

Calling redirect_edge_var_map_empty after each pass was slowing things
down because hash_table::empty () cleared all slots even if the hash
table was already empty.

Tested on x86_64-linux-gnu, where it gives a 1% compile time improvement
for fold-const.ii at -O and -O2.

gcc/
	* hash-table.h (hash_table::empty): Turn into an inline wrapper
	that checks whether the table is already empty.  Rename the
	original implementation to...
	(hash_table::empty_slot): ...this new private function.

From-SVN: r232467
parent b62df3bf
2016-01-16 Richard Sandiford <richard.sandiford@arm.com>
* hash-table.h (hash_table::empty): Turn into an inline wrapper
that checks whether the table is already empty. Rename the
original implementation to...
(hash_table::empty_slot): ...this new private function.
2016-01-15 David Malcolm <dmalcolm@redhat.com> 2016-01-15 David Malcolm <dmalcolm@redhat.com>
PR diagnostic/68899 PR diagnostic/68899
......
...@@ -390,8 +390,8 @@ public: ...@@ -390,8 +390,8 @@ public:
/* Return the current number of elements in this hash table. */ /* Return the current number of elements in this hash table. */
size_t elements_with_deleted () const { return m_n_elements; } size_t elements_with_deleted () const { return m_n_elements; }
/* This function clears all entries in the given hash table. */ /* This function clears all entries in this hash table. */
void empty (); void empty () { if (elements ()) empty_slow (); }
/* This function clears a specified SLOT in a hash table. It is /* This function clears a specified SLOT in a hash table. It is
useful when you've already done the lookup and don't want to do it useful when you've already done the lookup and don't want to do it
...@@ -499,6 +499,8 @@ private: ...@@ -499,6 +499,8 @@ private:
template<typename T> friend void gt_cleare_cache (hash_table<T> *); template<typename T> friend void gt_cleare_cache (hash_table<T> *);
void empty_slow ();
value_type *alloc_entries (size_t n CXX_MEM_STAT_INFO) const; value_type *alloc_entries (size_t n CXX_MEM_STAT_INFO) const;
value_type *find_empty_slot_for_expand (hashval_t); value_type *find_empty_slot_for_expand (hashval_t);
void expand (); void expand ();
...@@ -755,9 +757,11 @@ hash_table<Descriptor, Allocator>::expand () ...@@ -755,9 +757,11 @@ hash_table<Descriptor, Allocator>::expand ()
ggc_free (oentries); ggc_free (oentries);
} }
/* Implements empty() in cases where it isn't a no-op. */
template<typename Descriptor, template<typename Type> class Allocator> template<typename Descriptor, template<typename Type> class Allocator>
void void
hash_table<Descriptor, Allocator>::empty () hash_table<Descriptor, Allocator>::empty_slow ()
{ {
size_t size = m_size; size_t size = m_size;
value_type *entries = m_entries; value_type *entries = m_entries;
......
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