mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[AllocBoxToStack] Transfer var_decl flag.
As with the lexical flag, when creating an alloc_stack corresponding to an alloc_box, transfer the var_decl flag from any begin_borrow users of the box.
This commit is contained in:
@@ -624,12 +624,16 @@ static bool rewriteAllocBoxAsAllocStack(AllocBoxInst *ABI) {
|
||||
&& "rewriting multi-field box not implemented");
|
||||
auto ty = getSILBoxFieldType(TypeExpansionContext(*ABI->getFunction()),
|
||||
ABI->getBoxType(), ABI->getModule().Types, 0);
|
||||
auto isLexical = [&]() -> IsLexical_t {
|
||||
struct Flags {
|
||||
IsLexical_t isLexical;
|
||||
IsFromVarDecl_t isVarDecl;
|
||||
};
|
||||
auto getFlags = [&]() -> Flags {
|
||||
auto &mod = ABI->getFunction()->getModule();
|
||||
bool lexicalLifetimesEnabled =
|
||||
mod.getASTContext().SILOpts.supportsLexicalLifetimes(mod);
|
||||
if (!lexicalLifetimesEnabled)
|
||||
return IsNotLexical;
|
||||
bool sawLexical = false;
|
||||
bool sawVarDecl = false;
|
||||
// Look for lexical borrows of the alloc_box.
|
||||
GraphNodeWorklist<Operand *, 4> worklist;
|
||||
worklist.initializeRange(ABI->getUses());
|
||||
@@ -642,16 +646,20 @@ static bool rewriteAllocBoxAsAllocStack(AllocBoxInst *ABI) {
|
||||
worklist.insert(use);
|
||||
} else if (auto *bbi = dyn_cast<BeginBorrowInst>(use->getUser())) {
|
||||
if (bbi->isLexical())
|
||||
return IsLexical;
|
||||
sawLexical = true;
|
||||
if (bbi->isFromVarDecl())
|
||||
sawVarDecl = true;
|
||||
for (auto *use : bbi->getUses())
|
||||
worklist.insert(use);
|
||||
}
|
||||
}
|
||||
return IsNotLexical;
|
||||
return Flags{IsLexical_t(lexicalLifetimesEnabled && sawLexical),
|
||||
IsFromVarDecl_t(sawVarDecl)};
|
||||
};
|
||||
auto flags = getFlags();
|
||||
auto *ASI = Builder.createAllocStack(
|
||||
ABI->getLoc(), ty, ABI->getVarInfo(), ABI->hasDynamicLifetime(),
|
||||
isLexical(), IsNotFromVarDecl, DoesNotUseMoveableValueDebugInfo
|
||||
flags.isLexical, flags.isVarDecl, DoesNotUseMoveableValueDebugInfo
|
||||
#ifndef NDEBUG
|
||||
,
|
||||
true
|
||||
|
||||
Reference in New Issue
Block a user