1 | // RUN: %clang_cc1 %s -O0 -ffake-address-space-map -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,SPIR |
2 | // RUN: %clang_cc1 %s -O0 -DCL20 -cl-std=CL2.0 -ffake-address-space-map -emit-llvm -o - | FileCheck %s --check-prefixes=CL20,CL20SPIR |
3 | // RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -emit-llvm -o - | FileCheck --check-prefixes=CHECK,AMDGCN %s |
4 | // RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -DCL20 -cl-std=CL2.0 -emit-llvm -o - | FileCheck %s --check-prefixes=CL20,CL20AMDGCN |
5 | // RUN: %clang_cc1 %s -O0 -triple amdgcn-mesa-mesa3d -emit-llvm -o - | FileCheck --check-prefixes=CHECK,AMDGCN %s |
6 | // RUN: %clang_cc1 %s -O0 -triple r600-- -emit-llvm -o - | FileCheck --check-prefixes=CHECK,AMDGCN %s |
7 | |
8 | // SPIR: %struct.S = type { i32, i32, i32* } |
9 | // CL20SPIR: %struct.S = type { i32, i32, i32 addrspace(4)* } |
10 | struct S { |
11 | int x; |
12 | int y; |
13 | int *z; |
14 | }; |
15 | |
16 | // CL20-DAG: @g_extern_var = external {{(dso_local )?}}addrspace(1) global float |
17 | // CL20-DAG: @l_extern_var = external {{(dso_local )?}}addrspace(1) global float |
18 | // CL20-DAG: @test_static.l_static_var = internal addrspace(1) global float 0.000000e+00 |
19 | // CL20-DAG: @g_static_var = internal addrspace(1) global float 0.000000e+00 |
20 | |
21 | #ifdef CL20 |
22 | // CL20-DAG: @g_s = {{(common )?}}{{(dso_local )?}}addrspace(1) global %struct.S zeroinitializer |
23 | struct S g_s; |
24 | #endif |
25 | |
26 | // SPIR: i32* %arg |
27 | // AMDGCN: i32 addrspace(5)* %arg |
28 | void f__p(__private int *arg) {} |
29 | |
30 | // CHECK: i32 addrspace(1)* %arg |
31 | void f__g(__global int *arg) {} |
32 | |
33 | // CHECK: i32 addrspace(3)* %arg |
34 | void f__l(__local int *arg) {} |
35 | |
36 | // SPIR: i32 addrspace(2)* %arg |
37 | // AMDGCN: i32 addrspace(4)* %arg |
38 | void f__c(__constant int *arg) {} |
39 | |
40 | // SPIR: i32* %arg |
41 | // AMDGCN: i32 addrspace(5)* %arg |
42 | void fp(private int *arg) {} |
43 | |
44 | // CHECK: i32 addrspace(1)* %arg |
45 | void fg(global int *arg) {} |
46 | |
47 | // CHECK: i32 addrspace(3)* %arg |
48 | void fl(local int *arg) {} |
49 | |
50 | // SPIR: i32 addrspace(2)* %arg |
51 | // AMDGCN: i32 addrspace(4)* %arg |
52 | void fc(constant int *arg) {} |
53 | |
54 | #ifdef CL20 |
55 | int i; |
56 | // CL20-DAG: @i = common {{(dso_local )?}}addrspace(1) global i32 0 |
57 | int *ptr; |
58 | // CL20SPIR-DAG: @ptr = {{(common )?}}{{(dso_local )?}}addrspace(1) global i32 addrspace(4)* null |
59 | // CL20AMDGCN-DAG: @ptr = common {{(dso_local )?}}addrspace(1) global i32* null |
60 | #endif |
61 | |
62 | // SPIR: i32* %arg |
63 | // AMDGCN: i32 addrspace(5)* %arg |
64 | // CL20SPIR-DAG: i32 addrspace(4)* %arg |
65 | // CL20AMDGCN-DAG: i32* %arg |
66 | void f(int *arg) { |
67 | |
68 | int i; |
69 | // SPIR: %i = alloca i32, |
70 | // AMDGCN: %i = alloca i32{{.*}}addrspace(5) |
71 | // CL20SPIR-DAG: %i = alloca i32, |
72 | // CL20AMDGCN-DAG: %i = alloca i32{{.*}}addrspace(5) |
73 | |
74 | #ifdef CL20 |
75 | static int ii; |
76 | // CL20-DAG: @f.ii = internal addrspace(1) global i32 0 |
77 | #endif |
78 | } |
79 | |
80 | typedef int int_td; |
81 | typedef int *intp_td; |
82 | // SPIR: define {{(dso_local )?}}void @test_typedef(i32 addrspace(1)* %x, i32 addrspace(2)* %y, i32* %z) |
83 | void test_typedef(global int_td *x, constant int_td *y, intp_td z) { |
84 | *x = *y; |
85 | *z = 0; |
86 | } |
87 | |
88 | // SPIR: define {{(dso_local )?}}void @test_struct() |
89 | void test_struct() { |
90 | // SPIR: %ps = alloca %struct.S* |
91 | // CL20SPIR: %ps = alloca %struct.S addrspace(4)* |
92 | struct S *ps; |
93 | // SPIR: store i32 0, i32* %x |
94 | // CL20SPIR: store i32 0, i32 addrspace(4)* %x |
95 | ps->x = 0; |
96 | #ifdef CL20 |
97 | // CL20SPIR: store i32 0, i32 addrspace(1)* getelementptr inbounds (%struct.S, %struct.S addrspace(1)* @g_s, i32 0, i32 0) |
98 | g_s.x = 0; |
99 | #endif |
100 | } |
101 | |
102 | // SPIR-LABEL: define {{(dso_local )?}}void @test_void_par() |
103 | void test_void_par(void) {} |
104 | |
105 | // On ppc64 returns signext i32. |
106 | // SPIR-LABEL: define{{.*}} i32 @test_func_return_type() |
107 | int test_func_return_type(void) { |
108 | return 0; |
109 | } |
110 | |
111 | #ifdef CL20 |
112 | extern float g_extern_var; |
113 | |
114 | // CL20-LABEL: define {{.*}}void @test_extern( |
115 | kernel void test_extern(global float *buf) { |
116 | extern float l_extern_var; |
117 | buf[0] += g_extern_var + l_extern_var; |
118 | } |
119 | |
120 | static float g_static_var; |
121 | |
122 | // CL20-LABEL: define {{.*}}void @test_static( |
123 | kernel void test_static(global float *buf) { |
124 | static float l_static_var; |
125 | buf[0] += g_static_var + l_static_var; |
126 | } |
127 | |
128 | #endif |
129 | |