142 lines · plain
1// RUN: %clang_cc1 %s -O0 -ffake-address-space-map -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,SPIR2// RUN: %clang_cc1 %s -O0 -cl-std=CL3.0 -cl-ext=-all -ffake-address-space-map -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,SPIR3// RUN: %clang_cc1 %s -O0 -cl-std=clc++2021 -cl-ext=-all -ffake-address-space-map -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,SPIR4// RUN: %clang_cc1 %s -O0 -DCL20 -cl-std=CL2.0 -ffake-address-space-map -emit-llvm -o - | FileCheck %s --check-prefixes=CL20,CL20SPIR5// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -emit-llvm -o - | FileCheck --check-prefixes=CHECK,AMDGCN %s6// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL3.0 -emit-llvm -o - | FileCheck --check-prefixes=CHECK,AMDGCN %s7// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -DCL20 -cl-std=CL2.0 -emit-llvm -o - | FileCheck %s --check-prefixes=CL20,CL20AMDGCN8// RUN: %clang_cc1 %s -O0 -triple amdgcn-mesa-mesa3d -emit-llvm -o - | FileCheck --check-prefixes=CHECK,AMDGCN %s9// RUN: %clang_cc1 %s -O0 -triple amdgcn-mesa-mesa3d -cl-std=CL3.0 -emit-llvm -o - | FileCheck --check-prefixes=CHECK,AMDGCN %s10// RUN: %clang_cc1 %s -O0 -triple r600-- -emit-llvm -o - | FileCheck --check-prefixes=CHECK,AMDGCN %s11// RUN: %clang_cc1 %s -O0 -triple r600-- -emit-llvm -cl-std=CL3.0 -o - | FileCheck --check-prefixes=CHECK,AMDGCN %s12 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 float22// CL20-DAG: @l_extern_var = external {{(dso_local )?}}addrspace(1) global float23// CL20-DAG: @test_static.l_static_var = internal addrspace(1) global float 0.000000e+0024// CL20-DAG: @g_static_var = internal addrspace(1) global float 0.000000e+0025 26#ifdef CL2027// CL20-DAG: @g_s = {{(common )?}}{{(dso_local )?}}addrspace(1) global %struct.S zeroinitializer28struct S g_s;29#endif30 31// SPIR: ptr %arg32// AMDGCN: ptr addrspace(5) %arg33void f__p(__private int *arg) {}34 35// CHECK: ptr addrspace(1) %arg36void f__g(__global int *arg) {}37 38// CHECK: ptr addrspace(3) %arg39void f__l(__local int *arg) {}40 41// SPIR: ptr addrspace(2) %arg42// AMDGCN: ptr addrspace(4) %arg43void f__c(__constant int *arg) {}44 45// SPIR: ptr %arg46// AMDGCN: ptr addrspace(5) %arg47void fp(private int *arg) {}48 49// CHECK: ptr addrspace(1) %arg50void fg(global int *arg) {}51 52// CHECK: ptr addrspace(3) %arg53void fl(local int *arg) {}54 55// SPIR: ptr addrspace(2) %arg56// AMDGCN: ptr addrspace(4) %arg57void fc(constant int *arg) {}58 59// SPIR: ptr addrspace(5) %arg60// AMDGCN: ptr addrspace(1) %arg61void fd(__attribute__((opencl_global_device)) int *arg) {}62 63// SPIR: ptr addrspace(6) %arg64// AMDGCN: ptr addrspace(1) %arg65void fh(__attribute__((opencl_global_host)) int *arg) {}66 67#ifdef CL2068int i;69// CL20-DAG: @i = {{(dso_local )?}}addrspace(1) global i32 070int *ptr;71// CL20SPIR-DAG: @ptr = {{(common )?}}{{(dso_local )?}}addrspace(1) global ptr addrspace(4) null72// CL20AMDGCN-DAG: @ptr = {{(dso_local )?}}addrspace(1) global ptr null73#endif74 75// SPIR: ptr noundef %arg76// AMDGCN: ptr addrspace(5) noundef %arg77// CL20SPIR-DAG: ptr addrspace(4) noundef %arg78// CL20AMDGCN-DAG: ptr noundef %arg79void 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 CL2088 static int ii;89// CL20-DAG: @f.ii = internal addrspace(1) global i32 090#endif91}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 ptr104 // CL20SPIR: %ps = alloca ptr addrspace(4)105 struct S *ps;106 // SPIR: store i32 0, ptr %x107 // CL20SPIR: store i32 0, ptr addrspace(4) %x108 ps->x = 0;109#ifdef CL20110 // CL20SPIR: store i32 0, ptr addrspace(1) @g_s111 g_s.x = 0;112#endif113}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 CL20125extern 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#endif142