Skip to content

Commit bccc8b0

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

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
@@ -88,10 +88,10 @@ class StackNesting {
8888
///
8989
/// Each stack location is allocated by a single allocation instruction.
9090
struct StackLoc {
91-
StackLoc(SingleValueInstruction *Alloc) : Alloc(Alloc) { }
91+
StackLoc(SILInstruction *Alloc) : Alloc(Alloc) {}
9292

9393
/// Back-link to the allocation instruction.
94-
SingleValueInstruction *Alloc;
94+
SILInstruction *Alloc;
9595

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

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

105105
/// The list of stack locations. The index into this array is also the bit
106106
/// number in the bit-sets.
@@ -147,7 +147,7 @@ class StackNesting {
147147
/// Returns the location bit number for a stack allocation instruction.
148148
int bitNumberForAlloc(SILInstruction *AllocInst) {
149149
assert(AllocInst->isAllocatingStack());
150-
return StackLoc2BitNumbers[cast<SingleValueInstruction>(AllocInst)];
150+
return StackLoc2BitNumbers[AllocInst];
151151
}
152152

153153
/// Returns the location bit number for a stack deallocation instruction.
@@ -159,9 +159,8 @@ class StackNesting {
159159

160160
/// Returns the stack allocation instruction for a stack deallocation
161161
/// instruction.
162-
SingleValueInstruction *getAllocForDealloc(SILInstruction *Dealloc) const {
163-
return cast<SingleValueInstruction>(
164-
Dealloc->getOperand(0)->getDefiningInstruction());
162+
SILInstruction *getAllocForDealloc(SILInstruction *Dealloc) const {
163+
return Dealloc->getOperand(0)->getDefiningInstruction();
165164
}
166165

167166
/// 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;
@@ -201,7 +201,7 @@ bool StackNesting::solve() {
201201
return isNested;
202202
}
203203

204-
static SILInstruction *createDealloc(SingleValueInstruction *Alloc,
204+
static SILInstruction *createDealloc(SILInstruction *Alloc,
205205
SILInstruction *InsertionPoint,
206206
SILLocation Location) {
207207
SILBuilderWithScope B(InsertionPoint);
@@ -211,13 +211,14 @@ static SILInstruction *createDealloc(SingleValueInstruction *Alloc,
211211
assert((isa<AllocStackInst>(Alloc) ||
212212
cast<PartialApplyInst>(Alloc)->isOnStack()) &&
213213
"wrong instruction");
214-
return B.createDeallocStack(Location, Alloc);
214+
return B.createDeallocStack(Location,
215+
cast<SingleValueInstruction>(Alloc));
215216
case SILInstructionKind::AllocRefDynamicInst:
216217
case SILInstructionKind::AllocRefInst:
217218
assert(cast<AllocRefInstBase>(Alloc)->canAllocOnStack());
218-
return B.createDeallocStackRef(Location, Alloc);
219+
return B.createDeallocStackRef(Location, cast<AllocRefInstBase>(Alloc));
219220
case SILInstructionKind::AllocPackInst:
220-
return B.createDeallocPack(Location, Alloc);
221+
return B.createDeallocPack(Location, cast<AllocPackInst>(Alloc));
221222
default:
222223
llvm_unreachable("unknown stack allocation");
223224
}
@@ -368,7 +369,7 @@ void StackNesting::dump() const {
368369
llvm::dbgs() << '\n';
369370
for (SILInstruction *StackInst : bd.data.StackInsts) {
370371
if (StackInst->isAllocatingStack()) {
371-
auto AllocInst = cast<SingleValueInstruction>(StackInst);
372+
auto AllocInst = StackInst;
372373
int BitNr = StackLoc2BitNumbers.lookup(AllocInst);
373374
llvm::dbgs() << " alloc #" << BitNr << ": alive=";
374375
dumpBits(StackLocs[BitNr].AliveLocs);

0 commit comments

Comments
 (0)