Clang Project

clang_source_code/test/CodeGenOpenCL/address-spaces.cl
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)* }
10struct 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
23struct S g_s;
24#endif
25
26// SPIR: i32* %arg
27// AMDGCN: i32 addrspace(5)* %arg
28void f__p(__private int *arg) {}
29
30// CHECK: i32 addrspace(1)* %arg
31void f__g(__global int *arg) {}
32
33// CHECK: i32 addrspace(3)* %arg
34void f__l(__local int *arg) {}
35
36// SPIR: i32 addrspace(2)* %arg
37// AMDGCN: i32 addrspace(4)* %arg
38void f__c(__constant int *arg) {}
39
40// SPIR: i32* %arg
41// AMDGCN: i32 addrspace(5)* %arg
42void fp(private int *arg) {}
43
44// CHECK: i32 addrspace(1)* %arg
45void fg(global int *arg) {}
46
47// CHECK: i32 addrspace(3)* %arg
48void fl(local int *arg) {}
49
50// SPIR: i32 addrspace(2)* %arg
51// AMDGCN: i32 addrspace(4)* %arg
52void fc(constant int *arg) {}
53
54#ifdef CL20
55int i;
56// CL20-DAG: @i = common {{(dso_local )?}}addrspace(1) global i32 0
57int *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
66void 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
80typedef int int_td;
81typedef int *intp_td;
82// SPIR: define {{(dso_local )?}}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 {{(dso_local )?}}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 {{(dso_local )?}}void @test_void_par()
103void test_void_par(void) {}
104
105// On ppc64 returns signext i32.
106// SPIR-LABEL: define{{.*}} i32 @test_func_return_type()
107int 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
129