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