Last active
March 27, 2022 06:49
-
-
Save colemancda/a6112d449b76eddf12dfa46e260bfca0 to your computer and use it in GitHub Desktop.
Swift 5.6 patched for RISCV64
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/CMakeLists.txt b/CMakeLists.txt | |
index bc9b6790922..6cc8149e184 100644 | |
--- a/CMakeLists.txt | |
+++ b/CMakeLists.txt | |
@@ -724,6 +724,8 @@ else() | |
set(SWIFT_HOST_VARIANT_ARCH_default "i686") | |
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "wasm32") | |
set(SWIFT_HOST_VARIANT_ARCH_default "wasm32") | |
+ elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "riscv64") | |
+ set(SWIFT_HOST_VARIANT_ARCH_default "riscv64") | |
else() | |
message(FATAL_ERROR "Unrecognized architecture on host system: ${CMAKE_SYSTEM_PROCESSOR}") | |
endif() | |
diff --git a/cmake/modules/SwiftConfigureSDK.cmake b/cmake/modules/SwiftConfigureSDK.cmake | |
index 3c866f2e65c..21d325c07c7 100644 | |
--- a/cmake/modules/SwiftConfigureSDK.cmake | |
+++ b/cmake/modules/SwiftConfigureSDK.cmake | |
@@ -325,7 +325,7 @@ macro(configure_sdk_unix name architectures) | |
if("${prefix}" STREQUAL "LINUX") | |
if(arch MATCHES "(armv6|armv7)") | |
set(SWIFT_SDK_LINUX_ARCH_${arch}_TRIPLE "${arch}-unknown-linux-gnueabihf") | |
- elseif(arch MATCHES "(aarch64|i686|powerpc64|powerpc64le|s390x|x86_64)") | |
+ elseif(arch MATCHES "(aarch64|i686|powerpc64|powerpc64le|s390x|x86_64|riscv64)") | |
set(SWIFT_SDK_LINUX_ARCH_${arch}_TRIPLE "${arch}-unknown-linux-gnu") | |
else() | |
message(FATAL_ERROR "unknown arch for ${prefix}: ${arch}") | |
diff --git a/cmake/modules/SwiftSetIfArchBitness.cmake b/cmake/modules/SwiftSetIfArchBitness.cmake | |
index fa29d77fe26..d43050d2a6e 100644 | |
--- a/cmake/modules/SwiftSetIfArchBitness.cmake | |
+++ b/cmake/modules/SwiftSetIfArchBitness.cmake | |
@@ -23,7 +23,8 @@ function(set_if_arch_bitness var_name) | |
"${SIA_ARCH}" STREQUAL "aarch64" OR | |
"${SIA_ARCH}" STREQUAL "powerpc64" OR | |
"${SIA_ARCH}" STREQUAL "powerpc64le" OR | |
- "${SIA_ARCH}" STREQUAL "s390x") | |
+ "${SIA_ARCH}" STREQUAL "s390x" OR | |
+ "${SIA_ARCH}" STREQUAL "riscv64") | |
set("${var_name}" "${SIA_CASE_64_BIT}" PARENT_SCOPE) | |
else() | |
message(FATAL_ERROR "Unknown architecture: ${SIA_ARCH}") | |
diff --git a/lib/Basic/LangOptions.cpp b/lib/Basic/LangOptions.cpp | |
index b9e8b488d9c..04ce2b64444 100644 | |
--- a/lib/Basic/LangOptions.cpp | |
+++ b/lib/Basic/LangOptions.cpp | |
@@ -66,6 +66,7 @@ static const SupportedConditionalValue SupportedConditionalCompilationArches[] = | |
"powerpc64le", | |
"s390x", | |
"wasm32", | |
+ "riscv64", | |
}; | |
static const SupportedConditionalValue SupportedConditionalCompilationEndianness[] = { | |
@@ -312,6 +313,9 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) { | |
addPlatformConditionValue(PlatformConditionKind::Arch, "arm64"); | |
} | |
break; | |
+ case llvm::Triple::ArchType::riscv64: | |
+ addPlatformConditionValue(PlatformConditionKind::Arch, "riscv64"); | |
+ break; | |
case llvm::Triple::ArchType::ppc64: | |
addPlatformConditionValue(PlatformConditionKind::Arch, "powerpc64"); | |
break; | |
@@ -346,6 +350,7 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) { | |
case llvm::Triple::ArchType::aarch64_32: | |
case llvm::Triple::ArchType::ppc64le: | |
case llvm::Triple::ArchType::wasm32: | |
+ case llvm::Triple::ArchType::riscv64: | |
case llvm::Triple::ArchType::x86: | |
case llvm::Triple::ArchType::x86_64: | |
addPlatformConditionValue(PlatformConditionKind::Endianness, "little"); | |
diff --git a/stdlib/cmake/modules/SwiftSource.cmake b/stdlib/cmake/modules/SwiftSource.cmake | |
index 4bc312f7f89..322e7829578 100644 | |
--- a/stdlib/cmake/modules/SwiftSource.cmake | |
+++ b/stdlib/cmake/modules/SwiftSource.cmake | |
@@ -520,6 +520,10 @@ function(_compile_swift_files | |
list(APPEND swift_flags ${SWIFT_STDLIB_EXTRA_SWIFT_COMPILE_FLAGS}) | |
+ if(CFLAGS_ARCH STREQUAL "riscv64") | |
+ list(APPEND swift_flags "-Xcc" "-mno-relax") | |
+ endif() | |
+ | |
list(APPEND swift_flags ${SWIFT_EXPERIMENTAL_EXTRA_FLAGS}) | |
if(SWIFTFILE_OPT_FLAGS) | |
diff --git a/stdlib/public/core/AtomicInt.swift.gyb b/stdlib/public/core/AtomicInt.swift.gyb | |
index a66212f4b35..1910009c996 100644 | |
--- a/stdlib/public/core/AtomicInt.swift.gyb | |
+++ b/stdlib/public/core/AtomicInt.swift.gyb | |
@@ -68,7 +68,7 @@ internal func _swift_stdlib_atomicCompareExchangeStrongInt( | |
#if arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32) | |
let (oldValue, won) = Builtin.cmpxchg_seqcst_seqcst_Int32( | |
target._rawValue, expected.pointee._value, desired._value) | |
-#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x) | |
+#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x) || arch(riscv64) | |
let (oldValue, won) = Builtin.cmpxchg_seqcst_seqcst_Int64( | |
target._rawValue, expected.pointee._value, desired._value) | |
#endif | |
@@ -85,7 +85,7 @@ func _swift_stdlib_atomicLoadInt( | |
#if arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32) | |
let value = Builtin.atomicload_seqcst_Int32(target._rawValue) | |
return Int(value) | |
-#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x) | |
+#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x) || arch(riscv64) | |
let value = Builtin.atomicload_seqcst_Int64(target._rawValue) | |
return Int(value) | |
#endif | |
@@ -97,7 +97,7 @@ internal func _swift_stdlib_atomicStoreInt( | |
desired: Int) { | |
#if arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32) | |
Builtin.atomicstore_seqcst_Int32(target._rawValue, desired._value) | |
-#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x) | |
+#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x) || arch(riscv64) | |
Builtin.atomicstore_seqcst_Int64(target._rawValue, desired._value) | |
#endif | |
} | |
@@ -115,7 +115,7 @@ func _swift_stdlib_atomicFetch${operation}Int( | |
let value = _swift_stdlib_atomicFetch${operation}Int32( | |
object: rawTarget.assumingMemoryBound(to: Int32.self), | |
operand: Int32(operand)) | |
-#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x) | |
+#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x) || arch(riscv64) | |
let value = _swift_stdlib_atomicFetch${operation}Int64( | |
object: rawTarget.assumingMemoryBound(to: Int64.self), | |
operand: Int64(operand)) | |
diff --git a/stdlib/public/core/Builtin.swift b/stdlib/public/core/Builtin.swift | |
index 8a7bb33243a..f74f5c7b769 100644 | |
--- a/stdlib/public/core/Builtin.swift | |
+++ b/stdlib/public/core/Builtin.swift | |
@@ -389,7 +389,7 @@ internal var _objectPointerLowSpareBitShift: UInt { | |
} | |
#if arch(i386) || arch(arm) || arch(wasm32) || arch(powerpc64) || arch( | |
- powerpc64le) || arch(s390x) || arch(arm64_32) | |
+ powerpc64le) || arch(s390x) || arch(arm64_32) || arch(riscv64) | |
@inlinable | |
internal var _objectPointerIsObjCBit: UInt { | |
@inline(__always) get { return 0x0000_0002 } | |
diff --git a/stdlib/public/runtime/Float16Support.cpp b/stdlib/public/runtime/Float16Support.cpp | |
index 817739d4cdf..acc4cb93811 100644 | |
--- a/stdlib/public/runtime/Float16Support.cpp | |
+++ b/stdlib/public/runtime/Float16Support.cpp | |
@@ -29,8 +29,8 @@ | |
// Android NDK <r21 do not provide `__aeabi_d2h` in the compiler runtime, | |
// provide shims in that case. | |
-#if (defined(__ANDROID__) && defined(__ARM_ARCH_7A__) && defined(__ARM_EABI__)) || \ | |
- ((defined(__i386__) || defined(__i686__) || defined(__x86_64__)) && !defined(__APPLE__)) | |
+#if ((defined(__ANDROID__) || defined(__linux__)) && defined(__arm__)) || \ | |
+ ((defined(__i386__) || defined(__i686__) || defined(__x86_64__) || defined(__riscv)) && !defined(__APPLE__)) | |
#include "../SwiftShims/Visibility.h" | |
diff --git a/stdlib/public/runtime/HeapObject.cpp b/stdlib/public/runtime/HeapObject.cpp | |
index 0a276206225..74589177170 100644 | |
--- a/stdlib/public/runtime/HeapObject.cpp | |
+++ b/stdlib/public/runtime/HeapObject.cpp | |
@@ -66,7 +66,7 @@ static inline bool isValidPointerForNativeRetain(const void *p) { | |
// arm64_32 is special since it has 32-bit pointers but __arm64__ is true. | |
// Catch it early since __POINTER_WIDTH__ is generally non-portable. | |
return p != nullptr; | |
-#elif defined(__x86_64__) || defined(__arm64__) || defined(__aarch64__) || defined(_M_ARM64) || defined(__s390x__) || (defined(__powerpc64__) && defined(__LITTLE_ENDIAN__)) | |
+#elif defined(__x86_64__) || defined(__arm64__) || defined(__aarch64__) || defined(_M_ARM64) || defined(__s390x__) || (defined(__powerpc64__) && defined(__LITTLE_ENDIAN__)) || defined(__riscv) | |
// On these platforms, except s390x, the upper half of address space is reserved for the | |
// kernel, so we can assume that pointer values in this range are invalid. | |
// On s390x it is theoretically possible to have high bit set but in practice | |
diff --git a/stdlib/public/stubs/MathStubs.cpp b/stdlib/public/stubs/MathStubs.cpp | |
index 8d0617089ca..7ff97bc3687 100644 | |
--- a/stdlib/public/stubs/MathStubs.cpp | |
+++ b/stdlib/public/stubs/MathStubs.cpp | |
@@ -64,6 +64,7 @@ extern "C" { | |
(defined(__linux__) && defined(__aarch64__)) || \ | |
(defined(__linux__) && defined(__powerpc64__)) || \ | |
(defined(__linux__) && defined(__s390x__)) || \ | |
+ (defined(__linux__) && defined(__riscv)) || \ | |
(defined(__ANDROID__) && defined(__aarch64__)) | |
SWIFT_RUNTIME_STDLIB_API | |
diff --git a/utils/build-presets.ini b/utils/build-presets.ini | |
index 64ba12b1e04..c2827b1212b 100644 | |
--- a/utils/build-presets.ini | |
+++ b/utils/build-presets.ini | |
@@ -864,6 +864,7 @@ relocate-xdg-cache-home-under-build-subdir | |
mixin-preset= | |
mixin_linux_installation | |
build-subdir=buildbot_linux | |
+llvm-targets-to-build=X86;ARM;AArch64;PowerPC;SystemZ;Mips;RISCV | |
lldb | |
release | |
test | |
@@ -1481,7 +1482,7 @@ mixin-preset= | |
[preset: LLDB_Nested] | |
skip-build-benchmarks | |
install-destdir=%(swift_install_destdir)s | |
-llvm-targets-to-build=X86;ARM;AArch64;PowerPC;SystemZ;Mips | |
+llvm-targets-to-build=X86;ARM;AArch64;PowerPC;SystemZ;Mips;RISCV | |
[preset: LLDB_Swift_DebugAssert] | |
mixin-preset= |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment