blob: f4ddbc611c28d0fee5f05640ff96d292ca5efd0f [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
Yaxun Liuf8ad59d2018-02-15 19:12:41 +00003// 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
Peter Collingbourne599cb8e2011-03-18 22:38:29 +00007
Yaxun Liub7318e02017-10-13 03:37:48 +00008// SPIR: %struct.S = type { i32, i32, i32* }
9// CL20SPIR: %struct.S = type { i32, i32, i32 addrspace(4)* }
10struct S {
11 int x;
12 int y;
13 int *z;
14};
15
16// CL20-DAG: @g_extern_var = external addrspace(1) global float
17// CL20-DAG: @l_extern_var = external 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 addrspace(1) global %struct.S zeroinitializer
23struct S g_s;
24#endif
25
Yaxun Liub34ec822017-04-11 17:24:23 +000026// SPIR: i32* %arg
Yaxun Liuf8ad59d2018-02-15 19:12:41 +000027// AMDGCN: i32 addrspace(5)* %arg
Anastasia Stulova784fb782015-11-23 11:14:44 +000028void f__p(__private int *arg) {}
Peter Collingbourne599cb8e2011-03-18 22:38:29 +000029
Anastasia Stulova784fb782015-11-23 11:14:44 +000030// CHECK: i32 addrspace(1)* %arg
31void f__g(__global int *arg) {}
Peter Collingbourne599cb8e2011-03-18 22:38:29 +000032
Egor Churaev28f00aa2016-12-23 16:11:25 +000033// CHECK: i32 addrspace(3)* %arg
Anastasia Stulova784fb782015-11-23 11:14:44 +000034void f__l(__local int *arg) {}
Peter Collingbourne599cb8e2011-03-18 22:38:29 +000035
Yaxun Liu651bd732018-02-13 18:01:21 +000036// SPIR: i32 addrspace(2)* %arg
Yaxun Liuf8ad59d2018-02-15 19:12:41 +000037// AMDGCN: i32 addrspace(4)* %arg
Anastasia Stulova784fb782015-11-23 11:14:44 +000038void f__c(__constant int *arg) {}
Peter Collingbourne599cb8e2011-03-18 22:38:29 +000039
Yaxun Liub34ec822017-04-11 17:24:23 +000040// SPIR: i32* %arg
Yaxun Liuf8ad59d2018-02-15 19:12:41 +000041// AMDGCN: i32 addrspace(5)* %arg
Anastasia Stulova784fb782015-11-23 11:14:44 +000042void fp(private int *arg) {}
Peter Collingbourne599cb8e2011-03-18 22:38:29 +000043
Anastasia Stulova784fb782015-11-23 11:14:44 +000044// CHECK: i32 addrspace(1)* %arg
45void fg(global int *arg) {}
Peter Collingbourne599cb8e2011-03-18 22:38:29 +000046
Egor Churaev28f00aa2016-12-23 16:11:25 +000047// CHECK: i32 addrspace(3)* %arg
Anastasia Stulova784fb782015-11-23 11:14:44 +000048void fl(local int *arg) {}
Peter Collingbourne599cb8e2011-03-18 22:38:29 +000049
Yaxun Liu651bd732018-02-13 18:01:21 +000050// SPIR: i32 addrspace(2)* %arg
Yaxun Liuf8ad59d2018-02-15 19:12:41 +000051// AMDGCN: i32 addrspace(4)* %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
Yaxun Liuf8ad59d2018-02-15 19:12:41 +000059// CL20AMDGCN-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
Yaxun Liuf8ad59d2018-02-15 19:12:41 +000063// AMDGCN: i32 addrspace(5)* %arg
Yaxun Liub34ec822017-04-11 17:24:23 +000064// CL20SPIR-DAG: i32 addrspace(4)* %arg
Yaxun Liuf8ad59d2018-02-15 19:12:41 +000065// CL20AMDGCN-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,
Yaxun Liuf8ad59d2018-02-15 19:12:41 +000070// AMDGCN: %i = alloca i32{{.*}}addrspace(5)
Yaxun Liub34ec822017-04-11 17:24:23 +000071// CL20SPIR-DAG: %i = alloca i32,
Yaxun Liuf8ad59d2018-02-15 19:12:41 +000072// CL20AMDGCN-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