Skip to content

Commit ae983d8

Browse files
committed
Add Synchronization module
1 parent f365316 commit ae983d8

File tree

7 files changed

+150
-0
lines changed

7 files changed

+150
-0
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,10 @@ option(SWIFT_ENABLE_EXPERIMENTAL_OBSERVATION
647647
"Enable build of the Swift observation module"
648648
FALSE)
649649

650+
option(SWIFT_ENABLE_SYNCHRONIZATION
651+
"Enable build of the Swift Synchronization module"
652+
FALSE)
653+
650654
option(SWIFT_ENABLE_DISPATCH
651655
"Enable use of libdispatch"
652656
TRUE)
@@ -1222,6 +1226,7 @@ if(SWIFT_BUILD_STDLIB OR SWIFT_BUILD_SDK_OVERLAY)
12221226
message(STATUS "Backtracing Support: ${SWIFT_ENABLE_BACKTRACING}")
12231227
message(STATUS "Unicode Support: ${SWIFT_STDLIB_ENABLE_UNICODE_DATA}")
12241228
message(STATUS "Observation Support: ${SWIFT_ENABLE_EXPERIMENTAL_OBSERVATION}")
1229+
message(STATUS "Synchronization Support: ${SWIFT_ENABLE_SYNCHRONIZATION}")
12251230
message(STATUS "")
12261231
else()
12271232
message(STATUS "Not building Swift standard library, SDK overlays, and runtime")

stdlib/cmake/modules/SwiftSource.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,10 @@ function(_add_target_variant_swift_compile_flags
321321
list(APPEND result "-D" "SWIFT_ENABLE_EXPERIMENTAL_OBSERVATION")
322322
endif()
323323

324+
if (SWIFT_ENABLE_SYNCHRONIZATION)
325+
list(APPEND result "-D" "SWIFT_ENABLE_SYNCHRONIZATION")
326+
endif()
327+
324328
if(SWIFT_STDLIB_OS_VERSIONING)
325329
list(APPEND result "-D" "SWIFT_RUNTIME_OS_VERSIONING")
326330
endif()

stdlib/public/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ if(SWIFT_BUILD_STDLIB AND NOT SWIFT_STDLIB_BUILD_ONLY_CORE_MODULES)
245245
if(SWIFT_ENABLE_BACKTRACING)
246246
add_subdirectory(Backtracing)
247247
endif()
248+
249+
if(SWIFT_ENABLE_SYNCHRONIZATION)
250+
add_subdirectory(Synchronization)
251+
endif()
248252
endif()
249253

250254
if(SWIFT_BUILD_REMOTE_MIRROR)

utils/SwiftAtomics.py

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#===-----------------------------------------------------------------------===//
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2023 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See https://swift.org/LICENSE.txt for license information
9+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
#
11+
#===-----------------------------------------------------------------------===//
12+
13+
atomicTypes = [
14+
# Swift Size Alignment Builtin
15+
("AtomicInt8Storage", "8", "1", "Builtin.Int8"),
16+
("AtomicInt16Storage", "16", "2", "Builtin.Int16"),
17+
("AtomicInt32Storage", "32", "4", "Builtin.Int32"),
18+
("AtomicInt64Storage", "64", "8", "Builtin.Int64"),
19+
("AtomicInt128Storage", "128", "16", "Builtin.Int128"),
20+
]
21+
22+
intTypes = [
23+
# Swift Storage Type
24+
("Int8", "AtomicInt8Storage", "Int8"),
25+
("Int16", "AtomicInt16Storage", "Int16"),
26+
("Int32", "AtomicInt32Storage", "Int32"),
27+
("Int64", "AtomicInt64Storage", "Int64"),
28+
29+
# We handle the word type's storage in source.
30+
("Int", "", "Word"),
31+
32+
("UInt8", "AtomicInt8Storage", "Int8"),
33+
("UInt16", "AtomicInt16Storage", "Int16"),
34+
("UInt32", "AtomicInt32Storage", "Int32"),
35+
("UInt64", "AtomicInt64Storage", "Int64"),
36+
37+
# We handle the word type's storage in source.
38+
("UInt", "", "Word"),
39+
]
40+
41+
loadOrderings = [
42+
# Swift API name doc name LLVM name
43+
("relaxed", "Relaxed", "relaxed", "monotonic"),
44+
("acquiring", "Acquiring", "acquiring", "acquire"),
45+
("sequentiallyConsistent", "SequentiallyConsistent", "sequentially consistent", "seqcst")
46+
]
47+
48+
storeOrderings = [
49+
# Swift enum case, API name, doc name, LLVM name
50+
("relaxed", "Relaxed", "relaxed", "monotonic"),
51+
("releasing", "Releasing", "releasing", "release"),
52+
("sequentiallyConsistent", "SequentiallyConsistent", "sequentially consistent", "seqcst")
53+
]
54+
55+
updateOrderings = [
56+
# Swift enum case, API name, doc name, LLVM name, failure name
57+
("relaxed", "Relaxed", "relaxed", "monotonic", "monotonic"),
58+
("acquiring", "Acquiring", "acquiring", "acquire", "acquire"),
59+
("releasing", "Releasing", "releasing", "release", "monotonic"),
60+
("acquiringAndReleasing", "AcquiringAndReleasing", "acquiring-and-releasing", "acqrel", "acquire"),
61+
("sequentiallyConsistent", "SequentiallyConsistent", "sequentially consistent", "seqcst", "seqcst"),
62+
]
63+
64+
integerOperations = [
65+
# Swift name, llvm name, operator, label, doc name
66+
("WrappingIncrement", "add", "&+", "by", "wrapping add"),
67+
("WrappingDecrement", "sub", "&-", "by", "wrapping subtract"),
68+
("BitwiseAnd", "and", "&", "with", "bitwise AND"),
69+
("BitwiseOr", "or", "|", "with", "bitwise OR"),
70+
("BitwiseXor", "xor", "^", "with", "bitwise XOR"),
71+
72+
# These two are handled specially in source.
73+
("Min", "min", "", "with", "minimum"),
74+
("Max", "max", "", "with", "maximum")
75+
]
76+
77+
boolOperations = [
78+
# Swift name, llvm name, operator, label, doc
79+
("LogicalAnd", "and", "&&", "with", "logical AND"),
80+
("LogicalOr", "or", "||", "with", "logical OR"),
81+
("LogicalXor", "xor", "!=", "with", "logical XOR")
82+
]
83+
84+
# LLVM doesn't support arbitrary ordering combinations yet, so for the
85+
# two-ordering cmpxchg variants we need to upgrade the success
86+
# ordering when necessary so that it is at least as "strong" as the
87+
# failure case. This function implements that mapping.
88+
#
89+
# See llvm/Support/AtomicOrdering.h
90+
def actualOrders(success, failure):
91+
def max(success, failure):
92+
if failure == "acquire":
93+
if success == "monotonic":
94+
return "acquire"
95+
if success == "release":
96+
return "acqrel"
97+
if failure == "seqcst":
98+
return "seqcst"
99+
return success
100+
actualSuccess = max(success, failure)
101+
return actualSuccess + "_" + failure
102+
103+
def llvmToCaseName(ordering):
104+
if ordering == "monotonic":
105+
return "relaxed"
106+
if ordering == "acquire":
107+
return "acquiring"
108+
if ordering == "release":
109+
return "releasing"
110+
if ordering == "acqrel":
111+
return "acquiringAndReleasing"
112+
if ordering == "seqcst":
113+
return "sequentiallyConsistent"
114+
115+
def atomicOperationName(intType, operation):
116+
if operation == "Min":
117+
return "umin" if intType.startswith("U") else "min"
118+
if operation == "Max":
119+
return "umax" if intType.startswith("U") else "max"
120+
return operation
121+
122+
def lowerFirst(str):
123+
return str[:1].lower() + str[1:] if str else ""

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,10 @@ def create_argument_parser():
13421342
default=True,
13431343
help='Enable experimental Swift observation.')
13441344

1345+
option('--enable-synchronization', toggle_true,
1346+
default=True,
1347+
help='Enable Swift Synchronization')
1348+
13451349
# -------------------------------------------------------------------------
13461350
in_group('Unsupported options')
13471351

utils/swift-api-dump.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ def create_parser():
106106
help='Enable experimental distributed actors.')
107107
parser.add_argument('--enable-experimental-observation', action='store_true',
108108
help='Enable experimental observation.')
109+
parser.add_argument('--enable-synchronization', action='store_true',
110+
help='Enable Synchronization.')
109111
parser.add_argument('-swift-version', metavar='N',
110112
help='the Swift version to use')
111113
parser.add_argument('-show-overlay', action='store_true',

utils/swift_build_support/swift_build_support/products/swift.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ def __init__(self, args, toolchain, source_dir, build_dir):
6565
# Add experimental observation flag.
6666
self.cmake_options.extend(self._enable_experimental_observation)
6767

68+
# Add synchronization flag.
69+
self.cmake_options.extend(self._enable_synchronization)
70+
6871
# Add static vprintf flag
6972
self.cmake_options.extend(self._enable_stdlib_static_vprintf)
7073

@@ -197,6 +200,11 @@ def _enable_experimental_observation(self):
197200
return [('SWIFT_ENABLE_EXPERIMENTAL_OBSERVATION:BOOL',
198201
self.args.enable_experimental_observation)]
199202

203+
@property
204+
def _enable_synchronization(self):
205+
return [('SWIFT_ENABLE_SYNCHRONIZATION:BOOL',
206+
self.args.enable_synchronization)]
207+
200208
@property
201209
def _enable_stdlib_static_vprintf(self):
202210
return [('SWIFT_STDLIB_STATIC_PRINT',

0 commit comments

Comments
 (0)