Skip to content

[5.3] Apple Silicon support #32706

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 34 commits into from
Jul 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
87612b4
[Apple Silicon] Add arm64 macOS support to benchmark suite
shahmishal Jul 2, 2020
8d74d35
[Apple Silicon][Test] Enable testing for arm64 macOS
shahmishal Jul 2, 2020
d795169
[Apple Silicon] Mark several tests that require the Swift interpreter…
shahmishal Jul 2, 2020
d5b48bc
[Apple Silicon] Generalize tests for other macOS architectures
shahmishal Jul 2, 2020
e24f7df
[Apple Silicon] Mark macOS tests that require x86_64
shahmishal Jul 2, 2020
6c183c8
[Apple Silicon] [Build] Generalize macOS architecture check
shahmishal Jul 2, 2020
76c5fac
[Apple Silicon] [ObjectiveC Overlay] ObjCBool is C _Bool on arm64 macOS.
shahmishal Jul 2, 2020
16110be
[Apple Silicon] Baseline arm64 macOS at Swift 5.3 / macOS 10.16
shahmishal Jul 2, 2020
7c94216
[Apple Silicon] [Test] Fix various IRGen tests for arm64 macOS
shahmishal Jul 3, 2020
781aa53
[Apple Silicon] [Test] Generalize api-digester tests for Apple Silico…
shahmishal Jul 3, 2020
885ef36
[Apple Silicon] Support building for macOS arm64/arm64e
shahmishal Jul 3, 2020
3b74951
[Apple Silicon] [build-script] Support stdlib macOS arm64/arm64e
shahmishal Jul 3, 2020
d84da25
[Apple Silicon] Use SWIFT_CROSS_COMPILING to use build-time tools (tb…
shahmishal Jul 3, 2020
676b9af
[Apple Silicon] Don't set native llvm tools path when cross compiling…
shahmishal Jul 3, 2020
b850bc6
[Apple Silicon] [build-script] Build compiler-rt even when cross-comp…
shahmishal Jul 3, 2020
824a3e6
[Apple Silicon] [build-script] Fix cross-compile check.
shahmishal Jul 3, 2020
39ee89f
[Apple Silicon] Build system configuration to support arm64 macOS
shahmishal Jul 3, 2020
05028a2
[Apple Silicon] [build-script] Fix lipo step invocation with --no-leg…
shahmishal Jul 3, 2020
2ef95d3
[Apple Silicon] Fix cross-compilation in Xcode trains where we're not…
shahmishal Jul 3, 2020
69ead9d
[Apple Silicon] [Platform] Default arm64 macOS and arm64 simulators t…
shahmishal Jul 3, 2020
7ca2bac
[Apple Silicon] [IRGen] Fix test for arm64 macOS
shahmishal Jul 3, 2020
0360f68
[Apple Silicon] [macCatalyst] Baseline arm64(e) macCatalyst at Swift …
shahmishal Jul 3, 2020
5566ace
[Apple Silicon] Adjust linking deployment target from 11.0 down to 10…
shahmishal Jul 3, 2020
e5d11ff
[Apple Silicon] [In-process memory reader] Adjust low-bits computatio…
shahmishal Jul 3, 2020
0b73826
[Apple Silicon] [Build] Filter out any architectures that are unsuppo…
shahmishal Jul 3, 2020
dedd426
[Apple Silicon] [Test] Fix a few tests for SDK differences
shahmishal Jul 3, 2020
8364ec9
[Apple Silicon] [Test] Remove explicitly-specified target.
shahmishal Jul 3, 2020
795c363
[Apple Silicon] Simulator support for arm64
shahmishal Jul 3, 2020
00a9c11
[Apple Silicon] [Platform] Baseline arm64 simulators at iOS/tvOS 14.0…
shahmishal Jul 3, 2020
54d8f93
[Apple Silicon] Use a correct isa mask on Apple Silicon without signe…
shahmishal Jul 3, 2020
0c5dc54
[Apple Silicon] Fix the availability for Swift 5.3 version
shahmishal Jul 3, 2020
d764db0
[Apple Silicon] Add support for triple and availability canonicalization
shahmishal Jul 3, 2020
f3a6146
[Apple Silicon] Update tests for no macOS target triple canonicalization
shahmishal Jul 3, 2020
962ce48
[Apple Silicon] Remove tvOS/watchOS simulator from Driver/linker test
shahmishal Jul 3, 2020
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
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,12 @@ if(SWIFT_PATH_TO_CMARK_BUILD)
endif()
message(STATUS "")

if("${SWIFT_NATIVE_LLVM_TOOLS_PATH}" STREQUAL "")
set(SWIFT_CROSS_COMPILING FALSE)
else()
set(SWIFT_CROSS_COMPILING TRUE)
endif()

include(SwiftSharedCMakeConfig)

# NOTE: We include this before SwiftComponents as it relies on some LLVM CMake
Expand Down
8 changes: 2 additions & 6 deletions benchmark/cmake/modules/AddSwiftBenchmarkSuite.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ macro(configure_build)
endmacro()

macro(configure_sdks_darwin)
set(macosx_arch "x86_64")
set(macosx_arch "x86_64" "arm64")
set(iphoneos_arch "arm64" "arm64e" "armv7")
set(appletvos_arch "arm64")
set(watchos_arch "armv7k")
Expand Down Expand Up @@ -609,11 +609,7 @@ function (swift_benchmark_compile_archopts)

if(is_darwin)
# If host == target.
if("${BENCH_COMPILE_ARCHOPTS_PLATFORM}" STREQUAL "macosx")
set(OUTPUT_EXEC "${benchmark-bin-dir}/Benchmark_${BENCH_COMPILE_ARCHOPTS_OPT}")
else()
set(OUTPUT_EXEC "${benchmark-bin-dir}/Benchmark_${BENCH_COMPILE_ARCHOPTS_OPT}-${target}")
endif()
set(OUTPUT_EXEC "${benchmark-bin-dir}/Benchmark_${BENCH_COMPILE_ARCHOPTS_OPT}-${target}")
else()
# If we are on Linux, we do not support cross compiling.
set(OUTPUT_EXEC "${benchmark-bin-dir}/Benchmark_${BENCH_COMPILE_ARCHOPTS_OPT}")
Expand Down
27 changes: 22 additions & 5 deletions cmake/modules/DarwinSDKs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,34 @@ option(SWIFT_ENABLE_IOS32

if(SWIFT_ENABLE_IOS32)
set(SUPPORTED_IOS_ARCHS "armv7;armv7s;arm64;arm64e")
set(SUPPORTED_IOS_SIMULATOR_ARCHS "i386;x86_64")
set(SUPPORTED_IOS_SIMULATOR_ARCHS "i386;x86_64;arm64")
else()
set(SUPPORTED_IOS_ARCHS "arm64;arm64e")
set(SUPPORTED_IOS_SIMULATOR_ARCHS "x86_64")
set(SUPPORTED_IOS_SIMULATOR_ARCHS "x86_64;arm64")
endif()

set(SUPPORTED_TVOS_ARCHS "arm64")
set(SUPPORTED_TVOS_SIMULATOR_ARCHS "x86_64")
set(SUPPORTED_TVOS_SIMULATOR_ARCHS "x86_64;arm64")
set(SUPPORTED_WATCHOS_ARCHS "armv7k")
set(SUPPORTED_WATCHOS_SIMULATOR_ARCHS "i386")
set(SUPPORTED_OSX_ARCHS "x86_64")
set(SUPPORTED_WATCHOS_SIMULATOR_ARCHS "i386;arm64")
set(SUPPORTED_OSX_ARCHS "x86_64;arm64;arm64e")

# Get the SDK version from SDKSettings.
execute_process(
COMMAND "defaults" "read" "${CMAKE_OSX_SYSROOT}/SDKSettings.plist" "Version"
OUTPUT_VARIABLE SWIFT_OSX_SDK_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)

# Remove the last component, if any. e.g. 10.15.26 -> 10.15
string(REGEX REPLACE "\([0-9]*[.][0-9]*\)[.][0-9]*" "\\1"
SWIFT_OSX_SDK_VERSION "${SWIFT_OSX_SDK_VERSION}")

if (${SWIFT_OSX_SDK_VERSION} STREQUAL "10.14" OR
${SWIFT_OSX_SDK_VERSION} STREQUAL "10.15")
set(SUPPORTED_OSX_ARCHS "x86_64")
else()
set(SUPPORTED_OSX_ARCHS "x86_64;arm64e")
endif()

is_sdk_requested(OSX swift_build_osx)
if(swift_build_osx)
Expand Down
35 changes: 35 additions & 0 deletions cmake/modules/SwiftConfigureSDK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,38 @@ function(_report_sdk prefix)
message(STATUS "")
endfunction()

# Remove architectures not supported by the SDK from the given list.
function(remove_sdk_unsupported_archs name os sdk_path architectures_var)
execute_process(COMMAND
/usr/libexec/PlistBuddy -c "Print :SupportedTargets:${os}:Archs" ${sdk_path}/SDKSettings.plist
OUTPUT_VARIABLE sdk_supported_archs
RESULT_VARIABLE plist_error)

if (NOT plist_error EQUAL 0)
message(STATUS "${os} SDK at ${sdk_path} does not publish its supported architectures")
return()
endif()

set(architectures)
foreach(arch ${${architectures_var}})
if(sdk_supported_archs MATCHES "${arch}\n")
list(APPEND architectures ${arch})
elseif(arch MATCHES "^armv7(s)?$" AND os STREQUAL "iphoneos")
# 32-bit iOS is not listed explicitly in SDK settings.
message(STATUS "Assuming ${name} SDK at ${sdk_path} supports architecture ${arch}")
list(APPEND architectures ${arch})
elseif(arch STREQUAL "i386" AND os STREQUAL "iphonesimulator")
# 32-bit iOS simulatoris not listed explicitly in SDK settings.
message(STATUS "Assuming ${name} SDK at ${sdk_path} supports architecture ${arch}")
list(APPEND architectures ${arch})
else()
message(STATUS "${name} SDK at ${sdk_path} does not support architecture ${arch}")
endif()
endforeach()

set("${architectures_var}" ${architectures} PARENT_SCOPE)
endfunction()

# Configure an SDK
#
# Usage:
Expand Down Expand Up @@ -164,6 +196,9 @@ macro(configure_sdk_darwin
SWIFT_SDK_${prefix}_ARCHITECTURES) # result
endif()

# Remove any architectures not supported by the SDK.
remove_sdk_unsupported_archs(${name} ${xcrun_name} ${SWIFT_SDK_${prefix}_PATH} SWIFT_SDK_${prefix}_ARCHITECTURES)

list_intersect(
"${SWIFT_DARWIN_MODULE_ARCHS}" # lhs
"${architectures}" # rhs
Expand Down
2 changes: 1 addition & 1 deletion cmake/modules/SwiftSharedCMakeConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ macro(swift_common_standalone_build_config_llvm product)
fix_imported_targets_for_xcode("${LLVM_EXPORTED_TARGETS}")
endif()

if(NOT CMAKE_CROSSCOMPILING)
if(NOT CMAKE_CROSSCOMPILING AND NOT SWIFT_CROSS_COMPILING)
set(${product}_NATIVE_LLVM_TOOLS_PATH "${LLVM_TOOLS_BINARY_DIR}")
endif()

Expand Down
22 changes: 22 additions & 0 deletions include/swift/AST/AvailabilitySpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,33 @@ class PlatformVersionConstraintAvailabilitySpec : public AvailabilitySpec {
SourceLoc PlatformLoc;

llvm::VersionTuple Version;

// For macOS Big Sur, we we canonicalize 10.16 to 11.0 for compile-time
// checking since clang canonicalizes availability markup. However, to
// support Beta versions of macOS Big Sur where the OS
// reports 10.16 at run time, we need to compare against 10.16,
//
// This means for:
//
// if #available(macOS 10.16, *) { ... }
//
// we need to keep around both a canonical version for use in compile-time
// checks and an uncanonicalized version for the version to actually codegen
// with.
llvm::VersionTuple RuntimeVersion;

SourceRange VersionSrcRange;

public:
PlatformVersionConstraintAvailabilitySpec(PlatformKind Platform,
SourceLoc PlatformLoc,
llvm::VersionTuple Version,
llvm::VersionTuple RuntimeVersion,
SourceRange VersionSrcRange)
: AvailabilitySpec(AvailabilitySpecKind::PlatformVersionConstraint),
Platform(Platform),
PlatformLoc(PlatformLoc), Version(Version),
RuntimeVersion(RuntimeVersion),
VersionSrcRange(VersionSrcRange) {}

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

// The version to be used in codegen for version comparisons at run time.
// This is required to support beta versions of macOS Big Sur that
// report 10.16 at run time.
llvm::VersionTuple getRuntimeVersion() const { return RuntimeVersion; }

SourceRange getSourceRange() const;

void print(raw_ostream &OS, unsigned Indent) const;
Expand Down
4 changes: 4 additions & 0 deletions include/swift/AST/PlatformKind.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "swift/Basic/LLVM.h"
#include "swift/Config.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/VersionTuple.h"

namespace swift {

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

llvm::VersionTuple canonicalizePlatformVersion(
PlatformKind platform, const llvm::VersionTuple &version);

} // end namespace swift

#endif
4 changes: 2 additions & 2 deletions include/swift/Remote/InProcessMemoryReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class InProcessMemoryReader final : public MemoryReader {
#else
auto applePlatform = false;
#endif
#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))
#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__))
auto iosDerivedPlatform = true;
#else
auto iosDerivedPlatform = false;
Expand Down Expand Up @@ -67,7 +67,7 @@ class InProcessMemoryReader final : public MemoryReader {
case DLQ_GetObjCReservedLowBits: {
auto result = static_cast<uint8_t *>(outBuffer);
if (applePlatform && !iosDerivedPlatform && (sizeof(void *) == 8)) {
// Obj-C reserves low bit on 64-bit macOS only.
// Obj-C reserves low bit on 64-bit Intel macOS only.
// Other Apple platforms don't reserve this bit (even when
// running on x86_64-based simulators).
*result = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ swift_reflection_interop_minimalDataLayoutQueryFunction8(
#else
int applePlatform = 0;
#endif
#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))
#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__))
int iosDerivedPlatform = 1;
#else
int iosDerivedPlatform = 0;
Expand Down
55 changes: 45 additions & 10 deletions lib/AST/Availability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,16 @@ AvailabilityContext ASTContext::getSwift50Availability() {
return AvailabilityContext::alwaysAvailable();

if (target.isMacOSX()) {
if (target.isAArch64())
return AvailabilityContext::alwaysAvailable();

return AvailabilityContext(
VersionRange::allGTE(llvm::VersionTuple(10,14,4)));
} else if (target.isiOS()) {
if (target.isAArch64() &&
(target.isSimulatorEnvironment() || target.isMacCatalystEnvironment()))
return AvailabilityContext::alwaysAvailable();

return AvailabilityContext(
VersionRange::allGTE(llvm::VersionTuple(12,2)));
} else if (target.isWatchOS()) {
Expand All @@ -274,9 +281,16 @@ AvailabilityContext ASTContext::getSwift51Availability() {
return AvailabilityContext::alwaysAvailable();

if (target.isMacOSX()) {
if (target.isAArch64())
return AvailabilityContext::alwaysAvailable();

return AvailabilityContext(
VersionRange::allGTE(llvm::VersionTuple(10,15,0)));
} else if (target.isiOS()) {
if (target.isAArch64() &&
(target.isSimulatorEnvironment() || target.isMacCatalystEnvironment()))
return AvailabilityContext::alwaysAvailable();

return AvailabilityContext(
VersionRange::allGTE(llvm::VersionTuple(13,0,0)));
} else if (target.isWatchOS()) {
Expand All @@ -301,18 +315,27 @@ AvailabilityContext ASTContext::getSwift52Availability() {
if (target.getArchName() == "arm64e")
return AvailabilityContext::alwaysAvailable();

if (target.isMacOSX() ) {
if (target.isMacOSX()) {
if (target.isAArch64())
return AvailabilityContext::alwaysAvailable();

return AvailabilityContext(
VersionRange::allGTE(llvm::VersionTuple(10, 99, 0)));
VersionRange::allGTE(llvm::VersionTuple(10, 15, 4)));
} else if (target.isiOS()) {
if (target.isAArch64() &&
(target.isSimulatorEnvironment() || target.isMacCatalystEnvironment()))
return AvailabilityContext::alwaysAvailable();

return AvailabilityContext(
VersionRange::allGTE(llvm::VersionTuple(99, 0, 0)));
VersionRange::allGTE(llvm::VersionTuple(13, 4, 0)));
} else if (target.isWatchOS()) {
if (target.isArch64Bit())
return AvailabilityContext::alwaysAvailable();

return AvailabilityContext(
VersionRange::allGTE(llvm::VersionTuple(9, 99, 0)));
} else {
return AvailabilityContext::alwaysAvailable();
VersionRange::allGTE(llvm::VersionTuple(6, 2, 0)));
}
return AvailabilityContext::alwaysAvailable();
}

AvailabilityContext ASTContext::getSwift53Availability() {
Expand All @@ -322,14 +345,26 @@ AvailabilityContext ASTContext::getSwift53Availability() {
return AvailabilityContext::alwaysAvailable();

if (target.isMacOSX() ) {
if (target.isAArch64())
return AvailabilityContext::alwaysAvailable();

llvm::VersionTuple macOVersion53(10, 16, 0);
macOVersion53 = canonicalizePlatformVersion(PlatformKind::OSX, macOVersion53);
return AvailabilityContext(
VersionRange::allGTE(llvm::VersionTuple(10, 99, 0)));
VersionRange::allGTE(macOVersion53));
} else if (target.isiOS()) {
if (target.isAArch64() &&
(target.isSimulatorEnvironment() || target.isMacCatalystEnvironment()))
return AvailabilityContext::alwaysAvailable();

return AvailabilityContext(
VersionRange::allGTE(llvm::VersionTuple(99, 0, 0)));
VersionRange::allGTE(llvm::VersionTuple(14, 0, 0)));
} else if (target.isWatchOS()) {
if (target.isArch64Bit())
return AvailabilityContext::alwaysAvailable();

return AvailabilityContext(
VersionRange::allGTE(llvm::VersionTuple(9, 99, 0)));
VersionRange::allGTE(llvm::VersionTuple(7, 0, 0)));
} else {
return AvailabilityContext::alwaysAvailable();
}
Expand All @@ -340,7 +375,7 @@ AvailabilityContext ASTContext::getSwiftFutureAvailability() {

if (target.isMacOSX() ) {
return AvailabilityContext(
VersionRange::allGTE(llvm::VersionTuple(10, 99, 0)));
VersionRange::allGTE(llvm::VersionTuple(99, 99, 0)));
} else if (target.isiOS()) {
return AvailabilityContext(
VersionRange::allGTE(llvm::VersionTuple(99, 0, 0)));
Expand Down
15 changes: 15 additions & 0 deletions lib/AST/PlatformKind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/ErrorHandling.h"


using namespace swift;

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

return false;
}

llvm::VersionTuple swift::canonicalizePlatformVersion(
PlatformKind platform, const llvm::VersionTuple &version) {

// Canonicalize macOS version for macOS Big Sur to great
// 10.16 as 11.0.
if (platform == PlatformKind::OSX ||
platform == PlatformKind::OSXApplicationExtension) {
return llvm::Triple::getCanonicalVersionForOS(llvm::Triple::MacOSX,
version);
}

return version;
}
12 changes: 12 additions & 0 deletions lib/Basic/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,9 @@ swift::getSwiftRuntimeCompatibilityVersionForTarget(
if (Triple.isMacOSX()) {
Triple.getMacOSXVersion(Major, Minor, Micro);
if (Major == 10) {
if (Triple.isAArch64() && Minor <= 16)
return llvm::VersionTuple(5, 3);

if (Minor <= 14) {
return llvm::VersionTuple(5, 0);
} else if (Minor <= 15) {
Expand All @@ -396,9 +399,18 @@ swift::getSwiftRuntimeCompatibilityVersionForTarget(
return llvm::VersionTuple(5, 2);
}
}
} else if (Major == 11) {
return llvm::VersionTuple(5, 3);
}
} else if (Triple.isiOS()) { // includes tvOS
Triple.getiOSVersion(Major, Minor, Micro);

// arm64 simulators and macCatalyst are introduced in iOS 14.0/tvOS 14.0
// with Swift 5.3
if (Triple.isAArch64() && Major <= 14 &&
(Triple.isSimulatorEnvironment() || Triple.isMacCatalystEnvironment()))
return llvm::VersionTuple(5, 3);

if (Major <= 12) {
return llvm::VersionTuple(5, 0);
} else if (Major <= 13) {
Expand Down
Loading