Skip to content

Commit 8ce070e

Browse files
committed
[KeyInstr] Complex assignment atoms
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 6788769 commit 8ce070e

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

clang/lib/CodeGen/CGExprComplex.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,12 @@ void ComplexExprEmitter::EmitStoreOfComplex(ComplexPairTy Val, LValue lvalue,
456456
Address RealPtr = CGF.emitAddrOfRealComponent(Ptr, lvalue.getType());
457457
Address ImagPtr = CGF.emitAddrOfImagComponent(Ptr, lvalue.getType());
458458

459-
Builder.CreateStore(Val.first, RealPtr, lvalue.isVolatileQualified());
460-
Builder.CreateStore(Val.second, ImagPtr, lvalue.isVolatileQualified());
459+
auto *R =
460+
Builder.CreateStore(Val.first, RealPtr, lvalue.isVolatileQualified());
461+
CGF.addInstToCurrentSourceAtom(R, Val.first);
462+
auto *I =
463+
Builder.CreateStore(Val.second, ImagPtr, lvalue.isVolatileQualified());
464+
CGF.addInstToCurrentSourceAtom(I, Val.second);
461465
}
462466

463467

@@ -1204,6 +1208,7 @@ LValue ComplexExprEmitter::
12041208
EmitCompoundAssignLValue(const CompoundAssignOperator *E,
12051209
ComplexPairTy (ComplexExprEmitter::*Func)(const BinOpInfo&),
12061210
RValue &Val) {
1211+
ApplyAtomGroup Grp(CGF.getDebugInfo());
12071212
TestAndClearIgnoreReal();
12081213
TestAndClearIgnoreImag();
12091214
QualType LHSTy = E->getLHS()->getType();
@@ -1351,6 +1356,7 @@ LValue ComplexExprEmitter::EmitBinAssignLValue(const BinaryOperator *E,
13511356
}
13521357

13531358
ComplexPairTy ComplexExprEmitter::VisitBinAssign(const BinaryOperator *E) {
1359+
ApplyAtomGroup Grp(CGF.getDebugInfo());
13541360
ComplexPairTy Val;
13551361
LValue LV = EmitBinAssignLValue(E, Val);
13561362

clang/test/KeyInstructions/complex.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
// RUN: %clang -gkey-instructions -x c++ %s -gmlt -gcolumn-info -S -emit-llvm -o - -Wno-unused-variable \
3+
// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank
4+
5+
// RUN: %clang -gkey-instructions -x c %s -gmlt -gcolumn-info -S -emit-llvm -o - -Wno-unused-variable \
6+
// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank
7+
8+
_Complex float ci;
9+
void test() {
10+
// CHECK: %ci.real = load float, ptr @ci{{.*}}, !dbg [[G1R2:!.*]]
11+
// CHECK: %ci.imag = load float, ptr getelementptr inbounds nuw ({ float, float }, ptr @ci, i32 0, i32 1){{.*}}, !dbg [[G1R2]]
12+
// CHECK: store float %ci.real, ptr %lc.realp{{.*}}, !dbg [[G1R1:!.*]]
13+
// CHECK: store float %ci.imag, ptr %lc.imagp{{.*}}, !dbg [[G1R1]]
14+
_Complex float lc = ci;
15+
16+
// CHECK: %ci.real1 = load float, ptr @ci{{.*}}, !dbg [[G2R2:!.*]]
17+
// CHECK: %ci.imag2 = load float, ptr getelementptr inbounds nuw ({ float, float }, ptr @ci, i32 0, i32 1){{.*}}, !dbg [[G2R2]]
18+
// CHECK: store float %ci.real1, ptr @ci{{.*}}, !dbg [[G2R1:!.*]]
19+
// CHECK: store float %ci.imag2, ptr getelementptr inbounds nuw ({ float, float }, ptr @ci, i32 0, i32 1){{.*}}, !dbg [[G2R1]]
20+
ci = ci;
21+
22+
// CHECK: %add.r = fadd float %ci.real5, %ci.real3, !dbg [[G3R2:!.*]]
23+
// CHECK: %add.i = fadd float %ci.imag6, %ci.imag4, !dbg [[G3R2]]
24+
// CHECK: store float %add.r, ptr @ci{{.*}}, !dbg [[G3R1:!.*]]
25+
// CHECK: store float %add.i, ptr getelementptr inbounds nuw ({ float, float }, ptr @ci, i32 0, i32 1){{.*}}, !dbg [[G3R1]]
26+
ci += ci;
27+
28+
// CHECK: %add = fadd float %0, %1, !dbg [[G4R2:!.*]]
29+
// CHECK: store float %add, ptr getelementptr inbounds nuw ({ float, float }, ptr @ci, i32 0, i32 1){{.*}}, !dbg [[G4R1:!.*]]
30+
__imag ci = __imag ci + __imag ci;
31+
}
32+
33+
// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2)
34+
// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
35+
// CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2)
36+
// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
37+
// CHECK: [[G3R2]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 2)
38+
// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)
39+
// CHECK: [[G4R2]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 2)
40+
// CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1)

0 commit comments

Comments
 (0)