Skip to content

Commit c44931e

Browse files
committed
Debug Info: Support generic function specialization by substituting
the archetype with the specialized type. rdar://problem/21949734
1 parent 4b7ed84 commit c44931e

File tree

5 files changed

+50
-31
lines changed

5 files changed

+50
-31
lines changed

lib/IRGen/DebugTypeInfo.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,19 @@ namespace swift {
7676
Type = Type->getLValueOrInOutObjectType().getPointer();
7777
}
7878

79+
// Determine whether this type is an Archetype itself.
80+
bool isArchetype() const {
81+
return Type->getLValueOrInOutObjectType()->getKind() ==
82+
TypeKind::Archetype;
83+
}
84+
85+
/// LValues, inout args, and Archetypes are implicitly indirect by
86+
/// virtue of their DWARF type.
87+
bool isImplicitlyIndirect() const {
88+
return Type->isLValueType() || isArchetype() ||
89+
(Type->getKind() == TypeKind::InOut);
90+
}
91+
7992
bool isNull() const { return Type == nullptr; }
8093
bool operator==(DebugTypeInfo T) const;
8194
bool operator!=(DebugTypeInfo T) const;

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -961,24 +961,6 @@ getStorageSize(const llvm::DataLayout &DL, ArrayRef<llvm::Value *> Storage) {
961961
return Size(size);
962962
}
963963

964-
/// LValues, inout args, and Archetypes are implicitly indirect by
965-
/// virtue of their DWARF type.
966-
static bool isImplicitlyIndirect(TypeBase *Ty) {
967-
switch (Ty->getKind()) {
968-
case TypeKind::Paren:
969-
return isImplicitlyIndirect(
970-
cast<ParenType>(Ty)->getUnderlyingType().getPointer());
971-
case TypeKind::NameAlias:
972-
return isImplicitlyIndirect(
973-
cast<NameAliasType>(Ty)->getSinglyDesugaredType());
974-
case TypeKind::InOut:
975-
case TypeKind::Archetype:
976-
return true;
977-
default:
978-
return false;
979-
}
980-
}
981-
982964
void IRGenDebugInfo::emitVariableDeclaration(
983965
IRBuilder &Builder, ArrayRef<llvm::Value *> Storage, DebugTypeInfo DbgTy,
984966
const SILDebugScope *DS, StringRef Name, unsigned ArgNo,
@@ -1018,9 +1000,6 @@ void IRGenDebugInfo::emitVariableDeclaration(
10181000
if (Artificial || DITy->isArtificial() || DITy == InternalType)
10191001
Flags |= llvm::DINode::FlagArtificial;
10201002

1021-
if (isImplicitlyIndirect(DbgTy.getType()))
1022-
Indirection = DirectValue;
1023-
10241003
// Create the descriptor for the variable.
10251004
llvm::DILocalVariable *Var = nullptr;
10261005

lib/IRGen/IRGenSIL.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3012,11 +3012,18 @@ void IRGenSILFunction::visitDebugValueAddrInst(DebugValueAddrInst *i) {
30123012

30133013
StringRef Name = getVarName(i);
30143014
auto Addr = getLoweredAddress(SILVal).getAddress();
3015-
DebugTypeInfo DbgTy(Decl, Decl->getType(), getTypeInfo(SILVal.getType()));
3016-
// Put the value into a stack slot at -Onone and emit a debug intrinsic.
3015+
DebugTypeInfo DbgTy(Decl, SILVal.getType().getSwiftType(),
3016+
getTypeInfo(SILVal.getType()));
3017+
// Unwrap implicitly indirect types and types that are passed by
3018+
// reference only at the SIL level and below.
3019+
if (DbgTy.isArchetype() || i->getVarInfo().Constant)
3020+
DbgTy.unwrapLValueOrInOutType();
3021+
// Put the value's address into a stack slot at -Onone and emit a debug
3022+
// intrinsic.
30173023
emitDebugVariableDeclaration(
3018-
emitShadowCopy(Addr, i->getDebugScope(), Name), DbgTy,
3019-
i->getDebugScope(), Name, i->getVarInfo().ArgNo, IndirectValue);
3024+
emitShadowCopy(Addr, i->getDebugScope(), Name), DbgTy, i->getDebugScope(),
3025+
Name, i->getVarInfo().ArgNo,
3026+
DbgTy.isImplicitlyIndirect() ? DirectValue : IndirectValue);
30203027
}
30213028

30223029
void IRGenSILFunction::visitLoadWeakInst(swift::LoadWeakInst *i) {
@@ -3427,10 +3434,11 @@ void IRGenSILFunction::visitAllocBoxInst(swift::AllocBoxInst *i) {
34273434
if (Name == IGM.Context.Id_self.str())
34283435
return;
34293436

3437+
DebugTypeInfo DbgTy(Decl, i->getElementType().getSwiftType(), type);
34303438
IGM.DebugInfo->emitVariableDeclaration(
34313439
Builder, emitShadowCopy(addr.getAddress(), i->getDebugScope(), Name),
3432-
DebugTypeInfo(Decl, i->getElementType().getSwiftType(), type),
3433-
i->getDebugScope(), Name, 0, IndirectValue);
3440+
DbgTy, i->getDebugScope(), Name, 0,
3441+
DbgTy.isImplicitlyIndirect() ? DirectValue : IndirectValue);
34343442
}
34353443
}
34363444

test/DebugInfo/byref-capture.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ func makeIncrementor(inc : Int64) -> () -> Int64
77
func inner() -> Int64 {
88
// CHECK: call void @llvm.dbg.declare(metadata %Vs5Int64**
99
// CHECK-SAME: metadata ![[SUM_CAPTURE:[0-9]+]],
10-
// CHECK-SAME: metadata ![[DEREF:[0-9]+]])
11-
// CHECK: ![[DEREF]] = !DIExpression(DW_OP_deref)
12-
// CHECK: ![[SUM_CAPTURE]] = !DILocalVariable(name: "sum",
13-
// CHECK-SAME: line: [[@LINE-8]]
10+
// CHECK-SAME: metadata ![[EMPTY:.*]])
11+
// CHECK: ![[EMPTY]] = !DIExpression()
12+
// CHECK: ![[SUM_CAPTURE]] = !DILocalVariable(name: "sum", arg: 1,
13+
// CHECK-SAME: line: [[@LINE-8]], type: !"_TtRVs5Int64"
14+
// ^ inout type.
1415
sum += inc
1516
return sum
1617
}

test/DebugInfo/specialization.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %target-swift-frontend -O %s -disable-llvm-optzns -emit-sil -g -o - | FileCheck %s
2+
3+
// CHECK: sil shared [noinline] @_TTSg5SiSis21IntegerArithmeticTypes__
4+
// CHECK-SAME: _TF14specialization3sumuRxs21IntegerArithmeticTyperFTxx_x
5+
// CHECK-SAME: $@convention(thin) (@out Int, @in Int, @in Int) -> () {
6+
// CHECK: bb0(%0 : $*Int, %1 : $*Int, %2 : $*Int):
7+
// CHECK: debug_value_addr %1 : $*Int, let, name "i", argno 1
8+
// CHECK: debug_value_addr %2 : $*Int, let, name "j", argno 2
9+
10+
@inline(never)
11+
public func sum<T : IntegerArithmeticType>(i : T, _ j : T) -> T {
12+
let result = i + j
13+
return result
14+
}
15+
16+
public func inc(inout i : Int) {
17+
i = sum(i, 1)
18+
}

0 commit comments

Comments
 (0)