Skip to content

Commit 9e218fc

Browse files
Merge pull request swiftlang#79201 from aschwaighofer/pr143456806
IRGen: Replace retail_value_addr implementation by destroy_addr's
2 parents 407451d + 056e18c commit 9e218fc

File tree

5 files changed

+47
-46
lines changed

5 files changed

+47
-46
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5404,18 +5404,14 @@ void IRGenSILFunction::visitRetainValueInst(swift::RetainValueInst *i) {
54045404
void IRGenSILFunction::visitRetainValueAddrInst(swift::RetainValueAddrInst *i) {
54055405
SILValue operandValue = i->getOperand();
54065406
assert(!operandValue->getType().isMoveOnly());
5407-
Address addr = getLoweredAddress(operandValue);
5408-
SILType addrTy = operandValue->getType();
5409-
SILType objectT = addrTy.getObjectType();
5410-
llvm::Type *llvmType = addr.getAddress()->getType();
5411-
const TypeInfo &addrTI = getTypeInfo(addrTy);
5412-
auto atomicity = i->isAtomic() ? Atomicity::Atomic : Atomicity::NonAtomic;
5413-
auto *outlinedF = cast<llvm::Function>(
5414-
IGM.getOrCreateRetainFunction(addrTI, objectT, llvmType, atomicity));
5415-
llvm::Value *args[] = {addr.getAddress()};
5416-
llvm::CallInst *call =
5417-
Builder.CreateCall(outlinedF->getFunctionType(), outlinedF, args);
5418-
call->setCallingConv(IGM.DefaultCC);
5407+
5408+
auto objTy = operandValue->getType().getObjectType();
5409+
const TypeInfo &type = getTypeInfo(objTy);
5410+
auto stackAddr = type.allocateStack(*this, objTy, "retain.value.addr.tmp");
5411+
Address src = getLoweredAddress(operandValue);
5412+
type.initializeWithCopy(*this, stackAddr.getAddress(), src,
5413+
operandValue->getType(), false);
5414+
type.deallocateStack(*this, stackAddr, operandValue->getType());
54195415
}
54205416

54215417
void IRGenSILFunction::visitCopyValueInst(swift::CopyValueInst *i) {
@@ -5494,15 +5490,10 @@ void IRGenSILFunction::visitReleaseValueInst(swift::ReleaseValueInst *i) {
54945490
void IRGenSILFunction::visitReleaseValueAddrInst(
54955491
swift::ReleaseValueAddrInst *i) {
54965492
SILValue operandValue = i->getOperand();
5497-
Address addr = getLoweredAddress(operandValue);
54985493
SILType addrTy = operandValue->getType();
5499-
SILType objectT = addrTy.getObjectType();
5500-
if (tryEmitDestroyUsingDeinit(*this, addr, addrTy)) {
5501-
return;
5502-
}
55035494
const TypeInfo &addrTI = getTypeInfo(addrTy);
5504-
auto atomicity = i->isAtomic() ? Atomicity::Atomic : Atomicity::NonAtomic;
5505-
addrTI.callOutlinedRelease(*this, addr, objectT, atomicity);
5495+
Address base = getLoweredAddress(operandValue);
5496+
addrTI.destroy(*this, base, addrTy, false /*isOutlined*/);
55065497
}
55075498

55085499
void IRGenSILFunction::visitDestroyValueInst(swift::DestroyValueInst *i) {

test/IRGen/big_types_tests.sil

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public struct BigStruct {
2121

2222
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @testDestroyValue(ptr noalias nocapture dereferenceable({{.*}}) #0 {
2323
// CHECK-NEXT: entry
24-
// CHECK-NEXT: call ptr @"$s15big_types_tests9BigStructVWOs"(ptr %0)
2524
// CHECK-NEXT: ret void
2625
sil @testDestroyValue : $@convention(thin) (@owned BigStruct) -> () {
2726
entry(%x : $BigStruct):

test/IRGen/moveonly_deinit.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ entry(%b : $*MOEnum):
209209

210210
// CHECK-LABEL: define{{.*}}@destroy_combo_struct_value(
211211
// CHECK-NEXT: entry:
212-
// CHECK-NEXT: call {{.*}} @[[COMBO_STRUCT_OUTLINED_DESTROY:"\$.*13MOComboStructVWOs"]](
212+
// CHECK-NEXT: call {{.*}} @[[COMBO_STRUCT_OUTLINED_DESTROY:"\$.*13MOComboStructVWOh"]](
213213
// CHECK-NEXT: ret void
214214
sil @destroy_combo_struct_value : $@convention(thin) (@owned MOComboStruct) -> () {
215215
entry(%b : $MOComboStruct):

test/IRGen/moveonly_value_functions.swift

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,16 @@ public func takeOuterDeinitingNC_1<T>(_ t: consuming OuterDeinitingNC_1<T>) {
177177
// CHECK-SAME: ptr{{.*}} %0,
178178
// CHECK-SAME: ptr %T)
179179
// CHECK-SAME: {
180-
// CHECK: call{{.*}} @"$s24moveonly_value_functions9OuterNC_1VyxGlWOs"(
180+
// CHECK: call{{.*}} @"$s24moveonly_value_functions9OuterNC_1VyxGlWOh"(
181181
// CHECK-SAME: ptr %0,
182182
// CHECK-SAME: ptr %T)
183183
// CHECK: }
184184

185185
// Verify that the outlined release function takes the metadata for the
186186
// move-only-with-deinit type InnerDeinitingReleasableNC<T> and passes it along
187187
// to that deinit.
188-
// $s24moveonly_value_functions9OuterNC_1VyxGlWOs ---> outlined release of moveonly_value_functions.OuterNC_2<A>
189-
// CHECK-LABEL: define{{.*}} @"$s24moveonly_value_functions9OuterNC_1VyxGlWOs"(
188+
// $s24moveonly_value_functions9OuterNC_1VyxGlWOh ---> outlined destroy of moveonly_value_functions.OuterNC_2<A>
189+
// CHECK-LABEL: define{{.*}} @"$s24moveonly_value_functions9OuterNC_1VyxGlWOh"(
190190
// CHECK-SAME: ptr %0,
191191
// CHECK-SAME: ptr %T)
192192
// CHECK-SAME: {
@@ -298,24 +298,15 @@ public func takeOuterSinglePayloadNC_1<T>(_ e: consuming OuterSinglePayloadNC_1<
298298
// : ptr noalias nocapture dereferenceable(64) %0,
299299
// CHECK-SAME: ptr %T)
300300
// CHECK-SAME: {
301-
// CHECK: call{{.*}} @"$s24moveonly_value_functions22OuterSinglePayloadNC_2OyxGlWOs"(
301+
// CHECK: call{{.*}} @"$s24moveonly_value_functions22OuterSinglePayloadNC_2OyxGlWOh"(
302302
// CHECK-SAME: ptr %0,
303303
// CHECK-SAME: ptr %T)
304304
// CHECK: }
305-
// CHECK-LABEL: define{{.*}} @"$s24moveonly_value_functions22OuterSinglePayloadNC_2OyxGlWOs"(
305+
// CHECK-LABEL: define{{.*}} @"$s24moveonly_value_functions22OuterSinglePayloadNC_2OyxGlWOh"(
306306
// CHECK-SAME: ptr %0,
307307
// CHECK-SAME: ptr %T)
308308
// CHECK-SAME: {
309-
// CHECK: call{{.*}} @"$s24moveonly_value_functions22OuterSinglePayloadNC_2OyxGlWOe"(
310-
// : i64 %2,
311-
// : i64 %4,
312-
// : i64 %6,
313-
// : i64 %8,
314-
// : i64 %10,
315-
// : i64 %12,
316-
// : i64 %14,
317-
// : i64 %16,
318-
// : ptr %T)
309+
// CHECK: call{{.*}} @"$s24moveonly_value_functions26InnerDeinitingReleasableNCVfD"(
319310
// CHECK: }
320311
public func takeOuterSinglePayloadNC_2<T>(_ e: consuming OuterSinglePayloadNC_2<T>) {}
321312

@@ -400,23 +391,15 @@ public func takeOuterMultiPayloadNC_2<T>(_ e: consuming OuterMultiPayloadNC_2<T>
400391
// : ptr noalias nocapture dereferenceable(64) %0,
401392
// CHECK-SAME: ptr %T)
402393
// CHECK-SAME: {
403-
// CHECK: call{{.*}} @"$s24moveonly_value_functions21OuterMultiPayloadNC_3OyxGlWOs"(
394+
// CHECK: call{{.*}} @"$s24moveonly_value_functions21OuterMultiPayloadNC_3OyxGlWOh"(
404395
// CHECK-SAME: ptr %0,
405396
// CHECK-SAME: ptr %T)
406397
// CHECK: }
407-
// CHECK-LABEL: define{{.*}} @"$s24moveonly_value_functions21OuterMultiPayloadNC_3OyxGlWOs"(
398+
// CHECK-LABEL: define{{.*}} @"$s24moveonly_value_functions21OuterMultiPayloadNC_3OyxGlWOh"(
408399
// CHECK-SAME: ptr %0,
409400
// CHECK-SAME: ptr %T)
410401
// CHECK-SAME: {
411402
// CHECK: call{{.*}} @"$s24moveonly_value_functions21OuterMultiPayloadNC_3OyxGlWOe"(
412-
// : i64 %2,
413-
// : i64 %4,
414-
// : i64 %6,
415-
// : i64 %8,
416-
// : i64 %10,
417-
// : i64 %12,
418-
// : i64 %14,
419-
// : i64 %16,
420403
// CHECK-SAME: ptr %T)
421404
// CHECK: }
422405
public func takeOuterMultiPayloadNC_3<T>(_ e: consuming OuterMultiPayloadNC_3<T>) {}

test/IRGen/variadic_generic_outlining.sil

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,31 @@ bb3:
4545
%ret = tuple ()
4646
return %ret : $()
4747
}
48+
49+
sil hidden @test_outlining_retain_release_addr : $@convention(thin) <each T> (@pack_guaranteed Pack{repeat Wrapper<each T>}) -> @pack_out Pack{repeat Wrapper<each T>} {
50+
bb0(%0 : $*Pack{repeat Wrapper<each T>}, %1 : $*Pack{repeat Wrapper<each T>}):
51+
%zero = integer_literal $Builtin.Word, 0
52+
%one = integer_literal $Builtin.Word, 1
53+
%len = pack_length $Pack{repeat each T}
54+
br bb1(%zero : $Builtin.Word)
55+
56+
bb1(%idx : $Builtin.Word):
57+
%done = builtin "cmp_eq_Word"(%idx : $Builtin.Word, %len : $Builtin.Word) : $Builtin.Int1 // user: %10
58+
cond_br %done, bb3, bb2
59+
60+
bb2:
61+
%pi = dynamic_pack_index %idx of $Pack{repeat Wrapper<each T>}
62+
%opening = open_pack_element %pi of <each T> at <Pack{repeat each T}>, shape $T, uuid "31FF306C-BF88-11ED-A03F-ACDE48001123"
63+
%in = pack_element_get %pi of %0 : $*Pack{repeat Wrapper<each T>} as $*Wrapper<@pack_element("31FF306C-BF88-11ED-A03F-ACDE48001123") T>
64+
%out = pack_element_get %pi of %1 : $*Pack{repeat Wrapper<each T>} as $*Wrapper<@pack_element("31FF306C-BF88-11ED-A03F-ACDE48001123") T>
65+
// Make sure that these don't crash.
66+
retain_value_addr %in : $*Wrapper<@pack_element("31FF306C-BF88-11ED-A03F-ACDE48001123") T>
67+
release_value_addr %in : $*Wrapper<@pack_element("31FF306C-BF88-11ED-A03F-ACDE48001123") T>
68+
copy_addr %in to [init] %out : $*Wrapper<@pack_element("31FF306C-BF88-11ED-A03F-ACDE48001123") T>
69+
%next = builtin "add_Word"(%idx : $Builtin.Word, %one : $Builtin.Word) : $Builtin.Word
70+
br bb1(%next : $Builtin.Word)
71+
72+
bb3:
73+
%ret = tuple ()
74+
return %ret : $()
75+
}

0 commit comments

Comments
 (0)