Skip to content

Commit 229aa66

Browse files
authored
[KeyInstr][Clang] Agg init atom (#134635)
Covers aggregate initialisation and -ftrivial-auto-var-init=pattern. 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 5df819f commit 229aa66

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

clang/lib/CodeGen/CGDecl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,7 @@ void CodeGenFunction::emitStoresForInitAfterBZero(llvm::Constant *Init,
945945
isa<llvm::ConstantVector>(Init) || isa<llvm::BlockAddress>(Init) ||
946946
isa<llvm::ConstantExpr>(Init)) {
947947
auto *I = Builder.CreateStore(Init, Loc, isVolatile);
948+
addInstToCurrentSourceAtom(I, nullptr);
948949
if (IsAutoInit)
949950
I->addAnnotationMetadata("auto-init");
950951
return;
@@ -1188,6 +1189,7 @@ void CodeGenFunction::emitStoresForConstant(const VarDecl &D, Address Loc,
11881189
Ty->isPtrOrPtrVectorTy() || Ty->isFPOrFPVectorTy();
11891190
if (canDoSingleStore) {
11901191
auto *I = Builder.CreateStore(constant, Loc, isVolatile);
1192+
addInstToCurrentSourceAtom(I, nullptr);
11911193
if (IsAutoInit)
11921194
I->addAnnotationMetadata("auto-init");
11931195
return;
@@ -1200,6 +1202,8 @@ void CodeGenFunction::emitStoresForConstant(const VarDecl &D, Address Loc,
12001202
if (shouldUseBZeroPlusStoresToInitialize(constant, ConstantSize)) {
12011203
auto *I = Builder.CreateMemSet(Loc, llvm::ConstantInt::get(CGM.Int8Ty, 0),
12021204
SizeVal, isVolatile);
1205+
addInstToCurrentSourceAtom(I, nullptr);
1206+
12031207
if (IsAutoInit)
12041208
I->addAnnotationMetadata("auto-init");
12051209

@@ -1224,6 +1228,7 @@ void CodeGenFunction::emitStoresForConstant(const VarDecl &D, Address Loc,
12241228
}
12251229
auto *I = Builder.CreateMemSet(
12261230
Loc, llvm::ConstantInt::get(CGM.Int8Ty, Value), SizeVal, isVolatile);
1231+
addInstToCurrentSourceAtom(I, nullptr);
12271232
if (IsAutoInit)
12281233
I->addAnnotationMetadata("auto-init");
12291234
return;
@@ -1270,6 +1275,8 @@ void CodeGenFunction::emitStoresForConstant(const VarDecl &D, Address Loc,
12701275
createUnnamedGlobalForMemcpyFrom(
12711276
CGM, D, Builder, constant, Loc.getAlignment()),
12721277
SizeVal, isVolatile);
1278+
addInstToCurrentSourceAtom(I, nullptr);
1279+
12731280
if (IsAutoInit)
12741281
I->addAnnotationMetadata("auto-init");
12751282
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
// RUN: %clang_cc1 -gkey-instructions %s -debug-info-kind=line-tables-only -gno-column-info -emit-llvm -o - -ftrivial-auto-var-init=pattern \
3+
// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank
4+
5+
// The implicit-check-not is important; we don't want the GEPs created for the
6+
// store locations to be included in the atom group.
7+
8+
int g;
9+
void a() {
10+
// CHECK: _Z1av()
11+
// CHECK: call void @llvm.memcpy{{.*}}%A, {{.*}}@__const._Z1av.A{{.*}}, !dbg [[G1R1:!.*]]
12+
int A[] = { 1, 2, 3 };
13+
14+
// CHECK: call void @llvm.memcpy{{.*}}%B, {{.*}}@__const._Z1av.B{{.*}}, !dbg [[G2R1:!.*]]
15+
// CHECK-NEXT: store i32 1, ptr %B{{.*}}, !dbg [[G2R1:!.*]]
16+
// CHECK-NEXT: %arrayinit.element = getelementptr {{.*}}, ptr %B, i64 1, !dbg [[B_LINE:!.*]]
17+
// CHECK-NEXT: store i32 2, ptr %arrayinit.element{{.*}}, !dbg [[G2R1]]
18+
// CHECK-NEXT: %arrayinit.element1 = getelementptr {{.*}}, ptr %B, i64 2, !dbg [[B_LINE]]
19+
// CHECK-NEXT: %0 = load i32, ptr @g{{.*}}, !dbg [[G2R2:!.*]]
20+
// CHECK-NEXT: store i32 %0, ptr %arrayinit.element1{{.*}}, !dbg [[G2R1]]
21+
int B[] = { 1, 2, g };
22+
23+
// CHECK: call void @llvm.memset{{.*}}%big{{.*}} !dbg [[G3R1:!.*]]
24+
// CHECK-NEXT: %1 = getelementptr {{.*}}, ptr %big, i32 0, i32 0, !dbg [[big_LINE:!.*]]
25+
// CHECK-NEXT: store i8 97, ptr %1{{.*}}, !dbg [[G3R1]]
26+
// CHECK-NEXT: %2 = getelementptr {{.*}}, ptr %big, i32 0, i32 1, !dbg [[big_LINE]]
27+
// CHECK-NEXT: store i8 98, ptr %2{{.*}}, !dbg [[G3R1]]
28+
// CHECK-NEXT: %3 = getelementptr {{.*}}, ptr %big, i32 0, i32 2, !dbg [[big_LINE]]
29+
// CHECK-NEXT: store i8 99, ptr %3{{.*}}, !dbg [[G3R1]]
30+
// CHECK-NEXT: %4 = getelementptr {{.*}}, ptr %big, i32 0, i32 3, !dbg [[big_LINE]]
31+
// CHECK: store i8 100, ptr %4{{.*}} !dbg [[G3R1]]
32+
char big[65536] = { 'a', 'b', 'c', 'd' };
33+
34+
// CHECK: call void @llvm.memset{{.*}}%arr{{.*}}, !dbg [[G4R1:!.*]]
35+
char arr[] = { 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, };
36+
37+
// CHECK: store i8 -86, ptr %uninit{{.*}}, !dbg [[G5R1:!.*]], !annotation
38+
char uninit; // -ftrivial-auto-var-init=pattern
39+
}
40+
41+
// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
42+
// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
43+
// CHECK: [[B_LINE]] = !DILocation(line: 21, scope: ![[#]])
44+
// CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2)
45+
// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)
46+
// CHECK: [[big_LINE]] = !DILocation(line: 32, scope: ![[#]])
47+
// CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1)
48+
// CHECK: [[G5R1]] = !DILocation({{.*}}, atomGroup: 5, atomRank: 1)

0 commit comments

Comments
 (0)