This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[google] Fix bugs in sampled profile collection
- From: Easwaran Raman <eraman at google dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Xinliang David Li <davidxl at google dot com>
- Date: Fri, 30 Sep 2011 18:54:47 -0700
- Subject: [google] Fix bugs in sampled profile collection
This fixes two issues with sampled profile collection. It delays
cleanup of instrumentation_to_be_sampled after all callgraph nodes
have been instrumented and prevents gcov_sample_counter_decl and
gcov_sampling_rate_decl from being garbage collected.
Ok for google/gcc-4_6 and google/main branches?
-Easwaran
2011-09-30 Easwaran Raman <eraman@google.com>
* tree-profile.c (gcov_sample_counter_decl): Add GTY marker.
(gcov_sampling_rate_decl): Likewise.
(add_sampling_to_edge_counters): Do not free
instrumentation_to_be_sampled.
(cleanup_instrumentation_sampling): New function.
(tree_profiling): Call cleanup_instrumentation_sampling at the end.
testsuite/ChangeLog.google-4_6:
2011-09-30 Easwaran Raman <eraman@google.com>
* gcc.dg/sample-profile-generate-1.c: New test.
Index: gcc/testsuite/gcc.dg/sample-profile-generate-1.c
===================================================================
--- gcc/testsuite/gcc.dg/sample-profile-generate-1.c (revision 0)
+++ gcc/testsuite/gcc.dg/sample-profile-generate-1.c (revision 0)
@@ -0,0 +1,26 @@
+/* { dg-do compile} */
+/* { dg-options "-O2 -fprofile-generate -fprofile-generate-sampling" } */
+
+void foobar(int);
+
+void
+foo (void)
+{
+ int i;
+ for (i = 0; i < 100; i++)
+ {
+ foobar(i);
+ }
+}
+
+void
+bar (void)
+{
+ int i;
+ for (i = 0; i < 100; i++)
+ {
+ foobar(i);
+ }
+}
+
+/* { dg-final { cleanup-coverage-files } } */
Index: tree-profile.c
===================================================================
--- tree-profile.c (revision 178897)
+++ tree-profile.c (working copy)
@@ -163,10 +163,10 @@ init_ic_make_global_vars (void)
static struct pointer_set_t *instrumentation_to_be_sampled = NULL;
/* extern __thread gcov_unsigned_t __gcov_sample_counter */
-static tree gcov_sample_counter_decl = NULL_TREE;
+static GTY(()) tree gcov_sample_counter_decl = NULL_TREE;
/* extern gcov_unsigned_t __gcov_sampling_rate */
-static tree gcov_sampling_rate_decl = NULL_TREE;
+static GTY(()) tree gcov_sampling_rate_decl = NULL_TREE;
/* forward declaration. */
void gimple_init_instrumentation_sampling (void);
@@ -281,9 +281,13 @@ add_sampling_to_edge_counters (void)
break;
}
}
+}
+static void
+cleanup_instrumentation_sampling (void)
+{
/* Free the bitmap. */
- if (instrumentation_to_be_sampled)
+ if (flag_profile_generate_sampling && instrumentation_to_be_sampled)
{
pointer_set_destroy (instrumentation_to_be_sampled);
instrumentation_to_be_sampled = NULL;
@@ -1452,6 +1456,7 @@ tree_profiling (void)
}
del_node_map();
+ cleanup_instrumentation_sampling();
return 0;
}