From patchwork Wed Feb 14 11:44:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1898886 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=tgWJIra5; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TZbxT6Nkkz23y6 for ; Wed, 14 Feb 2024 22:46:05 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AD222385DC27 for ; Wed, 14 Feb 2024 11:46:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AD222385DC27 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1707911163; bh=lnilSjNkyNw+P75u1spnEUULrgCxyRX7LpCiyrJytKY=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=tgWJIra5cCviwX+5eNpwyqoQ8CKHR32FGjok8UfSU1iuxWEWVIjqCYYInMvGMd/8h rWhedF8Znnq/zja7RH/zlXVNekg2WBA3g1VspbkXuBI5ahSAsj/PAcifwvOn2tQaLm pL8lLwvAq8eD7ZKf/O4xgK4Hank+mweYdRaWF5aA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id 4FEDF385C6E8; Wed, 14 Feb 2024 11:45:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4FEDF385C6E8 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4FEDF385C6E8 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707911130; cv=none; b=fk3HfkaKWatW5iBtEPsVZ50YsT9ZhG9Dp0wpGboeziaJqOi3DdcFRa3J+lbk3zCbL7Ld8JzA8ts2yVojujkZHs66oylPO2GLkA1StpFy2StHjozQm7Mk9aTLL+HnIzJmVy5KJYch+JXvkNqaM2k+vD1MxL0bLZl2TcJXmxm5NCs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707911130; c=relaxed/simple; bh=TC36lHwh3uKtei4oLZoVcS9hpnutBz1xIUTByxldaiE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=rEnKJ3GOuIwEUQRIPBo9cqgW3p2rZ+q6WoHaSysJDP5myssL6lznZTtrKehUzqng+pUgPUaSama8tzSvxJBUCnfvAcwBIiGkMQhfGs4z6aT/kIVNMrnqRtW/jLDQDEtg0S5yI/Mtzfsw0S93H4Yb9gk5GRDjelRR8b5fz2tLU3E= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247474.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41EBg4YW024993; Wed, 14 Feb 2024 11:45:27 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3w8f1c4kf7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Feb 2024 11:45:27 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41EBj5uq019284 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 14 Feb 2024 03:45:05 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.143]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41EBj59u001247 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Feb 2024 03:45:05 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH 1/2] c++: Implement __add_pointer built-in trait Date: Wed, 14 Feb 2024 03:44:47 -0800 Message-ID: <20240214114448.847646-1-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: SpElQZmHLXScYySB0Yx7YBLuVP8PVWuL X-Proofpoint-GUID: SpElQZmHLXScYySB0Yx7YBLuVP8PVWuL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-14_04,2024-02-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 lowpriorityscore=0 priorityscore=1501 bulkscore=0 spamscore=0 suspectscore=0 phishscore=0 mlxlogscore=581 adultscore=0 clxscore=1034 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402140091 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org This patch implements built-in trait for std::add_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __add_pointer. * semantics.cc (finish_trait_type): Handle CPTK_ADD_POINTER. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __add_pointer. * g++.dg/ext/add_pointer.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 9 ++++++ gcc/testsuite/g++.dg/ext/add_pointer.C | 37 ++++++++++++++++++++++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ 4 files changed, 50 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/add_pointer.C diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 394f006f20f..cec385ee501 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -48,6 +48,7 @@ #define DEFTRAIT_TYPE_DEFAULTED #endif +DEFTRAIT_TYPE (ADD_POINTER, "__add_pointer", 1) DEFTRAIT_EXPR (HAS_NOTHROW_ASSIGN, "__has_nothrow_assign", 1) DEFTRAIT_EXPR (HAS_NOTHROW_CONSTRUCTOR, "__has_nothrow_constructor", 1) DEFTRAIT_EXPR (HAS_NOTHROW_COPY, "__has_nothrow_copy", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 57840176863..e23693ab57f 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12760,6 +12760,15 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, switch (kind) { + case CPTK_ADD_POINTER: + if (TREE_CODE (type1) == FUNCTION_TYPE + && ((TYPE_QUALS (type1) & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)) + || FUNCTION_REF_QUALIFIED (type1))) + return type1; + if (TYPE_REF_P (type1)) + type1 = TREE_TYPE (type1); + return build_pointer_type (type1); + case CPTK_REMOVE_CV: return cv_unqualified (type1); diff --git a/gcc/testsuite/g++.dg/ext/add_pointer.C b/gcc/testsuite/g++.dg/ext/add_pointer.C new file mode 100644 index 00000000000..3091510f3b5 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/add_pointer.C @@ -0,0 +1,37 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +class ClassType { }; + +SA(__is_same(__add_pointer(int), int*)); +SA(__is_same(__add_pointer(int*), int**)); +SA(__is_same(__add_pointer(const int), const int*)); +SA(__is_same(__add_pointer(int&), int*)); +SA(__is_same(__add_pointer(ClassType*), ClassType**)); +SA(__is_same(__add_pointer(ClassType), ClassType*)); +SA(__is_same(__add_pointer(void), void*)); +SA(__is_same(__add_pointer(const void), const void*)); +SA(__is_same(__add_pointer(volatile void), volatile void*)); +SA(__is_same(__add_pointer(const volatile void), const volatile void*)); + +void f1(); +using f1_type = decltype(f1); +using pf1_type = decltype(&f1); +SA(__is_same(__add_pointer(f1_type), pf1_type)); + +void f2() noexcept; // PR libstdc++/78361 +using f2_type = decltype(f2); +using pf2_type = decltype(&f2); +SA(__is_same(__add_pointer(f2_type), pf2_type)); + +using fn_type = void(); +using pfn_type = void(*)(); +SA(__is_same(__add_pointer(fn_type), pfn_type)); + +SA(__is_same(__add_pointer(void() &), void() &)); +SA(__is_same(__add_pointer(void() & noexcept), void() & noexcept)); +SA(__is_same(__add_pointer(void() const), void() const)); +SA(__is_same(__add_pointer(void(...) &), void(...) &)); +SA(__is_same(__add_pointer(void(...) & noexcept), void(...) & noexcept)); +SA(__is_same(__add_pointer(void(...) const), void(...) const)); diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 02b4b4d745d..56e8db7ac32 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -2,6 +2,9 @@ // { dg-do compile } // Verify that __has_builtin gives the correct answer for C++ built-ins. +#if !__has_builtin (__add_pointer) +# error "__has_builtin (__add_pointer) failed" +#endif #if !__has_builtin (__builtin_addressof) # error "__has_builtin (__builtin_addressof) failed" #endif From patchwork Wed Feb 14 11:44:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1898887 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=MMxmZHg6; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TZbxT4x3yz23hM for ; Wed, 14 Feb 2024 22:46:05 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 74163385E006 for ; Wed, 14 Feb 2024 11:46:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 74163385E006 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1707911163; bh=piDE3AgxzrW0dXa2e3uQh2wEapv7CFxKuS7kgH2unj0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=MMxmZHg60gAW5oj85v1OWf0wLKqw6W8jsMRh3m92TsY5tcVip2fvKyZf+77exTGyk t1J4Fz2pmKFY1ddPYSKMnUf58/4Hf0P0m9A7qu5EzUVqzIChgzFCIURDSQmd8XPNVo MSqvOPmRk96l5uQmBLyCy6tWzJ82uu2w4NK3QAyw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id 4E6E1385C422; Wed, 14 Feb 2024 11:45:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4E6E1385C422 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4E6E1385C422 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707911129; cv=none; b=b2rYIBCKAu/krNbG68KIaKQR+3+2WhAwjD8dmM3CNZDR86Xl7nl3wST5advNZIZLyjtC8wsKX56iJ6/Zy9fWuWeuMz1s6kbsRjG/SnRCPy+sgBlwhGin2ThCwkO+fI1FCvgKpUHIV+F1FP0AUTdGU1Cwz7SB8ywSTvRS4v6iEEM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707911129; c=relaxed/simple; bh=mgSd9TEezsOin328Daikj7GhRV0O1ne8sDSsrKJn60A=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=DA7iK8Th7EtyWsfLEvckrZyHE3qZkphvO3+yX0PsFQ2fiRs5hrP70PkjTp2y6BAaO0BqxaIOfLeoJOd+1O5nA5lr3MCT2uE0KNzIpMNlR7wJhqe1y5quuxQ8eR3JPczzj1aGHQKz8VSUhkc19QsFSyxIu6dqjDLaU8cz86EoiPQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247470.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41EBj7j7015829; Wed, 14 Feb 2024 11:45:27 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3w8kq8t1e8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Feb 2024 11:45:27 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41EBjD4m019290 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 14 Feb 2024 03:45:13 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.143]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41EBj59v001247 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Feb 2024 03:45:13 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH 2/2] libstdc++: Optimize std::add_pointer compilation performance Date: Wed, 14 Feb 2024 03:44:48 -0800 Message-ID: <20240214114448.847646-2-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240214114448.847646-1-kmatsui@gcc.gnu.org> References: <20240214114448.847646-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: zWsrtYC3xRY-XUcvJMEUfX2m0_DlsVct X-Proofpoint-GUID: zWsrtYC3xRY-XUcvJMEUfX2m0_DlsVct X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-14_04,2024-02-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 suspectscore=0 mlxlogscore=503 impostorscore=0 malwarescore=0 phishscore=0 lowpriorityscore=0 bulkscore=0 spamscore=0 mlxscore=0 adultscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402140091 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org This patch optimizes the compilation performance of std::add_pointer by dispatching to the new __add_pointer built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (add_pointer): Use __add_pointer built-in trait. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 21402fd8c13..3bde7cb8ba3 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -2121,6 +2121,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; #endif + /// add_pointer +#if _GLIBCXX_USE_BUILTIN_TRAIT(__add_pointer) + template + struct add_pointer + { using type = __add_pointer(_Tp); }; +#else template struct __add_pointer_helper { using type = _Tp; }; @@ -2129,7 +2135,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __add_pointer_helper<_Tp, __void_t<_Tp*>> { using type = _Tp*; }; - /// add_pointer template struct add_pointer : public __add_pointer_helper<_Tp> @@ -2142,6 +2147,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct add_pointer<_Tp&&> { using type = _Tp*; }; +#endif #if __cplusplus > 201103L /// Alias template for remove_pointer