Skip to content

Commit 5e687ec

Browse files
authored
Merge pull request #1389 from swiftwasm/katei/merge-master-2020-07-06
The added lines by Apple Silicon patch really depend on the build machine platform and it forces that we can build stdlib only for darwin targets. So I changed to allow non-darwin targets and filter only unsupported darwin targets. This patch should be sent to upstream. Resolve #1388
2 parents 53b3064 + 9a99563 commit 5e687ec

File tree

129 files changed

+3249
-389
lines changed

Some content is hidden

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

129 files changed

+3249
-389
lines changed

CMakeLists.txt

+6
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

+2-6
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

+22-5
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

+35
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

+1-1
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

+22
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/DiagnosticsSema.def

+2
Original file line numberDiff line numberDiff line change
@@ -3151,6 +3151,8 @@ ERROR(autodiff_attr_original_multiple_semantic_results,none,
31513151
ERROR(autodiff_attr_result_not_differentiable,none,
31523152
"can only differentiate functions with results that conform to "
31533153
"'Differentiable', but %0 does not conform to 'Differentiable'", (Type))
3154+
ERROR(autodiff_attr_opaque_result_type_unsupported,none,
3155+
"cannot differentiate functions returning opaque result types", ())
31543156

31553157
// differentiation `wrt` parameters clause
31563158
ERROR(diff_function_no_parameters,none,

include/swift/AST/PlatformKind.h

+4
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/AST/SubstitutionMap.h

+6
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,12 @@ class SubstitutionMap {
286286
Type lookupSubstitution(CanSubstitutableType type) const;
287287
};
288288

289+
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
290+
const SubstitutionMap &subs) {
291+
subs.dump(OS);
292+
return OS;
293+
}
294+
289295
/// A function object suitable for use as a \c TypeSubstitutionFn that
290296
/// queries an underlying \c SubstitutionMap.
291297
struct QuerySubstitutionMap {

include/swift/AST/TypeCheckRequests.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -2192,7 +2192,7 @@ class DerivativeAttrOriginalDeclRequest
21922192
/// property in a `Differentiable`-conforming type.
21932193
class TangentStoredPropertyRequest
21942194
: public SimpleRequest<TangentStoredPropertyRequest,
2195-
TangentPropertyInfo(VarDecl *),
2195+
TangentPropertyInfo(VarDecl *, CanType),
21962196
RequestFlags::Cached> {
21972197
public:
21982198
using SimpleRequest::SimpleRequest;
@@ -2201,8 +2201,8 @@ class TangentStoredPropertyRequest
22012201
friend SimpleRequest;
22022202

22032203
// Evaluation.
2204-
TangentPropertyInfo evaluate(Evaluator &evaluator,
2205-
VarDecl *originalField) const;
2204+
TangentPropertyInfo evaluate(Evaluator &evaluator, VarDecl *originalField,
2205+
CanType parentType) const;
22062206

22072207
public:
22082208
// Caching.

include/swift/AST/TypeCheckerTypeIDZone.def

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ SWIFT_REQUEST(TypeChecker, SynthesizeAccessorRequest,
204204
AccessorDecl *(AbstractStorageDecl *, AccessorKind),
205205
SeparatelyCached, NoLocationInfo)
206206
SWIFT_REQUEST(TypeChecker, TangentStoredPropertyRequest,
207-
llvm::Expected<VarDecl *>(VarDecl *), Cached, NoLocationInfo)
207+
llvm::Expected<VarDecl *>(VarDecl *, CanType), Cached, NoLocationInfo)
208208
SWIFT_REQUEST(TypeChecker, TypeCheckFunctionBodyRequest,
209209
bool(AbstractFunctionDecl *), Cached, NoLocationInfo)
210210
SWIFT_REQUEST(TypeChecker, TypeCheckFunctionBodyAtLocRequest,

include/swift/Remote/InProcessMemoryReader.h

+2-2
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/SIL/ApplySite.h

+31-1
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121
#ifndef SWIFT_SIL_APPLYSITE_H
2222
#define SWIFT_SIL_APPLYSITE_H
2323

24+
#include "swift/SIL/SILArgument.h"
2425
#include "swift/SIL/SILBasicBlock.h"
25-
#include "swift/SIL/SILInstruction.h"
2626
#include "swift/SIL/SILFunction.h"
27+
#include "swift/SIL/SILInstruction.h"
28+
#include "llvm/ADT/ArrayRef.h"
2729

2830
namespace swift {
2931

@@ -502,6 +504,34 @@ class FullApplySite : public ApplySite {
502504
return getSubstCalleeConv().hasIndirectSILResults();
503505
}
504506

507+
/// If our apply site has a single direct result SILValue, return that
508+
/// SILValue. Return SILValue() otherwise.
509+
///
510+
/// This means that:
511+
///
512+
/// 1. If we have an ApplyInst, we just visit the apply.
513+
/// 2. If we have a TryApplyInst, we visit the first argument of the normal
514+
/// block.
515+
/// 3. If we have a BeginApplyInst, we return SILValue() since the begin_apply
516+
/// yields values instead of returning them. A returned value should only
517+
/// be valid after a full apply site has completely finished executing.
518+
SILValue getSingleDirectResult() const {
519+
switch (getKind()) {
520+
case FullApplySiteKind::ApplyInst:
521+
return SILValue(cast<ApplyInst>(getInstruction()));
522+
case FullApplySiteKind::BeginApplyInst: {
523+
return SILValue();
524+
}
525+
case FullApplySiteKind::TryApplyInst: {
526+
auto *normalBlock = cast<TryApplyInst>(getInstruction())->getNormalBB();
527+
assert(normalBlock->getNumArguments() == 1 &&
528+
"Expected try apply to have a single result");
529+
return normalBlock->getArgument(0);
530+
}
531+
}
532+
llvm_unreachable("Covered switch isn't covered?!");
533+
}
534+
505535
unsigned getNumIndirectSILResults() const {
506536
return getSubstCalleeConv().getNumIndirectSILResults();
507537
}

include/swift/SIL/SILBuilder.h

+37-1
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,8 @@ class SILBuilder {
726726
}
727727

728728
LoadBorrowInst *createLoadBorrow(SILLocation Loc, SILValue LV) {
729-
assert(isLoadableOrOpaque(LV->getType()));
729+
assert(isLoadableOrOpaque(LV->getType()) &&
730+
!LV->getType().isTrivial(getFunction()));
730731
return insert(new (getModule())
731732
LoadBorrowInst(getSILDebugLocation(Loc), LV));
732733
}
@@ -737,11 +738,19 @@ class SILBuilder {
737738
BeginBorrowInst(getSILDebugLocation(Loc), LV));
738739
}
739740

741+
/// Convenience function for creating a load_borrow on non-trivial values and
742+
/// load [trivial] on trivial values. Becomes load unqualified in non-ossa
743+
/// functions.
740744
SILValue emitLoadBorrowOperation(SILLocation loc, SILValue v) {
741745
if (!hasOwnership()) {
742746
return emitLoadValueOperation(loc, v,
743747
LoadOwnershipQualifier::Unqualified);
744748
}
749+
750+
if (v->getType().isTrivial(getFunction())) {
751+
return emitLoadValueOperation(loc, v, LoadOwnershipQualifier::Trivial);
752+
}
753+
745754
return createLoadBorrow(loc, v);
746755
}
747756

@@ -877,6 +886,33 @@ class SILBuilder {
877886
StoreBorrowInst(getSILDebugLocation(Loc), Src, DestAddr));
878887
}
879888

889+
/// A helper function for emitting store_borrow in operations where one must
890+
/// handle both ossa and non-ossa code.
891+
///
892+
/// In words:
893+
///
894+
/// * If the function does not have ownership, this just emits an unqualified
895+
/// store.
896+
///
897+
/// * If the function has ownership, but the type is trivial, use store
898+
/// [trivial].
899+
///
900+
/// * Otherwise, emit an actual store_borrow.
901+
void emitStoreBorrowOperation(SILLocation loc, SILValue src,
902+
SILValue destAddr) {
903+
if (!hasOwnership()) {
904+
return emitStoreValueOperation(loc, src, destAddr,
905+
StoreOwnershipQualifier::Unqualified);
906+
}
907+
908+
if (src->getType().isTrivial(getFunction())) {
909+
return emitStoreValueOperation(loc, src, destAddr,
910+
StoreOwnershipQualifier::Trivial);
911+
}
912+
913+
createStoreBorrow(loc, src, destAddr);
914+
}
915+
880916
MarkUninitializedInst *
881917
createMarkUninitialized(SILLocation Loc, SILValue src,
882918
MarkUninitializedInst::Kind k) {

0 commit comments

Comments
 (0)