Skip to content

Commit fcd25ea

Browse files
committed
[NFC] LifetimeCompletion: Clarify doc and code.
1 parent 9c16318 commit fcd25ea

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

lib/SIL/Utils/OSSALifetimeCompletion.cpp

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -193,36 +193,47 @@ class VisitUnreachableLifetimeEnds {
193193

194194
void VisitUnreachableLifetimeEnds::computeRegion(
195195
const SSAPrunedLiveness &liveness) {
196-
// Find the non-lifetime-ending boundary of `value`.
196+
// (1) Compute the complete liveness boundary.
197197
PrunedLivenessBoundary boundary;
198198
liveness.computeBoundary(boundary);
199199

200+
// Used in the forward walk below (3).
201+
BasicBlockWorklist regionWorklist(value->getFunction());
202+
203+
// (2) Collect the non-lifetime-ending liveness boundary. This is the
204+
// portion of `boundary` consisting of:
205+
// - non-lifetime-ending instructions (their parent blocks)
206+
// - boundary edges
207+
// - dead defs (their parent blocks)
208+
auto collect = [&](SILBasicBlock *block) {
209+
// `region` consists of the non-lifetime-ending boundary and all its
210+
// iterative successors.
211+
region.insert(block);
212+
// `starts` just consists of the blocks in the non-lifetime-ending
213+
// boundary.
214+
starts.insert(block);
215+
// The forward walk begins from the non-lifetime-ending boundary.
216+
regionWorklist.push(block);
217+
};
218+
200219
for (SILInstruction *lastUser : boundary.lastUsers) {
201220
if (liveness.isInterestingUser(lastUser)
202221
!= PrunedLiveness::LifetimeEndingUse) {
203-
region.insert(lastUser->getParent());
204-
starts.insert(lastUser->getParent());
222+
collect(lastUser->getParent());
205223
}
206224
}
207225
for (SILBasicBlock *edge : boundary.boundaryEdges) {
208-
region.insert(edge);
209-
starts.insert(edge);
226+
collect(edge);
210227
}
211228
for (SILNode *deadDef : boundary.deadDefs) {
212-
region.insert(deadDef->getParentBlock());
213-
starts.insert(deadDef->getParentBlock());
229+
collect(deadDef->getParentBlock());
214230
}
215231

216-
// Forward walk to find the region in which `value` might be available.
217-
BasicBlockWorklist regionWorklist(value->getFunction());
218-
// Start the forward walk from the non-lifetime-ending boundary.
219-
for (auto *start : region) {
220-
regionWorklist.push(start);
221-
}
232+
// (3) Forward walk to find the region in which `value` might be available.
222233
while (auto *block = regionWorklist.pop()) {
223234
if (block->succ_empty()) {
224-
// This assert will fail unless there are already lifetime-ending
225-
// instruction on all paths to normal function exits.
235+
// This assert will fail unless there is already a lifetime-ending
236+
// instruction on each path to normal function exits.
226237
assert(isa<UnreachableInst>(block->getTerminator()));
227238
}
228239
for (auto *successor : block->getSuccessorBlocks()) {

0 commit comments

Comments
 (0)