Skip to content

Commit 8534d6e

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 ca03a49 commit 8534d6e

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
@@ -1925,6 +1925,7 @@ void CodeGenFunction::EmitAutoVarInit(const AutoVarEmission &emission) {
19251925

19261926
const VarDecl &D = *emission.Variable;
19271927
auto DL = ApplyDebugLocation::CreateDefaultArtificial(*this, D.getLocation());
1928+
ApplyAtomGroup Grp(getDebugInfo());
19281929
QualType type = D.getType();
19291930

19301931
// 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
@@ -2222,6 +2222,8 @@ void CodeGenFunction::EmitStoreOfScalar(llvm::Value *Value, Address Addr,
22222222
}
22232223

22242224
llvm::StoreInst *Store = Builder.CreateStore(Value, Addr, Volatile);
2225+
addInstToCurrentSourceAtom(Store, Value);
2226+
22252227
if (isNontemporal) {
22262228
llvm::MDNode *Node =
22272229
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)