Skip to content

Commit f4268a9

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 fbf1561 commit f4268a9

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
@@ -562,6 +562,9 @@ namespace {
562562
struct UseState {
563563
MarkMustCheckInst *address;
564564

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

567570
/// The blocks that consume fields of the value.
@@ -575,7 +578,7 @@ struct UseState {
575578

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

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

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

630633
/// The set of drop_deinits of this mark_must_check
631634
SmallSetVector<SILInstruction *, 2> dropDeinitInsts;
@@ -652,32 +655,35 @@ struct UseState {
652655
return *cachedNumSubelements;
653656
}
654657

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

667+
void setAffectedBits(SILInstruction *inst, SmallBitVector const &bits,
668+
InstToBitMap &map) {
669+
getOrCreateAffectedBits(inst, map) |= bits;
670+
}
671+
672+
void setAffectedBits(SILInstruction *inst, TypeTreeLeafTypeRange range,
673+
InstToBitMap &map) {
674+
range.setBits(getOrCreateAffectedBits(inst, map));
675+
}
676+
664677
void recordLivenessUse(SILInstruction *inst, SmallBitVector const &bits) {
665-
getOrCreateLivenessUse(inst) |= bits;
678+
setAffectedBits(inst, bits, livenessUses);
666679
}
667680

668681
void recordLivenessUse(SILInstruction *inst, TypeTreeLeafTypeRange range) {
669-
auto &bits = getOrCreateLivenessUse(inst);
670-
range.setBits(bits);
682+
setAffectedBits(inst, range, livenessUses);
671683
}
672684

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

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

0 commit comments

Comments
 (0)