public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Regarding gcov instrumentation in gcc, tree-profile.c
@ 2009-07-12 17:44 Hayawardh V
  0 siblings, 0 replies; only message in thread
From: Hayawardh V @ 2009-07-12 17:44 UTC (permalink / raw)
  To: gcc

Hi,

I am looking to change the edge instrumentation for gcov. Instead of
just incrementing the edge count by 1, I want it to call an (external)
function which determines whether it should increment, and depending
on the answer, increment the edge.

I modified the tree_gen_edge_profiler function in tree-profile.c as
follows in gcc-4.4, (changed lines prefixed by [*]) :
(to instrument:

temp = function_return_value(); /* function returns 0 or 1 */
edge_count = edge_count + temp;

)

static void
tree_gen_edge_profiler (int edgeno, edge e)
{
 tree ref, one;
 gimple stmt1, stmt2, stmt3;
[*] gimple call;
[*] tree lhs, decl, should_gcov_name, should_gcov_type;

 /* 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);

[*] should_gcov_name = get_identifier("__should_gcov");
[*] should_gcov_type = build_function_type(gcov_type_node, NULL_TREE
/* no args */);

[*] decl = build_decl(FUNCTION_DECL, should_gcov_name, should_gcov_type);

[*] lhs = create_tmp_var (TREE_TYPE (TREE_TYPE (decl)), NULL);
[*] call = gimple_build_call (decl, 0);
[*] gimple_call_set_lhs (call, lhs);

  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, lhs);
  stmt3 = gimple_build_assign (unshare_expr (ref), gcov_type_tmp_var);
[*]  gsi_insert_on_edge (e, call);
  gsi_insert_on_edge (e, stmt1);
  gsi_insert_on_edge (e, stmt2);
  gsi_insert_on_edge (e, stmt3);
}
When I compile a program using this gcc and -fprofile-arcs, it does
ask for the function __should_gcov. But when I use gcov to read the
gcda file after running the program, there is some format error and it
terminates stating buffer overflow. Hence, the format of the gcda file
is somehow corrupt.
Is there some other place I should modify because of my changes, like
the number of basic blocks etc? (I don't care about the branch
probability etc options -- I just want the line execution count) .
Thanks,
Hayawardh

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-07-12 17:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-12 17:44 Regarding gcov instrumentation in gcc, tree-profile.c Hayawardh V

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).