Skip to content

[SILOptimizer] Do not hardcode unowned for loadable ref storage types #31094

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
Apr 21, 2020
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
18 changes: 12 additions & 6 deletions lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -781,10 +781,13 @@ SILInstruction *SILCombiner::visitReleaseValueInst(ReleaseValueInst *RVI) {
}
}

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

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

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

// RetainValueInst of a reference type is a strong_release.
if (OperandTy.isReferenceCounted(RVI->getModule())) {
Expand Down
26 changes: 15 additions & 11 deletions lib/SILOptimizer/Utils/InstOptUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ swift::createIncrementBefore(SILValue ptr, SILInstruction *insertPt) {
// If Ptr is refcounted itself, create the strong_retain and
// return.
if (ptr->getType().isReferenceCounted(builder.getModule())) {
if (ptr->getType().is<UnownedStorageType>())
return builder.createUnownedRetain(loc, ptr,
builder.getDefaultAtomicity());
else
return builder.createStrongRetain(loc, ptr,
builder.getDefaultAtomicity());
#define ALWAYS_OR_SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
if (ptr->getType().is<Name##StorageType>()) \
return builder.create##Name##Retain(loc, ptr, \
builder.getDefaultAtomicity());
#include "swift/AST/ReferenceStorage.def"

return builder.createStrongRetain(loc, ptr,
builder.getDefaultAtomicity());
}

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

// If ptr has reference semantics itself, create a strong_release.
if (ptr->getType().isReferenceCounted(builder.getModule())) {
if (ptr->getType().is<UnownedStorageType>())
return builder.createUnownedRelease(loc, ptr,
#define ALWAYS_OR_SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
if (ptr->getType().is<Name##StorageType>()) \
return builder.create##Name##Release(loc, ptr, \
builder.getDefaultAtomicity());
else
return builder.createStrongRelease(loc, ptr,
builder.getDefaultAtomicity());
#include "swift/AST/ReferenceStorage.def"

return builder.createStrongRelease(loc, ptr,
builder.getDefaultAtomicity());
}

// Otherwise create a release value.
Expand Down