Skip to content

Commit f731558

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 34deb76 commit f731558

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
@@ -461,8 +461,12 @@ void ComplexExprEmitter::EmitStoreOfComplex(ComplexPairTy Val, LValue lvalue,
461461
Address RealPtr = CGF.emitAddrOfRealComponent(Ptr, lvalue.getType());
462462
Address ImagPtr = CGF.emitAddrOfImagComponent(Ptr, lvalue.getType());
463463

464-
Builder.CreateStore(Val.first, RealPtr, lvalue.isVolatileQualified());
465-
Builder.CreateStore(Val.second, ImagPtr, lvalue.isVolatileQualified());
464+
auto *R =
465+
Builder.CreateStore(Val.first, RealPtr, lvalue.isVolatileQualified());
466+
CGF.addInstToCurrentSourceAtom(R, Val.first);
467+
auto *I =
468+
Builder.CreateStore(Val.second, ImagPtr, lvalue.isVolatileQualified());
469+
CGF.addInstToCurrentSourceAtom(I, Val.second);
466470
}
467471

468472

@@ -1209,6 +1213,7 @@ LValue ComplexExprEmitter::
12091213
EmitCompoundAssignLValue(const CompoundAssignOperator *E,
12101214
ComplexPairTy (ComplexExprEmitter::*Func)(const BinOpInfo&),
12111215
RValue &Val) {
1216+
ApplyAtomGroup Grp(CGF.getDebugInfo());
12121217
TestAndClearIgnoreReal();
12131218
TestAndClearIgnoreImag();
12141219
QualType LHSTy = E->getLHS()->getType();
@@ -1356,6 +1361,7 @@ LValue ComplexExprEmitter::EmitBinAssignLValue(const BinaryOperator *E,
13561361
}
13571362

13581363
ComplexPairTy ComplexExprEmitter::VisitBinAssign(const BinaryOperator *E) {
1364+
ApplyAtomGroup Grp(CGF.getDebugInfo());
13591365
ComplexPairTy Val;
13601366
LValue LV = EmitBinAssignLValue(E, Val);
13611367

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)