Skip to content

runtime: return the argument from swift_retain family of functions #11986

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

Merged
merged 2 commits into from
Sep 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions include/swift/Runtime/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@

#endif

// The runtime implementation uses the preserve_most convention to save
// registers spills on the hot path.
#if __has_attribute(preserve_most) && \
(defined(__aarch64__) || defined(__x86_64__))
#define SWIFT_CC_PreserveMost __attribute__((preserve_most))
#else
#define SWIFT_CC_PreserveMost
#endif

// Generates a name of the runtime entry's implementation by
// adding an underscore as a prefix and a suffix.
#define SWIFT_RT_ENTRY_IMPL(Name) _##Name##_
Expand Down
61 changes: 33 additions & 28 deletions include/swift/Runtime/HeapObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ void swift_slowDealloc(void *ptr, size_t bytes, size_t alignMask)
///
/// \param object - may be null, in which case this is a no-op
///
/// \return object - we return the object because this enables tail call
/// optimization and the argument register to be live through the call on
/// architectures whose argument and return register is the same register.
///
/// POSSIBILITIES: We may end up wanting a bunch of different variants:
/// - the general version which correctly handles null values, swift
/// objects, and ObjC objects
Expand All @@ -213,34 +217,35 @@ void swift_slowDealloc(void *ptr, size_t bytes, size_t alignMask)
/// It may also prove worthwhile to have this use a custom CC
/// which preserves a larger set of registers.
SWIFT_RT_ENTRY_VISIBILITY
void swift_retain(HeapObject *object)
HeapObject *swift_retain(HeapObject *object)
SWIFT_CC(RegisterPreservingCC);

SWIFT_RUNTIME_EXPORT
void (*SWIFT_CC(RegisterPreservingCC) _swift_retain)(HeapObject *object);
HeapObject *(*SWIFT_CC(RegisterPreservingCC) _swift_retain)(HeapObject *object);

SWIFT_RT_ENTRY_VISIBILITY
void swift_retain_n(HeapObject *object, uint32_t n)
HeapObject *swift_retain_n(HeapObject *object, uint32_t n)
SWIFT_CC(RegisterPreservingCC);

SWIFT_RUNTIME_EXPORT
void (*SWIFT_CC(RegisterPreservingCC) _swift_retain_n)(HeapObject *object,
uint32_t n);
HeapObject *(*SWIFT_CC(RegisterPreservingCC)
_swift_retain_n)(HeapObject *object, uint32_t n);

SWIFT_RT_ENTRY_VISIBILITY
void swift_nonatomic_retain(HeapObject *object)
HeapObject *swift_nonatomic_retain(HeapObject *object)
SWIFT_CC(RegisterPreservingCC);

SWIFT_RUNTIME_EXPORT
void (*SWIFT_CC(RegisterPreservingCC) _swift_nonatomic_retain)(HeapObject *object);
HeapObject *(*SWIFT_CC(RegisterPreservingCC)
_swift_nonatomic_retain)(HeapObject *object);

SWIFT_RT_ENTRY_VISIBILITY
void swift_nonatomic_retain_n(HeapObject *object, uint32_t n)
HeapObject* swift_nonatomic_retain_n(HeapObject *object, uint32_t n)
SWIFT_CC(RegisterPreservingCC);

SWIFT_RUNTIME_EXPORT
void (*SWIFT_CC(RegisterPreservingCC) _swift_nonatomic_retain_n)(HeapObject *object,
uint32_t n);
HeapObject *(*SWIFT_CC(RegisterPreservingCC)
_swift_nonatomic_retain_n)(HeapObject *object, uint32_t n);

/// Atomically increments the reference count of an object, unless it has
/// already been destroyed. Returns nil if the object is dead.
Expand Down Expand Up @@ -525,7 +530,7 @@ struct UnownedReference {

/// Increment the unowned retain count.
SWIFT_RT_ENTRY_VISIBILITY
void swift_unownedRetain(HeapObject *value)
HeapObject *swift_unownedRetain(HeapObject *value)
SWIFT_CC(RegisterPreservingCC);

/// Decrement the unowned retain count.
Expand All @@ -535,7 +540,7 @@ void swift_unownedRelease(HeapObject *value)

/// Increment the unowned retain count.
SWIFT_RT_ENTRY_VISIBILITY
void swift_nonatomic_unownedRetain(HeapObject *value)
void *swift_nonatomic_unownedRetain(HeapObject *value)
SWIFT_CC(RegisterPreservingCC);

/// Decrement the unowned retain count.
Expand All @@ -545,7 +550,7 @@ void swift_nonatomic_unownedRelease(HeapObject *value)

/// Increment the unowned retain count by n.
SWIFT_RT_ENTRY_VISIBILITY
void swift_unownedRetain_n(HeapObject *value, int n)
HeapObject *swift_unownedRetain_n(HeapObject *value, int n)
SWIFT_CC(RegisterPreservingCC);

/// Decrement the unowned retain count by n.
Expand All @@ -555,7 +560,7 @@ void swift_unownedRelease_n(HeapObject *value, int n)

/// Increment the unowned retain count by n.
SWIFT_RT_ENTRY_VISIBILITY
void swift_nonatomic_unownedRetain_n(HeapObject *value, int n)
HeapObject *swift_nonatomic_unownedRetain_n(HeapObject *value, int n)
SWIFT_CC(RegisterPreservingCC);

/// Decrement the unowned retain count by n.
Expand All @@ -566,13 +571,13 @@ void swift_nonatomic_unownedRelease_n(HeapObject *value, int n)
/// Increment the strong retain count of an object, aborting if it has
/// been deallocated.
SWIFT_RT_ENTRY_VISIBILITY
void swift_unownedRetainStrong(HeapObject *value)
HeapObject *swift_unownedRetainStrong(HeapObject *value)
SWIFT_CC(RegisterPreservingCC);

/// Increment the strong retain count of an object, aborting if it has
/// been deallocated.
SWIFT_RT_ENTRY_VISIBILITY
void swift_nonatomic_unownedRetainStrong(HeapObject *value)
HeapObject *swift_nonatomic_unownedRetainStrong(HeapObject *value)
SWIFT_CC(RegisterPreservingCC);

/// Increment the strong retain count of an object which may have been
Expand Down Expand Up @@ -770,46 +775,46 @@ void *swift_nonatomic_bridgeObjectRetain_n(void *value, int n)
/// Increment the strong retain count of an object which might not be a native
/// Swift object.
SWIFT_RUNTIME_EXPORT
void swift_unknownRetain(void *value)
void *swift_unknownRetain(void *value)
SWIFT_CC(DefaultCC);
/// Increment the strong retain count of an object which might not be a native
/// Swift object by n.
SWIFT_RUNTIME_EXPORT
void swift_unknownRetain_n(void *value, int n)
void *swift_unknownRetain_n(void *value, int n)
SWIFT_CC(DefaultCC);

/// Increment the strong retain count of an object which might not be a native
/// Swift object.
SWIFT_RUNTIME_EXPORT
void swift_nonatomic_unknownRetain(void *value)
void *swift_nonatomic_unknownRetain(void *value)
SWIFT_CC(DefaultCC);
/// Increment the strong retain count of an object which might not be a native
/// Swift object by n.
SWIFT_RUNTIME_EXPORT
void swift_nonatomic_unknownRetain_n(void *value, int n)
void *swift_nonatomic_unknownRetain_n(void *value, int n)
SWIFT_CC(DefaultCC);


#else

static inline void swift_unknownRetain(void *value)
static inline void *swift_unknownRetain(void *value)
SWIFT_CC(DefaultCC) {
swift_retain(static_cast<HeapObject *>(value));
return swift_retain(static_cast<HeapObject *>(value));
}

static inline void swift_unknownRetain_n(void *value, int n)
static inline void *swift_unknownRetain_n(void *value, int n)
SWIFT_CC(DefaultCC) {
swift_retain_n(static_cast<HeapObject *>(value), n);
return swift_retain_n(static_cast<HeapObject *>(value), n);
}

static inline void swift_nonatomic_unknownRetain(void *value)
static inline void *swift_nonatomic_unknownRetain(void *value)
SWIFT_CC(DefaultCC) {
swift_nonatomic_retain(static_cast<HeapObject *>(value));
return swift_nonatomic_retain(static_cast<HeapObject *>(value));
}

static inline void swift_nonatomic_unknownRetain_n(void *value, int n)
static inline void *swift_nonatomic_unknownRetain_n(void *value, int n)
SWIFT_CC(DefaultCC) {
swift_nonatomic_retain_n(static_cast<HeapObject *>(value), n);
return swift_nonatomic_retain_n(static_cast<HeapObject *>(value), n);
}


Expand Down
6 changes: 3 additions & 3 deletions include/swift/Runtime/InstrumentsSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ SWIFT_RUNTIME_EXPORT
BoxPair::Return (*_swift_allocBox)(Metadata const *type);

SWIFT_RUNTIME_EXPORT
void (*_swift_retain)(HeapObject *object);
HeapObject *(*_swift_retain)(HeapObject *object);
SWIFT_RUNTIME_EXPORT
void (*_swift_retain_n)(HeapObject *object, uint32_t n);
HeapObject *(*_swift_retain_n)(HeapObject *object, uint32_t n);
SWIFT_RUNTIME_EXPORT
void (*_swift_nonatomic_retain)(HeapObject *object);
HeapObject *(*_swift_nonatomic_retain)(HeapObject *object);
SWIFT_RUNTIME_EXPORT
HeapObject *(*_swift_tryRetain)(HeapObject *object);
SWIFT_RUNTIME_EXPORT
Expand Down
Loading