Skip to content

Commit aeb31bf

Browse files
committed
Add arm64_32 support for Swift
Commit the platform definition and build script work necessary to cross-compile for arm64_32. arm64_32 is a variant of AARCH64 that supports an ILP32 architecture.
1 parent fea60e4 commit aeb31bf

File tree

71 files changed

+574
-102
lines changed

Some content is hidden

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

71 files changed

+574
-102
lines changed

benchmark/cmake/modules/AddSwiftBenchmarkSuite.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ macro(configure_sdks_darwin)
108108
set(macosx_arch "x86_64" "arm64")
109109
set(iphoneos_arch "arm64" "arm64e" "armv7")
110110
set(appletvos_arch "arm64")
111-
set(watchos_arch "armv7k")
111+
set(watchos_arch "armv7k" "arm64_32")
112112

113113
set(macosx_ver "10.9")
114114
set(iphoneos_ver "8.0")

cmake/modules/DarwinSDKs.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ endif()
1212

1313
set(SUPPORTED_TVOS_ARCHS "arm64")
1414
set(SUPPORTED_TVOS_SIMULATOR_ARCHS "x86_64;arm64")
15-
set(SUPPORTED_WATCHOS_ARCHS "armv7k")
15+
set(SUPPORTED_WATCHOS_ARCHS "armv7k;arm64_32")
1616
set(SUPPORTED_WATCHOS_SIMULATOR_ARCHS "i386;x86_64;arm64")
1717
set(SUPPORTED_OSX_ARCHS "x86_64;arm64;arm64e")
1818

cmake/modules/SwiftSetIfArchBitness.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ function(set_if_arch_bitness var_name)
1212
"${SIA_ARCH}" STREQUAL "armv6" OR
1313
"${SIA_ARCH}" STREQUAL "armv7" OR
1414
"${SIA_ARCH}" STREQUAL "armv7k" OR
15+
"${SIA_ARCH}" STREQUAL "arm64_32" OR
1516
"${SIA_ARCH}" STREQUAL "armv7s" OR
1617
"${SIA_ARCH}" STREQUAL "wasm32")
1718
set("${var_name}" "${SIA_CASE_32_BIT}" PARENT_SCOPE)

lib/Basic/LangOptions.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ static const SupportedConditionalValue SupportedConditionalCompilationOSs[] = {
5858
static const SupportedConditionalValue SupportedConditionalCompilationArches[] = {
5959
"arm",
6060
"arm64",
61+
"arm64_32",
6162
"i386",
6263
"x86_64",
6364
"powerpc64",
@@ -303,7 +304,12 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
303304
addPlatformConditionValue(PlatformConditionKind::Arch, "arm");
304305
break;
305306
case llvm::Triple::ArchType::aarch64:
306-
addPlatformConditionValue(PlatformConditionKind::Arch, "arm64");
307+
case llvm::Triple::ArchType::aarch64_32:
308+
if (Target.getArchName() == "arm64_32") {
309+
addPlatformConditionValue(PlatformConditionKind::Arch, "arm64_32");
310+
} else {
311+
addPlatformConditionValue(PlatformConditionKind::Arch, "arm64");
312+
}
307313
break;
308314
case llvm::Triple::ArchType::ppc64:
309315
addPlatformConditionValue(PlatformConditionKind::Arch, "powerpc64");
@@ -336,6 +342,7 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
336342
case llvm::Triple::ArchType::arm:
337343
case llvm::Triple::ArchType::thumb:
338344
case llvm::Triple::ArchType::aarch64:
345+
case llvm::Triple::ArchType::aarch64_32:
339346
case llvm::Triple::ArchType::ppc64le:
340347
case llvm::Triple::ArchType::wasm32:
341348
case llvm::Triple::ArchType::x86:

lib/Basic/Platform.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ getArchForAppleTargetSpecificModuleTriple(const llvm::Triple &triple) {
262262
// .Case ("armv7s", "armv7s")
263263
// .Case ("armv7k", "armv7k")
264264
// .Case ("armv7", "armv7")
265+
// .Case ("arm64_32", "arm64_32")
265266
// .Case ("arm64e", "arm64e")
266267
.Default(tripleArchName);
267268
}

lib/ClangImporter/ClangImporter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ importer::getNormalInvocationArguments(
635635
invocationArgStrs.insert(invocationArgStrs.end(), {"-D_ARM_"});
636636
break;
637637
case llvm::Triple::aarch64:
638+
case llvm::Triple::aarch64_32:
638639
invocationArgStrs.insert(invocationArgStrs.end(), {"-D_ARM64_"});
639640
break;
640641
case llvm::Triple::x86:
@@ -765,6 +766,7 @@ importer::addCommonInvocationArguments(
765766
(triple.isiOS() || triple.isWatchOS()))
766767
invocationArgStrs.push_back("-mcpu=apple-a12");
767768
else if (triple.getArch() == llvm::Triple::aarch64 ||
769+
triple.getArch() == llvm::Triple::aarch64_32 ||
768770
triple.getArch() == llvm::Triple::aarch64_be) {
769771
invocationArgStrs.push_back("-mcpu=apple-a7");
770772
}

lib/Driver/ToolChains.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
169169
}
170170

171171
// Enable address top-byte ignored in the ARM64 backend.
172-
if (Triple.getArch() == llvm::Triple::aarch64) {
172+
if (Triple.getArch() == llvm::Triple::aarch64 ||
173+
Triple.getArch() == llvm::Triple::aarch64_32) {
173174
arguments.push_back("-Xllvm");
174175
arguments.push_back("-aarch64-use-tbi");
175176
}
@@ -968,7 +969,8 @@ ToolChain::constructInvocation(const BackendJobAction &job,
968969
Arguments.push_back(context.Args.MakeArgString(getTriple().str()));
969970

970971
// Enable address top-byte ignored in the ARM64 backend.
971-
if (getTriple().getArch() == llvm::Triple::aarch64) {
972+
if (getTriple().getArch() == llvm::Triple::aarch64 ||
973+
getTriple().getArch() == llvm::Triple::aarch64_32) {
972974
Arguments.push_back("-Xllvm");
973975
Arguments.push_back("-aarch64-use-tbi");
974976
}

lib/Driver/UnixToolChains.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ std::string toolchains::GenericUnix::getDefaultLinker() const {
8888
switch (getTriple().getArch()) {
8989
case llvm::Triple::arm:
9090
case llvm::Triple::aarch64:
91+
case llvm::Triple::aarch64_32:
9192
case llvm::Triple::armeb:
9293
case llvm::Triple::thumb:
9394
case llvm::Triple::thumbeb:

lib/IRGen/GenType.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,7 @@ static llvm::StringLiteral platformsWithLegacyLayouts[][2] = {
13591359
{"iphonesimulator", "x86_64"},
13601360
{"macosx", "x86_64"},
13611361
{"watchos", "armv7k"},
1362+
{"watchos", "arm64_32"},
13621363
{"watchsimulator", "i386"}
13631364
};
13641365

lib/IRGen/SwiftTargetInfo.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,24 @@ static void configureARM64(IRGenModule &IGM, const llvm::Triple &triple,
6464
target.UsableSwiftAsyncContextAddrIntrinsic = true;
6565
}
6666

67+
/// Configures target-specific information for arm64_32 platforms.
68+
static void configureARM64_32(IRGenModule &IGM, const llvm::Triple &triple,
69+
SwiftTargetInfo &target) {
70+
setToMask(target.PointerSpareBits, 32,
71+
SWIFT_ABI_ARM_SWIFT_SPARE_BITS_MASK);
72+
73+
// arm64_32 has no special objc_msgSend variants, not even stret.
74+
target.ObjCUseStret = false;
75+
76+
// arm64_32 requires marker assembly for objc_retainAutoreleasedReturnValue.
77+
target.ObjCRetainAutoreleasedReturnValueMarker =
78+
"mov\tfp, fp\t\t// marker for objc_retainAutoreleaseReturnValue";
79+
80+
setToMask(target.IsObjCPointerBit, 32, SWIFT_ABI_ARM_IS_OBJC_BIT);
81+
82+
target.ObjCHasOpaqueISAs = true;
83+
}
84+
6785
/// Configures target-specific information for x86-64 platforms.
6886
static void configureX86_64(IRGenModule &IGM, const llvm::Triple &triple,
6987
SwiftTargetInfo &target) {
@@ -196,7 +214,11 @@ SwiftTargetInfo SwiftTargetInfo::get(IRGenModule &IGM) {
196214
break;
197215

198216
case llvm::Triple::aarch64:
199-
configureARM64(IGM, triple, target);
217+
case llvm::Triple::aarch64_32:
218+
if (triple.getArchName() == "arm64_32")
219+
configureARM64_32(IGM, triple, target);
220+
else
221+
configureARM64(IGM, triple, target);
200222
break;
201223

202224
case llvm::Triple::ppc64:

0 commit comments

Comments
 (0)