From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) by sourceware.org (Postfix) with ESMTPS id 8442A3854834 for ; Wed, 11 Aug 2021 06:58:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8442A3854834 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embedded-brains.de Received: from sslproxy02.your-server.de ([78.47.166.47]) by dedi548.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from ) id 1mDiCH-0004t8-QB; Wed, 11 Aug 2021 08:58:41 +0200 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy02.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mDiCH-0009wo-Mi; Wed, 11 Aug 2021 08:58:41 +0200 Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 6409E2A1610; Wed, 11 Aug 2021 08:58:41 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id pbkx5lgapsH1; Wed, 11 Aug 2021 08:58:40 +0200 (CEST) Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id B98392A165B; Wed, 11 Aug 2021 08:58:40 +0200 (CEST) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id yzGkLj3mftde; Wed, 11 Aug 2021 08:58:40 +0200 (CEST) Received: from zimbra.eb.localhost (unknown [192.168.96.242]) by mail.embedded-brains.de (Postfix) with ESMTPSA id 98DB72A1610; Wed, 11 Aug 2021 08:58:40 +0200 (CEST) From: Sebastian Huber To: gcc-patches@gcc.gnu.org Cc: =?UTF-8?q?Martin=20Li=C5=A1ka?= , Joseph Myers Subject: [PATCH v3] gcov: Add TARGET_GCOV_TYPE_SIZE target macro Date: Wed, 11 Aug 2021 08:58:37 +0200 Message-Id: <20210811065837.114010-1-sebastian.huber@embedded-brains.de> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.103.2/26259/Tue Aug 10 10:19:56 2021) X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 06:58:54 -0000 If -fprofile-update=3Datomic is used, then the target must provide atomic operations for the counters of the type returned by get_gcov_type(). This is a 64-bit type for targets which have a 64-bit long long type. On 32-bit targets this could be an issue since they may not provide 64-bit atomic operations. Allow targets to override the default type size with the new TARGET_GCOV_TYPE_SIZE target macro. If a 32-bit gcov type size is used, then there is currently a warning in libgcov-driver.c in a dead code block due to sizeof (counter) =3D=3D sizeof (gcov_unsigned_t): libgcc/libgcov-driver.c: In function 'dump_counter': libgcc/libgcov-driver.c:401:46: warning: right shift count >=3D width of = type [-Wshift-count-overflow] 401 | dump_unsigned ((gcov_unsigned_t)(counter >> 32), dump_fn, arg= ); | ^~ gcc/ * c-family/c-cppbuiltin.c (c_cpp_builtins): Define __LIBGCC_GCOV_TYPE_SIZE if flag_building_libgcc is true. * config/sparc/rtemself.h (TARGET_GCOV_TYPE_SIZE): Redefine. * coverage.c (get_gcov_type): Use targetm.gcov_type_size. * doc/tm.texi (TARGET_GCOV_TYPE_SIZE): Add hook under "Misc". * doc/tm.texi.in: Regenerate. * target.def (gcov_type_size): New POD hook. * tree-profile.c (gimple_gen_edge_profiler): Use precision of gcov_type_node. (gimple_gen_time_profiler): Likewise. libgcc/ * libgcov.h (gcov_type): Define using __LIBGCC_GCOV_TYPE_SIZE. (gcov_type_unsigned): Likewise. --- gcc/c-family/c-cppbuiltin.c | 2 ++ gcc/config/sparc/rtemself.h | 3 +++ gcc/coverage.c | 3 +-- gcc/doc/tm.texi | 11 +++++++++++ gcc/doc/tm.texi.in | 2 ++ gcc/target.def | 12 ++++++++++++ gcc/tree-profile.c | 4 ++-- libgcc/libgcov.h | 6 +++--- 8 files changed, 36 insertions(+), 7 deletions(-) diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c index f79f939bd10f..e85b60c79f49 100644 --- a/gcc/c-family/c-cppbuiltin.c +++ b/gcc/c-family/c-cppbuiltin.c @@ -1450,6 +1450,8 @@ c_cpp_builtins (cpp_reader *pfile) /* For libgcov. */ builtin_define_with_int_value ("__LIBGCC_VTABLE_USES_DESCRIPTORS__= ", TARGET_VTABLE_USES_DESCRIPTORS); + builtin_define_with_int_value ("__LIBGCC_GCOV_TYPE_SIZE", + TARGET_GCOV_TYPE_SIZE); } =20 /* For use in assembly language. */ diff --git a/gcc/config/sparc/rtemself.h b/gcc/config/sparc/rtemself.h index fa972af640cc..87a3ceb640c0 100644 --- a/gcc/config/sparc/rtemself.h +++ b/gcc/config/sparc/rtemself.h @@ -40,3 +40,6 @@ =20 /* Use the default */ #undef LINK_GCC_C_SEQUENCE_SPEC + +#undef TARGET_GCOV_TYPE_SIZE +#define TARGET_GCOV_TYPE_SIZE 32 diff --git a/gcc/coverage.c b/gcc/coverage.c index ac9a9fdad228..6166247ad179 100644 --- a/gcc/coverage.c +++ b/gcc/coverage.c @@ -145,8 +145,7 @@ static void coverage_obj_finish (vec *); tree get_gcov_type (void) { - scalar_int_mode mode - =3D smallest_int_mode_for_size (LONG_LONG_TYPE_SIZE > 32 ? 64 : 32); + scalar_int_mode mode =3D smallest_int_mode_for_size (targetm.gcov_type= _size); return lang_hooks.types.type_for_mode (mode, false); } =20 diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index a30fdcbbf3d6..429e7edf0e9d 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -12588,3 +12588,14 @@ Return an RTX representing @var{tagged_pointer} = with its tag set to zero. Store the result in @var{target} if convenient. The default clears the top byte of the original pointer. @end deftypefn + +@deftypevr {Target Hook} HOST_WIDE_INT TARGET_GCOV_TYPE_SIZE +The gcov type size in bits. This type is used for example for counters +incremented by profiling and code-coverage events. The default value is= 64, +if the type size of long long is greater than 32, otherwise the default +value is 32. A 64-bit type is recommended to avoid overflows of the +counters. If the @option{-fprofile-update=3Datomic} is used, then the +counters are incremented using atomic operations. Targets not supportin= g +64-bit atomic operations may override the default value and request a 32= -bit +type. +@end deftypevr diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index 611fc500ac86..fdf16b901c53 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -8180,3 +8180,5 @@ maintainer is familiar with. @hook TARGET_MEMTAG_EXTRACT_TAG =20 @hook TARGET_MEMTAG_UNTAGGED_POINTER + +@hook TARGET_GCOV_TYPE_SIZE diff --git a/gcc/target.def b/gcc/target.def index 7676d5e626e3..b94c2c40dcf1 100644 --- a/gcc/target.def +++ b/gcc/target.def @@ -7104,6 +7104,18 @@ DEFHOOK void, (void), NULL) =20 +DEFHOOKPOD +(gcov_type_size, + "The gcov type size in bits. This type is used for example for counter= s\n\ +incremented by profiling and code-coverage events. The default value is= 64,\n\ +if the type size of long long is greater than 32, otherwise the default\= n\ +value is 32. A 64-bit type is recommended to avoid overflows of the\n\ +counters. If the @option{-fprofile-update=3Datomic} is used, then the\n= \ +counters are incremented using atomic operations. Targets not supportin= g\n\ +64-bit atomic operations may override the default value and request a 32= -bit\n\ +type.", + HOST_WIDE_INT, (LONG_LONG_TYPE_SIZE > 32 ? 64 : 32)) + /* Close the 'struct gcc_target' definition. */ HOOK_VECTOR_END (C90_EMPTY_HACK) =20 diff --git a/gcc/tree-profile.c b/gcc/tree-profile.c index 5a74cc96e132..cf46912631cb 100644 --- a/gcc/tree-profile.c +++ b/gcc/tree-profile.c @@ -250,7 +250,7 @@ gimple_gen_edge_profiler (int edgeno, edge e) { /* __atomic_fetch_add (&counter, 1, MEMMODEL_RELAXED); */ tree addr =3D tree_coverage_counter_addr (GCOV_COUNTER_ARCS, edgen= o); - tree f =3D builtin_decl_explicit (LONG_LONG_TYPE_SIZE > 32 + tree f =3D builtin_decl_explicit (TYPE_PRECISION (gcov_type_node) = > 32 ? BUILT_IN_ATOMIC_FETCH_ADD_8: BUILT_IN_ATOMIC_FETCH_ADD_4); gcall *stmt =3D gimple_build_call (f, 3, addr, one, @@ -525,7 +525,7 @@ gimple_gen_time_profiler (unsigned tag) tree_time_profiler_counter); gassign *assign =3D gimple_build_assign (ptr, NOP_EXPR, addr); gsi_insert_before (&gsi, assign, GSI_NEW_STMT); - tree f =3D builtin_decl_explicit (LONG_LONG_TYPE_SIZE > 32 + tree f =3D builtin_decl_explicit (TYPE_PRECISION (gcov_type_node) = > 32 ? BUILT_IN_ATOMIC_ADD_FETCH_8: BUILT_IN_ATOMIC_ADD_FETCH_4); gcall *stmt =3D gimple_build_call (f, 3, ptr, one, diff --git a/libgcc/libgcov.h b/libgcc/libgcov.h index 9c537253293f..f6354a7a0705 100644 --- a/libgcc/libgcov.h +++ b/libgcc/libgcov.h @@ -52,7 +52,7 @@ #if __CHAR_BIT__ =3D=3D 8 typedef unsigned gcov_unsigned_t __attribute__ ((mode (SI))); typedef unsigned gcov_position_t __attribute__ ((mode (SI))); -#if LONG_LONG_TYPE_SIZE > 32 +#if __LIBGCC_GCOV_TYPE_SIZE > 32 typedef signed gcov_type __attribute__ ((mode (DI))); typedef unsigned gcov_type_unsigned __attribute__ ((mode (DI))); #else @@ -63,7 +63,7 @@ typedef unsigned gcov_type_unsigned __attribute__ ((mod= e (SI))); #if __CHAR_BIT__ =3D=3D 16 typedef unsigned gcov_unsigned_t __attribute__ ((mode (HI))); typedef unsigned gcov_position_t __attribute__ ((mode (HI))); -#if LONG_LONG_TYPE_SIZE > 32 +#if __LIBGCC_GCOV_TYPE_SIZE > 32 typedef signed gcov_type __attribute__ ((mode (SI))); typedef unsigned gcov_type_unsigned __attribute__ ((mode (SI))); #else @@ -73,7 +73,7 @@ typedef unsigned gcov_type_unsigned __attribute__ ((mod= e (HI))); #else typedef unsigned gcov_unsigned_t __attribute__ ((mode (QI))); typedef unsigned gcov_position_t __attribute__ ((mode (QI))); -#if LONG_LONG_TYPE_SIZE > 32 +#if __LIBGCC_GCOV_TYPE_SIZE > 32 typedef signed gcov_type __attribute__ ((mode (HI))); typedef unsigned gcov_type_unsigned __attribute__ ((mode (HI))); #else --=20 2.26.2