Skip to content

Commit aacb538

Browse files
committed
[FieldSensitivePL] NFC: Added initDef(bit vector).
The new overload iterates over the contiguous ranges in the bit vector and calls through to the overload that takes a range.
1 parent 6f4b16c commit aacb538

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

include/swift/SIL/FieldSensitivePrunedLiveness.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,10 @@ struct TypeTreeLeafTypeRange {
321321
SmallVectorImpl<std::pair<SILValue, TypeTreeLeafTypeRange>>
322322
&resultingProjections);
323323

324+
static void visitContiguousRanges(
325+
SmallBitVector const &bits,
326+
llvm::function_ref<void(TypeTreeLeafTypeRange)> callback);
327+
324328
bool operator==(const TypeTreeLeafTypeRange &other) const {
325329
return startEltOffset == other.startEltOffset &&
326330
endEltOffset == other.endEltOffset;
@@ -1216,6 +1220,11 @@ class FieldSensitiveMultiDefPrunedLiveRange
12161220
defBlocks.setFrozen();
12171221
}
12181222

1223+
void initializeDef(SILInstruction *def, SmallBitVector const &bits) {
1224+
TypeTreeLeafTypeRange::visitContiguousRanges(
1225+
bits, [&](auto range) { initializeDef(def, range); });
1226+
}
1227+
12191228
void initializeDef(SILValue def, TypeTreeLeafTypeRange span) {
12201229
assert(Super::isInitialized());
12211230
defs.insert(def, span);

lib/SIL/Utils/FieldSensitivePrunedLiveness.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,29 @@ void TypeTreeLeafTypeRange::constructProjectionsForNeededElements(
465465
}
466466
}
467467

468+
void TypeTreeLeafTypeRange::visitContiguousRanges(
469+
SmallBitVector const &bits,
470+
llvm::function_ref<void(TypeTreeLeafTypeRange)> callback) {
471+
if (bits.size() == 0)
472+
return;
473+
474+
Optional<unsigned> current = llvm::None;
475+
for (unsigned bit = 0, size = bits.size(); bit < size; ++bit) {
476+
auto isSet = bits.test(bit);
477+
if (current) {
478+
if (!isSet) {
479+
callback(TypeTreeLeafTypeRange(*current, bit));
480+
current = llvm::None;
481+
}
482+
} else if (isSet) {
483+
current = bit;
484+
}
485+
}
486+
if (current) {
487+
callback(TypeTreeLeafTypeRange(*current, bits.size()));
488+
}
489+
}
490+
468491
//===----------------------------------------------------------------------===//
469492
// MARK: FieldSensitivePrunedLiveBlocks
470493
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)