Skip to content

Commit be50c56

Browse files
committed
[pruned-liveness] Specialize scalar pruned liveness routines
Just a small cleanup that will improve performance in the scalar case which is important for OSSA utilities.
1 parent 2637c0b commit be50c56

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

include/swift/SIL/PrunedLiveness.h

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,10 @@ class PrunedLiveBlocks {
196196

197197
unsigned size() const { return bits.size() / 2; }
198198

199-
// FIXME: specialize this for scalar liveness, which is the critical path
200-
// for all OSSA utilities.
201199
IsLive getLiveness(unsigned bitNo) const {
202-
SmallVector<IsLive, 1> foundLiveness;
203-
getLiveness(bitNo, bitNo + 1, foundLiveness);
204-
return foundLiveness[0];
200+
if (!bits[bitNo * 2])
201+
return IsLive::Dead;
202+
return bits[bitNo * 2 + 1] ? LiveOut : LiveWithin;
205203
}
206204

207205
void getLiveness(unsigned startBitNo, unsigned endBitNo,
@@ -281,9 +279,12 @@ class PrunedLiveBlocks {
281279

282280
/// Update this liveness result for a single use.
283281
IsLive updateForUse(SILInstruction *user, unsigned bitNo) {
284-
SmallVector<IsLive, 1> resultingLiveness;
285-
updateForUse(user, bitNo, bitNo + 1, resultingLiveness);
286-
return resultingLiveness[0];
282+
auto *block = user->getParent();
283+
auto liveness = getBlockLiveness(block, bitNo);
284+
if (liveness != Dead)
285+
return liveness;
286+
computeUseBlockLiveness(block, bitNo, bitNo + 1);
287+
return getBlockLiveness(block, bitNo);
287288
}
288289

289290
/// Update this range of liveness results for a single use.
@@ -292,9 +293,12 @@ class PrunedLiveBlocks {
292293
SmallVectorImpl<IsLive> &resultingLiveness);
293294

294295
IsLive getBlockLiveness(SILBasicBlock *bb, unsigned bitNo) const {
295-
SmallVector<IsLive, 1> isLive;
296-
getBlockLiveness(bb, bitNo, bitNo + 1, isLive);
297-
return isLive[0];
296+
auto liveBlockIter = liveBlocks.find(bb);
297+
if (liveBlockIter == liveBlocks.end()) {
298+
return Dead;
299+
}
300+
301+
return liveBlockIter->second.getLiveness(bitNo);
298302
}
299303

300304
// FIXME: This API should directly return the live bitset. The live bitset

0 commit comments

Comments
 (0)