Skip to content

Commit b2780c2

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

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
@@ -148,10 +148,17 @@ class StackNesting {
148148
/// Returns the location bit number for a stack deallocation instruction.
149149
int bitNumberForDealloc(SILInstruction *DeallocInst) {
150150
assert(DeallocInst->isDeallocatingStack());
151-
auto *AllocInst = cast<SingleValueInstruction>(DeallocInst->getOperand(0));
151+
auto *AllocInst = getAllocForDealloc(DeallocInst);
152152
return bitNumberForAlloc(AllocInst);
153153
}
154154

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+
155162
/// Insert deallocations at block boundaries.
156163
Changes insertDeallocsAtBlockBoundaries();
157164

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.
@@ -349,7 +349,7 @@ void StackNesting::dump() const {
349349
dumpBits(StackLocs[BitNr].AliveLocs);
350350
llvm::dbgs() << ", " << *StackInst;
351351
} else if (StackInst->isDeallocatingStack()) {
352-
auto *AllocInst = cast<SingleValueInstruction>(StackInst->getOperand(0));
352+
auto *AllocInst = getAllocForDealloc(StackInst);
353353
int BitNr = StackLoc2BitNumbers.lookup(AllocInst);
354354
llvm::dbgs() << " dealloc for #" << BitNr << "\n"
355355
" " << *StackInst;

0 commit comments

Comments
 (0)