Skip to content

Commit 4ec56ac

Browse files
[clang][DebugInfo] Add virtual call-site target information in DWARF.
Make the extra call site information available by default.
1 parent 96678f3 commit 4ec56ac

File tree

8 files changed

+29
-67
lines changed

8 files changed

+29
-67
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4958,11 +4958,7 @@ void CGDebugInfo::EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc,
49584958
Fn->setSubprogram(SP);
49594959
}
49604960

4961-
bool CGDebugInfo::generateCallSiteForPS() const {
4962-
// The added call target will be available only for SCE targets.
4963-
if (CGM.getCodeGenOpts().getDebuggerTuning() != llvm::DebuggerKind::SCE)
4964-
return false;
4965-
4961+
bool CGDebugInfo::generateVirtualCallSite() const {
49664962
// Check general conditions for call site generation.
49674963
return (getCallSiteRelatedAttrs() != llvm::DINode::FlagZero);
49684964
}
@@ -4976,7 +4972,7 @@ void CGDebugInfo::addCallTargetMetadata(llvm::MDNode *MD, llvm::CallBase *CI) {
49764972

49774973
// Finalize call_target generation.
49784974
void CGDebugInfo::finalizeCallTarget() {
4979-
if (!generateCallSiteForPS())
4975+
if (!generateVirtualCallSite())
49804976
return;
49814977

49824978
for (auto &E : CallTargetCache) {
@@ -4989,7 +4985,7 @@ void CGDebugInfo::finalizeCallTarget() {
49894985

49904986
void CGDebugInfo::addCallTarget(StringRef Name, llvm::MDNode *MD,
49914987
llvm::CallBase *CI) {
4992-
if (!generateCallSiteForPS())
4988+
if (!generateVirtualCallSite())
49934989
return;
49944990

49954991
// Record only indirect calls.
@@ -5019,7 +5015,7 @@ void CGDebugInfo::addCallTarget(StringRef Name, llvm::MDNode *MD,
50195015

50205016
void CGDebugInfo::addCallTarget(llvm::Function *F, const FunctionDecl *FD,
50215017
llvm::CallBase *CI) {
5022-
if (!generateCallSiteForPS())
5018+
if (!generateVirtualCallSite())
50235019
return;
50245020

50255021
if (!F && !FD)
@@ -5035,7 +5031,7 @@ void CGDebugInfo::addCallTarget(llvm::Function *F, const FunctionDecl *FD,
50355031
}
50365032

50375033
void CGDebugInfo::removeCallTarget(StringRef Name) {
5038-
if (!generateCallSiteForPS())
5034+
if (!generateVirtualCallSite())
50395035
return;
50405036

50415037
auto It = CallTargetCache.find(Name);
@@ -5044,7 +5040,7 @@ void CGDebugInfo::removeCallTarget(StringRef Name) {
50445040
}
50455041

50465042
void CGDebugInfo::removeCallTarget(llvm::Function *F) {
5047-
if (!generateCallSiteForPS())
5043+
if (!generateVirtualCallSite())
50485044
return;
50495045

50505046
if (F && F->hasName())

clang/lib/CodeGen/CGDebugInfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,8 +925,8 @@ class CGDebugInfo {
925925
using CallTargetEntry = std::pair<llvm::TrackingMDNodeRef, InstrList>;
926926
llvm::SmallDenseMap<StringRef, CallTargetEntry> CallTargetCache;
927927

928-
/// Generate call target information only for SIE debugger.
929-
bool generateCallSiteForPS() const;
928+
/// Generate call target information.
929+
bool generateVirtualCallSite() const;
930930

931931
/// Add 'call_target' metadata to the 'call' instruction.
932932
void addCallTargetMetadata(llvm::MDNode *MD, llvm::CallBase *CI);

clang/test/DebugInfo/CXX/callsite-base.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ void bar(CBase *Base) {
1919
B.one();
2020
}
2121

22-
// RUN: %clang_cc1 -debugger-tuning=sce -triple=x86_64-linux -disable-llvm-passes -emit-llvm -debug-info-kind=constructor -dwarf-version=5 -O1 %s -o - | FileCheck %s -check-prefix CHECK-BASE
22+
// RUN: %clang_cc1 -triple=x86_64-linux -disable-llvm-passes -emit-llvm \
23+
// RUN: -debug-info-kind=constructor -dwarf-version=5 -O1 %s \
24+
// RUN: -o - | FileCheck %s -check-prefix CHECK-BASE
2325

2426
// CHECK-BASE: define {{.*}} @_Z3barP5CBase{{.*}} {
2527
// CHECK-BASE-DAG: call void %1{{.*}} !dbg {{![0-9]+}}, !call_target [[BASE_ONE:![0-9]+]]
@@ -32,11 +34,3 @@ void bar(CBase *Base) {
3234
// CHECK-BASE-DAG: [[BASE_ONE]] = {{.*}}!DISubprogram(name: "one", linkageName: "_ZN5CBase3oneEv"
3335
// CHECK-BASE-DAG: [[BASE_TWO]] = {{.*}}!DISubprogram(name: "two", linkageName: "_ZN5CBase3twoEv"
3436
// CHECK-BASE-DAG: [[BASE_THREE]] = {{.*}}!DISubprogram(name: "three", linkageName: "_ZN5CBase5threeEv"
35-
36-
// RUN: %clang_cc1 -triple=x86_64-linux -disable-llvm-passes -emit-llvm -debug-info-kind=constructor -dwarf-version=5 -O1 %s -o - | FileCheck %s -check-prefix CHECK-BASE-NON
37-
38-
// CHECK-BASE-NON: define {{.*}} @_Z3barP5CBase{{.*}} {
39-
// CHECK-BASE-NON-DAG: call void %1{{.*}} !dbg {{![0-9]+}}
40-
// CHECK-BASE-NON-DAG: call void %3{{.*}} !dbg {{![0-9]+}}
41-
// CHECK-BASE-NON-DAG: call void %5{{.*}} !dbg {{![0-9]+}}
42-
// CHECK-BASE-NON: }

clang/test/DebugInfo/CXX/callsite-derived.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ void foo(CDerived *Derived) {
4242
Derived->one(true);
4343
}
4444

45-
// RUN: %clang_cc1 -debugger-tuning=sce -triple=x86_64-linux -disable-llvm-passes -emit-llvm -debug-info-kind=constructor -dwarf-version=5 -O1 %s -o - | FileCheck %s -check-prefix CHECK-DERIVED
45+
// RUN: %clang_cc1 -triple=x86_64-linux -disable-llvm-passes -emit-llvm \
46+
// RUN: -debug-info-kind=constructor -dwarf-version=5 -O1 %s \
47+
// RUN: -o - | FileCheck %s -check-prefix CHECK-DERIVED
4648

4749
// CHECK-DERIVED: define {{.*}} @_Z3fooP5CBase{{.*}} {
4850
// CHECK-DERIVED-DAG: call void @_ZN5CBase5threeEv{{.*}} !dbg {{![0-9]+}}
@@ -73,13 +75,3 @@ void foo(CDerived *Derived) {
7375

7476
// CHECK-DERIVED-DAG: [[BASE_TWO]] = {{.*}}!DISubprogram(name: "two", linkageName: "_ZN5CBase3twoEic"
7577
// CHECK-DERIVED-DAG: [[DERIVED_ONE]] = {{.*}}!DISubprogram(name: "one", linkageName: "_ZN8CDerived3oneEb"
76-
77-
// RUN: %clang_cc1 -triple=x86_64-linux -disable-llvm-passes -emit-llvm -debug-info-kind=constructor -dwarf-version=5 -O1 %s -o - | FileCheck %s -check-prefix CHECK-DERIVED-NON
78-
79-
// CHECK-DERIVED-NON: define {{.*}} @_Z3barP5CBase{{.*}} {
80-
// CHECK-DERIVED-NON-DAG: call void %1{{.*}} !dbg {{![0-9]+}}
81-
// CHECK-DERIVED-NON: }
82-
83-
// CHECK-DERIVED-NON: define {{.*}} @_Z3fooP8CDerived{{.*}} {
84-
// CHECK-DERIVED-NON-DAG: call void %1{{.*}} !dbg {{![0-9]+}}
85-
// CHECK-DERIVED-NON: }

clang/test/DebugInfo/CXX/callsite-edges.cpp

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ void edge_c(CDeep *Deep) {
7878
D3->d3(3);
7979
}
8080

81-
// RUN: %clang -Xclang -debugger-tuning=sce --target=x86_64-linux -Xclang -disable-llvm-passes -fno-discard-value-names -emit-llvm -S -g -O1 %s -o - | FileCheck %s -check-prefix CHECK-EDGES
81+
// RUN: %clang_cc1 -triple=x86_64-linux -disable-llvm-passes -emit-llvm \
82+
// RUN: -debug-info-kind=constructor -dwarf-version=5 -O1 %s \
83+
// RUN: -o - | FileCheck %s -check-prefix CHECK-EDGES
8284

8385
// CHECK-EDGES: define {{.*}} @_Z6edge_aP6CEmpty{{.*}} {
8486
// CHECK-EDGES-DAG: call void %1{{.*}} !dbg {{![0-9]+}}
@@ -105,21 +107,3 @@ void edge_c(CDeep *Deep) {
105107
// CHECK-EDGES-DAG: [[CDEEP_D1]] = {{.*}}!DISubprogram(name: "d1", linkageName: "_ZN5CDeep3CD12d1Ei"
106108
// CHECK-EDGES-DAG: [[CDEEP_D2]] = {{.*}}!DISubprogram(name: "d2", linkageName: "_ZN5CDeep3CD13CD22d2Ei"
107109
// CHECK-EDGES-DAG: [[CDEEP_D3]] = {{.*}}!DISubprogram(name: "d3", linkageName: "_ZN5CDeep3CD13CD23CD32d3Ei"
108-
109-
// RUN: %clang --target=x86_64-linux -Xclang -disable-llvm-passes -fno-discard-value-names -emit-llvm -S -g -O1 %s -o - | FileCheck %s -check-prefix CHECK-EDGES-NON
110-
111-
// CHECK-EDGES-NON: define {{.*}} @_Z6edge_aP6CEmpty{{.*}} {
112-
// CHECK-EDGES-NON-DAG: call void %3{{.*}} !dbg {{![0-9]+}}
113-
// CHECK-EDGES-NON: }
114-
115-
// CHECK-EDGES-NON: define {{.*}} @_Z6edge_bP5CBase{{.*}} {
116-
// CHECK-EDGES-NON-DAG: call void %1{{.*}} !dbg {{![0-9]+}}
117-
// CHECK-EDGES-NON-DAG: call void %3{{.*}} !dbg {{![0-9]+}}
118-
// CHECK-EDGES-NON: }
119-
120-
// CHECK-EDGES-NON: define {{.*}} @_Z6edge_cP5CDeep{{.*}} {
121-
// CHECK-EDGES-NON-DAG: call void %1{{.*}} !dbg {{![0-9]+}}
122-
// CHECK-EDGES-NON-DAG: call void %4{{.*}} !dbg {{![0-9]+}}
123-
// CHECK-EDGES-NON-DAG: call void %7{{.*}} !dbg {{![0-9]+}}
124-
// CHECK-EDGES-NON-DAG: call void %10{{.*}} !dbg {{![0-9]+}}
125-
// CHECK-EDGES-NON: }

cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/callsite-dwarf.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ void CDerivedTwo::bar(int &j) { DerivedOne->foo(j); }
3838
// !40 = !DISubprogram(name: "bar", linkageName: "_ZN11CDerivedTwo3barERi", ...)
3939
// !65 = !DILocation(line: 25, column: 15, scope: !40)
4040

41-
// RUN: %clang --target=x86_64-unknown-linux -c -g -O1 \
42-
// RUN: -Xclang -debugger-tuning=sce %s -o - | \
41+
// RUN: %clang --target=x86_64-unknown-linux -c -g -O1 %s -o - | \
4342
// RUN: llvm-dwarfdump --debug-info - | FileCheck %s --check-prefix=CHECK
4443

4544
// CHECK: DW_TAG_compile_unit
@@ -51,7 +50,7 @@ void CDerivedTwo::bar(int &j) { DerivedOne->foo(j); }
5150
// CHECK: DW_AT_name ("CBaseOne")
5251
// CHECK: [[FOO_DEF:0x[a-f0-9]+]]: DW_TAG_subprogram
5352
// CHECK: DW_AT_call_all_calls (true)
54-
// CHECK: DW_AT_specification ([[FOO_DCL]] "foo")
53+
// CHECK: DW_AT_specification ([[FOO_DCL]] "{{.*}}foo{{.*}}")
5554
// CHECK: DW_TAG_structure_type
5655
// CHECK: DW_AT_name ("CDerivedTwo")
5756
// CHECK: DW_TAG_subprogram
@@ -60,9 +59,9 @@ void CDerivedTwo::bar(int &j) { DerivedOne->foo(j); }
6059
// CHECK: DW_AT_name ("CBaseTwo")
6160
// CHECK: DW_TAG_subprogram
6261
// CHECK: DW_AT_call_all_calls (true)
63-
// CHECK: DW_AT_specification (0x{{.*}} "bar")
62+
// CHECK: DW_AT_specification (0x{{.*}} "{{.*}}bar{{.*}}")
6463
// CHECK: DW_TAG_call_site
6564
// CHECK: DW_AT_call_target (DW_OP_reg0 RAX)
6665
// CHECK: DW_AT_call_tail_call (true)
6766
// CHECK: DW_AT_call_pc (0x{{.*}})
68-
// CHECK: DW_AT_call_origin ([[FOO_DEF]] "foo")
67+
// CHECK: DW_AT_call_origin ([[FOO_DEF]] "{{.*}}foo{{.*}}")

llvm/lib/Target/X86/X86ISelLoweringCall.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,12 +2053,11 @@ X86TargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
20532053
// Set type id for call site info and metadata 'call_target'.
20542054
// We are filtering for:
20552055
// a) The call-graph-section use case that wants to know about indirect
2056-
// calls, and
2057-
// b) the SCE-tuing case where we want to annotate indirect calls.
2058-
if (CB &&
2059-
((MF.getTarget().Options.EmitCallGraphSection && CB->isIndirectCall()) ||
2060-
(MF.getTarget().Options.EmitCallSiteInfo &&
2061-
MF.getTarget().Options.DebuggerTuning == DebuggerKind::SCE)))
2056+
// calls, or
2057+
// b) We want to annotate indirect calls.
2058+
if (CB && CB->isIndirectCall() &&
2059+
(MF.getTarget().Options.EmitCallGraphSection ||
2060+
MF.getTarget().Options.EmitCallSiteInfo))
20622061
CSInfo = MachineFunction::CallSiteInfo(*CB);
20632062

20642063
if (IsIndirectCall && !IsWin64 &&

llvm/test/CodeGen/MIR/X86/callsite-emit-calleetypeid.ll

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,13 @@
3232
;; Test printer and parser with -emit-call-site-info only.
3333

3434
;; Test printer.
35-
;; Verify that fwdArgRegs is set, calleeTypeIds is not set.
35+
;; Verify that fwdArgRegs and calleeTypeIds are set.
3636
; RUN: llc -mtriple=x86_64 -emit-call-site-info %s -stop-after=finalize-isel -o %t2.mir
3737
; RUN: cat %t2.mir | FileCheck %s --check-prefix=PRINTER_CSI
3838
; PRINTER_CSI: name: main
3939
; PRINTER_CSI: callSites:
4040
; PRINTER_CSI-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs:
41-
; PRINTER_CSI-NEXT: { arg: 0, reg: {{.*}} }
42-
; PRINTER_CSI-NOT: calleeTypeIds:
41+
; PRINTER_CSI-NEXT: { arg: 0, reg: {{.*}} }, calleeTypeIds:
4342

4443

4544
;; Test parser.
@@ -49,8 +48,7 @@
4948
; PARSER_CSI: name: main
5049
; PARSER_CSI: callSites:
5150
; PARSER_CSI-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs:
52-
; PARSER_CSI-NEXT: { arg: 0, reg: {{.*}} }
53-
; PARSER_CSI-NOT: calleeTypeIds:
51+
; PARSER_CSI-NEXT: { arg: 0, reg: {{.*}} }, calleeTypeIds:
5452

5553
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5654
;; Test printer and parser with both -emit-call-site-info and --call-graph-section.

0 commit comments

Comments
 (0)