Skip to content

Commit ab0601d

Browse files
committed
Add PrunedLiveness::computeSSALiveness
Straighforward API to build pruned liveness from a single SSA value. This 3-line function allows PrunedLiveness to be used anywhere ValueLifetimeAnalysis was used in OSSA form. Aside from simplicity and efficiency, the difference is that this composes with other utilities that only care about PrunedLiveBlocks, PrunedLiveness, or PrunesLivenessBounary independent of how those data structures were generated.
1 parent c056ca6 commit ab0601d

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

include/swift/SIL/PrunedLiveness.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ class PrunedLiveness {
284284

285285
bool areUsesWithinBoundary(ArrayRef<Operand *> uses,
286286
DeadEndBlocks &deadEndBlocks) const;
287+
288+
/// Compute liveness for a single SSA definition.
289+
void computeSSALiveness(SILValue def);
287290
};
288291

289292
/// Record the last use points and CFG edges that form the boundary of

lib/SIL/Utils/PrunedLiveness.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,17 @@ bool PrunedLiveness::areUsesWithinBoundary(ArrayRef<Operand *> uses,
161161
return true;
162162
}
163163

164+
// An SSA def meets all the criteria for pruned liveness--def dominates all uses
165+
// with no holes in the liverange. The lifetime-ending uses are also
166+
// recorded--destroy_value or end_borrow. However destroy_values may not
167+
// jointly-post dominate if dead-end blocks are present.
168+
void PrunedLiveness::computeSSALiveness(SILValue def) {
169+
initializeDefBlock(def->getParentBlock());
170+
for (Operand *use : def->getUses()) {
171+
updateForUse(use->getUser(), use->isLifetimeEnding());
172+
}
173+
}
174+
164175
void PrunedLivenessBoundary::visitInsertionPoints(
165176
llvm::function_ref<void(SILBasicBlock::iterator insertPt)> visitor,
166177
DeadEndBlocks *deBlocks) {

0 commit comments

Comments
 (0)