Skip to content

Commit 8062e40

Browse files
committed
Migrate to OwnershipLifetimeExtender API: borrowCopyOverScope etc.
Preparation for rewriting non-trivial terminators and generalizing support for guaranteed phis. Add guaranteedUsePoints to the RAUW context. This will replace ALL existing context book-keeping once the old code is deleted. Introduce a borrowCopyOverScope entry point to handle extending lifetime over a BorrowedValue. This simply uses the BorrowedLifetimeExtender. Introduce higher-level APIs: - borrowOverValue to extened over a guaranteedValue - borrowOverSingleUse to extened over a single guaranteed use These replace both createPlusZeroBorrow and createPlusOneBorrow. Update RAUW-ctor, RAUW::handleUnowned, and replaceAddressUses to use the new API. Restructure RAUW::canFixUpOwnershipForRAUW. Simply use findInnerTransitiveGuaranteedUses. Replace RAUW::handleGuaranteed and rewriteReborrows with OLE::borrowOverValue. Use the BorrowedLifetimeExtender utility to handle all situations correctly. TODO: createPlusOneBorrow can be completely removed, and a massive amount of confusing/incomplete code can be deleted in a follow-up commit.
1 parent 2dd50bb commit 8062e40

File tree

2 files changed

+310
-236
lines changed

2 files changed

+310
-236
lines changed

include/swift/SILOptimizer/Utils/OwnershipOptUtils.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ struct OwnershipFixupContext {
148148
InstModCallbacks &callbacks;
149149
DeadEndBlocks &deBlocks;
150150

151+
// Cache the use-points for the lifetime of an inner guaranteed value (which
152+
// does not introduce a borrow scope) after checking validity. These will be
153+
// used again to extend the lifetime of the replacement value.
154+
SmallVector<Operand *, 8> guaranteedUsePoints;
151155

152156
// FIXME: remove these two vectors once BorrowedLifetimeExtender is used
153157
// everywhere.
@@ -162,6 +166,8 @@ struct OwnershipFixupContext {
162166
/// compute all transitive address uses of oldValue. If we find that we do
163167
/// need this fixed up, then we will copy our interior pointer base value
164168
/// and use this to seed that new lifetime.
169+
///
170+
/// FIXME: shouldn't these already be covered by guaranteedUsePoints?
165171
SmallVector<Operand *, 8> allAddressUsesFromOldValue;
166172

167173
/// This is the interior pointer (e.g. ref_element_addr)
@@ -184,6 +190,7 @@ struct OwnershipFixupContext {
184190
: callbacks(callbacks), deBlocks(deBlocks) {}
185191

186192
void clear() {
193+
guaranteedUsePoints.clear();
187194
transitiveBorrowedUses.clear();
188195
recursiveReborrows.clear();
189196
extraAddressFixupInfo.allAddressUsesFromOldValue.clear();

0 commit comments

Comments
 (0)