[libcxx-commits] [PATCH] D63748: Pass std::unique_ptr, std::shared_ptr and std::weak_ptr in registers when possible.

Richard Smith - zygoloid via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jun 24 17:42:39 PDT 2019


rsmith created this revision.
rsmith added reviewers: EricWF, mclow.lists.
Herald added a subscriber: christof.
Herald added a project: libc++.

Currently, these types are all always passed indirectly, because they
have non-trivial special members. With this patch, we'll pass them in
registers instead under the libc++ unstable ABI when using a recent
Clang.

This has a small impact on observable behavior: the destructor will be
run in the callee rather than in the caller, which means

1. the pointee type of `unique_ptr<T>` must be complete in the context of a function definition that takes such a pointer by value, and
2. the order in which destructors for parameters are run is not strictly in reverse construction order.

This still needs some performance testing and (since it's technically
non-conforming due to the above) should be put behind a flag, but I'm
mailing it out now to test the waters for this kind of change.

This depends on D63744 <https://reviews.llvm.org/D63744> (though that dependence could be removed with
some changes to `__compressed_pair`).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63748

Files:
  libcxx/include/__config
  libcxx/include/memory


Index: libcxx/include/memory
===================================================================
--- libcxx/include/memory
+++ libcxx/include/memory
@@ -2395,7 +2395,7 @@
 };
 
 template <class _Tp, class _Dp = default_delete<_Tp> >
-class _LIBCPP_TEMPLATE_VIS unique_ptr {
+class _LIBCPP_TEMPLATE_VIS _LIBCPP_TRIVIAL_ABI unique_ptr {
 public:
   typedef _Tp element_type;
   typedef _Dp deleter_type;
@@ -2691,7 +2691,7 @@
 
 
 template <class _Tp, class _Dp>
-class _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp> {
+class _LIBCPP_TEMPLATE_VIS _LIBCPP_TRIVIAL_ABI unique_ptr<_Tp[], _Dp> {
 public:
   typedef _Tp element_type;
   typedef _Dp deleter_type;
@@ -3848,7 +3848,7 @@
 template<class _Tp> class _LIBCPP_TEMPLATE_VIS enable_shared_from_this;
 
 template<class _Tp>
-class _LIBCPP_TEMPLATE_VIS shared_ptr
+class _LIBCPP_TEMPLATE_VIS _LIBCPP_TRIVIAL_ABI shared_ptr
 {
 public:
     typedef _Tp element_type;
@@ -5109,7 +5109,7 @@
 #endif  // _LIBCPP_NO_RTTI
 
 template<class _Tp>
-class _LIBCPP_TEMPLATE_VIS weak_ptr
+class _LIBCPP_TEMPLATE_VIS _LIBCPP_TRIVIAL_ABI weak_ptr
 {
 public:
     typedef _Tp element_type;
Index: libcxx/include/__config
===================================================================
--- libcxx/include/__config
+++ libcxx/include/__config
@@ -1014,6 +1014,12 @@
 #  define _LIBCPP_USE_NO_UNIQUE_ADDRESS 1
 #endif
 
+#if __has_cpp_attribute(clang::trivial_abi) && defined(_LIBCPP_ABI_UNSTABLE)
+#  define _LIBCPP_TRIVIAL_ABI [[clang::trivial_abi]]
+#else
+#  define _LIBCPP_TRIVIAL_ABI
+#endif
+
 #if _LIBCPP_STD_VER > 14 && defined(__cpp_inline_variables) && (__cpp_inline_variables >= 201606L)
 #  define _LIBCPP_INLINE_VAR inline
 #else


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63748.206343.patch
Type: text/x-patch
Size: 1678 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190625/af24a958/attachment.bin>


More information about the libcxx-commits mailing list