blob: 0f2448323a989930f0985b6ce50638a0b0a4c798 [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 Liuf5f45e52018-02-02 16:08:24 +00003// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa-opencl -emit-llvm -o - | FileCheck --check-prefixes=CHECK,GIZ %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,CL20GIZ
5// RUN: %clang_cc1 %s -O0 -triple amdgcn-mesa-mesa3d -emit-llvm -o - | FileCheck --check-prefixes=CHECK,GIZ %s
6// RUN: %clang_cc1 %s -O0 -triple r600-- -emit-llvm -o - | FileCheck --check-prefixes=CHECK,GIZ %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
27// GIZ: 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
Egor Churaev28f00aa2016-12-23 16:11:25 +000036// CHECK: i32 addrspace(2)* %arg
Anastasia Stulova784fb782015-11-23 11:14:44 +000037void f__c(__constant int *arg) {}
Peter Collingbourne599cb8e2011-03-18 22:38:29 +000038
Yaxun Liub34ec822017-04-11 17:24:23 +000039// SPIR: i32* %arg
40// GIZ: i32 addrspace(5)* %arg
Anastasia Stulova784fb782015-11-23 11:14:44 +000041void fp(private int *arg) {}
Peter Collingbourne599cb8e2011-03-18 22:38:29 +000042
Anastasia Stulova784fb782015-11-23 11:14:44 +000043// CHECK: i32 addrspace(1)* %arg
44void fg(global int *arg) {}
Peter Collingbourne599cb8e2011-03-18 22:38:29 +000045
Egor Churaev28f00aa2016-12-23 16:11:25 +000046// CHECK: i32 addrspace(3)* %arg
Anastasia Stulova784fb782015-11-23 11:14:44 +000047void fl(local int *arg) {}
Peter Collingbourne599cb8e2011-03-18 22:38:29 +000048
Egor Churaev28f00aa2016-12-23 16:11:25 +000049// CHECK: i32 addrspace(2)* %arg
Anastasia Stulova784fb782015-11-23 11:14:44 +000050void fc(constant int *arg) {}
Peter Collingbourne599cb8e2011-03-18 22:38:29 +000051
Anastasia Stulova784fb782015-11-23 11:14:44 +000052#ifdef CL20
53int i;
54// CL20-DAG: @i = common addrspace(1) global i32 0
55int *ptr;
Yaxun Liub34ec822017-04-11 17:24:23 +000056// CL20SPIR-DAG: @ptr = common addrspace(1) global i32 addrspace(4)* null
57// CL20GIZ-DAG: @ptr = common addrspace(1) global i32* null
Anastasia Stulova784fb782015-11-23 11:14:44 +000058#endif
Peter Collingbourne599cb8e2011-03-18 22:38:29 +000059
Yaxun Liub34ec822017-04-11 17:24:23 +000060// SPIR: i32* %arg
61// GIZ: i32 addrspace(5)* %arg
62// CL20SPIR-DAG: i32 addrspace(4)* %arg
63// CL20GIZ-DAG: i32* %arg
Anastasia Stulova784fb782015-11-23 11:14:44 +000064void f(int *arg) {
65
66 int i;
Yaxun Liub34ec822017-04-11 17:24:23 +000067// SPIR: %i = alloca i32,
68// GIZ: %i = alloca i32{{.*}}addrspace(5)
69// CL20SPIR-DAG: %i = alloca i32,
70// CL20GIZ-DAG: %i = alloca i32{{.*}}addrspace(5)
Anastasia Stulova784fb782015-11-23 11:14:44 +000071
72#ifdef CL20
73 static int ii;
74// CL20-DAG: @f.ii = internal addrspace(1) global i32 0
75#endif
76}
Yaxun Liub7318e02017-10-13 03:37:48 +000077
78typedef int int_td;
79typedef int *intp_td;
80// SPIR: define void @test_typedef(i32 addrspace(1)* %x, i32 addrspace(2)* %y, i32* %z)
81void test_typedef(global int_td *x, constant int_td *y, intp_td z) {
82 *x = *y;
83 *z = 0;
84}
85
86// SPIR: define void @test_struct()
87void test_struct() {
88 // SPIR: %ps = alloca %struct.S*
89 // CL20SPIR: %ps = alloca %struct.S addrspace(4)*
90 struct S *ps;
91 // SPIR: store i32 0, i32* %x
92 // CL20SPIR: store i32 0, i32 addrspace(4)* %x
93 ps->x = 0;
94#ifdef CL20
95 // CL20SPIR: store i32 0, i32 addrspace(1)* getelementptr inbounds (%struct.S, %struct.S addrspace(1)* @g_s, i32 0, i32 0)
96 g_s.x = 0;
97#endif
98}
99
100// SPIR-LABEL: define void @test_void_par()
101void test_void_par(void) {}
102
Yaxun Liud0292342017-10-13 13:53:06 +0000103// On ppc64 returns signext i32.
104// SPIR-LABEL: define{{.*}} i32 @test_func_return_type()
Yaxun Liub7318e02017-10-13 03:37:48 +0000105int test_func_return_type(void) {
106 return 0;
107}
108
109#ifdef CL20
110extern float g_extern_var;
111
112// CL20-LABEL: define {{.*}}void @test_extern(
113kernel void test_extern(global float *buf) {
114 extern float l_extern_var;
115 buf[0] += g_extern_var + l_extern_var;
116}
117
118static float g_static_var;
119
120// CL20-LABEL: define {{.*}}void @test_static(
121kernel void test_static(global float *buf) {
122 static float l_static_var;
123 buf[0] += g_static_var + l_static_var;
124}
125
126#endif