28
28
29
29
using namespace swift ;
30
30
31
+ static llvm::cl::opt<bool > EmitLogging (
32
+ " sil-move-only-checker-emit-pruned-liveness-logging" );
33
+
34
+ #define PRUNED_LIVENESS_LOG (X ) \
35
+ do { \
36
+ if (EmitLogging) { \
37
+ LLVM_DEBUG (X); \
38
+ } \
39
+ } while (0 )
40
+
31
41
// We can only analyze components of structs whose storage is fully accessible
32
42
// from Swift.
33
43
static StructDecl *getFullyReferenceableStruct (SILType ktypeTy) {
@@ -298,7 +308,7 @@ void TypeTreeLeafTypeRange::constructFilteredProjections(
298
308
auto *fn = insertPt->getFunction ();
299
309
SILType type = value->getType ();
300
310
301
- LLVM_DEBUG (llvm::dbgs () << " ConstructFilteredProjection. Bv: "
311
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " ConstructFilteredProjection. Bv: "
302
312
<< filterBitVector << ' \n ' );
303
313
SILBuilderWithScope builder (insertPt);
304
314
@@ -564,14 +574,14 @@ bool FieldSensitivePrunedLiveRange<LivenessWithDefs>::isWithinBoundary(
564
574
SILInstruction *inst, TypeTreeLeafTypeRange span) const {
565
575
assert (asImpl ().isInitialized ());
566
576
567
- LLVM_DEBUG (
577
+ PRUNED_LIVENESS_LOG (
568
578
llvm::dbgs () << " FieldSensitivePrunedLiveRange::isWithinBoundary!\n "
569
579
<< " Span: " ;
570
580
span.print (llvm::dbgs ()); llvm::dbgs () << ' \n ' );
571
581
572
582
// If we do not have any span, return true since we have no counter examples.
573
583
if (span.empty ()) {
574
- LLVM_DEBUG (llvm::dbgs () << " span is empty! Returning true!\n " );
584
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " span is empty! Returning true!\n " );
575
585
return true ;
576
586
}
577
587
@@ -584,11 +594,11 @@ bool FieldSensitivePrunedLiveRange<LivenessWithDefs>::isWithinBoundary(
584
594
585
595
for (auto pair : llvm::enumerate (outVector)) {
586
596
unsigned bit = span.startEltOffset + pair.index ();
587
- LLVM_DEBUG (llvm::dbgs () << " Visiting bit: " << bit << ' \n ' );
597
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Visiting bit: " << bit << ' \n ' );
588
598
bool isLive = false ;
589
599
switch (pair.value ()) {
590
600
case FieldSensitivePrunedLiveBlocks::Dead:
591
- LLVM_DEBUG (llvm::dbgs () << " Dead... continuing!\n " );
601
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Dead... continuing!\n " );
592
602
// We are only not within the boundary if all of our bits are dead. We
593
603
// track this via allDeadBits. So, just continue.
594
604
continue ;
@@ -598,52 +608,52 @@ bool FieldSensitivePrunedLiveRange<LivenessWithDefs>::isWithinBoundary(
598
608
// the boundary if /any/ of our bits are within the boundary. So return
599
609
// true.
600
610
if (!asImpl ().isDefBlock (block, bit)) {
601
- LLVM_DEBUG (
611
+ PRUNED_LIVENESS_LOG (
602
612
llvm::dbgs ()
603
613
<< " LiveOut... but not in a def block... returning true "
604
614
" since we are within the boundary for at least one bit" );
605
615
return true ;
606
616
}
607
617
608
618
isLive = true ;
609
- LLVM_DEBUG (llvm::dbgs ()
619
+ PRUNED_LIVENESS_LOG (llvm::dbgs ()
610
620
<< " LiveOut, but a def block... searching block!\n " );
611
621
[[clang::fallthrough]];
612
622
case FieldSensitivePrunedLiveBlocks::LiveWithin:
613
623
bool shouldContinue = false ;
614
624
if (!isLive)
615
- LLVM_DEBUG (llvm::dbgs () << " LiveWithin... searching block!\n " );
625
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " LiveWithin... searching block!\n " );
616
626
617
627
// Now check if the instruction is between a last use and a definition.
618
628
for (auto &blockInst : llvm::reverse (*block)) {
619
- LLVM_DEBUG (llvm::dbgs () << " Inst: Live: "
629
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Inst: Live: "
620
630
<< (isLive ? " true" : " false" ) << " \n "
621
631
<< " " << blockInst);
622
632
623
633
// First if we see a def, set isLive to false.
624
634
if (asImpl ().isDef (&blockInst, bit)) {
625
- LLVM_DEBUG (llvm::dbgs ()
635
+ PRUNED_LIVENESS_LOG (llvm::dbgs ()
626
636
<< " Inst is a def... marking live to false!\n " );
627
637
isLive = false ;
628
638
}
629
639
630
640
// Then check if we found our instruction in the block...
631
641
if (&blockInst == inst) {
632
- LLVM_DEBUG (llvm::dbgs ()
642
+ PRUNED_LIVENESS_LOG (llvm::dbgs ()
633
643
<< " Inst is inst we are looking for.\n " );
634
644
635
645
// If we are live in the block when we reach the inst... we must be in
636
646
// the block.
637
647
if (isLive) {
638
- LLVM_DEBUG (llvm::dbgs ()
648
+ PRUNED_LIVENESS_LOG (llvm::dbgs ()
639
649
<< " Inst was live... so returning true!\n " );
640
650
return true ;
641
651
}
642
652
643
653
// Otherwise, we know that we are not within the boundary for this
644
654
// def... continue.
645
655
shouldContinue = true ;
646
- LLVM_DEBUG (llvm::dbgs ()
656
+ PRUNED_LIVENESS_LOG (llvm::dbgs ()
647
657
<< " Inst was dead... so breaking out of loop!\n " );
648
658
break ;
649
659
}
@@ -654,7 +664,7 @@ bool FieldSensitivePrunedLiveRange<LivenessWithDefs>::isWithinBoundary(
654
664
auto interestingUser = isInterestingUser (&blockInst);
655
665
bool isInteresting =
656
666
interestingUser.first && interestingUser.second ->contains (bit);
657
- LLVM_DEBUG (llvm::dbgs ()
667
+ PRUNED_LIVENESS_LOG (llvm::dbgs ()
658
668
<< " Inst was dead... Is InterestingUser: "
659
669
<< (isInteresting ? " true" : " false" ) << ' \n ' );
660
670
isLive |= isInteresting;
@@ -688,29 +698,29 @@ void FieldSensitivePrunedLiveRange<LivenessWithDefs>::computeBoundary(
688
698
FieldSensitivePrunedLivenessBoundary &boundary) const {
689
699
assert (asImpl ().isInitialized ());
690
700
691
- LLVM_DEBUG (llvm::dbgs () << " Liveness Boundary Compuation!\n " );
701
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Liveness Boundary Compuation!\n " );
692
702
693
703
using IsLive = FieldSensitivePrunedLiveBlocks::IsLive;
694
704
SmallVector<IsLive, 8 > isLiveTmp;
695
705
for (SILBasicBlock *block : getDiscoveredBlocks ()) {
696
706
SWIFT_DEFER { isLiveTmp.clear (); };
697
707
getBlockLiveness (block, isLiveTmp);
698
708
699
- LLVM_DEBUG (llvm::dbgs ()
709
+ PRUNED_LIVENESS_LOG (llvm::dbgs ()
700
710
<< " Checking for boundary in bb" << block->getDebugID () << ' \n ' );
701
711
702
712
// Process each block that has not been visited and is not LiveOut.
703
713
bool foundAnyNonDead = false ;
704
714
for (auto pair : llvm::enumerate (isLiveTmp)) {
705
715
unsigned index = pair.index ();
706
- LLVM_DEBUG (llvm::dbgs () << " Bit: " << index << " . Liveness: "
716
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Bit: " << index << " . Liveness: "
707
717
<< getStringRef (pair.value ()) << ' \n ' );
708
718
switch (pair.value ()) {
709
719
case FieldSensitivePrunedLiveBlocks::LiveOut:
710
720
for (SILBasicBlock *succBB : block->getSuccessors ()) {
711
721
if (getBlockLiveness (succBB, index) ==
712
722
FieldSensitivePrunedLiveBlocks::Dead) {
713
- LLVM_DEBUG (llvm::dbgs () << " Marking succBB as boundary edge: bb"
723
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Marking succBB as boundary edge: bb"
714
724
<< succBB->getDebugID () << ' \n ' );
715
725
boundary.getBoundaryEdgeBits (succBB).set (index);
716
726
}
@@ -739,12 +749,12 @@ void FieldSensitivePrunedLiveRange<LivenessWithDefs>::computeBoundary(
739
749
template <typename LivenessWithDefs>
740
750
void FieldSensitivePrunedLiveRange<LivenessWithDefs>::updateForUse(
741
751
SILInstruction *user, TypeTreeLeafTypeRange range, bool lifetimeEnding) {
742
- LLVM_DEBUG (
752
+ PRUNED_LIVENESS_LOG (
743
753
llvm::dbgs ()
744
754
<< " Begin FieldSensitivePrunedLiveRange<LivenessWithDefs>::updateForUse "
745
755
" for: "
746
756
<< *user);
747
- LLVM_DEBUG (
757
+ PRUNED_LIVENESS_LOG (
748
758
llvm::dbgs () << " Looking for def instruction earlier in the block!\n " );
749
759
750
760
auto *parentBlock = user->getParent ();
@@ -754,8 +764,8 @@ void FieldSensitivePrunedLiveRange<LivenessWithDefs>::updateForUse(
754
764
// If we find the def, just mark this instruction as being an interesting
755
765
// instruction.
756
766
if (asImpl ().isDef (&*ii, range)) {
757
- LLVM_DEBUG (llvm::dbgs () << " Found def: " << *ii);
758
- LLVM_DEBUG (llvm::dbgs ()
767
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Found def: " << *ii);
768
+ PRUNED_LIVENESS_LOG (llvm::dbgs ()
759
769
<< " Marking inst as interesting user and returning!\n " );
760
770
addInterestingUser (user, range, lifetimeEnding);
761
771
return ;
@@ -765,7 +775,7 @@ void FieldSensitivePrunedLiveRange<LivenessWithDefs>::updateForUse(
765
775
// Otherwise, just delegate to our parent class's update for use. This will
766
776
// update liveness for our predecessor blocks and add this instruction as an
767
777
// interesting user.
768
- LLVM_DEBUG (llvm::dbgs () << " No defs found! Delegating to "
778
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " No defs found! Delegating to "
769
779
" FieldSensitivePrunedLiveness::updateForUse.\n " );
770
780
FieldSensitivePrunedLiveness::updateForUse (user, range, lifetimeEnding);
771
781
}
@@ -781,12 +791,12 @@ void findBoundaryInNonDefBlock(SILBasicBlock *block, unsigned bitNo,
781
791
assert (liveness.getBlockLiveness (block, bitNo) ==
782
792
FieldSensitivePrunedLiveBlocks::LiveWithin);
783
793
784
- LLVM_DEBUG (llvm::dbgs () << " Looking for boundary in non-def block\n " );
794
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Looking for boundary in non-def block\n " );
785
795
for (SILInstruction &inst : llvm::reverse (*block)) {
786
- LLVM_DEBUG (llvm::dbgs () << " Visiting: " << inst);
796
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Visiting: " << inst);
787
797
auto interestingUser = liveness.isInterestingUser (&inst);
788
798
if (interestingUser.first && interestingUser.second ->contains (bitNo)) {
789
- LLVM_DEBUG (llvm::dbgs () << " Is interesting user for this bit!\n " );
799
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Is interesting user for this bit!\n " );
790
800
boundary.getLastUserBits (&inst).set (bitNo);
791
801
return ;
792
802
}
@@ -806,25 +816,25 @@ void findBoundaryInSSADefBlock(SILNode *ssaDef, unsigned bitNo,
806
816
FieldSensitivePrunedLivenessBoundary &boundary,
807
817
const FieldSensitivePrunedLiveness &liveness) {
808
818
// defInst is null for argument defs.
809
- LLVM_DEBUG (llvm::dbgs () << " Searching using findBoundaryInSSADefBlock.\n " );
819
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Searching using findBoundaryInSSADefBlock.\n " );
810
820
SILInstruction *defInst = dyn_cast<SILInstruction>(ssaDef);
811
821
for (SILInstruction &inst : llvm::reverse (*ssaDef->getParentBlock ())) {
812
- LLVM_DEBUG (llvm::dbgs () << " Visiting: " << inst);
822
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Visiting: " << inst);
813
823
if (&inst == defInst) {
814
- LLVM_DEBUG (llvm::dbgs () << " Found dead def: " << *defInst);
824
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Found dead def: " << *defInst);
815
825
boundary.getDeadDefsBits (cast<SILNode>(&inst)).set (bitNo);
816
826
return ;
817
827
}
818
828
auto interestingUser = liveness.isInterestingUser (&inst);
819
829
if (interestingUser.first && interestingUser.second ->contains (bitNo)) {
820
- LLVM_DEBUG (llvm::dbgs () << " Found interesting user: " << inst);
830
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Found interesting user: " << inst);
821
831
boundary.getLastUserBits (&inst).set (bitNo);
822
832
return ;
823
833
}
824
834
}
825
835
826
836
auto *deadArg = cast<SILArgument>(ssaDef);
827
- LLVM_DEBUG (llvm::dbgs () << " Found dead arg: " << *deadArg);
837
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Found dead arg: " << *deadArg);
828
838
boundary.getDeadDefsBits (deadArg).set (bitNo);
829
839
}
830
840
@@ -873,47 +883,47 @@ void FieldSensitiveMultiDefPrunedLiveRange::findBoundariesInBlock(
873
883
FieldSensitivePrunedLivenessBoundary &boundary) const {
874
884
assert (isInitialized ());
875
885
876
- LLVM_DEBUG (llvm::dbgs () << " Checking for boundary in bb"
886
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Checking for boundary in bb"
877
887
<< block->getDebugID () << " for bit: " << bitNo
878
888
<< " . Is Live: " << (isLiveOut ? " true" : " false" )
879
889
<< ' \n ' );
880
890
881
891
if (!isDefBlock (block, bitNo)) {
882
- LLVM_DEBUG (llvm::dbgs () << " Not a def block for this bit?!\n " );
892
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Not a def block for this bit?!\n " );
883
893
// A live-out block that does not contain any defs cannot have a boundary.
884
894
if (isLiveOut) {
885
- LLVM_DEBUG (llvm::dbgs () << " Is live out... nothing further to do.\n " );
895
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Is live out... nothing further to do.\n " );
886
896
return ;
887
897
}
888
898
889
- LLVM_DEBUG (llvm::dbgs () << " Is LiveWithin, so looking for boundary "
899
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Is LiveWithin, so looking for boundary "
890
900
" in non-def block?!\n " );
891
901
findBoundaryInNonDefBlock (block, bitNo, boundary, *this );
892
902
return ;
893
903
}
894
904
895
- LLVM_DEBUG (llvm::dbgs () << " Is def block!\n " );
905
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Is def block!\n " );
896
906
897
907
// Handle def blocks...
898
908
//
899
909
// First, check for an SSA live range
900
910
if (defs.size () == 1 ) {
901
- LLVM_DEBUG (llvm::dbgs () << " Has single def...\n " );
911
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Has single def...\n " );
902
912
// For SSA, a live-out block cannot have a boundary.
903
913
if (isLiveOut) {
904
- LLVM_DEBUG (llvm::dbgs () << " Is live out... no further work to do...\n " );
914
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Is live out... no further work to do...\n " );
905
915
return ;
906
916
}
907
917
908
- LLVM_DEBUG (llvm::dbgs () << " Is live within... checking for boundary "
918
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Is live within... checking for boundary "
909
919
" using SSA def block impl.\n " );
910
920
assert (defs.vector_begin ()->second ->contains (bitNo));
911
921
findBoundaryInSSADefBlock (defs.vector_begin ()->first , bitNo, boundary,
912
922
*this );
913
923
return ;
914
924
}
915
925
916
- LLVM_DEBUG (llvm::dbgs () << " Has multiple defs!\n " );
926
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Has multiple defs!\n " );
917
927
918
928
// Handle a live-out or live-within block with potentially multiple defs
919
929
#ifndef NDEBUG
@@ -925,20 +935,20 @@ void FieldSensitiveMultiDefPrunedLiveRange::findBoundariesInBlock(
925
935
#endif
926
936
bool isLive = isLiveOut;
927
937
for (auto &inst : llvm::reverse (*block)) {
928
- LLVM_DEBUG (llvm::dbgs () << " Visiting: " << inst);
929
- LLVM_DEBUG (llvm::dbgs () << " Initial IsLive: "
938
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Visiting: " << inst);
939
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Initial IsLive: "
930
940
<< (isLive ? " true" : " false" ) << ' \n ' );
931
941
932
942
// Check if the instruction is a def before checking whether it is a
933
943
// use. The same instruction can be both a dead def and boundary use.
934
944
if (isDef (&inst, bitNo)) {
935
- LLVM_DEBUG (llvm::dbgs () << " Is a def inst!\n " );
945
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Is a def inst!\n " );
936
946
if (!isLive) {
937
- LLVM_DEBUG (llvm::dbgs () << " We are not live... so mark as dead "
947
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " We are not live... so mark as dead "
938
948
" def and keep isLive false!\n " );
939
949
boundary.getDeadDefsBits (cast<SILNode>(&inst)).set (bitNo);
940
950
} else {
941
- LLVM_DEBUG (
951
+ PRUNED_LIVENESS_LOG (
942
952
llvm::dbgs ()
943
953
<< " Is live usage... so just mark isLive to false.\n " );
944
954
}
@@ -948,37 +958,37 @@ void FieldSensitiveMultiDefPrunedLiveRange::findBoundariesInBlock(
948
958
// Note: the same instruction could potentially be both a dead def and last
949
959
// user. The liveness boundary supports this, although it won't happen in
950
960
// any context where we care about inserting code on the boundary.
951
- LLVM_DEBUG (llvm::dbgs ()
961
+ PRUNED_LIVENESS_LOG (llvm::dbgs ()
952
962
<< " Checking if this inst is also a last user...\n " );
953
963
if (!isLive) {
954
964
auto interestingUser = isInterestingUser (&inst);
955
965
if (interestingUser.first && interestingUser.second ->contains (bitNo)) {
956
- LLVM_DEBUG (
966
+ PRUNED_LIVENESS_LOG (
957
967
llvm::dbgs ()
958
968
<< " Was interesting user! Moving from dead -> live!\n " );
959
969
boundary.getLastUserBits (&inst).set (bitNo);
960
970
isLive = true ;
961
971
} else {
962
- LLVM_DEBUG (llvm::dbgs ()
972
+ PRUNED_LIVENESS_LOG (llvm::dbgs ()
963
973
<< " Not interesting user... keeping dead!\n " );
964
974
}
965
975
} else {
966
- LLVM_DEBUG (llvm::dbgs ()
976
+ PRUNED_LIVENESS_LOG (llvm::dbgs ()
967
977
<< " Was live already, so cannot be a last user!\n " );
968
978
}
969
979
}
970
980
971
- LLVM_DEBUG (llvm::dbgs () << " Finished processing block instructions... now "
981
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Finished processing block instructions... now "
972
982
" checking for dead arguments if dead!\n " );
973
983
if (!isLive) {
974
- LLVM_DEBUG (llvm::dbgs () << " Not live! Checking for dead args!\n " );
984
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Not live! Checking for dead args!\n " );
975
985
for (SILArgument *deadArg : block->getArguments ()) {
976
986
auto iter = defs.find (deadArg);
977
987
if (iter.has_value () &&
978
988
llvm::any_of (*iter, [&](TypeTreeLeafTypeRange span) {
979
989
return span.contains (bitNo);
980
990
})) {
981
- LLVM_DEBUG (llvm::dbgs () << " Found dead arg: " << *deadArg);
991
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Found dead arg: " << *deadArg);
982
992
boundary.getDeadDefsBits (deadArg).set (bitNo);
983
993
}
984
994
}
@@ -998,7 +1008,7 @@ void FieldSensitiveMultiDefPrunedLiveRange::findBoundariesInBlock(
998
1008
}
999
1009
}
1000
1010
} else {
1001
- LLVM_DEBUG (llvm::dbgs ()
1011
+ PRUNED_LIVENESS_LOG (llvm::dbgs ()
1002
1012
<< " Live at beginning of block! No dead args!\n " );
1003
1013
}
1004
1014
0 commit comments