Skip to content

Commit 081171c

Browse files
authored
Merge pull request #31094 from davezarzycki/pr31094
[SILOptimizer] Do not hardcode `unowned` for loadable ref storage types
2 parents 49ca2d0 + e2c4aa1 commit 081171c

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -781,10 +781,13 @@ SILInstruction *SILCombiner::visitReleaseValueInst(ReleaseValueInst *RVI) {
781781
}
782782
}
783783

784-
// ReleaseValueInst of an unowned type is an unowned_release.
785-
if (OperandTy.is<UnownedStorageType>())
786-
return Builder.createUnownedRelease(RVI->getLoc(), Operand,
784+
// ReleaseValueInst of a loadable reference storage type needs the
785+
// corresponding release instruction.
786+
#define ALWAYS_OR_SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
787+
if (OperandTy.is<Name##StorageType>()) \
788+
return Builder.create##Name##Release(RVI->getLoc(), Operand, \
787789
RVI->getAtomicity());
790+
#include "swift/AST/ReferenceStorage.def"
788791

789792
// ReleaseValueInst of a reference type is a strong_release.
790793
if (OperandTy.isReferenceCounted(RVI->getModule()))
@@ -821,10 +824,13 @@ SILInstruction *SILCombiner::visitRetainValueInst(RetainValueInst *RVI) {
821824
}
822825
}
823826

824-
// RetainValueInst of an unowned type is an unowned_retain.
825-
if (OperandTy.is<UnownedStorageType>())
826-
return Builder.createUnownedRetain(RVI->getLoc(), Operand,
827+
// RetainValueInst of a loadable reference storage type needs the
828+
// corresponding retain instruction.
829+
#define ALWAYS_OR_SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
830+
if (OperandTy.is<Name##StorageType>()) \
831+
return Builder.create##Name##Retain(RVI->getLoc(), Operand, \
827832
RVI->getAtomicity());
833+
#include "swift/AST/ReferenceStorage.def"
828834

829835
// RetainValueInst of a reference type is a strong_release.
830836
if (OperandTy.isReferenceCounted(RVI->getModule())) {

lib/SILOptimizer/Utils/InstOptUtils.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@ swift::createIncrementBefore(SILValue ptr, SILInstruction *insertPt) {
5858
// If Ptr is refcounted itself, create the strong_retain and
5959
// return.
6060
if (ptr->getType().isReferenceCounted(builder.getModule())) {
61-
if (ptr->getType().is<UnownedStorageType>())
62-
return builder.createUnownedRetain(loc, ptr,
63-
builder.getDefaultAtomicity());
64-
else
65-
return builder.createStrongRetain(loc, ptr,
66-
builder.getDefaultAtomicity());
61+
#define ALWAYS_OR_SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
62+
if (ptr->getType().is<Name##StorageType>()) \
63+
return builder.create##Name##Retain(loc, ptr, \
64+
builder.getDefaultAtomicity());
65+
#include "swift/AST/ReferenceStorage.def"
66+
67+
return builder.createStrongRetain(loc, ptr,
68+
builder.getDefaultAtomicity());
6769
}
6870

6971
// Otherwise, create the retain_value.
@@ -85,12 +87,14 @@ swift::createDecrementBefore(SILValue ptr, SILInstruction *insertPt) {
8587

8688
// If ptr has reference semantics itself, create a strong_release.
8789
if (ptr->getType().isReferenceCounted(builder.getModule())) {
88-
if (ptr->getType().is<UnownedStorageType>())
89-
return builder.createUnownedRelease(loc, ptr,
90+
#define ALWAYS_OR_SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
91+
if (ptr->getType().is<Name##StorageType>()) \
92+
return builder.create##Name##Release(loc, ptr, \
9093
builder.getDefaultAtomicity());
91-
else
92-
return builder.createStrongRelease(loc, ptr,
93-
builder.getDefaultAtomicity());
94+
#include "swift/AST/ReferenceStorage.def"
95+
96+
return builder.createStrongRelease(loc, ptr,
97+
builder.getDefaultAtomicity());
9498
}
9599

96100
// Otherwise create a release value.

0 commit comments

Comments
 (0)