Skip to content

Commit 6efd52d

Browse files
authored
Merge pull request #35122 from mikeash/refcount-always-inline
[Runtime] Add SWIFT_ALWAYS_INLINE to various refcounting helpers.
2 parents 1179136 + 4054521 commit 6efd52d

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

stdlib/public/SwiftShims/RefCount.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,7 @@ class RefCounts {
793793
}
794794

795795
// Increment the reference count.
796+
SWIFT_ALWAYS_INLINE
796797
void increment(uint32_t inc = 1) {
797798
auto oldbits = refCounts.load(SWIFT_MEMORY_ORDER_CONSUME);
798799

@@ -815,6 +816,7 @@ class RefCounts {
815816
std::memory_order_relaxed));
816817
}
817818

819+
SWIFT_ALWAYS_INLINE
818820
void incrementNonAtomic(uint32_t inc = 1) {
819821
auto oldbits = refCounts.load(SWIFT_MEMORY_ORDER_CONSUME);
820822

@@ -835,6 +837,7 @@ class RefCounts {
835837
}
836838

837839
// Increment the reference count, unless the object is deiniting.
840+
SWIFT_ALWAYS_INLINE
838841
bool tryIncrement() {
839842
auto oldbits = refCounts.load(SWIFT_MEMORY_ORDER_CONSUME);
840843
RefCountBits newbits;
@@ -854,6 +857,7 @@ class RefCounts {
854857
return true;
855858
}
856859

860+
SWIFT_ALWAYS_INLINE
857861
bool tryIncrementNonAtomic() {
858862
auto oldbits = refCounts.load(SWIFT_MEMORY_ORDER_CONSUME);
859863
if (!oldbits.hasSideTable() && oldbits.getIsDeiniting())
@@ -896,6 +900,7 @@ class RefCounts {
896900
// object as deiniting.
897901
//
898902
// Precondition: the reference count must be 1
903+
SWIFT_ALWAYS_INLINE
899904
void decrementFromOneNonAtomic() {
900905
auto bits = refCounts.load(SWIFT_MEMORY_ORDER_CONSUME);
901906
if (bits.isImmortal(true)) {
@@ -1078,6 +1083,7 @@ class RefCounts {
10781083
// Deinit is optionally handled directly instead of always deferring to
10791084
// the caller because the compiler can optimize this arrangement better.
10801085
template <PerformDeinit performDeinit>
1086+
SWIFT_ALWAYS_INLINE
10811087
bool doDecrement(uint32_t dec) {
10821088
auto oldbits = refCounts.load(SWIFT_MEMORY_ORDER_CONSUME);
10831089
RefCountBits newbits;

stdlib/public/runtime/HeapObject.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ using namespace swift;
6060

6161
/// Returns true if the pointer passed to a native retain or release is valid.
6262
/// If false, the operation should immediately return.
63+
SWIFT_ALWAYS_INLINE
6364
static inline bool isValidPointerForNativeRetain(const void *p) {
6465
#if defined(__x86_64__) || defined(__arm64__) || defined(__aarch64__) || defined(_M_ARM64) || defined(__s390x__) || (defined(__powerpc64__) && defined(__LITTLE_ENDIAN__))
6566
// On these platforms, except s390x, the upper half of address space is reserved for the
@@ -330,6 +331,7 @@ HeapObject *swift::swift_allocEmptyBox() {
330331
extern "C" SWIFT_LIBRARY_VISIBILITY SWIFT_NOINLINE SWIFT_USED void
331332
_swift_release_dealloc(HeapObject *object);
332333

334+
SWIFT_ALWAYS_INLINE
333335
static HeapObject *_swift_retain_(HeapObject *object) {
334336
SWIFT_RT_TRACK_INVOCATION(object, swift_retain);
335337
if (isValidPointerForNativeRetain(object))
@@ -356,6 +358,7 @@ HeapObject *swift::swift_nonatomic_retain(HeapObject *object) {
356358
return object;
357359
}
358360

361+
SWIFT_ALWAYS_INLINE
359362
static HeapObject *_swift_retain_n_(HeapObject *object, uint32_t n) {
360363
SWIFT_RT_TRACK_INVOCATION(object, swift_retain_n);
361364
if (isValidPointerForNativeRetain(object))
@@ -382,6 +385,7 @@ HeapObject *swift::swift_nonatomic_retain_n(HeapObject *object, uint32_t n) {
382385
return object;
383386
}
384387

388+
SWIFT_ALWAYS_INLINE
385389
static void _swift_release_(HeapObject *object) {
386390
SWIFT_RT_TRACK_INVOCATION(object, swift_release);
387391
if (isValidPointerForNativeRetain(object))
@@ -406,6 +410,7 @@ void swift::swift_nonatomic_release(HeapObject *object) {
406410
object->refCounts.decrementAndMaybeDeinitNonAtomic(1);
407411
}
408412

413+
SWIFT_ALWAYS_INLINE
409414
static void _swift_release_n_(HeapObject *object, uint32_t n) {
410415
SWIFT_RT_TRACK_INVOCATION(object, swift_release_n);
411416
if (isValidPointerForNativeRetain(object))
@@ -562,6 +567,7 @@ void swift::swift_nonatomic_unownedRelease_n(HeapObject *object, int n) {
562567
}
563568
}
564569

570+
SWIFT_ALWAYS_INLINE
565571
static HeapObject *_swift_tryRetain_(HeapObject *object) {
566572
SWIFT_RT_TRACK_INVOCATION(object, swift_tryRetain);
567573
if (!isValidPointerForNativeRetain(object))

0 commit comments

Comments
 (0)