@@ -187,9 +187,8 @@ class DCE {
187
187
llvm::SmallPtrSetImpl<SILBasicBlock *> &);
188
188
SILBasicBlock *nearestUsefulPostDominator (SILBasicBlock *Block);
189
189
void replaceBranchWithJump (SILInstruction *Inst, SILBasicBlock *Block);
190
- // / If \p value is live, insert a lifetime ending operation in ossa.
191
- // / destroy_value for @owned value and end_borrow for a @guaranteed value.
192
- void endLifetimeOfLiveValue (SILValue value, SILInstruction *insertPt);
190
+ // / Insert lifetime ending instruction if defining value of \p op is live.
191
+ void endLifetimeOfLiveValue (Operand *op, SILInstruction *insertPt);
193
192
194
193
public:
195
194
DCE (SILFunction *F, PostDominanceInfo *PDT)
@@ -585,23 +584,24 @@ void DCE::replaceBranchWithJump(SILInstruction *Inst, SILBasicBlock *Block) {
585
584
(void )Branch;
586
585
}
587
586
588
- void DCE::endLifetimeOfLiveValue (SILValue value, SILInstruction *insertPt) {
587
+ void DCE::endLifetimeOfLiveValue (Operand *op, SILInstruction *insertPt) {
588
+ auto value = op->get ();
589
589
if (SILInstruction *inst = value->getDefiningInstruction ()) {
590
590
if (!LiveInstructions.contains (inst))
591
591
return ;
592
592
} else if (auto *arg = dyn_cast<SILArgument>(value)) {
593
593
if (!LiveArguments.contains (arg))
594
594
return ;
595
595
}
596
+
597
+ assert (op->isLifetimeEnding ());
596
598
SILBuilderWithScope builder (insertPt);
597
599
if (value->getOwnershipKind () == OwnershipKind::Owned) {
598
- builder.emitDestroyOperation (RegularLocation::getAutoGeneratedLocation (),
599
- value);
600
+ builder.createDestroyValue (RegularLocation::getAutoGeneratedLocation (),
601
+ value);
600
602
}
601
- BorrowedValue borrow (lookThroughBorrowedFromDef (value));
602
- if (borrow && borrow.isLocalScope ()) {
603
- builder.emitEndBorrowOperation (RegularLocation::getAutoGeneratedLocation (),
604
- value);
603
+ if (value->getOwnershipKind () == OwnershipKind::Guaranteed) {
604
+ builder.createEndBorrow (RegularLocation::getAutoGeneratedLocation (), value);
605
605
}
606
606
}
607
607
@@ -657,7 +657,7 @@ bool DCE::removeDead() {
657
657
for (auto *pred : BB.getPredecessorBlocks ()) {
658
658
auto *predTerm = pred->getTerminator ();
659
659
SILInstruction *insertPt = predTerm;
660
- if (phiArg->getOwnershipKind () == OwnershipKind::Guaranteed ) {
660
+ if (phiArg->isReborrow () ) {
661
661
// If the phiArg is dead and had reborrow dependencies, its baseValue
662
662
// may also have been dead and a destroy_value of its baseValue may
663
663
// have been inserted before the pred's terminator. Make sure to
@@ -677,8 +677,10 @@ bool DCE::removeDead() {
677
677
insertPt = &predInst;
678
678
}
679
679
}
680
-
681
- endLifetimeOfLiveValue (phiArg->getIncomingPhiValue (pred), insertPt);
680
+ auto *predOp = phiArg->getIncomingPhiOperand (pred);
681
+ if (predOp->isLifetimeEnding ()) {
682
+ endLifetimeOfLiveValue (predOp, insertPt);
683
+ }
682
684
}
683
685
erasePhiArgument (&BB, i, /* cleanupDeadPhiOps=*/ true ,
684
686
InstModCallbacks ().onCreateNewInst (
@@ -702,7 +704,7 @@ bool DCE::removeDead() {
702
704
703
705
for (auto &op : termInst->getAllOperands ()) {
704
706
if (op.isLifetimeEnding ()) {
705
- endLifetimeOfLiveValue (op. get () , termInst);
707
+ endLifetimeOfLiveValue (&op , termInst);
706
708
}
707
709
}
708
710
LLVM_DEBUG (llvm::dbgs () << " Replacing branch: " );
@@ -725,7 +727,7 @@ bool DCE::removeDead() {
725
727
if (F->hasOwnership ()) {
726
728
for (auto &Op : Inst->getAllOperands ()) {
727
729
if (Op.isLifetimeEnding ()) {
728
- endLifetimeOfLiveValue (Op. get () , Inst);
730
+ endLifetimeOfLiveValue (&Op , Inst);
729
731
}
730
732
}
731
733
}
0 commit comments