Skip to content

Commit d669c1d

Browse files
committed
[LifetimeCompletion] Avoid instruction list walk.
When computing the available region, a forward walk is done from the non-lifetime-ending boundary of the live region. That boundary consists of (1) the target blocks of boundary edges, (2) dead defs, and (3) last users which are non-consuming. This forward walk is done at the block level, so neither the specific dead def (for (2)) nor specific last non-consuming user (for (3)) is required to perform the walk; indeed currently these are computed and then immediately used only to obtain the blocks in which they appear and then discarded. Avoid computing the specific dead defs and specific last non-consuming users by switching to a lower-fidelity liveness boundary computation via `PrunedLivenessBlockBoundary`.
1 parent 86cd960 commit d669c1d

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

lib/SIL/Utils/OSSALifetimeCompletion.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,18 @@ void AvailabilityBoundaryVisitor::visit(const SSAPrunedLiveness &liveness,
262262
void AvailabilityBoundaryVisitor::computeRegion(
263263
const SSAPrunedLiveness &liveness) {
264264
// (1) Compute the complete liveness boundary.
265-
PrunedLivenessBoundary boundary;
265+
PrunedLivenessBlockBoundary boundary;
266266
liveness.computeBoundary(boundary);
267267

268+
BasicBlockSet consumingBlocks(value->getFunction());
269+
270+
liveness.visitUsers(
271+
[&consumingBlocks](auto *instruction, auto lifetimeEnding) {
272+
if (lifetimeEnding.isEnding()) {
273+
consumingBlocks.insert(instruction->getParent());
274+
}
275+
});
276+
268277
// Used in the forward walk below (3).
269278
BasicBlockWorklist regionWorklist(value->getFunction());
270279

@@ -284,18 +293,14 @@ void AvailabilityBoundaryVisitor::computeRegion(
284293
regionWorklist.push(block);
285294
};
286295

287-
for (SILInstruction *lastUser : boundary.lastUsers) {
288-
if (liveness.isInterestingUser(lastUser)
289-
!= PrunedLiveness::LifetimeEndingUse) {
290-
collect(lastUser->getParent());
296+
for (auto *endBlock : boundary.endBlocks) {
297+
if (!consumingBlocks.contains(endBlock)) {
298+
collect(endBlock);
291299
}
292300
}
293301
for (SILBasicBlock *edge : boundary.boundaryEdges) {
294302
collect(edge);
295303
}
296-
for (SILNode *deadDef : boundary.deadDefs) {
297-
collect(deadDef->getParentBlock());
298-
}
299304

300305
// (3) Forward walk to find the region in which `value` might be available.
301306
while (auto *block = regionWorklist.pop()) {

0 commit comments

Comments
 (0)