[llvm-branch-commits] [libcxx] [libc++] Add ABI flag to make __tree nodes more compact (PR #147681)
Louis Dionne via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Jul 9 09:09:50 PDT 2025
================
@@ -593,6 +594,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)>;
----------------
ldionne wrote:
I think the base specialization should use `__pointer_int_pair` itself, that way if a fancy pointer has free bits (which is likely), we'd be able to reuse those as well. That would require the `__pointer_int_pair` to have a protocol for the 3rd party fancy pointer to advertise that.
A bit like this:
```c++
template <class _VoidPtr>
class _LIBCPP_STANDALONE_DEBUG
__tree_node_base : public __tree_end_node<__rebind_pointer_t<_VoidPtr, __tree_node_base<_VoidPtr> > > {
public:
using pointer = __rebind_pointer_t<_VoidPtr, __tree_node_base>;
using __end_node_pointer _LIBCPP_NODEBUG = __rebind_pointer_t<_VoidPtr, __tree_end_node<pointer> >;
pointer __right_;
private:
#if _LIBCPP_ABI_POINTER_INT_PAIR_STUFF
using __pair_t = __pointer_int_pair<__end_node_pointer, bool, __integer_width(1)>;
__pair_t __parent_and_color_;
#else
__end_node_pointer __parent_;
__tree_color __color_;
#endif
public:
_LIBCPP_HIDE_FROM_ABI pointer __parent_unsafe() const { return static_cast<pointer>(__parent_); }
_LIBCPP_HIDE_FROM_ABI void __set_parent(pointer __p) { __parent_ = static_cast<__end_node_pointer>(__p); }
_LIBCPP_HIDE_FROM_ABI void __set_parent(__end_node_pointer __p) { __parent_ = __p; }
_LIBCPP_HIDE_FROM_ABI __end_node_pointer __get_parent() const { return __parent_; }
_LIBCPP_HIDE_FROM_ABI __tree_color __get_color() const { return __color_; }
_LIBCPP_HIDE_FROM_ABI void __set_color(__tree_color __color) { __color_ = __color; }
~__tree_node_base() = delete;
__tree_node_base(__tree_node_base const&) = delete;
__tree_node_base& operator=(__tree_node_base const&) = delete;
};
```
https://github.com/llvm/llvm-project/pull/147681
More information about the llvm-branch-commits
mailing list