[0/4] gcov: Improve -fprofile-update=atomic

Message ID 20231114220825.22074-1-sebastian.huber@embedded-brains.de
Headers
Series gcov: Improve -fprofile-update=atomic |

Message

Sebastian Huber Nov. 14, 2023, 10:08 p.m. UTC
  Sebastian Huber (4):
  gcov: Remove TARGET_GCOV_TYPE_SIZE target hook
  Add TARGET_HAVE_LIBATOMIC
  gcov: Add gen_counter_update()
  gcov: Improve -fprofile-update=atomic

 gcc/c-family/c-cppbuiltin.cc |   4 +-
 gcc/config/rtems.h           |   2 +
 gcc/config/sparc/rtemself.h  |   2 -
 gcc/config/sparc/sparc.cc    |  11 --
 gcc/coverage.cc              |   2 +-
 gcc/doc/invoke.texi          |  19 ++-
 gcc/doc/tm.texi              |  16 +--
 gcc/doc/tm.texi.in           |   4 +-
 gcc/target.def               |  20 ++-
 gcc/targhooks.cc             |   7 --
 gcc/targhooks.h              |   2 -
 gcc/tree-profile.cc          | 232 +++++++++++++++++++++++------------
 libgcc/libgcov.h             |  16 +--
 13 files changed, 197 insertions(+), 140 deletions(-)
  

Comments

Jakub Jelinek Nov. 21, 2023, 9:53 a.m. UTC | #1
On Wed, Nov 15, 2023 at 06:51:10AM +0100, Sebastian Huber wrote:
> sorry, in the patch I should use targetm.have_atomic instead of TARGET_HAVE_LIBATOMIC. 

I've noticed the r14-5579 commit introduced some formatting issues,
this patch fixes what I saw.

In particular, operators don't go at the end of line but at the start of
next one.

Committed to trunk as obvious.

2023-11-21  Jakub Jelinek  <jakub@redhat.com>

gcc/
	* tree-profile.cc (gen_counter_update, tree_profiling): Formatting
	fixes.
libgcc/
	* libgcov.h (GCOV_SUPPORTS_ATOMIC): Formatting fixes.

--- gcc/tree-profile.cc.jj	2023-11-21 09:31:36.349387476 +0100
+++ gcc/tree-profile.cc	2023-11-21 10:45:26.035499140 +0100
@@ -304,8 +304,8 @@ gen_counter_update (gimple_stmt_iterator
   tree one = build_int_cst (type, 1);
   tree relaxed = build_int_cst (integer_type_node, MEMMODEL_RELAXED);
 
-  if (counter_update == COUNTER_UPDATE_ATOMIC_BUILTIN ||
-      (result && counter_update == COUNTER_UPDATE_ATOMIC_SPLIT))
+  if (counter_update == COUNTER_UPDATE_ATOMIC_BUILTIN
+      || (result && counter_update == COUNTER_UPDATE_ATOMIC_SPLIT))
     {
       /* __atomic_fetch_add (&counter, 1, MEMMODEL_RELAXED); */
       tree f = builtin_decl_explicit (TYPE_PRECISION (type) > 32
@@ -314,8 +314,8 @@ gen_counter_update (gimple_stmt_iterator
       gcall *call = gimple_build_call (f, 3, addr, one, relaxed);
       gen_assign_counter_update (gsi, call, f, result, name);
     }
-  else if (!result && (counter_update == COUNTER_UPDATE_ATOMIC_SPLIT ||
-		       counter_update == COUNTER_UPDATE_ATOMIC_PARTIAL))
+  else if (!result && (counter_update == COUNTER_UPDATE_ATOMIC_SPLIT
+		       || counter_update == COUNTER_UPDATE_ATOMIC_PARTIAL))
     {
       /* low = __atomic_add_fetch_4 (addr, 1, MEMMODEL_RELAXED);
 	 high_inc = low == 0 ? 1 : 0;
@@ -780,8 +780,8 @@ tree_profiling (void)
       flag_profile_update = PROFILE_UPDATE_SINGLE;
     }
   else if (flag_profile_update == PROFILE_UPDATE_PREFER_ATOMIC)
-    flag_profile_update = can_support_atomic
-      ? PROFILE_UPDATE_ATOMIC : PROFILE_UPDATE_SINGLE;
+    flag_profile_update
+      = can_support_atomic ? PROFILE_UPDATE_ATOMIC : PROFILE_UPDATE_SINGLE;
 
   if (flag_profile_update == PROFILE_UPDATE_ATOMIC)
     {
@@ -791,7 +791,7 @@ tree_profiling (void)
 	counter_update = COUNTER_UPDATE_ATOMIC_BUILTIN;
     }
   else if (gcov_type_size == 8 && have_atomic_4)
-      counter_update = COUNTER_UPDATE_ATOMIC_PARTIAL;
+    counter_update = COUNTER_UPDATE_ATOMIC_PARTIAL;
 
   /* This is a small-ipa pass that gets called only once, from
      cgraphunit.cc:ipa_passes().  */
--- libgcc/libgcov.h.jj	2023-11-20 09:50:08.434204617 +0100
+++ libgcc/libgcov.h	2023-11-21 10:47:50.320481543 +0100
@@ -96,9 +96,9 @@ typedef unsigned gcov_type_unsigned __at
 #endif
 
 /* Detect whether target can support atomic update of profilers.  */
-#if (__SIZEOF_LONG_LONG__ == 4 && __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) || \
-    (__SIZEOF_LONG_LONG__ == 8 && __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8) || \
-    defined (__LIBGCC_HAVE_LIBATOMIC)
+#if (__SIZEOF_LONG_LONG__ == 4 && __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) \
+    || (__SIZEOF_LONG_LONG__ == 8 && __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8) \
+    || defined (__LIBGCC_HAVE_LIBATOMIC)
 #define GCOV_SUPPORTS_ATOMIC 1
 #else
 #define GCOV_SUPPORTS_ATOMIC 0

	Jakub