Skip to content

Commit 6c88f4d

Browse files
committed
[SelectionDAG] Add debug info salvaging for bitcast operations
This is needed to retain debug info for 64 bit kernel parameters. Change-Id: Id3914345ef7a434355f36e45d3ea0bf6c7ae29aa
1 parent 692facd commit 6c88f4d

File tree

3 files changed

+131
-1
lines changed

3 files changed

+131
-1
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15821,8 +15821,10 @@ SDValue DAGCombiner::visitBITCAST(SDNode *N) {
1582115821
}
1582215822

1582315823
// (conv (conv x, t1), t2) -> (conv x, t2)
15824-
if (N0.getOpcode() == ISD::BITCAST)
15824+
if (N0.getOpcode() == ISD::BITCAST) {
15825+
DAG.salvageDebugInfo(*N0.getNode());
1582515826
return DAG.getBitcast(VT, N0.getOperand(0));
15827+
}
1582615828

1582715829
// fold (conv (logicop (conv x), (c))) -> (logicop x, (conv c))
1582815830
// iff the current bitwise logicop type isn't legal

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11577,6 +11577,35 @@ void SelectionDAG::salvageDebugInfo(SDNode &N) {
1157711577
dbgs() << " into " << *DbgExpression << '\n');
1157811578
break;
1157911579
}
11580+
case ISD::BITCAST: {
11581+
DIExpression *Expr = DV->getExpression();
11582+
if (Expr->holdsOldElements())
11583+
break;
11584+
11585+
SDValue N0 = N.getOperand(0);
11586+
auto NewLocOps = DV->copyLocationOps();
11587+
bool Changed = false;
11588+
for (size_t i = 0; i < NewLocOps.size(); ++i) {
11589+
if (NewLocOps[i].getKind() != SDDbgOperand::SDNODE ||
11590+
NewLocOps[i].getSDNode() != &N)
11591+
continue;
11592+
NewLocOps[i] = SDDbgOperand::fromNode(N0.getNode(), N0.getResNo());
11593+
Changed = true;
11594+
}
11595+
assert(Changed && "Salvage target doesn't use N");
11596+
(void)Changed;
11597+
11598+
SDDbgValue *Clone =
11599+
getDbgValueList(DV->getVariable(), Expr, NewLocOps,
11600+
DV->getAdditionalDependencies(), DV->isIndirect(),
11601+
DV->getDebugLoc(), DV->getOrder(), DV->isVariadic());
11602+
ClonedDVs.push_back(Clone);
11603+
DV->setIsInvalidated();
11604+
DV->setIsEmitted();
11605+
LLVM_DEBUG(dbgs() << "SALVAGE: Rewriting"; N0.getNode()->dumprFull(this);
11606+
dbgs() << " into " << *Expr << '\n');
11607+
break;
11608+
}
1158011609
}
1158111610
}
1158211611

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
; RUN: llc -O1 -mcpu=gfx1030 -mtriple=amdgcn-amd-amdhsa -filetype=obj -o - < %s | llvm-dwarfdump --debug-info - | FileCheck %s
2+
3+
;; Verify that we produce valid debug locations for parameters of various types.
4+
5+
@glob_ptr = global ptr addrspace(1) null
6+
7+
; CHECK-LABEL: DW_AT_name ("int32_k")
8+
define amdgpu_kernel void @int32_k(i32 %a) !dbg !9 {
9+
; CHECK: DW_AT_location
10+
; CHECK-NEXT: [0x{{[0-9a-z]+}}, 0x{{[0-9a-z]+}}): DW_OP_regx SGPR{{[0-9]+}})
11+
tail call void @llvm.dbg.value(metadata i32 %a, metadata !12, metadata !DIExpression(DIOpArg(0, i32))), !dbg !14
12+
store i32 %a, ptr @glob_ptr, align 4, !dbg !14
13+
ret void, !dbg !15
14+
}
15+
16+
; CHECK-LABEL: DW_AT_name ("int64_k")
17+
define amdgpu_kernel void @int64_k(i64 %a) !dbg !31 {
18+
; CHECK: DW_AT_location
19+
; CHECK-NEXT: DW_OP_regx SGPR{{[0-9a-z]+}}, DW_OP_piece 0x4, DW_OP_regx SGPR{{[0-9a-z]+}}, DW_OP_piece 0x4, DW_OP_LLVM_user DW_OP_LLVM_piece_end
20+
tail call void @llvm.dbg.value(metadata i64 %a, metadata !32, metadata !DIExpression(DIOpArg(0, i64))), !dbg !33
21+
store i64 %a, ptr @glob_ptr, align 8, !dbg !33
22+
ret void, !dbg !33
23+
}
24+
25+
; CHECK-LABEL: DW_AT_name ("as1_ptr")
26+
define void @as1_ptr(ptr addrspace(1) %ptr) !dbg !16 {
27+
; CHECK: DW_AT_location
28+
; CHECK-NEXT: [0x{{[0-9a-z]+}}, 0x{{[0-9a-z]+}}): DW_OP_regx 0x{{[0-9a-z]+}}, DW_OP_piece 0x4, DW_OP_regx 0x{{[0-9a-z]+}}, DW_OP_piece 0x4)
29+
tail call void @llvm.dbg.value(metadata ptr addrspace(1) %ptr, metadata !17, metadata !DIExpression(DIOpArg(0, ptr addrspace(1)))), !dbg !20
30+
store ptr addrspace(1) %ptr, ptr @glob_ptr, align 8, !dbg !20
31+
ret void, !dbg !20
32+
}
33+
34+
; CHECK-LABEL: DW_AT_name ("int64")
35+
define void @int64(i64 %a) !dbg !21 {
36+
; CHECK: DW_AT_location
37+
; CHECK-NEXT: [0x{{[0-9a-z]+}}, 0x{{[0-9a-z]+}}): DW_OP_regx 0x{{[0-9a-z]+}}, DW_OP_piece 0x4, DW_OP_regx 0x{{[0-9a-z]+}}, DW_OP_piece 0x4)
38+
tail call void @llvm.dbg.value(metadata i64 %a, metadata !22, metadata !DIExpression(DIOpArg(0, i64))), !dbg !23
39+
store i64 %a, ptr @glob_ptr, align 8, !dbg !23
40+
ret void, !dbg !24
41+
}
42+
43+
; CHECK-LABEL: DW_AT_name ("int32")
44+
define void @int32(i32 %a) !dbg !25 {
45+
; CHECK: DW_AT_location (DW_OP_regx 0x{{[0-9a-z]+}})
46+
tail call void @llvm.dbg.value(metadata i32 %a, metadata !26, metadata !DIExpression(DIOpArg(0, i32))), !dbg !27
47+
store i32 %a, ptr @glob_ptr, align 4, !dbg !27
48+
ret void, !dbg !27
49+
}
50+
51+
; CHECK-LABEL: DW_AT_name ("gen_ptr")
52+
define void @gen_ptr(ptr %ptr) !dbg !28 {
53+
; CHECK: DW_AT_location
54+
; CHECK-NEXT: [0x{{[0-9a-z]+}}, 0x{{[0-9a-z]+}}): DW_OP_regx 0x{{[0-9a-z]+}}, DW_OP_piece 0x4, DW_OP_regx 0x{{[0-9a-z]+}}, DW_OP_piece 0x4)
55+
tail call void @llvm.dbg.value(metadata ptr %ptr, metadata !29, metadata !DIExpression(DIOpArg(0, ptr))), !dbg !30
56+
store ptr %ptr, ptr @glob_ptr, align 8, !dbg !30
57+
ret void, !dbg !30
58+
}
59+
60+
declare void @llvm.dbg.value(metadata, metadata, metadata)
61+
62+
!llvm.dbg.cu = !{!0}
63+
!llvm.module.flags = !{!2, !3, !4, !5, !6, !7}
64+
!llvm.ident = !{!8}
65+
66+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 19.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
67+
!1 = !DIFile(filename: "t.cpp", directory: "/")
68+
!2 = !{i32 1, !"amdhsa_code_object_version", i32 500}
69+
!3 = !{i32 7, !"Dwarf Version", i32 5}
70+
!4 = !{i32 2, !"Debug Info Version", i32 3}
71+
!5 = !{i32 1, !"wchar_size", i32 4}
72+
!6 = !{i32 8, !"PIC Level", i32 2}
73+
!7 = !{i32 7, !"frame-pointer", i32 2}
74+
!8 = !{!"clang version 19.0.0"}
75+
!9 = distinct !DISubprogram(name: "int32_k", linkageName: "int32_k", scope: !1, file: !1, line: 1, type: !10, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
76+
!10 = !DISubroutineType(types: !11)
77+
!11 = !{}
78+
!12 = !DILocalVariable(name: "i32", arg: 1, scope: !9, file: !1, type: !13)
79+
!13 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed)
80+
!14 = !DILocation(line: 1, column: 1, scope: !9)
81+
!15 = !DILocation(line: 2, column: 1, scope: !9)
82+
!16 = distinct !DISubprogram(name: "as1_ptr", linkageName: "as1_ptr", scope: !1, file: !1, line: 1, type: !10, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
83+
!17 = !DILocalVariable(name: "ptr", arg: 1, scope: !16, file: !1, line: 1, type: !18)
84+
!18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64)
85+
!19 = !DIBasicType(name: "i64", size: 64, encoding: DW_ATE_signed)
86+
!20 = !DILocation(line: 1, column: 1, scope: !16)
87+
!21 = distinct !DISubprogram(name: "int64", linkageName: "int64", scope: !1, file: !1, line: 1, type: !10, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
88+
!22 = !DILocalVariable(name: "i64", arg: 1, scope: !21, file: !1, type: !19)
89+
!23 = !DILocation(line: 1, column: 1, scope: !21)
90+
!24 = !DILocation(line: 2, column: 1, scope: !21)
91+
!25 = distinct !DISubprogram(name: "int32", linkageName: "int32", scope: !1, file: !1, line: 1, type: !10, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
92+
!26 = !DILocalVariable(name: "i32", arg: 1, scope: !25, file: !1, type: !13)
93+
!27 = !DILocation(line: 1, column: 1, scope: !25)
94+
!28 = distinct !DISubprogram(name: "gen_ptr", linkageName: "gen_ptr", scope: !1, file: !1, line: 1, type: !10, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
95+
!29 = !DILocalVariable(name: "ptr", arg: 1, scope: !28, file: !1, type: !18)
96+
!30 = !DILocation(line: 1, column: 1, scope: !28)
97+
!31 = distinct !DISubprogram(name: "int64_k", linkageName: "int64_k", scope: !1, file: !1, line: 1, type: !10, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
98+
!32 = !DILocalVariable(name: "i32", arg: 1, scope: !31, file: !1, type: !19)
99+
!33 = !DILocation(line: 1, column: 1, scope: !31)

0 commit comments

Comments
 (0)