Skip to content

Commit 29d5428

Browse files
committed
[KeyInstr][Clang] Scalar init atom
This patch is part of a stack that teaches Clang to generate Key Instructions metadata for C and C++. The Key Instructions project is introduced, including a "quick summary" section at the top which adds context for this PR, here: 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. The Clang-side work is demoed here: #130943
1 parent 856f99e commit 29d5428

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

clang/lib/CodeGen/CGDecl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,6 +1921,7 @@ void CodeGenFunction::EmitAutoVarInit(const AutoVarEmission &emission) {
19211921

19221922
const VarDecl &D = *emission.Variable;
19231923
auto DL = ApplyDebugLocation::CreateDefaultArtificial(*this, D.getLocation());
1924+
ApplyAtomGroup Grp(getDebugInfo());
19241925
QualType type = D.getType();
19251926

19261927
// If this local has an initializer, emit it now.

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2180,6 +2180,8 @@ void CodeGenFunction::EmitStoreOfScalar(llvm::Value *Value, Address Addr,
21802180
}
21812181

21822182
llvm::StoreInst *Store = Builder.CreateStore(Value, Addr, Volatile);
2183+
addInstToCurrentSourceAtom(Store, Value);
2184+
21832185
if (isNontemporal) {
21842186
llvm::MDNode *Node =
21852187
llvm::MDNode::get(Store->getContext(),
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %clang -gkey-instructions -x c++ %s -gmlt -gcolumn-info -S -emit-llvm -o - \
2+
// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank
3+
4+
// RUN: %clang -gkey-instructions -x c %s -gmlt -gcolumn-info -S -emit-llvm -o - \
5+
// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank
6+
7+
void a() {
8+
// CHECK: store i32 0, ptr %A{{.*}}, !dbg [[G1R1:!.*]]
9+
int A = 0;
10+
// CHECK: %add = add {{.*}}, !dbg [[G2R2:!.*]]
11+
// CHECK: store i32 %add, ptr %B, align 4, !dbg [[G2R1:!.*]]
12+
int B = 2 * A + 1;
13+
// CHECK-TODO: ret{{.*}}, !dbg [[G3R1:!.*]]
14+
}
15+
16+
// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
17+
// CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2)
18+
// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
19+
// CHECK-TODO: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)

0 commit comments

Comments
 (0)