* [PATCH 0/2] Optimize is_bounded_array trait performance
@ 2023-09-12 2:38 Ken Matsui
2023-09-12 2:38 ` [PATCH 1/2] c++: Implement __is_bounded_array built-in trait Ken Matsui
2023-09-12 2:38 ` [PATCH 2/2] libstdc++: Optimize is_bounded_array trait performance Ken Matsui
0 siblings, 2 replies; 3+ messages in thread
From: Ken Matsui @ 2023-09-12 2:38 UTC (permalink / raw)
To: gcc-patches; +Cc: libstdc++, Ken Matsui
This patch series optimizes is_bounded_array trait
performance. The first patch implements __is_bounded_array
built-in trait. The second patch optimizes is_bounded_array
trait performance by using __is_bounded_array built-in trait
if available.
The performance improvement is shown in the following benchmark:
https://github.com/ken-matsui/gsoc23/blob/main/is_bounded_array_v.md#mon-sep-11-072608-pm-pdt-2023
Time:
Peak Memory Usage:
Total Memory Usage:
Ken Matsui (2):
c++: Implement __is_bounded_array built-in trait
libstdc++: Optimize is_bounded_array trait performance
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_bounded_array.C | 38 +++++++++++++++++++++
libstdc++-v3/include/std/type_traits | 5 +++
6 files changed, 54 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/ext/is_bounded_array.C
--
2.42.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] c++: Implement __is_bounded_array built-in trait
2023-09-12 2:38 [PATCH 0/2] Optimize is_bounded_array trait performance Ken Matsui
@ 2023-09-12 2:38 ` Ken Matsui
2023-09-12 2:38 ` [PATCH 2/2] libstdc++: Optimize is_bounded_array trait performance Ken Matsui
1 sibling, 0 replies; 3+ messages in thread
From: Ken Matsui @ 2023-09-12 2:38 UTC (permalink / raw)
To: gcc-patches; +Cc: libstdc++, Ken Matsui
This patch implements built-in trait for std::is_bounded_array.
gcc/cp/ChangeLog:
* cp-trait.def (IS_BOUNDED_ARRAY): Define __is_bounded_array.
* constraint.cc (diagnose_trait_expr): Handle CPTK_IS_BOUNDED_ARRAY.
* semantics.cc (trait_expr_value): Likewise.
(finish_trait_expr): Likewise.
gcc/testsuite/ChangeLog:
* g++.dg/ext/has-builtin-1.C: Test existence of __is_bounded_array.
* g++.dg/ext/is_bounded_array.C: New test.
Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
---
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_bounded_array.C | 38 +++++++++++++++++++++
5 files changed, 49 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/ext/is_bounded_array.C
diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index c9e4e7043cd..4db9acade65 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -3760,6 +3760,9 @@ diagnose_trait_expr (tree expr, tree args)
case CPTK_IS_ASSIGNABLE:
inform (loc, " %qT is not assignable from %qT", t1, t2);
break;
+ case CPTK_IS_BOUNDED_ARRAY:
+ inform (loc, " %qT is not a bounded array", t1);
+ break;
case CPTK_IS_TRIVIALLY_ASSIGNABLE:
inform (loc, " %qT is not trivially assignable from %qT", t1, t2);
break;
diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def
index 8b7fece0cc8..d50ca8a7781 100644
--- a/gcc/cp/cp-trait.def
+++ b/gcc/cp/cp-trait.def
@@ -61,6 +61,7 @@ DEFTRAIT_EXPR (IS_ABSTRACT, "__is_abstract", 1)
DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1)
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_CONSTRUCTIBLE, "__is_constructible", -1)
DEFTRAIT_EXPR (IS_CONVERTIBLE, "__is_convertible", 2)
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 0f7f4e87ae4..87eeed34068 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -12142,6 +12142,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
case CPTK_IS_ENUM:
return type_code1 == ENUMERAL_TYPE;
+ case CPTK_IS_BOUNDED_ARRAY:
+ return type_code1 == ARRAY_TYPE && TYPE_DOMAIN (type1);
+
case CPTK_IS_FINAL:
return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1);
@@ -12359,6 +12362,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2)
case CPTK_IS_ENUM:
case CPTK_IS_UNION:
case CPTK_IS_SAME:
+ case CPTK_IS_BOUNDED_ARRAY:
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 f343e153e56..04db7756a26 100644
--- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C
+++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
@@ -146,3 +146,6 @@
#if !__has_builtin (__remove_cvref)
# error "__has_builtin (__remove_cvref) failed"
#endif
+#if !__has_builtin (__is_bounded_array)
+# error "__has_builtin (__is_bounded_array) failed"
+#endif
diff --git a/gcc/testsuite/g++.dg/ext/is_bounded_array.C b/gcc/testsuite/g++.dg/ext/is_bounded_array.C
new file mode 100644
index 00000000000..346790eba12
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/is_bounded_array.C
@@ -0,0 +1,38 @@
+// { dg-do compile { target c++11 } }
+
+#include <testsuite_tr1.h>
+
+using namespace __gnu_test;
+
+#define SA(X) static_assert((X),#X)
+
+#define SA_TEST_CONST(TRAIT, TYPE, EXPECT) \
+ SA(TRAIT(TYPE) == EXPECT); \
+ SA(TRAIT(const TYPE) == EXPECT)
+
+#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)
+
+SA_TEST_CATEGORY(__is_bounded_array, int[2], true);
+SA_TEST_CATEGORY(__is_bounded_array, int[], false);
+SA_TEST_CATEGORY(__is_bounded_array, int[2][3], true);
+SA_TEST_CATEGORY(__is_bounded_array, int[][3], false);
+SA_TEST_CATEGORY(__is_bounded_array, float*[2], true);
+SA_TEST_CATEGORY(__is_bounded_array, float*[], false);
+SA_TEST_CATEGORY(__is_bounded_array, float*[2][3], true);
+SA_TEST_CATEGORY(__is_bounded_array, float*[][3], false);
+SA_TEST_CATEGORY(__is_bounded_array, ClassType[2], true);
+SA_TEST_CATEGORY(__is_bounded_array, ClassType[], false);
+SA_TEST_CATEGORY(__is_bounded_array, ClassType[2][3], true);
+SA_TEST_CATEGORY(__is_bounded_array, ClassType[][3], false);
+SA_TEST_CATEGORY(__is_bounded_array, int(*)[2], false);
+SA_TEST_CATEGORY(__is_bounded_array, int(*)[], false);
+SA_TEST_CATEGORY(__is_bounded_array, int(&)[2], false);
+SA_TEST_CONST(__is_bounded_array, int(&)[], false);
+
+// Sanity check.
+SA_TEST_CATEGORY(__is_bounded_array, ClassType, false);
+SA_TEST_CONST(__is_bounded_array, void(), false);
--
2.42.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] libstdc++: Optimize is_bounded_array trait performance
2023-09-12 2:38 [PATCH 0/2] Optimize is_bounded_array trait performance Ken Matsui
2023-09-12 2:38 ` [PATCH 1/2] c++: Implement __is_bounded_array built-in trait Ken Matsui
@ 2023-09-12 2:38 ` Ken Matsui
1 sibling, 0 replies; 3+ messages in thread
From: Ken Matsui @ 2023-09-12 2:38 UTC (permalink / raw)
To: gcc-patches; +Cc: libstdc++, Ken Matsui
This patch optimizes the performance of the is_bounded_array trait
by dispatching to the new __is_bounded_array built-in trait.
libstdc++-v3/ChangeLog:
* include/std/type_traits (is_bounded_array_v): Use __is_bounded_array
built-in trait.
Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
---
libstdc++-v3/include/std/type_traits | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index 677cd934b94..766f9a69445 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -3494,11 +3494,16 @@ template<typename _Ret, typename _Fn, typename... _Args>
/// True for a type that is an array of known bound.
/// @ingroup variable_templates
/// @since C++20
+# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_bounded_array)
+ template<typename _Tp>
+ inline constexpr bool is_bounded_array_v = __is_bounded_array(_Tp);
+# else
template<typename _Tp>
inline constexpr bool is_bounded_array_v = false;
template<typename _Tp, size_t _Size>
inline constexpr bool is_bounded_array_v<_Tp[_Size]> = true;
+# endif
/// True for a type that is an array of unknown bound.
/// @ingroup variable_templates
--
2.42.0
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-09-12 2:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-12 2:38 [PATCH 0/2] Optimize is_bounded_array trait performance Ken Matsui
2023-09-12 2:38 ` [PATCH 1/2] c++: Implement __is_bounded_array built-in trait Ken Matsui
2023-09-12 2:38 ` [PATCH 2/2] libstdc++: Optimize is_bounded_array trait performance Ken Matsui
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).