This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] profile feedback: -fprofile-use= and -fprofile-correction, correctness fixes and option semantic changes.
On Thu, Mar 27, 2008 at 1:52 AM, Jan Hubicka <jh@suse.cz> wrote:
> Hi,
> note that if we make -fprofile-use= shortcut, we probably could have
> also -fprofile-gen=
>
> > (or maybe even submitted, don't remember now).
> > But using atomic increment on highly multithreaded programs on high
> > core count systems
> > incur significant performance overhead.
> > So I'd rather like to see TLS counters than atomic increments.
> > Regardless, this option (-fprofile-correction) is completely
> > orthogonal to either atomic increment or TLS.
>
> Zdenek also had equivalent of TLS counters (before TLS architecture was
> added to GCC). The problem here that the counters can get pretty big,
> so for instance for Mozilla, you can end up producing quite few
> megabytes of extra data.
>
> Lets see where the patches are and try to get some to mainline.
> Profiling threaded applications is definitly important thing.
I think -fprofile-correction is orthogonal to atomic counter updates or TLS,
since it provides alternative way to other two methods.
Attached is the update patch for the first patch
- it now adds new options -fprofile-dir=, -fprofile-use=, -fprofile-generate=.
Changelog is below.
Profiled bootstrap and regtest in progress.
Seongbae
ChangeLog:
2008-03-27 Seongbae Park <seongbae.park@gmail.com>
* Makefile.tpl (.NOTPARALLEL): Serialize stageprofile libiberty.
* Makefile.in (.NOTPARALLEL): Serialize stageprofile libiberty
(updated through autogen).
gcc/ChangeLog:
2008-03-27 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/ChanceLog:
2008-03-27 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.
diff -r cb83744c2f8f Makefile.in
--- a/Makefile.in Wed Mar 26 18:00:34 2008 -0700
+++ b/Makefile.in Thu Mar 27 15:29:31 2008 -0700
@@ -395,6 +395,8 @@ PICFLAG_FOR_TARGET =
# The first rule in the file had better be this one. Don't put any above it.
# 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@
diff -r cb83744c2f8f Makefile.tpl
--- a/Makefile.tpl Wed Mar 26 18:00:34 2008 -0700
+++ b/Makefile.tpl Thu Mar 27 15:29:31 2008 -0700
@@ -398,6 +398,8 @@ PICFLAG_FOR_TARGET =
# The first rule in the file had better be this one. Don't put any above it.
# 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@
diff -r cb83744c2f8f gcc/common.opt
--- a/gcc/common.opt Wed Mar 26 18:00:34 2008 -0700
+++ b/gcc/common.opt Thu Mar 27 15:29:31 2008 -0700
@@ -811,13 +811,26 @@ Common Report Var(profile_arc_flag)
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)
diff -r cb83744c2f8f gcc/coverage.c
--- a/gcc/coverage.c Wed Mar 26 18:00:34 2008 -0700
+++ b/gcc/coverage.c Thu Mar 27 15:29:31 2008 -0700
@@ -545,7 +545,9 @@ int
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 @@ coverage_init (const char *filename)
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
diff -r cb83744c2f8f gcc/doc/invoke.texi
--- a/gcc/doc/invoke.texi Wed Mar 26 18:00:34 2008 -0700
+++ b/gcc/doc/invoke.texi Thu Mar 27 15:29:32 2008 -0700
@@ -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
@@ -6364,7 +6365,14 @@ 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}.
+If left unspecified, GCC will use the current directory as @var{path}.
+
@item -fprofile-generate
+@itemx -fprofile-generate=@var{path}
@opindex fprofile-generate
Enable options usually used for instrumenting application to produce
@@ -6374,7 +6382,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.
@@ -6386,6 +6398,9 @@ match the source code. This error can b
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
diff -r cb83744c2f8f gcc/opts.c
--- a/gcc/opts.c Wed Mar 26 18:00:34 2008 -0700
+++ b/gcc/opts.c Thu Mar 27 15:29:32 2008 -0700
@@ -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;
diff -r cb83744c2f8f gcc/testsuite/g++.dg/bprob/bprob.exp
--- a/gcc/testsuite/g++.dg/bprob/bprob.exp Wed Mar 26 18:00:34 2008 -0700
+++ b/gcc/testsuite/g++.dg/bprob/bprob.exp Thu Mar 27 15:29:32 2008 -0700
@@ -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 @@ load_lib profopt.exp
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 {
diff -r cb83744c2f8f gcc/testsuite/g++.dg/tree-prof/tree-prof.exp
--- a/gcc/testsuite/g++.dg/tree-prof/tree-prof.exp Wed Mar 26 18:00:34 2008 -0700
+++ b/gcc/testsuite/g++.dg/tree-prof/tree-prof.exp Thu Mar 27 15:29:32 2008 -0700
@@ -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 {}]
diff -r cb83744c2f8f gcc/testsuite/gcc.dg/matrix/matrix.exp
--- a/gcc/testsuite/gcc.dg/matrix/matrix.exp Wed Mar 26 18:00:34 2008 -0700
+++ b/gcc/testsuite/gcc.dg/matrix/matrix.exp Thu Mar 27 15:29:32 2008 -0700
@@ -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 {}]
diff -r cb83744c2f8f gcc/testsuite/gcc.dg/profile-dir-1.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gcc/testsuite/gcc.dg/profile-dir-1.c Thu Mar 27 15:29:32 2008 -0700
@@ -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 } } */
diff -r cb83744c2f8f gcc/testsuite/gcc.dg/profile-dir-2.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gcc/testsuite/gcc.dg/profile-dir-2.c Thu Mar 27 15:29:32 2008 -0700
@@ -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 } } */
diff -r cb83744c2f8f gcc/testsuite/gcc.dg/profile-dir-3.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gcc/testsuite/gcc.dg/profile-dir-3.c Thu Mar 27 15:29:32 2008 -0700
@@ -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 } } */
diff -r cb83744c2f8f gcc/testsuite/gcc.dg/struct/struct-reorg.exp
--- a/gcc/testsuite/gcc.dg/struct/struct-reorg.exp Wed Mar 26 18:00:34 2008 -0700
+++ b/gcc/testsuite/gcc.dg/struct/struct-reorg.exp Thu Mar 27 15:29:32 2008 -0700
@@ -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 {}]
diff -r cb83744c2f8f gcc/testsuite/gcc.dg/tree-prof/tree-prof.exp
--- a/gcc/testsuite/gcc.dg/tree-prof/tree-prof.exp Wed Mar 26 18:00:34 2008 -0700
+++ b/gcc/testsuite/gcc.dg/tree-prof/tree-prof.exp Thu Mar 27 15:29:32 2008 -0700
@@ -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 {}]
diff -r cb83744c2f8f gcc/testsuite/gcc.misc-tests/bprob.exp
--- a/gcc/testsuite/gcc.misc-tests/bprob.exp Wed Mar 26 18:00:34 2008 -0700
+++ b/gcc/testsuite/gcc.misc-tests/bprob.exp Thu Mar 27 15:29:32 2008 -0700
@@ -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 @@ load_lib profopt.exp
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]] {
diff -r cb83744c2f8f gcc/toplev.c
--- a/gcc/toplev.c Wed Mar 26 18:00:34 2008 -0700
+++ b/gcc/toplev.c Thu Mar 27 15:29:32 2008 -0700
@@ -151,6 +151,9 @@ const char *dump_base_name;
/* Name to use as a base for auxiliary output files. */
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. */
diff -r cb83744c2f8f gcc/toplev.h
--- a/gcc/toplev.h Wed Mar 26 18:00:34 2008 -0700
+++ b/gcc/toplev.h Thu Mar 27 15:29:32 2008 -0700
@@ -111,6 +111,7 @@ extern const char *dump_base_name;
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;