|
| 1 | +// RUN: %clang_cc1 -internal-isystem %S/Inputs -fsycl-is-device -std=c++20 -triple spir64-unknown-unknown -disable-llvm-passes -no-opaque-pointers -emit-llvm %s -o - | FileCheck %s |
| 2 | + |
| 3 | +#include "sycl.hpp" |
| 4 | + |
| 5 | +// This test checks that we correctly capture binding declarations. |
| 6 | + |
| 7 | +void foo() { |
| 8 | + sycl::handler h; |
| 9 | + int a[2] = {1, 2}; |
| 10 | + auto [x, y] = a; |
| 11 | + struct S { |
| 12 | + float b[3] = { 0, 3.0f, 4.0 }; |
| 13 | + } s; |
| 14 | + auto [f1, f2, f3] = s.b; |
| 15 | + auto Lambda = [=]() { x = 10; f2 = 2.3f; }; |
| 16 | + h.single_task(Lambda); |
| 17 | +} |
| 18 | + |
| 19 | +// CHECK: %class.anon = type { i32, float } |
| 20 | + |
| 21 | +// Check the sycl kernel arguments - one int and one float parameter |
| 22 | +// CHECK: define {{.*}} spir_kernel void @{{.*}}foov{{.*}}(i32 {{.*}} %_arg_x, float {{.*}} %_arg_f2) |
| 23 | +// CHECK: entry: |
| 24 | + |
| 25 | +// Check alloca of the captured types |
| 26 | +// CHECK: %_arg_x.addr = alloca i32, align 4 |
| 27 | +// CHECK: %_arg_f2.addr = alloca float, align 4 |
| 28 | +// CHECK: %__SYCLKernel = alloca %class.anon, align 4 |
| 29 | + |
| 30 | +// Copy the parameters into the alloca-ed addresses |
| 31 | +// CHECK: store i32 %_arg_x, i32 addrspace(4)* %_arg_x.addr |
| 32 | +// CHECK: store float %_arg_f2, float addrspace(4)* %_arg_f2.addr |
| 33 | + |
| 34 | +// Store the int and the float into the struct created |
| 35 | +// CHECK: %x = getelementptr inbounds %class.anon, %class.anon addrspace(4)* %__SYCLKernel{{.*}}, i32 0, i32 0 |
| 36 | +// CHECK: %1 = load i32, i32 addrspace(4)* %_arg_x.addr |
| 37 | +// CHECK: store i32 %1, i32 addrspace(4)* %x |
| 38 | +// CHECK: %f2 = getelementptr inbounds %class.anon, %class.anon addrspace(4)* %__SYCLKernel{{.*}}, i32 0, i32 1 |
| 39 | +// CHECK: %2 = load float, float addrspace(4)* %_arg_f2.addr |
| 40 | +// CHECK: store float %2, float addrspace(4)* %f2 |
| 41 | + |
| 42 | +// Call the lambda |
| 43 | +// CHECK: call spir_func void @{{.*}}foo{{.*}}(%class.anon addrspace(4)* {{.*}} %__SYCLKernel{{.*}}) |
| 44 | +// CHECK: ret void |
| 45 | + |
| 46 | +// Check the lambda call |
| 47 | +// CHECK: define {{.*}} spir_func void @{{.*}}foo{{.*}}(%class.anon addrspace(4)* {{.*}} %this) |
| 48 | +// CHECK: entry: |
| 49 | +// CHECK: %this.addr = alloca %class.anon addrspace(4)* |
| 50 | +// CHECK: %this.addr.ascast = addrspacecast %class.anon addrspace(4)** %this.addr to %class.anon addrspace(4)* addrspace(4)* |
| 51 | +// CHECK: store %class.anon addrspace(4)* %this, %class.anon addrspace(4)* addrspace(4)* %this.addr.ascast |
| 52 | +// CHECK: %this1 = load %class.anon addrspace(4)*, %class.anon addrspace(4)* addrspace(4)* %this.addr.ascast |
| 53 | + |
| 54 | +// Check the store of 10 into the int value |
| 55 | +// CHECK: %x = getelementptr inbounds %class.anon, %class.anon addrspace(4)* %this1, i32 0, i32 0 |
| 56 | +// CHECK: store i32 10, i32 addrspace(4)* %x |
| 57 | + |
| 58 | +// Check the store of 2.3f into the float value |
| 59 | +// CHECK: %f2 = getelementptr inbounds %class.anon, %class.anon addrspace(4)* %this1, i32 0, i32 1 |
| 60 | +// CHECK: store float 0x4002666660000000, float addrspace(4)* %f2 |
| 61 | +// CHECK: ret void |
0 commit comments