[builtin] Remove "unsafeGuaranteed" and related code since Unmanaged now has an Ownership SSA based implementation that works completely in SILGen.

This isn't used in the stdlib anymore as well.
This commit is contained in:
Michael Gottesman
2022-08-19 14:38:20 -07:00
parent 64cfb11e5d
commit 3e52007562
22 changed files with 2 additions and 1237 deletions

View File

@@ -1059,127 +1059,3 @@ bool swift::isARCInertTrapBB(const SILBasicBlock *BB) {
// ARC perspective in an unreachable BB.
return true;
}
//===----------------------------------------------------------------------===//
// Analysis of builtin "unsafeGuaranteed" instructions
//===----------------------------------------------------------------------===//
std::pair<SingleValueInstruction *, SingleValueInstruction *>
swift::getSingleUnsafeGuaranteedValueResult(BuiltinInst *BI) {
assert(BI->getBuiltinKind() &&
*BI->getBuiltinKind() == BuiltinValueKind::UnsafeGuaranteed &&
"Expecting a unsafeGuaranteed builtin");
SingleValueInstruction *GuaranteedValue = nullptr;
SingleValueInstruction *Token = nullptr;
auto Failed = std::make_pair(nullptr, nullptr);
for (auto *Operand : getNonDebugUses(BI)) {
auto *Usr = Operand->getUser();
if (isa<ReleaseValueInst>(Usr) || isa<RetainValueInst>(Usr))
continue;
auto *TE = dyn_cast<TupleExtractInst>(Usr);
if (!TE || TE->getOperand() != BI)
return Failed;
if (TE->getFieldIndex() == 0 && !GuaranteedValue) {
GuaranteedValue = TE;
continue;
}
if (TE->getFieldIndex() == 1 && !Token) {
Token = TE;
continue;
}
return Failed;
}
if (!GuaranteedValue || !Token)
return Failed;
return std::make_pair(GuaranteedValue, Token);
}
BuiltinInst *swift::getUnsafeGuaranteedEndUser(SILValue UnsafeGuaranteedToken) {
BuiltinInst *UnsafeGuaranteedEndI = nullptr;
for (auto *Operand : getNonDebugUses(UnsafeGuaranteedToken)) {
if (UnsafeGuaranteedEndI) {
LLVM_DEBUG(llvm::dbgs() << " multiple unsafeGuaranteedEnd users\n");
UnsafeGuaranteedEndI = nullptr;
break;
}
auto *BI = dyn_cast<BuiltinInst>(Operand->getUser());
if (!BI || !BI->getBuiltinKind() ||
*BI->getBuiltinKind() != BuiltinValueKind::UnsafeGuaranteedEnd) {
LLVM_DEBUG(llvm::dbgs() << " wrong unsafeGuaranteed token user "
<< *Operand->getUser());
break;
}
UnsafeGuaranteedEndI = BI;
}
return UnsafeGuaranteedEndI;
}
static bool hasUnsafeGuaranteedOperand(SILValue UnsafeGuaranteedValue,
SILValue UnsafeGuaranteedValueOperand,
RCIdentityFunctionInfo &RCII,
SILInstruction &Release) {
assert(isa<StrongReleaseInst>(Release) ||
isa<ReleaseValueInst>(Release) && "Expecting a release");
auto RCRoot = RCII.getRCIdentityRoot(Release.getOperand(0));
return RCRoot == UnsafeGuaranteedValue ||
RCRoot == UnsafeGuaranteedValueOperand;
}
SILInstruction *swift::findReleaseToMatchUnsafeGuaranteedValue(
SILInstruction *UnsafeGuaranteedEndI, SILInstruction *UnsafeGuaranteedI,
SILValue UnsafeGuaranteedValue, SILBasicBlock &BB,
RCIdentityFunctionInfo &RCFI) {
auto UnsafeGuaranteedRoot = RCFI.getRCIdentityRoot(UnsafeGuaranteedValue);
auto UnsafeGuaranteedOpdRoot =
RCFI.getRCIdentityRoot(UnsafeGuaranteedI->getOperand(0));
// Try finding it after the "unsafeGuaranteedEnd".
for (auto ForwardIt = std::next(UnsafeGuaranteedEndI->getIterator()),
End = BB.end();
ForwardIt != End; ++ForwardIt) {
SILInstruction &CurInst = *ForwardIt;
// Is this a release?
if (isa<ReleaseValueInst>(CurInst) || isa<StrongReleaseInst>(CurInst)) {
if (hasUnsafeGuaranteedOperand(UnsafeGuaranteedRoot,
UnsafeGuaranteedOpdRoot, RCFI, CurInst))
return &CurInst;
continue;
}
if (CurInst.mayHaveSideEffects() && !DebugValueInst::hasAddrVal(&CurInst))
break;
}
// Otherwise, Look before the "unsafeGuaranteedEnd".
for (auto ReverseIt = ++UnsafeGuaranteedEndI->getIterator().getReverse(),
End = BB.rend();
ReverseIt != End; ++ReverseIt) {
SILInstruction &CurInst = *ReverseIt;
// Is this a release?
if (isa<ReleaseValueInst>(CurInst) || isa<StrongReleaseInst>(CurInst)) {
if (hasUnsafeGuaranteedOperand(UnsafeGuaranteedRoot,
UnsafeGuaranteedOpdRoot, RCFI, CurInst))
return &CurInst;
continue;
}
if (CurInst.mayHaveSideEffects() && !DebugValueInst::hasAddrVal(&CurInst))
break;
}
return nullptr;
}