Skip to content

Commit 8e5ad75

Browse files
committed
[StackNesting] Handle stackAlloc builtins.
Both stackAlloc and unprotectedStackAlloc are paired with stackDealloc builtins.
1 parent bccc8b0 commit 8e5ad75

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/SILOptimizer/Utils/StackNesting.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,17 @@ static SILInstruction *createDealloc(SILInstruction *Alloc,
219219
return B.createDeallocStackRef(Location, cast<AllocRefInstBase>(Alloc));
220220
case SILInstructionKind::AllocPackInst:
221221
return B.createDeallocPack(Location, cast<AllocPackInst>(Alloc));
222+
case SILInstructionKind::BuiltinInst: {
223+
auto *bi = cast<BuiltinInst>(Alloc);
224+
assert(bi->getBuiltinKind() == BuiltinValueKind::StackAlloc ||
225+
bi->getBuiltinKind() == BuiltinValueKind::UnprotectedStackAlloc);
226+
auto &context = Alloc->getFunction()->getModule().getASTContext();
227+
auto identifier =
228+
context.getIdentifier(getBuiltinName(BuiltinValueKind::StackDealloc));
229+
return B.createBuiltin(Location, identifier,
230+
SILType::getEmptyTupleType(context),
231+
SubstitutionMap(), {bi});
232+
}
222233
default:
223234
llvm_unreachable("unknown stack allocation");
224235
}

0 commit comments

Comments
 (0)