Skip to content

Commit ed7788f

Browse files
committed
Get rid of isStorageValid flag on lastStoreInst
1 parent 8e9117d commit ed7788f

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

lib/SILOptimizer/Transforms/SILMem2Reg.cpp

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ SILInstruction *StackAllocationPromoter::promoteAllocationInBlock(
655655
Optional<StorageStateTracking<LiveValues>> runningVals;
656656
// Keep track of the last StoreInst that we found and the BeginBorrowInst and
657657
// CopyValueInst that we created in response if the alloc_stack was lexical.
658-
Optional<StorageStateTracking<SILInstruction *>> lastStoreInst;
658+
Optional<SILInstruction *> lastStoreInst;
659659

660660
// For all instructions in the block.
661661
for (auto bbi = blockPromotingWithin->begin(),
@@ -683,8 +683,6 @@ SILInstruction *StackAllocationPromoter::promoteAllocationInBlock(
683683
}
684684
if (runningVals)
685685
runningVals->isStorageValid = false;
686-
if (lastStoreInst)
687-
lastStoreInst->isStorageValid = false;
688686
}
689687

690688
if (runningVals) {
@@ -736,14 +734,14 @@ SILInstruction *StackAllocationPromoter::promoteAllocationInBlock(
736734

737735
// If we met a store before this one, delete it.
738736
if (lastStoreInst) {
739-
assert(cast<StoreInst>(lastStoreInst->value)->getOwnershipQualifier() !=
737+
assert(cast<StoreInst>(*lastStoreInst)->getOwnershipQualifier() !=
740738
StoreOwnershipQualifier::Assign &&
741739
"store [assign] to the stack location should have been "
742740
"transformed to a store [init]");
743-
LLVM_DEBUG(llvm::dbgs() << "*** Removing redundant store: "
744-
<< *lastStoreInst->value);
741+
LLVM_DEBUG(llvm::dbgs()
742+
<< "*** Removing redundant store: " << *lastStoreInst);
745743
++NumInstRemoved;
746-
prepareForDeletion(lastStoreInst->value, instructionsToDelete);
744+
prepareForDeletion(*lastStoreInst, instructionsToDelete);
747745
}
748746

749747
auto oldRunningVals = runningVals;
@@ -752,7 +750,7 @@ SILInstruction *StackAllocationPromoter::promoteAllocationInBlock(
752750
/*isStorageValid=*/true};
753751
// The current store is now the lastStoreInst (until we see
754752
// another).
755-
lastStoreInst = {inst, /*isStorageValid=*/true};
753+
lastStoreInst = inst;
756754
if (shouldAddLexicalLifetime(asi)) {
757755
if (oldRunningVals && oldRunningVals->isStorageValid &&
758756
canEndLexicalLifetime(oldRunningVals->value)) {
@@ -770,17 +768,17 @@ SILInstruction *StackAllocationPromoter::promoteAllocationInBlock(
770768

771769
// If we met a store before this one, delete it.
772770
if (lastStoreInst) {
773-
LLVM_DEBUG(llvm::dbgs() << "*** Removing redundant store: "
774-
<< *lastStoreInst->value);
771+
LLVM_DEBUG(llvm::dbgs()
772+
<< "*** Removing redundant store: " << *lastStoreInst);
775773
++NumInstRemoved;
776-
prepareForDeletion(lastStoreInst->value, instructionsToDelete);
774+
prepareForDeletion(*lastStoreInst, instructionsToDelete);
777775
}
778776

779777
// The stored value is the new running value.
780778
runningVals = {LiveValues::toReplace(asi, sbi->getSrc()),
781779
/*isStorageValid=*/true};
782780
// The current store is now the lastStoreInst.
783-
lastStoreInst = {inst, /*isStorageValid=*/true};
781+
lastStoreInst = inst;
784782
if (shouldAddLexicalLifetime(asi)) {
785783
runningVals = beginLexicalLifetimeAfterStore(asi, inst);
786784
}
@@ -837,8 +835,6 @@ SILInstruction *StackAllocationPromoter::promoteAllocationInBlock(
837835
runningVals->value);
838836
}
839837
runningVals->isStorageValid = false;
840-
if (lastStoreInst)
841-
lastStoreInst->isStorageValid = false;
842838
} else {
843839
assert(!deinitializationPoints[blockPromotingWithin]);
844840
deinitializationPoints[blockPromotingWithin] = dai;
@@ -853,15 +849,15 @@ SILInstruction *StackAllocationPromoter::promoteAllocationInBlock(
853849
}
854850
}
855851

856-
if (lastStoreInst && lastStoreInst->isStorageValid) {
857-
assert((isa<StoreBorrowInst>(lastStoreInst->value) ||
858-
(cast<StoreInst>(lastStoreInst->value)->getOwnershipQualifier() !=
852+
if (lastStoreInst && runningVals->isStorageValid) {
853+
assert((isa<StoreBorrowInst>(*lastStoreInst) ||
854+
(cast<StoreInst>(*lastStoreInst)->getOwnershipQualifier() !=
859855
StoreOwnershipQualifier::Assign)) &&
860856
"store [assign] to the stack location should have been "
861857
"transformed to a store [init]");
862-
LLVM_DEBUG(llvm::dbgs() << "*** Finished promotion. Last store: "
863-
<< *lastStoreInst->value);
864-
return lastStoreInst->value;
858+
LLVM_DEBUG(llvm::dbgs()
859+
<< "*** Finished promotion. Last store: " << *lastStoreInst);
860+
return *lastStoreInst;
865861
}
866862

867863
LLVM_DEBUG(llvm::dbgs() << "*** Finished promotion with no stores.\n");

0 commit comments

Comments
 (0)