[llvm] 8958e70 - [NVPTX] Keep metadata attached to module-scope variables

Igor Kudrin via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 22 05:51:40 PDT 2022


Author: Igor Kudrin
Date: 2022-06-22T05:51:29-07:00
New Revision: 8958e70ccbe9c12b2d0b622b8b5623a8f47bb183

URL: https://github.com/llvm/llvm-project/commit/8958e70ccbe9c12b2d0b622b8b5623a8f47bb183
DIFF: https://github.com/llvm/llvm-project/commit/8958e70ccbe9c12b2d0b622b8b5623a8f47bb183.diff

LOG: [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

Added: 
    

Modified: 
    llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp
    llvm/test/CodeGen/NVPTX/generic-to-nvvm-ir.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp b/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp
index 44afdb8d8ec1b..f1829c29a2bf8 100644
--- a/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp
@@ -83,6 +83,7 @@ bool GenericToNVVM::runOnModule(Module &M) {
           GV.hasInitializer() ? GV.getInitializer() : nullptr, "", &GV,
           GV.getThreadLocalMode(), llvm::ADDRESS_SPACE_GLOBAL);
       NewGV->copyAttributesFrom(&GV);
+      NewGV->copyMetadata(&GV, /*Offset=*/0);
       GVMap[&GV] = NewGV;
     }
   }

diff  --git a/llvm/test/CodeGen/NVPTX/generic-to-nvvm-ir.ll b/llvm/test/CodeGen/NVPTX/generic-to-nvvm-ir.ll
index 1239f351ba390..d75b02d97fe7b 100644
--- a/llvm/test/CodeGen/NVPTX/generic-to-nvvm-ir.ll
+++ b/llvm/test/CodeGen/NVPTX/generic-to-nvvm-ir.ll
@@ -6,7 +6,8 @@ target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"
 target triple = "nvptx64-nvidia-cuda"
 
 ; Generic space variables should be converted to global space AKA addrspace(1).
-; CHECK-DAG: @static_var = {{.*}}addrspace(1)
+; The debug info reference should be preserved.
+; CHECK-DAG: @static_var = {{.*}}addrspace(1) {{.*}} !dbg !{{[0-9]+}}
 @static_var = externally_initialized global i8 0, align 1, !dbg !4
 ; CHECK-DAG: @.str = {{.*}}addrspace(1)
 @.str = private unnamed_addr constant [4 x i8] c"XXX\00", align 1
@@ -36,18 +37,16 @@ declare void @extfunc(i8 signext)
 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1,
       producer: "clang version 4.0.0",
       isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3)
-; CHECK: [[CUNODE]] = distinct !DICompileUnit({{.*}} globals: [[GLOBALSNODE:![0-9]+]]
+; CHECK-DAG: [[CUNODE]] = distinct !DICompileUnit({{.*}} globals: [[GLOBALSNODE:![0-9]+]]
 !1 = !DIFile(filename: "foo.cu", directory: "/usr/local/google/home/tra/work/llvm/build/gpu/debug")
 !2 = !{}
 !3 = !{!4}
 ; Find list of global variables and make sure it's the one used by DICompileUnit
-; CHECK: [[GLOBALSNODE]] = !{[[GVNODE:![0-9]+]]}
+; CHECK-DAG: [[GLOBALSNODE]] = !{[[GVNODE:![0-9]+]]}
 !4 = !DIGlobalVariableExpression(var: !DIGlobalVariable(name: "static_var", scope: !0, file: !1, line: 2, type: !5, isLocal: false, isDefinition: true), expr: !DIExpression())
-; Debug info must also be updated to reflect new address space.
-; CHECK: [[GVNODE]] = !DIGlobalVariableExpression(var: [[GVVAR:.*]], expr: !DIExpression())
-; CHECK: [[GVVAR]] = !DIGlobalVariable(name: "static_var"
-; CHECK-SAME: scope: [[CUNODE]]
-; CHECK-SAME: type: [[TYPENODE:![0-9]+]]
+; Debug info must be updated to reflect new address space.
+; CHECK-DAG: [[GVNODE]] = !DIGlobalVariableExpression(var: [[GVVAR:.*]], expr: !DIExpression())
+; CHECK-DAG: [[GVVAR]] = !DIGlobalVariable(name: "static_var", scope: [[CUNODE]],{{.*}} type: [[TYPENODE:![0-9]+]]
 !5 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)
 ; CHECK: [[TYPENODE]] = !DIBasicType(name: "char"
 !6 = !{i32 2, !"Dwarf Version", i32 4}


        


More information about the llvm-commits mailing list