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 tree_coverage_counter_addr, simplify tree-profile.c


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

Richard.

2008-03-07  Richard Guenther  <rguenther@suse.de>

	* coverage.h (tree_coverage_counter_addr): Declare.
	* coverage.c (tree_coverage_counter_addr): New function.
	* tree-profile.c (tree_gen_edge_profiler): Unshare counter
	before using again.
	(tree_gen_pow2_profiler): Use tree_coverage_counter_addr.
	(tree_gen_one_value_profiler): Likewise.
	(tree_gen_ic_profiler): Likewise.
	(tree_gen_average_profiler): Likewise.
	(tree_gen_ior_profiler): Likewise.

Index: trunk/gcc/coverage.c
===================================================================
*** trunk.orig/gcc/coverage.c	2008-03-07 14:00:18.000000000 +0100
--- trunk/gcc/coverage.c	2008-03-07 14:04:12.000000000 +0100
*************** tree_coverage_counter_ref (unsigned coun
*** 442,447 ****
--- 442,464 ----
    return build4 (ARRAY_REF, gcov_type_node, tree_ctr_tables[counter],
  		 build_int_cst (NULL_TREE, no), NULL, NULL);
  }
+ 
+ /* Generate a tree to access the address of COUNTER NO.  */
+ 
+ tree
+ tree_coverage_counter_addr (unsigned counter, unsigned no)
+ {
+   tree gcov_type_node = get_gcov_type ();
+ 
+   gcc_assert (no < fn_n_ctrs[counter] - fn_b_ctrs[counter]);
+   no += prg_n_ctrs[counter] + fn_b_ctrs[counter];
+ 
+   /* "no" here is an array index, scaled to bytes later.  */
+   return build_fold_addr_expr (build4 (ARRAY_REF, gcov_type_node,
+ 				       tree_ctr_tables[counter],
+ 				       build_int_cst (NULL_TREE, no),
+ 				       NULL, NULL));
+ }
  
  /* Generate a checksum for a string.  CHKSUM is the current
     checksum.  */
Index: trunk/gcc/coverage.h
===================================================================
*** trunk.orig/gcc/coverage.h	2008-03-07 14:00:18.000000000 +0100
--- trunk/gcc/coverage.h	2008-03-07 14:00:56.000000000 +0100
*************** extern int coverage_begin_output (void);
*** 38,43 ****
--- 38,45 ----
  extern int coverage_counter_alloc (unsigned /*counter*/, unsigned/*num*/);
  /* Use a counter from the most recent allocation.  */
  extern tree tree_coverage_counter_ref (unsigned /*counter*/, unsigned/*num*/);
+ /* Use a counter address from the most recent allocation.  */
+ extern tree tree_coverage_counter_addr (unsigned /*counter*/, unsigned/*num*/);
  
  /* Get all the counters for the current function.  */
  extern gcov_type *get_coverage_counts (unsigned /*counter*/,
Index: trunk/gcc/tree-profile.c
===================================================================
*** trunk.orig/gcc/tree-profile.c	2008-03-07 14:00:18.000000000 +0100
--- trunk/gcc/tree-profile.c	2008-03-07 14:00:56.000000000 +0100
*************** tree_gen_edge_profiler (int edgeno, edge
*** 181,187 ****
    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);
--- 181,187 ----
    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 (unshare_expr (ref), gcov_type_tmp_var);
    bsi_insert_on_edge (e, stmt1);
    bsi_insert_on_edge (e, stmt2);
    bsi_insert_on_edge (e, stmt3);
*************** tree_gen_pow2_profiler (histogram_value 
*** 231,241 ****
  {
    tree stmt = value->hvalue.stmt;
    block_stmt_iterator bsi = bsi_for_stmt (stmt);
!   tree ref = tree_coverage_counter_ref (tag, base), ref_ptr;
    tree call, val;
    
!   ref_ptr = force_gimple_operand_bsi (&bsi,
! 				      build_addr (ref, current_function_decl),
  				      true, NULL_TREE, true, BSI_SAME_STMT);
    val = prepare_instrumented_value (&bsi, value);
    call = build_call_expr (tree_pow2_profiler_fn, 2, ref_ptr, val);
--- 231,240 ----
  {
    tree stmt = value->hvalue.stmt;
    block_stmt_iterator bsi = bsi_for_stmt (stmt);
!   tree ref_ptr = tree_coverage_counter_addr (tag, base);
    tree call, val;
    
!   ref_ptr = force_gimple_operand_bsi (&bsi, ref_ptr,
  				      true, NULL_TREE, true, BSI_SAME_STMT);
    val = prepare_instrumented_value (&bsi, value);
    call = build_call_expr (tree_pow2_profiler_fn, 2, ref_ptr, val);
*************** tree_gen_one_value_profiler (histogram_v
*** 251,261 ****
  {
    tree stmt = value->hvalue.stmt;
    block_stmt_iterator bsi = bsi_for_stmt (stmt);
!   tree ref = tree_coverage_counter_ref (tag, base), ref_ptr;
    tree call, val;
    
!   ref_ptr = force_gimple_operand_bsi (&bsi,
! 				      build_addr (ref, current_function_decl),
  				      true, NULL_TREE, true, BSI_SAME_STMT);
    val = prepare_instrumented_value (&bsi, value);
    call = build_call_expr (tree_one_value_profiler_fn, 2, ref_ptr, val);
--- 250,259 ----
  {
    tree stmt = value->hvalue.stmt;
    block_stmt_iterator bsi = bsi_for_stmt (stmt);
!   tree ref_ptr = tree_coverage_counter_addr (tag, base);
    tree call, val;
    
!   ref_ptr = force_gimple_operand_bsi (&bsi, ref_ptr,
  				      true, NULL_TREE, true, BSI_SAME_STMT);
    val = prepare_instrumented_value (&bsi, value);
    call = build_call_expr (tree_one_value_profiler_fn, 2, ref_ptr, val);
*************** tree_gen_ic_profiler (histogram_value va
*** 275,284 ****
    tree tmp1, stmt1, stmt2, stmt3;
    tree stmt = value->hvalue.stmt;
    block_stmt_iterator bsi = bsi_for_stmt (stmt);
!   tree ref = tree_coverage_counter_ref (tag, base), ref_ptr;
  
!   ref_ptr = force_gimple_operand_bsi (&bsi,
! 				      build_addr (ref, current_function_decl),
  				      true, NULL_TREE, true, BSI_SAME_STMT);
  
    /* Insert code:
--- 273,281 ----
    tree tmp1, stmt1, stmt2, stmt3;
    tree stmt = value->hvalue.stmt;
    block_stmt_iterator bsi = bsi_for_stmt (stmt);
!   tree ref_ptr = tree_coverage_counter_addr (tag, base);
  
!   ref_ptr = force_gimple_operand_bsi (&bsi, ref_ptr,
  				      true, NULL_TREE, true, BSI_SAME_STMT);
  
    /* Insert code:
*************** tree_gen_average_profiler (histogram_val
*** 367,377 ****
  {
    tree stmt = value->hvalue.stmt;
    block_stmt_iterator bsi = bsi_for_stmt (stmt);
!   tree ref = tree_coverage_counter_ref (tag, base), ref_ptr;
    tree call, val;
    
!   ref_ptr = force_gimple_operand_bsi (&bsi,
! 				      build_addr (ref, current_function_decl),
  				      true, NULL_TREE,
  				      true, BSI_SAME_STMT);
    val = prepare_instrumented_value (&bsi, value);
--- 364,373 ----
  {
    tree stmt = value->hvalue.stmt;
    block_stmt_iterator bsi = bsi_for_stmt (stmt);
!   tree ref_ptr = tree_coverage_counter_addr (tag, base);
    tree call, val;
    
!   ref_ptr = force_gimple_operand_bsi (&bsi, ref_ptr,
  				      true, NULL_TREE,
  				      true, BSI_SAME_STMT);
    val = prepare_instrumented_value (&bsi, value);
*************** tree_gen_ior_profiler (histogram_value v
*** 388,398 ****
  {
    tree stmt = value->hvalue.stmt;
    block_stmt_iterator bsi = bsi_for_stmt (stmt);
!   tree ref = tree_coverage_counter_ref (tag, base), ref_ptr;
    tree call, val;
    
!   ref_ptr = force_gimple_operand_bsi (&bsi,
! 				      build_addr (ref, current_function_decl),
  				      true, NULL_TREE, true, BSI_SAME_STMT);
    val = prepare_instrumented_value (&bsi, value);
    call = build_call_expr (tree_ior_profiler_fn, 2, ref_ptr, val);
--- 384,393 ----
  {
    tree stmt = value->hvalue.stmt;
    block_stmt_iterator bsi = bsi_for_stmt (stmt);
!   tree ref_ptr = tree_coverage_counter_addr (tag, base);
    tree call, val;
    
!   ref_ptr = force_gimple_operand_bsi (&bsi, ref_ptr,
  				      true, NULL_TREE, true, BSI_SAME_STMT);
    val = prepare_instrumented_value (&bsi, value);
    call = build_call_expr (tree_ior_profiler_fn, 2, ref_ptr, val);


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