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// SPIR: i32 addrspace(5)* %arg 55// AMDGCN: i32 addrspace(1)* %arg 56void fd(__attribute__((opencl_global_device)) int *arg) {} 57 58// SPIR: i32 addrspace(6)* %arg 59// AMDGCN: i32 addrspace(1)* %arg 60void fh(__attribute__((opencl_global_host)) int *arg) {} 61 62#ifdef CL20 63int i; 64// CL20-DAG: @i = {{(dso_local )?}}addrspace(1) global i32 0 65int *ptr; 66// CL20SPIR-DAG: @ptr = {{(common )?}}{{(dso_local )?}}addrspace(1) global i32 addrspace(4)* null 67// CL20AMDGCN-DAG: @ptr = {{(dso_local )?}}addrspace(1) global i32* null 68#endif 69 70// SPIR: i32* %arg 71// AMDGCN: i32 addrspace(5)* %arg 72// CL20SPIR-DAG: i32 addrspace(4)* %arg 73// CL20AMDGCN-DAG: i32* %arg 74void f(int *arg) { 75 76 int i; 77// SPIR: %i = alloca i32, 78// AMDGCN: %i = alloca i32{{.*}}addrspace(5) 79// CL20SPIR-DAG: %i = alloca i32, 80// CL20AMDGCN-DAG: %i = alloca i32{{.*}}addrspace(5) 81 82#ifdef CL20 83 static int ii; 84// CL20-DAG: @f.ii = internal addrspace(1) global i32 0 85#endif 86} 87 88typedef int int_td; 89typedef int *intp_td; 90// SPIR: define {{(dso_local )?}}void @test_typedef(i32 addrspace(1)* %x, i32 addrspace(2)* %y, i32* %z) 91void test_typedef(global int_td *x, constant int_td *y, intp_td z) { 92 *x = *y; 93 *z = 0; 94} 95 96// SPIR: define {{(dso_local )?}}void @test_struct() 97void test_struct() { 98 // SPIR: %ps = alloca %struct.S* 99 // CL20SPIR: %ps = alloca %struct.S addrspace(4)* 100 struct S *ps; 101 // SPIR: store i32 0, i32* %x 102 // CL20SPIR: store i32 0, i32 addrspace(4)* %x 103 ps->x = 0; 104#ifdef CL20 105 // CL20SPIR: store i32 0, i32 addrspace(1)* getelementptr inbounds (%struct.S, %struct.S addrspace(1)* @g_s, i32 0, i32 0) 106 g_s.x = 0; 107#endif 108} 109 110// SPIR-LABEL: define {{(dso_local )?}}void @test_void_par() 111void test_void_par(void) {} 112 113// On ppc64 returns signext i32. 114// SPIR-LABEL: define{{.*}} i32 @test_func_return_type() 115int test_func_return_type(void) { 116 return 0; 117} 118 119#ifdef CL20 120extern float g_extern_var; 121 122// CL20-LABEL: define {{.*}}void @test_extern( 123kernel void test_extern(global float *buf) { 124 extern float l_extern_var; 125 buf[0] += g_extern_var + l_extern_var; 126} 127 128static float g_static_var; 129 130// CL20-LABEL: define {{.*}}void @test_static( 131kernel void test_static(global float *buf) { 132 static float l_static_var; 133 buf[0] += g_static_var + l_static_var; 134} 135 136#endif 137