Skip to content

Large Types IRGen Pass: return large types as @out #11023

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 1 commit into from
Jul 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 6 additions & 20 deletions lib/IRGen/LoadableByAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ getNewResults(GenericEnvironment *GenericEnv,
ArrayRef<SILResultInfo> origResults, irgen::IRGenModule &Mod) {
// Get new SIL Function results - same as old results UNLESS:
// 1) Function type results might have a different signature
// 2) Large loadables are replaced by empty tuples
// 2) Large loadables are replaced by @out version
SmallVector<SILResultInfo, 2> newResults;
for (auto result : origResults) {
SILType currResultTy = result.getSILStorageType();
Expand All @@ -170,10 +170,8 @@ getNewResults(GenericEnvironment *GenericEnv,
newResults.push_back(newResult);
} else if (newSILType != currResultTy) {
// Case (2) Above
auto emptyTy = Mod.getSILModule().Types.getLoweredType(
TupleType::getEmpty(Mod.getSILModule().getASTContext()));
SILResultInfo newSILResultInfo(emptyTy.getSwiftRValueType(),
ResultConvention::Unowned);
SILResultInfo newSILResultInfo(newSILType.getSwiftRValueType(),
ResultConvention::Indirect);
newResults.push_back(newSILResultInfo);
} else {
newResults.push_back(result);
Expand Down Expand Up @@ -290,17 +288,6 @@ getNewArgTys(GenericEnvironment *GenericEnv,
SILFunctionType *currSILFunctionType, irgen::IRGenModule &Mod) {
ArrayRef<SILParameterInfo> params = currSILFunctionType->getParameters();
SmallVector<SILParameterInfo, 4> newArgTys;
auto canFuncType = CanSILFunctionType(currSILFunctionType);
if (modResultType(GenericEnv, canFuncType, Mod)) {
// Make a new param
auto singleResult = canFuncType->getSingleResult();
auto resultStorageType = singleResult.getSILStorageType();
assert(resultStorageType.isObject() && "Expected an Object return Type");
auto newType = resultStorageType.getAddressType();
auto newParam = SILParameterInfo(newType.getSwiftRValueType(),
ParameterConvention::Indirect_Inout);
newArgTys.push_back(newParam);
}
for (SILParameterInfo param : params) {
SILType storageType = param.getSILStorageType();
SILType newOptFuncType =
Expand Down Expand Up @@ -2016,9 +2003,9 @@ void LoadableByAddress::recreateSingleApply(SILInstruction *applyInst) {
}
}
SILFunctionType *origSILFunctionType = applySite.getSubstCalleeType();
auto origCanType = CanSILFunctionType(origSILFunctionType);
Lowering::GenericContextScope GenericScope(
getModule()->Types,
CanSILFunctionType(origSILFunctionType)->getGenericSignature());
getModule()->Types, origCanType->getGenericSignature());
GenericEnvironment *genEnv = nullptr;
if (origSILFunctionType->isPolymorphic()) {
genEnv = getGenericEnvironment(applyInst->getModule(),
Expand All @@ -2035,8 +2022,7 @@ void LoadableByAddress::recreateSingleApply(SILInstruction *applyInst) {
// If we turned a direct result into an indirect parameter
// Find the new alloc we created earlier.
// and pass it as first parameter:
if (origSILFunctionType->getParameters().size() !=
newSILFunctionType->getParameters().size()) {
if (modResultType(genEnv, origCanType, *currIRMod)) {
assert(allApplyRetToAllocMap.find(applyInst) !=
allApplyRetToAllocMap.end());
auto newAlloc = allApplyRetToAllocMap[applyInst];
Expand Down
6 changes: 3 additions & 3 deletions test/IRGen/big_types_corner_cases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public func f3_uses_f2() {
}

// CHECK-LABEL: define{{( protected)?}} swiftcc void @_T022big_types_corner_cases10f3_uses_f2yyF()
// CHECK:call swiftcc void @_T022big_types_corner_cases9BigStructVACycfC(%T22big_types_corner_cases9BigStructV* nocapture dereferenceable
// CHECK: call swiftcc void @_T022big_types_corner_cases9BigStructVACycfC(%T22big_types_corner_cases9BigStructV* noalias nocapture sret
// CHECK: call swiftcc { i8*, %swift.refcounted* } @_T022big_types_corner_cases13f2_returns_f1AA9BigStructVADcyF()
// CHECK: call swiftcc void {{.*}}(%T22big_types_corner_cases9BigStructV* nocapture dereferenceable({{.*}}) {{.*}}, %T22big_types_corner_cases9BigStructV* noalias nocapture dereferenceable({{.*}}) {{.*}}, %swift.refcounted* swiftself {{.*}})
// CHECK: call swiftcc void {{.*}}(%T22big_types_corner_cases9BigStructV* noalias nocapture sret {{.*}}, %T22big_types_corner_cases9BigStructV* noalias nocapture dereferenceable({{.*}}) {{.*}}, %swift.refcounted* swiftself {{.*}})
// CHECK: ret void

public func f4_tuple_use_of_f2() {
Expand All @@ -69,7 +69,7 @@ public func f4_tuple_use_of_f2() {
// CHECK: [[TUPLE:%.*]] = call swiftcc { i8*, %swift.refcounted* } @_T022big_types_corner_cases13f2_returns_f1AA9BigStructVADcyF()
// CHECK: [[TUPLE_EXTRACT:%.*]] = extractvalue { i8*, %swift.refcounted* } [[TUPLE]], 0
// CHECK: [[CAST_EXTRACT:%.*]] = bitcast i8* [[TUPLE_EXTRACT]] to void (%T22big_types_corner_cases9BigStructV*, %T22big_types_corner_cases9BigStructV*, %swift.refcounted*)*
// CHECK: call swiftcc void [[CAST_EXTRACT]](%T22big_types_corner_cases9BigStructV* nocapture dereferenceable({{.*}}) {{.*}}, %T22big_types_corner_cases9BigStructV* noalias nocapture dereferenceable({{.*}}) {{.*}}, %swift.refcounted* swiftself %{{.*}})
// CHECK: call swiftcc void [[CAST_EXTRACT]](%T22big_types_corner_cases9BigStructV* noalias nocapture sret {{.*}}, %T22big_types_corner_cases9BigStructV* noalias nocapture dereferenceable({{.*}}) {{.*}}, %swift.refcounted* swiftself %{{.*}})
// CHECK: ret void

public class BigClass {
Expand Down