Skip to content

Commit ca87af1

Browse files
authored
Merge pull request #32705 from apple/apple-silicon-master
[master] Apple Silicon support
2 parents 8a1f2c6 + bee7ba2 commit ca87af1

File tree

98 files changed

+1028
-278
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+1028
-278
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,12 @@ if(SWIFT_PATH_TO_CMARK_BUILD)
458458
endif()
459459
message(STATUS "")
460460

461+
if("${SWIFT_NATIVE_LLVM_TOOLS_PATH}" STREQUAL "")
462+
set(SWIFT_CROSS_COMPILING FALSE)
463+
else()
464+
set(SWIFT_CROSS_COMPILING TRUE)
465+
endif()
466+
461467
include(SwiftSharedCMakeConfig)
462468

463469
# NOTE: We include this before SwiftComponents as it relies on some LLVM CMake

benchmark/cmake/modules/AddSwiftBenchmarkSuite.cmake

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ macro(configure_build)
105105
endmacro()
106106

107107
macro(configure_sdks_darwin)
108-
set(macosx_arch "x86_64")
108+
set(macosx_arch "x86_64" "arm64")
109109
set(iphoneos_arch "arm64" "arm64e" "armv7")
110110
set(appletvos_arch "arm64")
111111
set(watchos_arch "armv7k")
@@ -609,11 +609,7 @@ function (swift_benchmark_compile_archopts)
609609

610610
if(is_darwin)
611611
# If host == target.
612-
if("${BENCH_COMPILE_ARCHOPTS_PLATFORM}" STREQUAL "macosx")
613-
set(OUTPUT_EXEC "${benchmark-bin-dir}/Benchmark_${BENCH_COMPILE_ARCHOPTS_OPT}")
614-
else()
615-
set(OUTPUT_EXEC "${benchmark-bin-dir}/Benchmark_${BENCH_COMPILE_ARCHOPTS_OPT}-${target}")
616-
endif()
612+
set(OUTPUT_EXEC "${benchmark-bin-dir}/Benchmark_${BENCH_COMPILE_ARCHOPTS_OPT}-${target}")
617613
else()
618614
# If we are on Linux, we do not support cross compiling.
619615
set(OUTPUT_EXEC "${benchmark-bin-dir}/Benchmark_${BENCH_COMPILE_ARCHOPTS_OPT}")

cmake/modules/DarwinSDKs.cmake

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,34 @@ option(SWIFT_ENABLE_IOS32
44

55
if(SWIFT_ENABLE_IOS32)
66
set(SUPPORTED_IOS_ARCHS "armv7;armv7s;arm64;arm64e")
7-
set(SUPPORTED_IOS_SIMULATOR_ARCHS "i386;x86_64")
7+
set(SUPPORTED_IOS_SIMULATOR_ARCHS "i386;x86_64;arm64")
88
else()
99
set(SUPPORTED_IOS_ARCHS "arm64;arm64e")
10-
set(SUPPORTED_IOS_SIMULATOR_ARCHS "x86_64")
10+
set(SUPPORTED_IOS_SIMULATOR_ARCHS "x86_64;arm64")
1111
endif()
1212

1313
set(SUPPORTED_TVOS_ARCHS "arm64")
14-
set(SUPPORTED_TVOS_SIMULATOR_ARCHS "x86_64")
14+
set(SUPPORTED_TVOS_SIMULATOR_ARCHS "x86_64;arm64")
1515
set(SUPPORTED_WATCHOS_ARCHS "armv7k")
16-
set(SUPPORTED_WATCHOS_SIMULATOR_ARCHS "i386")
17-
set(SUPPORTED_OSX_ARCHS "x86_64")
16+
set(SUPPORTED_WATCHOS_SIMULATOR_ARCHS "i386;arm64")
17+
set(SUPPORTED_OSX_ARCHS "x86_64;arm64;arm64e")
18+
19+
# Get the SDK version from SDKSettings.
20+
execute_process(
21+
COMMAND "defaults" "read" "${CMAKE_OSX_SYSROOT}/SDKSettings.plist" "Version"
22+
OUTPUT_VARIABLE SWIFT_OSX_SDK_VERSION
23+
OUTPUT_STRIP_TRAILING_WHITESPACE)
24+
25+
# Remove the last component, if any. e.g. 10.15.26 -> 10.15
26+
string(REGEX REPLACE "\([0-9]*[.][0-9]*\)[.][0-9]*" "\\1"
27+
SWIFT_OSX_SDK_VERSION "${SWIFT_OSX_SDK_VERSION}")
28+
29+
if (${SWIFT_OSX_SDK_VERSION} STREQUAL "10.14" OR
30+
${SWIFT_OSX_SDK_VERSION} STREQUAL "10.15")
31+
set(SUPPORTED_OSX_ARCHS "x86_64")
32+
else()
33+
set(SUPPORTED_OSX_ARCHS "x86_64;arm64e")
34+
endif()
1835

1936
is_sdk_requested(OSX swift_build_osx)
2037
if(swift_build_osx)

cmake/modules/SwiftConfigureSDK.cmake

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,38 @@ function(_report_sdk prefix)
8585
message(STATUS "")
8686
endfunction()
8787

88+
# Remove architectures not supported by the SDK from the given list.
89+
function(remove_sdk_unsupported_archs name os sdk_path architectures_var)
90+
execute_process(COMMAND
91+
/usr/libexec/PlistBuddy -c "Print :SupportedTargets:${os}:Archs" ${sdk_path}/SDKSettings.plist
92+
OUTPUT_VARIABLE sdk_supported_archs
93+
RESULT_VARIABLE plist_error)
94+
95+
if (NOT plist_error EQUAL 0)
96+
message(STATUS "${os} SDK at ${sdk_path} does not publish its supported architectures")
97+
return()
98+
endif()
99+
100+
set(architectures)
101+
foreach(arch ${${architectures_var}})
102+
if(sdk_supported_archs MATCHES "${arch}\n")
103+
list(APPEND architectures ${arch})
104+
elseif(arch MATCHES "^armv7(s)?$" AND os STREQUAL "iphoneos")
105+
# 32-bit iOS is not listed explicitly in SDK settings.
106+
message(STATUS "Assuming ${name} SDK at ${sdk_path} supports architecture ${arch}")
107+
list(APPEND architectures ${arch})
108+
elseif(arch STREQUAL "i386" AND os STREQUAL "iphonesimulator")
109+
# 32-bit iOS simulatoris not listed explicitly in SDK settings.
110+
message(STATUS "Assuming ${name} SDK at ${sdk_path} supports architecture ${arch}")
111+
list(APPEND architectures ${arch})
112+
else()
113+
message(STATUS "${name} SDK at ${sdk_path} does not support architecture ${arch}")
114+
endif()
115+
endforeach()
116+
117+
set("${architectures_var}" ${architectures} PARENT_SCOPE)
118+
endfunction()
119+
88120
# Configure an SDK
89121
#
90122
# Usage:
@@ -164,6 +196,9 @@ macro(configure_sdk_darwin
164196
SWIFT_SDK_${prefix}_ARCHITECTURES) # result
165197
endif()
166198

199+
# Remove any architectures not supported by the SDK.
200+
remove_sdk_unsupported_archs(${name} ${xcrun_name} ${SWIFT_SDK_${prefix}_PATH} SWIFT_SDK_${prefix}_ARCHITECTURES)
201+
167202
list_intersect(
168203
"${SWIFT_DARWIN_MODULE_ARCHS}" # lhs
169204
"${architectures}" # rhs

cmake/modules/SwiftSharedCMakeConfig.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ macro(swift_common_standalone_build_config_llvm product)
5858
fix_imported_targets_for_xcode("${LLVM_EXPORTED_TARGETS}")
5959
endif()
6060

61-
if(NOT CMAKE_CROSSCOMPILING)
61+
if(NOT CMAKE_CROSSCOMPILING AND NOT SWIFT_CROSS_COMPILING)
6262
set(${product}_NATIVE_LLVM_TOOLS_PATH "${LLVM_TOOLS_BINARY_DIR}")
6363
endif()
6464

include/swift/AST/AvailabilitySpec.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,33 @@ class PlatformVersionConstraintAvailabilitySpec : public AvailabilitySpec {
6868
SourceLoc PlatformLoc;
6969

7070
llvm::VersionTuple Version;
71+
72+
// For macOS Big Sur, we canonicalize 10.16 to 11.0 for compile-time
73+
// checking since clang canonicalizes availability markup. However, to
74+
// support Beta versions of macOS Big Sur where the OS
75+
// reports 10.16 at run time, we need to compare against 10.16,
76+
//
77+
// This means for:
78+
//
79+
// if #available(macOS 10.16, *) { ... }
80+
//
81+
// we need to keep around both a canonical version for use in compile-time
82+
// checks and an uncanonicalized version for the version to actually codegen
83+
// with.
84+
llvm::VersionTuple RuntimeVersion;
85+
7186
SourceRange VersionSrcRange;
7287

7388
public:
7489
PlatformVersionConstraintAvailabilitySpec(PlatformKind Platform,
7590
SourceLoc PlatformLoc,
7691
llvm::VersionTuple Version,
92+
llvm::VersionTuple RuntimeVersion,
7793
SourceRange VersionSrcRange)
7894
: AvailabilitySpec(AvailabilitySpecKind::PlatformVersionConstraint),
7995
Platform(Platform),
8096
PlatformLoc(PlatformLoc), Version(Version),
97+
RuntimeVersion(RuntimeVersion),
8198
VersionSrcRange(VersionSrcRange) {}
8299

83100
/// The required platform.
@@ -93,6 +110,11 @@ class PlatformVersionConstraintAvailabilitySpec : public AvailabilitySpec {
93110
llvm::VersionTuple getVersion() const { return Version; }
94111
SourceRange getVersionSrcRange() const { return VersionSrcRange; }
95112

113+
// The version to be used in codegen for version comparisons at run time.
114+
// This is required to support beta versions of macOS Big Sur that
115+
// report 10.16 at run time.
116+
llvm::VersionTuple getRuntimeVersion() const { return RuntimeVersion; }
117+
96118
SourceRange getSourceRange() const;
97119

98120
void print(raw_ostream &OS, unsigned Indent) const;

include/swift/AST/PlatformKind.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "swift/Basic/LLVM.h"
2121
#include "swift/Config.h"
2222
#include "llvm/ADT/StringRef.h"
23+
#include "llvm/Support/VersionTuple.h"
2324

2425
namespace swift {
2526

@@ -65,6 +66,9 @@ PlatformKind targetPlatform(const LangOptions &LangOpts);
6566
/// an explicit attribute for the child.
6667
bool inheritsAvailabilityFromPlatform(PlatformKind Child, PlatformKind Parent);
6768

69+
llvm::VersionTuple canonicalizePlatformVersion(
70+
PlatformKind platform, const llvm::VersionTuple &version);
71+
6872
} // end namespace swift
6973

7074
#endif

include/swift/Remote/InProcessMemoryReader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class InProcessMemoryReader final : public MemoryReader {
3838
#else
3939
auto applePlatform = false;
4040
#endif
41-
#if defined(__APPLE__) && __APPLE__ && ((defined(TARGET_OS_IOS) && TARGET_OS_IOS) || (defined(TARGET_OS_IOS) && TARGET_OS_WATCH) || (defined(TARGET_OS_TV) && TARGET_OS_TV))
41+
#if defined(__APPLE__) && __APPLE__ && ((defined(TARGET_OS_IOS) && TARGET_OS_IOS) || (defined(TARGET_OS_IOS) && TARGET_OS_WATCH) || (defined(TARGET_OS_TV) && TARGET_OS_TV) || defined(__arm64__))
4242
auto iosDerivedPlatform = true;
4343
#else
4444
auto iosDerivedPlatform = false;
@@ -67,7 +67,7 @@ class InProcessMemoryReader final : public MemoryReader {
6767
case DLQ_GetObjCReservedLowBits: {
6868
auto result = static_cast<uint8_t *>(outBuffer);
6969
if (applePlatform && !iosDerivedPlatform && (sizeof(void *) == 8)) {
70-
// Obj-C reserves low bit on 64-bit macOS only.
70+
// Obj-C reserves low bit on 64-bit Intel macOS only.
7171
// Other Apple platforms don't reserve this bit (even when
7272
// running on x86_64-based simulators).
7373
*result = 1;

include/swift/SwiftRemoteMirror/SwiftRemoteMirrorLegacyInterop.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ swift_reflection_interop_minimalDataLayoutQueryFunction8(
585585
#else
586586
int applePlatform = 0;
587587
#endif
588-
#if defined(__APPLE__) && __APPLE__ && ((defined(TARGET_OS_IOS) && TARGET_OS_IOS) || (defined(TARGET_OS_IOS) && TARGET_OS_WATCH) || (defined(TARGET_OS_TV) && TARGET_OS_TV))
588+
#if defined(__APPLE__) && __APPLE__ && ((defined(TARGET_OS_IOS) && TARGET_OS_IOS) || (defined(TARGET_OS_IOS) && TARGET_OS_WATCH) || (defined(TARGET_OS_TV) && TARGET_OS_TV) || defined(__arm64__))
589589
int iosDerivedPlatform = 1;
590590
#else
591591
int iosDerivedPlatform = 0;

lib/AST/Availability.cpp

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,16 @@ AvailabilityContext ASTContext::getSwift50Availability() {
246246
return AvailabilityContext::alwaysAvailable();
247247

248248
if (target.isMacOSX()) {
249+
if (target.isAArch64())
250+
return AvailabilityContext::alwaysAvailable();
251+
249252
return AvailabilityContext(
250253
VersionRange::allGTE(llvm::VersionTuple(10,14,4)));
251254
} else if (target.isiOS()) {
255+
if (target.isAArch64() &&
256+
(target.isSimulatorEnvironment() || target.isMacCatalystEnvironment()))
257+
return AvailabilityContext::alwaysAvailable();
258+
252259
return AvailabilityContext(
253260
VersionRange::allGTE(llvm::VersionTuple(12,2)));
254261
} else if (target.isWatchOS()) {
@@ -274,9 +281,16 @@ AvailabilityContext ASTContext::getSwift51Availability() {
274281
return AvailabilityContext::alwaysAvailable();
275282

276283
if (target.isMacOSX()) {
284+
if (target.isAArch64())
285+
return AvailabilityContext::alwaysAvailable();
286+
277287
return AvailabilityContext(
278288
VersionRange::allGTE(llvm::VersionTuple(10,15,0)));
279289
} else if (target.isiOS()) {
290+
if (target.isAArch64() &&
291+
(target.isSimulatorEnvironment() || target.isMacCatalystEnvironment()))
292+
return AvailabilityContext::alwaysAvailable();
293+
280294
return AvailabilityContext(
281295
VersionRange::allGTE(llvm::VersionTuple(13,0,0)));
282296
} else if (target.isWatchOS()) {
@@ -310,18 +324,27 @@ AvailabilityContext ASTContext::getSwift52Availability() {
310324
if (target.getArchName() == "arm64e")
311325
return AvailabilityContext::alwaysAvailable();
312326

313-
if (target.isMacOSX() ) {
327+
if (target.isMacOSX()) {
328+
if (target.isAArch64())
329+
return AvailabilityContext::alwaysAvailable();
330+
314331
return AvailabilityContext(
315-
VersionRange::allGTE(llvm::VersionTuple(10, 99, 0)));
332+
VersionRange::allGTE(llvm::VersionTuple(10, 15, 4)));
316333
} else if (target.isiOS()) {
334+
if (target.isAArch64() &&
335+
(target.isSimulatorEnvironment() || target.isMacCatalystEnvironment()))
336+
return AvailabilityContext::alwaysAvailable();
337+
317338
return AvailabilityContext(
318-
VersionRange::allGTE(llvm::VersionTuple(99, 0, 0)));
339+
VersionRange::allGTE(llvm::VersionTuple(13, 4, 0)));
319340
} else if (target.isWatchOS()) {
341+
if (target.isArch64Bit())
342+
return AvailabilityContext::alwaysAvailable();
343+
320344
return AvailabilityContext(
321-
VersionRange::allGTE(llvm::VersionTuple(9, 99, 0)));
322-
} else {
323-
return AvailabilityContext::alwaysAvailable();
345+
VersionRange::allGTE(llvm::VersionTuple(6, 2, 0)));
324346
}
347+
return AvailabilityContext::alwaysAvailable();
325348
}
326349

327350
AvailabilityContext ASTContext::getSwift53Availability() {
@@ -331,14 +354,26 @@ AvailabilityContext ASTContext::getSwift53Availability() {
331354
return AvailabilityContext::alwaysAvailable();
332355

333356
if (target.isMacOSX() ) {
357+
if (target.isAArch64())
358+
return AvailabilityContext::alwaysAvailable();
359+
360+
llvm::VersionTuple macOVersion53(10, 16, 0);
361+
macOVersion53 = canonicalizePlatformVersion(PlatformKind::OSX, macOVersion53);
334362
return AvailabilityContext(
335-
VersionRange::allGTE(llvm::VersionTuple(10, 99, 0)));
363+
VersionRange::allGTE(macOVersion53));
336364
} else if (target.isiOS()) {
365+
if (target.isAArch64() &&
366+
(target.isSimulatorEnvironment() || target.isMacCatalystEnvironment()))
367+
return AvailabilityContext::alwaysAvailable();
368+
337369
return AvailabilityContext(
338-
VersionRange::allGTE(llvm::VersionTuple(99, 0, 0)));
370+
VersionRange::allGTE(llvm::VersionTuple(14, 0, 0)));
339371
} else if (target.isWatchOS()) {
372+
if (target.isArch64Bit())
373+
return AvailabilityContext::alwaysAvailable();
374+
340375
return AvailabilityContext(
341-
VersionRange::allGTE(llvm::VersionTuple(9, 99, 0)));
376+
VersionRange::allGTE(llvm::VersionTuple(7, 0, 0)));
342377
} else {
343378
return AvailabilityContext::alwaysAvailable();
344379
}
@@ -349,7 +384,7 @@ AvailabilityContext ASTContext::getSwiftFutureAvailability() {
349384

350385
if (target.isMacOSX() ) {
351386
return AvailabilityContext(
352-
VersionRange::allGTE(llvm::VersionTuple(10, 99, 0)));
387+
VersionRange::allGTE(llvm::VersionTuple(99, 99, 0)));
353388
} else if (target.isiOS()) {
354389
return AvailabilityContext(
355390
VersionRange::allGTE(llvm::VersionTuple(99, 0, 0)));

lib/AST/PlatformKind.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "llvm/ADT/StringSwitch.h"
2121
#include "llvm/Support/ErrorHandling.h"
2222

23+
2324
using namespace swift;
2425

2526
StringRef swift::platformString(PlatformKind platform) {
@@ -155,3 +156,17 @@ bool swift::inheritsAvailabilityFromPlatform(PlatformKind Child,
155156

156157
return false;
157158
}
159+
160+
llvm::VersionTuple swift::canonicalizePlatformVersion(
161+
PlatformKind platform, const llvm::VersionTuple &version) {
162+
163+
// Canonicalize macOS version for macOS Big Sur to treat
164+
// 10.16 as 11.0.
165+
if (platform == PlatformKind::OSX ||
166+
platform == PlatformKind::OSXApplicationExtension) {
167+
return llvm::Triple::getCanonicalVersionForOS(llvm::Triple::MacOSX,
168+
version);
169+
}
170+
171+
return version;
172+
}

lib/Basic/Platform.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,9 @@ swift::getSwiftRuntimeCompatibilityVersionForTarget(
387387
if (Triple.isMacOSX()) {
388388
Triple.getMacOSXVersion(Major, Minor, Micro);
389389
if (Major == 10) {
390+
if (Triple.isAArch64() && Minor <= 16)
391+
return llvm::VersionTuple(5, 3);
392+
390393
if (Minor <= 14) {
391394
return llvm::VersionTuple(5, 0);
392395
} else if (Minor <= 15) {
@@ -396,9 +399,18 @@ swift::getSwiftRuntimeCompatibilityVersionForTarget(
396399
return llvm::VersionTuple(5, 2);
397400
}
398401
}
402+
} else if (Major == 11) {
403+
return llvm::VersionTuple(5, 3);
399404
}
400405
} else if (Triple.isiOS()) { // includes tvOS
401406
Triple.getiOSVersion(Major, Minor, Micro);
407+
408+
// arm64 simulators and macCatalyst are introduced in iOS 14.0/tvOS 14.0
409+
// with Swift 5.3
410+
if (Triple.isAArch64() && Major <= 14 &&
411+
(Triple.isSimulatorEnvironment() || Triple.isMacCatalystEnvironment()))
412+
return llvm::VersionTuple(5, 3);
413+
402414
if (Major <= 12) {
403415
return llvm::VersionTuple(5, 0);
404416
} else if (Major <= 13) {

0 commit comments

Comments
 (0)