File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed
include/swift/SILOptimizer/Utils Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -153,10 +153,17 @@ class StackNesting {
153153 // / Returns the location bit number for a stack deallocation instruction.
154154 int bitNumberForDealloc (SILInstruction *DeallocInst) {
155155 assert (DeallocInst->isDeallocatingStack ());
156- auto *AllocInst = cast<SingleValueInstruction> (DeallocInst-> getOperand ( 0 ) );
156+ auto *AllocInst = getAllocForDealloc (DeallocInst);
157157 return bitNumberForAlloc (AllocInst);
158158 }
159159
160+ // / Returns the stack allocation instruction for a stack deallocation
161+ // / instruction.
162+ SingleValueInstruction *getAllocForDealloc (SILInstruction *Dealloc) const {
163+ return cast<SingleValueInstruction>(
164+ Dealloc->getOperand (0 )->getDefiningInstruction ());
165+ }
166+
160167 // / Insert deallocations at block boundaries.
161168 Changes insertDeallocsAtBlockBoundaries ();
162169
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ void StackNesting::setup() {
4444
4545 BI.StackInsts .push_back (Alloc);
4646 } else if (I.isDeallocatingStack ()) {
47- auto *AllocInst = cast<SingleValueInstruction>(I. getOperand ( 0 ) );
47+ auto *AllocInst = getAllocForDealloc (&I );
4848 if (!BI.StackInsts .empty () && BI.StackInsts .back () == AllocInst) {
4949 // As an optimization, we ignore perfectly nested alloc-dealloc pairs
5050 // inside a basic block.
@@ -374,7 +374,7 @@ void StackNesting::dump() const {
374374 dumpBits (StackLocs[BitNr].AliveLocs );
375375 llvm::dbgs () << " , " << *StackInst;
376376 } else if (StackInst->isDeallocatingStack ()) {
377- auto *AllocInst = cast<SingleValueInstruction> (StackInst-> getOperand ( 0 ) );
377+ auto *AllocInst = getAllocForDealloc (StackInst);
378378 int BitNr = StackLoc2BitNumbers.lookup (AllocInst);
379379 llvm::dbgs () << " dealloc for #" << BitNr << " \n "
380380 " " << *StackInst;
You can’t perform that action at this time.
0 commit comments