From 677cb11df0d67bb9590eefd61aebd8851872e2ae Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Sat, 16 Jan 2016 11:03:18 +0000 Subject: [PATCH] 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 --- gcc/ChangeLog | 7 +++++++ gcc/hash-table.h | 10 +++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index cf0421880c0..227acf96c27 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2016-01-16 Richard Sandiford + + * 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 PR diagnostic/68899 diff --git a/gcc/hash-table.h b/gcc/hash-table.h index 2c52a4a653f..e925e1e12d6 100644 --- a/gcc/hash-table.h +++ b/gcc/hash-table.h @@ -390,8 +390,8 @@ public: /* Return the current number of elements in this hash table. */ size_t elements_with_deleted () const { return m_n_elements; } - /* This function clears all entries in the given hash table. */ - void empty (); + /* This function clears all entries in this hash table. */ + void empty () { if (elements ()) empty_slow (); } /* 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 @@ -499,6 +499,8 @@ private: template friend void gt_cleare_cache (hash_table *); + void empty_slow (); + value_type *alloc_entries (size_t n CXX_MEM_STAT_INFO) const; value_type *find_empty_slot_for_expand (hashval_t); void expand (); @@ -755,9 +757,11 @@ hash_table::expand () ggc_free (oentries); } +/* Implements empty() in cases where it isn't a no-op. */ + template class Allocator> void -hash_table::empty () +hash_table::empty_slow () { size_t size = m_size; value_type *entries = m_entries;