Skip to content

Commit 94935b5

Browse files
author
Joe Shajrawi
committed
Large Types IRGen Pass: return large types as @out
1 parent 3061dbe commit 94935b5

File tree

2 files changed

+9
-23
lines changed

2 files changed

+9
-23
lines changed

lib/IRGen/LoadableByAddress.cpp

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ getNewResults(GenericEnvironment *GenericEnv,
156156
ArrayRef<SILResultInfo> origResults, irgen::IRGenModule &Mod) {
157157
// Get new SIL Function results - same as old results UNLESS:
158158
// 1) Function type results might have a different signature
159-
// 2) Large loadables are replaced by empty tuples
159+
// 2) Large loadables are replaced by @out version
160160
SmallVector<SILResultInfo, 2> newResults;
161161
for (auto result : origResults) {
162162
SILType currResultTy = result.getSILStorageType();
@@ -170,10 +170,8 @@ getNewResults(GenericEnvironment *GenericEnv,
170170
newResults.push_back(newResult);
171171
} else if (newSILType != currResultTy) {
172172
// Case (2) Above
173-
auto emptyTy = Mod.getSILModule().Types.getLoweredType(
174-
TupleType::getEmpty(Mod.getSILModule().getASTContext()));
175-
SILResultInfo newSILResultInfo(emptyTy.getSwiftRValueType(),
176-
ResultConvention::Unowned);
173+
SILResultInfo newSILResultInfo(newSILType.getSwiftRValueType(),
174+
ResultConvention::Indirect);
177175
newResults.push_back(newSILResultInfo);
178176
} else {
179177
newResults.push_back(result);
@@ -290,17 +288,6 @@ getNewArgTys(GenericEnvironment *GenericEnv,
290288
SILFunctionType *currSILFunctionType, irgen::IRGenModule &Mod) {
291289
ArrayRef<SILParameterInfo> params = currSILFunctionType->getParameters();
292290
SmallVector<SILParameterInfo, 4> newArgTys;
293-
auto canFuncType = CanSILFunctionType(currSILFunctionType);
294-
if (modResultType(GenericEnv, canFuncType, Mod)) {
295-
// Make a new param
296-
auto singleResult = canFuncType->getSingleResult();
297-
auto resultStorageType = singleResult.getSILStorageType();
298-
assert(resultStorageType.isObject() && "Expected an Object return Type");
299-
auto newType = resultStorageType.getAddressType();
300-
auto newParam = SILParameterInfo(newType.getSwiftRValueType(),
301-
ParameterConvention::Indirect_Inout);
302-
newArgTys.push_back(newParam);
303-
}
304291
for (SILParameterInfo param : params) {
305292
SILType storageType = param.getSILStorageType();
306293
SILType newOptFuncType =
@@ -2016,9 +2003,9 @@ void LoadableByAddress::recreateSingleApply(SILInstruction *applyInst) {
20162003
}
20172004
}
20182005
SILFunctionType *origSILFunctionType = applySite.getSubstCalleeType();
2006+
auto origCanType = CanSILFunctionType(origSILFunctionType);
20192007
Lowering::GenericContextScope GenericScope(
2020-
getModule()->Types,
2021-
CanSILFunctionType(origSILFunctionType)->getGenericSignature());
2008+
getModule()->Types, origCanType->getGenericSignature());
20222009
GenericEnvironment *genEnv = nullptr;
20232010
if (origSILFunctionType->isPolymorphic()) {
20242011
genEnv = getGenericEnvironment(applyInst->getModule(),
@@ -2035,8 +2022,7 @@ void LoadableByAddress::recreateSingleApply(SILInstruction *applyInst) {
20352022
// If we turned a direct result into an indirect parameter
20362023
// Find the new alloc we created earlier.
20372024
// and pass it as first parameter:
2038-
if (origSILFunctionType->getParameters().size() !=
2039-
newSILFunctionType->getParameters().size()) {
2025+
if (modResultType(genEnv, origCanType, *currIRMod)) {
20402026
assert(allApplyRetToAllocMap.find(applyInst) !=
20412027
allApplyRetToAllocMap.end());
20422028
auto newAlloc = allApplyRetToAllocMap[applyInst];

test/IRGen/big_types_corner_cases.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ public func f3_uses_f2() {
5353
}
5454

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

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

7575
public class BigClass {

0 commit comments

Comments
 (0)