Skip to content

Commit 97964f1

Browse files
committed
Emit debug info for pack count parameters.
1 parent 4aadffe commit 97964f1

File tree

5 files changed

+93
-1
lines changed

5 files changed

+93
-1
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
243243
Optional<SILLocation> Loc);
244244
void emitTypeMetadata(IRGenFunction &IGF, llvm::Value *Metadata,
245245
unsigned Depth, unsigned Index, StringRef Name);
246+
void emitPackCountParameter(IRGenFunction &IGF, llvm::Value *Metadata,
247+
SILDebugVariable VarInfo);
246248

247249
/// Return the DIBuilder.
248250
llvm::DIBuilder &getBuilder() { return DBuilder; }
@@ -2982,6 +2984,25 @@ void IRGenDebugInfoImpl::emitTypeMetadata(IRGenFunction &IGF,
29822984
ArtificialValue);
29832985
}
29842986

2987+
void IRGenDebugInfoImpl::emitPackCountParameter(IRGenFunction &IGF,
2988+
llvm::Value *Metadata,
2989+
SILDebugVariable VarInfo) {
2990+
if (Opts.DebugInfoLevel <= IRGenDebugInfoLevel::LineTables)
2991+
return;
2992+
2993+
// Don't emit debug info in transparent functions.
2994+
auto *DS = IGF.getDebugScope();
2995+
if (!DS || DS->getInlinedFunction()->isTransparent())
2996+
return;
2997+
2998+
Type IntTy = IGM.Context.getIntType();
2999+
auto &TI = IGM.getTypeInfoForUnlowered(IntTy);
3000+
auto DbgTy = *CompletedDebugTypeInfo::getFromTypeInfo(IntTy, TI, IGM);
3001+
emitVariableDeclaration(
3002+
IGF.Builder, Metadata, DbgTy, IGF.getDebugScope(), {}, VarInfo,
3003+
IGF.isAsync() ? CoroDirectValue : DirectValue, ArtificialValue);
3004+
}
3005+
29853006
SILLocation::FilenameAndLocation
29863007
IRGenDebugInfoImpl::decodeSourceLoc(SourceLoc SL) {
29873008
auto &Cached = FilenameAndLocationCache[SL.getOpaquePointerValue()];
@@ -3113,6 +3134,13 @@ void IRGenDebugInfo::emitTypeMetadata(IRGenFunction &IGF, llvm::Value *Metadata,
31133134
Depth, Index, Name);
31143135
}
31153136

3137+
void IRGenDebugInfo::emitPackCountParameter(IRGenFunction &IGF,
3138+
llvm::Value *Metadata,
3139+
SILDebugVariable VarInfo) {
3140+
static_cast<IRGenDebugInfoImpl *>(this)->emitPackCountParameter(IGF, Metadata,
3141+
VarInfo);
3142+
}
3143+
31163144
llvm::DIBuilder &IRGenDebugInfo::getBuilder() {
31173145
return static_cast<IRGenDebugInfoImpl *>(this)->getBuilder();
31183146
}

lib/IRGen/IRGenDebugInfo.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ class IRGenDebugInfo {
188188
void emitTypeMetadata(IRGenFunction &IGF, llvm::Value *Metadata,
189189
unsigned Depth, unsigned Index, StringRef Name);
190190

191+
/// Emit debug info for the IR function parameter holding the size of one or
192+
/// more parameter / type packs.
193+
void emitPackCountParameter(IRGenFunction &IGF, llvm::Value *Metadata,
194+
SILDebugVariable VarInfo);
195+
191196
/// Return the DIBuilder.
192197
llvm::DIBuilder &getBuilder();
193198

lib/IRGen/IRGenSIL.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ class IRGenSILFunction :
415415
llvm::SmallDenseMap<StackSlotKey, Address, 8> ShadowStackSlots;
416416
llvm::SmallDenseMap<llvm::Value *, Address, 8> TaskAllocStackSlots;
417417
llvm::SmallDenseMap<Decl *, Identifier, 8> AnonymousVariables;
418+
llvm::SmallDenseSet<llvm::Value *, 4> PackShapeExpressions;
418419
/// To avoid inserting elements into ValueDomPoints twice.
419420
llvm::SmallDenseSet<llvm::Value *, 8> ValueVariables;
420421
/// Holds the DominancePoint of values that are storage for a source variable.
@@ -1099,7 +1100,20 @@ class IRGenSILFunction :
10991100
emitTypeMetadataRef(archetype);
11001101
else if (auto packArchetype = dyn_cast<PackArchetypeType>(t))
11011102
emitTypeMetadataRef(packArchetype);
1102-
1103+
else if (auto packtype = dyn_cast<SILPackType>(t)) {
1104+
llvm::Value *Shape = emitPackShapeExpression(t);
1105+
if (PackShapeExpressions.insert(Shape).second) {
1106+
llvm::SmallString<8> Buf;
1107+
llvm::raw_svector_ostream OS(Buf);
1108+
unsigned Position = PackShapeExpressions.size();
1109+
OS << "$pack_count_" << Position;
1110+
SILDebugVariable Var(OS.str(), true, 0);
1111+
Shape = emitShadowCopyIfNeeded(Shape, getDebugScope(), Var, false,
1112+
false /*was move*/);
1113+
if (IGM.DebugInfo)
1114+
IGM.DebugInfo->emitPackCountParameter(*this, Shape, Var);
1115+
}
1116+
}
11031117
});
11041118
}
11051119

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// RUN: %target-swift-frontend -emit-ir %s -g -o - \
2+
// RUN: -enable-experimental-feature VariadicGenerics \
3+
// RUN: -parse-as-library -module-name a \
4+
// RUN: -disable-round-trip-debug-types | %FileCheck %s
5+
// FIXME: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ remove this!
6+
// rdar://105021109
7+
8+
public func f1<T...>(ts: repeat each T) {
9+
// CHECK: define {{.*}} @"$s1a2f12tsyxxQp_tlF"(%swift.opaque** {{.*}}, i{{32|64}} [[COUNT1_1:.*]], %swift.type** {{.*}})
10+
// CHECK-DAG: store i{{32|64}} [[COUNT1_1]], i{{32|64}}* %[[COUNT1_1_A:.*]], align
11+
// CHECK-DAG: call void @llvm.dbg.declare({{.*}}[[COUNT1_1_A]], metadata ![[COUNT1_1_VAR:[0-9]+]], metadata !DIExpression())
12+
// CHECK-LABEL: ret void
13+
}
14+
15+
public func f2<U..., V...>(us: repeat each U, vs: repeat each V) {
16+
// CHECK: define {{.*}} @"$s1a2f22us2vsyxxQp_q_q_Qptr0_lF"(%swift.opaque** {{.*}}, %swift.opaque** {{.*}}, i{{32|64}} [[COUNT2_1:.*]], i{{32|64}} [[COUNT2_2:.*]], %swift.type** {{.*}}, %swift.type** {{.*}})
17+
// CHECK-DAG: store i{{32|64}} [[COUNT2_1]], i{{32|64}}* %[[COUNT2_1_A:.*]], align
18+
// CHECK-DAG: store i{{32|64}} [[COUNT2_2]], i{{32|64}}* %[[COUNT2_2_A:.*]], align
19+
// CHECK-DAG: call void @llvm.dbg.declare({{.*}}[[COUNT2_1_A]], metadata ![[COUNT2_1_VAR:[0-9]+]], metadata !DIExpression())
20+
// CHECK-DAG: call void @llvm.dbg.declare({{.*}}[[COUNT2_2_A]], metadata ![[COUNT2_2_VAR:[0-9]+]], metadata !DIExpression())
21+
// CHECK-LABEL: ret void
22+
}
23+
24+
public func f3<T...>(ts: repeat each T, more_ts: repeat each T) {
25+
// CHECK: define {{.*}} @"$s1a2f32ts05more_B0yxxQp_xxQptlF"(%swift.opaque** {{.*}}, %swift.opaque** {{.*}}, i{{32|64}} [[COUNT3_1:.*]], %swift.type** {{.*}})
26+
// CHECK-DAG: store i{{32|64}} [[COUNT3_1]], i{{32|64}}* %[[COUNT3_1_A:.*]], align
27+
// CHECK-DAG: call void @llvm.dbg.declare({{.*}}[[COUNT3_1_A]], metadata ![[COUNT3_1_VAR:[0-9]+]], metadata !DIExpression())
28+
// CHECK-LABEL: ret void
29+
}
30+
31+
public func f4<U..., V...>(us: repeat (each U, each V)) {
32+
// CHECK: define {{.*}} @"$s1a2f42usyx_q_txQp_tq_Rhzr0_lF"(%swift.opaque** {{.*}}, i{{32|64}} [[COUNT4_1:.*]], %swift.type** {{.*}}, %swift.type** {{.*}})
33+
// CHECK-DAG: store i{{32|64}} [[COUNT4_1]], i{{32|64}}* %[[COUNT4_1_A:.*]], align
34+
// CHECK-DAG: call void @llvm.dbg.declare({{.*}}[[COUNT4_1_A]], metadata ![[COUNT4_1_VAR:[0-9]+]], metadata !DIExpression())
35+
// CHECK-LABEL: ret void
36+
}
37+
38+
// CHECK-LABEL: !DICompileUnit
39+
// CHECK-DAG: [[COUNT1_1_VAR]] = !DILocalVariable(name: "$pack_count_1",{{.*}} flags: DIFlagArtificial)
40+
// CHECK-DAG: [[COUNT2_1_VAR]] = !DILocalVariable(name: "$pack_count_1",{{.*}} flags: DIFlagArtificial)
41+
// CHECK-DAG: [[COUNT2_2_VAR]] = !DILocalVariable(name: "$pack_count_2",{{.*}} flags: DIFlagArtificial)
42+
// CHECK-DAG: [[COUNT3_1_VAR]] = !DILocalVariable(name: "$pack_count_1",{{.*}} flags: DIFlagArtificial)
43+
// CHECK-DAG: [[COUNT4_1_VAR]] = !DILocalVariable(name: "$pack_count_1",{{.*}} flags: DIFlagArtificial)
44+

test/DebugInfo/variadic-generics.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// RUN: -parse-as-library -module-name a \
44
// RUN: -disable-round-trip-debug-types | %FileCheck %s
55
// FIXME: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ remove this!
6+
// rdar://105021109
67

78
public func foo<T...>(args: repeat each T) {
89
// CHECK: define {{.*}} @"$s1a3foo4argsyxxQp_tlF"

0 commit comments

Comments
 (0)