Skip to content

Commit 389fb97

Browse files
committed
[StackNesting] NFC: Added helper.
Just pull the notion that the alloc corresponds to operand 0 into a helper method.
1 parent 8c8f5df commit 389fb97

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

include/swift/SILOptimizer/Utils/StackNesting.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff 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

lib/SILOptimizer/Utils/StackNesting.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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;

0 commit comments

Comments
 (0)