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