blob: cb641f593711689eb2191f9bc3d4740ccf9a0613 [file] [log] [blame]
Yaxun Liub34ec822017-04-11 17:24:23 +00001// 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-opencl -emit-llvm -o - | FileCheck --check-prefixes=CHECK,SPIR %s
4// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa-opencl -DCL20 -cl-std=CL2.0 -emit-llvm -o - | FileCheck %s --check-prefixes=CL20,CL20SPIR
5// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa-amdgizcl -emit-llvm -o - | FileCheck %s -check-prefixes=CHECK,GIZ
6// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa-amdgizcl -DCL20 -cl-std=CL2.0 -emit-llvm -o - | FileCheck %s --check-prefixes=CL20,CL20GIZ
Yaxun Liu3ba4a722017-07-04 19:57:18 +00007// RUN: %clang_cc1 %s -O0 -triple amdgcn-mesa-mesa3d -emit-llvm -o - | FileCheck --check-prefixes=CHECK,SPIR %s
8// RUN: %clang_cc1 %s -O0 -triple r600-- -emit-llvm -o - | FileCheck --check-prefixes=CHECK,SPIR %s
Peter Collingbourne599cb8e2011-03-18 22:38:29 +00009
Yaxun Liub7318e02017-10-13 03:37:48 +000010// SPIR: %struct.S = type { i32, i32, i32* }
11// CL20SPIR: %struct.S = type { i32, i32, i32 addrspace(4)* }
12struct S {
13 int x;
14 int y;
15 int *z;
16};
17
18// CL20-DAG: @g_extern_var = external addrspace(1) global float
19// CL20-DAG: @l_extern_var = external addrspace(1) global float
20// CL20-DAG: @test_static.l_static_var = internal addrspace(1) global float 0.000000e+00
21// CL20-DAG: @g_static_var = internal addrspace(1) global float 0.000000e+00
22
23#ifdef CL20
24// CL20-DAG: @g_s = common addrspace(1) global %struct.S zeroinitializer
25struct S g_s;
26#endif
27
Yaxun Liub34ec822017-04-11 17:24:23 +000028// SPIR: i32* %arg
29// GIZ: i32 addrspace(5)* %arg
Anastasia Stulova784fb782015-11-23 11:14:44 +000030void f__p(__private int *arg) {}
Peter Collingbourne599cb8e2011-03-18 22:38:29 +000031
Anastasia Stulova784fb782015-11-23 11:14:44 +000032// CHECK: i32 addrspace(1)* %arg
33void f__g(__global int *arg) {}
Peter Collingbourne599cb8e2011-03-18 22:38:29 +000034
Egor Churaev28f00aa2016-12-23 16:11:25 +000035// CHECK: i32 addrspace(3)* %arg
Anastasia Stulova784fb782015-11-23 11:14:44 +000036void f__l(__local int *arg) {}
Peter Collingbourne599cb8e2011-03-18 22:38:29 +000037
Egor Churaev28f00aa2016-12-23 16:11:25 +000038// CHECK: i32 addrspace(2)* %arg
Anastasia Stulova784fb782015-11-23 11:14:44 +000039void f__c(__constant int *arg) {}
Peter Collingbourne599cb8e2011-03-18 22:38:29 +000040
Yaxun Liub34ec822017-04-11 17:24:23 +000041// SPIR: i32* %arg
42// GIZ: i32 addrspace(5)* %arg
Anastasia Stulova784fb782015-11-23 11:14:44 +000043void fp(private int *arg) {}
Peter Collingbourne599cb8e2011-03-18 22:38:29 +000044
Anastasia Stulova784fb782015-11-23 11:14:44 +000045// CHECK: i32 addrspace(1)* %arg
46void fg(global int *arg) {}
Peter Collingbourne599cb8e2011-03-18 22:38:29 +000047
Egor Churaev28f00aa2016-12-23 16:11:25 +000048// CHECK: i32 addrspace(3)* %arg
Anastasia Stulova784fb782015-11-23 11:14:44 +000049void fl(local int *arg) {}
Peter Collingbourne599cb8e2011-03-18 22:38:29 +000050
Egor Churaev28f00aa2016-12-23 16:11:25 +000051// CHECK: i32 addrspace(2)* %arg
Anastasia Stulova784fb782015-11-23 11:14:44 +000052void fc(constant int *arg) {}
Peter Collingbourne599cb8e2011-03-18 22:38:29 +000053
Anastasia Stulova784fb782015-11-23 11:14:44 +000054#ifdef CL20
55int i;
56// CL20-DAG: @i = common addrspace(1) global i32 0
57int *ptr;
Yaxun Liub34ec822017-04-11 17:24:23 +000058// CL20SPIR-DAG: @ptr = common addrspace(1) global i32 addrspace(4)* null
59// CL20GIZ-DAG: @ptr = common addrspace(1) global i32* null
Anastasia Stulova784fb782015-11-23 11:14:44 +000060#endif
Peter Collingbourne599cb8e2011-03-18 22:38:29 +000061
Yaxun Liub34ec822017-04-11 17:24:23 +000062// SPIR: i32* %arg
63// GIZ: i32 addrspace(5)* %arg
64// CL20SPIR-DAG: i32 addrspace(4)* %arg
65// CL20GIZ-DAG: i32* %arg
Anastasia Stulova784fb782015-11-23 11:14:44 +000066void f(int *arg) {
67
68 int i;
Yaxun Liub34ec822017-04-11 17:24:23 +000069// SPIR: %i = alloca i32,
70// GIZ: %i = alloca i32{{.*}}addrspace(5)
71// CL20SPIR-DAG: %i = alloca i32,
72// CL20GIZ-DAG: %i = alloca i32{{.*}}addrspace(5)
Anastasia Stulova784fb782015-11-23 11:14:44 +000073
74#ifdef CL20
75 static int ii;
76// CL20-DAG: @f.ii = internal addrspace(1) global i32 0
77#endif
78}
Yaxun Liub7318e02017-10-13 03:37:48 +000079
80typedef int int_td;
81typedef int *intp_td;
82// SPIR: define void @test_typedef(i32 addrspace(1)* %x, i32 addrspace(2)* %y, i32* %z)
83void test_typedef(global int_td *x, constant int_td *y, intp_td z) {
84 *x = *y;
85 *z = 0;
86}
87
88// SPIR: define void @test_struct()
89void 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 void @test_void_par()
103void test_void_par(void) {}
104
Yaxun Liud0292342017-10-13 13:53:06 +0000105// On ppc64 returns signext i32.
106// SPIR-LABEL: define{{.*}} i32 @test_func_return_type()
Yaxun Liub7318e02017-10-13 03:37:48 +0000107int test_func_return_type(void) {
108 return 0;
109}
110
111#ifdef CL20
112extern float g_extern_var;
113
114// CL20-LABEL: define {{.*}}void @test_extern(
115kernel void test_extern(global float *buf) {
116 extern float l_extern_var;
117 buf[0] += g_extern_var + l_extern_var;
118}
119
120static float g_static_var;
121
122// CL20-LABEL: define {{.*}}void @test_static(
123kernel 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