@@ -285,9 +285,8 @@ struct UseState {
285
285
llvm::SmallDenseMap<SILInstruction *, unsigned , 4 > destroyToIndexMap;
286
286
SmallBlotSetVector<SILInstruction *, 4 > reinits;
287
287
llvm::SmallDenseMap<SILInstruction *, unsigned , 4 > reinitToIndexMap;
288
- llvm::SmallMapVector<Operand *, ClosureOperandState, 1 >
289
- consumingClosureOperands;
290
- llvm::SmallDenseMap<Operand *, unsigned , 1 > consumingClosureOperandToIndexMap;
288
+ llvm::SmallMapVector<Operand *, ClosureOperandState, 1 > closureUses;
289
+ llvm::SmallDenseMap<Operand *, unsigned , 1 > closureOperandToIndexMap;
291
290
292
291
void insertMarkUnresolvedMoveAddr (MarkUnresolvedMoveAddrInst *inst) {
293
292
if (!seenMarkMoves.insert (inst).second )
@@ -305,9 +304,9 @@ struct UseState {
305
304
reinits.insert (inst);
306
305
}
307
306
308
- void insertConsumingClosureOperand (Operand *op) {
309
- consumingClosureOperandToIndexMap [op] = consumingClosureOperands .size ();
310
- consumingClosureOperands [op] = {};
307
+ void insertClosureOperand (Operand *op) {
308
+ closureOperandToIndexMap [op] = closureUses .size ();
309
+ closureUses [op] = {};
311
310
}
312
311
313
312
void clear () {
@@ -320,8 +319,8 @@ struct UseState {
320
319
destroyToIndexMap.clear ();
321
320
reinits.clear ();
322
321
reinitToIndexMap.clear ();
323
- consumingClosureOperands .clear ();
324
- consumingClosureOperandToIndexMap .clear ();
322
+ closureUses .clear ();
323
+ closureOperandToIndexMap .clear ();
325
324
}
326
325
327
326
SILFunction *getFunction () const { return address->getFunction (); }
@@ -440,7 +439,7 @@ bool GatherLexicalLifetimeUseVisitor::visitUse(Operand *op,
440
439
auto *func = fas.getCalleeFunction ();
441
440
if (!func || !func->isDefer ())
442
441
return false ;
443
- useState.insertConsumingClosureOperand (op);
442
+ useState.insertClosureOperand (op);
444
443
return true ;
445
444
}
446
445
}
@@ -505,14 +504,14 @@ downwardScanForMoveOut(MarkUnresolvedMoveAddrInst *mvi, UseState &useState,
505
504
if (auto fas = FullApplySite::isa (&next)) {
506
505
LLVM_DEBUG (llvm::dbgs () << " DownwardScan: ClosureCheck: " << **fas);
507
506
for (auto &op : fas.getArgumentOperands ()) {
508
- auto iter = useState.consumingClosureOperands .find (&op);
509
- if (iter == useState.consumingClosureOperands .end ()) {
507
+ auto iter = useState.closureUses .find (&op);
508
+ if (iter == useState.closureUses .end ()) {
510
509
continue ;
511
510
}
512
511
513
512
LLVM_DEBUG (llvm::dbgs ()
514
513
<< " DownwardScan: ClosureCheck: Matching Operand: "
515
- << fas.getAppliedArgIndex (op) << ' \n ' );
514
+ << fas.getAppliedArgIndex (op));
516
515
*foundInst = &next;
517
516
*foundOperand = &op;
518
517
switch (iter->second .result ) {
@@ -523,10 +522,12 @@ downwardScanForMoveOut(MarkUnresolvedMoveAddrInst *mvi, UseState &useState,
523
522
case DownwardScanResult::MoveOut:
524
523
llvm_unreachable (" unhandled" );
525
524
case DownwardScanResult::ClosureConsume:
525
+ LLVM_DEBUG (llvm::dbgs () << " . ClosureConsume.\n " );
526
526
llvm::copy (iter->second .pairedConsumingInsts ,
527
527
std::back_inserter (foundClosureInsts));
528
528
break ;
529
529
case DownwardScanResult::ClosureUse:
530
+ LLVM_DEBUG (llvm::dbgs () << " . ClosureUse.\n " );
530
531
llvm::copy (iter->second .pairedUseInsts ,
531
532
std::back_inserter (foundClosureInsts));
532
533
break ;
@@ -572,8 +573,7 @@ static bool upwardScanForUseOut(SILInstruction *inst, UseState &useState) {
572
573
return false ;
573
574
if (auto fas = FullApplySite::isa (&iter)) {
574
575
for (auto &op : fas.getArgumentOperands ()) {
575
- if (useState.consumingClosureOperands .find (&op) !=
576
- useState.consumingClosureOperands .end ())
576
+ if (useState.closureUses .find (&op) != useState.closureUses .end ())
577
577
return false ;
578
578
}
579
579
}
@@ -602,8 +602,7 @@ static bool upwardScanForDestroys(SILInstruction *inst, UseState &useState) {
602
602
return false ;
603
603
if (auto fas = FullApplySite::isa (&iter)) {
604
604
for (auto &op : fas.getArgumentOperands ()) {
605
- if (useState.consumingClosureOperands .find (&op) !=
606
- useState.consumingClosureOperands .end ())
605
+ if (useState.closureUses .find (&op) != useState.closureUses .end ())
607
606
return false ;
608
607
}
609
608
}
@@ -626,8 +625,7 @@ static bool upwardScanForInit(SILInstruction *inst, UseState &useState) {
626
625
return false ;
627
626
if (auto fas = FullApplySite::isa (&iter)) {
628
627
for (auto &op : fas.getArgumentOperands ()) {
629
- if (useState.consumingClosureOperands .find (&op) !=
630
- useState.consumingClosureOperands .end ())
628
+ if (useState.closureUses .find (&op) != useState.closureUses .end ())
631
629
return false ;
632
630
}
633
631
}
@@ -650,14 +648,14 @@ namespace {
650
648
// / since there must be some sort of use for the closure to even reference it
651
649
// / and the compiler emits assigns when it reinitializes vars this early in the
652
650
// / pipeline.
653
- struct ConsumingClosureArgDataflowState {
651
+ struct ClosureArgDataflowState {
654
652
SmallVector<SILInstruction *, 32 > livenessWorklist;
655
653
SmallVector<SILInstruction *, 32 > consumingWorklist;
656
654
PrunedLiveness livenessForConsumes;
657
655
UseState &useState;
658
656
659
657
public:
660
- ConsumingClosureArgDataflowState (UseState &useState) : useState(useState) {}
658
+ ClosureArgDataflowState (UseState &useState) : useState(useState) {}
661
659
662
660
bool process (
663
661
SILArgument *arg, ClosureOperandState &state,
@@ -688,7 +686,7 @@ struct ConsumingClosureArgDataflowState {
688
686
689
687
} // namespace
690
688
691
- bool ConsumingClosureArgDataflowState ::handleSingleBlockCase (
689
+ bool ClosureArgDataflowState ::handleSingleBlockCase (
692
690
SILArgument *address, ClosureOperandState &state) {
693
691
// Walk the instructions from the beginning of the block to the end.
694
692
for (auto &inst : *address->getParent ()) {
@@ -741,9 +739,10 @@ bool ConsumingClosureArgDataflowState::handleSingleBlockCase(
741
739
return false ;
742
740
}
743
741
744
- bool ConsumingClosureArgDataflowState ::performLivenessDataflow (
742
+ bool ClosureArgDataflowState ::performLivenessDataflow (
745
743
const BasicBlockSet &initBlocks, const BasicBlockSet &livenessBlocks,
746
744
const BasicBlockSet &consumingBlocks) {
745
+ LLVM_DEBUG (llvm::dbgs () << " ClosureArgLivenessDataflow. Start!\n " );
747
746
bool foundSingleLivenessUse = false ;
748
747
auto *fn = useState.getFunction ();
749
748
auto *frontBlock = &*fn->begin ();
@@ -752,8 +751,9 @@ bool ConsumingClosureArgDataflowState::performLivenessDataflow(
752
751
for (unsigned i : indices (livenessWorklist)) {
753
752
auto *&user = livenessWorklist[i];
754
753
755
- if (frontBlock == user->getParent ())
754
+ if (frontBlock == user->getParent ()) {
756
755
continue ;
756
+ }
757
757
758
758
bool success = false ;
759
759
for (auto *predBlock : user->getParent ()->getPredecessorBlocks ()) {
@@ -782,7 +782,7 @@ bool ConsumingClosureArgDataflowState::performLivenessDataflow(
782
782
return foundSingleLivenessUse;
783
783
}
784
784
785
- bool ConsumingClosureArgDataflowState ::performConsumingDataflow (
785
+ bool ClosureArgDataflowState ::performConsumingDataflow (
786
786
const BasicBlockSet &initBlocks, const BasicBlockSet &consumingBlocks) {
787
787
auto *fn = useState.getFunction ();
788
788
auto *frontBlock = &*fn->begin ();
@@ -821,9 +821,9 @@ bool ConsumingClosureArgDataflowState::performConsumingDataflow(
821
821
return foundSingleConsumingUse;
822
822
}
823
823
824
- void ConsumingClosureArgDataflowState ::classifyUses (
825
- BasicBlockSet &initBlocks, BasicBlockSet &livenessBlocks,
826
- BasicBlockSet &consumingBlocks) {
824
+ void ClosureArgDataflowState ::classifyUses (BasicBlockSet &initBlocks,
825
+ BasicBlockSet &livenessBlocks,
826
+ BasicBlockSet &consumingBlocks) {
827
827
828
828
for (auto *user : useState.inits ) {
829
829
if (upwardScanForInit (user, useState)) {
@@ -868,7 +868,7 @@ void ConsumingClosureArgDataflowState::classifyUses(
868
868
}
869
869
}
870
870
871
- bool ConsumingClosureArgDataflowState ::process (
871
+ bool ClosureArgDataflowState ::process (
872
872
SILArgument *address, ClosureOperandState &state,
873
873
SmallBlotSetVector<SILInstruction *, 8 > &postDominatingConsumingUsers) {
874
874
clear ();
@@ -915,6 +915,8 @@ bool ConsumingClosureArgDataflowState::process(
915
915
if (performLivenessDataflow (initBlocks, livenessBlocks, consumingBlocks)) {
916
916
for (unsigned i : indices (livenessWorklist)) {
917
917
if (auto *ptr = livenessWorklist[i]) {
918
+ LLVM_DEBUG (llvm::dbgs ()
919
+ << " ClosureArgLivenessDataflow. Liveness User: " << *ptr);
918
920
state.pairedUseInsts .push_back (ptr);
919
921
}
920
922
}
@@ -932,8 +934,10 @@ bool ConsumingClosureArgDataflowState::process(
932
934
// debug_value user. If we have many we can't handle it since something in
933
935
// SILGen is emitting weird code. Our tests will ensure that SILGen does not
934
936
// diverge by mistake. So we are really just being careful.
935
- if (hasMoreThanOneDebugUse (address))
937
+ if (hasMoreThanOneDebugUse (address)) {
938
+ // Failing b/c more than one debug use!
936
939
return false ;
940
+ }
937
941
938
942
SWIFT_DEFER { livenessForConsumes.clear (); };
939
943
auto *frontBlock = &*fn->begin ();
@@ -1417,7 +1421,7 @@ bool DataflowState::cleanupAllDestroyAddr(
1417
1421
LLVM_DEBUG (llvm::dbgs () << " Visiting consuming closures!\n " );
1418
1422
for (int index = consumingClosureIndices.find_first (); index != -1 ;
1419
1423
index = consumingClosureIndices.find_next (index)) {
1420
- auto &pair = *std::next (useState.consumingClosureOperands .begin (), index);
1424
+ auto &pair = *std::next (useState.closureUses .begin (), index);
1421
1425
auto *op = pair.first ;
1422
1426
LLVM_DEBUG (llvm::dbgs () << " Consuming closure: " << *op->getUser ());
1423
1427
for (auto *predBlock : op->getUser ()->getParent ()->getPredecessorBlocks ()) {
@@ -1478,7 +1482,7 @@ bool DataflowState::cleanupAllDestroyAddr(
1478
1482
// rather than multiple times for multiple vars.
1479
1483
for (int index = consumingClosureIndices.find_first (); index != -1 ;
1480
1484
index = consumingClosureIndices.find_next (index)) {
1481
- auto &pair = *std::next (useState.consumingClosureOperands .begin (), index);
1485
+ auto &pair = *std::next (useState.closureUses .begin (), index);
1482
1486
auto *closureUse = pair.first ;
1483
1487
if (!closureUse)
1484
1488
continue ;
@@ -1526,9 +1530,8 @@ bool DataflowState::process(
1526
1530
SmallBitVector indicesOfPairedConsumingClosureUses;
1527
1531
auto getIndicesOfPairedConsumingClosureUses = [&]() -> SmallBitVector & {
1528
1532
if (indicesOfPairedConsumingClosureUses.size () !=
1529
- useState.consumingClosureOperands .size ())
1530
- indicesOfPairedConsumingClosureUses.resize (
1531
- useState.consumingClosureOperands .size ());
1533
+ useState.closureUses .size ())
1534
+ indicesOfPairedConsumingClosureUses.resize (useState.closureUses .size ());
1532
1535
return indicesOfPairedConsumingClosureUses;
1533
1536
};
1534
1537
@@ -1616,9 +1619,8 @@ bool DataflowState::process(
1616
1619
if (iter != consumingClosureBlocks.end ()) {
1617
1620
LLVM_DEBUG (llvm::dbgs () << " Is reinit Block! Setting up for "
1618
1621
" later deletion if possible!\n " );
1619
- auto indexIter =
1620
- useState.consumingClosureOperandToIndexMap .find (iter->second );
1621
- assert (indexIter != useState.consumingClosureOperandToIndexMap .end ());
1622
+ auto indexIter = useState.closureOperandToIndexMap .find (iter->second );
1623
+ assert (indexIter != useState.closureOperandToIndexMap .end ());
1622
1624
getIndicesOfPairedConsumingClosureUses ().set (indexIter->second );
1623
1625
continue ;
1624
1626
}
@@ -1928,7 +1930,7 @@ struct MoveKillsCopyableAddressesChecker {
1928
1930
UseState useState;
1929
1931
DataflowState dataflowState;
1930
1932
UseState closureUseState;
1931
- ConsumingClosureArgDataflowState closureUseDataflowState;
1933
+ ClosureArgDataflowState closureUseDataflowState;
1932
1934
SILOptFunctionBuilder &funcBuilder;
1933
1935
llvm::SmallMapVector<FullApplySite, SmallBitVector, 8 >
1934
1936
applySiteToPromotedArgIndices;
@@ -2110,7 +2112,7 @@ bool MoveKillsCopyableAddressesChecker::check(SILValue address) {
2110
2112
//
2111
2113
// This summary will let us treat the whole closure's effect on the closure
2112
2114
// operand as if it was a single instruction.
2113
- for (auto &pair : useState.consumingClosureOperands ) {
2115
+ for (auto &pair : useState.closureUses ) {
2114
2116
auto *operand = pair.first ;
2115
2117
auto &closureState = pair.second ;
2116
2118
0 commit comments