@@ -587,8 +587,7 @@ static SILValue tryRewriteToPartialApplyStack(
587
587
ConvertEscapeToNoEscapeInst *cvt, SILInstruction *closureUser,
588
588
DominanceAnalysis *dominanceAnalysis, InstructionDeleter &deleter,
589
589
llvm::DenseMap<SILInstruction *, SILInstruction *> &memoized,
590
- llvm::DenseSet<SILBasicBlock *> &unreachableBlocks,
591
- const bool &modifiedCFG) {
590
+ ReachableBlocks const &reachableBlocks, const bool &modifiedCFG) {
592
591
593
592
auto *origPA = dyn_cast<PartialApplyInst>(skipConvert (cvt->getOperand ()));
594
593
if (!origPA)
@@ -972,8 +971,8 @@ static SILValue tryRewriteToPartialApplyStack(
972
971
973
972
// Don't run insertDeallocOfCapturedArguments if newPA is in an unreachable
974
973
// block insertDeallocOfCapturedArguments will run code that computes the DF
975
- // for newPA that will loop infinetly .
976
- if (unreachableBlocks. count (newPA->getParent ()))
974
+ // for newPA that will loop infinitely .
975
+ if (!reachableBlocks. isReachable (newPA->getParent ()))
977
976
return closureOp;
978
977
979
978
auto getAddressToDealloc = [&](SILValue argAddress) -> SILValue {
@@ -995,8 +994,8 @@ static bool tryExtendLifetimeToLastUse(
995
994
ConvertEscapeToNoEscapeInst *cvt, DominanceAnalysis *dominanceAnalysis,
996
995
DeadEndBlocksAnalysis *deadEndBlocksAnalysis,
997
996
llvm::DenseMap<SILInstruction *, SILInstruction *> &memoized,
998
- llvm::DenseSet<SILBasicBlock *> &unreachableBlocks ,
999
- InstructionDeleter &deleter, const bool &modifiedCFG) {
997
+ ReachableBlocks const &reachableBlocks, InstructionDeleter &deleter ,
998
+ const bool &modifiedCFG) {
1000
999
// If there is a single user, this is simple: extend the
1001
1000
// lifetime of the operand until the use ends.
1002
1001
auto *singleUser = lookThroughRebastractionUsers (cvt, memoized);
@@ -1019,7 +1018,7 @@ static bool tryExtendLifetimeToLastUse(
1019
1018
1020
1019
if (SILValue closureOp = tryRewriteToPartialApplyStack (
1021
1020
cvt, singleUser, dominanceAnalysis, deleter, memoized,
1022
- unreachableBlocks , /* const*/ modifiedCFG)) {
1021
+ reachableBlocks , /* const*/ modifiedCFG)) {
1023
1022
if (endAsyncLet) {
1024
1023
// Add the closure as a second operand to the endAsyncLet builtin.
1025
1024
// This ensures that the closure arguments are kept alive until the
@@ -1428,22 +1427,6 @@ static bool fixupCopyBlockWithoutEscaping(CopyBlockWithoutEscapingInst *cb,
1428
1427
return true ;
1429
1428
}
1430
1429
1431
- static void computeUnreachableBlocks (
1432
- llvm::DenseSet<SILBasicBlock*> &unreachableBlocks,
1433
- SILFunction &fn) {
1434
-
1435
- ReachableBlocks isReachable (&fn);
1436
- llvm::DenseSet<SILBasicBlock *> reachable;
1437
- isReachable.visit ([&] (SILBasicBlock *block) -> bool {
1438
- reachable.insert (block);
1439
- return true ;
1440
- });
1441
- for (auto &block : fn) {
1442
- if (!reachable.count (&block))
1443
- unreachableBlocks.insert (&block);
1444
- }
1445
- }
1446
-
1447
1430
static bool fixupClosureLifetimes (SILFunction &fn,
1448
1431
DominanceAnalysis *dominanceAnalysis,
1449
1432
DeadEndBlocksAnalysis *deadEndBlocksAnalysis,
@@ -1454,8 +1437,8 @@ static bool fixupClosureLifetimes(SILFunction &fn,
1454
1437
// queries.
1455
1438
llvm::DenseMap<SILInstruction *, SILInstruction *> memoizedQueries;
1456
1439
1457
- llvm::DenseSet<SILBasicBlock *> unreachableBlocks ;
1458
- computeUnreachableBlocks (unreachableBlocks, fn );
1440
+ ReachableBlocks reachableBlocks (&fn) ;
1441
+ reachableBlocks. compute ( );
1459
1442
1460
1443
for (auto &block : fn) {
1461
1444
SILSSAUpdater updater;
@@ -1485,7 +1468,7 @@ static bool fixupClosureLifetimes(SILFunction &fn,
1485
1468
1486
1469
if (tryExtendLifetimeToLastUse (cvt, dominanceAnalysis,
1487
1470
deadEndBlocksAnalysis, memoizedQueries,
1488
- unreachableBlocks , updater.getDeleter (),
1471
+ reachableBlocks , updater.getDeleter (),
1489
1472
/* const*/ modifiedCFG)) {
1490
1473
changed = true ;
1491
1474
checkStackNesting = true ;
0 commit comments