Skip to content

Commit f7f5802

Browse files
committed
[MoveOnlyAddressChecker] NFC: Extracted helpers.
In preparation for having a third instance getting or creating the bits affected by an instruction, introduce a typealias for maps SILInstruction->SmallBitVector and a helper function that returns a reference to the SmallBitVector for an instruction and two others that set into those bits the bits from another bit vector or from a range.
1 parent 4a5009a commit f7f5802

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerUtils.cpp

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,9 @@ namespace {
563563
struct UseState {
564564
MarkMustCheckInst *address;
565565

566+
using InstToBitMap =
567+
llvm::SmallMapVector<SILInstruction *, SmallBitVector, 4>;
568+
566569
llvm::Optional<unsigned> cachedNumSubelements;
567570

568571
/// The blocks that consume fields of the value.
@@ -576,7 +579,7 @@ struct UseState {
576579

577580
/// A map from a liveness requiring use to the part of the type that it
578581
/// requires liveness for.
579-
llvm::SmallMapVector<SILInstruction *, SmallBitVector, 4> livenessUses;
582+
InstToBitMap livenessUses;
580583

581584
/// A map from a load [copy] or load [take] that we determined must be
582585
/// converted to a load_borrow to the part of the type tree that it needs to
@@ -626,7 +629,7 @@ struct UseState {
626629

627630
/// memInstMustReinitialize insts. Contains both insts like copy_addr/store
628631
/// [assign] that are reinits that we will convert to inits and true reinits.
629-
llvm::SmallMapVector<SILInstruction *, SmallBitVector, 4> reinitInsts;
632+
InstToBitMap reinitInsts;
630633

631634
/// The set of drop_deinits of this mark_must_check
632635
SmallSetVector<SILInstruction *, 2> dropDeinitInsts;
@@ -653,32 +656,35 @@ struct UseState {
653656
return *cachedNumSubelements;
654657
}
655658

656-
SmallBitVector &getOrCreateLivenessUse(SILInstruction *inst) {
657-
auto iter = livenessUses.find(inst);
658-
if (iter == livenessUses.end()) {
659-
iter = livenessUses.insert({inst, SmallBitVector(getNumSubelements())})
660-
.first;
659+
SmallBitVector &getOrCreateAffectedBits(SILInstruction *inst,
660+
InstToBitMap &map) {
661+
auto iter = map.find(inst);
662+
if (iter == map.end()) {
663+
iter = map.insert({inst, SmallBitVector(getNumSubelements())}).first;
661664
}
662665
return iter->second;
663666
}
664667

668+
void setAffectedBits(SILInstruction *inst, SmallBitVector const &bits,
669+
InstToBitMap &map) {
670+
getOrCreateAffectedBits(inst, map) |= bits;
671+
}
672+
673+
void setAffectedBits(SILInstruction *inst, TypeTreeLeafTypeRange range,
674+
InstToBitMap &map) {
675+
range.setBits(getOrCreateAffectedBits(inst, map));
676+
}
677+
665678
void recordLivenessUse(SILInstruction *inst, SmallBitVector const &bits) {
666-
getOrCreateLivenessUse(inst) |= bits;
679+
setAffectedBits(inst, bits, livenessUses);
667680
}
668681

669682
void recordLivenessUse(SILInstruction *inst, TypeTreeLeafTypeRange range) {
670-
auto &bits = getOrCreateLivenessUse(inst);
671-
range.setBits(bits);
683+
setAffectedBits(inst, range, livenessUses);
672684
}
673685

674686
void recordReinitUse(SILInstruction *inst, TypeTreeLeafTypeRange range) {
675-
auto iter = reinitInsts.find(inst);
676-
if (iter == reinitInsts.end()) {
677-
iter =
678-
reinitInsts.insert({inst, SmallBitVector(getNumSubelements())}).first;
679-
}
680-
auto &bits = iter->second;
681-
range.setBits(bits);
687+
setAffectedBits(inst, range, reinitInsts);
682688
}
683689

684690
/// Returns true if this is a terminator instruction that although it doesn't

0 commit comments

Comments
 (0)