Skip to content

Commit 64594a8

Browse files
committed
fix rebase fallout - use new addInstToSpecificSourceAtom function, and fixup some tests
1 parent e692b9a commit 64594a8

20 files changed

+125
-30
lines changed

clang/lib/CodeGen/CGCall.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3921,9 +3921,9 @@ llvm::Value *CodeGenFunction::EmitCMSEClearRecord(llvm::Value *Src,
39213921
return R;
39223922
}
39233923

3924-
void CodeGenFunction::EmitFunctionEpilog(const CGFunctionInfo &FI,
3925-
bool EmitRetDbgLoc,
3926-
SourceLocation EndLoc) {
3924+
void CodeGenFunction::EmitFunctionEpilog(
3925+
const CGFunctionInfo &FI, bool EmitRetDbgLoc, SourceLocation EndLoc,
3926+
uint64_t RetKeyInstructionsSourceAtom) {
39273927
if (FI.isNoReturn()) {
39283928
// Noreturn functions don't return.
39293929
EmitUnreachable(EndLoc);
@@ -3939,7 +3939,10 @@ void CodeGenFunction::EmitFunctionEpilog(const CGFunctionInfo &FI,
39393939
// Functions with no result always return void.
39403940
if (!ReturnValue.isValid()) {
39413941
auto *I = Builder.CreateRetVoid();
3942-
addRetToOverrideOrNewSourceAtom(I, nullptr);
3942+
if (RetKeyInstructionsSourceAtom)
3943+
addInstToSpecificSourceAtom(I, nullptr, RetKeyInstructionsSourceAtom);
3944+
else
3945+
addInstToNewSourceAtom(I, nullptr);
39433946
return;
39443947
}
39453948

@@ -4121,7 +4124,10 @@ void CodeGenFunction::EmitFunctionEpilog(const CGFunctionInfo &FI,
41214124
Ret->setDebugLoc(std::move(RetDbgLoc));
41224125

41234126
llvm::Value *Backup = RV ? Ret->getOperand(0) : nullptr;
4124-
addRetToOverrideOrNewSourceAtom(cast<llvm::ReturnInst>(Ret), Backup);
4127+
if (RetKeyInstructionsSourceAtom)
4128+
addInstToSpecificSourceAtom(Ret, Backup, RetKeyInstructionsSourceAtom);
4129+
else
4130+
addInstToNewSourceAtom(Ret, Backup);
41254131
}
41264132

41274133
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
@@ -341,15 +341,6 @@ llvm::DebugLoc CodeGenFunction::EmitReturnBlock() {
341341
// later by the actual 'ret' instruction.
342342
llvm::DebugLoc Loc = BI->getDebugLoc();
343343
Builder.SetInsertPoint(BI->getParent());
344-
345-
// Key Instructions: If there's only one `ret` then we want to put the
346-
// instruction in the same source atom group as the store to the ret-value
347-
// alloca and unconditional `br` to the return block that we're about to
348-
// delete. It all comes from the same source (`return (value)`).
349-
if (auto *DI = getDebugInfo(); DI && BI->getDebugLoc())
350-
DI->setRetInstSourceAtomOverride(
351-
BI->getDebugLoc().get()->getAtomGroup());
352-
353344
BI->eraseFromParent();
354345
delete ReturnBlock.getBlock();
355346
ReturnBlock = JumpDest();
@@ -452,8 +443,14 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) {
452443

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

459456
assert(EHStack.empty() &&

clang/lib/CodeGen/CodeGenFunction.h

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

26142614
/// EmitFunctionEpilog - Emit the target specific LLVM code to return the
2615-
/// given temporary.
2615+
/// given temporary. Specify the source location atom group (Key Instructions
2616+
/// debug info feature) for the `ret` using \p RetKeyInstructionsSourceAtom.
2617+
/// If it's 0, the `ret` will get added to a new source atom group.
26162618
void EmitFunctionEpilog(const CGFunctionInfo &FI, bool EmitRetDbgLoc,
2617-
SourceLocation EndLoc);
2619+
SourceLocation EndLoc,
2620+
uint64_t RetKeyInstructionsSourceAtom);
26182621

26192622
/// Emit a test that checks if the return value \p RV is nonnull.
26202623
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)