[gcc r15-1252] libstdc++: Optimize std::rank compilation performance
Ken Matsui
kmatsui@gcc.gnu.org
Thu Jun 13 12:58:36 GMT 2024
https://gcc.gnu.org/g:6f0dfa6f1acdf78d764d6f5d6f53c2f2a768c047
commit r15-1252-g6f0dfa6f1acdf78d764d6f5d6f53c2f2a768c047
Author: Ken Matsui <kmatsui@gcc.gnu.org>
Date: Thu Feb 15 07:19:02 2024 -0800
libstdc++: Optimize std::rank compilation performance
This patch optimizes the compilation performance of std::rank
by dispatching to the new __array_rank built-in trait.
libstdc++-v3/ChangeLog:
* include/std/type_traits (rank): Use __array_rank built-in
trait.
(rank_v): Likewise.
Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
Reviewed-by: Patrick Palka <ppalka@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Diff:
---
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 3d158f993a8b..5402574efe99 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -1447,6 +1447,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
};
/// rank
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__array_rank)
+ template<typename _Tp>
+ struct rank
+ : public integral_constant<std::size_t, __array_rank(_Tp)> { };
+#else
template<typename>
struct rank
: public integral_constant<std::size_t, 0> { };
@@ -1458,6 +1463,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Tp>
struct rank<_Tp[]>
: public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
+#endif
/// extent
template<typename, unsigned _Uint = 0>
@@ -3531,12 +3537,17 @@ template <typename _Tp>
template <typename _Tp>
inline constexpr size_t alignment_of_v = alignment_of<_Tp>::value;
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__array_rank)
+template <typename _Tp>
+ inline constexpr size_t rank_v = __array_rank(_Tp);
+#else
template <typename _Tp>
inline constexpr size_t rank_v = 0;
template <typename _Tp, size_t _Size>
inline constexpr size_t rank_v<_Tp[_Size]> = 1 + rank_v<_Tp>;
template <typename _Tp>
inline constexpr size_t rank_v<_Tp[]> = 1 + rank_v<_Tp>;
+#endif
template <typename _Tp, unsigned _Idx = 0>
inline constexpr size_t extent_v = 0;
More information about the Libstdc++-cvs
mailing list