diff mbox

[pph] Add more PPH timers and stats. (issue5937045)

Message ID 20120327193748.B7802AE1F2@tobiano.tor.corp.google.com
State New
Headers show

Commit Message

Diego Novillo March 27, 2012, 7:37 p.m. UTC
Add more PPH timers and stats.

We are spending too much time inside the reading of template bodies.
This patch adds more timers that pinpoint the problem to be the
hashing of specialization tables.  We spend roughly 50% of PPH reading
inside the hashing code.


2012-03-27   Diego Novillo  <dnovillo@google.com>

cp/ChangeLog.pph
	* pph-core.c (pph_dump_stats): Print pph_stats.num_spec_entry_elems.
	* pph.h (struct pph_stats_s): Add field num_spec_entry_elems.
	* pt.c (pph_out_spec_entry_htab): Update pph_stats.num_spec_entry_elems.
	(pph_in_bodies_spec_entry_htab): Likewise.
	Add timer TV_PPH_SPECIALIZATION_HASH around hashing operations.

ChangeLog.pph
	* timevar.def (TV_PPH_SPECIALIZATION_HASH): New timer.
	(TV_PPH_OUT_MERGE_KEYS, TV_PPH_OUT_MERGE_BODIES, TV_PPH_IN_MERGE_KEYS,
	TV_PPH_IN_MERGE_BODIES): Remove.
	(TV_PPH_OUT_BL_K): New.  Update previous users of TV_PPH_OUT_MERGE_KEYS.
	(TV_PPH_OUT_BL_B): New.  Update previous users of
	TV_PPH_OUT_MERGE_BODIES.
	(TV_PPH_OUT_TMPL_K): New.  Update previous users of
	TV_PPH_OUT_MERGE_KEYS.
	(TV_PPH_OUT_TMPL_B): New.  Update previous users of
	TV_PPH_OUT_MERGE_BODIES.
	(TV_PPH_IN_BL_K): New.  Update previous users of TV_PPH_OUT_MERGE_KEYS.
	(TV_PPH_IN_BL_B): New.  Update previous users of
	TV_PPH_OUT_MERGE_BODIES.
	(TV_PPH_IN_TMPL_K): New.  Update previous users of
	TV_PPH_OUT_MERGE_KEYS.
	(TV_PPH_IN_TMPL_B): New.  Update previous users of
	TV_PPH_OUT_MERGE_BODIES.


--
This patch is available for review at http://codereview.appspot.com/5937045
diff mbox

Patch

diff --git a/gcc/cp/pph-core.c b/gcc/cp/pph-core.c
index f16675c..da91524 100644
--- a/gcc/cp/pph-core.c
+++ b/gcc/cp/pph-core.c
@@ -1601,6 +1601,10 @@  pph_dump_stats (FILE *f)
 	   PERCENT (pph_stats.cache_hits, pph_stats.cache_lookups));
 
   fprintf (f, "\n");
+  fprintf (f, "Number of elements in all spec_entry tables: %lu",
+	   pph_stats.num_spec_entry_elems);
+
+  fprintf (f, "\n");
   timevar_print (f);
 }
 
diff --git a/gcc/cp/pph-in.c b/gcc/cp/pph-in.c
index d50581e..546a591 100644
--- a/gcc/cp/pph-in.c
+++ b/gcc/cp/pph-in.c
@@ -3121,7 +3121,7 @@  pph_in_global_binding_keys (pph_stream *stream)
   cp_binding_level *bl, *other_bl;
   bool existed_p;
 
-  timevar_start (TV_PPH_IN_MERGE_KEYS);
+  timevar_start (TV_PPH_IN_BL_K);
 
   bl = scope_chain->bindings;
   other_bl = pph_in_binding_level_start (stream, bl, &existed_p);
@@ -3138,7 +3138,7 @@  pph_in_global_binding_keys (pph_stream *stream)
      bound to scope_chain->bindings.  */
   pph_in_merge_key_binding_level (stream, &bl);
 
-  timevar_stop (TV_PPH_IN_MERGE_KEYS);
+  timevar_stop (TV_PPH_IN_BL_K);
 }
 
 
@@ -3151,14 +3151,14 @@  pph_in_global_binding_bodies (pph_stream *stream)
 {
   cp_binding_level *bl = scope_chain->bindings;
 
-  timevar_start (TV_PPH_IN_MERGE_BODIES);
+  timevar_start (TV_PPH_IN_BL_B);
 
   /* Once all the symbols and types at every binding level have been
      merged to the corresponding binding levels in the current
      compilation, read all the bodies.  */
   pph_in_merge_body_binding_level (stream, bl);
 
-  timevar_stop (TV_PPH_IN_MERGE_BODIES);
+  timevar_stop (TV_PPH_IN_BL_B);
 }
 
 
diff --git a/gcc/cp/pph-out.c b/gcc/cp/pph-out.c
index 018a5f0..7b4cf01 100644
--- a/gcc/cp/pph-out.c
+++ b/gcc/cp/pph-out.c
@@ -2610,7 +2610,7 @@  pph_out_global_binding_keys (pph_stream *stream)
 {
   cp_binding_level *bl;
 
-  timevar_start (TV_PPH_OUT_MERGE_KEYS);
+  timevar_start (TV_PPH_OUT_BL_K);
 
   /* We only need to write out the scope_chain->bindings, everything
      else should be NULL or be some temporary disposable state.
@@ -2643,7 +2643,7 @@  pph_out_global_binding_keys (pph_stream *stream)
      reading multiple PPH images.  */
   pph_out_merge_key_binding_level (stream, bl);
 
-  timevar_stop (TV_PPH_OUT_MERGE_KEYS);
+  timevar_stop (TV_PPH_OUT_BL_K);
 }
 
 
@@ -2654,12 +2654,12 @@  pph_out_global_binding_bodies (pph_stream *stream)
 {
   cp_binding_level *bl = scope_chain->bindings;
 
-  timevar_start (TV_PPH_OUT_MERGE_BODIES);
+  timevar_start (TV_PPH_OUT_BL_B);
 
   /* Now emit all the bodies.  */
   pph_out_merge_body_binding_level (stream, bl);
 
-  timevar_stop (TV_PPH_OUT_MERGE_BODIES);
+  timevar_stop (TV_PPH_OUT_BL_B);
 }
 
 
diff --git a/gcc/cp/pph.h b/gcc/cp/pph.h
index 74860be..b28b3cc 100644
--- a/gcc/cp/pph.h
+++ b/gcc/cp/pph.h
@@ -164,6 +164,9 @@  typedef struct pph_stats_s {
 
   /* Total number of replay actions in the replay table.  */
   unsigned long num_replay_actions;
+
+  /* Total number of entries in a spec_entry template table.  */
+  unsigned long num_spec_entry_elems;
 } pph_stats_t;
 
 extern pph_stats_t pph_stats;
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 2cd3835..6a4c634 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -20803,6 +20803,7 @@  pph_out_spec_entry_htab (pph_stream *stream, htab_t *table,
       unsigned count = htab_elements (*table);
       /*FIXME pph: This write may be unstable.  */
       pph_out_uint (stream, count);
+      pph_stats.num_spec_entry_elems += count;
       if (flag_pph_debug >= 2)
         fprintf (pph_logfile, "PPH: writing %d spec_entries\n", count );
       htab_traverse_noresize (*table, func, stream);
@@ -20885,6 +20886,9 @@  static void
 pph_in_bodies_spec_entry_htab (pph_stream *stream, htab_t *table)
 {
   unsigned count = pph_in_uint (stream);
+
+  pph_stats.num_spec_entry_elems += count;
+
   if (flag_pph_debug >= 2)
     fprintf (pph_logfile, "PPH: loading bodies %d spec_entries\n", count );
   for (; count > 0; --count)
@@ -20895,8 +20899,10 @@  pph_in_bodies_spec_entry_htab (pph_stream *stream, htab_t *table)
       se->tmpl = pph_in_tree (stream);
       se->args = pph_in_tree (stream);
       se->spec = pph_in_tree (stream);
+      timevar_start (TV_PPH_SPECIALIZATION_HASH);
       hash = hash_specialization (se);
       slot = (spec_entry **)htab_find_slot_with_hash (*table, se, hash, INSERT);
+      timevar_stop (TV_PPH_SPECIALIZATION_HASH);
       *slot = se;
     }
 }
@@ -20907,12 +20913,14 @@  pph_in_bodies_spec_entry_htab (pph_stream *stream, htab_t *table)
 void
 pph_out_merge_key_template_state (pph_stream *stream ATTRIBUTE_UNUSED)
 {
-  timevar_start (TV_PPH_OUT_MERGE_KEYS);
+  timevar_start (TV_PPH_OUT_TMPL_K);
+
   pph_out_spec_entry_htab (stream, &decl_specializations,
 			   pph_out_key_spec_entry_slot);
   pph_out_spec_entry_htab (stream, &type_specializations,
 			   pph_out_key_spec_entry_slot);
-  timevar_stop (TV_PPH_OUT_MERGE_KEYS);
+
+  timevar_stop (TV_PPH_OUT_TMPL_K);
 }
 
 
@@ -20921,7 +20929,7 @@  pph_out_merge_key_template_state (pph_stream *stream ATTRIBUTE_UNUSED)
 void
 pph_out_merge_body_template_state (pph_stream *stream)
 {
-  timevar_start (TV_PPH_OUT_MERGE_BODIES);
+  timevar_start (TV_PPH_OUT_TMPL_B);
 
   pph_out_spec_entry_htab (stream, &decl_specializations,
 			   pph_out_body_spec_entry_slot);
@@ -20935,7 +20943,7 @@  pph_out_merge_body_template_state (pph_stream *stream)
       pph_dump_pending_templates_list (stderr);
     }
 
-  timevar_stop (TV_PPH_OUT_MERGE_BODIES);
+  timevar_stop (TV_PPH_OUT_TMPL_B);
 }
 
 
@@ -20950,7 +20958,7 @@  static strptrmap_t *type_spec_tbl = NULL;
 void
 pph_in_merge_key_template_state (pph_stream *stream ATTRIBUTE_UNUSED)
 {
-  timevar_start (TV_PPH_IN_MERGE_KEYS);
+  timevar_start (TV_PPH_IN_TMPL_K);
 
   if (!decl_spec_tbl)
     decl_spec_tbl = strptrmap_create ();
@@ -20961,7 +20969,7 @@  pph_in_merge_key_template_state (pph_stream *stream ATTRIBUTE_UNUSED)
   pph_in_keys_spec_entry_htab (stream, pph_in_search_key_spec,
 			       type_spec_tbl);
 
-  timevar_stop (TV_PPH_IN_MERGE_KEYS);
+  timevar_stop (TV_PPH_IN_TMPL_K);
 }
 
 
@@ -20970,7 +20978,7 @@  pph_in_merge_key_template_state (pph_stream *stream ATTRIBUTE_UNUSED)
 void
 pph_in_merge_body_template_state (pph_stream *stream)
 {
-  timevar_start (TV_PPH_IN_MERGE_BODIES);
+  timevar_start (TV_PPH_IN_TMPL_B);
 
   pph_in_bodies_spec_entry_htab (stream, &decl_specializations);
   pph_in_bodies_spec_entry_htab (stream, &type_specializations);
@@ -20982,7 +20990,7 @@  pph_in_merge_body_template_state (pph_stream *stream)
       pph_dump_pending_templates_list (stderr);
     }
 
-  timevar_stop (TV_PPH_IN_MERGE_BODIES);
+  timevar_stop (TV_PPH_IN_TMPL_B);
 }
 
 
diff --git a/gcc/timevar.def b/gcc/timevar.def
index 1b50892..b1dd3db 100644
--- a/gcc/timevar.def
+++ b/gcc/timevar.def
@@ -63,20 +63,25 @@  DEFTIMEVAR (TV_PCH_CPP_RESTORE       , "PCH preprocessor state restore")
 /* Time spent saving/restoring PPH state.  */
 DEFTIMEVAR (TV_PPH                   , "PPH (global)")
 DEFTIMEVAR (TV_PPH_VALIDATE_IDENTIFIERS, "PPH validate identifiers")
+DEFTIMEVAR (TV_PPH_SPECIALIZATION_HASH, "PPH specialization hash")
 
 DEFTIMEVAR (TV_PPH_OUT               , "PPH out (main)")
 DEFTIMEVAR (TV_PPH_OUT_LINE_TABLE    , "PPH out (line table)")
 DEFTIMEVAR (TV_PPH_OUT_IDENTIFIERS   , "PPH out (identifiers)")
-DEFTIMEVAR (TV_PPH_OUT_MERGE_KEYS    , "PPH out (merge keys)")
-DEFTIMEVAR (TV_PPH_OUT_MERGE_BODIES  , "PPH out (merge bodies)")
+DEFTIMEVAR (TV_PPH_OUT_BL_K          , "PPH out (BL [k])")
+DEFTIMEVAR (TV_PPH_OUT_BL_B          , "PPH out (BL [b])")
+DEFTIMEVAR (TV_PPH_OUT_TMPL_K        , "PPH out (TMPL [k])")
+DEFTIMEVAR (TV_PPH_OUT_TMPL_B        , "PPH out (TMPL [b])")
 DEFTIMEVAR (TV_PPH_OUT_MISC          , "PPH out (misc state)")
 DEFTIMEVAR (TV_PPH_OUT_REPLAY        , "PPH out (replay table)")
 
 DEFTIMEVAR (TV_PPH_IN                , "PPH in (main)")
 DEFTIMEVAR (TV_PPH_IN_LINE_TABLE     , "PPH in (line table)")
 DEFTIMEVAR (TV_PPH_IN_IDENTIFIERS    , "PPH in (identifiers)")
-DEFTIMEVAR (TV_PPH_IN_MERGE_KEYS     , "PPH in (merge keys)")
-DEFTIMEVAR (TV_PPH_IN_MERGE_BODIES   , "PPH in (merge bodies)")
+DEFTIMEVAR (TV_PPH_IN_BL_K           , "PPH in (BL [k])")
+DEFTIMEVAR (TV_PPH_IN_BL_B           , "PPH in (BL [b])")
+DEFTIMEVAR (TV_PPH_IN_TMPL_K         , "PPH in (TMPL [k])")
+DEFTIMEVAR (TV_PPH_IN_TMPL_B         , "PPH in (TMPL [b])")
 DEFTIMEVAR (TV_PPH_IN_MISC           , "PPH in (misc state)")
 DEFTIMEVAR (TV_PPH_IN_REPLAY         , "PPH in (replay table)")