From patchwork Thu May 2 16:13:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1930701 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=NJkVSgKy; 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 4VVfPZ1DgSz20fb for ; Fri, 3 May 2024 02:23:30 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6A4AC3849ADC for ; Thu, 2 May 2024 16:23:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6A4AC3849ADC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714667008; bh=rvLFnmUwT9ZQ6o3gRXi4F1l67pl0uoTfoO1sKSNIx+k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=NJkVSgKyxVlBBfrZReaq4ZOlErdv6I2DLCuzQWKsdHqPC45zXADqh54SZg4Ud5fzx HUhOx7L8/lqNfOugQZDr1cny5pCJHuowu8ptgn8WGZQs/rbMfOXq+EA7UUr+Mub5vn YyJXdPHJJ48qOXJ9DtlN9msK69HSkQGvjJPq9h/s= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 74640384AB63; Thu, 2 May 2024 16:16:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 74640384AB63 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 74640384AB63 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666606; cv=none; b=tRTO3cVoS/DpbcL6P0kyZArcUvw/6jGasALsV/DDWKV4yjvaGfy1o/l1XlxJK3O7TvG+RzxcXUpC4a1yyVQLqkRxYAw96gzuDqoOEYx24w+W2AlsyW1imk+rSqYSW6mJSDpvQ/FBKZy+PWk1HB+/sxbfItgg4LTqUjLlRwbQxyg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666606; c=relaxed/simple; bh=p5HgnhCjKT3R13+e/nJkIpUAEtUmRhUVzJUvpiPLutY=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=DRsPUBzgZeu56ShSdWMblA+Q2F12houwk1t1e/8iMBXNHvHGU6DKCCJXnQOpaUt++AvZRAzI6X8nGCyzN9dxdEsyHis15dhpqIWuUi54/CeeKkK3AckplFqSeGSnkYTpSlLxBFn2ikkaV5WvAr89B01YMP4dUilVEvaKW6+toQg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247476.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442Fo00S011686; Thu, 2 May 2024 16:16:38 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xv4e4kd9a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 16:16:37 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442GGFhf024913 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 09:16:16 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442GGFoe023119 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 09:16:15 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v16 01/26] c++: Implement __builtin_is_const trait Date: Thu, 2 May 2024 09:13:27 -0700 Message-ID: <20240502161614.3705912-2-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502161614.3705912-1-kmatsui@gcc.gnu.org> References: <20240228192843.188979-1-kmatsui@gcc.gnu.org> <20240502161614.3705912-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: _EPzX7-BuSV2O_32BHTvzmmAIdsl80rJ X-Proofpoint-GUID: _EPzX7-BuSV2O_32BHTvzmmAIdsl80rJ X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_05,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 lowpriorityscore=0 suspectscore=0 bulkscore=0 phishscore=0 mlxscore=0 priorityscore=1501 clxscore=1034 impostorscore=0 mlxlogscore=807 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020106 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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::is_const. gcc/cp/ChangeLog: * cp-trait.def: Define __builtin_is_const. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_CONST. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __builtin_is_const. * g++.dg/ext/is_const.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 +++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 ++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ gcc/testsuite/g++.dg/ext/is_const.C | 20 ++++++++++++++++++++ 5 files changed, 31 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_const.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 8a3b5d80ba7..eaf17a50877 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3768,6 +3768,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_CLASS: inform (loc, " %qT is not a class", t1); break; + case CPTK_IS_CONST: + inform (loc, " %qT is not a const type", t1); + break; case CPTK_IS_CONSTRUCTIBLE: if (!t2) inform (loc, " %qT is not default constructible", t1); diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 394f006f20f..4cc11818a66 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -64,6 +64,7 @@ DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) DEFTRAIT_EXPR (IS_BOUNDED_ARRAY, "__is_bounded_array", 1) DEFTRAIT_EXPR (IS_CLASS, "__is_class", 1) +DEFTRAIT_EXPR (IS_CONST, "__builtin_is_const", 1) DEFTRAIT_EXPR (IS_CONSTRUCTIBLE, "__is_constructible", -1) DEFTRAIT_EXPR (IS_CONVERTIBLE, "__is_convertible", 2) DEFTRAIT_EXPR (IS_EMPTY, "__is_empty", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 2dde65a970b..fa7ba6a9edc 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12530,6 +12530,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: return NON_UNION_CLASS_TYPE_P (type1); + case CPTK_IS_CONST: + return CP_TYPE_CONST_P (type1); + case CPTK_IS_CONSTRUCTIBLE: return is_xible (INIT_EXPR, type1, type2); @@ -12812,6 +12815,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_ARRAY: case CPTK_IS_BOUNDED_ARRAY: case CPTK_IS_CLASS: + case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_FUNCTION: case CPTK_IS_MEMBER_FUNCTION_POINTER: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 02b4b4d745d..29199442ea1 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -8,6 +8,9 @@ #if !__has_builtin (__builtin_bit_cast) # error "__has_builtin (__builtin_bit_cast) failed" #endif +#if !__has_builtin (__builtin_is_const) +# error "__has_builtin (__builtin_is_const) failed" +#endif #if !__has_builtin (__builtin_is_constant_evaluated) # error "__has_builtin (__builtin_is_constant_evaluated) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_const.C b/gcc/testsuite/g++.dg/ext/is_const.C new file mode 100644 index 00000000000..0dc9027c589 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_const.C @@ -0,0 +1,20 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +class ClassType { }; +using cClassType = const ClassType; +using vClassType = volatile ClassType; +using cvClassType = const volatile ClassType; + +// Positive tests. +SA(__builtin_is_const(const int)); +SA(__builtin_is_const(const volatile int)); +SA(__builtin_is_const(cClassType)); +SA(__builtin_is_const(cvClassType)); + +// Negative tests. +SA(!__builtin_is_const(int)); +SA(!__builtin_is_const(volatile int)); +SA(!__builtin_is_const(ClassType)); +SA(!__builtin_is_const(vClassType)); From patchwork Thu May 2 16:13:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1930689 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=dNsg1nkz; 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 4VVfJ83vByz23hd for ; Fri, 3 May 2024 02:18:47 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D42C1384AB6E for ; Thu, 2 May 2024 16:18:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D42C1384AB6E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714666725; bh=PEkh7OW2UZDgzCg1MPsxWSsG1mmvoqJcd9bIRhe7Ba8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=dNsg1nkz32U7ymgKS7gvhdjE3md3zVn/E62FM4iaVsPbIJXJkZQ9ELZamZAVllDDx dtwxocZbQd8pg8LVQ9kBP4fNFauZ33yFuEz/R+xRIKr9FHR2tWVbIlY+u/uN0QEW1v sII6194MYPr6gND1GG8x71xoJXjsJ6Mb6SfvGr3g= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 80B573858CDB; Thu, 2 May 2024 16:16:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 80B573858CDB 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 80B573858CDB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666595; cv=none; b=Lxz+Ol2Wvm+oM6/O1hhhLY0WDzgQyUuvKx+2wjFBV172t016OHeXCI6V2tZPJH1vLUGbQDzTk96/wWVWXXa7mdfbNMeh+8b2oT3vnWQmbhmw7pz56FZ/ski3QTX/LvHJJEubkveYmunpUQhJeZSgW7tKb6cHuX1smU5Ua1jZwa8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666595; c=relaxed/simple; bh=gk4M439mEVW52xaTVIJElMxKl8DRFr2VYpbpZ0sX8io=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=ZWZmMEOZl6j97OKMP22Uza+bv+a5JqQHHn7iTmlf6kO9MkIk2rEaWiQBaFtzjKX7W9m4mdXui6IPMX9XsdAOfvkJWO0OACZlAyb1e5CWbYfLdLhqIYcwNZjxIbxK3h/8f+xR0TPcdnMN7fQLQUaTIYhvUR6OZQBoS/15VvtDvm8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442GClxu019938; Thu, 2 May 2024 16:16:33 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xv4e2ueku-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 16:16:33 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442GGFCd003501 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 09:16:16 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442GGFof023119 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 09:16:15 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v16 02/26] libstdc++: Optimize std::is_const compilation performance Date: Thu, 2 May 2024 09:13:28 -0700 Message-ID: <20240502161614.3705912-3-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502161614.3705912-1-kmatsui@gcc.gnu.org> References: <20240228192843.188979-1-kmatsui@gcc.gnu.org> <20240502161614.3705912-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: fNRqAQ45wYsTGxRC4WQGzwLH5BXrhT1X X-Proofpoint-ORIG-GUID: fNRqAQ45wYsTGxRC4WQGzwLH5BXrhT1X X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_05,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 priorityscore=1501 bulkscore=0 suspectscore=0 clxscore=1034 mlxlogscore=808 spamscore=0 mlxscore=0 phishscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020106 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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::is_const by dispatching to the new __builtin_is_const trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_const): Use __builtin_is_const trait. (is_const_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index b441bf9908f..b2a696ccd2e 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -835,6 +835,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Type properties. /// is_const +#if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_is_const) + template + struct is_const + : public __bool_constant<__builtin_is_const(_Tp)> + { }; +#else template struct is_const : public false_type { }; @@ -842,6 +848,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct is_const<_Tp const> : public true_type { }; +#endif /// is_volatile template @@ -3331,10 +3338,15 @@ template inline constexpr bool is_member_pointer_v = is_member_pointer<_Tp>::value; #endif +#if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_is_const) +template + inline constexpr bool is_const_v = __builtin_is_const(_Tp); +#else template inline constexpr bool is_const_v = false; template inline constexpr bool is_const_v = true; +#endif #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function) template From patchwork Thu May 2 16:13:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1930690 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=tpYwwTY6; 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 4VVfJ83v7hz1ydT for ; Fri, 3 May 2024 02:18:47 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D42F73849AF3 for ; Thu, 2 May 2024 16:18:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D42F73849AF3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714666725; bh=EfAFIF41aPeOQdHvaloeHAQSeLO7VAtX6AFkIcCh/Vs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=tpYwwTY6059RcQ7LNQT1wVJQUvcXQ1DnD+HVIsJfGvhFEClj4WhQntAEwqsiGx4x0 /4ousHp5JiK9XSuATQRU6OGnZe4xG/Ft3xZ/N1N/pQiJu08dmCqDNA1+kWyZrVLPGA yQB9Wx7rUyXa8J6BnE0Hfvvds13ssQpdPXNIXksY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 7DEDE3858D34; Thu, 2 May 2024 16:16:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7DEDE3858D34 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 7DEDE3858D34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666595; cv=none; b=BetbcZZXOH3Ycy8y1H3NxVkML84OnHjDqsvK3L9aBMvbKXHNh5uz6/i8XT2eWYG1oZ24WjAwf4TYaDeHU9wtwgK38Q/a2xnqsD0n+6CHDzbStIgNxpqFrX043koml7XJFY8uLa7/HUmtBPVSWQNxUdzggBJREI1MhwRS0fxVu/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666595; c=relaxed/simple; bh=xbwy1Yg6EveJPlqEjz04jtUZrkxbHZN3FxsS+E9Rh4w=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=GbL5N00y9wDy3EHFKO4J5724WQAUHVjhj3iX3Ve99E92fIGsNOpIvVbEB92QNV8O46Tpltfs3c+F0JU//OqjXGajGztaBMAqErcgr0nf425nH94MIRzBe4gMFnJlD5kulkcxlREnRpX/N518L/P81zt4cNlBglFF8tReXrhvMU4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247476.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442GEUbQ009945; Thu, 2 May 2024 16:16:33 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xv4e4kd8h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 16:16:32 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442GGGEl003502 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 09:16:16 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442GGFog023119 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 09:16:15 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v16 03/26] c++: Implement __builtin_is_volatile trait Date: Thu, 2 May 2024 09:13:29 -0700 Message-ID: <20240502161614.3705912-4-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502161614.3705912-1-kmatsui@gcc.gnu.org> References: <20240228192843.188979-1-kmatsui@gcc.gnu.org> <20240502161614.3705912-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: Kcn_EEa1SmYme8wl95TOdOfJ978UVsy_ X-Proofpoint-GUID: Kcn_EEa1SmYme8wl95TOdOfJ978UVsy_ X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_05,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 lowpriorityscore=0 suspectscore=0 bulkscore=0 phishscore=0 mlxscore=0 priorityscore=1501 clxscore=1034 impostorscore=0 mlxlogscore=814 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020106 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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::is_volatile. gcc/cp/ChangeLog: * cp-trait.def: Define __builtin_is_volatile. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_VOLATILE. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __builtin_is_volatile. * g++.dg/ext/is_volatile.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 +++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 ++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ gcc/testsuite/g++.dg/ext/is_volatile.C | 20 ++++++++++++++++++++ 5 files changed, 31 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_volatile.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index eaf17a50877..d9caf546423 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3862,6 +3862,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_UNION: inform (loc, " %qT is not a union", t1); break; + case CPTK_IS_VOLATILE: + inform (loc, " %qT is not a volatile type", t1); + break; case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: inform (loc, " %qT is not a reference that binds to a temporary " "object of type %qT (direct-initialization)", t1, t2); diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 4cc11818a66..a7ea3caff4e 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -92,6 +92,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2) DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1) DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) +DEFTRAIT_EXPR (IS_VOLATILE, "__builtin_is_volatile", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) DEFTRAIT_TYPE (REMOVE_CV, "__remove_cv", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index fa7ba6a9edc..351235a639a 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12616,6 +12616,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_UNION: return type_code1 == UNION_TYPE; + case CPTK_IS_VOLATILE: + return CP_TYPE_VOLATILE_P (type1); + case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: return ref_xes_from_temporary (type1, type2, /*direct_init=*/true); @@ -12826,6 +12829,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNION: + case CPTK_IS_VOLATILE: break; case CPTK_IS_LAYOUT_COMPATIBLE: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 29199442ea1..398719fe8d6 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -20,6 +20,9 @@ #if !__has_builtin (__builtin_is_pointer_interconvertible_with_class) # error "__has_builtin (__builtin_is_pointer_interconvertible_with_class) failed" #endif +#if !__has_builtin (__builtin_is_volatile) +# error "__has_builtin (__builtin_is_volatile) failed" +#endif #if !__has_builtin (__builtin_launder) # error "__has_builtin (__builtin_launder) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_volatile.C b/gcc/testsuite/g++.dg/ext/is_volatile.C new file mode 100644 index 00000000000..b04f028bd25 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_volatile.C @@ -0,0 +1,20 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +class ClassType { }; +using cClassType = const ClassType; +using vClassType = volatile ClassType; +using cvClassType = const volatile ClassType; + +// Positive tests. +SA(__builtin_is_volatile(volatile int)); +SA(__builtin_is_volatile(const volatile int)); +SA(__builtin_is_volatile(vClassType)); +SA(__builtin_is_volatile(cvClassType)); + +// Negative tests. +SA(!__builtin_is_volatile(int)); +SA(!__builtin_is_volatile(const int)); +SA(!__builtin_is_volatile(ClassType)); +SA(!__builtin_is_volatile(cClassType)); From patchwork Thu May 2 16:13:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1930688 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=SqtLVYL+; 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 4VVfGf0PPxz1ydT for ; Fri, 3 May 2024 02:17:29 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7B7013849ACE for ; Thu, 2 May 2024 16:17:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7B7013849ACE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714666644; bh=hmAFA2S86AJICw7nq2IxwiWoigxWR/gvMUma8RhUWoM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=SqtLVYL+2+/1PUryyy44UjAdEFyUrrSOtg8KcrUG9B+NfoiwSjqzjoHvmMbs51qWp Dkw/pdGzhtYohHZJQ1CV85nLutm4vv9ywztuCCGbtuflI5wbNtK+xRbh2Lqqz82fa2 28vOs7kYyC80Z1wuAqy8r9BXos8I3g8XKa1hl7EM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 96F193858C50; Thu, 2 May 2024 16:16:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 96F193858C50 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 96F193858C50 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666595; cv=none; b=N4M5nqAbXDp6cBijHLS9gmzND3MrflICnAufIuHUyYA4cwtauGwKLmQ9KcpDyD0Ij32NBpu1nh1QmEzhscVCqNjMsTeaGZrEGP+F7WHA59RvyKu2ok6oFb2TI/8EAhloWZ1gQ6/EsjYPjMOmld2B6gI0rab6j2brBUtIzQcxFdg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666595; c=relaxed/simple; bh=lo6nuJ1hH7UStdGpyMNHVarawfIlz0LQZgxFRy0mAuc=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=SO7EJEJeqeoS4uJksUn9a2jL9BB8xiz2HodxkaPbZO7M0PaIcJrqsI4/hB3SPc73HjfvTdZFUBUrLdzbe7F6+T9AHTEjga2julY7v11KAWQA+7dd1VkaNz3664JF24WPLSXLBvpnpvAS55VGc+7YnSXUJBmAwpxjTeGW/uJqP2A= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247481.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442GGXlO024991; Thu, 2 May 2024 16:16:33 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xv4e1kahd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 16:16:32 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442GGGbP003503 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 09:16:16 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442GGFoh023119 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 09:16:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v16 04/26] libstdc++: Optimize std::is_volatile compilation performance Date: Thu, 2 May 2024 09:13:30 -0700 Message-ID: <20240502161614.3705912-5-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502161614.3705912-1-kmatsui@gcc.gnu.org> References: <20240228192843.188979-1-kmatsui@gcc.gnu.org> <20240502161614.3705912-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: 4QaXa3OiWVpZSUq3MvYv_RhLdoezhDBG X-Proofpoint-ORIG-GUID: 4QaXa3OiWVpZSUq3MvYv_RhLdoezhDBG X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_05,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 adultscore=0 clxscore=1034 priorityscore=1501 suspectscore=0 lowpriorityscore=0 spamscore=0 mlxscore=0 phishscore=0 bulkscore=0 malwarescore=0 mlxlogscore=765 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020106 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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::is_volatile by dispatching to the new __builtin_is_volatile trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_volatile): Use __builtin_is_volatile trait. (is_volatile_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index b2a696ccd2e..e9674ff87d1 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -851,6 +851,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif /// is_volatile +#if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_is_volatile) + template + struct is_volatile + : public __bool_constant<__builtin_is_volatile(_Tp)> + { }; +#else template struct is_volatile : public false_type { }; @@ -858,6 +864,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct is_volatile<_Tp volatile> : public true_type { }; +#endif /// is_trivial template @@ -3360,10 +3367,15 @@ template inline constexpr bool is_function_v<_Tp&&> = false; #endif +#if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_is_volatile) +template + inline constexpr bool is_volatile_v = __builtin_is_volatile(_Tp); +#else template inline constexpr bool is_volatile_v = false; template inline constexpr bool is_volatile_v = true; +#endif template inline constexpr bool is_trivial_v = __is_trivial(_Tp); From patchwork Thu May 2 16:13:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1930718 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=Tkgk5hzO; 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 4VVfVv67CDz1ydX for ; Fri, 3 May 2024 02:28:07 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2A5543849AC6 for ; Thu, 2 May 2024 16:28:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2A5543849AC6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714667285; bh=ZhJqVYh/eJIdai0mTg0L6sOfWboiIwS5lpF08a88luo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Tkgk5hzOex/oGbkCSvcBgKdqxMYKFDis86QYwu/W8l8tfDCy/CclpRvZ5wfFp7Hi1 uws1fyMUXpTr/RftIzASDqePvGBYc4iws4SV7a5AdK9C/p7WGGMSxJ7TJ52KEfPTXX 4X2oy5nVkiV+pORRnFUqCrIVxx+pWhA6B6wBqPFU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 74800384AB67; Thu, 2 May 2024 16:16:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 74800384AB67 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 74800384AB67 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666608; cv=none; b=Wq5uCFPU+JQpIweWoy4X6nIRovuFD6CTtNwp1OHjpezMDFJsI1XYTr1kkwjklOdEHoAoURY0zT1AhIqcBdIoUus8KUlK5uHLuBBqmzucofavt1uNW9JeouknWEjRYJbc5897zRmT7nj9W0CdO0w589pYa0C37PcvwR7U2RFiUw4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666608; c=relaxed/simple; bh=FRuuCiOTc7DjrwCm4eM0ctZg5Y9aICULpWy0p/FOd6Q=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=KpET0Ih8Vs++IWzUlgBhZi9M+Lj/zdSPRA4RqP5t8pVNUA3s9CUUuVWxn7jFEaEngR3ehSFE24/LDcIkY2BJ2f7lBggLq0hPRXS0XU3OGp6iLFIHARx8ohZS6U3KkjJ/q9DgxiQ0EiLzZw0U4wc9M9SG+Aq/3hvGpBRlX6nN6qQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247476.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442GEUbR009945; Thu, 2 May 2024 16:16:38 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xv4e4kd9b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 16:16:37 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442GGG9S024914 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 09:16:16 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442GGFoi023119 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 09:16:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v16 05/26] c++: Implement __builtin_is_pointer trait Date: Thu, 2 May 2024 09:13:31 -0700 Message-ID: <20240502161614.3705912-6-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502161614.3705912-1-kmatsui@gcc.gnu.org> References: <20240228192843.188979-1-kmatsui@gcc.gnu.org> <20240502161614.3705912-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 0g2jH-A1CpOFDK7Ei2aQwbM9S8OVhek2 X-Proofpoint-GUID: 0g2jH-A1CpOFDK7Ei2aQwbM9S8OVhek2 X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_05,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 lowpriorityscore=0 suspectscore=0 bulkscore=0 phishscore=0 mlxscore=0 priorityscore=1501 clxscore=1034 impostorscore=0 mlxlogscore=788 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020106 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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::is_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __builtin_is_pointer. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_POINTER. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __builtin_is_pointer. * g++.dg/ext/is_pointer.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 ++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_pointer.C | 51 ++++++++++++++++++++++++ 5 files changed, 62 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index d9caf546423..5a8aaa70fa6 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3829,6 +3829,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_POD: inform (loc, " %qT is not a POD type", t1); break; + case CPTK_IS_POINTER: + inform (loc, " %qT is not a pointer", t1); + break; case CPTK_IS_POLYMORPHIC: inform (loc, " %qT is not a polymorphic type", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index a7ea3caff4e..a6a3c195529 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -82,6 +82,7 @@ DEFTRAIT_EXPR (IS_NOTHROW_CONVERTIBLE, "__is_nothrow_convertible", 2) DEFTRAIT_EXPR (IS_OBJECT, "__is_object", 1) DEFTRAIT_EXPR (IS_POINTER_INTERCONVERTIBLE_BASE_OF, "__is_pointer_interconvertible_base_of", 2) DEFTRAIT_EXPR (IS_POD, "__is_pod", 1) +DEFTRAIT_EXPR (IS_POINTER, "__builtin_is_pointer", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 351235a639a..86372ea0aba 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12586,6 +12586,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_POD: return pod_type_p (type1); + case CPTK_IS_POINTER: + return TYPE_PTR_P (type1); + case CPTK_IS_POLYMORPHIC: return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1); @@ -12825,6 +12828,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: case CPTK_IS_OBJECT: + case CPTK_IS_POINTER: case CPTK_IS_REFERENCE: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 398719fe8d6..7954b42df97 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -17,6 +17,9 @@ #if !__has_builtin (__builtin_is_corresponding_member) # error "__has_builtin (__builtin_is_corresponding_member) failed" #endif +#if !__has_builtin (__builtin_is_pointer) +# error "__has_builtin (__builtin_is_pointer) failed" +#endif #if !__has_builtin (__builtin_is_pointer_interconvertible_with_class) # error "__has_builtin (__builtin_is_pointer_interconvertible_with_class) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_pointer.C b/gcc/testsuite/g++.dg/ext/is_pointer.C new file mode 100644 index 00000000000..9a7a4939bbe --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_pointer.C @@ -0,0 +1,51 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +SA(!__builtin_is_pointer(int)); +SA(__builtin_is_pointer(int*)); +SA(__builtin_is_pointer(int**)); + +SA(__builtin_is_pointer(const int*)); +SA(__builtin_is_pointer(const int**)); +SA(__builtin_is_pointer(int* const)); +SA(__builtin_is_pointer(int** const)); +SA(__builtin_is_pointer(int* const* const)); + +SA(__builtin_is_pointer(volatile int*)); +SA(__builtin_is_pointer(volatile int**)); +SA(__builtin_is_pointer(int* volatile)); +SA(__builtin_is_pointer(int** volatile)); +SA(__builtin_is_pointer(int* volatile* volatile)); + +SA(__builtin_is_pointer(const volatile int*)); +SA(__builtin_is_pointer(const volatile int**)); +SA(__builtin_is_pointer(const int* volatile)); +SA(__builtin_is_pointer(volatile int* const)); +SA(__builtin_is_pointer(int* const volatile)); +SA(__builtin_is_pointer(const int** volatile)); +SA(__builtin_is_pointer(volatile int** const)); +SA(__builtin_is_pointer(int** const volatile)); +SA(__builtin_is_pointer(int* const* const volatile)); +SA(__builtin_is_pointer(int* volatile* const volatile)); +SA(__builtin_is_pointer(int* const volatile* const volatile)); + +SA(!__builtin_is_pointer(int&)); +SA(!__builtin_is_pointer(const int&)); +SA(!__builtin_is_pointer(volatile int&)); +SA(!__builtin_is_pointer(const volatile int&)); + +SA(!__builtin_is_pointer(int&&)); +SA(!__builtin_is_pointer(const int&&)); +SA(!__builtin_is_pointer(volatile int&&)); +SA(!__builtin_is_pointer(const volatile int&&)); + +SA(!__builtin_is_pointer(int[3])); +SA(!__builtin_is_pointer(const int[3])); +SA(!__builtin_is_pointer(volatile int[3])); +SA(!__builtin_is_pointer(const volatile int[3])); + +SA(!__builtin_is_pointer(int(int))); +SA(__builtin_is_pointer(int(*const)(int))); +SA(__builtin_is_pointer(int(*volatile)(int))); +SA(__builtin_is_pointer(int(*const volatile)(int))); From patchwork Thu May 2 16:13:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1930694 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=qoXQnCX8; 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 4VVfL44Hqyz20fb for ; Fri, 3 May 2024 02:20:28 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A33D1384514A for ; Thu, 2 May 2024 16:20:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A33D1384514A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714666826; bh=fZRV6IINyVUrhvwz2wGPGrzEU2yJ28r4wya1pn1rQ8c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=qoXQnCX8Z29Sfq2sCYdbZiIEgxTB7BEzDtxJoDtfxkWoURooYHotKlbYfYnQwLJZQ IASCkdpUcxxfTRTIrRzlZ6kFfe0NmwDbf2z8lsunH+ZihLIXDSYda/QRbT0gt+P1ks a7LCtzwPD8FUWhAyjwKYfK+GWNTNmJTCUlH6in88= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 78E813858D20; Thu, 2 May 2024 16:16:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 78E813858D20 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 78E813858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666595; cv=none; b=h/uwuOiKTP+oqLdRbIT/uDvTuiPgeH/9huy9jBIj1nAbEUEaL4jppooN7pH23zZI1A9HVIQrXGO7PfxTdY5VmXJnD/Kw4KGrv3Qb5WXt3M8kt1tBMJoxKKw/RiNP7icBBCUmbN2/EQiaPc+wFHurBp1hkp7nnR/Rw/Z7ZYQGhNk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666595; c=relaxed/simple; bh=Ih8DBbyEZyp8RdDolGLswzdJyvELfM+6+A+/iu4B0RU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=DNLFBPomUUEMmmqWhicuPL4Ir+aAb545U2ywIn/eO5z/r5bz+Uog4wlYtb3nBlaid/IfRI3c+lG2vNFOkFj3E0oabTV8b/3FQPSsvDEYqlt44mr52sCbrnM7IgXLLg2hXmk34r1ZuP1Hx4/uK2MkZ4qq/Mo+vTLZqMyChRAGKMQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247478.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442FhmdD002879; Thu, 2 May 2024 16:16:33 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xv4e0kfhv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 16:16:32 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442GGGjk003504 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 09:16:16 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442GGFoj023119 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 09:16:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui , Jonathan Wakely Subject: [PATCH v16 06/26] libstdc++: Optimize std::is_pointer compilation performance Date: Thu, 2 May 2024 09:13:32 -0700 Message-ID: <20240502161614.3705912-7-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502161614.3705912-1-kmatsui@gcc.gnu.org> References: <20240228192843.188979-1-kmatsui@gcc.gnu.org> <20240502161614.3705912-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: DMssgssM3F3esahwclJUZNbcde0oBU-C X-Proofpoint-ORIG-GUID: DMssgssM3F3esahwclJUZNbcde0oBU-C X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_05,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 mlxscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 adultscore=0 mlxlogscore=432 phishscore=0 spamscore=0 lowpriorityscore=0 impostorscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020106 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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::is_pointer by dispatching to the new __builtin_is_pointer trait. libstdc++-v3/ChangeLog: * include/bits/cpp_type_traits.h (__is_pointer): Use __builtin_is_pointer trait. Optimize its implementation. * include/std/type_traits (is_pointer): Likewise. (is_pointer_v): Likewise. Co-authored-by: Jonathan Wakely Signed-off-by: Ken Matsui --- libstdc++-v3/include/bits/cpp_type_traits.h | 31 ++++++++++++++- libstdc++-v3/include/std/type_traits | 44 +++++++++++++++++---- 2 files changed, 66 insertions(+), 9 deletions(-) diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h index 59f1a1875eb..a780c205fd2 100644 --- a/libstdc++-v3/include/bits/cpp_type_traits.h +++ b/libstdc++-v3/include/bits/cpp_type_traits.h @@ -363,6 +363,13 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) // // Pointer types // +#if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_is_pointer) + template + struct __is_pointer : __truth_type<_IsPtr> + { + enum { __value = _IsPtr }; + }; +#else template struct __is_pointer { @@ -377,6 +384,28 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) typedef __true_type __type; }; + template + struct __is_pointer<_Tp* const> + { + enum { __value = 1 }; + typedef __true_type __type; + }; + + template + struct __is_pointer<_Tp* volatile> + { + enum { __value = 1 }; + typedef __true_type __type; + }; + + template + struct __is_pointer<_Tp* const volatile> + { + enum { __value = 1 }; + typedef __true_type __type; + }; +#endif + // // An arithmetic type is an integer type or a floating point type // @@ -387,7 +416,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) // // A scalar type is an arithmetic type or a pointer type - // + // template struct __is_scalar : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> > diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index e9674ff87d1..812619803f4 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -542,19 +542,33 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public true_type { }; #endif - template - struct __is_pointer_helper + /// is_pointer +#if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_is_pointer) + template + struct is_pointer + : public __bool_constant<__builtin_is_pointer(_Tp)> + { }; +#else + template + struct is_pointer : public false_type { }; template - struct __is_pointer_helper<_Tp*> + struct is_pointer<_Tp*> : public true_type { }; - /// is_pointer template - struct is_pointer - : public __is_pointer_helper<__remove_cv_t<_Tp>>::type - { }; + struct is_pointer<_Tp* const> + : public true_type { }; + + template + struct is_pointer<_Tp* volatile> + : public true_type { }; + + template + struct is_pointer<_Tp* const volatile> + : public true_type { }; +#endif /// is_lvalue_reference template @@ -3268,8 +3282,22 @@ template inline constexpr bool is_array_v<_Tp[_Num]> = true; #endif +#if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_is_pointer) +template + inline constexpr bool is_pointer_v = __builtin_is_pointer(_Tp); +#else template - inline constexpr bool is_pointer_v = is_pointer<_Tp>::value; + inline constexpr bool is_pointer_v = false; +template + inline constexpr bool is_pointer_v<_Tp*> = true; +template + inline constexpr bool is_pointer_v<_Tp* const> = true; +template + inline constexpr bool is_pointer_v<_Tp* volatile> = true; +template + inline constexpr bool is_pointer_v<_Tp* const volatile> = true; +#endif + template inline constexpr bool is_lvalue_reference_v = false; template From patchwork Thu May 2 16:13:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1930692 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=Byfbs8Rh; 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 4VVfJs4KmHz1ydT for ; Fri, 3 May 2024 02:19:25 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 94F553849AE0 for ; Thu, 2 May 2024 16:19:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 94F553849AE0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714666763; bh=jPXc1h2J1NCpRai9YZIHwqCkF6fxyy4IXLYL3ZM3e6I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Byfbs8RhTS4ZIHgklGsD02WAtL5dm7SFnfluRgGB80bdTFFfXPdGTTFwjvbPJbxV7 h01Bv3qkg5OPymkTzwm4s5S1VbFh/82Oc3yF8EPQ+T4Aa/Y0i6K+f2TDYtAc2Bc6o6 tUMHzHAmX172AzhyOY2/wmcI83XSTv6w7oL2Ylqk= 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 B1AA9385840A; Thu, 2 May 2024 16:16:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B1AA9385840A 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 B1AA9385840A 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=1714666597; cv=none; b=NJ6Hcbfq8srSWkYBNgdxMQebFfHIHl3M6X9nXDICBLKbcqwWyjGTJURC2rF6R9WEYpiEBX+DgQwiXx5GvBevhEhsVPYodpWU3K6X3BXrV8juR8QQ7Wm4ACqDx64AGS/XuQyxPB5ols6XA8ldMiIZQDUv4dxdXIzVQFwUD0eEKxg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666597; c=relaxed/simple; bh=/WXKRZPJPj5TjFNjP2pz6Ipq4+0rSugKmLH4fBMsYKI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=ghX8b8xXeGgdeAQAlwoiYW3HNgBbH4Ocxe4gSZX/ZcuDw5KsIxQwu3HEfYJWxqKFdkNNjJ1AZl2oLRCnm93G3KJ+PzDeVoAYYuPHVzEGw6oWrZCF0NLsJsa+dYWY0jhRsaXbadqL9cggmMjYolYQlcuieQfmBfpHSeb+SC+V9RQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247473.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442GBmmP017725; Thu, 2 May 2024 16:16:32 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xv4e2bp6w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 16:16:32 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442GGGxv003505 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 09:16:16 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442GGFok023119 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 09:16:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v16 07/26] c++: Implement __builtin_is_unbounded_array trait Date: Thu, 2 May 2024 09:13:33 -0700 Message-ID: <20240502161614.3705912-8-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502161614.3705912-1-kmatsui@gcc.gnu.org> References: <20240228192843.188979-1-kmatsui@gcc.gnu.org> <20240502161614.3705912-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: 01opouMX0wwMXBUwYWG101RhEK3qmeO9 X-Proofpoint-ORIG-GUID: 01opouMX0wwMXBUwYWG101RhEK3qmeO9 X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_08,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 malwarescore=0 lowpriorityscore=0 spamscore=0 suspectscore=0 clxscore=1034 mlxlogscore=622 adultscore=0 impostorscore=0 phishscore=0 priorityscore=1501 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020106 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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::is_unbounded_array. gcc/cp/ChangeLog: * cp-trait.def: Define __builtin_is_unbounded_array. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_UNBOUNDED_ARRAY. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __builtin_is_unbounded_array. * g++.dg/ext/is_unbounded_array.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 ++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_unbounded_array.C | 37 +++++++++++++++++++ 5 files changed, 48 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_unbounded_array.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 5a8aaa70fa6..d4cc8850486 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3862,6 +3862,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_TRIVIALLY_COPYABLE: inform (loc, " %qT is not trivially copyable", t1); break; + case CPTK_IS_UNBOUNDED_ARRAY: + inform (loc, " %qT is not an unbounded array", t1); + break; case CPTK_IS_UNION: inform (loc, " %qT is not a union", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index a6a3c195529..7a3cbbebde6 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -92,6 +92,7 @@ DEFTRAIT_EXPR (IS_TRIVIAL, "__is_trivial", 1) DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2) DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1) DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) +DEFTRAIT_EXPR (IS_UNBOUNDED_ARRAY, "__builtin_is_unbounded_array", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) DEFTRAIT_EXPR (IS_VOLATILE, "__builtin_is_volatile", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 86372ea0aba..138b180d9fb 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12616,6 +12616,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_TRIVIALLY_COPYABLE: return trivially_copyable_p (type1); + case CPTK_IS_UNBOUNDED_ARRAY: + return array_of_unknown_bound_p (type1); + case CPTK_IS_UNION: return type_code1 == UNION_TYPE; @@ -12832,6 +12835,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_REFERENCE: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: + case CPTK_IS_UNBOUNDED_ARRAY: case CPTK_IS_UNION: case CPTK_IS_VOLATILE: break; diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 7954b42df97..7eb341a8068 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -23,6 +23,9 @@ #if !__has_builtin (__builtin_is_pointer_interconvertible_with_class) # error "__has_builtin (__builtin_is_pointer_interconvertible_with_class) failed" #endif +#if !__has_builtin (__builtin_is_unbounded_array) +# error "__has_builtin (__builtin_is_unbounded_array) failed" +#endif #if !__has_builtin (__builtin_is_volatile) # error "__has_builtin (__builtin_is_volatile) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_unbounded_array.C b/gcc/testsuite/g++.dg/ext/is_unbounded_array.C new file mode 100644 index 00000000000..ac593b99aa7 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_unbounded_array.C @@ -0,0 +1,37 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +class ClassType { }; +class IncompleteClass; +union IncompleteUnion; + +SA_TEST_CATEGORY(__builtin_is_unbounded_array, int[2], false); +SA_TEST_CATEGORY(__builtin_is_unbounded_array, int[], true); +SA_TEST_CATEGORY(__builtin_is_unbounded_array, int[2][3], false); +SA_TEST_CATEGORY(__builtin_is_unbounded_array, int[][3], true); +SA_TEST_CATEGORY(__builtin_is_unbounded_array, float*[2], false); +SA_TEST_CATEGORY(__builtin_is_unbounded_array, float*[], true); +SA_TEST_CATEGORY(__builtin_is_unbounded_array, float*[2][3], false); +SA_TEST_CATEGORY(__builtin_is_unbounded_array, float*[][3], true); +SA_TEST_CATEGORY(__builtin_is_unbounded_array, ClassType[2], false); +SA_TEST_CATEGORY(__builtin_is_unbounded_array, ClassType[], true); +SA_TEST_CATEGORY(__builtin_is_unbounded_array, ClassType[2][3], false); +SA_TEST_CATEGORY(__builtin_is_unbounded_array, ClassType[][3], true); +SA_TEST_CATEGORY(__builtin_is_unbounded_array, IncompleteClass[2][3], false); +SA_TEST_CATEGORY(__builtin_is_unbounded_array, IncompleteClass[][3], true); +SA_TEST_CATEGORY(__builtin_is_unbounded_array, int(*)[2], false); +SA_TEST_CATEGORY(__builtin_is_unbounded_array, int(*)[], false); +SA_TEST_CATEGORY(__builtin_is_unbounded_array, int(&)[2], false); +SA_TEST_CATEGORY(__builtin_is_unbounded_array, int(&)[], false); + +// Sanity check. +SA_TEST_CATEGORY(__builtin_is_unbounded_array, ClassType, false); +SA_TEST_CATEGORY(__builtin_is_unbounded_array, IncompleteClass, false); +SA_TEST_CATEGORY(__builtin_is_unbounded_array, IncompleteUnion, false); From patchwork Thu May 2 16:13:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1930696 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=uaf4azhK; 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 4VVfMP4pbVz20fb for ; Fri, 3 May 2024 02:21:37 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4E0263846403 for ; Thu, 2 May 2024 16:21:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E0263846403 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714666895; bh=QX3mhh0mBIgN/haFxYTErjExLmUNn6OCBsR0dcdp2HU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=uaf4azhKg8fsVmEmPmW1+8uyJ87k1w+LayOD9E+/mWNrnNgjnaKcf1GlwetayB7mG +6wrTg1ZOS02FB1ucmDpC+G2uPTCgdr/qLmnYAN/ZJnk1WQSoJN/Ijc0eB4igT9k+W jcfohmSQm4qDmhYKeHgpzChNi9t0olUyeg1htk+c= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 49E49384AB5E; Thu, 2 May 2024 16:16:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 49E49384AB5E 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 49E49384AB5E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666606; cv=none; b=sDPDzY9C/hHxJNOUVbJG77yDf76sojIpcN8pHmZ7aSaVivPuSyxE6oic2bBU/q3xUBnwfb1BsXTaqioydCVMt0Y5Oz0YkKbo0KFMWD6kKNnFWCHZfRjfiFXV2F1kNSS5bgHaEkOe0bgPKiW6go9b5GaDJmWziIKhA6D16Dcl1fk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666606; c=relaxed/simple; bh=mys8ktj8PAq6PFcnxZ0at+ZXlaTAxdVt7skd3K+a5mI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=cpgAGit/QfX40RB8bnZd+cB1ccLPMUfk2Sx/hYvnLAUCxVCtZEggKncOeEoIu6J0tX8Hnf/4yLUv66m0iBhbcu2yw7Uz4PjAYBiEWsI3MVahpTQz0NFd9xu4TXp1KgEQWE/E5uric7HU+ctKJQtJiR4fW7e2jgSwY6/JT4EhZLY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247478.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442GBZCC006112; Thu, 2 May 2024 16:16:37 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xv4e0kfjk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 16:16:37 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442GGGsN024915 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 09:16:16 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442GGFol023119 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 09:16:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v16 08/26] libstdc++: Optimize std::is_unbounded_array compilation performance Date: Thu, 2 May 2024 09:13:34 -0700 Message-ID: <20240502161614.3705912-9-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502161614.3705912-1-kmatsui@gcc.gnu.org> References: <20240228192843.188979-1-kmatsui@gcc.gnu.org> <20240502161614.3705912-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: liEEcvTrGet3nlEht_RBbXC9klm1Cqrg X-Proofpoint-ORIG-GUID: liEEcvTrGet3nlEht_RBbXC9klm1Cqrg X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_05,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 mlxscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 adultscore=0 mlxlogscore=553 phishscore=0 spamscore=0 lowpriorityscore=0 impostorscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020106 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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::is_unbounded_array by dispatching to the new __builtin_is_unbounded_array trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_unbounded_array_v): Use __builtin_is_unbounded_array trait. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 812619803f4..3d7d00c3bb8 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3710,11 +3710,17 @@ template /// True for a type that is an array of unknown bound. /// @ingroup variable_templates /// @since C++20 +# if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_is_unbounded_array) + template + inline constexpr bool is_unbounded_array_v = + __builtin_is_unbounded_array(_Tp); +# else template inline constexpr bool is_unbounded_array_v = false; template inline constexpr bool is_unbounded_array_v<_Tp[]> = true; +# endif /// True for a type that is an array of known bound. /// @since C++20 From patchwork Thu May 2 16:13:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1930697 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=goPptg0v; 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 4VVfNG5gXpz20fb for ; Fri, 3 May 2024 02:22:22 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D833F3844772 for ; Thu, 2 May 2024 16:22:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D833F3844772 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714666940; bh=iZMIHrjJSLQhWLHoU/2C9874xyH0PAUESfPnOkiOcXU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=goPptg0vjc3BEMOggYjVARtsIM9UgGLneWXYBFk15SftqMCv+glifLtElgunKYQIi A7T5d5JDSL77Mt8kmpmBh1vB+ldbcd6EtLX1mX7BsT3pG5UeKhkCZMWiK3ZbFSHnjQ ralUKDhfSEjdWfRIuyAmKuXwaBqueANBnHsmOwwo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id EB753385842D; Thu, 2 May 2024 16:16:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EB753385842D 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 EB753385842D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666597; cv=none; b=hfpMkEmGuUVVek1if7mJKwKuVu6DKDxigyG2Z+1Rafzr/RWN0YzubvoaknUyqn7a9ToEWbEOkFycx6w1Qxt++GDdJ8jGg8PfG1PEWSGKebWtJ1Xb0JPXeYz7t7R2XM8ccaHcdO8cgadZQcirSjP06oMBJFbx1aNxrcV3RKK5k5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666597; c=relaxed/simple; bh=V6i+ATSAq3aJd2gyvlmLtx291cI18vYPXLJR2yGhYnY=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=QQOl4xq9/EhpKwaoZBlmCjHeLNMIeTKxi+O3877GK10dCpa0fD42hQnpFS1FJwcgfDLBJdFYwmJxVVhcmKezOJCbf709APOowvR0FS9NS8/XAW/fe1w9mzV4aB2HVAIxaV3G4H8SUjlIhrZvGBU5aq/LvwrdyjOSTrOVB9yh1+U= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247477.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442GAsUi028310; Thu, 2 May 2024 16:16:33 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xv4e5kd3g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 16:16:32 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442GGGpu003506 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 09:16:16 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442GGFom023119 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 09:16:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v16 09/26] c++: Implement __builtin_add_pointer trait Date: Thu, 2 May 2024 09:13:35 -0700 Message-ID: <20240502161614.3705912-10-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502161614.3705912-1-kmatsui@gcc.gnu.org> References: <20240228192843.188979-1-kmatsui@gcc.gnu.org> <20240502161614.3705912-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: hSipzt1qQ0HdTWnXqqSqKjDympEZqufP X-Proofpoint-ORIG-GUID: hSipzt1qQ0HdTWnXqqSqKjDympEZqufP X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_05,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=732 spamscore=0 priorityscore=1501 suspectscore=0 phishscore=0 adultscore=0 impostorscore=0 bulkscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1034 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020106 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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 __builtin_add_pointer. * semantics.cc (finish_trait_type): Handle CPTK_ADD_POINTER. (object_type_p): New function. (referenceable_type_p): Likewise. (trait_expr_value): Use object_type_p. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __builtin_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 | 36 ++++++++++++++++++++-- gcc/testsuite/g++.dg/ext/add_pointer.C | 39 ++++++++++++++++++++++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ 4 files changed, 76 insertions(+), 3 deletions(-) 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 7a3cbbebde6..7847ce748f6 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, "__builtin_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 138b180d9fb..29c1dbe2a85 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12434,6 +12434,16 @@ fold_builtin_is_corresponding_member (location_t loc, int nargs, fold_convert (TREE_TYPE (arg1), arg2))); } +/* [basic.types] 8. True iff TYPE is an object type. */ + +static bool +object_type_p (const_tree type) +{ + return (TREE_CODE (type) != FUNCTION_TYPE + && !TYPE_REF_P (type) + && !VOID_TYPE_P (type)); +} + /* Actually evaluates the trait. */ static bool @@ -12576,9 +12586,7 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) return is_nothrow_convertible (type1, type2); case CPTK_IS_OBJECT: - return (type_code1 != FUNCTION_TYPE - && type_code1 != REFERENCE_TYPE - && type_code1 != VOID_TYPE); + return object_type_p (type1); case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF: return pointer_interconvertible_base_of_p (type1, type2); @@ -12733,6 +12741,18 @@ same_type_ref_bind_p (cp_trait_kind kind, tree type1, tree type2) (non_reference (to), non_reference (from)))); } +/* [defns.referenceable] True iff TYPE is a referenceable type. */ + +static bool +referenceable_type_p (const_tree type) +{ + return (TYPE_REF_P (type) + || object_type_p (type) + || (FUNC_OR_METHOD_TYPE_P (type) + && (type_memfn_quals (type) == TYPE_UNQUALIFIED + && type_memfn_rqual (type) == REF_QUAL_NONE))); +} + /* Process a trait expression. */ tree @@ -12900,6 +12920,16 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, switch (kind) { + case CPTK_ADD_POINTER: + /* [meta.trans.ptr]. */ + if (VOID_TYPE_P (type1) || referenceable_type_p (type1)) + { + if (TYPE_REF_P (type1)) + type1 = TREE_TYPE (type1); + return build_pointer_type (type1); + } + return 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..1b9a318e7d9 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/add_pointer.C @@ -0,0 +1,39 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +class ClassType { }; + +SA(__is_same(__builtin_add_pointer(int), int*)); +SA(__is_same(__builtin_add_pointer(int*), int**)); +SA(__is_same(__builtin_add_pointer(const int), const int*)); +SA(__is_same(__builtin_add_pointer(int&), int*)); +SA(__is_same(__builtin_add_pointer(ClassType*), ClassType**)); +SA(__is_same(__builtin_add_pointer(ClassType), ClassType*)); +SA(__is_same(__builtin_add_pointer(void), void*)); +SA(__is_same(__builtin_add_pointer(const void), const void*)); +SA(__is_same(__builtin_add_pointer(volatile void), volatile void*)); +SA(__is_same(__builtin_add_pointer(const volatile void), const volatile void*)); + +void f1(); +using f1_type = decltype(f1); +using pf1_type = decltype(&f1); +SA(__is_same(__builtin_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(__builtin_add_pointer(f2_type), pf2_type)); + +using fn_type = void(); +using pfn_type = void(*)(); +SA(__is_same(__builtin_add_pointer(fn_type), pfn_type)); + +SA(__is_same(__builtin_add_pointer(void() &), void() &)); +SA(__is_same(__builtin_add_pointer(void() & noexcept), void() & noexcept)); +SA(__is_same(__builtin_add_pointer(void() const), void() const)); +SA(__is_same(__builtin_add_pointer(void(...) &), void(...) &)); +SA(__is_same(__builtin_add_pointer(void(...) & noexcept), void(...) & noexcept)); +SA(__is_same(__builtin_add_pointer(void(...) const), void(...) const)); + +SA(__is_same(__builtin_add_pointer(void() __restrict), void() __restrict)); diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 7eb341a8068..509cd4294f6 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -5,6 +5,9 @@ #if !__has_builtin (__builtin_addressof) # error "__has_builtin (__builtin_addressof) failed" #endif +#if !__has_builtin (__builtin_add_pointer) +# error "__has_builtin (__builtin_add_pointer) failed" +#endif #if !__has_builtin (__builtin_bit_cast) # error "__has_builtin (__builtin_bit_cast) failed" #endif From patchwork Thu May 2 16:13:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1930722 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=QPzLsgUW; 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 4VVfZh0JPpz1ydT for ; Fri, 3 May 2024 02:31:24 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2C95C384474A for ; Thu, 2 May 2024 16:31:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2C95C384474A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714667482; bh=Car4UBZfY9QKWYqqEFPSA1bZT+1PzqJbNC2ypkwu9VA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=QPzLsgUWtGDE0vHJuaNQ76MrqToIu6GHBsbKkQ1UlSRIWW2vvwP/RxazJlJNx23Ep XZhExOyCWC4+4EzXjLWNDGaiG5pMeVxTLRSxgTxZl9naE4HJj4q3C0x2Xa/EvHWEHA +9yBi+j7JcX0RjcRKeB1vhLyxf5PmpMg3Vbz4igI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id B89A5384AB55; Thu, 2 May 2024 16:16:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B89A5384AB55 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 B89A5384AB55 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666614; cv=none; b=Athhfb43N4Hc5jjNIjgASn15tUFqNz+Oy90AoxnrVyivfXEADYdmN+nCfGiohlmEBNscDeGHRD/BA5f1x45I2/umzl+CaSPRQhlqx33quESGrbBatdEo1xitgG7MvxyZ6FPQIUCbD0MV3oNK5yTNJ0WfX6YjzWXjXxaxMy10mhc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666614; c=relaxed/simple; bh=PuO8vOYeXmCD28528HssOUATtQMRh/+DqA0gzty9C9k=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=naOmzqN4lzAA+PzZHVrbrF2Eo9ecWLGXt3r8a2n56Enz10yHb+IkNUsTRgK0fLsVrx1WJ3rowBe6gWNWWNfxiEz2+IIVTd5Yw/4IOWAzwiqhbNgZSZsxKhHKueNtmVtOmE0OtfLRK5klLx25K8On8pC5CybMIeV7wrofF0GxfXs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442GExmZ023338; Thu, 2 May 2024 16:16:38 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xv4e2uemt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 16:16:38 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442GGGdV024916 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 09:16:16 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442GGFon023119 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 09:16:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v16 10/26] libstdc++: Optimize std::add_pointer compilation performance Date: Thu, 2 May 2024 09:13:36 -0700 Message-ID: <20240502161614.3705912-11-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502161614.3705912-1-kmatsui@gcc.gnu.org> References: <20240228192843.188979-1-kmatsui@gcc.gnu.org> <20240502161614.3705912-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: 2etIm-klREdl2d3iZ7xPojFrhSan5wr9 X-Proofpoint-ORIG-GUID: 2etIm-klREdl2d3iZ7xPojFrhSan5wr9 X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_05,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 priorityscore=1501 bulkscore=0 suspectscore=0 clxscore=1034 mlxlogscore=683 spamscore=0 mlxscore=0 phishscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020106 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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 __builtin_add_pointer trait. libstdc++-v3/ChangeLog: * include/std/type_traits (add_pointer): Use __builtin_add_pointer 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 3d7d00c3bb8..59d952194af 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -2149,6 +2149,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; #endif + /// add_pointer +#if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_add_pointer) + template + struct add_pointer + { using type = __builtin_add_pointer(_Tp); }; +#else template struct __add_pointer_helper { using type = _Tp; }; @@ -2157,7 +2163,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> @@ -2170,6 +2175,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct add_pointer<_Tp&&> { using type = _Tp*; }; +#endif #if __cplusplus > 201103L /// Alias template for remove_pointer From patchwork Thu May 2 16:13:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1930698 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=R7CE37wd; 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 4VVfNH3C9xz23hd for ; Fri, 3 May 2024 02:22:23 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 99714384403B for ; Thu, 2 May 2024 16:22:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 99714384403B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714666941; bh=IJAicifYyY4cBbHaGozmMg5OCK6w1D2b3xqWeQ8c7BI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=R7CE37wd2qjadynQ61RmbVAE5njusAo2FpwKZDqas+pOL22AXM+6MbooCZZTNK9pE HouJlmtDD4Xk2tub47IolvPONsDtbFabWTqtvXsqssAH1NDv6AKatBM5SttkFt4UXd tG5VqYuO1sQSME9MCcVP+7czUz6gyeSrcQZyJ8Ug= 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 AC0753858C32; Thu, 2 May 2024 16:16:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AC0753858C32 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 AC0753858C32 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=1714666596; cv=none; b=p9L5WwYPLs/WUmgrPjuvwaJOBMEKQU0bIPU+Ldiub1/i5ira9K94nDIIjLIoQOeNL9CNyv093faaINpkg6jo5mx03NzfVfldpkFfqSFJbC7j+kwO1x4apMn2oiYfsEK4lmWZ0F+5Ll08d74jFm+35fqM0/Zh7Flpmt8zxvwqtBE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666596; c=relaxed/simple; bh=Ht4iGkd9Jd/wJls3RQxjEKBpzMdvBPE/eznRkT/z3Ow=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=LYcbjDTTjH9vJMfOeoY52Gs9rPiQmMxOyajGj8ue8aib4TkA2qfp4Ng+X6TPyJVhPvWZER/GJvNEcg8PFZKUwO6E5R7MbtHRjjCRdYzlhE+6LGzGdc8m6srVI7AE3fwzeL1O3TDkXkmlMR5DSEjf4lxZBIBH/F0Ap8KW+7iYXOg= 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.18.1.2/8.18.1.2) with ESMTP id 442GE8ip010122; Thu, 2 May 2024 16:16:32 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xv4e23sxh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 16:16:32 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442GGGD5003507 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 09:16:16 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442GGFoo023119 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 09:16:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v16 11/26] c++: Implement __builtin_remove_extent trait Date: Thu, 2 May 2024 09:13:37 -0700 Message-ID: <20240502161614.3705912-12-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502161614.3705912-1-kmatsui@gcc.gnu.org> References: <20240228192843.188979-1-kmatsui@gcc.gnu.org> <20240502161614.3705912-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: -_e8ZPsvB0ee56awL-Td_ZSSHoMhdHfS X-Proofpoint-ORIG-GUID: -_e8ZPsvB0ee56awL-Td_ZSSHoMhdHfS X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_08,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 priorityscore=1501 mlxscore=0 adultscore=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 impostorscore=0 mlxlogscore=489 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020106 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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::remove_extent. gcc/cp/ChangeLog: * cp-trait.def: Define __builtin_remove_extent. * semantics.cc (finish_trait_type): Handle CPTK_REMOVE_EXTENT. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __builtin_remove_extent. * g++.dg/ext/remove_extent.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 5 +++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ gcc/testsuite/g++.dg/ext/remove_extent.C | 16 ++++++++++++++++ 4 files changed, 25 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/remove_extent.C diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 7847ce748f6..56b706a6127 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -100,6 +100,7 @@ DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_tempo DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) DEFTRAIT_TYPE (REMOVE_CV, "__remove_cv", 1) DEFTRAIT_TYPE (REMOVE_CVREF, "__remove_cvref", 1) +DEFTRAIT_TYPE (REMOVE_EXTENT, "__builtin_remove_extent", 1) DEFTRAIT_TYPE (REMOVE_POINTER, "__remove_pointer", 1) DEFTRAIT_TYPE (REMOVE_REFERENCE, "__remove_reference", 1) DEFTRAIT_TYPE (TYPE_PACK_ELEMENT, "__type_pack_element", -1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 29c1dbe2a85..383259fca56 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12938,6 +12938,11 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, type1 = TREE_TYPE (type1); return cv_unqualified (type1); + case CPTK_REMOVE_EXTENT: + if (TREE_CODE (type1) == ARRAY_TYPE) + type1 = TREE_TYPE (type1); + return type1; + case CPTK_REMOVE_POINTER: if (TYPE_PTR_P (type1)) type1 = TREE_TYPE (type1); diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 509cd4294f6..d2f91862c03 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -35,6 +35,9 @@ #if !__has_builtin (__builtin_launder) # error "__has_builtin (__builtin_launder) failed" #endif +#if !__has_builtin (__builtin_remove_extent) +# error "__has_builtin (__builtin_remove_extent) failed" +#endif #if !__has_builtin (__builtin_source_location) # error "__has_builtin (__builtin_source_location) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/remove_extent.C b/gcc/testsuite/g++.dg/ext/remove_extent.C new file mode 100644 index 00000000000..70c6bc3d84d --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/remove_extent.C @@ -0,0 +1,16 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +class ClassType { }; + +SA(__is_same(__builtin_remove_extent(int), int)); +SA(__is_same(__builtin_remove_extent(int[2]), int)); +SA(__is_same(__builtin_remove_extent(int[2][3]), int[3])); +SA(__is_same(__builtin_remove_extent(int[][3]), int[3])); +SA(__is_same(__builtin_remove_extent(const int[2]), const int)); +SA(__is_same(__builtin_remove_extent(ClassType), ClassType)); +SA(__is_same(__builtin_remove_extent(ClassType[2]), ClassType)); +SA(__is_same(__builtin_remove_extent(ClassType[2][3]), ClassType[3])); +SA(__is_same(__builtin_remove_extent(ClassType[][3]), ClassType[3])); +SA(__is_same(__builtin_remove_extent(const ClassType[2]), const ClassType)); From patchwork Thu May 2 16:13:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1930705 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=XByu/cCM; 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 4VVfSk4CVnz1ydX for ; Fri, 3 May 2024 02:26:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C64D7384AB5F for ; Thu, 2 May 2024 16:26:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C64D7384AB5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714667172; bh=smQPwushxJHUsmdVlJYKAL6t0LwTOc4orCO+ZzWUYzo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=XByu/cCMxNw8S+rwh0ZwqR7FrXAvTLmLWDPEaeE+LPCKnnybNcJZKhqDrN7UCLTNg oePOJ0A9gnH02UHMxKXDLIIhQbJCXoEAeCYEO/PZ7ZtFmCoGNZwQZO2tlnlpoglcCl +yylIWJgm6td23xXFJ3FQvxZ94p/nZGbw8HzWSig= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 747C2384AB66; Thu, 2 May 2024 16:16:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 747C2384AB66 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 747C2384AB66 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666606; cv=none; b=J4xSxqT3PtGAqFgfeYJrVsNHT8DXmoKBc1ayFflMAqYKpqaz1qnY7nBEiPMPQzJu7QQeB0KKvQdoMwp2cwtYS6dz5MdJGwIkykcAun9LI7yIavVXdLuHrQWJa+imrbf810hvKmD0ZEY9zFf8SLn5x1TUhT0D0imLyphjISQ+kbs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666606; c=relaxed/simple; bh=uKRAECOO63jmFyOZ53a7vfX0BSRr8xwNqXr89raR2NQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=vAf4yj2FMz9AM5BOsdx8ndEC81mGZYjTKyknw8O/lMujzSs0YLM7DWtWQ9XD3ZEVwQBkMPlVJBda8cJTeqR+K+HdbPkK3LhjFIFq9w+c2JqBqlJDCkvNowzc13B4yHi72lJCnvuUz8lJCJLDcVtOOyZviUg8eXJfOxubD63R0uE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247476.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442FtXbO022929; Thu, 2 May 2024 16:16:38 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xv4e4kd98-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 16:16:37 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442GGGCw024917 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 09:16:16 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442GGFop023119 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 09:16:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v16 12/26] libstdc++: Optimize std::remove_extent compilation performance Date: Thu, 2 May 2024 09:13:38 -0700 Message-ID: <20240502161614.3705912-13-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502161614.3705912-1-kmatsui@gcc.gnu.org> References: <20240228192843.188979-1-kmatsui@gcc.gnu.org> <20240502161614.3705912-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: yz-kmbowv9qJlKRb7wudtdh27nMsYnI8 X-Proofpoint-GUID: yz-kmbowv9qJlKRb7wudtdh27nMsYnI8 X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_05,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 lowpriorityscore=0 suspectscore=0 bulkscore=0 phishscore=0 mlxscore=0 priorityscore=1501 clxscore=1034 impostorscore=0 mlxlogscore=702 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020106 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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::remove_extent by dispatching to the new __builtin_remove_extent trait. libstdc++-v3/ChangeLog: * include/std/type_traits (remove_extent): Use __builtin_remove_extent trait. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 59d952194af..36136440fdd 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -2092,6 +2092,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Array modifications. /// remove_extent +#if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_remove_extent) + template + struct remove_extent + { using type = __builtin_remove_extent(_Tp); }; +#else template struct remove_extent { using type = _Tp; }; @@ -2103,6 +2108,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct remove_extent<_Tp[]> { using type = _Tp; }; +#endif /// remove_all_extents template From patchwork Thu May 2 16:13:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1930702 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=RhLrdwMC; 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 4VVfQ111HSz20fb for ; Fri, 3 May 2024 02:23:53 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 61A78386F83C for ; Thu, 2 May 2024 16:23:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 61A78386F83C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714667031; bh=Fvmxrb3CCQ3uQXLDEy37pOO64+PxyT4PUQtSYiWFltI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=RhLrdwMCLSs9jK1pMrVCBa2d++k9sdvKz2UExKZrqL1V5IYMHetQYfhHzfh+6Px6B 4qDQMFXwhrO7JkJX/46fBDem55wCn+loamnXEPPsZ+RxnsM6ybVIhYNy6Vd4cf83tg nrsh0Q39TVcr4rnCB1gRTnIZMwvTzwdUmJA/E/V0= 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 BF04D385840F; Thu, 2 May 2024 16:16:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BF04D385840F 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 BF04D385840F 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=1714666597; cv=none; b=ttFGszEJTLxL1X6Z4IFpesqdBgQVG/x6Edi78+OE7+frwFgKWCXHO6hrwLlp5Bp3mgZmk//qHhpbYcRH2lUkfYK8zmHwaPyhrGiwsc6XC1S+dyV6cmDJy+0FzVpicbPIKBzIpZIw3/Eg/q7azX0MkQm9u0TDfx0VbKBqO5UJw+M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666597; c=relaxed/simple; bh=UxmYt07xBQWNCl6QnwdgQ/TB9hgEdxXltUtVsbnp4co=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=L6OjxYZt1YQtCZtwjFUqqezdmfGEk2YPTBGwpeNufNXUeg2ep3V01dByw5fRe9hjyBWe1D7p205OfY3bKDy12kF5p8aVNnczpvOKMrhbKx7Akwnxrsg64ykWRTc7ogUBkm9xkrTb9Qz0tTUl05Rglc21PtPUDIJSKKI2cdunwe0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247473.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442GFKi4025466; Thu, 2 May 2024 16:16:32 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xv4e2bp6x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 16:16:32 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442GGGkV003510 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 09:16:16 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442GGFoq023119 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 09:16:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v16 13/26] c++: Implement __builtin_remove_all_extents trait Date: Thu, 2 May 2024 09:13:39 -0700 Message-ID: <20240502161614.3705912-14-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502161614.3705912-1-kmatsui@gcc.gnu.org> References: <20240228192843.188979-1-kmatsui@gcc.gnu.org> <20240502161614.3705912-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: -P-CW7J5YjTs8zKp_oB6OZJ12QobmbMW X-Proofpoint-ORIG-GUID: -P-CW7J5YjTs8zKp_oB6OZJ12QobmbMW X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_08,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 malwarescore=0 lowpriorityscore=0 spamscore=0 suspectscore=0 clxscore=1034 mlxlogscore=501 adultscore=0 impostorscore=0 phishscore=0 priorityscore=1501 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020106 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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::remove_all_extents. gcc/cp/ChangeLog: * cp-trait.def: Define __builtin_remove_all_extents. * semantics.cc (finish_trait_type): Handle CPTK_REMOVE_ALL_EXTENTS. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __builtin_remove_all_extents. * g++.dg/ext/remove_all_extents.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 3 +++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ gcc/testsuite/g++.dg/ext/remove_all_extents.C | 16 ++++++++++++++++ 4 files changed, 23 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/remove_all_extents.C diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 56b706a6127..4df0c63032e 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -98,6 +98,7 @@ DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) DEFTRAIT_EXPR (IS_VOLATILE, "__builtin_is_volatile", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) +DEFTRAIT_TYPE (REMOVE_ALL_EXTENTS, "__builtin_remove_all_extents", 1) DEFTRAIT_TYPE (REMOVE_CV, "__remove_cv", 1) DEFTRAIT_TYPE (REMOVE_CVREF, "__remove_cvref", 1) DEFTRAIT_TYPE (REMOVE_EXTENT, "__builtin_remove_extent", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 383259fca56..07779a79d24 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12930,6 +12930,9 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, } return type1; + case CPTK_REMOVE_ALL_EXTENTS: + return strip_array_types (type1); + case CPTK_REMOVE_CV: return cv_unqualified (type1); diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index d2f91862c03..7ca80daf6d1 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -35,6 +35,9 @@ #if !__has_builtin (__builtin_launder) # error "__has_builtin (__builtin_launder) failed" #endif +#if !__has_builtin (__builtin_remove_all_extents) +# error "__has_builtin (__builtin_remove_all_extents) failed" +#endif #if !__has_builtin (__builtin_remove_extent) # error "__has_builtin (__builtin_remove_extent) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/remove_all_extents.C b/gcc/testsuite/g++.dg/ext/remove_all_extents.C new file mode 100644 index 00000000000..029a029e6d9 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/remove_all_extents.C @@ -0,0 +1,16 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +class ClassType { }; + +SA(__is_same(__builtin_remove_all_extents(int), int)); +SA(__is_same(__builtin_remove_all_extents(int[2]), int)); +SA(__is_same(__builtin_remove_all_extents(int[2][3]), int)); +SA(__is_same(__builtin_remove_all_extents(int[][3]), int)); +SA(__is_same(__builtin_remove_all_extents(const int[2][3]), const int)); +SA(__is_same(__builtin_remove_all_extents(ClassType), ClassType)); +SA(__is_same(__builtin_remove_all_extents(ClassType[2]), ClassType)); +SA(__is_same(__builtin_remove_all_extents(ClassType[2][3]), ClassType)); +SA(__is_same(__builtin_remove_all_extents(ClassType[][3]), ClassType)); +SA(__is_same(__builtin_remove_all_extents(const ClassType[2][3]), const ClassType)); From patchwork Thu May 2 16:13:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1930723 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=y7fQDWf/; 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 4VVfZj72tRz1ydT for ; Fri, 3 May 2024 02:31:25 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3E9F4384641C for ; Thu, 2 May 2024 16:31:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3E9F4384641C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714667484; bh=6degbOzPfAbHWQEoUqO0+MhkNf7ofgfUEzCbt+fVh14=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=y7fQDWf/ktLw7ZainzzX+p+r/AYG7en7I+HSGCbvW7Hfrh/CE0QXhyupruwXnnhpv L/jxBulPyZASQiu4fjuFYIxK3/fBegxuQFA7cDyFHgPAa4tKn5I1v7OltDWT2KHw2n D3YVG5AMtFmFjqTe0n7WY/XLz4KawurVJwLPfW/o= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 49E13384AB5D; Thu, 2 May 2024 16:16:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 49E13384AB5D 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 49E13384AB5D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666605; cv=none; b=x44b+gpkn9y0Hvupb+c//V2TfF58RQugI7X5R2K1ZvSMJZEcgNreLyf+27ladZVnCqed38KNJZGxp8OmoYi+Xr9kWal3CZoiDOiU9MT0N+fw4MwB+bFsOPmSIhC3xS8HqKAMj9zTo0TVkLp7My+9uT1DAyzOyK8ouIBornCuQj0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666605; c=relaxed/simple; bh=JogDg5lk7qviN8YC5LoODZ+ZL9QBf8mrw8shPLEQNLU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=QJExzTlIp8SunFvfHtnNKdNs3OThUyiZvYK4ABbOfr1H9wxslSe43cNH02qZpJVLt7JZBgL2QXgxpWm26E3sIJ+EBzDvOaFWnmqdm+BokQjZkbVToS88pLuMm44bSlm9h5G1ZY2WJK0W5cYpobSLxTntzFZOwn9BixyJ8K7BBuY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442GEuhQ023317; Thu, 2 May 2024 16:16:37 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xv4e2uems-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 16:16:37 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442GGG7Y024918 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 09:16:16 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442GGFor023119 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 09:16:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v16 14/26] libstdc++: Optimize std::remove_all_extents compilation performance Date: Thu, 2 May 2024 09:13:40 -0700 Message-ID: <20240502161614.3705912-15-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502161614.3705912-1-kmatsui@gcc.gnu.org> References: <20240228192843.188979-1-kmatsui@gcc.gnu.org> <20240502161614.3705912-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: pHshDXVs5gxe-MJ2WAsodxtsWrLpxJrt X-Proofpoint-ORIG-GUID: pHshDXVs5gxe-MJ2WAsodxtsWrLpxJrt X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_05,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 priorityscore=1501 bulkscore=0 suspectscore=0 clxscore=1034 mlxlogscore=857 spamscore=0 mlxscore=0 phishscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020106 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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::remove_all_extents by dispatching to the new __builtin_remove_all_extents trait. libstdc++-v3/ChangeLog: * include/std/type_traits (remove_all_extents): Use __builtin_remove_all_extents trait. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 36136440fdd..8f756712c63 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -2111,6 +2111,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif /// remove_all_extents +#if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_remove_all_extents) + template + struct remove_all_extents + { using type = __builtin_remove_all_extents(_Tp); }; +#else template struct remove_all_extents { using type = _Tp; }; @@ -2122,6 +2127,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct remove_all_extents<_Tp[]> { using type = typename remove_all_extents<_Tp>::type; }; +#endif #if __cplusplus > 201103L /// Alias template for remove_extent From patchwork Thu May 2 16:13:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1930695 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=DZ7S6vZE; 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 4VVfM90kwdz20fb for ; Fri, 3 May 2024 02:21:25 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 35C103849AC6 for ; Thu, 2 May 2024 16:21:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 35C103849AC6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714666883; bh=08TsQS2vCHcJA0dNTrKuFn038tgMqIAMiV5EW2w5BPU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=DZ7S6vZEkwBkHLvLLVvMYhsuZ9ffoRCcWH6ta+NGlWv6diYVZA0c1QP6gTYRI84oN mrvp1nu4VpADz2KEO8+jH6l3uH68kmMnhkq008ad3Td9yhgDEOJWI3GdMcdxUPigv7 lAju9OmerVrVNgDVRzC2r92ONC08LdhxJN541NGs= 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 0A7E73858289; Thu, 2 May 2024 16:16:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0A7E73858289 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 0A7E73858289 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=1714666601; cv=none; b=rRbh489ld37AtrkYeGxmvycrPUQL+gvJbbVK8lpvMPbSlJjRIdMZc+ZI7n7VYw4uXZy3h872+GqwCI5u5VL9D8RIWGGGsko2eZ2QVsgbbSe5lJQzU1aoLSWRVA9RYh7mYCtzZE15DkBLu0TTbbYVOSIDPssLY0lTzvWrPLsJ7us= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666601; c=relaxed/simple; bh=4qBCb6WHZCcFt2y8nea8NhA/LmYtZ2ZYxQSkYHsVITE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=ezBgi9E2cTgvPW0/UTOPykuf4teM5fg0hZ7yZ8wwODVEOuTuHwY2oKSl9gaq75FKe3DEGglY2g42QJi6mYwZbl/4brO8NKeV2GvYSqYXStbNLgdfg/hRk8twbYAeAqwpenmMyDEWo/JZ9oPKkmPLDuKHsHEQgJyh2/G8NFW4SjE= 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.18.1.2/8.18.1.2) with ESMTP id 442GBMEu032012; Thu, 2 May 2024 16:16:33 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xv4e43h33-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 16:16:32 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442GGGjR003512 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 09:16:16 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442GGFos023119 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 09:16:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v16 15/26] c++: Implement __builtin_add_lvalue_reference trait Date: Thu, 2 May 2024 09:13:41 -0700 Message-ID: <20240502161614.3705912-16-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502161614.3705912-1-kmatsui@gcc.gnu.org> References: <20240228192843.188979-1-kmatsui@gcc.gnu.org> <20240502161614.3705912-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: Okzg04Lw8jBNMpJIdNX6BnXWfqMTaubO X-Proofpoint-ORIG-GUID: Okzg04Lw8jBNMpJIdNX6BnXWfqMTaubO X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_08,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 bulkscore=0 mlxlogscore=913 suspectscore=0 impostorscore=0 phishscore=0 clxscore=1034 malwarescore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020106 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_H2, SPF_HELO_NONE, SPF_NEUTRAL, TVD_SPACE_RATIO, TXREP 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_lvalue_reference. gcc/cp/ChangeLog: * cp-trait.def: Define __builtin_add_lvalue_reference. * semantics.cc (finish_trait_type): Handle CPTK_ADD_LVALUE_REFERENCE. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __builtin_add_lvalue_reference. * g++.dg/ext/add_lvalue_reference.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 6 ++++++ .../g++.dg/ext/add_lvalue_reference.C | 21 +++++++++++++++++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ 4 files changed, 31 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/add_lvalue_reference.C diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 4df0c63032e..228df46e3e4 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_LVALUE_REFERENCE, "__builtin_add_lvalue_reference", 1) DEFTRAIT_TYPE (ADD_POINTER, "__builtin_add_pointer", 1) DEFTRAIT_EXPR (HAS_NOTHROW_ASSIGN, "__has_nothrow_assign", 1) DEFTRAIT_EXPR (HAS_NOTHROW_CONSTRUCTOR, "__has_nothrow_constructor", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 07779a79d24..9f2220a1a91 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12920,6 +12920,12 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, switch (kind) { + case CPTK_ADD_LVALUE_REFERENCE: + /* [meta.trans.ref]. */ + if (referenceable_type_p (type1)) + return cp_build_reference_type (type1, /*rval=*/false); + return type1; + case CPTK_ADD_POINTER: /* [meta.trans.ptr]. */ if (VOID_TYPE_P (type1) || referenceable_type_p (type1)) diff --git a/gcc/testsuite/g++.dg/ext/add_lvalue_reference.C b/gcc/testsuite/g++.dg/ext/add_lvalue_reference.C new file mode 100644 index 00000000000..56afa5c342d --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/add_lvalue_reference.C @@ -0,0 +1,21 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +class ClassType { }; + +SA(__is_same(__builtin_add_lvalue_reference(int), int&)); +SA(__is_same(__builtin_add_lvalue_reference(int&), int&)); +SA(__is_same(__builtin_add_lvalue_reference(const int), const int&)); +SA(__is_same(__builtin_add_lvalue_reference(int*), int*&)); +SA(__is_same(__builtin_add_lvalue_reference(ClassType&), ClassType&)); +SA(__is_same(__builtin_add_lvalue_reference(ClassType), ClassType&)); +SA(__is_same(__builtin_add_lvalue_reference(int(int)), int(&)(int))); +SA(__is_same(__builtin_add_lvalue_reference(int&&), int&)); +SA(__is_same(__builtin_add_lvalue_reference(ClassType&&), ClassType&)); +SA(__is_same(__builtin_add_lvalue_reference(void), void)); +SA(__is_same(__builtin_add_lvalue_reference(const void), const void)); +SA(__is_same(__builtin_add_lvalue_reference(bool(int) const), bool(int) const)); +SA(__is_same(__builtin_add_lvalue_reference(bool(int) &), bool(int) &)); +SA(__is_same(__builtin_add_lvalue_reference(bool(int) const &&), bool(int) const &&)); +SA(__is_same(__builtin_add_lvalue_reference(bool(int)), bool(&)(int))); diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 7ca80daf6d1..77c65f9c920 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -5,6 +5,9 @@ #if !__has_builtin (__builtin_addressof) # error "__has_builtin (__builtin_addressof) failed" #endif +#if !__has_builtin (__builtin_add_lvalue_reference) +# error "__has_builtin (__builtin_add_lvalue_reference) failed" +#endif #if !__has_builtin (__builtin_add_pointer) # error "__has_builtin (__builtin_add_pointer) failed" #endif From patchwork Thu May 2 16:13:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1930724 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=Z6qZy4Wn; 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 4VVfcW3d55z1ydT for ; Fri, 3 May 2024 02:32:59 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A2B99384AB59 for ; Thu, 2 May 2024 16:32:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A2B99384AB59 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714667577; bh=N6DhEfp3iRKMgabh71KkPcvCuv4nkgdRhJvA8stBOdw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Z6qZy4WngcUoUPYnxdFtPoRxEoA6a7y7C/3XCvJEIAnJBlzhmUJIhInRG7+QLlpFO HDQJ2bTuDddX1wLC6XZNF0+qdnOBEGVj012njOBYJvivNqOfWBR96RmnaqPXi3wJ99 SjfVTr4Ps7jtn6M8SLgEPjkKTmbbtWKKi373Ea0g= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 83A69384AB59; Thu, 2 May 2024 16:16:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 83A69384AB59 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 83A69384AB59 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666608; cv=none; b=XVxUozwgjiwvMA0TH+efEIRpuyNelkDhiWT9+rj2aCFhfigOo5sslZVAKges5RLrtjiSiRuOVP/RGU9egss1kjjZrFcrV9PtSrJHFC5u+R1RRl1Ps84crSVH3/AKLXfmYg4o1biyBV8xH7WaaPzpIhm9LhxfV9jOKK4KM4esvzE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666608; c=relaxed/simple; bh=s9vn9khYrbE1t4cLJ5qRCOdsc3R89vZ4bbJZZTSVVw0=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=kGV/Hxd9BJ1f1wjbjrsckJFOCg621DOg6aEgZVxZnSvKdYgDqHp4wE52SMfjtfUpmLvl/G6Df1sOITFuG0pD34gjvUBvatgwVbDW0zvKnhX0Q9FB5E/tp6UWSecVKR+yUNloDKCrv6eHXdN+eYKBh0rrFEFAxlCFRgD9aP5yPh8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247476.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442GEUbS009945; Thu, 2 May 2024 16:16:38 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xv4e4kd9c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 16:16:37 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442GGGiW024919 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 09:16:16 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442GGFot023119 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 09:16:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v16 16/26] libstdc++: Optimize std::add_lvalue_reference compilation performance Date: Thu, 2 May 2024 09:13:42 -0700 Message-ID: <20240502161614.3705912-17-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502161614.3705912-1-kmatsui@gcc.gnu.org> References: <20240228192843.188979-1-kmatsui@gcc.gnu.org> <20240502161614.3705912-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: zCE8XFJ6nIZFU8CsYZbGRYkwlNR_ZN_d X-Proofpoint-GUID: zCE8XFJ6nIZFU8CsYZbGRYkwlNR_ZN_d X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_05,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 lowpriorityscore=0 suspectscore=0 bulkscore=0 phishscore=0 mlxscore=0 priorityscore=1501 clxscore=1034 impostorscore=0 mlxlogscore=752 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020106 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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_lvalue_reference by dispatching to the new __builtin_add_lvalue_reference trait. libstdc++-v3/ChangeLog: * include/std/type_traits (add_lvalue_reference): Use __builtin_add_lvalue_reference trait. (__add_lvalue_reference_helper): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 8f756712c63..4e97e45f130 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -1157,6 +1157,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; /// @cond undocumented +#if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_add_lvalue_reference) + template + struct __add_lvalue_reference_helper + { using type = __builtin_add_lvalue_reference(_Tp); }; +#else template struct __add_lvalue_reference_helper { using type = _Tp; }; @@ -1164,6 +1169,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct __add_lvalue_reference_helper<_Tp, __void_t<_Tp&>> { using type = _Tp&; }; +#endif template using __add_lval_ref_t = typename __add_lvalue_reference_helper<_Tp>::type; @@ -1731,9 +1737,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif /// add_lvalue_reference +#if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_add_lvalue_reference) + template + struct add_lvalue_reference + { using type = __builtin_add_lvalue_reference(_Tp); }; +#else template struct add_lvalue_reference { using type = __add_lval_ref_t<_Tp>; }; +#endif /// add_rvalue_reference template From patchwork Thu May 2 16:13:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1930720 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=c4O9OOEl; 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 4VVfXs5myfz1ydX for ; Fri, 3 May 2024 02:29:48 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7EEFA384AB5D for ; Thu, 2 May 2024 16:29:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7EEFA384AB5D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714667386; bh=hvQRfNjcNBoad6tdU/a4azkvyZ3o9Rt3Vm8IdagnfgQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=c4O9OOElrNCqjNWmX03VibsoiOPO5NCG+tZDn4EgT/fu1y6Pk+jE+P3+7TF2Mu8Eg +PY8wJAQVNynlx6jHr7PXTmlWAWjSRgwuk0oRQMeauAKGwL/BUxCEtriGfHUapg01w HEJe611zTXHf00niKBFPuIbELErjeujhmuVsI5Kc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 74734384AB65; Thu, 2 May 2024 16:16:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 74734384AB65 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 74734384AB65 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666609; cv=none; b=e9+4SIwGy0HQdmnRfJnedlGcOVi8aAgYcUQHR0ioOmPk1chITIUTf3KHijo19XOeM8p3NAogMpoGneg3vPCdZo0JNxj6uoXVzXCpEizCD2RhYU0YYEkBYyAg0oVVunXqhK+uwyqnlhtm7bNusNbzI+NyioFZ922HstD2iiwMD6M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666609; c=relaxed/simple; bh=rBbkLefTMxWrza9oDQXdAbRBnvIw7ce2q0/l0wik0Bg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=t1Za4C1kxyzvBwflsNVOlZp8//FXcgBbvW1QdKfGSf2s2NvTWguMAcC+ksdkf7Xv0aMJLuXbQmz/QJ7tz1LorUglWALRak+9DQ2rnfXcJxSMeaMR3ToITugQJDt9SYViOwWgbxhXIQP/bckbBtNyiZyiaS9pHvqX59y2S6U3khs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247480.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442GEW0G022508; Thu, 2 May 2024 16:16:38 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xv4e3behd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 16:16:37 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442GGGOe024920 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 09:16:16 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442GGFou023119 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 09:16:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v16 17/26] c++: Implement __builtin_add_rvalue_reference trait Date: Thu, 2 May 2024 09:13:43 -0700 Message-ID: <20240502161614.3705912-18-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502161614.3705912-1-kmatsui@gcc.gnu.org> References: <20240228192843.188979-1-kmatsui@gcc.gnu.org> <20240502161614.3705912-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: Gqe_n6pPIrb4AMorRgspce-HPhi6avr2 X-Proofpoint-GUID: Gqe_n6pPIrb4AMorRgspce-HPhi6avr2 X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_05,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 malwarescore=0 suspectscore=0 phishscore=0 impostorscore=0 spamscore=0 clxscore=1034 bulkscore=0 lowpriorityscore=0 mlxlogscore=666 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020106 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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_rvalue_reference. gcc/cp/ChangeLog: * cp-trait.def: Define __builtin_add_rvalue_reference. * semantics.cc (finish_trait_type): Handle CPTK_ADD_RVALUE_REFERENCE. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __builtin_add_rvalue_reference. * g++.dg/ext/add_rvalue_reference.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 6 ++++++ .../g++.dg/ext/add_rvalue_reference.C | 20 +++++++++++++++++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ 4 files changed, 30 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/add_rvalue_reference.C diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 228df46e3e4..c6fb2aa5f1e 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -50,6 +50,7 @@ DEFTRAIT_TYPE (ADD_LVALUE_REFERENCE, "__builtin_add_lvalue_reference", 1) DEFTRAIT_TYPE (ADD_POINTER, "__builtin_add_pointer", 1) +DEFTRAIT_TYPE (ADD_RVALUE_REFERENCE, "__builtin_add_rvalue_reference", 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 9f2220a1a91..fd6d9fc1dc5 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12936,6 +12936,12 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, } return type1; + case CPTK_ADD_RVALUE_REFERENCE: + /* [meta.trans.ref]. */ + if (referenceable_type_p (type1)) + return cp_build_reference_type (type1, /*rval=*/true); + return type1; + case CPTK_REMOVE_ALL_EXTENTS: return strip_array_types (type1); diff --git a/gcc/testsuite/g++.dg/ext/add_rvalue_reference.C b/gcc/testsuite/g++.dg/ext/add_rvalue_reference.C new file mode 100644 index 00000000000..3c09c5b05d6 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/add_rvalue_reference.C @@ -0,0 +1,20 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +class ClassType { }; + +SA(__is_same(__builtin_add_rvalue_reference(int), int&&)); +SA(__is_same(__builtin_add_rvalue_reference(int&&), int&&)); +SA(__is_same(__builtin_add_rvalue_reference(int&), int&)); +SA(__is_same(__builtin_add_rvalue_reference(const int), const int&&)); +SA(__is_same(__builtin_add_rvalue_reference(int*), int*&&)); +SA(__is_same(__builtin_add_rvalue_reference(ClassType&&), ClassType&&)); +SA(__is_same(__builtin_add_rvalue_reference(ClassType), ClassType&&)); +SA(__is_same(__builtin_add_rvalue_reference(int(int)), int(&&)(int))); +SA(__is_same(__builtin_add_rvalue_reference(void), void)); +SA(__is_same(__builtin_add_rvalue_reference(const void), const void)); +SA(__is_same(__builtin_add_rvalue_reference(bool(int) const), bool(int) const)); +SA(__is_same(__builtin_add_rvalue_reference(bool(int) &), bool(int) &)); +SA(__is_same(__builtin_add_rvalue_reference(bool(int) const &&), bool(int) const &&)); +SA(__is_same(__builtin_add_rvalue_reference(bool(int)), bool(&&)(int))); diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 77c65f9c920..fc66c816887 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -11,6 +11,9 @@ #if !__has_builtin (__builtin_add_pointer) # error "__has_builtin (__builtin_add_pointer) failed" #endif +#if !__has_builtin (__builtin_add_rvalue_reference) +# error "__has_builtin (__builtin_add_rvalue_reference) failed" +#endif #if !__has_builtin (__builtin_bit_cast) # error "__has_builtin (__builtin_bit_cast) failed" #endif From patchwork Thu May 2 16:13:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1930687 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=EZDPd/LJ; 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 4VVfGf0W3hz23hd for ; Fri, 3 May 2024 02:17:29 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 71DE33849AD9 for ; Thu, 2 May 2024 16:17:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 71DE33849AD9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714666647; bh=em7oBu9xglJgo/x23gaiKfVUJxud/OmqDqYlnCvKj/g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=EZDPd/LJW0SizfR67FLlHIEQOWHhpctHLkWlmetxYbgP9Frcvl8p2H/MvX0tjSSS2 Phd1YQGYhGtdNucNAM5wuZUPw7q4NgoaHf5WS5t/QhrjFs272exRO25bWLTT4J7y3b FxlT2LOlqeXbrP23LjtiGq6hko8jiRYQ5sKZFW1E= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id A8E1E3858C52; Thu, 2 May 2024 16:16:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A8E1E3858C52 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 A8E1E3858C52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666595; cv=none; b=C5HnLUjWYiaErXjBPwdwpOOuh7RSEmPFHO1JK8TVm+JV+n3MDe38mrsIIPiTWY0fNcyi9EI2cSMun5XdsSJNcBPB2L3NBfonhTyKYh1RdZ7SmP5N8swP4tIdpT7LqbWbTnJYaLyLc17qgT1clVQ7Nc5N/2N4vd0OQLYoXSU8t4g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666595; c=relaxed/simple; bh=2M8x3fS5GlYS1VALiyF93wfrOvcvWUcTOr+hq/C1qAo=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=AOsjmkrBSWSgVXMV2/SXiM8lj2PMKM+p+HJSQkjo56XOT5r0iRGKC9KN3aozlu6beOpE0BXVaQok7+5nPUjQZ9EZg/tp4Rfho5n5OKo1c0KgfcYKsmXA9bPvNM23aIomAatzDglHZtgg+RDLIATiTKNBBWkmK5dsrSRCYoHUu0Q= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247480.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442GCEs4018589; Thu, 2 May 2024 16:16:33 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xv4e3befs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 16:16:32 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442GGGHw003513 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 09:16:16 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442GGFov023119 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 09:16:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v16 18/26] libstdc++: Optimize std::add_rvalue_reference compilation performance Date: Thu, 2 May 2024 09:13:44 -0700 Message-ID: <20240502161614.3705912-19-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502161614.3705912-1-kmatsui@gcc.gnu.org> References: <20240228192843.188979-1-kmatsui@gcc.gnu.org> <20240502161614.3705912-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: fz7N4L8cJEyK3lV6_zbZDY-G8tnWvQEF X-Proofpoint-GUID: fz7N4L8cJEyK3lV6_zbZDY-G8tnWvQEF X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_05,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 malwarescore=0 suspectscore=0 phishscore=0 impostorscore=0 spamscore=0 clxscore=1034 bulkscore=0 lowpriorityscore=0 mlxlogscore=782 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020106 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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_rvalue_reference by dispatching to the new __builtin_add_rvalue_reference trait. libstdc++-v3/ChangeLog: * include/std/type_traits (add_rvalue_reference): Use __builtin_add_rvalue_reference trait. (__add_rvalue_reference_helper): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 4e97e45f130..36ac900605a 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -1185,6 +1185,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; /// @cond undocumented +#if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_add_rvalue_reference) + template + struct __add_rvalue_reference_helper + { using type = __builtin_add_rvalue_reference(_Tp); }; +#else template struct __add_rvalue_reference_helper { using type = _Tp; }; @@ -1192,6 +1197,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct __add_rvalue_reference_helper<_Tp, __void_t<_Tp&&>> { using type = _Tp&&; }; +#endif template using __add_rval_ref_t = typename __add_rvalue_reference_helper<_Tp>::type; @@ -1748,9 +1754,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif /// add_rvalue_reference +#if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_add_rvalue_reference) + template + struct add_rvalue_reference + { using type = __builtin_add_rvalue_reference(_Tp); }; +#else template struct add_rvalue_reference { using type = __add_rval_ref_t<_Tp>; }; +#endif #if __cplusplus > 201103L /// Alias template for remove_reference From patchwork Thu May 2 16:13:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1930725 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=XESoywIb; 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 4VVffX0LCRz1ydT for ; Fri, 3 May 2024 02:34:44 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2AF9E3858289 for ; Thu, 2 May 2024 16:34:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2AF9E3858289 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714667682; bh=+prTGpv10Op6wofX8769Ae1r68C0yM1mL2hhjHx+HPw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=XESoywIbwCXfKNVKHHcFdUrrNtCfUs1Jioj6HJYiT15+WWJi/Z5R0Zd1azczqyMZm VKEyXh7gmLVpVX2qYZVAHxHDk9m6/QuMNknm3aMKEhBdV69Nr5p3N3xxGasg90hqzz 6X08RmXNaGwcccQV7GABv9troIjaG9Uq8DJ6e2mc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 745EA384AB61; Thu, 2 May 2024 16:16:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 745EA384AB61 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 745EA384AB61 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666609; cv=none; b=CM5Pp2BMXkbXC1Mxnq+cJx0z6busN6QYB2M067+GiCpYWTL4UXuGDGmA7SxfC5zFX5By+0nfrWm3asxpe4xtOp5GpJfHOnI/Kb3vpiAQhVrIvcG1VS+yye1dywv3fmBFVoNT5A+mC0u37tALek11EzO20zVqJJtqojAgOJP1StU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666609; c=relaxed/simple; bh=sZ33hKJCsyudCeZEtB7vlseh1/yc9Zs1DS+F7sf/eyE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=C0NVIzilmfOEPm0EoAhe3bpKZYxvzntwSMzTcftyskJrvhH1eYLUqfojNHfy5htsOvifvfZe1a6OhsqQI4jOnH82sTt7NSbAnGBw1JXEzazvGqbbCjW4/f3JzUoPc0wWx/gaVMk4e0h5EKc2QTyhs+41gnVqnXtEXcKVIK5zDAo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442FuCLc008851; Thu, 2 May 2024 16:16:38 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xv4e2uemu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 16:16:37 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442GGGkb024921 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 09:16:16 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442GGFow023119 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 09:16:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v16 19/26] c++: Implement __builtin_decay trait Date: Thu, 2 May 2024 09:13:45 -0700 Message-ID: <20240502161614.3705912-20-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502161614.3705912-1-kmatsui@gcc.gnu.org> References: <20240228192843.188979-1-kmatsui@gcc.gnu.org> <20240502161614.3705912-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: _UYPFpCjZxWFBDyhVbdGXgPAJwS2kCA7 X-Proofpoint-ORIG-GUID: _UYPFpCjZxWFBDyhVbdGXgPAJwS2kCA7 X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_05,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 priorityscore=1501 bulkscore=0 suspectscore=0 clxscore=1034 mlxlogscore=623 spamscore=0 mlxscore=0 phishscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020106 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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::decay. gcc/cp/ChangeLog: * cp-trait.def: Define __builtin_decay. * semantics.cc (finish_trait_type): Handle CPTK_DECAY. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __builtin_decay. * g++.dg/ext/decay.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 12 ++++++++++++ gcc/testsuite/g++.dg/ext/decay.C | 22 ++++++++++++++++++++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ 4 files changed, 38 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/decay.C diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index c6fb2aa5f1e..90cd5ff99cc 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -51,6 +51,7 @@ DEFTRAIT_TYPE (ADD_LVALUE_REFERENCE, "__builtin_add_lvalue_reference", 1) DEFTRAIT_TYPE (ADD_POINTER, "__builtin_add_pointer", 1) DEFTRAIT_TYPE (ADD_RVALUE_REFERENCE, "__builtin_add_rvalue_reference", 1) +DEFTRAIT_TYPE (DECAY, "__builtin_decay", 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 fd6d9fc1dc5..c498191a3c8 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12942,6 +12942,18 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, return cp_build_reference_type (type1, /*rval=*/true); return type1; + case CPTK_DECAY: + if (TYPE_REF_P (type1)) + type1 = TREE_TYPE (type1); + + if (TREE_CODE (type1) == ARRAY_TYPE) + return finish_trait_type (CPTK_ADD_POINTER, TREE_TYPE (type1), type2, + complain); + else if (TREE_CODE (type1) == FUNCTION_TYPE) + return finish_trait_type (CPTK_ADD_POINTER, type1, type2, complain); + else + return cv_unqualified (type1); + case CPTK_REMOVE_ALL_EXTENTS: return strip_array_types (type1); diff --git a/gcc/testsuite/g++.dg/ext/decay.C b/gcc/testsuite/g++.dg/ext/decay.C new file mode 100644 index 00000000000..f8b161a97c7 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/decay.C @@ -0,0 +1,22 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +// Positive tests. +using test1_type = __builtin_decay(bool); +SA(__is_same(test1_type, bool)); + +// NB: DR 705. +using test2_type = __builtin_decay(const int); +SA(__is_same(test2_type, int)); + +using test3_type = __builtin_decay(int[4]); +SA(__is_same(test3_type, __builtin_remove_extent(int[4])*)); + +using fn_type = void (); +using test4_type = __builtin_decay(fn_type); +SA(__is_same(test4_type, __builtin_add_pointer(fn_type))); + +using cfn_type = void () const; +using test5_type = __builtin_decay(cfn_type); +SA(__is_same(test5_type, cfn_type)); diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index fc66c816887..0ea96d0ea87 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -17,6 +17,9 @@ #if !__has_builtin (__builtin_bit_cast) # error "__has_builtin (__builtin_bit_cast) failed" #endif +#if !__has_builtin (__builtin_decay) +# error "__has_builtin (__builtin_decay) failed" +#endif #if !__has_builtin (__builtin_is_const) # error "__has_builtin (__builtin_is_const) failed" #endif From patchwork Thu May 2 16:13:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1930703 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=VnivsmFP; 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 4VVfRH4cQpz20fb for ; Fri, 3 May 2024 02:24:59 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8B0A33849AE3 for ; Thu, 2 May 2024 16:24:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8B0A33849AE3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714667097; bh=kPxXqDzWH/yEDPi1ip0MlGpZG4AxoEwlUsYmHWyJUvU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=VnivsmFP/Np9+Aca7aVsDtFh54QleG7SbFA4NotCZsJ6kY8El3BYUAwRrzQmRlnri /YDZts8OL1Rg0yoj1lLqegMTAalQIb0A1T4LojL2xzAettoBtM7ppHFSSEpFffg6xk pJMtALOQfZMNPSbkbVIbyaAhHwjNVuE9xgWYAUEg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id B3785384AB53; Thu, 2 May 2024 16:16:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B3785384AB53 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 B3785384AB53 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666614; cv=none; b=VG2NrLSY+13gVHpo161wAN7qWnoXhDPzkGRToonxGWb0iJ0dZwdCmiokmNSRoWtkMbFcYNJhNNYEvluvClNznZ8D18gxNEcZeswvgM0SbeBX5zuo3fOz8WLBLCq3fPLApjuoweF6s89LvzVYIGOIEJvw2aCDZQYz20KmkMx5YPM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666614; c=relaxed/simple; bh=gUrOpT3YVqZYD74/Vg9/FJq0FVqylh/usuP5hlYDAkA=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=XRDfQyoxyHWjtqIlwzJ38OAcSCTRUo5FGZWc2ERcombutvLV5D97mRSh/SQJNFS9UsHfUlRpA+iIDHXnOrm0+t5/bS917pBHa8ujtqlp/RUPD/6qcfl33rZ8WPGr7MsI5qfVD+h7ro4+M5b3wfOVkzKVXI1BRZ0zk8FU74vGEf0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442GG7WB026272; Thu, 2 May 2024 16:16:38 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xv4e2uemv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 16:16:37 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442GGGih024922 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 09:16:16 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442GGFox023119 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 09:16:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v16 20/26] libstdc++: Optimize std::decay compilation performance Date: Thu, 2 May 2024 09:13:46 -0700 Message-ID: <20240502161614.3705912-21-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502161614.3705912-1-kmatsui@gcc.gnu.org> References: <20240228192843.188979-1-kmatsui@gcc.gnu.org> <20240502161614.3705912-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: 1UHZZrahqujaahRdO7F9dRO2hq0IMaVp X-Proofpoint-ORIG-GUID: 1UHZZrahqujaahRdO7F9dRO2hq0IMaVp X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_05,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 priorityscore=1501 bulkscore=0 suspectscore=0 clxscore=1034 mlxlogscore=799 spamscore=0 mlxscore=0 phishscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020106 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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::decay by dispatching to the new __builtin_decay trait. libstdc++-v3/ChangeLog: * include/std/type_traits (decay): Use __builtin_decay trait. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 36ac900605a..45c73d477d0 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -2316,6 +2316,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// @cond undocumented +#if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_decay) + template + struct decay + { using type = __builtin_decay(_Tp); }; +#else // Decay trait for arrays and functions, used for perfect forwarding // in make_pair, make_tuple, etc. template @@ -2347,6 +2352,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct decay<_Tp&&> { using type = typename __decay_selector<_Tp>::type; }; +#endif /// @cond undocumented From patchwork Thu May 2 16:13: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: 1930693 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=nUXpdgGk; 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 4VVfK266XKz1ydT for ; Fri, 3 May 2024 02:19:34 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 22EE23849AF0 for ; Thu, 2 May 2024 16:19:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 22EE23849AF0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714666773; bh=0wkDfVbCctUNha224025NZbx/9EVe71VWfMAkVr3R3M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=nUXpdgGkS+DQzsChEwZTk78JQoD+dyNmeWfb0FZo/qnugXwvH4Zfb9dzjVxBJNb8Y NlK4x5zcvxzCz7yuX2XpvoSsX8KhEQhpdEKch1P3CpM5cDd8cyM1sWjMzForIKn7Kz sVMDlmWvrr2IqwXjURa+cq5uVNGSy3eBHuAplC5Y= 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 D5436385841C; Thu, 2 May 2024 16:16:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D5436385841C 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 D5436385841C 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=1714666601; cv=none; b=VsGJ7QVvFqn4N+i3kglnx8mzA3Feea4qw2Jbqpj71NRAtgKMjbpHW1XMSxa2DnSK7C6ejns/LOTDz2TvPDo0db9upn4sYtxrwGkSkjQ3gw5IhQHFZGB3OWJrmaafhwbLAe09gzFbGPrktd52fAND4lED2pjm9QldHGI5BhGU8K4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666601; c=relaxed/simple; bh=L9Bv7cQLtCZOuG0mETa9mxpnEBELUNJKTC+wjt+jcFI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=w7yD3wEQGhOGrpZ7Oy+DRXWjWOyulUvve7UYTnSmJLf50xg91iNB0TdJ5mDd9nQShuERQZAkc1BFQ+FJoukGcTy1iciLloxDbzpGUvNyPOSGT10IIgtz0P8AjqJxj6GLz45Qw9oDwE4959RxhFkGFkznUSbVdiKTCKqM9t1VTyI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247471.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442Fxgre018571; Thu, 2 May 2024 16:16:33 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xv4e43n3m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 16:16:32 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442GGGg9003514 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 09:16:16 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442GGFp0023119 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 09:16:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v16 21/26] c++: Implement __builtin_rank trait Date: Thu, 2 May 2024 09:13:47 -0700 Message-ID: <20240502161614.3705912-22-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502161614.3705912-1-kmatsui@gcc.gnu.org> References: <20240228192843.188979-1-kmatsui@gcc.gnu.org> <20240502161614.3705912-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: E9VT1I0ZpAr-oEEW9r-xsycUlaqb6cOP X-Proofpoint-GUID: E9VT1I0ZpAr-oEEW9r-xsycUlaqb6cOP X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_05,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 lowpriorityscore=0 spamscore=0 malwarescore=0 impostorscore=0 phishscore=0 priorityscore=1501 mlxscore=0 suspectscore=0 adultscore=0 bulkscore=0 mlxlogscore=965 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020106 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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::rank. gcc/cp/ChangeLog: * cp-trait.def: Define __builtin_rank. * constraint.cc (diagnose_trait_expr): Handle CPTK_RANK. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __builtin_rank. * g++.dg/ext/rank.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 +++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 24 +++++++++++++++++++++--- gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ gcc/testsuite/g++.dg/ext/rank.C | 24 ++++++++++++++++++++++++ 5 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/rank.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index d4cc8850486..c28d7bf428e 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3871,6 +3871,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_VOLATILE: inform (loc, " %qT is not a volatile type", t1); break; + case CPTK_RANK: + inform (loc, " %qT cannot yield a rank", t1); + break; case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: inform (loc, " %qT is not a reference that binds to a temporary " "object of type %qT (direct-initialization)", t1, t2); diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 90cd5ff99cc..bf21ea4f4c6 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -99,6 +99,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) DEFTRAIT_EXPR (IS_UNBOUNDED_ARRAY, "__builtin_is_unbounded_array", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) DEFTRAIT_EXPR (IS_VOLATILE, "__builtin_is_volatile", 1) +DEFTRAIT_EXPR (RANK, "__builtin_rank", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) DEFTRAIT_TYPE (REMOVE_ALL_EXTENTS, "__builtin_remove_all_extents", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index c498191a3c8..9be3eb1e204 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12642,6 +12642,10 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_DEDUCIBLE: return type_targs_deducible_from (type1, type2); + /* __builtin_rank is handled in finish_trait_expr. */ + case CPTK_RANK: + gcc_unreachable (); + #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \ case CPTK_##CODE: #include "cp-trait.def" @@ -12765,7 +12769,10 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) if (processing_template_decl) { tree trait_expr = make_node (TRAIT_EXPR); - TREE_TYPE (trait_expr) = boolean_type_node; + if (kind == CPTK_RANK) + TREE_TYPE (trait_expr) = size_type_node; + else + TREE_TYPE (trait_expr) = boolean_type_node; TRAIT_EXPR_TYPE1 (trait_expr) = type1; TRAIT_EXPR_TYPE2 (trait_expr) = type2; TRAIT_EXPR_KIND (trait_expr) = kind; @@ -12858,6 +12865,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_UNBOUNDED_ARRAY: case CPTK_IS_UNION: case CPTK_IS_VOLATILE: + case CPTK_RANK: break; case CPTK_IS_LAYOUT_COMPATIBLE: @@ -12889,8 +12897,18 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) gcc_unreachable (); } - tree val = (trait_expr_value (kind, type1, type2) - ? boolean_true_node : boolean_false_node); + tree val; + if (kind == CPTK_RANK) + { + size_t rank = 0; + for (; TREE_CODE (type1) == ARRAY_TYPE; type1 = TREE_TYPE (type1)) + ++rank; + val = build_int_cst (size_type_node, rank); + } + else + val = (trait_expr_value (kind, type1, type2) + ? boolean_true_node : boolean_false_node); + return maybe_wrap_with_location (val, loc); } diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 0ea96d0ea87..fdd4c143978 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -44,6 +44,9 @@ #if !__has_builtin (__builtin_launder) # error "__has_builtin (__builtin_launder) failed" #endif +#if !__has_builtin (__builtin_rank) +# error "__has_builtin (__builtin_rank) failed" +#endif #if !__has_builtin (__builtin_remove_all_extents) # error "__has_builtin (__builtin_remove_all_extents) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/rank.C b/gcc/testsuite/g++.dg/ext/rank.C new file mode 100644 index 00000000000..7d095349a8b --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/rank.C @@ -0,0 +1,24 @@ +// { dg-do compile { target c++11 } } + +#include + +#define SA(X) static_assert((X),#X) + +class ClassType { }; + +SA(__builtin_rank(int) == 0); +SA(__builtin_rank(int[2]) == 1); +SA(__builtin_rank(int[][4]) == 2); +SA(__builtin_rank(int[2][2][4][4][6][6]) == 6); +SA(__builtin_rank(ClassType) == 0); +SA(__builtin_rank(ClassType[2]) == 1); +SA(__builtin_rank(ClassType[][4]) == 2); +SA(__builtin_rank(ClassType[2][2][4][4][6][6]) == 6); + +template void f(T) = delete; +void f(size_t); + +template +void g() { f(__builtin_rank(T)); } + +template void g(); From patchwork Thu May 2 16:13: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: 1930691 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=ujPxzsJ0; 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 4VVfJN6pnsz1ydT for ; Fri, 3 May 2024 02:19:00 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 179043849ADD for ; Thu, 2 May 2024 16:18:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 179043849ADD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714666739; bh=gedVZkjEWAtfhBJEZirlGSz4UHujsTfnLXG1KR9UjJU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ujPxzsJ0GydL4mPO+TN0T5Vvs1wzrE7TatUOuV/aXCjsDPrqqPy+mtuatdKyK7IO1 zeuOJAFDJdQ7d5cWcoLc3+4XaD6cjd3cKDiUmVe2j7uUNQVldPR7kVB1yOwcAO0AYx 3doTb8t5o0PDScutbaDqLtX1lFgrvRgzqYNdJMdI= 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 AEE333858408; Thu, 2 May 2024 16:16:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AEE333858408 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 AEE333858408 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=1714666596; cv=none; b=xGs7eq6Nsm8GnIUL30Q7/MiNbuT6CW1r+st05S7K4qCoIOL5mCgMvXZc1PKgafpP/gQyD8rgcueR2EqfmE/gw3hcxjddU2JJiP/pRNGKUf/tEwlMcCfYYOGh9wVxY6JVx6JwATzfkWlVVxYK7ndotk7En7LQx6lPlpdidwFtBsc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666596; c=relaxed/simple; bh=GGh+gJW2JDbLyns9p4n8Bi7KkVtV6Sp8hFM31gTQtfo=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=sBUOnfG/vwhRV6X9aZUjBXaimCAMRyPYIIHOKmijAGE2vXBlDSoIw50xKik7xTEz6hlpTSbslF3N4l1arfwuOxOgP3heYNaCIerjL4ldl3tNMsCydAtbjuGH1Nywrh6/F9yQcxhoaFaLRY2oVl/dl5i358wGpNZTfHiLFgVyfog= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247472.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442GFbQl008287; Thu, 2 May 2024 16:16:32 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xv4e2upu6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 16:16:32 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442GGGOG003515 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 09:16:16 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442GGFp1023119 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 09:16:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v16 22/26] libstdc++: Optimize std::rank compilation performance Date: Thu, 2 May 2024 09:13:48 -0700 Message-ID: <20240502161614.3705912-23-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502161614.3705912-1-kmatsui@gcc.gnu.org> References: <20240228192843.188979-1-kmatsui@gcc.gnu.org> <20240502161614.3705912-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: U2kIXe1oQ51z8am5CJ6NLIHhm1cUWPVU X-Proofpoint-ORIG-GUID: U2kIXe1oQ51z8am5CJ6NLIHhm1cUWPVU X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_08,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 spamscore=0 mlxscore=0 phishscore=0 priorityscore=1501 mlxlogscore=836 adultscore=0 clxscore=1034 suspectscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020106 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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::rank by dispatching to the new __builtin_rank trait. libstdc++-v3/ChangeLog: * include/std/type_traits (rank): Use __builtin_rank trait. (rank_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 45c73d477d0..15933a0730e 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -1473,6 +1473,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; /// rank +#if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_rank) + template + struct rank + : public integral_constant { }; +#else template struct rank : public integral_constant { }; @@ -1484,6 +1489,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct rank<_Tp[]> : public integral_constant::value> { }; +#endif /// extent template @@ -3583,12 +3589,17 @@ template template inline constexpr size_t alignment_of_v = alignment_of<_Tp>::value; +#if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_rank) +template + inline constexpr size_t rank_v = __builtin_rank(_Tp); +#else template inline constexpr size_t rank_v = 0; template inline constexpr size_t rank_v<_Tp[_Size]> = 1 + rank_v<_Tp>; template inline constexpr size_t rank_v<_Tp[]> = 1 + rank_v<_Tp>; +#endif template inline constexpr size_t extent_v = 0; From patchwork Thu May 2 16:13:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1930700 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=f6AVXNz6; 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 4VVfPJ3FMCz20fb for ; Fri, 3 May 2024 02:23:16 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 98DB03849AFD for ; Thu, 2 May 2024 16:23:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 98DB03849AFD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714666994; bh=jKe+TZU6z04VM4XTBEjRA2qgd3CJVaQVlnK9/JN/+RQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=f6AVXNz6r2/2BPKU8/0X1K5/1WOQlfjURPe3Pe4dfD0ySNz8wfF4iRrc237lk17Jw RHZI6xh7F1dzPp6ALDhAkr0FFkXf8or3TGr2XSL6ZDkL/zGCrgMdjBfOHkE7oWbkxv XXMKmJnHM/bz7PChCaaziSHExNT8mDJ0Qmuav84U= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 8EDDD384AB6B; Thu, 2 May 2024 16:16:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8EDDD384AB6B 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 8EDDD384AB6B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666614; cv=none; b=dG7flpwZz4gQ/l3fkApMr501cB+SJ29owgjPgs6J+77ncA0YhH7SmXY9HwL+QvHCuOAGY+EwM2opxefhLY/DZnkd6jDPC/XIpU/4tMOr6spWMTSA5M/CyhZDrNmNOEcjvOKuql+4ypvCMp4ZRXWDdXogNztp1VDkGRTuoxa+Gn0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666614; c=relaxed/simple; bh=+mjYVnAyVuSIwDPkwLUJCVHtbUZSrvpeTPw+p/G5dZA=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=cgrbuiZC3adHISV9DLWA3oF99ayF6cbmpHrO0vqi98qlH/+nIgnF2tXyY2P2eY4uLlTw2OIxn5ikRxl5hOQkzS/OvsuzRmxcNjxkds7Cnf7xbDbkcv6LY+/UPHSsbrRalB4TLYIN7GI6c/fGygt0JlMxQuG1ixEAycAMKVVjSjg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247477.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442GEQhU002521; Thu, 2 May 2024 16:16:38 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xv4e5kd4k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 16:16:37 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442GGG4h024923 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 09:16:16 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442GGFp2023119 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 09:16:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v16 23/26] c++: Implement __builtin_is_invocable trait Date: Thu, 2 May 2024 09:13:49 -0700 Message-ID: <20240502161614.3705912-24-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502161614.3705912-1-kmatsui@gcc.gnu.org> References: <20240228192843.188979-1-kmatsui@gcc.gnu.org> <20240502161614.3705912-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: UXoq--XAAaEf11GVTihwFSmkx3cMvjFq X-Proofpoint-ORIG-GUID: UXoq--XAAaEf11GVTihwFSmkx3cMvjFq X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_05,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 spamscore=0 priorityscore=1501 suspectscore=0 phishscore=0 adultscore=0 impostorscore=0 bulkscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1034 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020106 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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::is_invocable. gcc/cp/ChangeLog: * cp-trait.def: Define __builtin_is_invocable. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_INVOCABLE. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. * cp-tree.h (build_invoke): New function. * method.cc (build_invoke): New function. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __builtin_is_invocable. * g++.dg/ext/is_invocable1.C: New test. * g++.dg/ext/is_invocable2.C: New test. * g++.dg/ext/is_invocable3.C: New test. * g++.dg/ext/is_invocable4.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 6 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-tree.h | 2 + gcc/cp/method.cc | 134 +++++++++ gcc/cp/semantics.cc | 5 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_invocable1.C | 349 +++++++++++++++++++++++ gcc/testsuite/g++.dg/ext/is_invocable2.C | 139 +++++++++ gcc/testsuite/g++.dg/ext/is_invocable3.C | 51 ++++ gcc/testsuite/g++.dg/ext/is_invocable4.C | 33 +++ 10 files changed, 723 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_invocable1.C create mode 100644 gcc/testsuite/g++.dg/ext/is_invocable2.C create mode 100644 gcc/testsuite/g++.dg/ext/is_invocable3.C create mode 100644 gcc/testsuite/g++.dg/ext/is_invocable4.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index c28d7bf428e..6d14ef7dcc7 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3792,6 +3792,12 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_FUNCTION: inform (loc, " %qT is not a function", t1); break; + case CPTK_IS_INVOCABLE: + if (!t2) + inform (loc, " %qT is not invocable", t1); + else + inform (loc, " %qT is not invocable by %qE", t1, t2); + break; case CPTK_IS_LAYOUT_COMPATIBLE: inform (loc, " %qT is not layout compatible with %qT", t1, t2); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index bf21ea4f4c6..5ae256c56ab 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -75,6 +75,7 @@ DEFTRAIT_EXPR (IS_EMPTY, "__is_empty", 1) DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) DEFTRAIT_EXPR (IS_FUNCTION, "__is_function", 1) +DEFTRAIT_EXPR (IS_INVOCABLE, "__builtin_is_invocable", -1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) DEFTRAIT_EXPR (IS_MEMBER_FUNCTION_POINTER, "__is_member_function_pointer", 1) diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 1938ada0268..83dc20e1130 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -7338,6 +7338,8 @@ extern tree get_copy_assign (tree); extern tree get_default_ctor (tree); extern tree get_dtor (tree, tsubst_flags_t); extern tree build_stub_object (tree); +extern tree build_invoke (tree, const_tree, + tsubst_flags_t); extern tree strip_inheriting_ctors (tree); extern tree inherited_ctor_binfo (tree); extern bool base_ctor_omit_inherited_parms (tree); diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc index 08a3d34fb01..faf932258e6 100644 --- a/gcc/cp/method.cc +++ b/gcc/cp/method.cc @@ -1928,6 +1928,140 @@ build_trait_object (tree type) return build_stub_object (type); } +/* [func.require] Build an expression of INVOKE(FN_TYPE, ARG_TYPES...). If the + given is not invocable, returns error_mark_node. */ + +tree +build_invoke (tree fn_type, const_tree arg_types, tsubst_flags_t complain) +{ + if (error_operand_p (fn_type) || error_operand_p (arg_types)) + return error_mark_node; + + gcc_assert (TYPE_P (fn_type)); + gcc_assert (TREE_CODE (arg_types) == TREE_VEC); + + /* Access check is required to determine if the given is invocable. */ + deferring_access_check_sentinel acs (dk_no_deferred); + + /* INVOKE is an unevaluated context. */ + cp_unevaluated cp_uneval_guard; + + bool is_ptrdatamem; + bool is_ptrmemfunc; + if (TREE_CODE (fn_type) == REFERENCE_TYPE) + { + tree deref_fn_type = TREE_TYPE (fn_type); + is_ptrdatamem = TYPE_PTRDATAMEM_P (deref_fn_type); + is_ptrmemfunc = TYPE_PTRMEMFUNC_P (deref_fn_type); + + /* Dereference fn_type if it is a pointer to member. */ + if (is_ptrdatamem || is_ptrmemfunc) + fn_type = deref_fn_type; + } + else + { + is_ptrdatamem = TYPE_PTRDATAMEM_P (fn_type); + is_ptrmemfunc = TYPE_PTRMEMFUNC_P (fn_type); + } + + if (is_ptrdatamem && TREE_VEC_LENGTH (arg_types) != 1) + { + if (complain & tf_error) + error ("pointer to data member type %qT can only be invoked with " + "one argument", fn_type); + return error_mark_node; + } + + if (is_ptrmemfunc && TREE_VEC_LENGTH (arg_types) == 0) + { + if (complain & tf_error) + error ("pointer to member function type %qT must be invoked with " + "at least one argument", fn_type); + return error_mark_node; + } + + /* Construct an expression of a pointer to member. */ + tree ptrmem_expr; + if (is_ptrdatamem || is_ptrmemfunc) + { + tree datum_type = TREE_VEC_ELT (arg_types, 0); + + /* datum must be a class type or a reference/pointer to a class type. */ + if (!(CLASS_TYPE_P (datum_type) + || ((TYPE_REF_P (datum_type) || POINTER_TYPE_P (datum_type)) + && CLASS_TYPE_P (TREE_TYPE (datum_type))))) + { + if (complain & tf_error) + error ("first argument type %qT of a pointer to member must be" + "a class type or a reference/pointer to a class type", + datum_type); + return error_mark_node; + } + + bool is_refwrap = false; + if (CLASS_TYPE_P (datum_type)) + { + /* 1.2 & 1.5: Handle std::reference_wrapper. */ + tree datum_decl = TYPE_NAME (TYPE_MAIN_VARIANT (datum_type)); + if (decl_in_std_namespace_p (datum_decl)) + { + const_tree name = DECL_NAME (datum_decl); + if (name && (id_equal (name, "reference_wrapper"))) + { + /* Retrieve T from std::reference_wrapper, + i.e., decltype(datum.get()). */ + datum_type = TREE_VEC_ELT (TYPE_TI_ARGS (datum_type), 0); + is_refwrap = true; + } + } + } + + tree ptrmem_class_type = TYPE_PTRMEM_CLASS_TYPE (fn_type); + const bool ptrmem_is_base_of_datum = + (NON_UNION_CLASS_TYPE_P (ptrmem_class_type) + && NON_UNION_CLASS_TYPE_P (datum_type) + && (same_type_ignoring_top_level_qualifiers_p (ptrmem_class_type, + datum_type) + || DERIVED_FROM_P (ptrmem_class_type, datum_type))); + + tree datum_expr = build_trait_object (datum_type); + if (!ptrmem_is_base_of_datum && !is_refwrap && !TYPE_REF_P (datum_type)) + /* 1.3 & 1.6: Try to dereference datum_expr. */ + datum_expr = build_x_indirect_ref (UNKNOWN_LOCATION, datum_expr, + RO_UNARY_STAR, NULL_TREE, complain); + /* 1.1, 1.2, 1.4, & 1.5: Otherwise. */ + + tree fn_expr = build_trait_object (fn_type); + ptrmem_expr = build_m_component_ref (datum_expr, fn_expr, complain); + + if (error_operand_p (ptrmem_expr)) + return error_mark_node; + + if (is_ptrdatamem) + return ptrmem_expr; + } + + /* Construct expressions for arguments to INVOKE. For a pointer to member + function, the first argument, which is the object, is not arguments to + the function. */ + releasing_vec args; + for (int i = is_ptrmemfunc ? 1 : 0; i < TREE_VEC_LENGTH (arg_types); ++i) + { + tree arg_type = TREE_VEC_ELT (arg_types, i); + tree arg = build_trait_object (arg_type); + vec_safe_push (args, arg); + } + + tree invoke_expr; + if (is_ptrmemfunc) + invoke_expr = build_offset_ref_call_from_tree (ptrmem_expr, &args, + complain); + else /* 1.7. */ + invoke_expr = finish_call_expr (build_trait_object (fn_type), &args, false, + false, complain); + return invoke_expr; +} + /* Determine which function will be called when looking up NAME in TYPE, called with a single ARGTYPE argument, or no argument if ARGTYPE is null. FLAGS and COMPLAIN are as for build_new_method_call. diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 9be3eb1e204..4a13a36a81e 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12561,6 +12561,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_FUNCTION: return type_code1 == FUNCTION_TYPE; + case CPTK_IS_INVOCABLE: + return !error_operand_p (build_invoke (type1, type2, tf_none)); + case CPTK_IS_LAYOUT_COMPATIBLE: return layout_compatible_type_p (type1, type2); @@ -12719,6 +12722,7 @@ same_type_ref_bind_p (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CONSTRUCTIBLE: case CPTK_IS_NOTHROW_CONSTRUCTIBLE: case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: + case CPTK_IS_INVOCABLE: case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: case CPTK_REF_CONVERTS_FROM_TEMPORARY: to = type1; @@ -12821,6 +12825,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CONSTRUCTIBLE: case CPTK_IS_CONVERTIBLE: + case CPTK_IS_INVOCABLE: case CPTK_IS_NOTHROW_CONSTRUCTIBLE: case CPTK_IS_NOTHROW_CONVERTIBLE: case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index fdd4c143978..f4ac659e9b8 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -29,6 +29,9 @@ #if !__has_builtin (__builtin_is_corresponding_member) # error "__has_builtin (__builtin_is_corresponding_member) failed" #endif +#if !__has_builtin (__builtin_is_invocable) +# error "__has_builtin (__builtin_is_invocable) failed" +#endif #if !__has_builtin (__builtin_is_pointer) # error "__has_builtin (__builtin_is_pointer) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_invocable1.C b/gcc/testsuite/g++.dg/ext/is_invocable1.C new file mode 100644 index 00000000000..7f12d5fe8d2 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_invocable1.C @@ -0,0 +1,349 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +using func_type_v0 = void(*)(); + +SA( __builtin_is_invocable( func_type_v0 ) ); +SA( ! __builtin_is_invocable( func_type_v0, int ) ); + +using func_type_i0 = int(*)(); + +SA( __builtin_is_invocable( func_type_i0 ) ); +SA( ! __builtin_is_invocable( func_type_i0, int ) ); + +using func_type_l0 = int&(*)(); + +SA( __builtin_is_invocable( func_type_l0 ) ); +SA( ! __builtin_is_invocable( func_type_l0(int) ) ); + +using func_type_ii = int(*)(int); + +SA( ! __builtin_is_invocable( func_type_ii ) ); +SA( __builtin_is_invocable( func_type_ii, int ) ); + +using func_type_il = int(*)(int&); + +SA( ! __builtin_is_invocable( func_type_il ) ); +SA( ! __builtin_is_invocable( func_type_il, int ) ); +SA( __builtin_is_invocable( func_type_il, int& ) ); + +using func_type_ir = int(*)(int&&); + +SA( ! __builtin_is_invocable( func_type_ir ) ); +SA( ! __builtin_is_invocable( func_type_ir, int& ) ); +SA( __builtin_is_invocable( func_type_ir, int ) ); +SA( __builtin_is_invocable( func_type_ir, int&& ) ); + +struct A { }; + +using mem_type_i = int A::*; + +SA( ! __builtin_is_invocable( mem_type_i ) ); +SA( ! __builtin_is_invocable( mem_type_i, int ) ); +SA( ! __builtin_is_invocable( mem_type_i, int* ) ); +SA( ! __builtin_is_invocable( mem_type_i, int& ) ); +SA( ! __builtin_is_invocable( mem_type_i, int&& ) ); +SA( __builtin_is_invocable( mem_type_i, A ) ); +SA( __builtin_is_invocable( mem_type_i, A* ) ); +SA( __builtin_is_invocable( mem_type_i, A& ) ); +SA( __builtin_is_invocable( mem_type_i, A&& ) ); +SA( __builtin_is_invocable( mem_type_i, const A& ) ); +SA( ! __builtin_is_invocable( mem_type_i, A&, int ) ); + +using memfun_type_i = int (A::*)(); + +SA( ! __builtin_is_invocable( memfun_type_i ) ); +SA( ! __builtin_is_invocable( memfun_type_i, int ) ); +SA( ! __builtin_is_invocable( memfun_type_i, int* ) ); +SA( ! __builtin_is_invocable( memfun_type_i, int& ) ); +SA( ! __builtin_is_invocable( memfun_type_i, int&& ) ); +SA( __builtin_is_invocable( memfun_type_i, A ) ); +SA( __builtin_is_invocable( memfun_type_i, A* ) ); +SA( __builtin_is_invocable( memfun_type_i, A& ) ); +SA( __builtin_is_invocable( memfun_type_i, A&& ) ); +SA( ! __builtin_is_invocable( memfun_type_i, const A& ) ); +SA( ! __builtin_is_invocable( memfun_type_i, A&, int ) ); + +using memfun_type_ic = int (A::*)() const; + +SA( ! __builtin_is_invocable( memfun_type_ic ) ); +SA( ! __builtin_is_invocable( memfun_type_ic, int ) ); +SA( ! __builtin_is_invocable( memfun_type_ic, int& ) ); +SA( __builtin_is_invocable( memfun_type_ic, A& ) ); +SA( __builtin_is_invocable( memfun_type_ic, A* ) ); +SA( ! __builtin_is_invocable( memfun_type_ic, A&, int ) ); +SA( ! __builtin_is_invocable( memfun_type_ic, A*, int& ) ); +SA( __builtin_is_invocable( memfun_type_ic, const A& ) ); +SA( __builtin_is_invocable( memfun_type_ic, const A* ) ); +SA( ! __builtin_is_invocable( memfun_type_ic, const A&, int& ) ); +SA( ! __builtin_is_invocable( memfun_type_ic, const A*, int ) ); + +using memfun_type_iic = int& (A::*)(int&) const; + +SA( ! __builtin_is_invocable( memfun_type_iic ) ); +SA( ! __builtin_is_invocable( memfun_type_iic, int ) ); +SA( ! __builtin_is_invocable( memfun_type_iic, int& ) ); +SA( ! __builtin_is_invocable( memfun_type_iic, A&, int ) ); +SA( __builtin_is_invocable( memfun_type_iic, A&, int& ) ); +SA( ! __builtin_is_invocable( memfun_type_iic, A*, int ) ); +SA( __builtin_is_invocable( memfun_type_iic, A*, int& ) ); +SA( ! __builtin_is_invocable( memfun_type_iic, const A&, int ) ); +SA( ! __builtin_is_invocable( memfun_type_iic, const A&, int&, int ) ); +SA( __builtin_is_invocable( memfun_type_iic, const A&, int& ) ); +SA( __builtin_is_invocable( memfun_type_iic, const A*, int& ) ); + +struct B { + int& operator()(); + long& operator()() const; + bool& operator()(int); +private: + void operator()(int, int); +}; +using CB = const B; + +SA( __builtin_is_invocable( B ) ); +SA( __builtin_is_invocable( B& ) ); +SA( __builtin_is_invocable( B&& ) ); +SA( ! __builtin_is_invocable( B* ) ); +SA( __builtin_is_invocable( CB ) ); +SA( __builtin_is_invocable( CB& ) ); +SA( ! __builtin_is_invocable( CB* ) ); + +SA( __builtin_is_invocable( B, int ) ); +SA( __builtin_is_invocable( B&, int ) ); +SA( __builtin_is_invocable( B&&, int ) ); +SA( ! __builtin_is_invocable( B*, int ) ); +SA( ! __builtin_is_invocable( CB, int ) ); +SA( ! __builtin_is_invocable( CB&, int ) ); +SA( ! __builtin_is_invocable( CB*, int ) ); + +SA( ! __builtin_is_invocable( B, int, int ) ); +SA( ! __builtin_is_invocable( B&, int, int ) ); +SA( ! __builtin_is_invocable( B&&, int, int ) ); +SA( ! __builtin_is_invocable( B*, int, int ) ); +SA( ! __builtin_is_invocable( CB, int, int ) ); +SA( ! __builtin_is_invocable( CB&, int, int ) ); +SA( ! __builtin_is_invocable( CB*, int, int ) ); + +struct C : B { int& operator()() = delete; }; +using CC = const C; + +SA( ! __builtin_is_invocable( C ) ); +SA( ! __builtin_is_invocable( C& ) ); +SA( ! __builtin_is_invocable( C&& ) ); +SA( ! __builtin_is_invocable( C* ) ); +SA( ! __builtin_is_invocable( CC ) ); +SA( ! __builtin_is_invocable( CC& ) ); +SA( ! __builtin_is_invocable( CC* ) ); + +struct D { B operator*(); }; +using CD = const D; + +SA( ! __builtin_is_invocable( D ) ); + +struct E { void v(); }; +using CE = const E; + +SA( ! __builtin_is_invocable( E ) ); +SA( ! __builtin_is_invocable( void (E::*)() ) ); +SA( __builtin_is_invocable( void (E::*)(), E ) ); +SA( __builtin_is_invocable( void (E::*)(), E* ) ); +SA( ! __builtin_is_invocable( void (E::*)(), CE ) ); + +struct F : E {}; +using CF = const F; + +SA( ! __builtin_is_invocable( F ) ); +SA( __builtin_is_invocable( void (E::*)(), F ) ); +SA( __builtin_is_invocable( void (E::*)(), F* ) ); +SA( ! __builtin_is_invocable( void (E::*)(), CF ) ); + +struct G { E operator*(); }; +using CG = const G; + +SA( ! __builtin_is_invocable( G ) ); +SA( __builtin_is_invocable( void (E::*)(), G ) ); +SA( ! __builtin_is_invocable( void (E::*)(), G* ) ); +SA( ! __builtin_is_invocable( void (E::*)(), CG ) ); + +struct H { E& operator*(); }; +using CH = const H; + +SA( ! __builtin_is_invocable( H ) ); +SA( __builtin_is_invocable( void (E::*)(), H ) ); +SA( ! __builtin_is_invocable( void (E::*)(), H* ) ); +SA( ! __builtin_is_invocable( void (E::*)(), CH ) ); + +struct I { E&& operator*(); }; +using CI = const I; + +SA( ! __builtin_is_invocable( I ) ); +SA( __builtin_is_invocable( void (E::*)(), I ) ); +SA( ! __builtin_is_invocable( void (E::*)(), I* ) ); +SA( ! __builtin_is_invocable( void (E::*)(), CI ) ); + +struct K { E* operator*(); }; +using CK = const K; + +SA( ! __builtin_is_invocable( K ) ); +SA( ! __builtin_is_invocable( void (E::*)(), K ) ); +SA( ! __builtin_is_invocable( void (E::*)(), K* ) ); +SA( ! __builtin_is_invocable( void (E::*)(), CK ) ); + +struct L { CE operator*(); }; +using CL = const L; + +SA( ! __builtin_is_invocable( L ) ); +SA( ! __builtin_is_invocable( void (E::*)(), L ) ); +SA( ! __builtin_is_invocable( void (E::*)(), L* ) ); +SA( ! __builtin_is_invocable( void (E::*)(), CL ) ); + +struct M { + int i; +private: + long l; +}; +using CM = const M; + +SA( ! __builtin_is_invocable( M ) ); +SA( ! __builtin_is_invocable( M& ) ); +SA( ! __builtin_is_invocable( M&& ) ); +SA( ! __builtin_is_invocable( M* ) ); +SA( ! __builtin_is_invocable( CM ) ); +SA( ! __builtin_is_invocable( CM& ) ); +SA( ! __builtin_is_invocable( CM* ) ); + +SA( ! __builtin_is_invocable( int M::* ) ); +SA( __builtin_is_invocable( int M::*, M ) ); +SA( __builtin_is_invocable( int M::*, M& ) ); +SA( __builtin_is_invocable( int M::*, M&& ) ); +SA( __builtin_is_invocable( int M::*, M* ) ); +SA( __builtin_is_invocable( int M::*, CM ) ); +SA( __builtin_is_invocable( int M::*, CM& ) ); +SA( __builtin_is_invocable( int M::*, CM* ) ); +SA( ! __builtin_is_invocable( int M::*, int ) ); + +SA( ! __builtin_is_invocable( int CM::* ) ); +SA( __builtin_is_invocable( int CM::*, M ) ); +SA( __builtin_is_invocable( int CM::*, M& ) ); +SA( __builtin_is_invocable( int CM::*, M&& ) ); +SA( __builtin_is_invocable( int CM::*, M* ) ); +SA( __builtin_is_invocable( int CM::*, CM ) ); +SA( __builtin_is_invocable( int CM::*, CM& ) ); +SA( __builtin_is_invocable( int CM::*, CM* ) ); +SA( ! __builtin_is_invocable( int CM::*, int ) ); + +SA( ! __builtin_is_invocable( long M::* ) ); +SA( __builtin_is_invocable( long M::*, M ) ); +SA( __builtin_is_invocable( long M::*, M& ) ); +SA( __builtin_is_invocable( long M::*, M&& ) ); +SA( __builtin_is_invocable( long M::*, M* ) ); +SA( __builtin_is_invocable( long M::*, CM ) ); +SA( __builtin_is_invocable( long M::*, CM& ) ); +SA( __builtin_is_invocable( long M::*, CM* ) ); +SA( ! __builtin_is_invocable( long M::*, long ) ); + +SA( ! __builtin_is_invocable( long CM::* ) ); +SA( __builtin_is_invocable( long CM::*, M ) ); +SA( __builtin_is_invocable( long CM::*, M& ) ); +SA( __builtin_is_invocable( long CM::*, M&& ) ); +SA( __builtin_is_invocable( long CM::*, M* ) ); +SA( __builtin_is_invocable( long CM::*, CM ) ); +SA( __builtin_is_invocable( long CM::*, CM& ) ); +SA( __builtin_is_invocable( long CM::*, CM* ) ); +SA( ! __builtin_is_invocable( long CM::*, long ) ); + +SA( ! __builtin_is_invocable( short M::* ) ); +SA( __builtin_is_invocable( short M::*, M ) ); +SA( __builtin_is_invocable( short M::*, M& ) ); +SA( __builtin_is_invocable( short M::*, M&& ) ); +SA( __builtin_is_invocable( short M::*, M* ) ); +SA( __builtin_is_invocable( short M::*, CM ) ); +SA( __builtin_is_invocable( short M::*, CM& ) ); +SA( __builtin_is_invocable( short M::*, CM* ) ); +SA( ! __builtin_is_invocable( short M::*, short ) ); + +SA( ! __builtin_is_invocable( short CM::* ) ); +SA( __builtin_is_invocable( short CM::*, M ) ); +SA( __builtin_is_invocable( short CM::*, M& ) ); +SA( __builtin_is_invocable( short CM::*, M&& ) ); +SA( __builtin_is_invocable( short CM::*, M* ) ); +SA( __builtin_is_invocable( short CM::*, CM ) ); +SA( __builtin_is_invocable( short CM::*, CM& ) ); +SA( __builtin_is_invocable( short CM::*, CM* ) ); +SA( ! __builtin_is_invocable( short CM::*, short ) ); + +struct N { M operator*(); }; +SA( __builtin_is_invocable( int M::*, N ) ); +SA( ! __builtin_is_invocable( int M::*, N* ) ); + +struct O { M& operator*(); }; +SA( __builtin_is_invocable( int M::*, O ) ); +SA( ! __builtin_is_invocable( int M::*, O* ) ); + +struct P { M&& operator*(); }; +SA( __builtin_is_invocable( int M::*, P ) ); +SA( ! __builtin_is_invocable( int M::*, P* ) ); + +struct Q { M* operator*(); }; +SA( ! __builtin_is_invocable( int M::*, Q ) ); +SA( ! __builtin_is_invocable( int M::*, Q* ) ); + +struct R { void operator()(int = 0); }; + +SA( __builtin_is_invocable( R ) ); +SA( __builtin_is_invocable( R, int ) ); +SA( ! __builtin_is_invocable( R, int, int ) ); + +struct S { void operator()(int, ...); }; + +SA( ! __builtin_is_invocable( S ) ); +SA( __builtin_is_invocable( S, int ) ); +SA( __builtin_is_invocable( S, int, int ) ); +SA( __builtin_is_invocable( S, int, int, int ) ); + +void fn1() {} + +SA( __builtin_is_invocable( decltype(fn1) ) ); + +void fn2(int arr[10]); + +SA( __builtin_is_invocable( decltype(fn2), int[10] ) ); +SA( __builtin_is_invocable( decltype(fn2), int(&)[10] ) ); +SA( __builtin_is_invocable( decltype(fn2), int(&&)[10] ) ); +SA( ! __builtin_is_invocable( decltype(fn2), int(*)[10] ) ); +SA( ! __builtin_is_invocable( decltype(fn2), int(*&)[10] ) ); +SA( ! __builtin_is_invocable( decltype(fn2), int(*&&)[10] ) ); +SA( __builtin_is_invocable( decltype(fn2), int[] ) ); + +auto lambda = []() {}; + +SA( __builtin_is_invocable( decltype(lambda) ) ); + +template +struct can_invoke { + static constexpr bool value = __builtin_is_invocable( Func, Args... ); +}; + +SA( can_invoke::value ); + +struct T { + void func() const {} + int data; +}; + +SA( __builtin_is_invocable( decltype(&T::func)&, T& ) ); +SA( __builtin_is_invocable( decltype(&T::data)&, T& ) ); + +struct U { }; +struct V : U { U& operator*() = delete; }; +SA( __builtin_is_invocable( int U::*, V ) ); + +struct W : private U { U& operator*(); }; +SA( ! __builtin_is_invocable( int U::*, W ) ); + +struct X { int m; }; +struct Y { X& operator*(); }; +struct Z : Y { }; +SA( __builtin_is_invocable(int X::*, Z) ); diff --git a/gcc/testsuite/g++.dg/ext/is_invocable2.C b/gcc/testsuite/g++.dg/ext/is_invocable2.C new file mode 100644 index 00000000000..bf4d2a58d9f --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_invocable2.C @@ -0,0 +1,139 @@ +// { dg-do compile { target c++11 } } +// __builtin_is_invocable should handle std::reference_wrapper correctly. + +#include + +#define SA(X) static_assert((X),#X) + +using std::reference_wrapper; + +using func_type_v0 = void(*)(); + +SA( __builtin_is_invocable( reference_wrapper ) ); +SA( ! __builtin_is_invocable( reference_wrapper, int ) ); + +using func_type_i0 = int(*)(); + +SA( __builtin_is_invocable( reference_wrapper ) ); +SA( ! __builtin_is_invocable( reference_wrapper, int ) ); + +using func_type_l0 = int&(*)(); + +SA( __builtin_is_invocable( reference_wrapper ) ); +SA( ! __builtin_is_invocable( reference_wrapper ) ); + +using func_type_ii = int(*)(int); + +SA( ! __builtin_is_invocable( reference_wrapper ) ); +SA( __builtin_is_invocable( reference_wrapper, int ) ); + +using func_type_il = int(*)(int&); + +SA( ! __builtin_is_invocable( reference_wrapper ) ); +SA( ! __builtin_is_invocable( reference_wrapper, int ) ); +SA( __builtin_is_invocable( reference_wrapper, int& ) ); + +using func_type_ir = int(*)(int&&); + +SA( ! __builtin_is_invocable( reference_wrapper ) ); +SA( ! __builtin_is_invocable( reference_wrapper, int& ) ); +SA( __builtin_is_invocable( reference_wrapper, int ) ); +SA( __builtin_is_invocable( reference_wrapper, int&& ) ); + +struct A { }; + +using mem_type_i = int A::*; + +SA( ! __builtin_is_invocable( reference_wrapper ) ); +SA( ! __builtin_is_invocable( reference_wrapper, int ) ); +SA( ! __builtin_is_invocable( reference_wrapper, int* ) ); +SA( ! __builtin_is_invocable( reference_wrapper, int& ) ); +SA( ! __builtin_is_invocable( reference_wrapper, int&& ) ); +SA( __builtin_is_invocable( reference_wrapper, A ) ); +SA( __builtin_is_invocable( reference_wrapper, A* ) ); +SA( __builtin_is_invocable( reference_wrapper, A& ) ); +SA( __builtin_is_invocable( reference_wrapper, A&& ) ); + +using memfun_type_i = int (A::*)(); + +SA( ! __builtin_is_invocable( reference_wrapper ) ); +SA( ! __builtin_is_invocable( reference_wrapper, int ) ); +SA( ! __builtin_is_invocable( reference_wrapper, int* ) ); +SA( ! __builtin_is_invocable( reference_wrapper, int& ) ); +SA( ! __builtin_is_invocable( reference_wrapper, int&& ) ); +SA( __builtin_is_invocable( reference_wrapper, A ) ); +SA( __builtin_is_invocable( reference_wrapper, A* ) ); +SA( __builtin_is_invocable( reference_wrapper, A& ) ); +SA( __builtin_is_invocable( reference_wrapper, A&& ) ); +SA( ! __builtin_is_invocable( reference_wrapper, const A& ) ); +SA( ! __builtin_is_invocable( reference_wrapper, A&, int ) ); + +using memfun_type_ic = int (A::*)() const; + +SA( ! __builtin_is_invocable( reference_wrapper ) ); +SA( ! __builtin_is_invocable( reference_wrapper, int ) ); +SA( ! __builtin_is_invocable( reference_wrapper, int& ) ); +SA( __builtin_is_invocable( reference_wrapper, A& ) ); +SA( __builtin_is_invocable( reference_wrapper, A* ) ); +SA( ! __builtin_is_invocable( reference_wrapper, A&, int ) ); +SA( ! __builtin_is_invocable( reference_wrapper, A*, int& ) ); +SA( __builtin_is_invocable( reference_wrapper, const A& ) ); +SA( __builtin_is_invocable( reference_wrapper, const A* ) ); +SA( ! __builtin_is_invocable( reference_wrapper, const A&, int& ) ); +SA( ! __builtin_is_invocable( reference_wrapper, const A*, int ) ); + +using memfun_type_iic = int& (A::*)(int&) const; + +SA( ! __builtin_is_invocable( reference_wrapper ) ); +SA( ! __builtin_is_invocable( reference_wrapper, int ) ); +SA( ! __builtin_is_invocable( reference_wrapper, int& ) ); +SA( ! __builtin_is_invocable( reference_wrapper, A&, int ) ); +SA( __builtin_is_invocable( reference_wrapper, A&, int& ) ); +SA( ! __builtin_is_invocable( reference_wrapper, A*, int ) ); +SA( __builtin_is_invocable( reference_wrapper, A*, int& ) ); +SA( ! __builtin_is_invocable( reference_wrapper, const A&, int ) ); +SA( ! __builtin_is_invocable( reference_wrapper, const A&, int&, int ) ); +SA( __builtin_is_invocable( reference_wrapper, const A&, int& ) ); +SA( __builtin_is_invocable( reference_wrapper, const A*, int& ) ); + +struct B { + int& operator()(); + long& operator()() const; + bool& operator()(int); +private: + void operator()(int, int); +}; +using CB = const B; + +SA( __builtin_is_invocable( reference_wrapper ) ); +SA( __builtin_is_invocable( reference_wrapper& ) ); +SA( __builtin_is_invocable( reference_wrapper&& ) ); +SA( __builtin_is_invocable( reference_wrapper ) ); +SA( __builtin_is_invocable( reference_wrapper& ) ); +SA( __builtin_is_invocable( reference_wrapper, int ) ); +SA( ! __builtin_is_invocable( reference_wrapper&, int, int ) ); + +struct C : B { int& operator()() = delete; }; +using CC = const C; + +SA( ! __builtin_is_invocable( reference_wrapper ) ); +SA( ! __builtin_is_invocable( reference_wrapper& ) ); +SA( ! __builtin_is_invocable( reference_wrapper&& ) ); +SA( ! __builtin_is_invocable( reference_wrapper ) ); +SA( ! __builtin_is_invocable( reference_wrapper& ) ); + +struct D { B operator*(); }; +using CD = const D; + +SA( ! __builtin_is_invocable( reference_wrapper ) ); +SA( ! __builtin_is_invocable( reference_wrapper& ) ); +SA( ! __builtin_is_invocable( reference_wrapper&& ) ); +SA( ! __builtin_is_invocable( reference_wrapper* ) ); +SA( ! __builtin_is_invocable( reference_wrapper ) ); +SA( ! __builtin_is_invocable( reference_wrapper* ) ); + +std::function fn = []() {}; +auto refwrap = std::ref(fn); + +SA( __builtin_is_invocable( decltype(fn) ) ); +SA( __builtin_is_invocable( decltype(refwrap) ) ); diff --git a/gcc/testsuite/g++.dg/ext/is_invocable3.C b/gcc/testsuite/g++.dg/ext/is_invocable3.C new file mode 100644 index 00000000000..aa6d4d7183a --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_invocable3.C @@ -0,0 +1,51 @@ +// { dg-do compile { target c++11 } } +// __builtin_is_invocable should handle incomplete class correctly. + +#define SA(X) static_assert((X),#X) + +struct Incomplete; + +SA( ! __builtin_is_invocable( Incomplete ) ); // { dg-error "incomplete type" } +SA( ! __builtin_is_invocable( Incomplete, int ) ); // { dg-error "incomplete type" } + +SA( ! __builtin_is_invocable( int, Incomplete, int ) ); // { dg-error "incomplete type" } +SA( ! __builtin_is_invocable( int, Incomplete ) ); // { dg-error "incomplete type" } + +SA( ! __builtin_is_invocable( Incomplete, Incomplete() ) ); // { dg-error "incomplete type" } +SA( ! __builtin_is_invocable( Incomplete, Incomplete(int), int ) ); // { dg-error "incomplete type" } +SA( ! __builtin_is_invocable( Incomplete, Incomplete(int, int), int, int ) ); // { dg-error "incomplete type" } + +SA( ! __builtin_is_invocable( Incomplete, Incomplete(), int, int ) ); // { dg-error "incomplete type" } + +SA( ! __builtin_is_invocable( int(Incomplete), Incomplete ) ); // { dg-error "incomplete type" } +SA( ! __builtin_is_invocable( int(int, Incomplete), int, Incomplete ) ); // { dg-error "incomplete type" } +SA( ! __builtin_is_invocable( int(int, Incomplete), Incomplete, int ) ); // { dg-error "incomplete type" } + +SA( __builtin_is_invocable( int(Incomplete&), Incomplete& ) ); // { dg-bogus "incomplete type" } +SA( __builtin_is_invocable( int(int, Incomplete&), int, Incomplete& ) ); // { dg-bogus "incomplete type" } + +SA( __builtin_is_invocable( int(Incomplete&&), Incomplete&& ) ); // { dg-bogus "incomplete type" } +SA( __builtin_is_invocable( int(int, Incomplete&&), int, Incomplete&& ) ); // { dg-bogus "incomplete type" } + +SA( __builtin_is_invocable( int(const Incomplete&&), const Incomplete&& ) ); // { dg-bogus "incomplete type" } +SA( __builtin_is_invocable( int(int, const Incomplete&&), int, const Incomplete&& ) ); // { dg-bogus "incomplete type" } + +SA( __builtin_is_invocable( int(const Incomplete&), const Incomplete& ) ); // { dg-bogus "incomplete type" } +SA( __builtin_is_invocable( int(int, const Incomplete&), int, const Incomplete& ) ); // { dg-bogus "incomplete type" } + +SA( __builtin_is_invocable( int(const Incomplete&), Incomplete& ) ); // { dg-bogus "incomplete type" } +SA( __builtin_is_invocable( int(int, const Incomplete&), int, Incomplete& ) ); // { dg-bogus "incomplete type" } + +SA( __builtin_is_invocable( int Incomplete::*, const Incomplete& ) ); // { dg-bogus "incomplete type" } +SA( ! __builtin_is_invocable( void (Incomplete::*)(long&), const Incomplete*, long& ) ); // { dg-bogus "incomplete type" } +SA( __builtin_is_invocable( void (Incomplete::*)(long&) const, Incomplete*, long& ) ); // { dg-bogus "incomplete type" } + +template +struct Holder { T t; }; + +SA( __builtin_is_invocable( int(Holder&), Holder& ) ); // { dg-bogus "incomplete type" } + +// Define Incomplete, which is now not incomplete. +struct Incomplete { void operator()(); }; + +SA( __builtin_is_invocable( Incomplete ) ); // { dg-bogus "incomplete type" } diff --git a/gcc/testsuite/g++.dg/ext/is_invocable4.C b/gcc/testsuite/g++.dg/ext/is_invocable4.C new file mode 100644 index 00000000000..6c9c6212439 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_invocable4.C @@ -0,0 +1,33 @@ +// { dg-do compile { target c++11 } } +// Failed access check should be a substitution failure, not an error. + +#define SA(X) static_assert((X),#X) + +template +struct bool_constant { static constexpr bool value = B; }; + +template +struct is_invocable +: public bool_constant<__builtin_is_invocable(_Fn, _ArgTypes...)> +{ }; + +#if __cpp_variable_templates +template +constexpr bool is_invocable_v = __builtin_is_invocable(_Fn, _ArgTypes...); +#endif + +class Private +{ + void operator()() const + { + SA( ! is_invocable::value ); +#if __cpp_variable_templates + SA( ! is_invocable_v ); +#endif + } +}; + +SA( ! is_invocable::value ); +#if __cpp_variable_templates +SA( ! is_invocable_v ); +#endif From patchwork Thu May 2 16:13:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1930719 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=UDL4oopQ; 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 4VVfVv6XVrz23hd for ; Fri, 3 May 2024 02:28:07 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0EF883849AC2 for ; Thu, 2 May 2024 16:28:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0EF883849AC2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714667285; bh=BCMfFaThrcn22NixK8cwNUt5eU6cx/xW8+wG6bamBxo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=UDL4oopQLrPRQ/ogZV8sBI3SakDom7QHdmPaJJdoBwmySEgfzKVCZ2+Ar2Kd7hAf+ ha2AKWZgOSVeLndDs8+UhSqaQlEg20plre2r4HITa3wsD1UgJ+CQUm/zH18ZryQvlj +gdP7tcE/cF/w6kQ/7N7/wgody/V0ehigNEaPG48= 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 F13473858431; Thu, 2 May 2024 16:16:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F13473858431 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 F13473858431 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=1714666601; cv=none; b=FVLKZEu31nz9zPT62XESy8KKJ+WkSGQ13H6sVyoZIscwcINPd33i/Q3G4XhftqRr+r06uLxZh6CoMgOnAEStMRjJhZoKegS866zeTaWNoml2BOdlze0y3BltmdUb946sH65Hg0jYUkOiMqSTAZSbmYtyOdciIi0BjezMfqQXE8A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666601; c=relaxed/simple; bh=LSleXw7iS1HKjfu6sFTzboUv1o2SuRcPlKoPMQQEM3s=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Ykpl6dOWxIF/aCN50zJ02nYO3/UsUU3ea1csfavs2uDYy/usko0uqDmo/DlMZ9g09mbdOAEj8yjAmcn2C0TYbyVh4PF7fEAhkjUo5bKRHJDC6QxVBisxThSf7tAeRzWk1oHAQFej1kfzh/bdbdWA7MFLWHWKN8p5X85AdzBr04U= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247473.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442GBmmQ017725; Thu, 2 May 2024 16:16:33 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xv4e2bp6y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 16:16:32 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442GGGE4003516 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 09:16:16 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442GGFp3023119 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 09:16:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v16 24/26] libstdc++: Optimize std::is_invocable compilation performance Date: Thu, 2 May 2024 09:13:50 -0700 Message-ID: <20240502161614.3705912-25-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502161614.3705912-1-kmatsui@gcc.gnu.org> References: <20240228192843.188979-1-kmatsui@gcc.gnu.org> <20240502161614.3705912-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: ZgNjvaXL1uwsJzg1EaLMW6vbPUvcrxhz X-Proofpoint-ORIG-GUID: ZgNjvaXL1uwsJzg1EaLMW6vbPUvcrxhz X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_08,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 malwarescore=0 lowpriorityscore=0 spamscore=0 suspectscore=0 clxscore=1034 mlxlogscore=999 adultscore=0 impostorscore=0 phishscore=0 priorityscore=1501 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020106 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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::is_invocable by dispatching to the new __builtin_is_invocable trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_invocable): Use __builtin_is_invocable trait. * testsuite/20_util/is_invocable/incomplete_args_neg.cc: Handle the new error from __builtin_is_invocable. * testsuite/20_util/is_invocable/incomplete_neg.cc: Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 4 ++++ .../testsuite/20_util/is_invocable/incomplete_args_neg.cc | 1 + libstdc++-v3/testsuite/20_util/is_invocable/incomplete_neg.cc | 1 + 3 files changed, 6 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 15933a0730e..1f2d3240faf 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3239,7 +3239,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// std::is_invocable template struct is_invocable +#if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_is_invocable) + : public __bool_constant<__builtin_is_invocable(_Fn, _ArgTypes...)> +#else : __is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>::type +#endif { static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}), "_Fn must be a complete class or an unbounded array"); diff --git a/libstdc++-v3/testsuite/20_util/is_invocable/incomplete_args_neg.cc b/libstdc++-v3/testsuite/20_util/is_invocable/incomplete_args_neg.cc index a575750f9e9..9619129b817 100644 --- a/libstdc++-v3/testsuite/20_util/is_invocable/incomplete_args_neg.cc +++ b/libstdc++-v3/testsuite/20_util/is_invocable/incomplete_args_neg.cc @@ -18,6 +18,7 @@ // . // { dg-error "must be a complete class" "" { target *-*-* } 0 } +// { dg-prune-output "invalid use of incomplete type" } #include diff --git a/libstdc++-v3/testsuite/20_util/is_invocable/incomplete_neg.cc b/libstdc++-v3/testsuite/20_util/is_invocable/incomplete_neg.cc index 05848603555..b478ebce815 100644 --- a/libstdc++-v3/testsuite/20_util/is_invocable/incomplete_neg.cc +++ b/libstdc++-v3/testsuite/20_util/is_invocable/incomplete_neg.cc @@ -18,6 +18,7 @@ // . // { dg-error "must be a complete class" "" { target *-*-* } 0 } +// { dg-prune-output "invalid use of incomplete type" } #include From patchwork Thu May 2 16:13:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1930704 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=gbPSwDga; 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 4VVfSC4B2Lz1ydX for ; Fri, 3 May 2024 02:25:47 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CD282385828E for ; Thu, 2 May 2024 16:25:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CD282385828E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714667145; bh=HAQnQHTbZ00jbI8ibcAPBsOkxpKtHGSj4jGFJwOUbtk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=gbPSwDga6oLrg2fR9YcFQDbbS4VphICulh6mUAbJ1S9ZIQVzBjYqyi8hmguTXHMIV wzmlBJ1DTq5FWy2810UqexOKzS8mKOZdC91EMYw+i2p1RlXU7ess+iLVdJkJ+BucPT YCEIu9C736jWuDCm2Cpj0DeAuUNy6TdIRJj2I0SY= 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 3C039385828E; Thu, 2 May 2024 16:16:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3C039385828E 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 3C039385828E 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=1714666601; cv=none; b=iIveU5eL/9fXH6iTaeQvcibB6EJOhS9T7hETC0rBWn+u/n2M3AINTSZgz0TPcu7hQ+EGFd2tC1OgWlgAeKgQra21RwIFHqO3GUFGRj5vblByz18tIT7gaFwQ8MB8PRBFATNTBhMAFm21b8CECzjY5VIZhY2zhpvm0tpPmE10i80= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666601; c=relaxed/simple; bh=kTJitnYFSNQqmVaSfkeNzpwzqWMQo46NO9XR1hib3F4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=AikIabBPH3R2YGxzuf45//cCYKTZvCt312EHluGOILOFKlLN7eUGin194Ok2/r4E7uTBNd71+x5wsWB5ZqYnSg9eaaO3DcsI6VBZ4Tsq6uq7zwvsDCt1wL0n4eqN8vo0+Rp5c+rgo+xqMnibzShVzpQJCEc9zGhr105OFEooaA8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442GFpul018017; Thu, 2 May 2024 16:16:33 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xv4e33fj1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 16:16:32 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442GGG50003517 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 09:16:16 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442GGFp4023119 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 09:16:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v16 25/26] c++: Implement __builtin_is_nothrow_invocable trait Date: Thu, 2 May 2024 09:13:51 -0700 Message-ID: <20240502161614.3705912-26-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502161614.3705912-1-kmatsui@gcc.gnu.org> References: <20240228192843.188979-1-kmatsui@gcc.gnu.org> <20240502161614.3705912-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: cqZmzFVF672AHTShJUirnrEtBSw228uq X-Proofpoint-GUID: cqZmzFVF672AHTShJUirnrEtBSw228uq X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_08,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 priorityscore=1501 clxscore=1034 adultscore=0 impostorscore=0 mlxlogscore=965 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020106 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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::is_nothrow_invocable. gcc/cp/ChangeLog: * cp-trait.def: Define __builtin_is_nothrow_invocable. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_NOTHROW_INVOCABLE. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __builtin_is_nothrow_invocable. * g++.dg/ext/is_nothrow_invocable.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 6 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 5 ++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + .../g++.dg/ext/is_nothrow_invocable.C | 62 +++++++++++++++++++ 5 files changed, 77 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_nothrow_invocable.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 6d14ef7dcc7..8679d3ce658 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3825,6 +3825,12 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_NOTHROW_CONVERTIBLE: inform (loc, " %qT is not nothrow convertible from %qE", t2, t1); break; + case CPTK_IS_NOTHROW_INVOCABLE: + if (!t2) + inform (loc, " %qT is not nothrow invocable", t1); + else + inform (loc, " %qT is not nothrow invocable by %qE", t1, t2); + break; case CPTK_IS_OBJECT: inform (loc, " %qT is not an object type", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 5ae256c56ab..fcdf009890e 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -84,6 +84,7 @@ DEFTRAIT_EXPR (IS_MEMBER_POINTER, "__is_member_pointer", 1) DEFTRAIT_EXPR (IS_NOTHROW_ASSIGNABLE, "__is_nothrow_assignable", 2) DEFTRAIT_EXPR (IS_NOTHROW_CONSTRUCTIBLE, "__is_nothrow_constructible", -1) DEFTRAIT_EXPR (IS_NOTHROW_CONVERTIBLE, "__is_nothrow_convertible", 2) +DEFTRAIT_EXPR (IS_NOTHROW_INVOCABLE, "__builtin_is_nothrow_invocable", -1) DEFTRAIT_EXPR (IS_OBJECT, "__is_object", 1) DEFTRAIT_EXPR (IS_POINTER_INTERCONVERTIBLE_BASE_OF, "__is_pointer_interconvertible_base_of", 2) DEFTRAIT_EXPR (IS_POD, "__is_pod", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 4a13a36a81e..8b600daf5fd 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12588,6 +12588,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_NOTHROW_CONVERTIBLE: return is_nothrow_convertible (type1, type2); + case CPTK_IS_NOTHROW_INVOCABLE: + return expr_noexcept_p (build_invoke (type1, type2, tf_none), tf_none); + case CPTK_IS_OBJECT: return object_type_p (type1); @@ -12723,6 +12726,7 @@ same_type_ref_bind_p (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_NOTHROW_CONSTRUCTIBLE: case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: case CPTK_IS_INVOCABLE: + case CPTK_IS_NOTHROW_INVOCABLE: case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: case CPTK_REF_CONVERTS_FROM_TEMPORARY: to = type1; @@ -12828,6 +12832,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_INVOCABLE: case CPTK_IS_NOTHROW_CONSTRUCTIBLE: case CPTK_IS_NOTHROW_CONVERTIBLE: + case CPTK_IS_NOTHROW_INVOCABLE: case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: case CPTK_REF_CONVERTS_FROM_TEMPORARY: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index f4ac659e9b8..d806fa7ae60 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -32,6 +32,9 @@ #if !__has_builtin (__builtin_is_invocable) # error "__has_builtin (__builtin_is_invocable) failed" #endif +#if !__has_builtin (__builtin_is_nothrow_invocable) +# error "__has_builtin (__builtin_is_nothrow_invocable) failed" +#endif #if !__has_builtin (__builtin_is_pointer) # error "__has_builtin (__builtin_is_pointer) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_nothrow_invocable.C b/gcc/testsuite/g++.dg/ext/is_nothrow_invocable.C new file mode 100644 index 00000000000..bb84f48d754 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_nothrow_invocable.C @@ -0,0 +1,62 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +using func_type = void(*)(); +SA( ! __builtin_is_nothrow_invocable(func_type) ); + +#if __cpp_noexcept_function_type +using func_type_nt = void(*)() noexcept; +SA( __builtin_is_nothrow_invocable(func_type_nt) ); +#endif + +struct X { }; +using mem_type = int X::*; + +SA( ! __builtin_is_nothrow_invocable(mem_type) ); +SA( ! __builtin_is_nothrow_invocable(mem_type, int) ); +SA( ! __builtin_is_nothrow_invocable(mem_type, int&) ); +SA( __builtin_is_nothrow_invocable(mem_type, X&) ); + +using memfun_type = int (X::*)(); + +SA( ! __builtin_is_nothrow_invocable(memfun_type) ); +SA( ! __builtin_is_nothrow_invocable(memfun_type, int) ); +SA( ! __builtin_is_nothrow_invocable(memfun_type, int&) ); +SA( ! __builtin_is_nothrow_invocable(memfun_type, X&) ); +SA( ! __builtin_is_nothrow_invocable(memfun_type, X*) ); + +#if __cpp_noexcept_function_type +using memfun_type_nt = int (X::*)() noexcept; + +SA( ! __builtin_is_nothrow_invocable(memfun_type_nt) ); +SA( ! __builtin_is_nothrow_invocable(memfun_type_nt, int) ); +SA( ! __builtin_is_nothrow_invocable(memfun_type_nt, int&) ); +SA( __builtin_is_nothrow_invocable(memfun_type_nt, X&) ); +SA( __builtin_is_nothrow_invocable(memfun_type_nt, X*) ); +#endif + +struct F { + int& operator()(); + long& operator()() const noexcept; + short& operator()(int) &&; + char& operator()(int) const& noexcept; +private: + void operator()(int, int) noexcept; +}; +using CF = const F; + +SA( ! __builtin_is_nothrow_invocable(F ) ); +SA( __builtin_is_nothrow_invocable(CF) ); + +SA( ! __builtin_is_nothrow_invocable(F, int) ); +SA( __builtin_is_nothrow_invocable(F&, int) ); + +SA( __builtin_is_nothrow_invocable(CF, int) ); +SA( __builtin_is_nothrow_invocable(CF&, int) ); +SA( ! __builtin_is_nothrow_invocable(F, int, int) ); + +struct FX { + X operator()() const noexcept { return {}; } +}; +SA( __builtin_is_nothrow_invocable(FX) ); From patchwork Thu May 2 16:13:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1930699 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=LFXBRKkK; 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 4VVfP41K12z20fb for ; Fri, 3 May 2024 02:23:04 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4A898386F432 for ; Thu, 2 May 2024 16:23:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4A898386F432 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714666982; bh=gNgSsLMuOX/4CegNR+kfK4efisBaj+mn44Gj8Vkwbes=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=LFXBRKkKlxpJKTBkefGjFPuNSmEOGDydehJVfrlNpJPUEAlTKnLgavfmHIhR1NPv8 ko6fe6hV1uUv8nnZ88j/+La6gu3rM3fEW8s38qGz/rmpBntvdpAI+9CioxGFBZaidI nqIs+lex4718fqWAXeldwhDEwqNn41eKHAMjTq2M= 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 DBE0E385842A; Thu, 2 May 2024 16:16:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DBE0E385842A 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 DBE0E385842A 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=1714666601; cv=none; b=hmMFMwJC+vXk51048/NdqCGyVvvQ/aFyHpFenctjuMdQJEWyzBHUyiv8GplRgU/HhCDb3GXnUBG+aTuS5tJpZu4hoCPbOTiZKYO+7pWiO8WGNVCby+q7jfcs2QKMgklPeNO8B+LaJeKEIdJ9wyyjvsKbzlA49P58K2v/bpJdjb8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666601; c=relaxed/simple; bh=TRjzu7c7eICRHmKbGqsayVD73KGOUWZPs2CoBtd8NB0=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=DnBIebjrmvGtgbGQ44/jOoKe5Th8E/x6HfTysvj1+JpJ7BDzO60FzCNQ3flEMfbpIvbGHwdfoCHEceWua4OMpTgH8Zy8/UADAGKNDCVAACuCZv2uPFBo+QrCok2deYwLM1iPOzl92uWoMYW5vFi1iVZpTZVwvcPFvPe6iLtb3Vs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247471.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442GD4Km023078; Thu, 2 May 2024 16:16:33 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xv4e43n3n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 16:16:32 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442GGHUb003518 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 09:16:17 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442GGFp5023119 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 09:16:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v16 26/26] libstdc++: Optimize std::is_nothrow_invocable compilation performance Date: Thu, 2 May 2024 09:13:52 -0700 Message-ID: <20240502161614.3705912-27-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502161614.3705912-1-kmatsui@gcc.gnu.org> References: <20240228192843.188979-1-kmatsui@gcc.gnu.org> <20240502161614.3705912-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: eqLnElGDO8GosLJvrmwHJK73LCSZRJud X-Proofpoint-GUID: eqLnElGDO8GosLJvrmwHJK73LCSZRJud X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_05,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 lowpriorityscore=0 spamscore=0 malwarescore=0 impostorscore=0 phishscore=0 priorityscore=1501 mlxscore=0 suspectscore=0 adultscore=0 bulkscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020106 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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::is_nothrow_invocable by dispatching to the new __builtin_is_nothrow_invocable trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_nothrow_invocable): Use __builtin_is_nothrow_invocable trait. * testsuite/20_util/is_nothrow_invocable/incomplete_args_neg.cc: Handle the new error from __builtin_is_nothrow_invocable. * testsuite/20_util/is_nothrow_invocable/incomplete_neg.cc: Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 4 ++++ .../20_util/is_nothrow_invocable/incomplete_args_neg.cc | 1 + .../testsuite/20_util/is_nothrow_invocable/incomplete_neg.cc | 1 + 3 files changed, 6 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 1f2d3240faf..2a34c9bcc21 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3269,8 +3269,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// std::is_nothrow_invocable template struct is_nothrow_invocable +#if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_is_nothrow_invocable) + : public __bool_constant<__builtin_is_nothrow_invocable(_Fn, _ArgTypes...)> +#else : __and_<__is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>, __call_is_nothrow_<_Fn, _ArgTypes...>>::type +#endif { static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}), "_Fn must be a complete class or an unbounded array"); diff --git a/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_args_neg.cc b/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_args_neg.cc index 3c225883eaf..3f8542dd366 100644 --- a/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_args_neg.cc +++ b/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_args_neg.cc @@ -18,6 +18,7 @@ // . // { dg-error "must be a complete class" "" { target *-*-* } 0 } +// { dg-prune-output "invalid use of incomplete type" } #include diff --git a/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_neg.cc b/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_neg.cc index 5a728bfa03b..d3bdf08448b 100644 --- a/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_neg.cc +++ b/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_neg.cc @@ -18,6 +18,7 @@ // . // { dg-error "must be a complete class" "" { target *-*-* } 0 } +// { dg-prune-output "invalid use of incomplete type" } #include