Skip to content

Commit 780f41c

Browse files
committed
[KeyInstr][Clang] Agg init atom (llvm#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 5364a99 commit 780f41c

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
@@ -938,6 +938,7 @@ void CodeGenFunction::emitStoresForInitAfterBZero(llvm::Constant *Init,
938938
isa<llvm::ConstantVector>(Init) || isa<llvm::BlockAddress>(Init) ||
939939
isa<llvm::ConstantExpr>(Init)) {
940940
auto *I = Builder.CreateStore(Init, Loc, isVolatile);
941+
addInstToCurrentSourceAtom(I, nullptr);
941942
if (IsAutoInit)
942943
I->addAnnotationMetadata("auto-init");
943944
return;
@@ -1181,6 +1182,7 @@ void CodeGenFunction::emitStoresForConstant(const VarDecl &D, Address Loc,
11811182
Ty->isPtrOrPtrVectorTy() || Ty->isFPOrFPVectorTy();
11821183
if (canDoSingleStore) {
11831184
auto *I = Builder.CreateStore(constant, Loc, isVolatile);
1185+
addInstToCurrentSourceAtom(I, nullptr);
11841186
if (IsAutoInit)
11851187
I->addAnnotationMetadata("auto-init");
11861188
return;
@@ -1193,6 +1195,8 @@ void CodeGenFunction::emitStoresForConstant(const VarDecl &D, Address Loc,
11931195
if (shouldUseBZeroPlusStoresToInitialize(constant, ConstantSize)) {
11941196
auto *I = Builder.CreateMemSet(Loc, llvm::ConstantInt::get(CGM.Int8Ty, 0),
11951197
SizeVal, isVolatile);
1198+
addInstToCurrentSourceAtom(I, nullptr);
1199+
11961200
if (IsAutoInit)
11971201
I->addAnnotationMetadata("auto-init");
11981202

@@ -1217,6 +1221,7 @@ void CodeGenFunction::emitStoresForConstant(const VarDecl &D, Address Loc,
12171221
}
12181222
auto *I = Builder.CreateMemSet(
12191223
Loc, llvm::ConstantInt::get(CGM.Int8Ty, Value), SizeVal, isVolatile);
1224+
addInstToCurrentSourceAtom(I, nullptr);
12201225
if (IsAutoInit)
12211226
I->addAnnotationMetadata("auto-init");
12221227
return;
@@ -1263,6 +1268,8 @@ void CodeGenFunction::emitStoresForConstant(const VarDecl &D, Address Loc,
12631268
createUnnamedGlobalForMemcpyFrom(
12641269
CGM, D, Builder, constant, Loc.getAlignment()),
12651270
SizeVal, isVolatile);
1271+
addInstToCurrentSourceAtom(I, nullptr);
1272+
12661273
if (IsAutoInit)
12671274
I->addAnnotationMetadata("auto-init");
12681275
}
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)