Skip to content

Commit 877f471

Browse files
Merge pull request #72211 from nate-chandler/var_decl-alloc_stack
[SIL] Key consume addr checking off var_decl attr.
2 parents ba6cd77 + a54a8dd commit 877f471

File tree

85 files changed

+774
-560
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+774
-560
lines changed

docs/SIL.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3786,6 +3786,7 @@ alloc_stack
37863786
sil-instruction ::= 'alloc_stack' alloc-stack-option* sil-type (',' debug-var-attr)*
37873787
alloc-stack-option ::= '[dynamic_lifetime]'
37883788
alloc-stack-option ::= '[lexical]'
3789+
alloc-stack-option ::= '[var_decl]'
37893790
alloc-stack-option ::= '[moveable_value_debuginfo]'
37903791

37913792
%1 = alloc_stack $T
@@ -3805,7 +3806,12 @@ The ``dynamic_lifetime`` attribute specifies that the initialization and
38053806
destruction of the stored value cannot be verified at compile time.
38063807
This is the case, e.g. for conditionally initialized objects.
38073808

3808-
The optional ``lexical`` attribute specifies that the storage corresponds to a
3809+
The optional ``lexical`` attribute specifies that the operand corresponds to a
3810+
local variable with a lexical lifetime in the Swift source, so special care
3811+
must be taken when hoisting ``destroy_addr``s. Compare to the ``var_decl``
3812+
attribute.
3813+
3814+
The optional ``var_decl`` attribute specifies that the storage corresponds to a
38093815
local variable in the Swift source.
38103816

38113817
The optional ``moveable_value_debuginfo`` attribute specifies that when emitting

include/swift/SIL/DebugUtils.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -488,11 +488,11 @@ struct DebugVarCarryingInst : VarDeclCarryingInst {
488488
case Kind::Invalid:
489489
llvm_unreachable("Invalid?!");
490490
case Kind::DebugValue:
491-
return cast<DebugValueInst>(**this)->getUsesMoveableValueDebugInfo();
491+
return cast<DebugValueInst>(**this)->usesMoveableValueDebugInfo();
492492
case Kind::AllocStack:
493-
return cast<AllocStackInst>(**this)->getUsesMoveableValueDebugInfo();
493+
return cast<AllocStackInst>(**this)->usesMoveableValueDebugInfo();
494494
case Kind::AllocBox:
495-
return cast<AllocBoxInst>(**this)->getUsesMoveableValueDebugInfo();
495+
return cast<AllocBoxInst>(**this)->usesMoveableValueDebugInfo();
496496
}
497497
}
498498

include/swift/SIL/SILBridgingImpl.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,9 +1461,12 @@ BridgedInstruction BridgedBuilder::createIntegerLiteral(BridgedType type, SwiftI
14611461

14621462
BridgedInstruction BridgedBuilder::createAllocStack(BridgedType type,
14631463
bool hasDynamicLifetime, bool isLexical, bool wasMoved) const {
1464-
return {unbridged().createAllocStack(regularLoc(), type.unbridged(),
1465-
std::nullopt, hasDynamicLifetime,
1466-
isLexical, wasMoved)};
1464+
return {unbridged().createAllocStack(
1465+
regularLoc(), type.unbridged(), std::nullopt,
1466+
swift::HasDynamicLifetime_t(hasDynamicLifetime),
1467+
swift::IsLexical_t(isLexical),
1468+
// TODO: Add this as an argument.
1469+
swift::IsNotFromVarDecl, swift::UsesMoveableValueDebugInfo_t(wasMoved))};
14671470
}
14681471

14691472
BridgedInstruction BridgedBuilder::createAllocVector(BridgedValue capacity, BridgedType type) const {

include/swift/SIL/SILBuilder.h

Lines changed: 53 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,14 @@ class SILBuilder {
402402
substituteAnonymousArgs(llvm::SmallString<4> Name,
403403
std::optional<SILDebugVariable> Var, SILLocation Loc);
404404

405-
AllocStackInst *
406-
createAllocStack(SILLocation Loc, SILType elementType,
407-
std::optional<SILDebugVariable> Var = std::nullopt,
408-
bool hasDynamicLifetime = false, bool isLexical = false,
409-
bool wasMoved = false, bool skipVarDeclAssert = false) {
405+
AllocStackInst *createAllocStack(
406+
SILLocation Loc, SILType elementType,
407+
std::optional<SILDebugVariable> Var = std::nullopt,
408+
HasDynamicLifetime_t dynamic = DoesNotHaveDynamicLifetime,
409+
IsLexical_t isLexical = IsNotLexical,
410+
IsFromVarDecl_t isFromVarDecl = IsNotFromVarDecl,
411+
UsesMoveableValueDebugInfo_t wasMoved = DoesNotUseMoveableValueDebugInfo,
412+
bool skipVarDeclAssert = false) {
410413
llvm::SmallString<4> Name;
411414
Loc.markAsPrologue();
412415
#ifndef NDEBUG
@@ -418,8 +421,8 @@ class SILBuilder {
418421
#endif
419422
return insert(AllocStackInst::create(
420423
getSILDebugLocation(Loc, true), elementType, getFunction(),
421-
substituteAnonymousArgs(Name, Var, Loc), hasDynamicLifetime, isLexical,
422-
wasMoved));
424+
substituteAnonymousArgs(Name, Var, Loc), dynamic, isLexical,
425+
isFromVarDecl, wasMoved));
423426
}
424427

425428
AllocVectorInst *
@@ -473,26 +476,30 @@ class SILBuilder {
473476

474477
/// Helper function that calls \p createAllocBox after constructing a
475478
/// SILBoxType for \p fieldType.
476-
AllocBoxInst *
477-
createAllocBox(SILLocation loc, SILType fieldType,
478-
std::optional<SILDebugVariable> Var = std::nullopt,
479-
bool hasDynamicLifetime = false, bool reflection = false,
480-
bool usesMoveableValueDebugInfo = false,
481-
bool hasPointerEscape = false) {
479+
AllocBoxInst *createAllocBox(
480+
SILLocation loc, SILType fieldType,
481+
std::optional<SILDebugVariable> Var = std::nullopt,
482+
HasDynamicLifetime_t hasDynamicLifetime = DoesNotHaveDynamicLifetime,
483+
bool reflection = false,
484+
UsesMoveableValueDebugInfo_t usesMoveableValueDebugInfo =
485+
DoesNotUseMoveableValueDebugInfo,
486+
HasPointerEscape_t hasPointerEscape = DoesNotHavePointerEscape) {
482487
return createAllocBox(loc, SILBoxType::get(fieldType.getASTType()), Var,
483488
hasDynamicLifetime, reflection,
484489
usesMoveableValueDebugInfo,
485490
/*skipVarDeclAssert*/ false,
486491
hasPointerEscape);
487492
}
488493

489-
AllocBoxInst *
490-
createAllocBox(SILLocation Loc, CanSILBoxType BoxType,
491-
std::optional<SILDebugVariable> Var = std::nullopt,
492-
bool hasDynamicLifetime = false, bool reflection = false,
493-
bool usesMoveableValueDebugInfo = false,
494-
bool skipVarDeclAssert = false,
495-
bool hasPointerEscape = false) {
494+
AllocBoxInst *createAllocBox(
495+
SILLocation Loc, CanSILBoxType BoxType,
496+
std::optional<SILDebugVariable> Var = std::nullopt,
497+
HasDynamicLifetime_t hasDynamicLifetime = DoesNotHaveDynamicLifetime,
498+
bool reflection = false,
499+
UsesMoveableValueDebugInfo_t usesMoveableValueDebugInfo =
500+
DoesNotUseMoveableValueDebugInfo,
501+
bool skipVarDeclAssert = false,
502+
HasPointerEscape_t hasPointerEscape = DoesNotHavePointerEscape) {
496503
#if NDEBUG
497504
(void)skipVarDeclAssert;
498505
#endif
@@ -818,11 +825,11 @@ class SILBuilder {
818825
LoadBorrowInst(getSILDebugLocation(Loc), LV));
819826
}
820827

821-
BeginBorrowInst *createBeginBorrow(SILLocation Loc, SILValue LV,
822-
bool isLexical = false,
823-
bool hasPointerEscape = false,
824-
bool fromVarDecl = false,
825-
bool fixed = false) {
828+
BeginBorrowInst *createBeginBorrow(
829+
SILLocation Loc, SILValue LV, IsLexical_t isLexical = IsNotLexical,
830+
HasPointerEscape_t hasPointerEscape = DoesNotHavePointerEscape,
831+
IsFromVarDecl_t fromVarDecl = IsNotFromVarDecl,
832+
BeginBorrowInst::IsFixed_t fixed = BeginBorrowInst::IsNotFixed) {
826833
assert(getFunction().hasOwnership());
827834
assert(!LV->getType().isAddress());
828835
return insert(new (getModule())
@@ -846,10 +853,10 @@ class SILBuilder {
846853
return createLoadBorrow(loc, v);
847854
}
848855

849-
SILValue emitBeginBorrowOperation(SILLocation loc, SILValue v,
850-
bool isLexical = false,
851-
bool hasPointerEscape = false,
852-
bool fromVarDecl = false) {
856+
SILValue emitBeginBorrowOperation(
857+
SILLocation loc, SILValue v, IsLexical_t isLexical = IsNotLexical,
858+
HasPointerEscape_t hasPointerEscape = DoesNotHavePointerEscape,
859+
IsFromVarDecl_t fromVarDecl = IsNotFromVarDecl) {
853860
if (!hasOwnership() ||
854861
v->getOwnershipKind().isCompatibleWith(OwnershipKind::Guaranteed))
855862
return v;
@@ -1050,15 +1057,15 @@ class SILBuilder {
10501057
MarkFunctionEscapeInst::create(getSILDebugLocation(Loc), vars, getFunction()));
10511058
}
10521059

1053-
DebugValueInst *createDebugValue(SILLocation Loc, SILValue src,
1054-
SILDebugVariable Var,
1055-
bool poisonRefs = false,
1056-
bool wasMoved = false,
1057-
bool trace = false);
1058-
DebugValueInst *createDebugValueAddr(SILLocation Loc, SILValue src,
1059-
SILDebugVariable Var,
1060-
bool wasMoved = false,
1061-
bool trace = false);
1060+
DebugValueInst *createDebugValue(
1061+
SILLocation Loc, SILValue src, SILDebugVariable Var,
1062+
bool poisonRefs = false,
1063+
UsesMoveableValueDebugInfo_t wasMoved = DoesNotUseMoveableValueDebugInfo,
1064+
bool trace = false);
1065+
DebugValueInst *createDebugValueAddr(
1066+
SILLocation Loc, SILValue src, SILDebugVariable Var,
1067+
UsesMoveableValueDebugInfo_t wasMoved = DoesNotUseMoveableValueDebugInfo,
1068+
bool trace = false);
10621069

10631070
DebugStepInst *createDebugStep(SILLocation Loc) {
10641071
return insert(new (getModule()) DebugStepInst(getSILDebugLocation(Loc)));
@@ -1421,10 +1428,10 @@ class SILBuilder {
14211428
operand, poisonRefs));
14221429
}
14231430

1424-
MoveValueInst *createMoveValue(SILLocation loc, SILValue operand,
1425-
bool isLexical = false,
1426-
bool hasPointerEscape = false,
1427-
bool fromVarDecl = false) {
1431+
MoveValueInst *createMoveValue(
1432+
SILLocation loc, SILValue operand, IsLexical_t isLexical = IsNotLexical,
1433+
HasPointerEscape_t hasPointerEscape = DoesNotHavePointerEscape,
1434+
IsFromVarDecl_t fromVarDecl = IsNotFromVarDecl) {
14281435
assert(getFunction().hasOwnership());
14291436
assert(!operand->getType().isTrivial(getFunction()) &&
14301437
"Should not be passing trivial values to this api. Use instead "
@@ -2844,10 +2851,10 @@ class SILBuilder {
28442851

28452852
/// Convenience function that is a no-op for trivial values and inserts a
28462853
/// move_value on non-trivial instructions.
2847-
SILValue emitMoveValueOperation(SILLocation Loc, SILValue v,
2848-
bool isLexical = false,
2849-
bool hasPointerEscape = false,
2850-
bool fromVarDecl = false) {
2854+
SILValue emitMoveValueOperation(
2855+
SILLocation Loc, SILValue v, IsLexical_t isLexical = IsNotLexical,
2856+
HasPointerEscape_t hasPointerEscape = DoesNotHavePointerEscape,
2857+
IsFromVarDecl_t fromVarDecl = IsNotFromVarDecl) {
28512858
assert(!v->getType().isAddress());
28522859
if (v->getType().isTrivial(*getInsertionBB()->getParent()))
28532860
return v;

include/swift/SIL/SILCloner.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -877,10 +877,11 @@ SILCloner<ImplClass>::visitAllocStackInst(AllocStackInst *Inst) {
877877
}
878878
auto *NewInst = getBuilder().createAllocStack(
879879
Loc, getOpType(Inst->getElementType()), VarInfo,
880-
Inst->hasDynamicLifetime(), Inst->isLexical(),
881-
Inst->getUsesMoveableValueDebugInfo()
880+
Inst->hasDynamicLifetime(), Inst->isLexical(), Inst->isFromVarDecl(),
881+
Inst->usesMoveableValueDebugInfo()
882882
#ifndef NDEBUG
883-
, true
883+
,
884+
true
884885
#endif
885886
);
886887
remapDebugVarInfo(DebugVarCarryingInst(NewInst));
@@ -969,10 +970,9 @@ SILCloner<ImplClass>::visitAllocBoxInst(AllocBoxInst *Inst) {
969970
Inst,
970971
getBuilder().createAllocBox(
971972
Loc, this->getOpType(Inst->getType()).template castTo<SILBoxType>(),
972-
VarInfo, /*hasDynamicLifetime*/ false,
973-
/*reflection*/ false,
974-
/*usesMoveableValueDebugInfo*/ false, /*skipVarDeclAssert*/ true
975-
));
973+
VarInfo, Inst->hasDynamicLifetime(), Inst->emitReflectionMetadata(),
974+
Inst->usesMoveableValueDebugInfo(),
975+
/*skipVarDeclAssert*/ true, Inst->hasPointerEscape()));
976976
}
977977

978978
template<typename ImplClass>
@@ -1410,8 +1410,7 @@ SILCloner<ImplClass>::visitDebugValueInst(DebugValueInst *Inst) {
14101410
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
14111411
auto *NewInst = getBuilder().createDebugValue(
14121412
Inst->getLoc(), getOpValue(Inst->getOperand()), VarInfo,
1413-
Inst->poisonRefs(), Inst->getUsesMoveableValueDebugInfo(),
1414-
Inst->hasTrace());
1413+
Inst->poisonRefs(), Inst->usesMoveableValueDebugInfo(), Inst->hasTrace());
14151414
remapDebugVarInfo(DebugVarCarryingInst(NewInst));
14161415
recordClonedInstruction(Inst, NewInst);
14171416
}

0 commit comments

Comments
 (0)