[PATCH] Save DECLs in edge instrumentation

Richard Guenther rguenther@suse.de
Fri Dec 7 10:38:00 GMT 2007


At the moment we create two variable decls per edge counter update for
-fprofile-generate, which is somewhat wasteful.  This patch reduces it
to a single variable decl per function instead, saving some memory
on DECLs and some time in the referenced vars walkers.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to mainline.

Richard.

2007-12-06  Richard Guenther  <rguenther@suse.de>

	* tree-profile.c (gcov_type_tmp_var): New global variable.
	(tree_gen_edge_profiler): Use a single shared variable decl per
	function for edge counter incrementing.
	(tree_profiling): Re-set the shared variable.

Index: tree-profile.c
===================================================================
*** tree-profile.c	(revision 130650)
--- tree-profile.c	(working copy)
*************** along with GCC; see the file COPYING3.  
*** 48,53 ****
--- 48,54 ----
  #include "cgraph.h"
  
  static GTY(()) tree gcov_type_node;
+ static GTY(()) tree gcov_type_tmp_var;
  static GTY(()) tree tree_interval_profiler_fn;
  static GTY(()) tree tree_pow2_profiler_fn;
  static GTY(()) tree tree_one_value_profiler_fn;
*************** tree_init_edge_profiler (void)
*** 168,182 ****
  static void
  tree_gen_edge_profiler (int edgeno, edge e)
  {
!   tree tmp1 = create_tmp_var (gcov_type_node, "PROF");
!   tree tmp2 = create_tmp_var (gcov_type_node, "PROF");
!   tree ref = tree_coverage_counter_ref (GCOV_COUNTER_ARCS, edgeno);
!   tree one = build_int_cst (gcov_type_node, 1);
!   tree stmt1 = build_gimple_modify_stmt (tmp1, ref);
!   tree stmt2 = build_gimple_modify_stmt (tmp2,
! 					 build2 (PLUS_EXPR, gcov_type_node,
! 						 tmp1, one));
!   tree stmt3 = build_gimple_modify_stmt (ref, tmp2);
    bsi_insert_on_edge (e, stmt1);
    bsi_insert_on_edge (e, stmt2);
    bsi_insert_on_edge (e, stmt3);
--- 169,187 ----
  static void
  tree_gen_edge_profiler (int edgeno, edge e)
  {
!   tree ref, one, stmt1, stmt2, stmt3;
! 
!   /* We share one temporary variable declaration per function.  This
!      gets re-set in tree_profiling.  */
!   if (gcov_type_tmp_var == NULL_TREE)
!     gcov_type_tmp_var = create_tmp_var (gcov_type_node, "PROF_edge_counter");
!   ref = tree_coverage_counter_ref (GCOV_COUNTER_ARCS, edgeno);
!   one = build_int_cst (gcov_type_node, 1);
!   stmt1 = build_gimple_modify_stmt (gcov_type_tmp_var, ref);
!   stmt2 = build_gimple_modify_stmt (gcov_type_tmp_var,
! 				    build2 (PLUS_EXPR, gcov_type_node,
! 					    gcov_type_tmp_var, one));
!   stmt3 = build_gimple_modify_stmt (ref, gcov_type_tmp_var);
    bsi_insert_on_edge (e, stmt1);
    bsi_insert_on_edge (e, stmt2);
    bsi_insert_on_edge (e, stmt3);
*************** tree_profiling (void)
*** 417,422 ****
--- 422,431 ----
       the gcov datastructure initializer.  */
    if (cgraph_state == CGRAPH_STATE_FINISHED)
      return 0;
+ 
+   /* Re-set global shared temporary variable for edge-counters.  */
+   gcov_type_tmp_var = NULL_TREE;
+ 
    branch_prob ();
  
    if (! flag_branch_probabilities 



More information about the Gcc-patches mailing list