https://github.com/philnik777 updated https://github.com/llvm/llvm-project/pull/147681
>From 019af0059fa1d33deb0aaf278212f9a37dcbf8de Mon Sep 17 00:00:00 2001 From: Nikolas Klauser <nikolasklau...@berlin.de> Date: Tue, 10 Jun 2025 05:56:20 +0200 Subject: [PATCH] [libc++] Add ABI flag to make __tree nodes more compact --- libcxx/include/__configuration/abi.h | 3 +++ libcxx/include/__tree | 40 ++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/libcxx/include/__configuration/abi.h b/libcxx/include/__configuration/abi.h index a75cd0a675339..759687914be91 100644 --- a/libcxx/include/__configuration/abi.h +++ b/libcxx/include/__configuration/abi.h @@ -75,6 +75,7 @@ # define _LIBCPP_ABI_OPTIMIZED_FUNCTION # define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO # define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION +# define _LIBCPP_ABI_TREE_POINTER_INT_PAIR # define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY # define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_STRING_VIEW # define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION @@ -98,6 +99,8 @@ # endif #endif +#define _LIBCPP_ABI_TREE_POINTER_INT_PAIR + // We had some bugs where we use [[no_unique_address]] together with construct_at, // which causes UB as the call on construct_at could write to overlapping subobjects // diff --git a/libcxx/include/__tree b/libcxx/include/__tree index 0f80f83e91619..ae7b348090300 100644 --- a/libcxx/include/__tree +++ b/libcxx/include/__tree @@ -41,6 +41,7 @@ #include <__utility/forward.h> #include <__utility/move.h> #include <__utility/pair.h> +#include <__utility/pointer_int_pair.h> #include <__utility/swap.h> #include <limits> @@ -573,6 +574,8 @@ public: using pointer = __rebind_pointer_t<_VoidPtr, __tree_node_base>; using __end_node_pointer _LIBCPP_NODEBUG = __rebind_pointer_t<_VoidPtr, __tree_end_node<pointer> >; + static_assert(is_same<typename pointer_traits<_VoidPtr>::element_type, void>::value); + pointer __right_; private: @@ -593,6 +596,43 @@ public: __tree_node_base& operator=(__tree_node_base const&) = delete; }; +#ifdef _LIBCPP_ABI_TREE_POINTER_INT_PAIR +template <> +class __tree_node_base<void*> : public __tree_end_node<__tree_node_base<void*>*> { +public: + using pointer = __tree_node_base<void*>*; + using __end_node_pointer _LIBCPP_NODEBUG = __tree_end_node<__tree_node_base<void*>*>*; + + pointer __right_; + +private: + using __pair_t = __pointer_int_pair<__end_node_pointer, bool, __integer_width(1)>; + + __pair_t __parent_and_color_; + +public: + _LIBCPP_HIDE_FROM_ABI pointer __parent_unsafe() const { + return static_cast<pointer>(__parent_and_color_.__get_ptr()); + } + + _LIBCPP_HIDE_FROM_ABI void __set_parent(pointer __ptr) { __set_parent(static_cast<__end_node_pointer>(__ptr)); } + + _LIBCPP_HIDE_FROM_ABI void __set_parent(__end_node_pointer __ptr) { + __parent_and_color_ = __pair_t(__ptr, __parent_and_color_.__get_value()); + } + + _LIBCPP_HIDE_FROM_ABI __end_node_pointer __get_parent() const { return __parent_and_color_.__get_ptr(); } + _LIBCPP_HIDE_FROM_ABI __tree_color __get_color() const { + return static_cast<__tree_color>(__parent_and_color_.__get_value()); + } + _LIBCPP_HIDE_FROM_ABI void __set_color(__tree_color __color) { + __parent_and_color_ = __pair_t(__parent_and_color_.__get_ptr(), __color == __tree_color::__black); + } +}; +#endif // _LIBCPP_ABI_TREE_POINTER_INT_PAIR + +static_assert(sizeof(__tree_node_base<void*>) == 24); + template <class _Tp, class _VoidPtr> class _LIBCPP_STANDALONE_DEBUG __tree_node : public __tree_node_base<_VoidPtr> { public: _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits