@@ -626,7 +626,7 @@ struct UseState {
626626
627627 // / memInstMustReinitialize insts. Contains both insts like copy_addr/store
628628 // / [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;
630630
631631 // / The set of drop_deinits of this mark_must_check
632632 SmallSetVector<SILInstruction *, 2 > dropDeinitInsts;
@@ -668,9 +668,17 @@ struct UseState {
668668
669669 void recordLivenessUse (SILInstruction *inst, TypeTreeLeafTypeRange range) {
670670 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 ;
673679 }
680+ auto &bits = iter->second ;
681+ range.setBits (bits);
674682 }
675683
676684 // / Returns true if this is a terminator instruction that although it doesn't
@@ -765,14 +773,24 @@ struct UseState {
765773 }
766774 }
767775
768- void recordConsumingBlock (SILBasicBlock *block, TypeTreeLeafTypeRange range ) {
776+ SmallBitVector & getOrCreateConsumingBlock (SILBasicBlock *block) {
769777 auto iter = consumingBlocks.find (block);
770778 if (iter == consumingBlocks.end ()) {
771779 iter =
772780 consumingBlocks.insert ({block, SmallBitVector (getNumSubelements ())})
773781 .first ;
774782 }
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;
776794 }
777795
778796 void
@@ -839,7 +857,7 @@ struct UseState {
839857 if (!isReinitToInitConvertibleInst (inst)) {
840858 auto iter = reinitInsts.find (inst);
841859 if (iter != reinitInsts.end ()) {
842- if (span.setIntersection (iter->second ))
860+ if (span.intersects (iter->second ))
843861 return true ;
844862 }
845863 }
@@ -864,7 +882,7 @@ struct UseState {
864882 if (isReinitToInitConvertibleInst (inst)) {
865883 auto iter = reinitInsts.find (inst);
866884 if (iter != reinitInsts.end ()) {
867- if (span.setIntersection (iter->second ))
885+ if (span.intersects (iter->second ))
868886 return true ;
869887 }
870888 }
@@ -1741,11 +1759,10 @@ bool GatherUsesVisitor::visitUse(Operand *op) {
17411759
17421760 if (::memInstMustReinitialize (op)) {
17431761 LLVM_DEBUG (llvm::dbgs () << " Found reinit: " << *user);
1744- assert (!useState.reinitInsts .count (user));
17451762 auto leafRange = TypeTreeLeafTypeRange::get (op->get (), getRootAddress ());
17461763 if (!leafRange)
17471764 return false ;
1748- useState.reinitInsts . insert ({ user, *leafRange} );
1765+ useState.recordReinitUse ( user, *leafRange);
17491766 return true ;
17501767 }
17511768
@@ -2730,9 +2747,7 @@ void MoveOnlyAddressCheckerPImpl::rewriteUses(
27302747 for (auto reinitPair : addressUseState.reinitInsts ) {
27312748 if (!isReinitToInitConvertibleInst (reinitPair.first ))
27322749 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 ))
27362751 convertMemoryReinitToInitForm (reinitPair.first , debugVar);
27372752 }
27382753
@@ -2923,7 +2938,7 @@ void ExtendUnconsumedLiveness::run() {
29232938 }
29242939 }
29252940 for (auto pair : addressUseState.reinitInsts ) {
2926- if (pair.second .contains (element)) {
2941+ if (pair.second .test (element)) {
29272942 destroys[pair.first ] = DestroyKind::Reinit;
29282943 }
29292944 }
0 commit comments