1 ; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=SPIRV
3 ; SPIRV: OpCapability Linkage
4 ; SPIRV: OpEntryPoint Kernel %[[#kern:]] "kern"
6 @ae = available_externally addrspace(1) global i32 79, align 4
7 ; SPIRV-DAG: OpName %[[#ae:]] "ae"
9 @i1 = addrspace(1) global i32 1, align 4
10 ; SPIRV-DAG: OpName %[[#i1:]] "i1"
12 @i2 = internal addrspace(1) global i32 2, align 4
13 ; SPIRV-DAG: OpName %[[#i2:]] "i2"
15 @i3 = addrspace(1) global i32 3, align 4
16 ; SPIRV-DAG: OpName %[[#i3:]] "i3"
18 @i4 = common addrspace(1) global i32 0, align 4
19 ; SPIRV-DAG: OpName %[[#i4:]] "i4"
21 @i5 = internal addrspace(1) global i32 0, align 4
22 ; SPIRV-DAG: OpName %[[#i5:]] "i5"
24 @color_table = addrspace(2) constant [2 x i32] [i32 0, i32 1], align 4
25 ; SPIRV-DAG: OpName %[[#color_table:]] "color_table"
27 @noise_table = external addrspace(2) constant [256 x i32]
28 ; SPIRV-DAG: OpName %[[#noise_table:]] "noise_table"
30 @w = addrspace(1) constant i32 0, align 4
31 ; SPIRV-DAG: OpName %[[#w:]] "w"
33 @f.color_table = internal addrspace(2) constant [2 x i32] [i32 2, i32 3], align 4
34 ; SPIRV-DAG: OpName %[[#f_color_table:]] "f.color_table"
36 @e = external addrspace(1) global i32
37 ; SPIRV-DAG: OpName %[[#e:]] "e"
39 @f.t = internal addrspace(1) global i32 5, align 4
40 ; SPIRV-DAG: OpName %[[#f_t:]] "f.t"
42 @f.stint = internal addrspace(1) global i32 0, align 4
43 ; SPIRV-DAG: OpName %[[#f_stint:]] "f.stint"
45 @f.inside = internal addrspace(1) global i32 0, align 4
46 ; SPIRV-DAG: OpName %[[#f_inside:]] "f.inside"
48 @f.b = internal addrspace(2) constant float 1.000000e+00, align 4
49 ; SPIRV-DAG: OpName %[[#f_b:]] "f.b"
51 ; SPIRV-DAG: OpName %[[#foo:]] "foo"
52 ; SPIRV-DAG: OpName %[[#f:]] "f"
53 ; SPIRV-DAG: OpName %[[#g:]] "g"
54 ; SPIRV-DAG: OpName %[[#inline_fun:]] "inline_fun"
56 ; SPIRV-DAG: OpDecorate %[[#ae]] LinkageAttributes "ae" Import
57 ; SPIRV-DAG: OpDecorate %[[#e]] LinkageAttributes "e" Import
58 ; SPIRV-DAG: OpDecorate %[[#f]] LinkageAttributes "f" Export
59 ; SPIRV-DAG: OpDecorate %[[#w]] LinkageAttributes "w" Export
60 ; SPIRV-DAG: OpDecorate %[[#i1]] LinkageAttributes "i1" Export
61 ; SPIRV-DAG: OpDecorate %[[#i3]] LinkageAttributes "i3" Export
62 ; SPIRV-DAG: OpDecorate %[[#i4]] LinkageAttributes "i4" Export
63 ; SPIRV-DAG: OpDecorate %[[#foo]] LinkageAttributes "foo" Import
64 ; SPIRV-DAG: OpDecorate %[[#inline_fun]] LinkageAttributes "inline_fun" Export
65 ; SPIRV-DAG: OpDecorate %[[#color_table]] LinkageAttributes "color_table" Export
66 ; SPIRV-DAG: OpDecorate %[[#noise_table]] LinkageAttributes "noise_table" Import
68 ; SPIRV: %[[#foo]] = OpFunction %[[#]]
69 declare spir_func void @foo()
71 ; SPIRV: %[[#f]] = OpFunction %[[#]]
72 define spir_func void @f() {
74 %q = alloca i32, align 4
75 %r = alloca i32, align 4
76 %0 = load i32, i32 addrspace(1)* @i2, align 4
77 store i32 %0, i32* %q, align 4
78 %1 = load i32, i32 addrspace(1)* @i3, align 4
79 store i32 %1, i32 addrspace(1)* @i5, align 4
80 %2 = load i32, i32 addrspace(1)* @e, align 4
81 store i32 %2, i32* %r, align 4
82 %3 = load i32, i32 addrspace(2)* getelementptr inbounds ([256 x i32], [256 x i32] addrspace(2)* @noise_table, i32 0, i32 0), align 4
83 store i32 %3, i32* %r, align 4
84 %4 = load i32, i32 addrspace(2)* getelementptr inbounds ([2 x i32], [2 x i32] addrspace(2)* @f.color_table, i32 0, i32 0), align 4
85 store i32 %4, i32* %r, align 4
86 %call = call spir_func i32 @g()
87 call spir_func void @inline_fun()
91 ; SPIRV: %[[#g]] = OpFunction %[[#]]
92 define internal spir_func i32 @g() {
94 call spir_func void @foo()
98 ; SPIRV: %[[#inline_fun]] = OpFunction %[[#]]
99 ;; "linkonce_odr" is lost in translation !
100 define linkonce_odr spir_func void @inline_fun() {
102 %t = alloca i32 addrspace(1)*, align 4
103 store i32 addrspace(1)* @i1, i32 addrspace(1)** %t, align 4
107 ; SPIRV: %[[#kern]] = OpFunction %[[#]]
108 define spir_kernel void @kern() {
110 call spir_func void @f()