Skip to content

Commit 0ee40ca

Browse files
authored
[KeyInstr][Clang] Aggregate init + copy (#134639)
This patch is part of a stack that teaches Clang to generate Key Instructions metadata for C and C++. RFC: https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668 The feature is only functional in LLVM if LLVM is built with CMake flag LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed.
1 parent 2804643 commit 0ee40ca

File tree

4 files changed

+35
-15
lines changed

4 files changed

+35
-15
lines changed

clang/lib/CodeGen/CGDebugInfo.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -892,20 +892,6 @@ class CGDebugInfo {
892892
}
893893
};
894894

895-
/// A scoped helper to set the current source atom group for
896-
/// CGDebugInfo::addInstToCurrentSourceAtom. A source atom is a source construct
897-
/// that is "interesting" for debug stepping purposes. We use an atom group
898-
/// number to track the instruction(s) that implement the functionality for the
899-
/// atom, plus backup instructions/source locations.
900-
class ApplyAtomGroup {
901-
uint64_t OriginalAtom = 0;
902-
CGDebugInfo *DI = nullptr;
903-
904-
public:
905-
ApplyAtomGroup(CGDebugInfo *DI);
906-
~ApplyAtomGroup();
907-
};
908-
909895
/// A scoped helper to set the current debug location to the specified
910896
/// location or preferred location of the specified Expr.
911897
class ApplyDebugLocation {

clang/lib/CodeGen/CGExprAgg.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,7 @@ static bool isBlockVarRef(const Expr *E) {
13321332
}
13331333

13341334
void AggExprEmitter::VisitBinAssign(const BinaryOperator *E) {
1335+
ApplyAtomGroup Grp(CGF.getDebugInfo());
13351336
// For an assignment to work, the value on the right has
13361337
// to be compatible with the value on the left.
13371338
assert(CGF.getContext().hasSameUnqualifiedType(E->getLHS()->getType(),
@@ -2393,7 +2394,8 @@ void CodeGenFunction::EmitAggregateCopy(LValue Dest, LValue Src, QualType Ty,
23932394
}
23942395
}
23952396

2396-
auto Inst = Builder.CreateMemCpy(DestPtr, SrcPtr, SizeVal, isVolatile);
2397+
auto *Inst = Builder.CreateMemCpy(DestPtr, SrcPtr, SizeVal, isVolatile);
2398+
addInstToCurrentSourceAtom(Inst, nullptr);
23972399

23982400
// Determine the metadata to describe the position of any padding in this
23992401
// memcpy, as well as the TBAA tags for the members of the struct, in case

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,20 @@ template <> struct DominatingValue<RValue> {
258258
}
259259
};
260260

261+
/// A scoped helper to set the current source atom group for
262+
/// CGDebugInfo::addInstToCurrentSourceAtom. A source atom is a source construct
263+
/// that is "interesting" for debug stepping purposes. We use an atom group
264+
/// number to track the instruction(s) that implement the functionality for the
265+
/// atom, plus backup instructions/source locations.
266+
class ApplyAtomGroup {
267+
uint64_t OriginalAtom = 0;
268+
CGDebugInfo *DI = nullptr;
269+
270+
public:
271+
ApplyAtomGroup(CGDebugInfo *DI);
272+
~ApplyAtomGroup();
273+
};
274+
261275
/// CodeGenFunction - This class organizes the per-function state that is used
262276
/// while generating LLVM code.
263277
class CodeGenFunction : public CodeGenTypeCache {
@@ -3035,6 +3049,7 @@ class CodeGenFunction : public CodeGenTypeCache {
30353049

30363050
/// Emit an aggregate assignment.
30373051
void EmitAggregateAssign(LValue Dest, LValue Src, QualType EltTy) {
3052+
ApplyAtomGroup Grp(getDebugInfo());
30383053
bool IsVolatile = hasVolatileMember(EltTy);
30393054
EmitAggregateCopy(Dest, Src, EltTy, AggValueSlot::MayOverlap, IsVolatile);
30403055
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %clang_cc1 -gkey-instructions -x c++ %s -debug-info-kind=line-tables-only -emit-llvm -o - \
2+
// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank
3+
4+
// RUN: %clang_cc1 -gkey-instructions -x c %s -debug-info-kind=line-tables-only -emit-llvm -o - \
5+
// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank
6+
7+
typedef struct { int a, b, c; } Struct;
8+
void fun(Struct a) {
9+
// CHECK: call void @llvm.memcpy{{.*}}, !dbg [[G1R1:!.*]]
10+
Struct b = a;
11+
12+
// CHECK: call void @llvm.memcpy{{.*}}, !dbg [[G2R1:!.*]]
13+
b = a;
14+
}
15+
16+
// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
17+
// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)

0 commit comments

Comments
 (0)