@@ -1257,6 +1257,7 @@ class IRGenSILFunction :
12571257 void visitEndCOWMutationInst (EndCOWMutationInst *i);
12581258 void visitIsEscapingClosureInst (IsEscapingClosureInst *i);
12591259 void visitDeallocStackInst (DeallocStackInst *i);
1260+ void visitDeallocStackRefInst (DeallocStackRefInst *i);
12601261 void visitDeallocBoxInst (DeallocBoxInst *i);
12611262 void visitDeallocRefInst (DeallocRefInst *i);
12621263 void visitDeallocPartialRefInst (DeallocPartialRefInst *i);
@@ -4515,9 +4516,9 @@ void IRGenSILFunction::visitSetDeallocatingInst(SetDeallocatingInst *i) {
45154516 // ...
45164517 // set_deallocating %0 // not needed
45174518 // // code which does not depend on the RC_DEALLOCATING_FLAG flag.
4518- // dealloc_ref %0 // not needed ( stems from the inlined deallocator)
4519+ // dealloc_ref %0 // stems from the inlined deallocator
45194520 // ...
4520- // dealloc_ref [stack] %0
4521+ // dealloc_stack_ref %0
45214522 SILBasicBlock::iterator Iter (i);
45224523 SILBasicBlock::iterator End = i->getParent ()->end ();
45234524 for (++Iter; Iter != End; ++Iter) {
@@ -5432,32 +5433,10 @@ void IRGenSILFunction::visitDeallocStackInst(swift::DeallocStackInst *i) {
54325433 allocatedTI.deallocateStack (*this , stackAddr, allocatedType);
54335434}
54345435
5435- void IRGenSILFunction::visitDeallocRefInst (swift::DeallocRefInst *i) {
5436- // Lower the operand.
5436+ void IRGenSILFunction::visitDeallocStackRefInst (DeallocStackRefInst *i) {
54375437 Explosion self = getLoweredExplosion (i->getOperand ());
54385438 auto selfValue = self.claimNext ();
5439- auto *ARI = dyn_cast<AllocRefInst>(i->getOperand ());
5440- if (!i->canAllocOnStack ()) {
5441- if (ARI && StackAllocs.count (ARI)) {
5442- // We can ignore dealloc_refs (without [stack]) for stack allocated
5443- // objects.
5444- //
5445- // %0 = alloc_ref [stack]
5446- // ...
5447- // dealloc_ref %0 // not needed (stems from the inlined deallocator)
5448- // ...
5449- // dealloc_ref [stack] %0
5450- return ;
5451- }
5452-
5453- auto classType = i->getOperand ()->getType ();
5454- emitClassDeallocation (*this , classType, selfValue);
5455- return ;
5456- }
5457- // It's a dealloc_ref [stack]. Even if the alloc_ref did not allocate the
5458- // object on the stack, we don't have to deallocate it, because it is
5459- // deallocated in the final release.
5460- assert (ARI->canAllocOnStack ());
5439+ auto *ARI = i->getAllocRef ();
54615440 if (StackAllocs.count (ARI)) {
54625441 if (IGM.IRGen .Opts .EmitStackPromotionChecks ) {
54635442 selfValue = Builder.CreateBitCast (selfValue, IGM.RefCountedPtrTy );
@@ -5473,6 +5452,25 @@ void IRGenSILFunction::visitDeallocRefInst(swift::DeallocRefInst *i) {
54735452 }
54745453}
54755454
5455+ void IRGenSILFunction::visitDeallocRefInst (swift::DeallocRefInst *i) {
5456+ // Lower the operand.
5457+ Explosion self = getLoweredExplosion (i->getOperand ());
5458+ auto selfValue = self.claimNext ();
5459+ auto *ARI = dyn_cast<AllocRefInst>(i->getOperand ());
5460+ if (ARI && StackAllocs.count (ARI)) {
5461+ // We can ignore dealloc_refs for stack allocated objects.
5462+ //
5463+ // %0 = alloc_ref [stack]
5464+ // ...
5465+ // dealloc_ref %0 // not needed (stems from the inlined deallocator)
5466+ // ...
5467+ // dealloc_stack_ref %0
5468+ return ;
5469+ }
5470+ auto classType = i->getOperand ()->getType ();
5471+ emitClassDeallocation (*this , classType, selfValue);
5472+ }
5473+
54765474void IRGenSILFunction::visitDeallocPartialRefInst (swift::DeallocPartialRefInst *i) {
54775475 Explosion self = getLoweredExplosion (i->getInstance ());
54785476 auto selfValue = self.claimNext ();
0 commit comments