Page MenuHomePhabricator

Pass std::unique_ptr, std::shared_ptr and std::weak_ptr in registers when possible.

Authored by rsmith on Jun 24 2019, 5:39 PM.


Group Reviewers
Restricted Project

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

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 (though that dependence could be removed with
some changes to __compressed_pair).

Event Timeline

rsmith created this revision.Jun 24 2019, 5:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 24 2019, 5:39 PM
Herald added a subscriber: christof. · View Herald Transcript
EricWF added inline comments.Jun 25 2019, 3:17 PM

I'm trying to keep all of the ABI configuration in the same place at the top of the file.

Could you give this a descriptive name like _LIBCPP_ABI_ENABLE_TRIVIAL_ABI_ATTRIBUTE and then use that here to configure _LIBCPP_TRIVIAL_ABI?

EricWF accepted this revision.Aug 30 2019, 11:15 AM

@rsmith Please address the inline comment. Otherwise this LGTM.

This revision is now accepted and ready to land.Aug 30 2019, 11:15 AM
Herald added a reviewer: Restricted Project. · View Herald TranscriptAug 31 2020, 11:20 PM