Patchwork Tidy timevars

login
register
mail settings
Submitter Michael Matz
Date Nov. 16, 2010, 4:20 p.m.
Message ID <Pine.LNX.4.64.1011161711581.29956@wotan.suse.de>
Download mbox | patch
Permalink /patch/71422/
State New
Headers show

Comments

Michael Matz - Nov. 16, 2010, 4:20 p.m.
Hello,

this patch was a result of me trying to find out why expand is generally 
so slow for all testcases.  I know that it's slow for certain ones, but it 
shouldn't generally be slow.  Well, it turns out that this is actually 
just a measurement error.  tree_rest_of_compilation() wrapped the whole 
pipeline with a TV_EXPAND timevar, meaning that _everything_ that didn't 
have a counter was accounted to expansion time.  Things like some slow 
verifiers and TODO functions.  Well ... ;-)

What I did was essentially wrapping areas of the compiler by several 
temporary timevars to see which things really take time and hence could 
use their own timevar.  This is what I ended up with.  I've introduced 
some new broad catch-all timevars (for gimple optims, ipa optims, RTL pre 
and post reload optims, and todos), and some detailed timevars for things 
really needing some time (address-taken computation, unused local removal, 
verifying RTL sharing and loop-closedness), some others that seemed to 
make sense and made several passes or functions use them.

I specifically did not create new timevars for each and every pass.

The timereport for e.g. combine.i looks much saner now, in particular 
expand only needs ~1% compile time, not silly >5% .

Regstrapping in progress.  Okay if it passes?


Ciao,
Michael.
Mark Mitchell - Nov. 16, 2010, 4:24 p.m.
On 11/16/2010 8:20 AM, Michael Matz wrote:

> What I did was essentially wrapping areas of the compiler by several 
> temporary timevars to see which things really take time and hence could 
> use their own timevar.  

> Regstrapping in progress.  Okay if it passes?

OK.

Patch

Index: tree-into-ssa.c
===================================================================
--- tree-into-ssa.c	(revision 166804)
+++ tree-into-ssa.c	(working copy)
@@ -2339,8 +2339,6 @@  rewrite_into_ssa (void)
   bitmap_head *dfs;
   basic_block bb;
 
-  timevar_push (TV_TREE_SSA_OTHER);
-
   /* Initialize operand data structures.  */
   init_ssa_operands ();
 
@@ -2380,7 +2378,6 @@  rewrite_into_ssa (void)
 
   fini_ssa_renamer ();
 
-  timevar_pop (TV_TREE_SSA_OTHER);
   return 0;
 }
 
@@ -2395,7 +2392,7 @@  struct gimple_opt_pass pass_build_ssa =
   NULL,					/* sub */
   NULL,					/* next */
   0,					/* static_pass_number */
-  TV_NONE,				/* tv_id */
+  TV_TREE_SSA_OTHER,			/* tv_id */
   PROP_cfg | PROP_referenced_vars,	/* properties_required */
   PROP_ssa,				/* properties_provided */
   0,					/* properties_destroyed */
Index: cgraphbuild.c
===================================================================
--- cgraphbuild.c	(revision 166804)
+++ cgraphbuild.c	(working copy)
@@ -521,7 +521,7 @@  struct gimple_opt_pass pass_rebuild_cgra
   NULL,					/* sub */
   NULL,					/* next */
   0,					/* static_pass_number */
-  TV_NONE,				/* tv_id */
+  TV_CGRAPH,				/* tv_id */
   PROP_cfg,				/* properties_required */
   0,					/* properties_provided */
   0,					/* properties_destroyed */
Index: tree-ssa-loop-manip.c
===================================================================
--- tree-ssa-loop-manip.c	(revision 166804)
+++ tree-ssa-loop-manip.c	(working copy)
@@ -455,6 +455,8 @@  verify_loop_closed_ssa (bool verify_ssa_
   if (verify_ssa_p)
     verify_ssa (false);
 
+  timevar_push (TV_VERIFY_LOOP_CLOSED);
+
   FOR_EACH_BB (bb)
     {
       for (bsi = gsi_start_phis (bb); !gsi_end_p (bsi); gsi_next (&bsi))
@@ -468,6 +470,8 @@  verify_loop_closed_ssa (bool verify_ssa_
       for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next (&bsi))
 	check_loop_closed_ssa_stmt (bb, gsi_stmt (bsi));
     }
+
+  timevar_pop (TV_VERIFY_LOOP_CLOSED);
 }
 
 /* Split loop exit edge EXIT.  The things are a bit complicated by a need to
Index: tree-emutls.c
===================================================================
--- tree-emutls.c	(revision 166804)
+++ tree-emutls.c	(working copy)
@@ -792,7 +792,7 @@  struct simple_ipa_opt_pass pass_ipa_lowe
   NULL,                                 /* sub */
   NULL,                                 /* next */
   0,                                    /* static_pass_number */
-  TV_NONE,				/* tv_id */
+  TV_IPA_OPT,				/* tv_id */
   PROP_cfg | PROP_ssa,			/* properties_required */
   0,                                    /* properties_provided */
   0,                                    /* properties_destroyed */
Index: df-core.c
===================================================================
--- df-core.c	(revision 166804)
+++ df-core.c	(working copy)
@@ -758,7 +758,7 @@  struct rtl_opt_pass pass_df_initialize_o
   NULL,                                 /* sub */
   NULL,                                 /* next */
   0,                                    /* static_pass_number */
-  TV_NONE,                              /* tv_id */
+  TV_DF_SCAN,                           /* tv_id */
   0,                                    /* properties_required */
   0,                                    /* properties_provided */
   0,                                    /* properties_destroyed */
@@ -785,7 +785,7 @@  struct rtl_opt_pass pass_df_initialize_n
   NULL,                                 /* sub */
   NULL,                                 /* next */
   0,                                    /* static_pass_number */
-  TV_NONE,                              /* tv_id */
+  TV_DF_SCAN,                           /* tv_id */
   0,                                    /* properties_required */
   0,                                    /* properties_provided */
   0,                                    /* properties_destroyed */
Index: timevar.def
===================================================================
--- timevar.def	(revision 166804)
+++ timevar.def	(working copy)
@@ -53,6 +53,7 @@  DEFTIMEVAR (TV_CGRAPHOPT             , "
 DEFTIMEVAR (TV_VARPOOL               , "varpool construction")
 DEFTIMEVAR (TV_IPA_CONSTANT_PROP     , "ipa cp")
 DEFTIMEVAR (TV_IPA_FNSPLIT           , "ipa function splitting")
+DEFTIMEVAR (TV_IPA_OPT		     , "ipa various optimizations")
 DEFTIMEVAR (TV_IPA_LTO_GIMPLE_IN     , "ipa lto gimple in")
 DEFTIMEVAR (TV_IPA_LTO_GIMPLE_OUT    , "ipa lto gimple out")
 DEFTIMEVAR (TV_IPA_LTO_DECL_IN       , "ipa lto decl in")
@@ -232,9 +233,19 @@  DEFTIMEVAR (TV_VAR_TRACKING          , "
 DEFTIMEVAR (TV_VAR_TRACKING_DATAFLOW , "var-tracking dataflow")
 DEFTIMEVAR (TV_VAR_TRACKING_EMIT     , "var-tracking emit")
 DEFTIMEVAR (TV_TREE_IFCOMBINE        , "tree if-combine")
-DEFTIMEVAR (TV_TREE_UNINIT           , "uninit var anaysis")
+DEFTIMEVAR (TV_TREE_UNINIT           , "uninit var analysis")
 DEFTIMEVAR (TV_PLUGIN_INIT           , "plugin initialization")
 DEFTIMEVAR (TV_PLUGIN_RUN            , "plugin execution")
 
 /* Everything else in rest_of_compilation not included above.  */
+DEFTIMEVAR (TV_EARLY_LOCAL	     , "early local passes")
+DEFTIMEVAR (TV_OPTIMIZE		     , "unaccounted optimizations")
 DEFTIMEVAR (TV_REST_OF_COMPILATION   , "rest of compilation")
+DEFTIMEVAR (TV_POSTRELOAD	     , "unaccounted post reload")
+DEFTIMEVAR (TV_REMOVE_UNUSED	     , "remove unused locals")
+DEFTIMEVAR (TV_ADDRESS_TAKEN	     , "address taken")
+DEFTIMEVAR (TV_TODO		     , "unaccounted todo")
+DEFTIMEVAR (TV_VERIFY_LOOP_CLOSED    , "verify loop closed")
+DEFTIMEVAR (TV_VERIFY_RTL_SHARING    , "verify RTL sharing")
+DEFTIMEVAR (TV_REBUILD_FREQUENCIES   , "rebuild frequencies")
+DEFTIMEVAR (TV_REPAIR_LOOPS	     , "repair loop structures")
Index: predict.c
===================================================================
--- predict.c	(revision 166804)
+++ predict.c	(working copy)
@@ -2329,6 +2329,7 @@  struct gimple_opt_pass pass_strip_predic
 void
 rebuild_frequencies (void)
 {
+  timevar_push (TV_REBUILD_FREQUENCIES);
   if (profile_status == PROFILE_GUESSED)
     {
       loop_optimizer_init (0);
@@ -2343,4 +2344,5 @@  rebuild_frequencies (void)
     counts_to_freqs ();
   else
     gcc_unreachable ();
+  timevar_pop (TV_REBUILD_FREQUENCIES);
 }
Index: tree-vectorizer.c
===================================================================
--- tree-vectorizer.c	(revision 166804)
+++ tree-vectorizer.c	(working copy)
@@ -383,7 +383,7 @@  struct simple_ipa_opt_pass pass_ipa_incr
   NULL,                                 /* sub */
   NULL,                                 /* next */
   0,                                    /* static_pass_number */
-  TV_NONE,                              /* tv_id */
+  TV_IPA_OPT,                           /* tv_id */
   0,                                    /* properties_required */
   0,                                    /* properties_provided */
   0,                                    /* properties_destroyed */
Index: emit-rtl.c
===================================================================
--- emit-rtl.c	(revision 166804)
+++ emit-rtl.c	(working copy)
@@ -2526,6 +2526,8 @@  verify_rtl_sharing (void)
 {
   rtx p;
 
+  timevar_push (TV_VERIFY_RTL_SHARING);
+
   for (p = get_insns (); p; p = NEXT_INSN (p))
     if (INSN_P (p))
       {
@@ -2552,6 +2554,8 @@  verify_rtl_sharing (void)
 	verify_rtx_sharing (PATTERN (p), p);
 	verify_rtx_sharing (REG_NOTES (p), p);
       }
+
+  timevar_pop (TV_VERIFY_RTL_SHARING);
 }
 
 /* Go through all the RTL insn bodies and copy any invalid shared structure.
Index: tree-cfgcleanup.c
===================================================================
--- tree-cfgcleanup.c	(revision 166804)
+++ tree-cfgcleanup.c	(working copy)
@@ -777,7 +777,10 @@  cleanup_tree_cfg_noloop (void)
 static void
 repair_loop_structures (void)
 {
-  bitmap changed_bbs = BITMAP_ALLOC (NULL);
+  bitmap changed_bbs;
+
+  timevar_push (TV_REPAIR_LOOPS);
+  changed_bbs = BITMAP_ALLOC (NULL);
   fix_loop_structure (changed_bbs);
 
   /* This usually does nothing.  But sometimes parts of cfg that originally
@@ -794,6 +797,7 @@  repair_loop_structures (void)
   scev_reset ();
 
   loops_state_clear (LOOPS_NEED_FIXUP);
+  timevar_pop (TV_REPAIR_LOOPS);
 }
 
 /* Cleanup cfg and repair loop structures.  */
Index: tree-ssa-live.c
===================================================================
--- tree-ssa-live.c	(revision 166804)
+++ tree-ssa-live.c	(working copy)
@@ -695,6 +695,8 @@  remove_unused_locals (void)
   if (!optimize)
     return;
 
+  timevar_push (TV_REMOVE_UNUSED);
+
   mark_scope_block_unused (DECL_INITIAL (current_function_decl));
 
   /* Assume all locals are unused.  */
@@ -827,6 +829,8 @@  remove_unused_locals (void)
       fprintf (dump_file, "Scope blocks after cleanups:\n");
       dump_scope_blocks (dump_file, dump_flags);
     }
+
+  timevar_pop (TV_REMOVE_UNUSED);
 }
 
 
Index: cfglayout.c
===================================================================
--- cfglayout.c	(revision 166804)
+++ cfglayout.c	(working copy)
@@ -374,7 +374,7 @@  struct rtl_opt_pass pass_into_cfg_layout
   NULL,                                 /* sub */
   NULL,                                 /* next */
   0,                                    /* static_pass_number */
-  TV_NONE,                              /* tv_id */
+  TV_CFG,                               /* tv_id */
   0,                                    /* properties_required */
   PROP_cfglayout,                       /* properties_provided */
   0,                                    /* properties_destroyed */
@@ -393,7 +393,7 @@  struct rtl_opt_pass pass_outof_cfg_layou
   NULL,                                 /* sub */
   NULL,                                 /* next */
   0,                                    /* static_pass_number */
-  TV_NONE,                              /* tv_id */
+  TV_CFG,                               /* tv_id */
   0,                                    /* properties_required */
   0,                                    /* properties_provided */
   PROP_cfglayout,                       /* properties_destroyed */
Index: tree-ssa.c
===================================================================
--- tree-ssa.c	(revision 166804)
+++ tree-ssa.c	(working copy)
@@ -1816,7 +1816,7 @@  struct gimple_opt_pass pass_early_warn_u
   NULL,					/* sub */
   NULL,					/* next */
   0,					/* static_pass_number */
-  TV_NONE,				/* tv_id */
+  TV_TREE_UNINIT,			/* tv_id */
   PROP_ssa,				/* properties_required */
   0,					/* properties_provided */
   0,					/* properties_destroyed */
@@ -1958,6 +1958,8 @@  execute_update_addresses_taken (void)
   tree var;
   unsigned i;
 
+  timevar_push (TV_ADDRESS_TAKEN);
+
   /* Collect into ADDRESSES_TAKEN all variables whose address is taken within
      the function body.  */
   FOR_EACH_BB (bb)
@@ -2173,6 +2175,7 @@  execute_update_addresses_taken (void)
 
   BITMAP_FREE (not_reg_needs);
   BITMAP_FREE (addresses_taken);
+  timevar_pop (TV_ADDRESS_TAKEN);
 }
 
 struct gimple_opt_pass pass_update_address_taken =
@@ -2185,7 +2188,7 @@  struct gimple_opt_pass pass_update_addre
   NULL,					/* sub */
   NULL,					/* next */
   0,					/* static_pass_number */
-  TV_NONE,				/* tv_id */
+  TV_ADDRESS_TAKEN,			/* tv_id */
   PROP_ssa,				/* properties_required */
   0,					/* properties_provided */
   0,					/* properties_destroyed */
Index: tree-optimize.c
===================================================================
--- tree-optimize.c	(revision 166804)
+++ tree-optimize.c	(working copy)
@@ -69,7 +69,7 @@  struct gimple_opt_pass pass_all_optimiza
   NULL,					/* sub */
   NULL,					/* next */
   0,					/* static_pass_number */
-  TV_NONE,				/* tv_id */
+  TV_OPTIMIZE,				/* tv_id */
   0,					/* properties_required */
   0,					/* properties_provided */
   0,					/* properties_destroyed */
@@ -111,7 +111,7 @@  struct simple_ipa_opt_pass pass_early_lo
   NULL,					/* sub */
   NULL,					/* next */
   0,					/* static_pass_number */
-  TV_NONE,				/* tv_id */
+  TV_EARLY_LOCAL,			/* tv_id */
   0,					/* properties_required */
   0,					/* properties_provided */
   0,					/* properties_destroyed */
@@ -203,7 +203,7 @@  struct gimple_opt_pass pass_cleanup_cfg_
   NULL,					/* sub */
   NULL,					/* next */
   0,					/* static_pass_number */
-  TV_NONE,				/* tv_id */
+  TV_TREE_CLEANUP_CFG,			/* tv_id */
   PROP_cfg,				/* properties_required */
   0,					/* properties_provided */
   0,					/* properties_destroyed */
@@ -389,7 +389,7 @@  tree_rest_of_compilation (tree fndecl)
 {
   location_t saved_loc;
 
-  timevar_push (TV_EXPAND);
+  timevar_push (TV_REST_OF_COMPILATION);
 
   gcc_assert (cgraph_global_info_ready);
 
@@ -471,5 +472,5 @@  tree_rest_of_compilation (tree fndecl)
   input_location = saved_loc;
 
   ggc_collect ();
-  timevar_pop (TV_EXPAND);
+  timevar_pop (TV_REST_OF_COMPILATION);
 }
Index: reginfo.c
===================================================================
--- reginfo.c	(revision 166804)
+++ reginfo.c	(working copy)
@@ -1019,7 +1019,7 @@  struct rtl_opt_pass pass_reginfo_init =
   NULL,                                 /* sub */
   NULL,                                 /* next */
   0,                                    /* static_pass_number */
-  TV_NONE,                                    /* tv_id */
+  TV_NONE,                              /* tv_id */
   0,                                    /* properties_required */
   0,                                    /* properties_provided */
   0,                                    /* properties_destroyed */
Index: passes.c
===================================================================
--- passes.c	(revision 166804)
+++ passes.c	(working copy)
@@ -324,7 +324,7 @@  struct rtl_opt_pass pass_postreload =
   NULL,                                 /* sub */
   NULL,                                 /* next */
   0,                                    /* static_pass_number */
-  TV_NONE,                              /* tv_id */
+  TV_POSTRELOAD,                        /* tv_id */
   PROP_rtl,                             /* properties_required */
   0,                                    /* properties_provided */
   0,                                    /* properties_destroyed */
@@ -1269,6 +1269,8 @@  execute_todo (unsigned int flags)
     gcc_assert (flags & TODO_update_ssa_any);
 #endif
 
+  timevar_push (TV_TODO);
+
   /* Inform the pass whether it is the first time it is run.  */
   first_pass_instance = (flags & TODO_mark_first_instance) != 0;
 
@@ -1302,6 +1304,8 @@  execute_todo (unsigned int flags)
      df problems.  */
   if (flags & TODO_df_finish)
     df_finish_pass ((flags & TODO_df_verify) != 0);
+
+  timevar_pop (TV_TODO);
 }
 
 /* Verify invariants that should hold between passes.  This is a place
Index: tree-ssanames.c
===================================================================
--- tree-ssanames.c	(revision 166804)
+++ tree-ssanames.c	(working copy)
@@ -373,7 +373,7 @@  struct gimple_opt_pass pass_release_ssa_
   NULL,					/* sub */
   NULL,					/* next */
   0,					/* static_pass_number */
-  TV_NONE,				/* tv_id */
+  TV_TREE_SSA_OTHER,			/* tv_id */
   PROP_ssa,				/* properties_required */
   0,					/* properties_provided */
   0,					/* properties_destroyed */