Patchwork [google] Add libgcov interface for accessing profile directory (issue8726046)

login
register
mail settings
Submitter Teresa Johnson
Date April 17, 2013, 4 p.m.
Message ID <20130417160050.73DB880250@tjsboxrox.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/237271/
State New
Headers show

Comments

Teresa Johnson - April 17, 2013, 4 p.m.
Patch to add interface for querying the profile directory prefix
specified to the -fprofile-generate= option.

Google ref b/8629045.

Tested with regression tests and internal test. Ok for google branches?

2013-04-17  Teresa Johnson  <tejohnson@google.com>

	* libgcc/libgcov.c (__gcov_get_profile_prefix): New function.
	* gcc/tree-profile.c (tree_init_instrumentation): New function.
	* gcc/coverage.c (get_const_string_type): Make non-static.
	(coverage_init): Invoke tree_init_instrumentation().
	* gcc/coverage.h (get_const_string_type): Declare.
        (tree_init_instrumentation): Ditto.


--
This patch is available for review at http://codereview.appspot.com/8726046
Xinliang David Li - April 17, 2013, 4:22 p.m.
looks ok.

David

On Wed, Apr 17, 2013 at 9:00 AM, Teresa Johnson <tejohnson@google.com> wrote:
> Patch to add interface for querying the profile directory prefix
> specified to the -fprofile-generate= option.
>
> Google ref b/8629045.
>
> Tested with regression tests and internal test. Ok for google branches?
>
> 2013-04-17  Teresa Johnson  <tejohnson@google.com>
>
>         * libgcc/libgcov.c (__gcov_get_profile_prefix): New function.
>         * gcc/tree-profile.c (tree_init_instrumentation): New function.
>         * gcc/coverage.c (get_const_string_type): Make non-static.
>         (coverage_init): Invoke tree_init_instrumentation().
>         * gcc/coverage.h (get_const_string_type): Declare.
>         (tree_init_instrumentation): Ditto.
>
> Index: libgcc/libgcov.c
> ===================================================================
> --- libgcc/libgcov.c    (revision 197640)
> +++ libgcc/libgcov.c    (working copy)
> @@ -183,6 +183,14 @@ unsigned int __gcov_sampling_enabled ()
>    return __gcov_has_sampling;
>  }
>
> +/* Profile directory prefix specified to -fprofile-generate=.  */
> +extern char * __gcov_profile_prefix;
> +
> +char *__gcov_get_profile_prefix ()
> +{
> +  return __gcov_profile_prefix;
> +}
> +
>  /* Per thread sample counter.  */
>  THREAD_PREFIX gcov_unsigned_t __gcov_sample_counter = 0;
>
> Index: gcc/tree-profile.c
> ===================================================================
> --- gcc/tree-profile.c  (revision 197640)
> +++ gcc/tree-profile.c  (working copy)
> @@ -165,6 +165,9 @@ static struct pointer_set_t *instrumentation_to_be
>  /* extern __thread gcov_unsigned_t __gcov_sample_counter  */
>  static GTY(()) tree gcov_sample_counter_decl = NULL_TREE;
>
> +/* extern gcov_unsigned_t __gcov_profile_prefix  */
> +static tree GTY(()) gcov_profile_prefix_decl = NULL_TREE;
> +
>  /* extern gcov_unsigned_t __gcov_sampling_period  */
>  static tree GTY(()) gcov_sampling_period_decl = NULL_TREE;
>
> @@ -407,6 +410,41 @@ cleanup_instrumentation_sampling (void)
>      }
>  }
>
> +/* Initialization function for FDO instrumentation.  */
> +
> +void
> +tree_init_instrumentation (void)
> +{
> +  if (!gcov_profile_prefix_decl)
> +    {
> +      tree prefix_ptr;
> +      int prefix_len;
> +      tree prefix_string;
> +
> +      /* Construct an initializer for __gcov_profile_prefix.  */
> +      gcov_profile_prefix_decl =
> +        build_decl (UNKNOWN_LOCATION, VAR_DECL,
> +                    get_identifier ("__gcov_profile_prefix"),
> +                    get_const_string_type ());
> +      TREE_PUBLIC (gcov_profile_prefix_decl) = 1;
> +      DECL_ARTIFICIAL (gcov_profile_prefix_decl) = 1;
> +      make_decl_one_only (gcov_profile_prefix_decl,
> +                          DECL_ASSEMBLER_NAME (gcov_profile_prefix_decl));
> +      TREE_STATIC (gcov_profile_prefix_decl) = 1;
> +
> +      prefix_len = strlen (profile_data_prefix);
> +      prefix_string = build_string (prefix_len + 1, profile_data_prefix);
> +      TREE_TYPE (prefix_string) = build_array_type
> +          (char_type_node, build_index_type
> +           (build_int_cst (NULL_TREE, prefix_len)));
> +      prefix_ptr = build1 (ADDR_EXPR, get_const_string_type (),
> +                           prefix_string);
> +
> +      DECL_INITIAL (gcov_profile_prefix_decl) = prefix_ptr;
> +      varpool_finalize_decl (gcov_profile_prefix_decl);
> +    }
> +}
> +
>  /* Initialization function for FDO sampling.  */
>
>  void
> Index: gcc/coverage.c
> ===================================================================
> --- gcc/coverage.c      (revision 197640)
> +++ gcc/coverage.c      (working copy)
> @@ -227,7 +227,7 @@ get_gcov_unsigned_t (void)
>
>  /* Return the type node for const char *.  */
>
> -static tree
> +tree
>  get_const_string_type (void)
>  {
>    return build_pointer_type
> @@ -2879,6 +2879,7 @@ coverage_init (const char *filename, const char* s
>    /* Define variables which are referenced at runtime by libgcov.  */
>    if (profiling_enabled_p ())
>      {
> +      tree_init_instrumentation ();
>        tree_init_dyn_ipa_parameters ();
>        init_pmu_profiling ();
>        tree_init_instrumentation_sampling ();
> Index: gcc/coverage.h
> ===================================================================
> --- gcc/coverage.h      (revision 197640)
> +++ gcc/coverage.h      (working copy)
> @@ -82,6 +82,7 @@ extern bool pmu_data_present (void);
>
>  extern tree get_gcov_type (void);
>  extern tree get_gcov_unsigned_t (void);
> +extern tree get_const_string_type (void);
>
>  /* Mark this module as containing asm statements.  */
>  extern void coverage_has_asm_stmt (void);
> @@ -89,5 +90,6 @@ extern void coverage_has_asm_stmt (void);
>  /* Defined in tree-profile.c.  */
>  extern void tree_init_instrumentation_sampling (void);
>  extern void tree_init_dyn_ipa_parameters (void);
> +extern void tree_init_instrumentation (void);
>
>  #endif
>
> --
> This patch is available for review at http://codereview.appspot.com/8726046

Patch

Index: libgcc/libgcov.c
===================================================================
--- libgcc/libgcov.c	(revision 197640)
+++ libgcc/libgcov.c	(working copy)
@@ -183,6 +183,14 @@  unsigned int __gcov_sampling_enabled ()
   return __gcov_has_sampling;
 }
 
+/* Profile directory prefix specified to -fprofile-generate=.  */
+extern char * __gcov_profile_prefix;
+
+char *__gcov_get_profile_prefix ()
+{
+  return __gcov_profile_prefix;
+}
+
 /* Per thread sample counter.  */
 THREAD_PREFIX gcov_unsigned_t __gcov_sample_counter = 0;
 
Index: gcc/tree-profile.c
===================================================================
--- gcc/tree-profile.c	(revision 197640)
+++ gcc/tree-profile.c	(working copy)
@@ -165,6 +165,9 @@  static struct pointer_set_t *instrumentation_to_be
 /* extern __thread gcov_unsigned_t __gcov_sample_counter  */
 static GTY(()) tree gcov_sample_counter_decl = NULL_TREE;
 
+/* extern gcov_unsigned_t __gcov_profile_prefix  */
+static tree GTY(()) gcov_profile_prefix_decl = NULL_TREE;
+
 /* extern gcov_unsigned_t __gcov_sampling_period  */
 static tree GTY(()) gcov_sampling_period_decl = NULL_TREE;
 
@@ -407,6 +410,41 @@  cleanup_instrumentation_sampling (void)
     }
 }
 
+/* Initialization function for FDO instrumentation.  */
+
+void
+tree_init_instrumentation (void)
+{
+  if (!gcov_profile_prefix_decl)
+    {
+      tree prefix_ptr;
+      int prefix_len;
+      tree prefix_string;
+
+      /* Construct an initializer for __gcov_profile_prefix.  */
+      gcov_profile_prefix_decl =
+        build_decl (UNKNOWN_LOCATION, VAR_DECL,
+                    get_identifier ("__gcov_profile_prefix"),
+                    get_const_string_type ());
+      TREE_PUBLIC (gcov_profile_prefix_decl) = 1;
+      DECL_ARTIFICIAL (gcov_profile_prefix_decl) = 1;
+      make_decl_one_only (gcov_profile_prefix_decl,
+                          DECL_ASSEMBLER_NAME (gcov_profile_prefix_decl));
+      TREE_STATIC (gcov_profile_prefix_decl) = 1;
+
+      prefix_len = strlen (profile_data_prefix);
+      prefix_string = build_string (prefix_len + 1, profile_data_prefix);
+      TREE_TYPE (prefix_string) = build_array_type
+          (char_type_node, build_index_type
+           (build_int_cst (NULL_TREE, prefix_len)));
+      prefix_ptr = build1 (ADDR_EXPR, get_const_string_type (),
+                           prefix_string);
+
+      DECL_INITIAL (gcov_profile_prefix_decl) = prefix_ptr;
+      varpool_finalize_decl (gcov_profile_prefix_decl);
+    }
+}
+
 /* Initialization function for FDO sampling.  */
 
 void
Index: gcc/coverage.c
===================================================================
--- gcc/coverage.c	(revision 197640)
+++ gcc/coverage.c	(working copy)
@@ -227,7 +227,7 @@  get_gcov_unsigned_t (void)
 
 /* Return the type node for const char *.  */
 
-static tree
+tree
 get_const_string_type (void)
 {
   return build_pointer_type
@@ -2879,6 +2879,7 @@  coverage_init (const char *filename, const char* s
   /* Define variables which are referenced at runtime by libgcov.  */
   if (profiling_enabled_p ())
     {
+      tree_init_instrumentation ();
       tree_init_dyn_ipa_parameters ();
       init_pmu_profiling ();
       tree_init_instrumentation_sampling ();
Index: gcc/coverage.h
===================================================================
--- gcc/coverage.h	(revision 197640)
+++ gcc/coverage.h	(working copy)
@@ -82,6 +82,7 @@  extern bool pmu_data_present (void);
 
 extern tree get_gcov_type (void);
 extern tree get_gcov_unsigned_t (void);
+extern tree get_const_string_type (void);
 
 /* Mark this module as containing asm statements.  */
 extern void coverage_has_asm_stmt (void);
@@ -89,5 +90,6 @@  extern void coverage_has_asm_stmt (void);
 /* Defined in tree-profile.c.  */
 extern void tree_init_instrumentation_sampling (void);
 extern void tree_init_dyn_ipa_parameters (void);
+extern void tree_init_instrumentation (void);
 
 #endif