Skip to content

Commit 8769cbe

Browse files
committed
Simplify SILMem2Reg by using computeDominatedBoundaryBlocks api instead of computing in-place
1 parent f2d9bc7 commit 8769cbe

File tree

1 file changed

+8
-38
lines changed

1 file changed

+8
-38
lines changed

lib/SILOptimizer/Transforms/SILMem2Reg.cpp

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,45 +1719,15 @@ void MemoryToRegisters::removeSingleBlockAllocation(AllocStackInst *asi) {
17191719
// block which are the only instructions involving this alloc_stack.
17201720
// This can only happen if all paths from this block end in unreachable.
17211721
//
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) {
17331728
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);
17611731
}
17621732
}
17631733
}

0 commit comments

Comments
 (0)