Skip to content

Commit fae68b6

Browse files
authored
[RISCV] Enabled debug entry support by default (#157703)
This patch enables support for debug entry values. This improves quality of debug info for RISC-V
1 parent 1b05212 commit fae68b6

File tree

5 files changed

+143
-9
lines changed

5 files changed

+143
-9
lines changed

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,9 +1975,10 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
19751975
}
19761976

19771977
const llvm::Triple::ArchType DebugEntryValueArchs[] = {
1978-
llvm::Triple::x86, llvm::Triple::x86_64, llvm::Triple::aarch64,
1979-
llvm::Triple::arm, llvm::Triple::armeb, llvm::Triple::mips,
1980-
llvm::Triple::mipsel, llvm::Triple::mips64, llvm::Triple::mips64el};
1978+
llvm::Triple::x86, llvm::Triple::x86_64, llvm::Triple::aarch64,
1979+
llvm::Triple::arm, llvm::Triple::armeb, llvm::Triple::mips,
1980+
llvm::Triple::mipsel, llvm::Triple::mips64, llvm::Triple::mips64el,
1981+
llvm::Triple::riscv32, llvm::Triple::riscv64};
19811982

19821983
if (Opts.OptimizationLevel > 0 && Opts.hasReducedDebugInfo() &&
19831984
llvm::is_contained(DebugEntryValueArchs, T.getArch()))

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23258,6 +23258,10 @@ SDValue RISCVTargetLowering::LowerCall(CallLoweringInfo &CLI,
2325823258
if (VA.isRegLoc()) {
2325923259
// Queue up the argument copies and emit them at the end.
2326023260
RegsToPass.push_back(std::make_pair(VA.getLocReg(), ArgValue));
23261+
23262+
const TargetOptions &Options = DAG.getTarget().Options;
23263+
if (Options.EmitCallSiteInfo)
23264+
CSInfo.ArgRegPairs.emplace_back(VA.getLocReg(), i);
2326123265
} else {
2326223266
assert(VA.isMemLoc() && "Argument not register or memory");
2326323267
assert(!IsTailCall && "Tail call not allowed if stack is used "
@@ -23359,9 +23363,7 @@ SDValue RISCVTargetLowering::LowerCall(CallLoweringInfo &CLI,
2335923363
if (CLI.CFIType)
2336023364
Ret.getNode()->setCFIType(CLI.CFIType->getZExtValue());
2336123365
DAG.addNoMergeSiteInfo(Ret.getNode(), CLI.NoMerge);
23362-
if (MF.getTarget().Options.EmitCallGraphSection && CB &&
23363-
CB->isIndirectCall())
23364-
DAG.addCallSiteInfo(Ret.getNode(), std::move(CSInfo));
23366+
DAG.addCallSiteInfo(Ret.getNode(), std::move(CSInfo));
2336523367
return Ret;
2336623368
}
2336723369

@@ -23370,10 +23372,8 @@ SDValue RISCVTargetLowering::LowerCall(CallLoweringInfo &CLI,
2337023372
if (CLI.CFIType)
2337123373
Chain.getNode()->setCFIType(CLI.CFIType->getZExtValue());
2337223374

23373-
if (MF.getTarget().Options.EmitCallGraphSection && CB && CB->isIndirectCall())
23374-
DAG.addCallSiteInfo(Chain.getNode(), std::move(CSInfo));
23375-
2337623375
DAG.addNoMergeSiteInfo(Chain.getNode(), CLI.NoMerge);
23376+
DAG.addCallSiteInfo(Chain.getNode(), std::move(CSInfo));
2337723377
Glue = Chain.getValue(1);
2337823378

2337923379
// Mark the end of the call, which is glued to the call itself.

llvm/lib/Target/RISCV/RISCVTargetMachine.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ RISCVTargetMachine::RISCVTargetMachine(const Target &T, const Triple &TT,
163163
setMachineOutliner(true);
164164
setSupportsDefaultOutlining(true);
165165

166+
// RISC-V supports the debug entry values.
167+
setSupportsDebugEntryValues(true);
168+
166169
if (TT.isOSFuchsia() && !TT.isArch64Bit())
167170
report_fatal_error("Fuchsia is only supported for 64-bit");
168171

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
;; Test RISC-V 32 bit:
2+
; RUN: llc -emit-call-site-info -stop-after=livedebugvalues -mtriple=riscv32-linux-gnu -o - %s | FileCheck %s --check-prefix=CHECK32
3+
4+
;; Built from source:
5+
;; extern long fn1(long,long,long);
6+
;; long fn2(long a, long b, long c) {
7+
;; long local = fn1(a+b, c, b+10);
8+
;; if (local > 10)
9+
;; return local + 10;
10+
;; return b;
11+
;; }
12+
;; Using command:
13+
;; clang -g -O2 -target riscv32-linux-gnu m.c -c -S -emit-llvm
14+
;; Confirm that info from callSites attribute is used as entry_value in DIExpression.
15+
16+
;; Test riscv32:
17+
; CHECK32: $x10 = nsw ADD $x11, killed renamable $x10
18+
; CHECK32-NEXT: DBG_VALUE $x10, $noreg, !{{.*}}, !DIExpression(DW_OP_LLVM_entry_value, 1)
19+
20+
; ModuleID = 'm.c'
21+
source_filename = "m.c"
22+
target datalayout = "e-m:e-p:32:32-i64:64-n32-S128"
23+
target triple = "riscv32-unknown-linux-gnu"
24+
25+
; Function Attrs: nounwind uwtable
26+
define i32 @fn2(i32 noundef %a, i32 noundef %b, i32 noundef %c) !dbg !14 {
27+
entry:
28+
#dbg_value(i32 %a, !20, !DIExpression(), !23)
29+
#dbg_value(i32 %b, !21, !DIExpression(), !23)
30+
#dbg_value(i32 %c, !22, !DIExpression(), !23)
31+
%add = add nsw i32 %b, %a
32+
%add1 = add nsw i32 %b, 10
33+
%call = tail call i32 @fn1(i32 noundef %add, i32 noundef %c, i32 noundef %add1)
34+
#dbg_value(i32 %call, !22, !DIExpression(), !23)
35+
%cmp = icmp sgt i32 %call, 10
36+
%add2 = add nuw nsw i32 %call, 10
37+
%retval.0 = select i1 %cmp, i32 %add2, i32 %b
38+
ret i32 %retval.0, !dbg !29
39+
}
40+
41+
declare !dbg !30 i32 @fn1(i32 noundef, i32 noundef, i32 noundef)
42+
43+
!llvm.dbg.cu = !{!0}
44+
!llvm.module.flags = !{!2, !3, !4}
45+
!llvm.ident = !{!5}
46+
47+
!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
48+
!1 = !DIFile(filename: "m.c", directory: ".")
49+
!2 = !{i32 7, !"Dwarf Version", i32 5}
50+
!3 = !{i32 2, !"Debug Info Version", i32 3}
51+
!4 = !{i32 1, !"wchar_size", i32 4}
52+
!5 = !{!"clang"}
53+
!14 = distinct !DISubprogram(name: "fn2", scope: !1, file: !1, line: 2, type: !15, scopeLine: 2, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !18)
54+
!15 = !DISubroutineType(types: !16)
55+
!16 = !{!17, !17, !17, !17}
56+
!17 = !DIBasicType(name: "long", size: 64, encoding: DW_ATE_signed)
57+
!18 = !{!19, !20, !21, !22}
58+
!19 = !DILocalVariable(name: "a", arg: 1, scope: !14, file: !1, line: 2, type: !17)
59+
!20 = !DILocalVariable(name: "b", arg: 2, scope: !14, file: !1, line: 2, type: !17)
60+
!21 = !DILocalVariable(name: "c", arg: 3, scope: !14, file: !1, line: 2, type: !17)
61+
!22 = !DILocalVariable(name: "local", scope: !14, file: !1, line: 3, type: !17)
62+
!23 = !DILocation(line: 0, scope: !14)
63+
!29 = !DILocation(line: 7, column: 1, scope: !14)
64+
!30 = !DISubprogram(name: "fn1", scope: !1, file: !1, line: 1, type: !15, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
65+
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
;; Test RISC-V 64 bit:
2+
; RUN: llc -emit-call-site-info -stop-after=livedebugvalues -mtriple=riscv64-linux-gnu -o - %s | FileCheck %s --check-prefix=CHECK64
3+
4+
;; Built from source:
5+
;; extern long fn1(long,long,long);
6+
;; long fn2(long a, long b, long c) {
7+
;; long local = fn1(a+b, c, b+10);
8+
;; if (local > 10)
9+
;; return local + 10;
10+
;; return b;
11+
;; }
12+
;; Using command:
13+
;; clang -g -O2 -target riscv64-linux-gnu m.c -c -S -emit-llvm
14+
;; Confirm that info from callSites attribute is used as entry_value in DIExpression.
15+
16+
;; Test riscv64:
17+
; CHECK64: $x10 = nsw ADD $x11, killed renamable $x10
18+
; CHECK64-NEXT: DBG_VALUE $x10, $noreg, !{{.*}}, !DIExpression(DW_OP_LLVM_entry_value, 1)
19+
20+
; ModuleID = 'm.c'
21+
source_filename = "m.c"
22+
target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
23+
target triple = "riscv64-unknown-linux-gnu"
24+
25+
; Function Attrs: nounwind uwtable
26+
define i64 @fn2(i64 noundef %a, i64 noundef %b, i64 noundef %c) !dbg !14 {
27+
entry:
28+
#dbg_value(i64 %a, !19, !DIExpression(), !23)
29+
#dbg_value(i64 %b, !20, !DIExpression(), !23)
30+
#dbg_value(i64 %c, !21, !DIExpression(), !23)
31+
%add = add nsw i64 %b, %a
32+
%add1 = add nsw i64 %b, 10
33+
%call = tail call i64 @fn1(i64 noundef %add, i64 noundef %c, i64 noundef %add1)
34+
#dbg_value(i64 %call, !22, !DIExpression(), !23)
35+
%cmp = icmp sgt i64 %call, 10
36+
%add2 = add nuw nsw i64 %call, 10
37+
%retval.0 = select i1 %cmp, i64 %add2, i64 %b
38+
ret i64 %retval.0, !dbg !29
39+
}
40+
41+
declare !dbg !30 i64 @fn1(i64 noundef, i64 noundef, i64 noundef)
42+
43+
!llvm.dbg.cu = !{!0}
44+
!llvm.module.flags = !{!2, !3, !4}
45+
!llvm.ident = !{!5}
46+
47+
!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
48+
!1 = !DIFile(filename: "m.c", directory: ".")
49+
!2 = !{i32 7, !"Dwarf Version", i32 5}
50+
!3 = !{i32 2, !"Debug Info Version", i32 3}
51+
!4 = !{i32 1, !"wchar_size", i32 4}
52+
!5 = !{!"clang"}
53+
!14 = distinct !DISubprogram(name: "fn2", scope: !1, file: !1, line: 2, type: !15, scopeLine: 2, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !18)
54+
!15 = !DISubroutineType(types: !16)
55+
!16 = !{!17, !17, !17, !17}
56+
!17 = !DIBasicType(name: "long", size: 64, encoding: DW_ATE_signed)
57+
!18 = !{!19, !20, !21, !22}
58+
!19 = !DILocalVariable(name: "a", arg: 1, scope: !14, file: !1, line: 2, type: !17)
59+
!20 = !DILocalVariable(name: "b", arg: 2, scope: !14, file: !1, line: 2, type: !17)
60+
!21 = !DILocalVariable(name: "c", arg: 3, scope: !14, file: !1, line: 2, type: !17)
61+
!22 = !DILocalVariable(name: "local", scope: !14, file: !1, line: 3, type: !17)
62+
!23 = !DILocation(line: 0, scope: !14)
63+
!29 = !DILocation(line: 7, column: 1, scope: !14)
64+
!30 = !DISubprogram(name: "fn1", scope: !1, file: !1, line: 1, type: !15, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
65+

0 commit comments

Comments
 (0)