Skip to content

Commit 8dceef1

Browse files
committed
fix rebase fallout - use new addInstToSpecificSourceAtom function, and fixup some tests
1 parent c24cdd7 commit 8dceef1

File tree

18 files changed

+123
-28
lines changed

18 files changed

+123
-28
lines changed

clang/lib/CodeGen/CGCall.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3929,9 +3929,9 @@ llvm::Value *CodeGenFunction::EmitCMSEClearRecord(llvm::Value *Src,
39293929
return R;
39303930
}
39313931

3932-
void CodeGenFunction::EmitFunctionEpilog(const CGFunctionInfo &FI,
3933-
bool EmitRetDbgLoc,
3934-
SourceLocation EndLoc) {
3932+
void CodeGenFunction::EmitFunctionEpilog(
3933+
const CGFunctionInfo &FI, bool EmitRetDbgLoc, SourceLocation EndLoc,
3934+
uint64_t RetKeyInstructionsSourceAtom) {
39353935
if (FI.isNoReturn()) {
39363936
// Noreturn functions don't return.
39373937
EmitUnreachable(EndLoc);
@@ -3947,7 +3947,10 @@ void CodeGenFunction::EmitFunctionEpilog(const CGFunctionInfo &FI,
39473947
// Functions with no result always return void.
39483948
if (!ReturnValue.isValid()) {
39493949
auto *I = Builder.CreateRetVoid();
3950-
addRetToOverrideOrNewSourceAtom(I, nullptr);
3950+
if (RetKeyInstructionsSourceAtom)
3951+
addInstToSpecificSourceAtom(I, nullptr, RetKeyInstructionsSourceAtom);
3952+
else
3953+
addInstToNewSourceAtom(I, nullptr);
39513954
return;
39523955
}
39533956

@@ -4129,7 +4132,10 @@ void CodeGenFunction::EmitFunctionEpilog(const CGFunctionInfo &FI,
41294132
Ret->setDebugLoc(std::move(RetDbgLoc));
41304133

41314134
llvm::Value *Backup = RV ? Ret->getOperand(0) : nullptr;
4132-
addRetToOverrideOrNewSourceAtom(cast<llvm::ReturnInst>(Ret), Backup);
4135+
if (RetKeyInstructionsSourceAtom)
4136+
addInstToSpecificSourceAtom(Ret, Backup, RetKeyInstructionsSourceAtom);
4137+
else
4138+
addInstToNewSourceAtom(Ret, Backup);
41334139
}
41344140

41354141
void CodeGenFunction::EmitReturnValueCheck(llvm::Value *RV) {

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -342,15 +342,6 @@ llvm::DebugLoc CodeGenFunction::EmitReturnBlock() {
342342
// later by the actual 'ret' instruction.
343343
llvm::DebugLoc Loc = BI->getDebugLoc();
344344
Builder.SetInsertPoint(BI->getParent());
345-
346-
// Key Instructions: If there's only one `ret` then we want to put the
347-
// instruction in the same source atom group as the store to the ret-value
348-
// alloca and unconditional `br` to the return block that we're about to
349-
// delete. It all comes from the same source (`return (value)`).
350-
if (auto *DI = getDebugInfo(); DI && BI->getDebugLoc())
351-
DI->setRetInstSourceAtomOverride(
352-
BI->getDebugLoc().get()->getAtomGroup());
353-
354345
BI->eraseFromParent();
355346
delete ReturnBlock.getBlock();
356347
ReturnBlock = JumpDest();
@@ -453,8 +444,14 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) {
453444

454445
// Reset the debug location to that of the simple 'return' expression, if any
455446
// rather than that of the end of the function's scope '}'.
447+
uint64_t RetKeyInstructionsAtomGroup = Loc ? Loc->getAtomGroup() : 0;
448+
llvm::errs() << "RetKeyInstructionsAtomGroup " << RetKeyInstructionsAtomGroup
449+
<< "\n";
450+
if (Loc)
451+
llvm::errs() << *Loc << "\n";
456452
ApplyDebugLocation AL(*this, Loc);
457-
EmitFunctionEpilog(*CurFnInfo, EmitRetDbgLoc, EndLoc);
453+
EmitFunctionEpilog(*CurFnInfo, EmitRetDbgLoc, EndLoc,
454+
RetKeyInstructionsAtomGroup);
458455
EmitEndEHSpec(CurCodeDecl);
459456

460457
assert(EHStack.empty() &&

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2551,9 +2551,12 @@ class CodeGenFunction : public CodeGenTypeCache {
25512551
const FunctionArgList &Args);
25522552

25532553
/// EmitFunctionEpilog - Emit the target specific LLVM code to return the
2554-
/// given temporary.
2554+
/// given temporary. Specify the source location atom group (Key Instructions
2555+
/// debug info feature) for the `ret` using \p RetKeyInstructionsSourceAtom.
2556+
/// If it's 0, the `ret` will get added to a new source atom group.
25552557
void EmitFunctionEpilog(const CGFunctionInfo &FI, bool EmitRetDbgLoc,
2556-
SourceLocation EndLoc);
2558+
SourceLocation EndLoc,
2559+
uint64_t RetKeyInstructionsSourceAtom);
25572560

25582561
/// Emit a test that checks if the return value \p RV is nonnull.
25592562
void EmitReturnValueCheck(llvm::Value *RV);

clang/test/DebugInfo/KeyInstructions/agg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ void fun(Struct a) {
3434
// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)
3535
// CHECK: [[G4R2]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 2)
3636
// CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1)
37-
// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]])
37+
// CHECK: [[RET]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]])

clang/test/DebugInfo/KeyInstructions/assign-scalar.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,4 @@ void fun() {
8585
// CHECK: [[G11R2]] = !DILocation({{.*}}, atomGroup: 11, atomRank: 2)
8686
// CHECK: [[G11R1]] = !DILocation({{.*}}, atomGroup: 11, atomRank: 1)
8787
// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]])
88+
// CHECK: [[RET]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]])
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %clang_cc1 -gkey-instructions -x c++ %s -debug-info-kind=line-tables-only -emit-llvm -o - \
2+
// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank
3+
4+
// RUN: %clang_cc1 -gkey-instructions -x c %s -debug-info-kind=line-tables-only -emit-llvm -o - \
5+
// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank
6+
7+
unsigned long long g;
8+
void fun() {
9+
// CHECK: store i64 0, ptr @g{{.*}}, !dbg [[G1R1:!.*]]
10+
g = 0;
11+
12+
// Treat the two assignments as two atoms.
13+
//
14+
// FIXME: Because of the atomGroup implementation the load can only be
15+
// associated with one of the two stores, despite being a good backup
16+
// loction for both.
17+
// CHECK-NEXT: %0 = load i64, ptr @g{{.*}}, !dbg [[G2R2:!.*]]
18+
// CHECK-NEXT: store i64 %0, ptr @g{{.*}}, !dbg [[G3R1:!.*]]
19+
// CHECK-NEXT: store i64 %0, ptr @g{{.*}}, !dbg [[G2R1:!.*]]
20+
g = g = g;
21+
22+
// Compound assignment.
23+
// CHECK: %1 = load i64, ptr @g
24+
// CHECK: %add = add i64 %1, 50, !dbg [[G4R2:!.*]]
25+
// CHECK: store i64 %add, ptr @g{{.*}}, !dbg [[G4R1:!.*]]
26+
g += 50;
27+
// CHECK: ret{{.*}}, !dbg [[RET:!.*]]
28+
}
29+
30+
// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
31+
// CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2)
32+
// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)
33+
// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
34+
// CHECK: [[G4R2]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 2)
35+
// CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1)
36+
// CHECK: [[RET]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]])

clang/test/DebugInfo/KeyInstructions/bitfield.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ void foo(int x, S s) {
1616

1717
// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2)
1818
// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
19-
// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]])
19+
// CHECK: [[RET]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]])

clang/test/DebugInfo/KeyInstructions/builtin.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,4 @@ void fun() {
8888
// CHECK: [[G15R2]] = !DILocation({{.*}}, atomGroup: 15, atomRank: 2)
8989
// CHECK: [[G15R1]] = !DILocation({{.*}}, atomGroup: 15, atomRank: 1)
9090
// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]])
91+
// CHECK: [[RET]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]])

clang/test/DebugInfo/KeyInstructions/complex.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,4 @@ void test() {
9797
// CHECK-C: [[G11R2]] = !DILocation({{.*}}, atomGroup: 11, atomRank: 2)
9898
// CHECK-C: [[G11R1]] = !DILocation({{.*}}, atomGroup: 11, atomRank: 1)
9999
// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]])
100+
// CHECK: [[RET]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]])

clang/test/DebugInfo/KeyInstructions/do.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ void a(int A) {
3333
// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
3434
// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
3535
// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)
36-
// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]])
36+
// CHECK: [[RET]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]])

0 commit comments

Comments
 (0)