public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* conditional gcov instrumentation
@ 2009-09-07 19:51 Hayawardh V
  2009-09-08  3:28 ` Hayawardh V
  0 siblings, 1 reply; 3+ messages in thread
From: Hayawardh V @ 2009-09-07 19:51 UTC (permalink / raw)
  To: gcc

[-- Attachment #1: Type: text/plain, Size: 763 bytes --]

Hi,
I have been working on a conditional gcov patch, that calls a function
everytime the gcov counter is to be modified, so the function can
decide how to increment the counter.
The function's prototype is :

void __gcov_ctr(gcov_type*) ;

where gcov_type would be, for example, long long depending on the architecture.

This would be useful for kernel coverage instrumentation (eg) tracking
the coverage of only a particular pid, or for implementing atomic
counters per cpu, and probably for many others.
The libgcov could have a weak default implementation which increments
the counter by 1 as usual, and those wanting to add their own
implementation could do so. (Suggested by Peter Oberparleiter).

I am attaching a patch. Please comment.

Regards,
Hayawardh

[-- Attachment #2: gcc-4.4.0-gcov-ctr-ptr.patch --]
[-- Type: application/octet-stream, Size: 1487 bytes --]

--- gcc-4.4.0/gcc/tree-profile.c	2009-09-03 00:10:48.000000000 -0400
+++ gcc-4.4.0-gcov-ptr-src/gcc/tree-profile.c	2009-09-03 00:11:01.000000000 -0400
@@ -183,22 +183,25 @@
 static void
 tree_gen_edge_profiler (int edgeno, edge e)
 {
-  tree ref, one;
-  gimple stmt1, stmt2, stmt3;
+  tree ref;
+  gimple call; 
+  tree decl, gcov_ctr_fn_type, ctr_ptr, gcov_type_ptr;
 
   /* 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 = gimple_build_assign (gcov_type_tmp_var, ref);
-  stmt2 = gimple_build_assign_with_ops (PLUS_EXPR, gcov_type_tmp_var,
-					gcov_type_tmp_var, one);
-  stmt3 = gimple_build_assign (unshare_expr (ref), gcov_type_tmp_var);
-  gsi_insert_on_edge (e, stmt1);
-  gsi_insert_on_edge (e, stmt2);
-  gsi_insert_on_edge (e, stmt3);
+  gcov_type_ptr = build_pointer_type (get_gcov_type());
+
+  gcov_ctr_fn_type = build_function_type_list(void_type_node, gcov_type_ptr, NULL_TREE);
+
+  decl = build_decl(FUNCTION_DECL, get_identifier("__gcov_ctr"), gcov_ctr_fn_type);
+  ctr_ptr = build_addr(ref, current_function_decl);
+ 
+  call = gimple_build_call (decl, 1, ctr_ptr);
+
+  gsi_insert_on_edge (e, call);
 }
 
 /* Emits code to get VALUE to instrument at GSI, and returns the

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: conditional gcov instrumentation
  2009-09-07 19:51 conditional gcov instrumentation Hayawardh V
@ 2009-09-08  3:28 ` Hayawardh V
  2009-09-08 18:11   ` Richard Henderson
  0 siblings, 1 reply; 3+ messages in thread
From: Hayawardh V @ 2009-09-08  3:28 UTC (permalink / raw)
  To: gcc

Reattaching patch if not received.

--- gcc-4.4.0/gcc/tree-profile.c	2009-09-03 00:10:48.000000000 -0400
+++ gcc-4.4.0-gcov-ptr-src/gcc/tree-profile.c	2009-09-03
00:11:01.000000000 -0400
@@ -183,22 +183,25 @@
 static void
 tree_gen_edge_profiler (int edgeno, edge e)
 {
-  tree ref, one;
-  gimple stmt1, stmt2, stmt3;
+  tree ref;
+  gimple call;
+  tree decl, gcov_ctr_fn_type, ctr_ptr, gcov_type_ptr;

   /* 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 = gimple_build_assign (gcov_type_tmp_var, ref);
-  stmt2 = gimple_build_assign_with_ops (PLUS_EXPR, gcov_type_tmp_var,
-					gcov_type_tmp_var, one);
-  stmt3 = gimple_build_assign (unshare_expr (ref), gcov_type_tmp_var);
-  gsi_insert_on_edge (e, stmt1);
-  gsi_insert_on_edge (e, stmt2);
-  gsi_insert_on_edge (e, stmt3);
+  gcov_type_ptr = build_pointer_type (get_gcov_type());
+
+  gcov_ctr_fn_type = build_function_type_list(void_type_node,
gcov_type_ptr, NULL_TREE);
+
+  decl = build_decl(FUNCTION_DECL, get_identifier("__gcov_ctr"),
gcov_ctr_fn_type);
+  ctr_ptr = build_addr(ref, current_function_decl);
+
+  call = gimple_build_call (decl, 1, ctr_ptr);
+
+  gsi_insert_on_edge (e, call);
 }

 /* Emits code to get VALUE to instrument at GSI, and returns the



On Mon, Sep 7, 2009 at 3:51 PM, Hayawardh V<hayawardh@gmail.com> wrote:
> Hi,
> I have been working on a conditional gcov patch, that calls a function
> everytime the gcov counter is to be modified, so the function can
> decide how to increment the counter.
> The function's prototype is :
>
> void __gcov_ctr(gcov_type*) ;
>
> where gcov_type would be, for example, long long depending on the architecture.
>
> This would be useful for kernel coverage instrumentation (eg) tracking
> the coverage of only a particular pid, or for implementing atomic
> counters per cpu, and probably for many others.
> The libgcov could have a weak default implementation which increments
> the counter by 1 as usual, and those wanting to add their own
> implementation could do so. (Suggested by Peter Oberparleiter).
>
> I am attaching a patch. Please comment.
>
> Regards,
> Hayawardh
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: conditional gcov instrumentation
  2009-09-08  3:28 ` Hayawardh V
@ 2009-09-08 18:11   ` Richard Henderson
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Henderson @ 2009-09-08 18:11 UTC (permalink / raw)
  To: Hayawardh V; +Cc: gcc

On 09/07/2009 08:28 PM, Hayawardh V wrote:
> +  gcov_ctr_fn_type = build_function_type_list(void_type_node,
> gcov_type_ptr, NULL_TREE);
> +
> +  decl = build_decl(FUNCTION_DECL, get_identifier("__gcov_ctr"),
> gcov_ctr_fn_type);

Well you certainly don't want to be generating a
different function decl for every edge you instrument.


r~

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-09-08 18:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-07 19:51 conditional gcov instrumentation Hayawardh V
2009-09-08  3:28 ` Hayawardh V
2009-09-08 18:11   ` Richard Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).