@@ -626,7 +626,7 @@ struct UseState {
626
626
627
627
// / memInstMustReinitialize insts. Contains both insts like copy_addr/store
628
628
// / [assign] that are reinits that we will convert to inits and true reinits.
629
- llvm::SmallMapVector<SILInstruction *, TypeTreeLeafTypeRange , 4 > reinitInsts;
629
+ llvm::SmallMapVector<SILInstruction *, SmallBitVector , 4 > reinitInsts;
630
630
631
631
// / The set of drop_deinits of this mark_must_check
632
632
SmallSetVector<SILInstruction *, 2 > dropDeinitInsts;
@@ -668,9 +668,17 @@ struct UseState {
668
668
669
669
void recordLivenessUse (SILInstruction *inst, TypeTreeLeafTypeRange range) {
670
670
auto &bits = getOrCreateLivenessUse (inst);
671
- for (auto element : range.getRange ()) {
672
- bits.set (element);
671
+ range.setBits (bits);
672
+ }
673
+
674
+ 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 ;
673
679
}
680
+ auto &bits = iter->second ;
681
+ range.setBits (bits);
674
682
}
675
683
676
684
// / Returns true if this is a terminator instruction that although it doesn't
@@ -765,14 +773,24 @@ struct UseState {
765
773
}
766
774
}
767
775
768
- void recordConsumingBlock (SILBasicBlock *block, TypeTreeLeafTypeRange range ) {
776
+ SmallBitVector & getOrCreateConsumingBlock (SILBasicBlock *block) {
769
777
auto iter = consumingBlocks.find (block);
770
778
if (iter == consumingBlocks.end ()) {
771
779
iter =
772
780
consumingBlocks.insert ({block, SmallBitVector (getNumSubelements ())})
773
781
.first ;
774
782
}
775
- range.setBits (iter->second );
783
+ return iter->second ;
784
+ }
785
+
786
+ void recordConsumingBlock (SILBasicBlock *block, TypeTreeLeafTypeRange range) {
787
+ auto &consumingBits = getOrCreateConsumingBlock (block);
788
+ range.setBits (consumingBits);
789
+ }
790
+
791
+ void recordConsumingBlock (SILBasicBlock *block, SmallBitVector &bits) {
792
+ auto &consumingBits = getOrCreateConsumingBlock (block);
793
+ consumingBits |= bits;
776
794
}
777
795
778
796
void
@@ -839,7 +857,7 @@ struct UseState {
839
857
if (!isReinitToInitConvertibleInst (inst)) {
840
858
auto iter = reinitInsts.find (inst);
841
859
if (iter != reinitInsts.end ()) {
842
- if (span.setIntersection (iter->second ))
860
+ if (span.intersects (iter->second ))
843
861
return true ;
844
862
}
845
863
}
@@ -864,7 +882,7 @@ struct UseState {
864
882
if (isReinitToInitConvertibleInst (inst)) {
865
883
auto iter = reinitInsts.find (inst);
866
884
if (iter != reinitInsts.end ()) {
867
- if (span.setIntersection (iter->second ))
885
+ if (span.intersects (iter->second ))
868
886
return true ;
869
887
}
870
888
}
@@ -1741,11 +1759,10 @@ bool GatherUsesVisitor::visitUse(Operand *op) {
1741
1759
1742
1760
if (::memInstMustReinitialize (op)) {
1743
1761
LLVM_DEBUG (llvm::dbgs () << " Found reinit: " << *user);
1744
- assert (!useState.reinitInsts .count (user));
1745
1762
auto leafRange = TypeTreeLeafTypeRange::get (op->get (), getRootAddress ());
1746
1763
if (!leafRange)
1747
1764
return false ;
1748
- useState.reinitInsts . insert ({ user, *leafRange} );
1765
+ useState.recordReinitUse ( user, *leafRange);
1749
1766
return true ;
1750
1767
}
1751
1768
@@ -2730,9 +2747,7 @@ void MoveOnlyAddressCheckerPImpl::rewriteUses(
2730
2747
for (auto reinitPair : addressUseState.reinitInsts ) {
2731
2748
if (!isReinitToInitConvertibleInst (reinitPair.first ))
2732
2749
continue ;
2733
- SmallBitVector bits (liveness.getNumSubElements ());
2734
- reinitPair.second .setBits (bits);
2735
- if (!consumes.claimConsume (reinitPair.first , bits))
2750
+ if (!consumes.claimConsume (reinitPair.first , reinitPair.second ))
2736
2751
convertMemoryReinitToInitForm (reinitPair.first , debugVar);
2737
2752
}
2738
2753
@@ -2923,7 +2938,7 @@ void ExtendUnconsumedLiveness::run() {
2923
2938
}
2924
2939
}
2925
2940
for (auto pair : addressUseState.reinitInsts ) {
2926
- if (pair.second .contains (element)) {
2941
+ if (pair.second .test (element)) {
2927
2942
destroys[pair.first ] = DestroyKind::Reinit;
2928
2943
}
2929
2944
}
0 commit comments