@@ -1719,45 +1719,15 @@ void MemoryToRegisters::removeSingleBlockAllocation(AllocStackInst *asi) {
1719
1719
// block which are the only instructions involving this alloc_stack.
1720
1720
// This can only happen if all paths from this block end in unreachable.
1721
1721
//
1722
- // We need to end the lexical lifetime at the last possible location, either
1723
- // just before an unreachable instruction or just before a branch to a block
1724
- // that is not dominated by parentBlock.
1725
-
1726
- // Walk forward from parentBlock until finding blocks which either
1727
- // (1) terminate in unreachable
1728
- // (2) have successors which are not dominated by parentBlock
1729
- GraphNodeWorklist<SILBasicBlock *, 2 > worklist;
1730
- worklist.initialize (parentBlock);
1731
- while (auto *block = worklist.pop ()) {
1732
- assert (domInfo->dominates (parentBlock, block));
1722
+ // We need to end the lexical lifetime at the last possible location, at the
1723
+ // boundary blocks which are the predecessors of dominance frontier
1724
+ // dominated by the alloc_stack.
1725
+ SmallVector<SILBasicBlock *, 4 > boundary;
1726
+ computeDominatedBoundaryBlocks (asi->getParent (), domInfo, boundary);
1727
+ for (auto *block : boundary) {
1733
1728
auto *terminator = block->getTerminator ();
1734
- if (isa<UnreachableInst>(terminator)) {
1735
- endLexicalLifetimeBeforeInst (asi, /* beforeInstruction=*/ terminator, ctx,
1736
- runningVals->value );
1737
- continue ;
1738
- }
1739
- SILBasicBlock *successor = nullptr ;
1740
- // If any successor is not dominated by the parentBlock, then we must end
1741
- // the lifetime before that successor.
1742
- //
1743
- // Suppose that a successor is not dominated by parentBlock. Recall that
1744
- // block _is_ dominated by parentBlock. Thus that successor must have
1745
- // more than one predecessor: block, and at least one other. (Otherwise
1746
- // it would be dominated by parentBlock contrary to our assumption.)
1747
- // Recall that SIL does not allow critical edges. Therefore block has
1748
- // only a single successor.
1749
- //
1750
- // Use the above fact to only look for lack of domination of a successor
1751
- // if that successor is the single successor of block.
1752
- if ((successor = block->getSingleSuccessorBlock ()) &&
1753
- (!domInfo->dominates (parentBlock, successor))) {
1754
- endLexicalLifetimeBeforeInst (asi, /* beforeInstruction=*/ terminator, ctx,
1755
- runningVals->value );
1756
- continue ;
1757
- }
1758
- for (auto *successor : block->getSuccessorBlocks ()) {
1759
- worklist.insert (successor);
1760
- }
1729
+ endLexicalLifetimeBeforeInst (asi, /* beforeInstruction=*/ terminator, ctx,
1730
+ runningVals->value );
1761
1731
}
1762
1732
}
1763
1733
}
0 commit comments