@@ -553,7 +553,7 @@ struct UseState {
553
553
// / consider them to be takes since after the transform they must be a take.
554
554
// /
555
555
// / Importantly, these we know are never copied and are only consumed once.
556
- llvm::SmallMapVector<SILInstruction *, TypeTreeLeafTypeRange, 4 > takeInsts;
556
+ InstToBitMap takeInsts;
557
557
558
558
// / A map from a copy_addr, load [copy], or load [take] that we determine
559
559
// / semantically are true copies to the part of the type tree they must copy.
@@ -573,7 +573,7 @@ struct UseState {
573
573
// / We represent these separately from \p takeInsts since:
574
574
// /
575
575
// / 1.
576
- llvm::SmallMapVector<SILInstruction *, TypeTreeLeafTypeRange, 4 > copyInsts;
576
+ InstToBitMap copyInsts;
577
577
578
578
// / A map from an instruction that initializes memory to the description of
579
579
// / the part of the type tree that it initializes.
@@ -654,6 +654,14 @@ struct UseState {
654
654
setAffectedBits (inst, range, initInsts);
655
655
}
656
656
657
+ void recordTakeUse (SILInstruction *inst, TypeTreeLeafTypeRange range) {
658
+ setAffectedBits (inst, range, takeInsts);
659
+ }
660
+
661
+ void recordCopyUse (SILInstruction *inst, TypeTreeLeafTypeRange range) {
662
+ setAffectedBits (inst, range, copyInsts);
663
+ }
664
+
657
665
// / Returns true if this is an instruction that is used by the pass to ensure
658
666
// / that we reinit said argument if we consumed it in a region of code.
659
667
// /
@@ -795,18 +803,18 @@ struct UseState {
795
803
});
796
804
}
797
805
798
- bool isConsume (SILInstruction *inst, TypeTreeLeafTypeRange span ) const {
806
+ bool isConsume (SILInstruction *inst, SmallBitVector const &bits ) const {
799
807
{
800
808
auto iter = takeInsts.find (inst);
801
809
if (iter != takeInsts.end ()) {
802
- if (span. setIntersection (iter->second ))
810
+ if (bits. anyCommon (iter->second ))
803
811
return true ;
804
812
}
805
813
}
806
814
{
807
815
auto iter = copyInsts.find (inst);
808
816
if (iter != copyInsts.end ()) {
809
- if (span. setIntersection (iter->second ))
817
+ if (bits. anyCommon (iter->second ))
810
818
return true ;
811
819
}
812
820
}
@@ -816,34 +824,32 @@ struct UseState {
816
824
bool isCopy (SILInstruction *inst, const SmallBitVector &bv) const {
817
825
auto iter = copyInsts.find (inst);
818
826
if (iter != copyInsts.end ()) {
819
- for (unsigned index : iter->second .getRange ()) {
820
- if (bv[index])
821
- return true ;
822
- }
827
+ if (bv.anyCommon (iter->second ))
828
+ return true ;
823
829
}
824
830
return false ;
825
831
}
826
832
827
- bool isLivenessUse (SILInstruction *inst, TypeTreeLeafTypeRange span ) const {
833
+ bool isLivenessUse (SILInstruction *inst, SmallBitVector const &bits ) const {
828
834
{
829
835
auto iter = nonconsumingUses.find (inst);
830
836
if (iter != nonconsumingUses.end ()) {
831
- if (span. intersects (iter->second ))
837
+ if (bits. anyCommon (iter->second ))
832
838
return true ;
833
839
}
834
840
}
835
841
{
836
842
auto iter = borrows.find (inst);
837
843
if (iter != borrows.end ()) {
838
- if (span. setIntersection ( iter->second ))
844
+ if (iter->second . intersects (bits ))
839
845
return true ;
840
846
}
841
847
}
842
848
843
849
if (!isReinitToInitConvertibleInst (inst)) {
844
850
auto iter = reinitInsts.find (inst);
845
851
if (iter != reinitInsts.end ()) {
846
- if (span. intersects (iter->second ))
852
+ if (bits. anyCommon (iter->second ))
847
853
return true ;
848
854
}
849
855
}
@@ -857,40 +863,19 @@ struct UseState {
857
863
return false ;
858
864
}
859
865
860
- bool isInitUse (SILInstruction *inst, TypeTreeLeafTypeRange span) const {
861
- {
862
- auto iter = initInsts.find (inst);
863
- if (iter != initInsts.end ()) {
864
- if (span.intersects (iter->second ))
865
- return true ;
866
- }
867
- }
868
- if (isReinitToInitConvertibleInst (inst)) {
869
- auto iter = reinitInsts.find (inst);
870
- if (iter != reinitInsts.end ()) {
871
- if (span.intersects (iter->second ))
872
- return true ;
873
- }
874
- }
875
- return false ;
876
- }
877
-
878
- bool isInitUse (SILInstruction *inst, const SmallBitVector &requiredBits,
879
- SmallBitVector &foundInitBits) const {
866
+ bool isInitUse (SILInstruction *inst, const SmallBitVector &requiredBits) const {
880
867
{
881
868
auto iter = initInsts.find (inst);
882
869
if (iter != initInsts.end ()) {
883
- foundInitBits = iter->second & requiredBits;
884
- if (foundInitBits.any ())
870
+ if (requiredBits.anyCommon (iter->second ))
885
871
return true ;
886
872
}
887
873
}
888
874
889
875
if (isReinitToInitConvertibleInst (inst)) {
890
876
auto iter = reinitInsts.find (inst);
891
877
if (iter != reinitInsts.end ()) {
892
- foundInitBits = iter->second & requiredBits;
893
- if (foundInitBits.any ())
878
+ if (requiredBits.anyCommon (iter->second ))
894
879
return true ;
895
880
}
896
881
}
@@ -2193,10 +2178,10 @@ bool GatherUsesVisitor::visitUse(Operand *op) {
2193
2178
2194
2179
if (copyAddr->isTakeOfSrc ()) {
2195
2180
LLVM_DEBUG (llvm::dbgs () << " Found take: " << *user);
2196
- useState.takeInsts . insert ({ user, *leafRange} );
2181
+ useState.recordTakeUse ( user, *leafRange);
2197
2182
} else {
2198
2183
LLVM_DEBUG (llvm::dbgs () << " Found copy: " << *user);
2199
- useState.copyInsts . insert ({ user, *leafRange} );
2184
+ useState.recordCopyUse ( user, *leafRange);
2200
2185
}
2201
2186
return true ;
2202
2187
}
@@ -2405,10 +2390,10 @@ bool GatherUsesVisitor::visitUse(Operand *op) {
2405
2390
// done checking. The load [take] are already complete and good to go.
2406
2391
if (li->getOwnershipQualifier () == LoadOwnershipQualifier::Take) {
2407
2392
LLVM_DEBUG (llvm::dbgs () << " Found take inst: " << *user);
2408
- useState.takeInsts . insert ({ user, *leafRange} );
2393
+ useState.recordTakeUse ( user, *leafRange);
2409
2394
} else {
2410
2395
LLVM_DEBUG (llvm::dbgs () << " Found copy inst: " << *user);
2411
- useState.copyInsts . insert ({ user, *leafRange} );
2396
+ useState.recordCopyUse ( user, *leafRange);
2412
2397
}
2413
2398
}
2414
2399
return true ;
@@ -2457,7 +2442,7 @@ bool GatherUsesVisitor::visitUse(Operand *op) {
2457
2442
}
2458
2443
2459
2444
LLVM_DEBUG (llvm::dbgs () << " Pure consuming use: " << *user);
2460
- useState.takeInsts . insert ({ user, *leafRange} );
2445
+ useState.recordTakeUse ( user, *leafRange);
2461
2446
return true ;
2462
2447
}
2463
2448
@@ -2668,9 +2653,7 @@ struct GlobalLivenessChecker {
2668
2653
// / Returns true if we emitted any errors.
2669
2654
bool compute ();
2670
2655
2671
- bool testInstVectorLiveness (
2672
- llvm::SmallMapVector<SILInstruction *, TypeTreeLeafTypeRange, 4 >
2673
- &instsToTest);
2656
+ bool testInstVectorLiveness (UseState::InstToBitMap &instsToTest);
2674
2657
2675
2658
void clear () {
2676
2659
livenessVector.clear ();
@@ -2681,8 +2664,7 @@ struct GlobalLivenessChecker {
2681
2664
} // namespace
2682
2665
2683
2666
bool GlobalLivenessChecker::testInstVectorLiveness (
2684
- llvm::SmallMapVector<SILInstruction *, TypeTreeLeafTypeRange, 4 >
2685
- &instsToTest) {
2667
+ UseState::InstToBitMap &instsToTest) {
2686
2668
bool emittedDiagnostic = false ;
2687
2669
2688
2670
for (auto takeInstAndValue : instsToTest) {
@@ -2835,9 +2817,7 @@ bool GlobalLivenessChecker::testInstVectorLiveness(
2835
2817
#ifndef NDEBUG
2836
2818
SmallBitVector defBits (addressUseState.getNumSubelements ());
2837
2819
liveness.isDefBlock (block, errorSpan, defBits);
2838
- SmallBitVector errorSpanBits (addressUseState.getNumSubelements ());
2839
- errorSpan.setBits (errorSpanBits);
2840
- assert ((defBits & errorSpanBits).none () &&
2820
+ assert ((defBits & errorSpan).none () &&
2841
2821
" If in def block... we are in liveness block" );
2842
2822
#endif
2843
2823
[[clang::fallthrough]];
@@ -3228,8 +3208,7 @@ void MoveOnlyAddressCheckerPImpl::rewriteUses(
3228
3208
3229
3209
// Check all takes.
3230
3210
for (auto takeInst : addressUseState.takeInsts ) {
3231
- SmallBitVector bits (liveness.getNumSubElements ());
3232
- takeInst.second .setBits (bits);
3211
+ auto &bits = takeInst.second ;
3233
3212
bool claimedConsume = consumes.claimConsume (takeInst.first , bits);
3234
3213
(void )claimedConsume;
3235
3214
if (!claimedConsume) {
@@ -3242,8 +3221,7 @@ void MoveOnlyAddressCheckerPImpl::rewriteUses(
3242
3221
3243
3222
// Then rewrite all copy insts to be takes and claim them.
3244
3223
for (auto copyInst : addressUseState.copyInsts ) {
3245
- SmallBitVector bits (liveness.getNumSubElements ());
3246
- copyInst.second .setBits (bits);
3224
+ auto &bits = copyInst.second ;
3247
3225
bool claimedConsume = consumes.claimConsume (copyInst.first , bits);
3248
3226
if (!claimedConsume) {
3249
3227
llvm::errs ()
@@ -3408,7 +3386,7 @@ void ExtendUnconsumedLiveness::run() {
3408
3386
}
3409
3387
}
3410
3388
for (auto pair : addressUseState.takeInsts ) {
3411
- if (pair.second .contains (element)) {
3389
+ if (pair.second .test (element)) {
3412
3390
destroys[pair.first ] = DestroyKind::Take;
3413
3391
}
3414
3392
}
0 commit comments