| 1 |
// There are no blocks in SPIR-V. Therefore they are translated into regular |
| 2 |
// functions. An LLVM module which uses blocks, also contains some auxiliary |
| 3 |
// block-specific instructions, which are redundant in SPIR-V and should be |
| 4 |
// removed |
| 5 |
|
| 6 |
// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -cl-std=CL2.0 -x cl %s -emit-llvm-bc -o %t.bc -no-opaque-pointers |
| 7 |
|
| 8 |
// RUN: llvm-spirv --spirv-max-version=1.1 %t.bc -opaque-pointers=0 -spirv-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV |
| 9 |
// RUN: llvm-spirv --spirv-max-version=1.1 %t.bc -opaque-pointers=0 -o %t.spirv1.1.spv |
| 10 |
// RUN: spirv-val --target-env spv1.1 %t.spirv1.1.spv |
| 11 |
// RUN: llvm-spirv -r -emit-opaque-pointers %t.spirv1.1.spv -o - | llvm-dis | FileCheck %s --check-prefix=CHECK-LLVM |
| 12 |
|
| 13 |
// RUN: llvm-spirv --spirv-max-version=1.4 %t.bc -opaque-pointers=0 -spirv-text -o - | FileCheck %s --check-prefixes=CHECK-SPIRV1_4,CHECK-SPIRV |
| 14 |
// RUN: llvm-spirv --spirv-max-version=1.4 %t.bc -opaque-pointers=0 -o %t.spirv1.4.spv |
| 15 |
// RUN: spirv-val --target-env spv1.4 %t.spirv1.4.spv |
| 16 |
// RUN: llvm-spirv -r -emit-opaque-pointers %t.spirv1.4.spv -o - | llvm-dis | FileCheck %s --check-prefix=CHECK-LLVM |
| 17 |
|
| 18 |
kernel void block_kernel(__global int* res) { |
| 19 |
typedef int (^block_t)(int); |
| 20 |
constant block_t b1 = ^(int i) { return i + 1; }; |
| 21 |
*res = b1(5); |
| 22 |
} |
| 23 |
|
| 24 |
// CHECK-SPIRV1_4: EntryPoint 6 [[#]] "block_kernel" [[#InterfaceId:]] |
| 25 |
// CHECK-SPIRV1_4: Name [[#InterfaceId]] "__block_literal_global" |
| 26 |
// CHECK-SPIRV: Name [[block_invoke:[0-9]+]] "_block_invoke" |
| 27 |
// CHECK-SPIRV-DAG: TypeInt [[int:[0-9]+]] 32 |
| 28 |
// CHECK-SPIRV-DAG: TypeInt [[int8:[0-9]+]] 8 |
| 29 |
// CHECK-SPIRV: Constant [[int]] [[five:[0-9]+]] 5 |
| 30 |
// CHECK-SPIRV: TypePointer [[int8Ptr:[0-9]+]] 8 [[int8]] |
| 31 |
// CHECK-SPIRV: TypeFunction [[block_invoke_type:[0-9]+]] [[int]] [[int8Ptr]] [[int]] |
| 32 |
|
| 33 |
// CHECK-LLVM-LABEL: @block_kernel |
| 34 |
// CHECK-SPIRV: FunctionCall [[int]] {{[0-9]+}} [[block_invoke]] {{[0-9]+}} [[five]] |
| 35 |
// CHECK-LLVM: %call = call spir_func i32 @_block_invoke(ptr addrspace(4) {{.*}}, i32 5) |
| 36 |
|
| 37 |
// CHECK-SPIRV: 5 Function [[int]] [[block_invoke]] 2 [[block_invoke_type]] |
| 38 |
// CHECK-SPIRV-NEXT: 3 FunctionParameter [[int8Ptr]] {{[0-9]+}} |
| 39 |
// CHECK-SPIRV-NEXT: 3 FunctionParameter [[int]] {{[0-9]+}} |
| 40 |
// CHECK-LLVM: define internal spir_func i32 @_block_invoke(ptr addrspace(4) {{.*}}, i32 %{{.*}}) |