mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Mem2Reg] Replaced loop with getSingleSuccessor.
Thanks to the lack of critical edges in SIL, if a block B dominated by P has a successor S which is not dominated by P, then B must have only a single successor. Used this fact to replace a loop over successors to a call to getSinglePredecessor. Also added an assertion that, in the notation above, B is dominated by P.
This commit is contained in:
@@ -1665,22 +1665,30 @@ void MemoryToRegisters::removeSingleBlockAllocation(AllocStackInst *asi) {
|
||||
GraphNodeWorklist<SILBasicBlock *, 2> worklist;
|
||||
worklist.initialize(parentBlock);
|
||||
while (auto *block = worklist.pop()) {
|
||||
assert(domInfo->dominates(parentBlock, block));
|
||||
auto *terminator = block->getTerminator();
|
||||
if (isa<UnreachableInst>(terminator)) {
|
||||
endLexicalLifetimeBeforeInst(asi, /*beforeInstruction=*/terminator, ctx,
|
||||
runningVals->value);
|
||||
continue;
|
||||
}
|
||||
bool endedLifetime = false;
|
||||
for (auto *successor : block->getSuccessorBlocks()) {
|
||||
if (!domInfo->dominates(parentBlock, successor)) {
|
||||
endLexicalLifetimeBeforeInst(asi, /*beforeInstruction=*/terminator,
|
||||
ctx, runningVals->value);
|
||||
endedLifetime = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (endedLifetime) {
|
||||
SILBasicBlock *successor = nullptr;
|
||||
// If any successor is not dominated by the parentBlock, then we must end
|
||||
// the lifetime before that successor.
|
||||
//
|
||||
// Suppose that a successor is not dominated by parentBlock. Recall that
|
||||
// block _is_ dominated by parentBlock. Thus that successor must have
|
||||
// more than one predecessor: block, and at least one other. (Otherwise
|
||||
// it would be dominated by parentBlock contrary to our assumption.)
|
||||
// Recall that SIL does not allow critical edges. Therefore block has
|
||||
// only a single successor.
|
||||
//
|
||||
// Use the above fact to only look for lack of domination of a successor
|
||||
// if that successor is the single successor of block.
|
||||
if ((successor = block->getSingleSuccessorBlock()) &&
|
||||
(!domInfo->dominates(parentBlock, successor))) {
|
||||
endLexicalLifetimeBeforeInst(asi, /*beforeInstruction=*/terminator, ctx,
|
||||
runningVals->value);
|
||||
continue;
|
||||
}
|
||||
for (auto *successor : block->getSuccessorBlocks()) {
|
||||
|
||||
Reference in New Issue
Block a user