Skip to content

Commit e6b63fb

Browse files
committed
[pruned-liveness] Change markBlockLive to call the scalar implementation for each bit rather than attempt to do it for all bits at the same time.
1 parent 82abf02 commit e6b63fb

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

include/swift/SIL/PrunedLiveness.h

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ class PrunedLiveBlocks {
202202
return bits[bitNo * 2 + 1] ? LiveOut : LiveWithin;
203203
}
204204

205+
/// Returns the liveness in \p resultingFoundLiveness. We only return the
206+
/// bits for endBitNo - startBitNo.
205207
void getLiveness(unsigned startBitNo, unsigned endBitNo,
206208
SmallVectorImpl<IsLive> &resultingFoundLiveness) const {
207209
unsigned actualStartBitNo = startBitNo * 2;
@@ -301,8 +303,8 @@ class PrunedLiveBlocks {
301303
return liveBlockIter->second.getLiveness(bitNo);
302304
}
303305

304-
// FIXME: This API should directly return the live bitset. The live bitset
305-
// type should have an api for querying and iterating over the live fields.
306+
/// FIXME: This API should directly return the live bitset. The live bitset
307+
/// type should have an api for querying and iterating over the live fields.
306308
void getBlockLiveness(SILBasicBlock *bb, unsigned startBitNo,
307309
unsigned endBitNo,
308310
SmallVectorImpl<IsLive> &foundLivenessInfo) const {
@@ -324,11 +326,6 @@ class PrunedLiveBlocks {
324326

325327
protected:
326328
void markBlockLive(SILBasicBlock *bb, unsigned bitNo, IsLive isLive) {
327-
markBlockLive(bb, bitNo, bitNo + 1, isLive);
328-
}
329-
330-
void markBlockLive(SILBasicBlock *bb, unsigned startBitNo, unsigned endBitNo,
331-
IsLive isLive) {
332329
assert(isLive != Dead && "erasing live blocks isn't implemented.");
333330
auto iterAndInserted =
334331
liveBlocks.insert(std::make_pair(bb, LivenessSmallBitVector()));
@@ -338,13 +335,33 @@ class PrunedLiveBlocks {
338335
// we have more than SmallBitVector's small size number of bits.
339336
auto &insertedBV = iterAndInserted.first->getSecond();
340337
insertedBV.init(numBitsToTrack);
341-
insertedBV.setLiveness(startBitNo, endBitNo, isLive);
338+
insertedBV.setLiveness(bitNo, bitNo + 1, isLive);
342339
if (discoveredBlocks)
343340
discoveredBlocks->push_back(bb);
344-
} else if (isLive == LiveOut) {
345-
// Update the existing entry to be live-out.
346-
iterAndInserted.first->getSecond().setLiveness(startBitNo, endBitNo,
347-
LiveOut);
341+
} else {
342+
// If we are dead, always update to the new liveness.
343+
switch (iterAndInserted.first->getSecond().getLiveness(bitNo)) {
344+
case Dead:
345+
iterAndInserted.first->getSecond().setLiveness(bitNo, bitNo + 1,
346+
isLive);
347+
break;
348+
case LiveWithin:
349+
if (isLive == LiveOut) {
350+
// Update the existing entry to be live-out.
351+
iterAndInserted.first->getSecond().setLiveness(bitNo, bitNo + 1,
352+
LiveOut);
353+
}
354+
break;
355+
case LiveOut:
356+
break;
357+
}
358+
}
359+
}
360+
361+
void markBlockLive(SILBasicBlock *bb, unsigned startBitNo, unsigned endBitNo,
362+
IsLive isLive) {
363+
for (unsigned index : range(startBitNo, endBitNo)) {
364+
markBlockLive(bb, index, isLive);
348365
}
349366
}
350367

0 commit comments

Comments
 (0)