Skip to content

Commit 7f6fd0b

Browse files
committed
Reorganize if to reduce indentation
1 parent 8769cbe commit 7f6fd0b

File tree

1 file changed

+34
-32
lines changed

1 file changed

+34
-32
lines changed

lib/SILOptimizer/Transforms/SILMem2Reg.cpp

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -732,21 +732,22 @@ StoreInst *StackAllocationPromoter::promoteAllocationInBlock(
732732

733733
// Replace destroys with a release of the value.
734734
if (auto *dai = dyn_cast<DestroyAddrInst>(inst)) {
735-
if (dai->getOperand() == asi) {
736-
if (runningVals) {
737-
replaceDestroy(dai, runningVals->value.replacement(asi, dai), ctx,
738-
deleter, instructionsToDelete);
739-
if (shouldAddLexicalLifetime(asi)) {
740-
endLexicalLifetimeBeforeInst(asi, /*beforeInstruction=*/dai, ctx,
741-
runningVals->value);
742-
}
743-
runningVals->isStorageValid = false;
744-
if (lastStoreInst)
745-
lastStoreInst->isStorageValid = false;
746-
} else {
747-
assert(!deinitializationPoints[blockPromotingWithin]);
748-
deinitializationPoints[blockPromotingWithin] = dai;
735+
if (dai->getOperand() != asi) {
736+
continue;
737+
}
738+
if (runningVals) {
739+
replaceDestroy(dai, runningVals->value.replacement(asi, dai), ctx,
740+
deleter, instructionsToDelete);
741+
if (shouldAddLexicalLifetime(asi)) {
742+
endLexicalLifetimeBeforeInst(asi, /*beforeInstruction=*/dai, ctx,
743+
runningVals->value);
749744
}
745+
runningVals->isStorageValid = false;
746+
if (lastStoreInst)
747+
lastStoreInst->isStorageValid = false;
748+
} else {
749+
assert(!deinitializationPoints[blockPromotingWithin]);
750+
deinitializationPoints[blockPromotingWithin] = dai;
750751
}
751752
continue;
752753
}
@@ -1636,26 +1637,27 @@ void MemoryToRegisters::removeSingleBlockAllocation(AllocStackInst *asi) {
16361637
// Remove stores and record the value that we are saving as the running
16371638
// value.
16381639
if (auto *si = dyn_cast<StoreInst>(inst)) {
1639-
if (si->getDest() == asi) {
1640-
if (si->getOwnershipQualifier() == StoreOwnershipQualifier::Assign) {
1641-
assert(runningVals && runningVals->isStorageValid);
1642-
SILBuilderWithScope(si, ctx).createDestroyValue(
1643-
si->getLoc(), runningVals->value.replacement(asi, si));
1644-
}
1645-
auto oldRunningVals = runningVals;
1646-
runningVals = {LiveValues::toReplace(asi, /*replacement=*/si->getSrc()),
1647-
/*isStorageValid=*/true};
1648-
if (shouldAddLexicalLifetime(asi)) {
1649-
if (oldRunningVals && oldRunningVals->isStorageValid) {
1650-
endLexicalLifetimeBeforeInst(asi, /*beforeInstruction=*/si, ctx,
1651-
oldRunningVals->value);
1652-
}
1653-
runningVals = beginLexicalLifetimeAfterStore(asi, si);
1654-
}
1655-
deleter.forceDelete(inst);
1656-
++NumInstRemoved;
1640+
if (si->getDest() != asi) {
16571641
continue;
16581642
}
1643+
if (si->getOwnershipQualifier() == StoreOwnershipQualifier::Assign) {
1644+
assert(runningVals && runningVals->isStorageValid);
1645+
SILBuilderWithScope(si, ctx).createDestroyValue(
1646+
si->getLoc(), runningVals->value.replacement(asi, si));
1647+
}
1648+
auto oldRunningVals = runningVals;
1649+
runningVals = {LiveValues::toReplace(asi, /*replacement=*/si->getSrc()),
1650+
/*isStorageValid=*/true};
1651+
if (shouldAddLexicalLifetime(asi)) {
1652+
if (oldRunningVals && oldRunningVals->isStorageValid) {
1653+
endLexicalLifetimeBeforeInst(asi, /*beforeInstruction=*/si, ctx,
1654+
oldRunningVals->value);
1655+
}
1656+
runningVals = beginLexicalLifetimeAfterStore(asi, si);
1657+
}
1658+
deleter.forceDelete(inst);
1659+
++NumInstRemoved;
1660+
continue;
16591661
}
16601662

16611663
// Replace debug_value w/ address value with debug_value of

0 commit comments

Comments
 (0)