Skip to content

Commit b1dc990

Browse files
committed
[KeyInstr][Clang] Aggregate init + copy (llvm#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 b34e39c commit b1dc990

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
@@ -885,20 +885,6 @@ class CGDebugInfo {
885885
}
886886
};
887887

888-
/// A scoped helper to set the current source atom group for
889-
/// CGDebugInfo::addInstToCurrentSourceAtom. A source atom is a source construct
890-
/// that is "interesting" for debug stepping purposes. We use an atom group
891-
/// number to track the instruction(s) that implement the functionality for the
892-
/// atom, plus backup instructions/source locations.
893-
class ApplyAtomGroup {
894-
uint64_t OriginalAtom = 0;
895-
CGDebugInfo *DI = nullptr;
896-
897-
public:
898-
ApplyAtomGroup(CGDebugInfo *DI);
899-
~ApplyAtomGroup();
900-
};
901-
902888
/// A scoped helper to set the current debug location to the specified
903889
/// location or preferred location of the specified Expr.
904890
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(),
@@ -2394,7 +2395,8 @@ void CodeGenFunction::EmitAggregateCopy(LValue Dest, LValue Src, QualType Ty,
23942395
}
23952396
}
23962397

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

23992401
// Determine the metadata to describe the position of any padding in this
24002402
// 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 {
@@ -3036,6 +3050,7 @@ class CodeGenFunction : public CodeGenTypeCache {
30363050

30373051
/// Emit an aggregate assignment.
30383052
void EmitAggregateAssign(LValue Dest, LValue Src, QualType EltTy) {
3053+
ApplyAtomGroup Grp(getDebugInfo());
30393054
bool IsVolatile = hasVolatileMember(EltTy);
30403055
EmitAggregateCopy(Dest, Src, EltTy, AggValueSlot::MayOverlap, IsVolatile);
30413056
}
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)