Skip to content

Commit da67a99

Browse files
Merge pull request #5537 from swiftwasm/katei/merge-main-2023-06-20
Merge main 2023-06-20
2 parents 6aa2733 + d6a4123 commit da67a99

21 files changed

+222
-64
lines changed

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,14 @@ elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "ANDROID")
10481048
set(SWIFT_PRIMARY_VARIANT_SDK_default "${SWIFT_HOST_VARIANT_SDK}")
10491049
set(SWIFT_PRIMARY_VARIANT_ARCH_default "${SWIFT_HOST_VARIANT_ARCH}")
10501050

1051+
elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "WASI")
1052+
set(SWIFT_HOST_VARIANT "wasi" CACHE STRING
1053+
"Deployment OS for Swift host tools (the compiler) [wasi]")
1054+
1055+
configure_sdk_unix("WASI" "wasm32")
1056+
set(SWIFT_PRIMARY_VARIANT_SDK_default "${SWIFT_HOST_VARIANT_SDK}")
1057+
set(SWIFT_PRIMARY_VARIANT_ARCH_default "${SWIFT_HOST_VARIANT_ARCH}")
1058+
10511059
elseif("${SWIFT_HOST_VARIANT_SDK}" MATCHES "(OSX|IOS*|TVOS*|WATCHOS*)")
10521060

10531061
set(SWIFT_HOST_VARIANT "macosx" CACHE STRING

include/swift/AST/IRGenOptions.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "swift/Basic/OptimizationMode.h"
2626
#include "swift/Config.h"
2727
#include "clang/Basic/PointerAuthOptions.h"
28+
#include "llvm/IR/CallingConv.h"
2829
// FIXME: This include is just for llvm::SanitizerCoverageOptions. We should
2930
// split the header upstream so we don't include so much.
3031
#include "llvm/Transforms/Instrumentation.h"
@@ -477,6 +478,9 @@ class IRGenOptions {
477478
/// function instead of to trap instructions.
478479
std::string TrapFuncName = "";
479480

481+
/// The calling convention used to perform non-swift calls.
482+
llvm::CallingConv::ID PlatformCCallingConvention;
483+
480484
IRGenOptions()
481485
: DWARFVersion(2),
482486
OutputKind(IRGenOutputKind::LLVMAssemblyAfterOptimization),
@@ -517,7 +521,8 @@ class IRGenOptions {
517521
ColocateTypeDescriptors(true),
518522
UseRelativeProtocolWitnessTables(false), CmdArgs(),
519523
SanitizeCoverage(llvm::SanitizerCoverageOptions()),
520-
TypeInfoFilter(TypeInfoDumpFilter::All) {
524+
TypeInfoFilter(TypeInfoDumpFilter::All),
525+
PlatformCCallingConvention(llvm::CallingConv::C) {
521526
#ifndef NDEBUG
522527
DisableRoundTripDebugTypes = false;
523528
#else

include/swift/Option/FrontendOptions.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,4 +1224,12 @@ def experimental_spi_only_imports :
12241224
def enable_ossa_complete_lifetimes :
12251225
Flag<["-"], "enable-ossa-complete-lifetimes">,
12261226
HelpText<"Require linear OSSA lifetimes after SILGen">;
1227+
1228+
def platform_c_calling_convention :
1229+
Separate<["-"], "experimental-platform-c-calling-convention">,
1230+
HelpText<"Which calling convention is used to perform non-swift calls. "
1231+
"Defaults to llvm's standard C calling convention.">;
1232+
def platform_c_calling_convention_EQ :
1233+
Joined<["-"], "experimental-platform-c-calling-convention=">,
1234+
Alias<platform_c_calling_convention>;
12271235
} // end let Flags = [FrontendOption, NoDriverOption, HelpHidden]

include/swift/Sema/Constraint.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,12 @@ enum class ConstraintKind : char {
186186
/// constraint.
187187
OneWayBindParam,
188188
/// If there is no contextual info e.g. `_ = { 42 }` default first type
189-
/// to a second type (inferred closure type). This is effectively a
190-
/// `Defaultable` constraint which a couple of differences:
189+
/// to a second type. This is effectively a `Defaultable` constraint
190+
/// which one significant difference:
191191
///
192-
/// - References inferred closure type and all of the outer parameters
193-
/// referenced by closure body.
194192
/// - Handled specially by binding inference, specifically contributes
195193
/// to the bindings only if there are no contextual types available.
196-
DefaultClosureType,
194+
FallbackType,
197195
/// The first type represents a result of an unresolved member chain,
198196
/// and the second type is its base type. This constraint acts almost
199197
/// like `Equal` but also enforces following semantics:
@@ -701,7 +699,7 @@ class Constraint final : public llvm::ilist_node<Constraint>,
701699
case ConstraintKind::OptionalObject:
702700
case ConstraintKind::OneWayEqual:
703701
case ConstraintKind::OneWayBindParam:
704-
case ConstraintKind::DefaultClosureType:
702+
case ConstraintKind::FallbackType:
705703
case ConstraintKind::UnresolvedMemberChainBase:
706704
case ConstraintKind::PackElementOf:
707705
case ConstraintKind::SameShape:

include/swift/Sema/ConstraintSystem.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4852,11 +4852,12 @@ class ConstraintSystem {
48524852
TypeMatchOptions flags,
48534853
ConstraintLocatorBuilder locator);
48544854

4855-
/// Attempt to simplify the given defaultable closure type constraint.
4856-
SolutionKind simplifyDefaultClosureTypeConstraint(
4857-
Type closureType, Type inferredType,
4858-
ArrayRef<TypeVariableType *> referencedOuterParameters,
4859-
TypeMatchOptions flags, ConstraintLocatorBuilder locator);
4855+
/// Attempt to simplify the given fallback type constraint.
4856+
SolutionKind
4857+
simplifyFallbackTypeConstraint(Type defaultableType, Type fallbackType,
4858+
ArrayRef<TypeVariableType *> referencedVars,
4859+
TypeMatchOptions flags,
4860+
ConstraintLocatorBuilder locator);
48604861

48614862
/// Attempt to simplify a property wrapper constraint.
48624863
SolutionKind simplifyPropertyWrapperConstraint(Type wrapperType, Type wrappedValueType,

lib/Frontend/CompilerInvocation.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2807,6 +2807,16 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
28072807
return true;
28082808
}
28092809

2810+
if (const Arg *A = Args.getLastArg(options::OPT_platform_c_calling_convention)) {
2811+
Opts.PlatformCCallingConvention =
2812+
llvm::StringSwitch<llvm::CallingConv::ID>(A->getValue())
2813+
.Case("c", llvm::CallingConv::C)
2814+
.Case("arm_apcs", llvm::CallingConv::ARM_APCS)
2815+
.Case("arm_aapcs", llvm::CallingConv::ARM_AAPCS)
2816+
.Case("arm_aapcs_vfp", llvm::CallingConv::ARM_AAPCS_VFP)
2817+
.Default(llvm::CallingConv::C);
2818+
}
2819+
28102820
return false;
28112821
}
28122822

lib/IRGen/GenCall.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ llvm::CallingConv::ID irgen::expandCallingConv(IRGenModule &IGM,
322322
case SILFunctionTypeRepresentation::ObjCMethod:
323323
case SILFunctionTypeRepresentation::CXXMethod:
324324
case SILFunctionTypeRepresentation::Block:
325-
return llvm::CallingConv::C;
325+
return IGM.getOptions().PlatformCCallingConvention;
326326

327327
case SILFunctionTypeRepresentation::Method:
328328
case SILFunctionTypeRepresentation::WitnessMethod:

lib/IRGen/GenDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3297,7 +3297,7 @@ llvm::Constant *swift::irgen::emitCXXConstructorThunkIfNeeded(
32973297
llvm::Function *thunk = llvm::Function::Create(
32983298
assumedFnType, llvm::Function::PrivateLinkage, name, &IGM.Module);
32993299

3300-
thunk->setCallingConv(llvm::CallingConv::C);
3300+
thunk->setCallingConv(IGM.getOptions().PlatformCCallingConvention);
33013301

33023302
llvm::AttrBuilder attrBuilder(IGM.getLLVMContext());
33033303
IGM.constructInitialFnAttributes(attrBuilder);

lib/IRGen/GenHeap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1978,7 +1978,7 @@ emitHeapMetadataRefForUnknownHeapObject(IRGenFunction &IGF,
19781978
auto metadata = IGF.Builder.CreateCall(
19791979
IGF.IGM.getGetObjectClassFunctionPointer(), object);
19801980
metadata->setName(object->getName() + ".Type");
1981-
metadata->setCallingConv(llvm::CallingConv::C);
1981+
metadata->setCallingConv(IGF.IGM.getOptions().PlatformCCallingConvention);
19821982
metadata->setDoesNotThrow();
19831983
metadata->addFnAttr(llvm::Attribute::ReadOnly);
19841984
return metadata;

lib/IRGen/IRGenModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ IRGenModule::IRGenModule(IRGenerator &irgen,
570570
InvariantNode = llvm::MDNode::get(getLLVMContext(), {});
571571
DereferenceableID = getLLVMContext().getMDKindID("dereferenceable");
572572

573-
C_CC = llvm::CallingConv::C;
573+
C_CC = getOptions().PlatformCCallingConvention;
574574
// TODO: use "tinycc" on platforms that support it
575575
DefaultCC = SWIFT_DEFAULT_LLVM_CC;
576576
SwiftCC = llvm::CallingConv::Swift;

0 commit comments

Comments
 (0)