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]

Re: [PATCH] profile feedback: -fprofile-use= and -fprofile-correction, correctness fixes and option semantic changes.


The patch updated per comment has been applied to the mainline as
revision 133774.
Changelog is enclosed, and the applied patch is attached.
Thanks!

Seongbae

gcc/ChangeLog
2008-03-31  Seongbae Park <seongbae.park@gmail.com>

        * common.opt (fprofile-dir=, fprofile-use=, fprofile-generate=):
        New options
        (fprofile-use): Add var flag_profile_use
        * coverage.c (coverage_begin_output): Do not open a gcno file for output
        only if -ftest-coverage is set.
        Do not add getpwd() to gcda file path.
        (build_gcov_info): Check the new flag
        flag_profile_datafile_relative_path.
        (coverage_init): Use profile_data_prefix.
        Read profile counter only if flag_profile_use is set.
        * opts.c (common_handle_option): New option fprofile-use=,
        fprofile-dir=, fprofile-generate=.
        * toplev.c (profile_data_prefix): New variable definition.
        * toplev.h (profile_data_prefix): New declaration.
        * doc/invoke.tex (Option Summary, Optimization Options):
        Add new options.

gcc/testsuite/ChangeLog
2008-03-31  Seongbae Park <seongbae.park@gmail.com>

        * g++.db/bprob/bprob.exp: Do not check gcno files.
        Use -fprofile-use for profile use.
        * gcc.misc-tests/bprob.exp: Ditto.
        * g++.dg/tree-pro/tree-prof.exp: Do not check gcno files.
        * gcc.dg/matrix/matrix.exp: Ditto.
        * gcc.dg/struct/struct-reorg.exp: Ditto.
        * gcc.dg/tree-prof/tree-prof.exp: Ditto.
        * gcc.dg/profile-dir-1.c: New test.
        * gcc.dg/profile-dir-2.c: New test.
        * gcc.dg/profile-dir-3.c: New test.

ChangeLog
2008-03-31  Seongbae Park <seongbae.park@gmail.com>

        * Makefile.tpl (.NOTPARALLEL): Serialize stageprofile libiberty.
        * Makefile.in (.NOTPARALLEL): Regenerate.
Index: Makefile.in
===================================================================
--- Makefile.in	(revision 133772)
+++ Makefile.in	(working copy)
@@ -394,6 +394,8 @@ LDFLAGS_FOR_TARGET = 
 # This lives here to allow makefile fragments to contain dependencies.
 all:
 
+.NOTPARALLEL: all-stageprofile-libiberty
+
 #### host and target specific makefile fragments come in here.
 @target_makefile_frag@
 @alphaieee_frag@
Index: gcc/doc/invoke.texi
===================================================================
--- gcc/doc/invoke.texi	(revision 133772)
+++ gcc/doc/invoke.texi	(working copy)
@@ -341,8 +341,9 @@ Objective-C and Objective-C++ Dialects}.
 -fno-toplevel-reorder -fno-trapping-math -fno-zero-initialized-in-bss @gol
 -fomit-frame-pointer -foptimize-register-move -foptimize-sibling-calls @gol
 -fpeel-loops -fpredictive-commoning -fprefetch-loop-arrays @gol
--fprofile-generate -fprofile-use -fprofile-values -freciprocal-math @gol
--fregmove -frename-registers -freorder-blocks @gol
+-fprofile-dir=@var{path} -fprofile-generate -fprofile-generate=@var{path} @gol
+-fprofile-use -fprofile-use=@var{path} -fprofile-values @gol
+-freciprocal-math -fregmove -frename-registers -freorder-blocks @gol
 -freorder-blocks-and-partition -freorder-functions @gol
 -frerun-cse-after-loop -freschedule-modulo-scheduled-loops @gol
 -frounding-math -frtl-abstract-sequences -fsched2-use-superblocks @gol
@@ -6311,7 +6312,19 @@ and occasionally eliminate the copy.
 
 Enabled at levels @option{-O}, @option{-O2}, @option{-O3}, @option{-Os}.
 
+@item -fprofile-dir=@var{path}
+@opindex fprofile-dir
+
+Set the directory to search the profile data files in to @var{path}.
+This option affects only the profile data generated by
+@option{-fprofile-generate}, @option{-ftest-coverage}, @option{-fprofile-arcs}
+and used by @option{-fprofile-use} and @option{-fbranch-probabilities} 
+and its related options.
+By default, GCC will use the current directory as @var{path}
+thus the profile data file will appear in the same directory as the object file.
+
 @item -fprofile-generate
+@itemx -fprofile-generate=@var{path}
 @opindex fprofile-generate
 
 Enable options usually used for instrumenting application to produce
@@ -6321,7 +6334,11 @@ compiling and when linking your program.
 
 The following options are enabled: @code{-fprofile-arcs}, @code{-fprofile-values}, @code{-fvpt}.
 
+If @var{path} is specified, GCC will look at the @var{path} to find
+the profile feeedback data files. See @option{-fprofile-dir}.
+
 @item -fprofile-use
+@itemx -fprofile-use=@var{path}
 @opindex fprofile-use
 Enable profile feedback directed optimizations, and optimizations
 generally profitable only with profile feedback available.
@@ -6333,6 +6350,9 @@ By default, GCC emits an error message i
 match the source code.  This error can be turned into a warning by using
 @option{-Wcoverage-mismatch}.  Note this may result in poorly optimized
 code.
+
+If @var{path} is specified, GCC will look at the @var{path} to find
+the profile feedback data files. See @option{-fprofile-dir}.
 @end table
 
 The following options control compiler behavior regarding floating
Index: gcc/toplev.c
===================================================================
--- gcc/toplev.c	(revision 133772)
+++ gcc/toplev.c	(working copy)
@@ -152,6 +152,9 @@ const char *dump_base_name;
 
 const char *aux_base_name;
 
+/* Prefix for profile data files */
+const char *profile_data_prefix;
+
 /* A mask of target_flags that includes bit X if X was set or cleared
    on the command line.  */
 
Index: gcc/toplev.h
===================================================================
--- gcc/toplev.h	(revision 133772)
+++ gcc/toplev.h	(working copy)
@@ -111,6 +111,7 @@ extern const char *progname;
 extern const char *dump_base_name;
 extern const char *aux_base_name;
 extern const char *aux_info_file_name;
+extern const char *profile_data_prefix;
 extern const char *asm_file_name;
 extern bool exit_after_options;
 
Index: gcc/testsuite/gcc.dg/profile-dir-2.c
===================================================================
--- gcc/testsuite/gcc.dg/profile-dir-2.c	(revision 0)
+++ gcc/testsuite/gcc.dg/profile-dir-2.c	(revision 0)
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fprofile-generate" } */
+/* { dg-final { scan-assembler "/profile-dir-2.gcda" } } */
+
+int
+main(void)
+{
+  return 0;
+}
+
+/* { dg-final { cleanup-coverage-files } } */
Index: gcc/testsuite/gcc.dg/matrix/matrix.exp
===================================================================
--- gcc/testsuite/gcc.dg/matrix/matrix.exp	(revision 133772)
+++ gcc/testsuite/gcc.dg/matrix/matrix.exp	(working copy)
@@ -36,7 +36,7 @@ if { ![check_profiling_available ""] } {
 
 # The procedures in profopt.exp need these parameters.
 set tool gcc
-set prof_ext "gcda gcno"
+set prof_ext "gcda"
 
 # Override the list defined in profopt.exp.
 set PROFOPT_OPTIONS [list {}]
Index: gcc/testsuite/gcc.dg/struct/struct-reorg.exp
===================================================================
--- gcc/testsuite/gcc.dg/struct/struct-reorg.exp	(revision 133772)
+++ gcc/testsuite/gcc.dg/struct/struct-reorg.exp	(working copy)
@@ -36,7 +36,7 @@ if { ![check_profiling_available ""] } {
 
 # The procedures in profopt.exp need these parameters.
 set tool gcc
-set prof_ext "gcda gcno"
+set prof_ext "gcda"
 
 # Override the list defined in profopt.exp.
 set PROFOPT_OPTIONS [list {}]
Index: gcc/testsuite/gcc.dg/tree-prof/tree-prof.exp
===================================================================
--- gcc/testsuite/gcc.dg/tree-prof/tree-prof.exp	(revision 133772)
+++ gcc/testsuite/gcc.dg/tree-prof/tree-prof.exp	(working copy)
@@ -26,7 +26,7 @@ if { ![check_profiling_available ""] } {
 
 # The procedures in profopt.exp need these parameters.
 set tool gcc
-set prof_ext "gcda gcno"
+set prof_ext "gcda"
 
 # Override the list defined in profopt.exp.
 set PROFOPT_OPTIONS [list {}]
Index: gcc/testsuite/gcc.dg/profile-dir-1.c
===================================================================
--- gcc/testsuite/gcc.dg/profile-dir-1.c	(revision 0)
+++ gcc/testsuite/gcc.dg/profile-dir-1.c	(revision 0)
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fprofile-generate=." } */
+/* { dg-final { scan-assembler "\"./profile-dir-1.gcda\"" } } */
+
+int
+main(void)
+{
+  return 0;
+}
+
+/* { dg-final { cleanup-coverage-files } } */
Index: gcc/testsuite/gcc.dg/profile-dir-3.c
===================================================================
--- gcc/testsuite/gcc.dg/profile-dir-3.c	(revision 0)
+++ gcc/testsuite/gcc.dg/profile-dir-3.c	(revision 0)
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fprofile-generate -fprofile-dir=." } */
+/* { dg-final { scan-assembler "\"./profile-dir-3.gcda\"" } } */
+
+int
+main(void)
+{
+  return 0;
+}
+
+/* { dg-final { cleanup-coverage-files } } */
Index: gcc/testsuite/gcc.misc-tests/bprob.exp
===================================================================
--- gcc/testsuite/gcc.misc-tests/bprob.exp	(revision 133772)
+++ gcc/testsuite/gcc.misc-tests/bprob.exp	(working copy)
@@ -27,7 +27,7 @@ if { ![check_profiling_available "-fprof
 
 # The procedures in profopt.exp need these parameters.
 set tool gcc
-set prof_ext "gcda gcno"
+set prof_ext "gcda"
 set perf_ext tim
 
 # Override the list defined in profopt.exp.
@@ -48,7 +48,7 @@ if $tracelevel then {
 load_lib profopt.exp
 
 set profile_options "-fprofile-arcs"
-set feedback_options "-fbranch-probabilities"
+set feedback_options "-fprofile-use"
 
 foreach profile_option $profile_options feedback_option $feedback_options {
     foreach src [lsort [glob -nocomplain $srcdir/$subdir/bprob-*.c]] {
Index: gcc/testsuite/g++.dg/tree-prof/tree-prof.exp
===================================================================
--- gcc/testsuite/g++.dg/tree-prof/tree-prof.exp	(revision 133772)
+++ gcc/testsuite/g++.dg/tree-prof/tree-prof.exp	(working copy)
@@ -26,7 +26,7 @@ if { ![check_profiling_available ""] } {
 
 # The procedures in profopt.exp need these parameters.
 set tool g++
-set prof_ext "gcda gcno"
+set prof_ext "gcda"
 
 # Override the list defined in profopt.exp.
 set PROFOPT_OPTIONS [list {}]
Index: gcc/testsuite/g++.dg/bprob/bprob.exp
===================================================================
--- gcc/testsuite/g++.dg/bprob/bprob.exp	(revision 133772)
+++ gcc/testsuite/g++.dg/bprob/bprob.exp	(working copy)
@@ -27,7 +27,7 @@ if { ![check_profiling_available "-fprof
 
 # The procedures in profopt.exp need these parameters.
 set tool g++
-set prof_ext "gcda gcno"
+set prof_ext "gcda"
 
 if $tracelevel then {
     strace $tracelevel
@@ -51,7 +51,7 @@ if $tracelevel then {
 load_lib profopt.exp
 
 set profile_options "-fprofile-arcs"
-set feedback_options "-fbranch-probabilities"
+set feedback_options "-fprofile-use"
 
 # Main loop.
 foreach profile_option $profile_options feedback_option $feedback_options {
Index: gcc/opts.c
===================================================================
--- gcc/opts.c	(revision 133772)
+++ gcc/opts.c	(working copy)
@@ -1716,6 +1716,15 @@ common_handle_option (size_t scode, cons
       flag_inline_functions_set = true;
       break;
 
+    case OPT_fprofile_dir_:
+      profile_data_prefix = xstrdup (arg);
+      break;
+
+    case OPT_fprofile_use_:
+      profile_data_prefix = xstrdup (arg);
+      flag_profile_use = true;
+      value = true;
+      /* No break here - do -fprofile-use processing. */
     case OPT_fprofile_use:
       if (!flag_branch_probabilities_set)
         flag_branch_probabilities = value;
@@ -1733,6 +1742,10 @@ common_handle_option (size_t scode, cons
         flag_inline_functions = value;
       break;
 
+    case OPT_fprofile_generate_:
+      profile_data_prefix = xstrdup (arg);
+      value = true;
+      /* No break here - do -fprofile-generate processing. */
     case OPT_fprofile_generate:
       if (!profile_arc_flag_set)
         profile_arc_flag = value;
Index: gcc/coverage.c
===================================================================
--- gcc/coverage.c	(revision 133772)
+++ gcc/coverage.c	(working copy)
@@ -545,7 +545,9 @@ compute_checksum (void)
 int
 coverage_begin_output (void)
 {
-  if (no_coverage)
+  /* We don't need to output .gcno file unless we're under -ftest-coverage
+     (e.g. -fprofile-arcs/generate/use don't need .gcno to work). */
+  if (no_coverage || !flag_test_coverage)
     return 0;
 
   if (!bbg_function_announced)
@@ -802,8 +804,7 @@ build_gcov_info (void)
   tree field, fields = NULL_TREE;
   tree value = NULL_TREE;
   tree filename_string;
-  char *filename;
-  int filename_len;
+  int da_file_name_len;
   unsigned n_fns;
   const struct function_list *fn;
   tree string_type;
@@ -842,17 +843,11 @@ build_gcov_info (void)
   field = build_decl (FIELD_DECL, NULL_TREE, string_type);
   TREE_CHAIN (field) = fields;
   fields = field;
-  filename = getpwd ();
-  filename = (filename && da_file_name[0] != '/'
-	      ? concat (filename, "/", da_file_name, NULL)
-	      : da_file_name);
-  filename_len = strlen (filename);
-  filename_string = build_string (filename_len + 1, filename);
-  if (filename != da_file_name)
-    free (filename);
+  da_file_name_len = strlen (da_file_name);
+  filename_string = build_string (da_file_name_len + 1, da_file_name);
   TREE_TYPE (filename_string) = build_array_type
     (char_type_node, build_index_type
-     (build_int_cst (NULL_TREE, filename_len)));
+     (build_int_cst (NULL_TREE, da_file_name_len)));
   value = tree_cons (field, build1 (ADDR_EXPR, string_type, filename_string),
 		     value);
 
@@ -979,10 +974,27 @@ void
 coverage_init (const char *filename)
 {
   int len = strlen (filename);
+  /* + 1 for extra '/', in case prefix doesn't end with /.  */
+  int prefix_len;
+ 
+  if (profile_data_prefix == 0 && filename[0] != '/')
+    profile_data_prefix = getpwd ();
+
+  prefix_len = (profile_data_prefix) ? strlen (profile_data_prefix) + 1 : 0;
 
   /* Name of da file.  */
-  da_file_name = XNEWVEC (char, len + strlen (GCOV_DATA_SUFFIX) + 1);
-  strcpy (da_file_name, filename);
+  da_file_name = XNEWVEC (char, len + strlen (GCOV_DATA_SUFFIX) 
+			  + prefix_len + 1);
+
+  if (profile_data_prefix)
+    {
+      strcpy (da_file_name, profile_data_prefix);
+      da_file_name[prefix_len - 1] = '/';
+      da_file_name[prefix_len] = 0;
+    }
+  else
+    da_file_name[0] = 0;
+  strcat (da_file_name, filename);
   strcat (da_file_name, GCOV_DATA_SUFFIX);
 
   /* Name of bbg file.  */
@@ -990,7 +1002,8 @@ coverage_init (const char *filename)
   strcpy (bbg_file_name, filename);
   strcat (bbg_file_name, GCOV_NOTE_SUFFIX);
 
-  read_counts_file ();
+  if (flag_profile_use)
+    read_counts_file ();
 }
 
 /* Performs file-level cleanup.  Close graph file, generate coverage
Index: gcc/common.opt
===================================================================
--- gcc/common.opt	(revision 133772)
+++ gcc/common.opt	(working copy)
@@ -815,14 +815,27 @@ fprofile-arcs
 Common Report Var(profile_arc_flag)
 Insert arc-based program profiling code
 
+fprofile-dir=
+Common Joined RejectNegative
+Set the top-level directory for storing the profile data.
+The default is 'pwd'.
+
 fprofile-generate
 Common
 Enable common options for generating profile info for profile feedback directed optimizations
 
+fprofile-generate=
+Common Joined RejectNegative
+Enable common options for generating profile info for profile feedback directed optimizations, and set -fprofile-dir=
+
 fprofile-use
-Common
+Common Var(flag_profile_use)
 Enable common options for performing profile feedback directed optimizations
 
+fprofile-use=
+Common Joined RejectNegative
+Enable common options for performing profile feedback directed optimizations, and set -fprofile-dir=
+
 fprofile-values
 Common Report Var(flag_profile_values)
 Insert code to profile values of expressions
Index: Makefile.tpl
===================================================================
--- Makefile.tpl	(revision 133772)
+++ Makefile.tpl	(working copy)
@@ -397,6 +397,8 @@ LDFLAGS_FOR_TARGET = 
 # This lives here to allow makefile fragments to contain dependencies.
 all:
 
+.NOTPARALLEL: all-stageprofile-libiberty
+
 #### host and target specific makefile fragments come in here.
 @target_makefile_frag@
 @alphaieee_frag@

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