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 @@ -148,10 +148,17 @@ class StackNesting {
148
148
// / Returns the location bit number for a stack deallocation instruction.
149
149
int bitNumberForDealloc (SILInstruction *DeallocInst) {
150
150
assert (DeallocInst->isDeallocatingStack ());
151
- auto *AllocInst = cast<SingleValueInstruction> (DeallocInst-> getOperand ( 0 ) );
151
+ auto *AllocInst = getAllocForDealloc (DeallocInst);
152
152
return bitNumberForAlloc (AllocInst);
153
153
}
154
154
155
+ // / Returns the stack allocation instruction for a stack deallocation
156
+ // / instruction.
157
+ SingleValueInstruction *getAllocForDealloc (SILInstruction *Dealloc) const {
158
+ return cast<SingleValueInstruction>(
159
+ Dealloc->getOperand (0 )->getDefiningInstruction ());
160
+ }
161
+
155
162
// / Insert deallocations at block boundaries.
156
163
Changes insertDeallocsAtBlockBoundaries ();
157
164
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ void StackNesting::setup() {
44
44
45
45
BI.StackInsts .push_back (Alloc);
46
46
} else if (I.isDeallocatingStack ()) {
47
- auto *AllocInst = cast<SingleValueInstruction>(I. getOperand ( 0 ) );
47
+ auto *AllocInst = getAllocForDealloc (&I );
48
48
if (!BI.StackInsts .empty () && BI.StackInsts .back () == AllocInst) {
49
49
// As an optimization, we ignore perfectly nested alloc-dealloc pairs
50
50
// inside a basic block.
@@ -349,7 +349,7 @@ void StackNesting::dump() const {
349
349
dumpBits (StackLocs[BitNr].AliveLocs );
350
350
llvm::dbgs () << " , " << *StackInst;
351
351
} else if (StackInst->isDeallocatingStack ()) {
352
- auto *AllocInst = cast<SingleValueInstruction> (StackInst-> getOperand ( 0 ) );
352
+ auto *AllocInst = getAllocForDealloc (StackInst);
353
353
int BitNr = StackLoc2BitNumbers.lookup (AllocInst);
354
354
llvm::dbgs () << " dealloc for #" << BitNr << " \n "
355
355
" " << *StackInst;
You can’t perform that action at this time.
0 commit comments