This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] add statistics counting to postreload, copy-rename, and math-opts


It's a shame more passes don't make use of the statistics_*
infrastructure.  This patch is a step towards rectifying that and adds
statistics_counter_event calls to passes mentioned in $SUBJECT.
postreload-gcse already tracked the stats for the dump file and so only
needs the statistics_counter_event calls; the other passes needed to be
taught about the statistics also.

Tested on x86_64-unknown-linux-gnu.  OK to commit?

-Nathan

	* postreload-gcse.c (gcse_after_reload_main): Add calls to
	statistics_counter_event.
	* tree-ssa-copyrename.c (stats): Define.
	(rename_ssa_copies): Count coalesced SSA_NAMEs.  Add call to
	statistics_counter_event.
	* tree-ssa-math-opts.c (reciprocal_stats, sincos_stats): Define.
	(bswap_stats, widen_mul_stats): Define.
	(insert_reciprocals): Increment rdivs_inserted.
	(execute_cse_reciprocals): Zeroize reciprocal_stats.  Increment
	rfuncs_inserted.  Add calls to statistics_counter_event.
	(execute_cse_sincos_1): Increment inserted.
	(execute_cse_sincos): Zeroize sincos_stats.  Add call to
	statistics_counter_event.
	(execute_optimize_bswap): Zeroize bswap_stats.  Increment fields
	of bswap_stats.  Add calls to statistics_counter_event.
	(convert_mult_to_widen): Increment widen_mults_inserted.
	(convert_plusminus_to_widen): Increment maccs_inserted.
	(convert_mult_to_fma): Increment fmas_inserted.
	(execute_optimize_widening_mul): Zeroize widen_mul_stats.  Add
	calls to statistics_counter_event.

diff --git a/gcc/postreload-gcse.c b/gcc/postreload-gcse.c
index 7eeecf4..8e26419 100644
--- a/gcc/postreload-gcse.c
+++ b/gcc/postreload-gcse.c
@@ -1294,6 +1294,13 @@ gcse_after_reload_main (rtx f ATTRIBUTE_UNUSED)
 	  fprintf (dump_file, "insns deleted:   %d\n", stats.insns_deleted);
 	  fprintf (dump_file, "\n\n");
 	}
+
+      statistics_counter_event (cfun, "copies inserted",
+				stats.copies_inserted);
+      statistics_counter_event (cfun, "moves inserted",
+				stats.moves_inserted);
+      statistics_counter_event (cfun, "insns deleted",
+				stats.insns_deleted);
     }
 
   /* We are finished with alias.  */
diff --git a/gcc/tree-ssa-copyrename.c b/gcc/tree-ssa-copyrename.c
index dfc0b4e..ae4fb5f 100644
--- a/gcc/tree-ssa-copyrename.c
+++ b/gcc/tree-ssa-copyrename.c
@@ -40,6 +40,12 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-pass.h"
 #include "langhooks.h"
 
+static struct
+{
+  /* Number of copies coalesced.  */
+  int coalesced;
+} stats;
+
 /* The following routines implement the SSA copy renaming phase.
 
    This optimization looks for copies between 2 SSA_NAMES, either through a
@@ -360,9 +366,12 @@ rename_ssa_copies (void)
 	      fprintf (debug, "\n");
 	    }
 	}
+      stats.coalesced++;
       replace_ssa_name_symbol (var, SSA_NAME_VAR (part_var));
     }
 
+  statistics_counter_event (cfun, "copies coalesced",
+			    stats.coalesced);
   delete_var_map (map);
   return updated ? TODO_remove_unused_locals : 0;
 }
diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c
index 6e2213c..b9f631e 100644
--- a/gcc/tree-ssa-math-opts.c
+++ b/gcc/tree-ssa-math-opts.c
@@ -138,6 +138,41 @@ struct occurrence {
   bool bb_has_division;
 };
 
+static struct
+{
+  /* Number of 1.0/X ops inserted.  */
+  int rdivs_inserted;
+
+  /* Number of 1.0/FUNC ops inserted.  */
+  int rfuncs_inserted;
+} reciprocal_stats;
+
+static struct
+{
+  /* Number of cexpi calls inserted.  */
+  int inserted;
+} sincos_stats;
+
+static struct
+{
+  /* Number of hand-written 32-bit bswaps found.  */
+  int found_32bit;
+
+  /* Number of hand-written 64-bit bswaps found.  */
+  int found_64bit;
+} bswap_stats;
+
+static struct
+{
+  /* Number of widening multiplication ops inserted.  */
+  int widen_mults_inserted;
+
+  /* Number of integer multiply-and-accumulate ops inserted.  */
+  int maccs_inserted;
+
+  /* Number of fp fused multiply-add ops inserted.  */
+  int fmas_inserted;
+} widen_mul_stats;
 
 /* The instance of "struct occurrence" representing the highest
    interesting block in the dominator tree.  */
@@ -339,6 +374,8 @@ insert_reciprocals (gimple_stmt_iterator *def_gsi, struct occurrence *occ,
           gsi_insert_before (&gsi, new_stmt, GSI_SAME_STMT);
         }
 
+      reciprocal_stats.rdivs_inserted++;
+
       occ->recip_def_stmt = new_stmt;
     }
 
@@ -466,6 +503,7 @@ execute_cse_reciprocals (void)
 				sizeof (struct occurrence),
 				n_basic_blocks / 3 + 1);
 
+  memset (&reciprocal_stats, 0, sizeof (reciprocal_stats));
   calculate_dominance_info (CDI_DOMINATORS);
   calculate_dominance_info (CDI_POST_DOMINATORS);
 
@@ -568,6 +606,7 @@ execute_cse_reciprocals (void)
 		  gimple_replace_lhs (stmt1, arg1);
 		  gimple_call_set_fndecl (stmt1, fndecl);
 		  update_stmt (stmt1);
+		  reciprocal_stats.rfuncs_inserted++;
 
 		  FOR_EACH_IMM_USE_STMT (stmt, ui, arg1)
 		    {
@@ -580,6 +619,11 @@ execute_cse_reciprocals (void)
 	}
     }
 
+  statistics_counter_event (cfun, "reciprocal divs inserted",
+			    reciprocal_stats.rdivs_inserted);
+  statistics_counter_event (cfun, "reciprocal functions inserted",
+			    reciprocal_stats.rfuncs_inserted);
+
   free_dominance_info (CDI_DOMINATORS);
   free_dominance_info (CDI_POST_DOMINATORS);
   free_alloc_pool (occ_pool);
@@ -711,6 +755,7 @@ execute_cse_sincos_1 (tree name)
       gsi_insert_before (&gsi, stmt, GSI_SAME_STMT);
     }
   update_stmt (stmt);
+  sincos_stats.inserted++;
 
   /* And adjust the recorded old call sites.  */
   for (i = 0; VEC_iterate(gimple, stmts, i, use_stmt); ++i)
@@ -760,6 +805,7 @@ execute_cse_sincos (void)
   bool cfg_changed = false;
 
   calculate_dominance_info (CDI_DOMINATORS);
+  memset (&sincos_stats, 0, sizeof (sincos_stats));
 
   FOR_EACH_BB (bb)
     {
@@ -793,6 +839,9 @@ execute_cse_sincos (void)
 	}
     }
 
+  statistics_counter_event (cfun, "sincos statements inserted",
+			    sincos_stats.inserted);
+
   free_dominance_info (CDI_DOMINATORS);
   return cfg_changed ? TODO_cleanup_cfg : 0;
 }
@@ -1141,6 +1190,8 @@ execute_optimize_bswap (void)
       bswap64_type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
     }
 
+  memset (&bswap_stats, 0, sizeof (bswap_stats));
+
   FOR_EACH_BB (bb)
     {
       gimple_stmt_iterator gsi;
@@ -1189,6 +1240,10 @@ execute_optimize_bswap (void)
 	    continue;
 
 	  changed = true;
+	  if (type_size == 32)
+	    bswap_stats.found_32bit++;
+	  else
+	    bswap_stats.found_64bit++;
 
 	  bswap_tmp = bswap_src;
 
@@ -1237,6 +1292,11 @@ execute_optimize_bswap (void)
 	}
     }
 
+  statistics_counter_event (cfun, "32-bit bswap implementations found",
+			    bswap_stats.found_32bit);
+  statistics_counter_event (cfun, "64-bit bswap implementations found",
+			    bswap_stats.found_64bit);
+
   return (changed ? TODO_dump_func | TODO_update_ssa | TODO_verify_ssa
 	  | TODO_verify_stmts : 0);
 }
@@ -1389,6 +1449,7 @@ convert_mult_to_widen (gimple stmt)
   gimple_assign_set_rhs2 (stmt, fold_convert (type2, rhs2));
   gimple_assign_set_rhs_code (stmt, WIDEN_MULT_EXPR);
   update_stmt (stmt);
+  widen_mul_stats.widen_mults_inserted++;
   return true;
 }
 
@@ -1491,6 +1552,7 @@ convert_plusminus_to_widen (gimple_stmt_iterator *gsi, gimple stmt,
 				    fold_convert (type2, mult_rhs2),
 				    add_rhs);
   update_stmt (gsi_stmt (*gsi));
+  widen_mul_stats.maccs_inserted++;
   return true;
 }
 
@@ -1666,6 +1728,7 @@ convert_mult_to_fma (gimple mul_stmt, tree op1, tree op2)
 						mulop1, op2,
 						addop);
       gsi_replace (&gsi, fma_stmt, true);
+      widen_mul_stats.fmas_inserted++;
     }
 
   return true;
@@ -1681,6 +1744,8 @@ execute_optimize_widening_mul (void)
   basic_block bb;
   bool cfg_changed = false;
 
+  memset (&widen_mul_stats, 0, sizeof (widen_mul_stats));
+
   FOR_EACH_BB (bb)
     {
       gimple_stmt_iterator gsi;
@@ -1752,6 +1817,13 @@ execute_optimize_widening_mul (void)
 	}
     }
 
+  statistics_counter_event (cfun, "widening multiplications inserted",
+			    widen_mul_stats.widen_mults_inserted);
+  statistics_counter_event (cfun, "widening maccs inserted",
+			    widen_mul_stats.maccs_inserted);
+  statistics_counter_event (cfun, "fused multiply-adds inserted",
+			    widen_mul_stats.fmas_inserted);
+
   return cfg_changed ? TODO_cleanup_cfg : 0;
 }
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]