Skip to content

Commit 5d3bbd3

Browse files
kateinoigakukunMaxDesiatov
authored andcommitted
Add swiftcc attribute for runtime functions called from Swift
1 parent db90ea2 commit 5d3bbd3

File tree

8 files changed

+43
-21
lines changed

8 files changed

+43
-21
lines changed

include/swift/Runtime/HeapObject.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,13 @@ void swift_nonatomic_release_n(HeapObject *object, uint32_t n);
205205

206206
// Refcounting observation hooks for memory tools. Don't use these.
207207
SWIFT_RUNTIME_EXPORT
208+
SWIFT_CC(swift)
208209
size_t swift_retainCount(HeapObject *object);
209210
SWIFT_RUNTIME_EXPORT
211+
SWIFT_CC(swift)
210212
size_t swift_unownedRetainCount(HeapObject *object);
211213
SWIFT_RUNTIME_EXPORT
214+
SWIFT_CC(swift)
212215
size_t swift_weakRetainCount(HeapObject *object);
213216

214217
/// Is this pointer a non-null unique reference to an object?

lib/IRGen/GenKeyPath.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ getLayoutFunctionForComputedComponent(IRGenModule &IGM,
281281
auto layoutFn = llvm::Function::Create(fnTy,
282282
llvm::GlobalValue::PrivateLinkage, "keypath_get_arg_layout", IGM.getModule());
283283
layoutFn->setAttributes(IGM.constructInitialAttributes());
284-
284+
layoutFn->setCallingConv(IGM.SwiftCC);
285+
285286
{
286287
IRGenFunction IGF(IGM, layoutFn);
287288
if (IGM.DebugInfo)
@@ -381,6 +382,7 @@ getWitnessTableForComputedComponent(IRGenModule &IGM,
381382
/*vararg*/ false);
382383
auto destroyFn = llvm::Function::Create(destroyType,
383384
llvm::GlobalValue::PrivateLinkage, "keypath_destroy", IGM.getModule());
385+
destroyFn->setCallingConv(IGM.SwiftCC);
384386
destroy = destroyFn;
385387
destroyFn->setAttributes(IGM.constructInitialAttributes());
386388

@@ -430,6 +432,7 @@ getWitnessTableForComputedComponent(IRGenModule &IGM,
430432
/*vararg*/ false);
431433
auto copyFn = llvm::Function::Create(copyType,
432434
llvm::GlobalValue::PrivateLinkage, "keypath_copy", IGM.getModule());
435+
copyFn->setCallingConv(IGM.SwiftCC);
433436
copy = copyFn;
434437
copyFn->setAttributes(IGM.constructInitialAttributes());
435438

@@ -545,7 +548,8 @@ getInitializerForComputedComponent(IRGenModule &IGM,
545548
auto initFn = llvm::Function::Create(fnTy,
546549
llvm::GlobalValue::PrivateLinkage, "keypath_arg_init", IGM.getModule());
547550
initFn->setAttributes(IGM.constructInitialAttributes());
548-
551+
initFn->setCallingConv(IGM.SwiftCC);
552+
549553
{
550554
IRGenFunction IGF(IGM, initFn);
551555
if (IGM.DebugInfo)

stdlib/public/SwiftShims/HeapObject.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,25 @@ struct HeapObject {
8181
#ifdef __cplusplus
8282
extern "C" {
8383
#endif
84+
#if __has_attribute(swiftcall)
85+
#define SWIFT_CC_swift __attribute__((swiftcall))
86+
#else
87+
#define SWIFT_CC_swift
88+
#endif
8489

8590
SWIFT_RUNTIME_STDLIB_API
8691
void _swift_instantiateInertHeapObject(void *address,
8792
const HeapMetadata *metadata);
8893

94+
SWIFT_CC_swift
8995
SWIFT_RUNTIME_STDLIB_API
9096
__swift_size_t swift_retainCount(HeapObject *obj);
9197

98+
SWIFT_CC_swift
9299
SWIFT_RUNTIME_STDLIB_API
93100
__swift_size_t swift_unownedRetainCount(HeapObject *obj);
94101

102+
SWIFT_CC_swift
95103
SWIFT_RUNTIME_STDLIB_API
96104
__swift_size_t swift_weakRetainCount(HeapObject *obj);
97105

stdlib/public/runtime/Demangle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ swift::_swift_buildDemanglingForMetadata(const Metadata *type,
700700
//// define what these will be.
701701
/// \returns the demangled name. Returns nullptr if the input String is not a
702702
/// Swift mangled name.
703-
SWIFT_RUNTIME_EXPORT
703+
SWIFT_CC(swift)
704704
char *swift_demangle(const char *mangledName,
705705
size_t mangledNameLength,
706706
char *outputBuffer,

stdlib/public/runtime/HeapObject.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ class BoxCacheEntry {
252252

253253
static SimpleGlobalCache<BoxCacheEntry, BoxesTag> Boxes;
254254

255+
SWIFT_CC(swift)
255256
BoxPair swift::swift_makeBoxUnique(OpaqueValue *buffer, const Metadata *type,
256257
size_t alignMask) {
257258
auto *inlineBuffer = reinterpret_cast<ValueBuffer*>(buffer);
@@ -277,6 +278,7 @@ BoxPair swift::swift_makeBoxUnique(OpaqueValue *buffer, const Metadata *type,
277278
}
278279
}
279280

281+
SWIFT_CC(swift)
280282
BoxPair swift::swift_allocBox(const Metadata *type) {
281283
// Get the heap metadata for the box.
282284
auto metadata = &Boxes.getOrInsert(type).first->Data;
@@ -439,16 +441,19 @@ void swift::swift_nonatomic_release_n(HeapObject *object, uint32_t n) {
439441
object->refCounts.decrementAndMaybeDeinitNonAtomic(n);
440442
}
441443

444+
SWIFT_CC(swift)
442445
size_t swift::swift_retainCount(HeapObject *object) {
443446
if (isValidPointerForNativeRetain(object))
444447
return object->refCounts.getCount();
445448
return 0;
446449
}
447450

451+
SWIFT_CC(swift)
448452
size_t swift::swift_unownedRetainCount(HeapObject *object) {
449453
return object->refCounts.getUnownedCount();
450454
}
451455

456+
SWIFT_CC(swift)
452457
size_t swift::swift_weakRetainCount(HeapObject *object) {
453458
return object->refCounts.getWeakCount();
454459
}

stdlib/public/runtime/Numeric.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ static T convert(IntegerLiteral value) {
5050
return result;
5151
}
5252

53+
SWIFT_CC(swift)
5354
float swift::swift_intToFloat32(IntegerLiteral value) {
5455
return convert<float>(value);
5556
}
5657

58+
SWIFT_CC(swift)
5759
double swift::swift_intToFloat64(IntegerLiteral value) {
5860
return convert<double>(value);
5961
}

stdlib/public/runtime/RuntimeInvocationsTracking.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ static uint16_t RuntimeFunctionCountersOffsets[] = {
128128
/// Public APIs
129129

130130
/// Get the runtime object state associated with an object.
131-
void _swift_getObjectRuntimeFunctionCounters(
131+
SWIFT_CC(swift) void _swift_getObjectRuntimeFunctionCounters(
132132
HeapObject *object, RuntimeFunctionCountersState *result) {
133133
auto &theSentinel = RuntimeObjectStateCache.get();
134134
StaticScopedReadLock lock(theSentinel.Lock);
@@ -137,7 +137,7 @@ void _swift_getObjectRuntimeFunctionCounters(
137137

138138
/// Set the runtime object state associated with an object from a provided
139139
/// state.
140-
void _swift_setObjectRuntimeFunctionCounters(
140+
SWIFT_CC(swift) void _swift_setObjectRuntimeFunctionCounters(
141141
HeapObject *object, RuntimeFunctionCountersState *state) {
142142
auto &theSentinel = RuntimeObjectStateCache.get();
143143
StaticScopedWriteLock lock(theSentinel.Lock);
@@ -146,14 +146,14 @@ void _swift_setObjectRuntimeFunctionCounters(
146146

147147
/// Get the global runtime state containing the total numbers of invocations for
148148
/// each runtime function of interest.
149-
void _swift_getGlobalRuntimeFunctionCounters(
149+
SWIFT_CC(swift) void _swift_getGlobalRuntimeFunctionCounters(
150150
RuntimeFunctionCountersState *result) {
151151
StaticScopedReadLock lock(RuntimeGlobalFunctionCountersState.Lock);
152152
*result = RuntimeGlobalFunctionCountersState.State;
153153
}
154154

155155
/// Set the global runtime state of function pointers from a provided state.
156-
void _swift_setGlobalRuntimeFunctionCounters(
156+
SWIFT_CC(swift) void _swift_setGlobalRuntimeFunctionCounters(
157157
RuntimeFunctionCountersState *state) {
158158
StaticScopedWriteLock lock(RuntimeGlobalFunctionCountersState.Lock);
159159
RuntimeGlobalFunctionCountersState.State = *state;
@@ -162,19 +162,19 @@ void _swift_setGlobalRuntimeFunctionCounters(
162162
/// Return the names of the runtime functions being tracked.
163163
/// Their order is the same as the order of the counters in the
164164
/// RuntimeObjectState structure. All these strings are null terminated.
165-
const char **_swift_getRuntimeFunctionNames() {
165+
SWIFT_CC(swift) const char **_swift_getRuntimeFunctionNames() {
166166
return RuntimeFunctionNames;
167167
}
168168

169169
/// Return the offsets of the runtime function counters being tracked.
170170
/// Their order is the same as the order of the counters in the
171171
/// RuntimeObjectState structure.
172-
const uint16_t *_swift_getRuntimeFunctionCountersOffsets() {
172+
SWIFT_CC(swift) const uint16_t *_swift_getRuntimeFunctionCountersOffsets() {
173173
return RuntimeFunctionCountersOffsets;
174174
}
175175

176176
/// Return the number of runtime functions being tracked.
177-
uint64_t _swift_getNumRuntimeFunctionCounters() {
177+
SWIFT_CC(swift) uint64_t _swift_getNumRuntimeFunctionCounters() {
178178
return ID_LastRuntimeFunctionName;
179179
}
180180

@@ -202,15 +202,15 @@ void _swift_dumpObjectsRuntimeFunctionPointers() {
202202

203203
/// Set mode for global runtime function counters.
204204
/// Return the old value of this flag.
205-
int _swift_setGlobalRuntimeFunctionCountersMode(int mode) {
205+
SWIFT_CC(swift) int _swift_setGlobalRuntimeFunctionCountersMode(int mode) {
206206
int oldMode = UpdateGlobalRuntimeFunctionCounters;
207207
UpdateGlobalRuntimeFunctionCounters = mode ? 1 : 0;
208208
return oldMode;
209209
}
210210

211211
/// Set mode for per object runtime function counters.
212212
/// Return the old value of this flag.
213-
int _swift_setPerObjectRuntimeFunctionCountersMode(int mode) {
213+
SWIFT_CC(swift) int _swift_setPerObjectRuntimeFunctionCountersMode(int mode) {
214214
int oldMode = UpdatePerObjectRuntimeFunctionCounters;
215215
UpdatePerObjectRuntimeFunctionCounters = mode ? 1 : 0;
216216
return oldMode;

stdlib/public/runtime/RuntimeInvocationsTracking.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,47 +61,47 @@ using RuntimeFunctionCountersUpdateHandler =
6161

6262
/// Get the runtime object state associated with an object and store it
6363
/// into the result.
64-
SWIFT_RUNTIME_EXPORT void
64+
SWIFT_CC(swift) SWIFT_RUNTIME_EXPORT void
6565
_swift_getObjectRuntimeFunctionCounters(HeapObject *object,
6666
RuntimeFunctionCountersState *result);
6767

6868
/// Get the global runtime state containing the total numbers of invocations for
6969
/// each runtime function of interest and store it into the result.
70-
SWIFT_RUNTIME_EXPORT void _swift_getGlobalRuntimeFunctionCounters(
70+
SWIFT_CC(swift) SWIFT_RUNTIME_EXPORT void _swift_getGlobalRuntimeFunctionCounters(
7171
swift::RuntimeFunctionCountersState *result);
7272

7373
/// Return the names of the runtime functions being tracked.
7474
/// Their order is the same as the order of the counters in the
7575
/// RuntimeObjectState structure.
76-
SWIFT_RUNTIME_EXPORT const char **_swift_getRuntimeFunctionNames();
76+
SWIFT_CC(swift) SWIFT_RUNTIME_EXPORT const char **_swift_getRuntimeFunctionNames();
7777

7878
/// Return the offsets of the runtime function counters being tracked.
7979
/// Their order is the same as the order of the counters in the
8080
/// RuntimeFunctionCountersState structure.
81-
SWIFT_RUNTIME_EXPORT const uint16_t *_swift_getRuntimeFunctionCountersOffsets();
81+
SWIFT_CC(swift) SWIFT_RUNTIME_EXPORT const uint16_t *_swift_getRuntimeFunctionCountersOffsets();
8282

8383
/// Return the number of runtime functions being tracked.
84-
SWIFT_RUNTIME_EXPORT uint64_t _swift_getNumRuntimeFunctionCounters();
84+
SWIFT_CC(swift) SWIFT_RUNTIME_EXPORT uint64_t _swift_getNumRuntimeFunctionCounters();
8585

8686
/// Dump all per-object runtime function pointers.
8787
SWIFT_RUNTIME_EXPORT void _swift_dumpObjectsRuntimeFunctionPointers();
8888

8989
/// Set mode for global runtime function counters.
9090
/// Return the old value of this flag.
91-
SWIFT_RUNTIME_EXPORT int
91+
SWIFT_CC(swift) SWIFT_RUNTIME_EXPORT int
9292
_swift_setPerObjectRuntimeFunctionCountersMode(int mode);
9393

9494
/// Set mode for per object runtime function counters.
9595
/// Return the old value of this flag.
96-
SWIFT_RUNTIME_EXPORT int _swift_setGlobalRuntimeFunctionCountersMode(int mode);
96+
SWIFT_CC(swift) SWIFT_RUNTIME_EXPORT int _swift_setGlobalRuntimeFunctionCountersMode(int mode);
9797

9898
/// Set the global runtime state of function pointers from a provided state.
99-
SWIFT_RUNTIME_EXPORT void _swift_setGlobalRuntimeFunctionCounters(
99+
SWIFT_CC(swift) SWIFT_RUNTIME_EXPORT void _swift_setGlobalRuntimeFunctionCounters(
100100
swift::RuntimeFunctionCountersState *state);
101101

102102
/// Set the runtime object state associated with an object from a provided
103103
/// state.
104-
SWIFT_RUNTIME_EXPORT void
104+
SWIFT_CC(swift) SWIFT_RUNTIME_EXPORT void
105105
_swift_setObjectRuntimeFunctionCounters(HeapObject *object,
106106
RuntimeFunctionCountersState *state);
107107

0 commit comments

Comments
 (0)