On Mon, Mar 25, 2019 at 09:42:01PM +0100, Jakub Jelinek wrote:
> BTW, why don't do something like following (dunno if it is valid not to
> define the static data member out of the class unless it would be constexpr
> or inline, but it isn't really ODR used, is it?), because at least looking
> at currently emitted code without --enable-gather-detailed-mem-stats, we
> emit this statistics gathering code everywhere except in the ctors where
> optimizers can clearly see that m_gather_mem_stats is false.  But we usually
> don't see that in the destructor or in the methods, especially when they
> aren't inlined.  Martin?

Here is an updated version of this patch which I've bootstrapped/regtested
on x86_64-linux and i686-linux (doesn't deal with the issues Jason reported,
that needs a separate patch).

On my --enable-checking=yes,rtl,extra bootstrap on x86_64-linux, the patch
decreases a size of various sections (everything in bytes):
-.hash  155360
+.hash  152528
-.gnu.hash      170088
+.gnu.hash      167256
-.dynsym        538248
+.dynsym        521256
-.dynstr        1032304
+.dynstr        961759
-.gnu.version   44854
+.gnu.version   43438
-.text  24027797
+.text  23951957
-.rodata        8282592
+.rodata        8282432
-.eh_frame_hdr  407036
+.eh_frame_hdr  403700
-.eh_frame      2454384
+.eh_frame      2416392
-.debug_str     6848275
+.debug_str     6847936
I know it isn't that much, but 74KB savings on .text seems to be worth to
me with such a small patch.  Ok for trunk?

2019-03-25  Jakub Jelinek  <ja...@redhat.com>

        * hash-table.h (hash_table::m_gather_mem_stats): If GATHER_STATISTICS
        is constant 0, turn into static const data member initialized to false.
        (hash_table::hash_table): Only initialize m_gather_mem_stats #if
        GATHER_STATISTICS.  Add ATTRIBUTE_UNUSED to gather_mem_stats param.

--- gcc/hash-table.h    2019-03-21 22:59:16.501772695 +0100
+++ gcc/hash-table.h    2019-03-25 21:19:32.589325346 +0100
@@ -562,7 +562,11 @@ private:
   bool m_ggc;
 
   /* If we should gather memory statistics for the table.  */
+#if GATHER_STATISTICS
   bool m_gather_mem_stats;
+#else
+  static const bool m_gather_mem_stats = false;
+#endif
 };
 
 /* As mem-stats.h heavily utilizes hash maps (hash tables), we have to include
@@ -579,11 +583,15 @@ extern void dump_hash_table_loc_statisti
 template<typename Descriptor, bool Lazy,
         template<typename Type> class Allocator>
 hash_table<Descriptor, Lazy, Allocator>::hash_table (size_t size, bool ggc,
-                                                    bool gather_mem_stats,
+                                                    bool gather_mem_stats
+                                                    ATTRIBUTE_UNUSED,
                                                     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_gather_mem_stats (gather_mem_stats)
+  m_ggc (ggc)
+#if GATHER_STATISTICS
+  , m_gather_mem_stats (gather_mem_stats)
+#endif
 {
   unsigned int size_prime_index;
 
@@ -606,12 +614,15 @@ template<typename Descriptor, bool Lazy,
         template<typename Type> class Allocator>
 hash_table<Descriptor, Lazy, Allocator>::hash_table (const hash_table &h,
                                                     bool ggc,
-                                                    bool gather_mem_stats,
+                                                    bool gather_mem_stats
+                                                    ATTRIBUTE_UNUSED,
                                                     mem_alloc_origin origin
                                                     MEM_STAT_DECL) :
   m_n_elements (h.m_n_elements), m_n_deleted (h.m_n_deleted),
-  m_searches (0), m_collisions (0), m_ggc (ggc),
-  m_gather_mem_stats (gather_mem_stats)
+  m_searches (0), m_collisions (0), m_ggc (ggc)
+#if GATHER_STATISTICS
+  , m_gather_mem_stats (gather_mem_stats)
+#endif
 {
   size_t size = h.m_size;
 

        Jakub

Reply via email to