-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[libc++] Optimize std::exception_ptr
#162773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
12b8e7a
02ab3cb
4661785
3c8f64d
f792983
186bbd1
8466f58
ed1d67b
cdf5409
484cfaa
7280bd7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// -*- C++ -*- | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
namespace __cxxabiv1 { | ||
|
||
extern "C" { | ||
_LIBCPP_OVERRIDABLE_FUNC_VIS void __cxa_increment_exception_refcount(void*) _NOEXCEPT; | ||
_LIBCPP_OVERRIDABLE_FUNC_VIS void __cxa_decrement_exception_refcount(void*) _NOEXCEPT; | ||
_LIBCPP_OVERRIDABLE_FUNC_VIS void* __cxa_current_primary_exception() _NOEXCEPT; | ||
_LIBCPP_OVERRIDABLE_FUNC_VIS void __cxa_rethrow_primary_exception(void*); | ||
} | ||
|
||
} // namespace __cxxabiv1 | ||
|
||
namespace std { | ||
|
||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_ALWAYS_INLINE inline void exception_ptr::__increment_refcount(void* __ptr) _NOEXCEPT { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't spray always_inline everywhere. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I only added it to That being said, I guess I was overly careful here. I will remove it |
||
if (__ptr) | ||
__cxxabiv1::__cxa_increment_exception_refcount(__ptr); | ||
} | ||
|
||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_ALWAYS_INLINE inline void exception_ptr::__decrement_refcount(void* __ptr) _NOEXCEPT { | ||
if (__ptr) | ||
__cxxabiv1::__cxa_decrement_exception_refcount(__ptr); | ||
} | ||
|
||
_LIBCPP_EXPORTED_FROM_LIB_INLINEABLE exception_ptr current_exception() _NOEXCEPT { | ||
// It would be nicer if there was a constructor that took a ptr, then | ||
// this whole function would be just: | ||
// return exception_ptr(__cxa_current_primary_exception()); | ||
exception_ptr __ptr; | ||
__ptr.__ptr_ = __cxxabiv1::__cxa_current_primary_exception(); | ||
return __ptr; | ||
} | ||
|
||
_LIBCPP_EXPORTED_FROM_LIB_INLINEABLE void rethrow_exception(exception_ptr __ptr) { | ||
__cxxabiv1::__cxa_rethrow_primary_exception(__ptr.__ptr_); | ||
// if __ptr.__ptr_ is NULL, above returns so we terminate. | ||
_LIBCPP_VERBOSE_ABORT("tried to rethrow an empty exception_ptr\n"); | ||
} | ||
|
||
} // namespace std |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced this new macro is necessary. IIUC these functions are supposed to be inlined, so there isn't much point in providing an external version (except for ABI of course, but we don't need to use the dylib functions).
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Full disclosure: This isn't actually my idea. It was yours (modulo potential misunderstandings on my side). It was originally proposed back in April 2022 in https://reviews.llvm.org/D122536. Happy to adjust it however you prefer
correct
How should we ensure that the functions are still emitted as part of the dylib? Currently I rely on
_LIBCPP_EXPORTED_FROM_LIB_INLINEABLE
to be markedinline
in the headers but as non-inline in the dylib. By marking it non-inline in the dylib, I ensure that the compiler actually emits code for it. If I would mark theminline
also in the dylib, the compiler wouldn't actually emit any code, since the functions are never called / instantiated by the dylibRight, I think we can let the compiler choose freely to either use the inlined or the dylib-provided version. This means we might not need
[[gnu::inline]]
/__attribute__((__gnu_inline__))
.I used it primarily because you proposed its usage back in April 2022 in https://reviews.llvm.org/D122536. It provides a slight benefit that the linker has less work to do (it doesn't have to discard many duplicated definitions of the same inline function). Not sure if we consider this to be worth it, though 🤷