This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Introduce -fprofile-update=maybe-atomic
- From: Martin Liška <mliska at suse dot cz>
- To: Nathan Sidwell <nathan at acm dot org>, Jeff Law <law at redhat dot com>, Andi Kleen <andi at firstfloor dot org>
- Cc: gcc-patches at gcc dot gnu dot org, jh at suse dot cz, David Edelsohn <dje dot gcc at gmail dot com>
- Date: Thu, 13 Oct 2016 17:34:25 +0200
- Subject: [PATCH] Introduce -fprofile-update=maybe-atomic
- Authentication-results: sourceware.org; auth=none
- References: <87f2bc4f-c4df-eadd-aec6-a937ed0ccaba@acm.org> <1253ac69-3301-f185-e43a-a34cadf8f51e@suse.cz> <67fda6d2-9b3e-a0d1-effc-34e1115030b2@acm.org> <b62f3336-b332-048f-ed2f-9392824f0b84@suse.cz> <1ff3cc75-7cee-79f3-395b-ef7a4d286a3d@acm.org> <04a05835-4666-4d7d-c1a9-d4bcc4ea924a@suse.cz> <ac9182f6-7164-9426-c55b-c13a1a30d3bd@suse.cz> <87k2fpdatl.fsf@tassilo.jf.intel.com> <6f8b1905-818b-bfff-1bf3-5ba04f3b4b64@suse.cz> <c526f177-0304-787d-c57d-3fd3e49a57e5@redhat.com> <20160818155130.GE5871@two.firstfloor.org> <631cf1bd-8ae9-f07b-5672-5084b699f650@redhat.com> <2c750f4c-c96c-2b22-43ae-53bbebf18af8@suse.cz> <73aa44d7-5287-e4b8-6188-a87d52d3d6b9@acm.org> <9aca1f7c-e7eb-e101-249e-8b5edd21cd48@suse.cz>
Hello.
As it's very hard to guess from GCC driver whether a target supports atomic updates
for GCOV counter or not, I decided to come up with a new option value (maybe-atomic),
that would be transformed in a corresponding value (single or atomic) in tree-profile.c.
The GCC driver selects the option when -pthread is present in the command line.
That should fix all tests failures seen on AIX target.
Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.
Ready to be installed?
Martin
>From 1d00b7b4d42d080fe4d6cd51a03829b0fe525c9d Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Wed, 12 Oct 2016 15:05:49 +0200
Subject: [PATCH] Introduce -fprofile-update=maybe-atomic
gcc/ChangeLog:
2016-10-12 Martin Liska <mliska@suse.cz>
* common.opt: Add maybe-atomic as a new enum value for
-fprofile-update.
* coretypes.h: Likewise.
* doc/invoke.texi: Document the new option value.
* gcc.c: Replace atomic with maybe-atomic. Remove warning.
* tree-profile.c (tree_profiling): Select default value
of -fprofile-update when 'maybe-atomic' is selected.
gcc/testsuite/ChangeLog:
2016-10-12 Martin Liska <mliska@suse.cz>
* gcc.dg/no_profile_instrument_function-attr-1.c: Update test
to match scanned pattern.
* gcc.dg/tree-ssa/ssa-lim-11.c: Likewise.
---
gcc/common.opt | 5 +++-
gcc/coretypes.h | 3 +-
gcc/doc/invoke.texi | 11 +++++--
gcc/gcc.c | 6 +---
.../gcc.dg/no_profile_instrument_function-attr-1.c | 2 +-
gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-11.c | 2 +-
gcc/tree-profile.c | 35 +++++++++++-----------
7 files changed, 35 insertions(+), 29 deletions(-)
diff --git a/gcc/common.opt b/gcc/common.opt
index 15679c5..d6c5acd 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1937,7 +1937,7 @@ Enable correction of flow inconsistent profile data input.
fprofile-update=
Common Joined RejectNegative Enum(profile_update) Var(flag_profile_update) Init(PROFILE_UPDATE_SINGLE)
--fprofile-update=[single|atomic] Set the profile update method.
+-fprofile-update=[single|atomic|maybe-atomic] Set the profile update method.
Enum
Name(profile_update) Type(enum profile_update) UnknownError(unknown profile update method %qs)
@@ -1948,6 +1948,9 @@ Enum(profile_update) String(single) Value(PROFILE_UPDATE_SINGLE)
EnumValue
Enum(profile_update) String(atomic) Value(PROFILE_UPDATE_ATOMIC)
+EnumValue
+Enum(profile_update) String(maybe-atomic) Value(PROFILE_UPDATE_MAYBE_ATOMIC)
+
fprofile-generate
Common
Enable common options for generating profile info for profile feedback directed optimizations.
diff --git a/gcc/coretypes.h b/gcc/coretypes.h
index fe1e984..aec2a6e 100644
--- a/gcc/coretypes.h
+++ b/gcc/coretypes.h
@@ -177,7 +177,8 @@ enum offload_abi {
/* Types of profile update methods. */
enum profile_update {
PROFILE_UPDATE_SINGLE,
- PROFILE_UPDATE_ATOMIC
+ PROFILE_UPDATE_ATOMIC,
+ PROFILE_UPDATE_MAYBE_ATOMIC
};
/* Types of unwind/exception handling info that can be generated. */
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index c11f1d5..eb6cae3 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -10315,13 +10315,18 @@ To optimize the program based on the collected profile information, use
Alter the update method for an application instrumented for profile
feedback based optimization. The @var{method} argument should be one of
-@samp{single} or @samp{atomic}. The first one is useful for single-threaded
-applications, while the second one prevents profile corruption by emitting
-thread-safe code.
+@samp{single}, @samp{atomic} or @samp{maybe-atomic}.
+The first one is useful for single-threaded applications,
+while the second one prevents profile corruption by emitting thread-safe code.
@strong{Warning:} When an application does not properly join all threads
(or creates an detached thread), a profile file can be still corrupted.
+Using @samp{maybe-atomic} would be transformed either to @samp{atomic},
+when supported by a target, or to @samp{single} otherwise. The GCC driver
+automatically selects @samp{maybe-atomic} when @option{-pthread}
+is present in the command line.
+
@item -fsanitize=address
@opindex fsanitize=address
Enable AddressSanitizer, a fast memory error detector.
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 5213cb0..1959fc7 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -1144,11 +1144,7 @@ static const char *cc1_options =
%{coverage:-fprofile-arcs -ftest-coverage}\
%{fprofile-arcs|fprofile-generate*|coverage:\
%{!fprofile-update=single:\
- %{pthread:-fprofile-update=atomic}}}\
- %{fprofile-update=single:\
- %{fprofile-arcs|fprofile-generate*|coverage:\
- %{pthread:%n-fprofile-update=atomic should be used\
- for a multithreaded application}}}";
+ %{pthread:-fprofile-update=maybe-atomic}}}";
static const char *asm_options =
"%{-target-help:%:print-asm-header()} "
diff --git a/gcc/testsuite/gcc.dg/no_profile_instrument_function-attr-1.c b/gcc/testsuite/gcc.dg/no_profile_instrument_function-attr-1.c
index c93d171..29bffd90 100644
--- a/gcc/testsuite/gcc.dg/no_profile_instrument_function-attr-1.c
+++ b/gcc/testsuite/gcc.dg/no_profile_instrument_function-attr-1.c
@@ -1,4 +1,4 @@
-/* { dg-options "-O2 -fprofile-generate -fdump-tree-optimized" } */
+/* { dg-options "-O2 -fprofile-generate -fprofile-update=single -fdump-tree-optimized" } */
__attribute__ ((no_profile_instrument_function))
int foo()
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-11.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-11.c
index e4c11aa..4c38982 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-11.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-11.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O -fprofile-arcs -fdump-tree-lim2-details" } */
+/* { dg-options "-O -fprofile-arcs -fprofile-update=single -fdump-tree-lim2-details" } */
/* { dg-require-profiling "-fprofile-generate" } */
struct thread_param
diff --git a/gcc/tree-profile.c b/gcc/tree-profile.c
index 1f45b99..fcef2e5 100644
--- a/gcc/tree-profile.c
+++ b/gcc/tree-profile.c
@@ -534,25 +534,26 @@ tree_profiling (void)
struct cgraph_node *node;
/* Verify whether we can utilize atomic update operations. */
- if (flag_profile_update == PROFILE_UPDATE_ATOMIC)
+ bool can_support_atomic = false;
+ unsigned HOST_WIDE_INT gcov_type_size
+ = tree_to_uhwi (TYPE_SIZE_UNIT (get_gcov_type ()));
+ if (gcov_type_size == 4)
+ can_support_atomic
+ = HAVE_sync_compare_and_swapsi || HAVE_atomic_compare_and_swapsi;
+ else if (gcov_type_size == 8)
+ can_support_atomic
+ = HAVE_sync_compare_and_swapdi || HAVE_atomic_compare_and_swapdi;
+
+ if (flag_profile_update == PROFILE_UPDATE_ATOMIC
+ && !can_support_atomic)
{
- bool can_support = false;
- unsigned HOST_WIDE_INT gcov_type_size
- = tree_to_uhwi (TYPE_SIZE_UNIT (get_gcov_type ()));
- if (gcov_type_size == 4)
- can_support
- = HAVE_sync_compare_and_swapsi || HAVE_atomic_compare_and_swapsi;
- else if (gcov_type_size == 8)
- can_support
- = HAVE_sync_compare_and_swapdi || HAVE_atomic_compare_and_swapdi;
-
- if (!can_support)
- {
- warning (0, "target does not support atomic profile update, "
- "single mode is selected");
- flag_profile_update = PROFILE_UPDATE_SINGLE;
- }
+ warning (0, "target does not support atomic profile update, "
+ "single mode is selected");
+ flag_profile_update = PROFILE_UPDATE_SINGLE;
}
+ else if (flag_profile_update == PROFILE_UPDATE_MAYBE_ATOMIC)
+ flag_profile_update = can_support_atomic
+ ? PROFILE_UPDATE_ATOMIC : PROFILE_UPDATE_SINGLE;
/* This is a small-ipa pass that gets called only once, from
cgraphunit.c:ipa_passes(). */
--
2.9.2