@@ -148,23 +148,24 @@ bool StackNesting::solve() {
148
148
}
149
149
150
150
static SILInstruction *createDealloc (SILInstruction *Alloc,
151
- SILInstruction *InsertionPoint) {
151
+ SILInstruction *InsertionPoint,
152
+ SILLocation Location) {
152
153
SILBuilder B (InsertionPoint);
153
154
switch (Alloc->getKind ()) {
154
155
case ValueKind::AllocStackInst:
155
- return B.createDeallocStack (InsertionPoint-> getLoc () , Alloc);
156
+ return B.createDeallocStack (Location , Alloc);
156
157
case ValueKind::AllocRefInst:
157
158
assert (cast<AllocRefInst>(Alloc)->canAllocOnStack ());
158
- return B.createDeallocRef (InsertionPoint->getLoc (), Alloc,
159
- /* canBeOnStack*/ true );
159
+ return B.createDeallocRef (Location, Alloc, /* canBeOnStack*/ true );
160
160
default :
161
161
llvm_unreachable (" unknown stack allocation" );
162
162
}
163
163
}
164
164
165
165
bool StackNesting::insertDeallocs (const BitVector &AliveBefore,
166
166
const BitVector &AliveAfter,
167
- SILInstruction *InsertionPoint) {
167
+ SILInstruction *InsertionPoint,
168
+ Optional<SILLocation> Location) {
168
169
if (!AliveBefore.test (AliveAfter))
169
170
return false ;
170
171
@@ -175,7 +176,9 @@ bool StackNesting::insertDeallocs(const BitVector &AliveBefore,
175
176
for (int LocNr = AliveBefore.find_first (); LocNr >= 0 ;
176
177
LocNr = AliveBefore.find_next (LocNr)) {
177
178
if (!AliveAfter.test (LocNr)) {
178
- InsertionPoint = createDealloc (StackLocs[LocNr].Alloc , InsertionPoint);
179
+ SILInstruction *Alloc = StackLocs[LocNr].Alloc ;
180
+ InsertionPoint = createDealloc (Alloc, InsertionPoint,
181
+ Location.hasValue () ? Location.getValue () : Alloc->getLoc ());
179
182
changesMade = true ;
180
183
}
181
184
}
@@ -234,7 +237,7 @@ StackNesting::Changes StackNesting::adaptDeallocs() {
234
237
CFGChanged = true ;
235
238
}
236
239
InstChanged |= insertDeallocs (Bits, SuccBI->AliveStackLocsAtEntry ,
237
- &InsertionBlock->front ());
240
+ &InsertionBlock->front (), None );
238
241
}
239
242
240
243
// Insert/remove deallocations inside blocks.
@@ -264,7 +267,7 @@ StackNesting::Changes StackNesting::adaptDeallocs() {
264
267
// Insert deallocations for all locations which are not alive after
265
268
// StackInst but _are_ alive at the StackInst.
266
269
InstChanged |= insertDeallocs (StackLocs[BitNr].AliveLocs , Bits,
267
- InsertionPoint);
270
+ InsertionPoint, StackInst-> getLoc () );
268
271
Bits |= StackLocs[BitNr].AliveLocs ;
269
272
}
270
273
}
0 commit comments