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