Skip to content

Commit cb41882

Browse files
authored
Merge pull request #14130 from dcci/layoutlldb
2 parents 8c175c2 + fa10866 commit cb41882

File tree

2 files changed

+18
-35
lines changed

2 files changed

+18
-35
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -759,44 +759,31 @@ class IRGenSILFunction :
759759
Storage.getAlignment());
760760
}
761761

762-
void emitShadowCopy(ArrayRef<llvm::Value *> vals, const SILDebugScope *Scope,
762+
void emitShadowCopy(SILValue &SILVal, const SILDebugScope *Scope,
763763
StringRef Name, unsigned ArgNo, bool IsAnonymous,
764764
llvm::SmallVectorImpl<llvm::Value *> &copy) {
765+
Explosion e = getLoweredExplosion(SILVal);
766+
765767
// Only do this at -O0.
766768
if (IGM.IRGen.Opts.shouldOptimize() || IsAnonymous) {
769+
auto vals = e.claimAll();
767770
copy.append(vals.begin(), vals.end());
768771
return;
769772
}
770773

771774
// Single or empty values.
772-
if (vals.size() <= 1) {
775+
if (e.size() <= 1) {
776+
auto vals = e.claimAll();
773777
for (auto val : vals)
774778
copy.push_back(emitShadowCopy(val, Scope, Name, ArgNo, IsAnonymous));
775779
return;
776780
}
777781

778-
// Create a single aggregate alloca for explosions.
779-
// TODO: why are we doing this instead of using the TypeInfo?
780-
llvm::StructType *aggregateType = [&] {
781-
SmallVector<llvm::Type *, 8> eltTypes;
782-
for (auto val : vals)
783-
eltTypes.push_back(val->getType());
784-
return llvm::StructType::get(IGM.LLVMContext, eltTypes);
785-
}();
786-
787-
auto layout = IGM.DataLayout.getStructLayout(aggregateType);
788-
Alignment align(layout->getAlignment());
789-
790-
auto alloca = createAlloca(aggregateType, align, Name + ".debug");
791-
ArtificialLocation AutoRestore(Scope, IGM.DebugInfo, Builder);
792-
size_t i = 0;
793-
for (auto val : vals) {
794-
auto addr = Builder.CreateStructGEP(alloca, i,
795-
Size(layout->getElementOffset(i)));
796-
Builder.CreateStore(val, addr);
797-
i++;
798-
}
799-
copy.push_back(alloca.getAddress());
782+
SILType Type = SILVal->getType();
783+
auto &LTI = cast<LoadableTypeInfo>(IGM.getTypeInfo(Type));
784+
auto Alloca = LTI.allocateStack(*this, Type, "debug.copy");
785+
LTI.initialize(*this, e, Alloca.getAddress(), false /* isOutlined */);
786+
copy.push_back(Alloca.getAddressPointer());
800787
}
801788

802789
/// Determine whether a generic variable has been inlined.
@@ -3633,10 +3620,8 @@ void IRGenSILFunction::visitDebugValueInst(DebugValueInst *i) {
36333620

36343621
// Put the value into a stack slot at -Onone.
36353622
llvm::SmallVector<llvm::Value *, 8> Copy;
3636-
Explosion e = getLoweredExplosion(SILVal);
36373623
unsigned ArgNo = i->getVarInfo().ArgNo;
3638-
emitShadowCopy(e.claimAll(), i->getDebugScope(), Name, ArgNo, IsAnonymous,
3639-
Copy);
3624+
emitShadowCopy(SILVal, i->getDebugScope(), Name, ArgNo, IsAnonymous, Copy);
36403625
emitDebugVariableDeclaration(Copy, DbgTy, SILTy, i->getDebugScope(),
36413626
i->getDecl(), Name, ArgNo);
36423627
}

test/DebugInfo/guard-let.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@ func use<T>(_ t: T) {}
88
public func f(_ i : Int?)
99
{
1010
// CHECK: define {{.*}}@"$S4main1fyySiSgF"
11-
// The shadow copy store should not have a location.
12-
// Note that the store must be in the same scope or else it might defeat
13-
// livedebugvalues.
11+
// CHECK1: %debug.copy = alloca %TSiSg
12+
// CHECK1: @llvm.dbg.declare(metadata %TSiSg* %debug.copy
1413
// CHECK1: @llvm.dbg.declare(metadata {{(i32|i64)}}* %val.addr, {{.*}}, !dbg ![[DBG0:.*]]
15-
// CHECK1: %[[PHI:.*]] = phi
16-
// CHECK1: store {{(i32|i64)}} %[[PHI]], {{(i32|i64)}}* %val.addr, align {{(4|8)}}, !dbg ![[DBG1:.*]]
1714
// CHECK1: ![[F:.*]] = distinct !DISubprogram(name: "f",
1815
// CHECK1: ![[BLK:.*]] = distinct !DILexicalBlock(scope: ![[F]],
1916
// CHECK1: ![[DBG0]] = !DILocation(line: [[@LINE+2]],
@@ -29,10 +26,11 @@ public func f(_ i : Int?)
2926
public func g(_ s : String?)
3027
{
3128
// CHECK2: define {{.*}}@"$S4main1gyySSSgF"
32-
// The shadow copy store should not have a location.
33-
// CHECK2: getelementptr inbounds {{.*}} %s.debug, {{.*}}, !dbg ![[DBG0:.*]]
29+
// CHECK2: %debug.copy = alloca %TSSSg
30+
// CHECK2: @llvm.dbg.declare(metadata %TSSSg*
31+
// CHECK2: %debug.copy1 = alloca %TSS
32+
// CHECK2: @llvm.dbg.declare(metadata %TSS*
3433
// CHECK2: ![[G:.*]] = distinct !DISubprogram(name: "g"
35-
// CHECK2: ![[DBG0]] = !DILocation(line: 0, scope: ![[G]])
3634
guard let val = s else { return }
3735
use(val)
3836
}

0 commit comments

Comments
 (0)