Skip to content

Commit 8afcf86

Browse files
authored
Merge pull request #64212 from gottesmm/pr-fb301de4feea0e8915a38c05d19ef7580714284b
[move-only] Remove misguided handling of inout.
2 parents 2419729 + c3787df commit 8afcf86

File tree

4 files changed

+172
-73
lines changed

4 files changed

+172
-73
lines changed

lib/SIL/Utils/FieldSensitivePrunedLiveness.cpp

Lines changed: 63 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@
2828

2929
using namespace swift;
3030

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+
3141
// We can only analyze components of structs whose storage is fully accessible
3242
// from Swift.
3343
static StructDecl *getFullyReferenceableStruct(SILType ktypeTy) {
@@ -298,7 +308,7 @@ void TypeTreeLeafTypeRange::constructFilteredProjections(
298308
auto *fn = insertPt->getFunction();
299309
SILType type = value->getType();
300310

301-
LLVM_DEBUG(llvm::dbgs() << "ConstructFilteredProjection. Bv: "
311+
PRUNED_LIVENESS_LOG(llvm::dbgs() << "ConstructFilteredProjection. Bv: "
302312
<< filterBitVector << '\n');
303313
SILBuilderWithScope builder(insertPt);
304314

@@ -564,14 +574,14 @@ bool FieldSensitivePrunedLiveRange<LivenessWithDefs>::isWithinBoundary(
564574
SILInstruction *inst, TypeTreeLeafTypeRange span) const {
565575
assert(asImpl().isInitialized());
566576

567-
LLVM_DEBUG(
577+
PRUNED_LIVENESS_LOG(
568578
llvm::dbgs() << "FieldSensitivePrunedLiveRange::isWithinBoundary!\n"
569579
<< "Span: ";
570580
span.print(llvm::dbgs()); llvm::dbgs() << '\n');
571581

572582
// If we do not have any span, return true since we have no counter examples.
573583
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");
575585
return true;
576586
}
577587

@@ -584,11 +594,11 @@ bool FieldSensitivePrunedLiveRange<LivenessWithDefs>::isWithinBoundary(
584594

585595
for (auto pair : llvm::enumerate(outVector)) {
586596
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');
588598
bool isLive = false;
589599
switch (pair.value()) {
590600
case FieldSensitivePrunedLiveBlocks::Dead:
591-
LLVM_DEBUG(llvm::dbgs() << " Dead... continuing!\n");
601+
PRUNED_LIVENESS_LOG(llvm::dbgs() << " Dead... continuing!\n");
592602
// We are only not within the boundary if all of our bits are dead. We
593603
// track this via allDeadBits. So, just continue.
594604
continue;
@@ -598,52 +608,52 @@ bool FieldSensitivePrunedLiveRange<LivenessWithDefs>::isWithinBoundary(
598608
// the boundary if /any/ of our bits are within the boundary. So return
599609
// true.
600610
if (!asImpl().isDefBlock(block, bit)) {
601-
LLVM_DEBUG(
611+
PRUNED_LIVENESS_LOG(
602612
llvm::dbgs()
603613
<< " LiveOut... but not in a def block... returning true "
604614
"since we are within the boundary for at least one bit");
605615
return true;
606616
}
607617

608618
isLive = true;
609-
LLVM_DEBUG(llvm::dbgs()
619+
PRUNED_LIVENESS_LOG(llvm::dbgs()
610620
<< " LiveOut, but a def block... searching block!\n");
611621
[[clang::fallthrough]];
612622
case FieldSensitivePrunedLiveBlocks::LiveWithin:
613623
bool shouldContinue = false;
614624
if (!isLive)
615-
LLVM_DEBUG(llvm::dbgs() << " LiveWithin... searching block!\n");
625+
PRUNED_LIVENESS_LOG(llvm::dbgs() << " LiveWithin... searching block!\n");
616626

617627
// Now check if the instruction is between a last use and a definition.
618628
for (auto &blockInst : llvm::reverse(*block)) {
619-
LLVM_DEBUG(llvm::dbgs() << " Inst: Live: "
629+
PRUNED_LIVENESS_LOG(llvm::dbgs() << " Inst: Live: "
620630
<< (isLive ? "true" : "false") << "\n"
621631
<< " " << blockInst);
622632

623633
// First if we see a def, set isLive to false.
624634
if (asImpl().isDef(&blockInst, bit)) {
625-
LLVM_DEBUG(llvm::dbgs()
635+
PRUNED_LIVENESS_LOG(llvm::dbgs()
626636
<< " Inst is a def... marking live to false!\n");
627637
isLive = false;
628638
}
629639

630640
// Then check if we found our instruction in the block...
631641
if (&blockInst == inst) {
632-
LLVM_DEBUG(llvm::dbgs()
642+
PRUNED_LIVENESS_LOG(llvm::dbgs()
633643
<< " Inst is inst we are looking for.\n");
634644

635645
// If we are live in the block when we reach the inst... we must be in
636646
// the block.
637647
if (isLive) {
638-
LLVM_DEBUG(llvm::dbgs()
648+
PRUNED_LIVENESS_LOG(llvm::dbgs()
639649
<< " Inst was live... so returning true!\n");
640650
return true;
641651
}
642652

643653
// Otherwise, we know that we are not within the boundary for this
644654
// def... continue.
645655
shouldContinue = true;
646-
LLVM_DEBUG(llvm::dbgs()
656+
PRUNED_LIVENESS_LOG(llvm::dbgs()
647657
<< " Inst was dead... so breaking out of loop!\n");
648658
break;
649659
}
@@ -654,7 +664,7 @@ bool FieldSensitivePrunedLiveRange<LivenessWithDefs>::isWithinBoundary(
654664
auto interestingUser = isInterestingUser(&blockInst);
655665
bool isInteresting =
656666
interestingUser.first && interestingUser.second->contains(bit);
657-
LLVM_DEBUG(llvm::dbgs()
667+
PRUNED_LIVENESS_LOG(llvm::dbgs()
658668
<< " Inst was dead... Is InterestingUser: "
659669
<< (isInteresting ? "true" : "false") << '\n');
660670
isLive |= isInteresting;
@@ -688,29 +698,29 @@ void FieldSensitivePrunedLiveRange<LivenessWithDefs>::computeBoundary(
688698
FieldSensitivePrunedLivenessBoundary &boundary) const {
689699
assert(asImpl().isInitialized());
690700

691-
LLVM_DEBUG(llvm::dbgs() << "Liveness Boundary Compuation!\n");
701+
PRUNED_LIVENESS_LOG(llvm::dbgs() << "Liveness Boundary Compuation!\n");
692702

693703
using IsLive = FieldSensitivePrunedLiveBlocks::IsLive;
694704
SmallVector<IsLive, 8> isLiveTmp;
695705
for (SILBasicBlock *block : getDiscoveredBlocks()) {
696706
SWIFT_DEFER { isLiveTmp.clear(); };
697707
getBlockLiveness(block, isLiveTmp);
698708

699-
LLVM_DEBUG(llvm::dbgs()
709+
PRUNED_LIVENESS_LOG(llvm::dbgs()
700710
<< "Checking for boundary in bb" << block->getDebugID() << '\n');
701711

702712
// Process each block that has not been visited and is not LiveOut.
703713
bool foundAnyNonDead = false;
704714
for (auto pair : llvm::enumerate(isLiveTmp)) {
705715
unsigned index = pair.index();
706-
LLVM_DEBUG(llvm::dbgs() << "Bit: " << index << ". Liveness: "
716+
PRUNED_LIVENESS_LOG(llvm::dbgs() << "Bit: " << index << ". Liveness: "
707717
<< getStringRef(pair.value()) << '\n');
708718
switch (pair.value()) {
709719
case FieldSensitivePrunedLiveBlocks::LiveOut:
710720
for (SILBasicBlock *succBB : block->getSuccessors()) {
711721
if (getBlockLiveness(succBB, index) ==
712722
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"
714724
<< succBB->getDebugID() << '\n');
715725
boundary.getBoundaryEdgeBits(succBB).set(index);
716726
}
@@ -739,12 +749,12 @@ void FieldSensitivePrunedLiveRange<LivenessWithDefs>::computeBoundary(
739749
template <typename LivenessWithDefs>
740750
void FieldSensitivePrunedLiveRange<LivenessWithDefs>::updateForUse(
741751
SILInstruction *user, TypeTreeLeafTypeRange range, bool lifetimeEnding) {
742-
LLVM_DEBUG(
752+
PRUNED_LIVENESS_LOG(
743753
llvm::dbgs()
744754
<< "Begin FieldSensitivePrunedLiveRange<LivenessWithDefs>::updateForUse "
745755
"for: "
746756
<< *user);
747-
LLVM_DEBUG(
757+
PRUNED_LIVENESS_LOG(
748758
llvm::dbgs() << "Looking for def instruction earlier in the block!\n");
749759

750760
auto *parentBlock = user->getParent();
@@ -754,8 +764,8 @@ void FieldSensitivePrunedLiveRange<LivenessWithDefs>::updateForUse(
754764
// If we find the def, just mark this instruction as being an interesting
755765
// instruction.
756766
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()
759769
<< " Marking inst as interesting user and returning!\n");
760770
addInterestingUser(user, range, lifetimeEnding);
761771
return;
@@ -765,7 +775,7 @@ void FieldSensitivePrunedLiveRange<LivenessWithDefs>::updateForUse(
765775
// Otherwise, just delegate to our parent class's update for use. This will
766776
// update liveness for our predecessor blocks and add this instruction as an
767777
// interesting user.
768-
LLVM_DEBUG(llvm::dbgs() << "No defs found! Delegating to "
778+
PRUNED_LIVENESS_LOG(llvm::dbgs() << "No defs found! Delegating to "
769779
"FieldSensitivePrunedLiveness::updateForUse.\n");
770780
FieldSensitivePrunedLiveness::updateForUse(user, range, lifetimeEnding);
771781
}
@@ -781,12 +791,12 @@ void findBoundaryInNonDefBlock(SILBasicBlock *block, unsigned bitNo,
781791
assert(liveness.getBlockLiveness(block, bitNo) ==
782792
FieldSensitivePrunedLiveBlocks::LiveWithin);
783793

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");
785795
for (SILInstruction &inst : llvm::reverse(*block)) {
786-
LLVM_DEBUG(llvm::dbgs() << "Visiting: " << inst);
796+
PRUNED_LIVENESS_LOG(llvm::dbgs() << "Visiting: " << inst);
787797
auto interestingUser = liveness.isInterestingUser(&inst);
788798
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");
790800
boundary.getLastUserBits(&inst).set(bitNo);
791801
return;
792802
}
@@ -806,25 +816,25 @@ void findBoundaryInSSADefBlock(SILNode *ssaDef, unsigned bitNo,
806816
FieldSensitivePrunedLivenessBoundary &boundary,
807817
const FieldSensitivePrunedLiveness &liveness) {
808818
// 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");
810820
SILInstruction *defInst = dyn_cast<SILInstruction>(ssaDef);
811821
for (SILInstruction &inst : llvm::reverse(*ssaDef->getParentBlock())) {
812-
LLVM_DEBUG(llvm::dbgs() << "Visiting: " << inst);
822+
PRUNED_LIVENESS_LOG(llvm::dbgs() << "Visiting: " << inst);
813823
if (&inst == defInst) {
814-
LLVM_DEBUG(llvm::dbgs() << " Found dead def: " << *defInst);
824+
PRUNED_LIVENESS_LOG(llvm::dbgs() << " Found dead def: " << *defInst);
815825
boundary.getDeadDefsBits(cast<SILNode>(&inst)).set(bitNo);
816826
return;
817827
}
818828
auto interestingUser = liveness.isInterestingUser(&inst);
819829
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);
821831
boundary.getLastUserBits(&inst).set(bitNo);
822832
return;
823833
}
824834
}
825835

826836
auto *deadArg = cast<SILArgument>(ssaDef);
827-
LLVM_DEBUG(llvm::dbgs() << " Found dead arg: " << *deadArg);
837+
PRUNED_LIVENESS_LOG(llvm::dbgs() << " Found dead arg: " << *deadArg);
828838
boundary.getDeadDefsBits(deadArg).set(bitNo);
829839
}
830840

@@ -873,47 +883,47 @@ void FieldSensitiveMultiDefPrunedLiveRange::findBoundariesInBlock(
873883
FieldSensitivePrunedLivenessBoundary &boundary) const {
874884
assert(isInitialized());
875885

876-
LLVM_DEBUG(llvm::dbgs() << "Checking for boundary in bb"
886+
PRUNED_LIVENESS_LOG(llvm::dbgs() << "Checking for boundary in bb"
877887
<< block->getDebugID() << " for bit: " << bitNo
878888
<< ". Is Live: " << (isLiveOut ? "true" : "false")
879889
<< '\n');
880890

881891
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");
883893
// A live-out block that does not contain any defs cannot have a boundary.
884894
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");
886896
return;
887897
}
888898

889-
LLVM_DEBUG(llvm::dbgs() << " Is LiveWithin, so looking for boundary "
899+
PRUNED_LIVENESS_LOG(llvm::dbgs() << " Is LiveWithin, so looking for boundary "
890900
"in non-def block?!\n");
891901
findBoundaryInNonDefBlock(block, bitNo, boundary, *this);
892902
return;
893903
}
894904

895-
LLVM_DEBUG(llvm::dbgs() << "Is def block!\n");
905+
PRUNED_LIVENESS_LOG(llvm::dbgs() << "Is def block!\n");
896906

897907
// Handle def blocks...
898908
//
899909
// First, check for an SSA live range
900910
if (defs.size() == 1) {
901-
LLVM_DEBUG(llvm::dbgs() << "Has single def...\n");
911+
PRUNED_LIVENESS_LOG(llvm::dbgs() << "Has single def...\n");
902912
// For SSA, a live-out block cannot have a boundary.
903913
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");
905915
return;
906916
}
907917

908-
LLVM_DEBUG(llvm::dbgs() << "Is live within... checking for boundary "
918+
PRUNED_LIVENESS_LOG(llvm::dbgs() << "Is live within... checking for boundary "
909919
"using SSA def block impl.\n");
910920
assert(defs.vector_begin()->second->contains(bitNo));
911921
findBoundaryInSSADefBlock(defs.vector_begin()->first, bitNo, boundary,
912922
*this);
913923
return;
914924
}
915925

916-
LLVM_DEBUG(llvm::dbgs() << "Has multiple defs!\n");
926+
PRUNED_LIVENESS_LOG(llvm::dbgs() << "Has multiple defs!\n");
917927

918928
// Handle a live-out or live-within block with potentially multiple defs
919929
#ifndef NDEBUG
@@ -925,20 +935,20 @@ void FieldSensitiveMultiDefPrunedLiveRange::findBoundariesInBlock(
925935
#endif
926936
bool isLive = isLiveOut;
927937
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: "
930940
<< (isLive ? "true" : "false") << '\n');
931941

932942
// Check if the instruction is a def before checking whether it is a
933943
// use. The same instruction can be both a dead def and boundary use.
934944
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");
936946
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 "
938948
"def and keep isLive false!\n");
939949
boundary.getDeadDefsBits(cast<SILNode>(&inst)).set(bitNo);
940950
} else {
941-
LLVM_DEBUG(
951+
PRUNED_LIVENESS_LOG(
942952
llvm::dbgs()
943953
<< " Is live usage... so just mark isLive to false.\n");
944954
}
@@ -948,37 +958,37 @@ void FieldSensitiveMultiDefPrunedLiveRange::findBoundariesInBlock(
948958
// Note: the same instruction could potentially be both a dead def and last
949959
// user. The liveness boundary supports this, although it won't happen in
950960
// any context where we care about inserting code on the boundary.
951-
LLVM_DEBUG(llvm::dbgs()
961+
PRUNED_LIVENESS_LOG(llvm::dbgs()
952962
<< " Checking if this inst is also a last user...\n");
953963
if (!isLive) {
954964
auto interestingUser = isInterestingUser(&inst);
955965
if (interestingUser.first && interestingUser.second->contains(bitNo)) {
956-
LLVM_DEBUG(
966+
PRUNED_LIVENESS_LOG(
957967
llvm::dbgs()
958968
<< " Was interesting user! Moving from dead -> live!\n");
959969
boundary.getLastUserBits(&inst).set(bitNo);
960970
isLive = true;
961971
} else {
962-
LLVM_DEBUG(llvm::dbgs()
972+
PRUNED_LIVENESS_LOG(llvm::dbgs()
963973
<< " Not interesting user... keeping dead!\n");
964974
}
965975
} else {
966-
LLVM_DEBUG(llvm::dbgs()
976+
PRUNED_LIVENESS_LOG(llvm::dbgs()
967977
<< " Was live already, so cannot be a last user!\n");
968978
}
969979
}
970980

971-
LLVM_DEBUG(llvm::dbgs() << "Finished processing block instructions... now "
981+
PRUNED_LIVENESS_LOG(llvm::dbgs() << "Finished processing block instructions... now "
972982
"checking for dead arguments if dead!\n");
973983
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");
975985
for (SILArgument *deadArg : block->getArguments()) {
976986
auto iter = defs.find(deadArg);
977987
if (iter.has_value() &&
978988
llvm::any_of(*iter, [&](TypeTreeLeafTypeRange span) {
979989
return span.contains(bitNo);
980990
})) {
981-
LLVM_DEBUG(llvm::dbgs() << " Found dead arg: " << *deadArg);
991+
PRUNED_LIVENESS_LOG(llvm::dbgs() << " Found dead arg: " << *deadArg);
982992
boundary.getDeadDefsBits(deadArg).set(bitNo);
983993
}
984994
}
@@ -998,7 +1008,7 @@ void FieldSensitiveMultiDefPrunedLiveRange::findBoundariesInBlock(
9981008
}
9991009
}
10001010
} else {
1001-
LLVM_DEBUG(llvm::dbgs()
1011+
PRUNED_LIVENESS_LOG(llvm::dbgs()
10021012
<< " Live at beginning of block! No dead args!\n");
10031013
}
10041014

0 commit comments

Comments
 (0)