Skip to content

Commit 8958e70

Browse files
committed
[NVPTX] Keep metadata attached to module-scope variables
This helps to preserve the debug information of global variables. Differential Revision: https://reviews.llvm.org/D127510
1 parent 2c3a4a9 commit 8958e70

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ bool GenericToNVVM::runOnModule(Module &M) {
8383
GV.hasInitializer() ? GV.getInitializer() : nullptr, "", &GV,
8484
GV.getThreadLocalMode(), llvm::ADDRESS_SPACE_GLOBAL);
8585
NewGV->copyAttributesFrom(&GV);
86+
NewGV->copyMetadata(&GV, /*Offset=*/0);
8687
GVMap[&GV] = NewGV;
8788
}
8889
}

llvm/test/CodeGen/NVPTX/generic-to-nvvm-ir.ll

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"
66
target triple = "nvptx64-nvidia-cuda"
77

88
; Generic space variables should be converted to global space AKA addrspace(1).
9-
; CHECK-DAG: @static_var = {{.*}}addrspace(1)
9+
; The debug info reference should be preserved.
10+
; CHECK-DAG: @static_var = {{.*}}addrspace(1) {{.*}} !dbg !{{[0-9]+}}
1011
@static_var = externally_initialized global i8 0, align 1, !dbg !4
1112
; CHECK-DAG: @.str = {{.*}}addrspace(1)
1213
@.str = private unnamed_addr constant [4 x i8] c"XXX\00", align 1
@@ -36,18 +37,16 @@ declare void @extfunc(i8 signext)
3637
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1,
3738
producer: "clang version 4.0.0",
3839
isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3)
39-
; CHECK: [[CUNODE]] = distinct !DICompileUnit({{.*}} globals: [[GLOBALSNODE:![0-9]+]]
40+
; CHECK-DAG: [[CUNODE]] = distinct !DICompileUnit({{.*}} globals: [[GLOBALSNODE:![0-9]+]]
4041
!1 = !DIFile(filename: "foo.cu", directory: "/usr/local/google/home/tra/work/llvm/build/gpu/debug")
4142
!2 = !{}
4243
!3 = !{!4}
4344
; Find list of global variables and make sure it's the one used by DICompileUnit
44-
; CHECK: [[GLOBALSNODE]] = !{[[GVNODE:![0-9]+]]}
45+
; CHECK-DAG: [[GLOBALSNODE]] = !{[[GVNODE:![0-9]+]]}
4546
!4 = !DIGlobalVariableExpression(var: !DIGlobalVariable(name: "static_var", scope: !0, file: !1, line: 2, type: !5, isLocal: false, isDefinition: true), expr: !DIExpression())
46-
; Debug info must also be updated to reflect new address space.
47-
; CHECK: [[GVNODE]] = !DIGlobalVariableExpression(var: [[GVVAR:.*]], expr: !DIExpression())
48-
; CHECK: [[GVVAR]] = !DIGlobalVariable(name: "static_var"
49-
; CHECK-SAME: scope: [[CUNODE]]
50-
; CHECK-SAME: type: [[TYPENODE:![0-9]+]]
47+
; Debug info must be updated to reflect new address space.
48+
; CHECK-DAG: [[GVNODE]] = !DIGlobalVariableExpression(var: [[GVVAR:.*]], expr: !DIExpression())
49+
; CHECK-DAG: [[GVVAR]] = !DIGlobalVariable(name: "static_var", scope: [[CUNODE]],{{.*}} type: [[TYPENODE:![0-9]+]]
5150
!5 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)
5251
; CHECK: [[TYPENODE]] = !DIBasicType(name: "char"
5352
!6 = !{i32 2, !"Dwarf Version", i32 4}

0 commit comments

Comments
 (0)