Skip to content

Commit 1c8f142

Browse files
committed
OwnershipOptUtils - computeGuaranteedBoundary
1 parent bad72e2 commit 1c8f142

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

include/swift/SILOptimizer/Utils/OwnershipOptUtils.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ makeGuaranteedValueAvailable(SILValue value, SILInstruction *user,
7878
DeadEndBlocks &deBlocks,
7979
InstModCallbacks callbacks = InstModCallbacks());
8080

81+
/// Compute the liveness boundary for a guaranteed value. Returns true if no
82+
/// uses are pointer escapes. If pointer escapes are present, the liveness
83+
/// boundary is still valid for all known uses.
84+
///
85+
/// Precondition: \p value has guaranteed ownership and no reborrows. It is
86+
/// either an "inner" guaranteed value or a simple borrow introducer whose
87+
/// end_borrows have not yet been inserted.
88+
bool computeGuaranteedBoundary(SILValue value,
89+
PrunedLivenessBoundary &boundary);
90+
8191
//===----------------------------------------------------------------------===//
8292
// GuaranteedOwnershipExtension
8393
//===----------------------------------------------------------------------===//

lib/SILOptimizer/Utils/OwnershipOptUtils.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,29 @@ void swift::extendLocalBorrow(BeginBorrowInst *beginBorrow,
127127
}
128128
}
129129

130+
bool swift::computeGuaranteedBoundary(SILValue value,
131+
PrunedLivenessBoundary &boundary) {
132+
assert(value.getOwnershipKind() == OwnershipKind::Guaranteed);
133+
134+
// Place end_borrows that cover the load_borrow uses. It is not necessary to
135+
// cover the outer borrow scope of the extract's operand. If a lexical
136+
// borrow scope exists for the outer value, which is now in memory, then
137+
// its alloc_stack will be marked lexical, and the in-memory values will be
138+
// kept alive until the end of the outer scope.
139+
SmallVector<Operand *, 4> usePoints;
140+
bool noEscape = findInnerTransitiveGuaranteedUses(value, &usePoints);
141+
142+
SmallVector<SILBasicBlock *, 4> discoveredBlocks;
143+
PrunedLiveness liveness(&discoveredBlocks);
144+
for (auto *use : usePoints) {
145+
assert(!use->isLifetimeEnding());
146+
liveness.updateForUse(use->getUser(), /*lifetimeEnding*/ false);
147+
}
148+
boundary.compute(liveness);
149+
150+
return noEscape;
151+
}
152+
130153
//===----------------------------------------------------------------------===//
131154
// GuaranteedOwnershipExtension
132155
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)