Skip to content

Commit 99c7682

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 4514918 commit 99c7682

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,31 @@ void TypeTreeLeafTypeRange::constructProjectionsForNeededElements(
483483
}
484484
}
485485

486+
void TypeTreeLeafTypeRange::visitContiguousRanges(
487+
SmallBitVector const &bits,
488+
llvm::function_ref<void(TypeTreeLeafTypeRange)> callback) {
489+
if (bits.size() == 0)
490+
return;
491+
492+
Optional<std::pair<unsigned, /*isSet*/ bool>> current = llvm::None;
493+
for (unsigned bit = 0, size = bits.size(); bit < size; ++bit) {
494+
auto isSet = bits.test(bit);
495+
if (!current) {
496+
current = {bit, isSet};
497+
continue;
498+
}
499+
if (current->second != isSet) {
500+
if (current->second) {
501+
callback(TypeTreeLeafTypeRange(current->first, bit));
502+
}
503+
current = {bit, isSet};
504+
}
505+
}
506+
if (current->second) {
507+
callback(TypeTreeLeafTypeRange(current->first, bits.size()));
508+
}
509+
}
510+
486511
//===----------------------------------------------------------------------===//
487512
// MARK: FieldSensitivePrunedLiveBlocks
488513
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)