Skip to content

Commit dff0b2e

Browse files
committed
[SILGen] Allocs for VDs are var_decl.
Annotate alloc_stack instructions that correspond to VarDecls with the var_decl flag.
1 parent 7884892 commit dff0b2e

30 files changed

+114
-108
lines changed

lib/SILGen/SILGenDecl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -710,9 +710,9 @@ class LetValueInitialization : public Initialization {
710710
auto lifetime = SGF.F.getLifetime(vd, lowering->getLoweredType());
711711
auto isLexical =
712712
IsLexical_t(lexicalLifetimesEnabled && lifetime.isLexical());
713-
address =
714-
SGF.emitTemporaryAllocation(vd, lowering->getLoweredType(),
715-
DoesNotHaveDynamicLifetime, isLexical);
713+
address = SGF.emitTemporaryAllocation(vd, lowering->getLoweredType(),
714+
DoesNotHaveDynamicLifetime,
715+
isLexical, IsFromVarDecl);
716716
if (isUninitialized)
717717
address = SGF.B.createMarkUninitializedVar(vd, address);
718718
DestroyCleanup = SGF.enterDormantTemporaryCleanup(address, *lowering);

lib/SILGen/SILGenExpr.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,19 +1094,21 @@ RValue RValueEmitter::visitLoadExpr(LoadExpr *E, SGFContext C) {
10941094
SILValue SILGenFunction::emitTemporaryAllocation(SILLocation loc, SILType ty,
10951095
HasDynamicLifetime_t dynamic,
10961096
IsLexical_t isLexical,
1097+
IsFromVarDecl_t isFromVarDecl,
10971098
bool generateDebugInfo) {
10981099
ty = ty.getObjectType();
10991100
std::optional<SILDebugVariable> DbgVar;
11001101
if (generateDebugInfo)
11011102
if (auto *VD = loc.getAsASTNode<VarDecl>())
11021103
DbgVar = SILDebugVariable(VD->isLet(), 0);
1103-
auto *alloc = B.createAllocStack(loc, ty, DbgVar, dynamic, isLexical,
1104-
DoesNotUseMoveableValueDebugInfo
1104+
auto *alloc =
1105+
B.createAllocStack(loc, ty, DbgVar, dynamic, isLexical, isFromVarDecl,
1106+
DoesNotUseMoveableValueDebugInfo
11051107
#ifndef NDEBUG
1106-
,
1107-
!generateDebugInfo
1108+
,
1109+
!generateDebugInfo
11081110
#endif
1109-
);
1111+
);
11101112
enterDeallocStackCleanup(alloc);
11111113
return alloc;
11121114
}

lib/SILGen/SILGenFunction.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -699,9 +699,10 @@ void SILGenFunction::emitCaptures(SILLocation loc,
699699

700700
assert(!isPack);
701701

702-
auto addr = emitTemporaryAllocation(
703-
vd, entryValue->getType(), DoesNotHaveDynamicLifetime, IsNotLexical,
704-
/*generateDebugInfo*/ false);
702+
auto addr = emitTemporaryAllocation(vd, entryValue->getType(),
703+
DoesNotHaveDynamicLifetime,
704+
IsNotLexical, IsNotFromVarDecl,
705+
/*generateDebugInfo*/ false);
705706
auto val = B.emitCopyValueOperation(loc, entryValue);
706707
auto &lowering = getTypeLowering(entryValue->getType());
707708
lowering.emitStore(B, loc, val, addr, StoreOwnershipQualifier::Init);

lib/SILGen/SILGenFunction.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1335,7 +1335,9 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
13351335
SILValue emitTemporaryAllocation(
13361336
SILLocation loc, SILType ty,
13371337
HasDynamicLifetime_t hasDynamicLifetime = DoesNotHaveDynamicLifetime,
1338-
IsLexical_t isLexical = IsNotLexical, bool generateDebugInfo = true);
1338+
IsLexical_t isLexical = IsNotLexical,
1339+
IsFromVarDecl_t isFromVarDecl = IsNotFromVarDecl,
1340+
bool generateDebugInfo = true);
13391341

13401342
/// Emits a temporary allocation for a pack that will be deallocated
13411343
/// automatically at the end of the current scope. Returns the address

lib/SILGen/SILGenProlog.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,7 @@ class ArgumentInitHelper {
863863

864864
if (auto *allocStack = dyn_cast<AllocStackInst>(argrv.getValue())) {
865865
allocStack->setArgNo(ArgNo);
866+
allocStack->setIsFromVarDecl();
866867
if (SGF.getASTContext().SILOpts.supportsLexicalLifetimes(
867868
SGF.getModule()) &&
868869
SGF.F.getLifetime(pd, allocStack->getType()).isLexical())

test/AutoDiff/SILOptimizer/activity_analysis.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -851,12 +851,12 @@ func testActiveEnumAddr<T>(_ e: IndirectEnum<T>) -> T {
851851
// CHECK: [ACTIVE] %3 = alloc_stack $IndirectEnum<T>
852852
// CHECK: bb1:
853853
// CHECK: [ACTIVE] %6 = unchecked_take_enum_data_addr %3 : $*IndirectEnum<T>, #IndirectEnum.case1!enumelt
854-
// CHECK: [ACTIVE] %7 = alloc_stack [lexical] $T, let, name "y1"
854+
// CHECK: [ACTIVE] %7 = alloc_stack [lexical] [var_decl] $T, let, name "y1"
855855
// CHECK: bb2:
856856
// CHECK: [ACTIVE] {{.*}} = unchecked_take_enum_data_addr {{.*}} : $*IndirectEnum<T>, #IndirectEnum.case2!enumelt
857857
// CHECK: [ACTIVE] {{.*}} = tuple_element_addr {{.*}} : $*(Float, T), 0
858858
// CHECK: [VARIED] {{.*}} = load [trivial] {{.*}} : $*Float
859859
// CHECK: [ACTIVE] {{.*}} = tuple_element_addr {{.*}} : $*(Float, T), 1
860-
// CHECK: [ACTIVE] {{.*}} = alloc_stack [lexical] $T, let, name "y2"
860+
// CHECK: [ACTIVE] {{.*}} = alloc_stack [lexical] [var_decl] $T, let, name "y2"
861861
// CHECK: bb3:
862862
// CHECK: [NONE] {{.*}} = tuple ()

test/Interop/Cxx/class/type-classification-non-trivial-silgen.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import TypeClassification
55
// Make sure that "StructWithDestructor" is marked as non-trivial by checking for a
66
// "destroy_addr".
77
// CHECK-LABEL: sil [ossa] @$s4main24testStructWithDestructoryyF
8-
// CHECK: [[AS:%.*]] = alloc_stack [lexical] $StructWithDestructor
8+
// CHECK: [[AS:%.*]] = alloc_stack [lexical] [var_decl] $StructWithDestructor
99
// CHECK: [[FN:%.*]] = function_ref @{{_ZN20StructWithDestructorC1Ev|\?\?0StructWithDestructor@@QEAA@XZ}} : $@convention(c) () -> @out StructWithDestructor
1010
// CHECK: apply [[FN]]([[AS]]) : $@convention(c) () -> @out StructWithDestructor
1111
// CHECK: destroy_addr [[AS]]
@@ -20,7 +20,7 @@ public func testStructWithDestructor() {
2020
// Make sure that "HasMemberWithDestructor" is marked as non-trivial by checking
2121
// for a "destroy_addr".
2222
// CHECK-LABEL: sil [ossa] @$s4main33testStructWithSubobjectDestructoryyF : $@convention(thin) () -> ()
23-
// CHECK: [[AS:%.*]] = alloc_stack [lexical] $StructWithSubobjectDestructor
23+
// CHECK: [[AS:%.*]] = alloc_stack [lexical] [var_decl] $StructWithSubobjectDestructor
2424
// CHECK: [[FN:%.*]] = function_ref @{{_ZN29StructWithSubobjectDestructorC1Ev|\?\?0StructWithSubobjectDestructor@@QEAA@XZ}} : $@convention(c) () -> @out StructWithSubobjectDestructor
2525
// CHECK: apply [[FN]]([[AS]]) : $@convention(c) () -> @out StructWithSubobjectDestructor
2626
// CHECK: destroy_addr [[AS]]
@@ -32,7 +32,7 @@ public func testStructWithSubobjectDestructor() {
3232
}
3333

3434
// CHECK-LABEL: sil [ossa] @$s4main37testStructWithCopyConstructorAndValueSbyF
35-
// CHECK: [[AS:%.*]] = alloc_stack [lexical] $StructWithCopyConstructorAndValue
35+
// CHECK: [[AS:%.*]] = alloc_stack [lexical] [var_decl] $StructWithCopyConstructorAndValue
3636
// CHECK: [[FN:%.*]] = function_ref @{{_ZN33StructWithCopyConstructorAndValueC1Ei|\?\?0StructWithCopyConstructorAndValue@@QEAA@H@Z}} : $@convention(c) (Int32) -> @out StructWithCopyConstructorAndValue
3737
// CHECK: apply [[FN]]([[AS]], %{{.*}}) : $@convention(c) (Int32) -> @out StructWithCopyConstructorAndValue
3838
// CHECK: [[OBJ_VAL_ADDR:%.*]] = struct_element_addr [[AS]] : $*StructWithCopyConstructorAndValue, #StructWithCopyConstructorAndValue.value
@@ -53,10 +53,10 @@ public func testStructWithCopyConstructorAndValue() -> Bool {
5353
}
5454

5555
// CHECK-LABEL: sil [ossa] @$s4main46testStructWithSubobjectCopyConstructorAndValueSbyF : $@convention(thin) () -> Bool
56-
// CHECK: [[MEMBER_0:%.*]] = alloc_stack [lexical] $StructWithCopyConstructorAndValue
56+
// CHECK: [[MEMBER_0:%.*]] = alloc_stack [lexical] [var_decl] $StructWithCopyConstructorAndValue
5757
// CHECK: [[MAKE_MEMBER_FN:%.*]] = function_ref @{{_ZN33StructWithCopyConstructorAndValueC1Ei|\?\?0StructWithCopyConstructorAndValue@@QEAA@H@Z}} : $@convention(c) (Int32) -> @out StructWithCopyConstructorAndValue
5858
// CHECK: apply [[MAKE_MEMBER_FN]]([[MEMBER_0]], %{{.*}}) : $@convention(c) (Int32) -> @out StructWithCopyConstructorAndValue
59-
// CHECK: [[AS:%.*]] = alloc_stack [lexical] $StructWithSubobjectCopyConstructorAndValue
59+
// CHECK: [[AS:%.*]] = alloc_stack [lexical] [var_decl] $StructWithSubobjectCopyConstructorAndValue
6060
// CHECK: [[META:%.*]] = metatype $@thin StructWithSubobjectCopyConstructorAndValue.Type
6161
// CHECK: [[MEMBER_1:%.*]] = alloc_stack $StructWithCopyConstructorAndValue
6262
// CHECK: copy_addr %0 to [init] [[MEMBER_1]] : $*StructWithCopyConstructorAndValue
@@ -87,10 +87,10 @@ public func testStructWithSubobjectCopyConstructorAndValue() -> Bool {
8787

8888
// testStructWithCopyConstructorAndSubobjectCopyConstructorAndValue()
8989
// CHECK-LABEL: sil [ossa] @$s4main041testStructWithCopyConstructorAndSubobjectefG5ValueSbyF : $@convention(thin) () -> Bool
90-
// CHECK: [[MEMBER_0:%.*]] = alloc_stack [lexical] $StructWithCopyConstructorAndValue
90+
// CHECK: [[MEMBER_0:%.*]] = alloc_stack [lexical] [var_decl] $StructWithCopyConstructorAndValue
9191
// CHECK: [[CREATE_MEMBER_FN:%.*]] = function_ref @{{_ZN33StructWithCopyConstructorAndValueC1Ei|\?\?0StructWithCopyConstructorAndValue@@QEAA@H@Z}} : $@convention(c) (Int32) -> @out StructWithCopyConstructorAndValue
9292
// CHECK: apply [[CREATE_MEMBER_FN]]([[MEMBER_0]], %{{.*}}) : $@convention(c) (Int32) -> @out StructWithCopyConstructorAndValue
93-
// CHECK: [[AS:%.*]] = alloc_stack [lexical] $StructWithCopyConstructorAndSubobjectCopyConstructorAndValue
93+
// CHECK: [[AS:%.*]] = alloc_stack [lexical] [var_decl] $StructWithCopyConstructorAndSubobjectCopyConstructorAndValue
9494
// CHECK: [[MEMBER_1:%.*]] = alloc_stack $StructWithCopyConstructorAndValue
9595
// CHECK: copy_addr [[MEMBER_0]] to [init] [[MEMBER_1]] : $*StructWithCopyConstructorAndValue
9696
// CHECK: [[FN:%.*]] = function_ref @{{_ZN60StructWithCopyConstructorAndSubobjectCopyConstructorAndValueC1E33StructWithCopyConstructorAndValue|\?\?0StructWithCopyConstructorAndSubobjectCopyConstructorAndValue@@QEAA@UStructWithCopyConstructorAndValue@@@Z}} : $@convention(c) (@in StructWithCopyConstructorAndValue) -> @out StructWithCopyConstructorAndSubobjectCopyConstructorAndValue

test/SILGen/consume_operator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func testLoadableVar() {
4141
}
4242

4343
// CHECK-LABEL: sil hidden [ossa] @$s7consume18testAddressOnlyLetyyxmAA1PRzlF : $@convention(thin) <T where T : P> (@thick T.Type) -> () {
44-
// CHECK: [[BOX:%.*]] = alloc_stack [lexical] $T
44+
// CHECK: [[BOX:%.*]] = alloc_stack [lexical] [var_decl] $T
4545
//
4646
// CHECK: [[STACK:%.*]] = alloc_stack $T
4747
// CHECK: mark_unresolved_move_addr [[BOX]] to [[STACK]]

test/SILGen/copy_expr.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protocol P {
7878
}
7979

8080
// CHECK-LABEL: sil hidden [ossa] @$s9copy_expr25testCopyAddressOnlyRValueyyxmAA1PRzlF : $@convention(thin) <T where T : P> (@thick T.Type) -> () {
81-
// CHECK: [[BOX:%.*]] = alloc_stack [lexical] $T, let, name "x"
81+
// CHECK: [[BOX:%.*]] = alloc_stack [lexical] [var_decl] $T, let, name "x"
8282
// CHECK: [[TMP:%.*]] = alloc_stack $T
8383
// CHECK: explicit_copy_addr [[BOX]] to [init] [[TMP]]
8484
// CHECK: } // end sil function '$s9copy_expr25testCopyAddressOnlyRValueyyxmAA1PRzlF'
@@ -316,7 +316,7 @@ func testCallMethodOnLoadableGlobal() {
316316
}
317317

318318
// CHECK-LABEL: sil hidden [ossa] @$s9copy_expr34testCallMethodOnAddressOnlyLetCopyyyxmAA1PRzlF : $@convention(thin) <T where T : P> (@thick T.Type) -> () {
319-
// CHECK: [[X:%.*]] = alloc_stack [lexical] $T, let, name "x"
319+
// CHECK: [[X:%.*]] = alloc_stack [lexical] [var_decl] $T, let, name "x"
320320
//
321321
// Calling consumeFunc.
322322
// CHECK: [[TEMP:%.*]] = alloc_stack $T

0 commit comments

Comments
 (0)