blob: 4b33d27003512ae5faa92575beafca246af24bbf [file] [log] [blame]
Artem Belevichdb4bc662016-08-02 20:58:24 +00001; Verify functionality of NVPTXGenericToNVVM.cpp pass.
2;
3; RUN: opt < %s -march nvptx64 -S -generic-to-nvvm -verify-debug-info | FileCheck %s
4
5target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"
6target triple = "nvptx64-nvidia-cuda"
7
8; Generic space variables should be converted to global space AKA addrspace(1).
9; CHECK-DAG: @static_var = {{.*}}addrspace(1)
10@static_var = externally_initialized global i8 0, align 1
11; CHECK-DAG: @.str = {{.*}}addrspace(1)
12@.str = private unnamed_addr constant [4 x i8] c"XXX\00", align 1
13
14; Function Attrs: convergent
15define void @func() !dbg !8 {
16;CHECK-LABEL: @func()
17;CHECK-SAME: !dbg [[FUNCNODE:![0-9]+]]
18entry:
19; References to the variables must be converted back to generic address space via llvm intrinsic call
20; CHECK-DAG: call i8* @llvm.nvvm.ptr.global.to.gen.p0i8.p1i8({{.*}} addrspace(1)* @.str
21 %0 = load i8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), align 1
22 call void @extfunc(i8 signext %0)
23; CHECK-DAG: call i8* @llvm.nvvm.ptr.global.to.gen.p0i8.p1i8(i8 addrspace(1)* @static_var
24 %1 = load i8, i8* @static_var, align 1
25 call void @extfunc(i8 signext %1)
26 ret void
27; CHECK: ret void
28}
29
30declare void @extfunc(i8 signext)
31
32!llvm.dbg.cu = !{!0}
33; CHECK: !llvm.dbg.cu = !{[[CUNODE:![0-9]+]]}
34!llvm.module.flags = !{!6, !7}
35
36!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1,
37 producer: "clang version 4.0.0",
38 isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3)
39; CHECK: [[CUNODE]] = distinct !DICompileUnit({{.*}} globals: [[GLOBALSNODE:![0-9]+]]
40!1 = !DIFile(filename: "foo.cu", directory: "/usr/local/google/home/tra/work/llvm/build/gpu/debug")
41!2 = !{}
42!3 = !{!4}
43; Find list of global variables and make sure it's the one used by DICompileUnit
44; CHECK: [[GLOBALSNODE]] = !{[[GVNODE:![0-9]+]]}
45!4 = distinct !DIGlobalVariable(name: "static_var", scope: !0, file: !1, line: 2, type: !5, isLocal: false,
46 isDefinition: true, variable: i8* @static_var)
47; Debug info must also be updated to reflect new address space.
48; CHECK: [[GVNODE]] = distinct !DIGlobalVariable(name: "static_var"
49; CHECK-SAME: scope: [[CUNODE]]
50; CHECK-SAME: type: [[TYPENODE:![0-9]+]]
51; CHECK-SAME: variable: i8* addrspacecast (i8 addrspace(1)* @static_var to i8*)
52!5 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)
53; CHECK: [[TYPENODE]] = !DIBasicType(name: "char"
54!6 = !{i32 2, !"Dwarf Version", i32 4}
55!7 = !{i32 2, !"Debug Info Version", i32 3}
56!8 = distinct !DISubprogram(name: "foo", linkageName: "func",
57 scope: !1, file: !1, line: 3, type: !9, isLocal: false, isDefinition: true, scopeLine: 3,
58 flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
59; CHECK: [[FUNCNODE]] = distinct !DISubprogram(name: "foo",
60; CHECK-SAME: type: [[STYPENODE:![0-9]+]]
61; CHECK-SAME: unit: [[CUNODE]],
62!9 = !DISubroutineType(types: !10)
63; CHECK: [[STYPENODE]] = !DISubroutineType
64!10 = !{null}