Skip to content

Commit 50e22f9

Browse files
committed
SIL: allow atomic operations in @_noLocks functions
#74407
1 parent e3de408 commit 50e22f9

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

lib/SIL/Utils/InstructionUtils.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -728,8 +728,7 @@ RuntimeEffect swift::getRuntimeEffect(SILInstruction *inst, SILType &impactType)
728728
case SILInstructionKind::AllocStackInst:
729729
case SILInstructionKind::AllocVectorInst:
730730
case SILInstructionKind::ProjectBoxInst:
731-
if (!cast<SingleValueInstruction>(inst)->getType().
732-
isLoadable(*inst->getFunction())) {
731+
if (cast<SingleValueInstruction>(inst)->getType().hasArchetype()) {
733732
impactType = cast<SingleValueInstruction>(inst)->getType();
734733
return RuntimeEffect::MetaData;
735734
}
@@ -1028,7 +1027,7 @@ RuntimeEffect swift::getRuntimeEffect(SILInstruction *inst, SILType &impactType)
10281027
case BuiltinValueKind::AtomicLoad:
10291028
case BuiltinValueKind::AtomicStore:
10301029
case BuiltinValueKind::AtomicRMW:
1031-
return RuntimeEffect::Locking;
1030+
return RuntimeEffect::NoEffect;
10321031
case BuiltinValueKind::DestroyArray:
10331032
return RuntimeEffect::Releasing;
10341033
case BuiltinValueKind::CopyArray:
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %target-swift-frontend -parse-as-library -disable-availability-checking -emit-sil %s -o /dev/null
2+
3+
// REQUIRES: synchronization
4+
5+
import Synchronization
6+
7+
// Check that atomics work in no-locks mode.
8+
9+
@_noLocks
10+
func testFence() {
11+
atomicMemoryFence(ordering: .acquiring)
12+
atomicMemoryFence(ordering: .releasing)
13+
atomicMemoryFence(ordering: .acquiringAndReleasing)
14+
atomicMemoryFence(ordering: .sequentiallyConsistent)
15+
}
16+
17+
@_noLocks
18+
func testLoadStore() -> Int {
19+
let x = Atomic(0)
20+
x.store(27, ordering: .relaxed)
21+
x.compareExchange(expected: 27, desired: 42, successOrdering: .relaxed, failureOrdering: .relaxed)
22+
return x.load(ordering: .acquiring)
23+
}
24+
25+
@_noLocks
26+
func testRMW(_ b: Bool) -> (Bool, Bool) {
27+
let x = Atomic(false)
28+
return x.logicalOr(true, ordering: .relaxed)
29+
}
30+

0 commit comments

Comments
 (0)