Skip to content

Commit 4a85e18

Browse files
committed
Eliminate unused and incomplete OSSA logic.
1 parent 8062e40 commit 4a85e18

File tree

2 files changed

+0
-229
lines changed

2 files changed

+0
-229
lines changed

include/swift/SILOptimizer/Utils/OwnershipOptUtils.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,6 @@ struct OwnershipFixupContext {
153153
// used again to extend the lifetime of the replacement value.
154154
SmallVector<Operand *, 8> guaranteedUsePoints;
155155

156-
// FIXME: remove these two vectors once BorrowedLifetimeExtender is used
157-
// everywhere.
158-
SmallVector<Operand *, 8> transitiveBorrowedUses;
159-
SmallVector<PhiOperand, 8> recursiveReborrows;
160-
161156
/// Extra state initialized by OwnershipRAUWFixupHelper::get() that we use
162157
/// when RAUWing addresses. This ensures we do not need to recompute this
163158
/// state when we perform the actual RAUW.
@@ -191,8 +186,6 @@ struct OwnershipFixupContext {
191186

192187
void clear() {
193188
guaranteedUsePoints.clear();
194-
transitiveBorrowedUses.clear();
195-
recursiveReborrows.clear();
196189
extraAddressFixupInfo.allAddressUsesFromOldValue.clear();
197190
extraAddressFixupInfo.base = AccessBase();
198191
}

lib/SILOptimizer/Utils/OwnershipOptUtils.cpp

Lines changed: 0 additions & 222 deletions
Original file line numberDiff line numberDiff line change
@@ -286,37 +286,6 @@ static void cleanupOperandsBeforeDeletion(SILInstruction *oldValue,
286286
}
287287
}
288288

289-
static SILPhiArgument *
290-
insertOwnedBaseValueAlongBranchEdge(BranchInst *bi, SILValue innerCopy,
291-
InstModCallbacks &callbacks) {
292-
auto *destBB = bi->getDestBB();
293-
// We need to create the phi argument before calling addNewEdgeValueToBranch
294-
// since it checks that the destination block has enough arguments for the
295-
// argument.
296-
auto *phiArg =
297-
destBB->createPhiArgument(innerCopy->getType(), OwnershipKind::Owned);
298-
InstructionDeleter deleter(callbacks);
299-
addNewEdgeValueToBranch(bi, destBB, innerCopy, deleter);
300-
301-
// Grab our predecessor blocks, ignoring us, add to the branch edge an
302-
// undef corresponding to our value.
303-
//
304-
// We gather all predecessor blocks in a separate array to avoid
305-
// iterator invalidation issues as we mess with terminators.
306-
SmallVector<SILBasicBlock *, 8> predecessorBlocks(
307-
destBB->getPredecessorBlocks());
308-
309-
for (auto *predBlock : predecessorBlocks) {
310-
if (predBlock == innerCopy->getParentBlock())
311-
continue;
312-
addNewEdgeValueToBranch(
313-
predBlock->getTerminator(), destBB,
314-
SILUndef::get(innerCopy->getType(), *destBB->getParent()), deleter);
315-
}
316-
317-
return phiArg;
318-
}
319-
320289
//===----------------------------------------------------------------------===//
321290
// Ownership RAUW Helper Functions
322291
//===----------------------------------------------------------------------===//
@@ -373,9 +342,6 @@ bool OwnershipRAUWHelper::hasValidRAUWOwnership(SILValue oldValue,
373342

374343
// Determine whether it is valid to replace \p oldValue with \p newValue and
375344
// extend the lifetime of \p oldValue to cover the new uses.
376-
//
377-
// This updates the OwnershipFixupContext, populating transitiveBorrowedUses and
378-
// recursiveReborrows.
379345
static bool canFixUpOwnershipForRAUW(SILValue oldValue, SILValue newValue,
380346
OwnershipFixupContext &context) {
381347
if (!OwnershipRAUWHelper::hasValidRAUWOwnership(oldValue, newValue))
@@ -388,26 +354,6 @@ static bool canFixUpOwnershipForRAUW(SILValue oldValue, SILValue newValue,
388354
// book-keeping in the OwnershipFixupContext.
389355
context.clear();
390356

391-
if (auto borrowedValue = BorrowedValue(oldValue)) {
392-
// FIXME: remove this logic and use BorrowedLifetimeExtender.
393-
SmallPtrSet<SILValue, 4> reborrows;
394-
auto visitReborrow = [&](Operand *endScope) {
395-
auto borrowingOper = BorrowingOperand(endScope);
396-
assert(borrowingOper.isReborrow());
397-
if (reborrows.insert(borrowingOper.getBorrowIntroducingUserResult().value)
398-
.second) {
399-
context.recursiveReborrows.push_back(endScope);
400-
}
401-
};
402-
findTransitiveGuaranteedUses(oldValue, context.transitiveBorrowedUses,
403-
visitReborrow);
404-
for (unsigned idx = 0; idx < context.recursiveReborrows.size(); ++idx) {
405-
findTransitiveGuaranteedUses(context.recursiveReborrows[idx].getValue(),
406-
context.transitiveBorrowedUses,
407-
visitReborrow);
408-
}
409-
return true;
410-
}
411357
// Check that no transitive uses have a PointerEscape, and record the leaf
412358
// uses for liveness extension.
413359
return findExtendedTransitiveGuaranteedUses(oldValue,
@@ -708,15 +654,6 @@ struct OwnershipLifetimeExtender {
708654
/// the BorrowedValue that begins the scope.
709655
SILValue borrowOverSingleUse(SILValue newValue,
710656
Operand *singleGuaranteedUse);
711-
712-
// --- FIXME!!! remove the following (replaced by BorrowedLifetimeExtender)
713-
714-
/// Create a new borrow scope for \p newValue that is cleaned up along all
715-
/// paths that do not go through consuming point. The caller is expected to
716-
/// consumg \p newValue at \p consumingPoint since we insert a destroy_value
717-
/// right after wards.
718-
BeginBorrowInst *createPlusOneBorrow(SILValue newValue,
719-
SILInstruction *consumingPoint);
720657
};
721658

722659
} // end anonymous namespace
@@ -768,59 +705,6 @@ OwnershipLifetimeExtender::createPlusOneCopy(SILValue value,
768705
return result;
769706
}
770707

771-
// FIXME: This can be completely removed
772-
BeginBorrowInst *
773-
OwnershipLifetimeExtender::createPlusOneBorrow(SILValue value,
774-
SILInstruction *consumingPoint) {
775-
auto *newValInsertPt = value->getDefiningInsertionPoint();
776-
assert(newValInsertPt);
777-
CopyValueInst *copy;
778-
BeginBorrowInst *borrow;
779-
if (!isa<SILArgument>(value)) {
780-
SILBuilderWithScope::insertAfter(newValInsertPt, [&](SILBuilder &builder) {
781-
copy = builder.createCopyValue(builder.getInsertionPointLoc(), value);
782-
borrow = builder.createBeginBorrow(builder.getInsertionPointLoc(), copy);
783-
});
784-
} else {
785-
SILBuilderWithScope builder(newValInsertPt);
786-
copy = builder.createCopyValue(newValInsertPt->getLoc(), value);
787-
borrow = builder.createBeginBorrow(newValInsertPt->getLoc(), copy);
788-
}
789-
790-
auto &callbacks = ctx.callbacks;
791-
callbacks.createdNewInst(copy);
792-
callbacks.createdNewInst(borrow);
793-
794-
auto *result = borrow;
795-
findJointPostDominatingSet(
796-
newValInsertPt->getParent(), consumingPoint->getParent(),
797-
// inputBlocksFoundDuringWalk.
798-
[&](SILBasicBlock *loopBlock) {
799-
// This must be consumingPoint->getParent() since we only have one
800-
// consuming use. In this case, we know that this is the consuming
801-
// point where we will need a control equivalent copy_value (and that
802-
// destroy_value will be put for the out of loop value as appropriate.
803-
assert(loopBlock == consumingPoint->getParent());
804-
auto front = loopBlock->begin();
805-
SILBuilderWithScope newBuilder(front);
806-
result = newBuilder.createBeginBorrow(front->getLoc(), borrow);
807-
callbacks.createdNewInst(result);
808-
809-
llvm_unreachable("Should never visit this!");
810-
},
811-
// Input blocks in joint post dom set. We don't care about thse.
812-
[&](SILBasicBlock *postDomBlock) {
813-
auto front = postDomBlock->begin();
814-
SILBuilderWithScope newBuilder(front);
815-
auto loc = RegularLocation::getAutoGeneratedLocation(front->getLoc());
816-
auto *ebi = newBuilder.createEndBorrow(loc, borrow);
817-
callbacks.createdNewInst(ebi);
818-
auto *dvi = newBuilder.createDestroyValue(loc, copy);
819-
callbacks.createdNewInst(dvi);
820-
});
821-
return result;
822-
}
823-
824708
// A copy_value that we lifetime extend with destroy_value over range. We assume
825709
// all instructions passed into range do not consume value.
826710
template <typename RangeTy>
@@ -1060,83 +944,6 @@ OwnershipLifetimeExtender::borrowOverSingleUse(SILValue newValue,
1060944
return newBeginBorrow;
1061945
}
1062946

1063-
//===----------------------------------------------------------------------===//
1064-
// Reborrow Elimination
1065-
//===----------------------------------------------------------------------===//
1066-
1067-
static void eliminateReborrowsOfRecursiveBorrows(
1068-
ArrayRef<PhiOperand> transitiveReborrows,
1069-
SmallVectorImpl<Operand *> &usePoints, InstModCallbacks &callbacks) {
1070-
SmallVector<std::pair<SILPhiArgument *, SILPhiArgument *>, 8>
1071-
baseBorrowedValuePair;
1072-
// Ok, we have transitive reborrows.
1073-
for (auto it : transitiveReborrows) {
1074-
// We eliminate the reborrow by creating a new copy+borrow at the reborrow
1075-
// edge from the base value and using that for the reborrow instead of the
1076-
// actual value. We of course insert an end_borrow for our original incoming
1077-
// value.
1078-
auto *bi = cast<BranchInst>(it.predBlock->getTerminator());
1079-
auto &op = bi->getOperandRef(it.argIndex);
1080-
BorrowingOperand borrowingOperand(&op);
1081-
SILValue value = borrowingOperand->get();
1082-
SILBuilderWithScope reborrowBuilder(bi);
1083-
// Use an auto-generated location here, because the branch may have an
1084-
// incompatible LocationKind
1085-
auto loc = RegularLocation::getAutoGeneratedLocation(bi->getLoc());
1086-
auto *innerCopy = reborrowBuilder.createCopyValue(loc, value);
1087-
auto *innerBorrow = reborrowBuilder.createBeginBorrow(loc, innerCopy);
1088-
auto *outerEndBorrow = reborrowBuilder.createEndBorrow(loc, value);
1089-
1090-
callbacks.createdNewInst(innerCopy);
1091-
callbacks.createdNewInst(innerBorrow);
1092-
callbacks.createdNewInst(outerEndBorrow);
1093-
1094-
// Then set our borrowing operand to take our innerBorrow instead of value
1095-
// (whose lifetime we just ended).
1096-
callbacks.setUseValue(*borrowingOperand, innerBorrow);
1097-
// Add our outer end borrow as a use point to make sure that we extend our
1098-
// base value to this point.
1099-
usePoints.push_back(&outerEndBorrow->getAllOperands()[0]);
1100-
1101-
// Then check if in our destination block, we have further reborrows. If we
1102-
// do, we need to recursively process them.
1103-
auto *borrowedArg =
1104-
const_cast<SILPhiArgument *>(bi->getArgForOperand(*borrowingOperand));
1105-
auto *baseArg =
1106-
insertOwnedBaseValueAlongBranchEdge(bi, innerCopy, callbacks);
1107-
baseBorrowedValuePair.emplace_back(baseArg, borrowedArg);
1108-
}
1109-
1110-
// Now recursively update all further reborrows...
1111-
while (!baseBorrowedValuePair.empty()) {
1112-
SILPhiArgument *baseArg;
1113-
SILPhiArgument *borrowedArg;
1114-
std::tie(baseArg, borrowedArg) = baseBorrowedValuePair.pop_back_val();
1115-
1116-
for (auto *use : borrowedArg->getConsumingUses()) {
1117-
// If our consuming use is an end of scope marker, we need to end
1118-
// the lifetime of our base arg.
1119-
if (isEndOfScopeMarker(use->getUser())) {
1120-
SILBuilderWithScope::insertAfter(use->getUser(), [&](SILBuilder &b) {
1121-
auto *dvi = b.createDestroyValue(b.getInsertionPointLoc(), baseArg);
1122-
callbacks.createdNewInst(dvi);
1123-
});
1124-
continue;
1125-
}
1126-
1127-
// Otherwise, we have a reborrow. For now our reborrows must be
1128-
// phis. Add our owned value as a new argument of that phi along our
1129-
// edge and undef along all other edges.
1130-
auto borrowingOp = BorrowingOperand(use);
1131-
auto *brInst = cast<BranchInst>(borrowingOp.op->getUser());
1132-
auto *newBorrowedPhi = brInst->getArgForOperand(*borrowingOp);
1133-
auto *newBasePhi =
1134-
insertOwnedBaseValueAlongBranchEdge(brInst, baseArg, callbacks);
1135-
baseBorrowedValuePair.emplace_back(newBasePhi, newBorrowedPhi);
1136-
}
1137-
}
1138-
}
1139-
1140947
//===----------------------------------------------------------------------===//
1141948
// OwnershipRAUWUtility - RAUW + fix ownership
1142949
//===----------------------------------------------------------------------===//
@@ -1622,35 +1429,6 @@ SILBasicBlock::iterator SingleUseReplacementUtility::handleGuaranteed() {
16221429
// Ok, our use is guaranteed and our new value may not be guaranteed.
16231430
auto extender = getLifetimeExtender();
16241431

1625-
// If our original use was a lifetime ending use...
1626-
//
1627-
// TODO: Also just call borrowOverSingleUse in the lifetime-ending case.
1628-
if (use->isLifetimeEnding()) {
1629-
// And additionally was a reborrow, we will have placed it in recursive
1630-
// reborrows. In this case the RAUW
1631-
if (ctx.recursiveReborrows.size()) {
1632-
eliminateReborrowsOfRecursiveBorrows(
1633-
ctx.recursiveReborrows, ctx.transitiveBorrowedUses, ctx.callbacks);
1634-
// By eliminate the reborrows our lifetime ending use was already
1635-
// handled. Now, we need to lifetime extend the borrow over all of the
1636-
// end_lifetime after we eliminate the reborrow. These will be the
1637-
// transitive borrowed uses.
1638-
auto borrowPt = newValue->getNextInstruction()->getIterator();
1639-
SILValue borrow = extender.borrowCopyOverGuaranteedUses(
1640-
newValue, borrowPt, llvm::makeArrayRef(ctx.transitiveBorrowedUses));
1641-
1642-
// Then replace use->get() with this borrow.
1643-
return replaceSingleUse(use, borrow, ctx.callbacks);
1644-
} else {
1645-
// If we didn't have a reborrow and still had a lifetime ending use,
1646-
// handle it.
1647-
SILValue borrow = extender.createPlusOneBorrow(newValue, use->getUser());
1648-
// Then replace use->get() with this copy. We will insert compensating end
1649-
// scope instructions on use->get() if we need to.
1650-
return replaceSingleUse(use, borrow, ctx.callbacks);
1651-
}
1652-
}
1653-
16541432
// If we don't have a lifetime ending use, just create the borrow.
16551433
SILValue copy = extender.borrowOverSingleUse(newValue, use);
16561434

0 commit comments

Comments
 (0)