Skip to content

Commit 1238b0e

Browse files
committed
[StackNesting] NFC: Allocs are just insts.
Stop requiring that allocation instructions produce single values.
1 parent b2780c2 commit 1238b0e

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

include/swift/SILOptimizer/Utils/StackNesting.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ class StackNesting {
8383
///
8484
/// Each stack location is allocated by a single allocation instruction.
8585
struct StackLoc {
86-
StackLoc(SingleValueInstruction *Alloc) : Alloc(Alloc) { }
86+
StackLoc(SILInstruction *Alloc) : Alloc(Alloc) {}
8787

8888
/// Back-link to the allocation instruction.
89-
SingleValueInstruction *Alloc;
89+
SILInstruction *Alloc;
9090

9191
/// Bit-set which represents all alive locations at this allocation.
9292
/// It obviously includes this location itself. And it includes all "outer"
@@ -95,7 +95,7 @@ class StackNesting {
9595
};
9696

9797
/// Mapping from stack allocations (= locations) to bit numbers.
98-
llvm::DenseMap<SingleValueInstruction *, unsigned> StackLoc2BitNumbers;
98+
llvm::DenseMap<SILInstruction *, unsigned> StackLoc2BitNumbers;
9999

100100
/// The list of stack locations. The index into this array is also the bit
101101
/// number in the bit-sets.
@@ -142,7 +142,7 @@ class StackNesting {
142142
/// Returns the location bit number for a stack allocation instruction.
143143
int bitNumberForAlloc(SILInstruction *AllocInst) {
144144
assert(AllocInst->isAllocatingStack());
145-
return StackLoc2BitNumbers[cast<SingleValueInstruction>(AllocInst)];
145+
return StackLoc2BitNumbers[AllocInst];
146146
}
147147

148148
/// Returns the location bit number for a stack deallocation instruction.
@@ -154,9 +154,8 @@ class StackNesting {
154154

155155
/// Returns the stack allocation instruction for a stack deallocation
156156
/// instruction.
157-
SingleValueInstruction *getAllocForDealloc(SILInstruction *Dealloc) const {
158-
return cast<SingleValueInstruction>(
159-
Dealloc->getOperand(0)->getDefiningInstruction());
157+
SILInstruction *getAllocForDealloc(SILInstruction *Dealloc) const {
158+
return Dealloc->getOperand(0)->getDefiningInstruction();
160159
}
161160

162161
/// Insert deallocations at block boundaries.

lib/SILOptimizer/Utils/StackNesting.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void StackNesting::setup() {
3636
BlockInfo &BI = BlockInfos[Block];
3737
for (SILInstruction &I : *Block) {
3838
if (I.isAllocatingStack()) {
39-
auto Alloc = cast<SingleValueInstruction>(&I);
39+
auto Alloc = &I;
4040
// Register this stack location.
4141
unsigned CurrentBitNumber = StackLocs.size();
4242
StackLoc2BitNumbers[Alloc] = CurrentBitNumber;
@@ -178,7 +178,7 @@ bool StackNesting::solve() {
178178
return isNested;
179179
}
180180

181-
static SILInstruction *createDealloc(SingleValueInstruction *Alloc,
181+
static SILInstruction *createDealloc(SILInstruction *Alloc,
182182
SILInstruction *InsertionPoint,
183183
SILLocation Location) {
184184
SILBuilderWithScope B(InsertionPoint);
@@ -188,13 +188,14 @@ static SILInstruction *createDealloc(SingleValueInstruction *Alloc,
188188
assert((isa<AllocStackInst>(Alloc) ||
189189
cast<PartialApplyInst>(Alloc)->isOnStack()) &&
190190
"wrong instruction");
191-
return B.createDeallocStack(Location, Alloc);
191+
return B.createDeallocStack(Location,
192+
cast<SingleValueInstruction>(Alloc));
192193
case SILInstructionKind::AllocRefDynamicInst:
193194
case SILInstructionKind::AllocRefInst:
194195
assert(cast<AllocRefInstBase>(Alloc)->canAllocOnStack());
195-
return B.createDeallocStackRef(Location, Alloc);
196+
return B.createDeallocStackRef(Location, cast<AllocRefInstBase>(Alloc));
196197
case SILInstructionKind::AllocPackInst:
197-
return B.createDeallocPack(Location, Alloc);
198+
return B.createDeallocPack(Location, cast<AllocPackInst>(Alloc));
198199
default:
199200
llvm_unreachable("unknown stack allocation");
200201
}
@@ -343,7 +344,7 @@ void StackNesting::dump() const {
343344
llvm::dbgs() << '\n';
344345
for (SILInstruction *StackInst : bd.data.StackInsts) {
345346
if (StackInst->isAllocatingStack()) {
346-
auto AllocInst = cast<SingleValueInstruction>(StackInst);
347+
auto AllocInst = StackInst;
347348
int BitNr = StackLoc2BitNumbers.lookup(AllocInst);
348349
llvm::dbgs() << " alloc #" << BitNr << ": alive=";
349350
dumpBits(StackLocs[BitNr].AliveLocs);

0 commit comments

Comments
 (0)