• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1;; file: global_block.cl
2;; kernel void block_kernel(__global int* res) {
3;;   typedef int (^block_t)(int);
4;;   constant block_t b1 = ^(int i) { return i + 1; };
5;;   *res = b1(5);
6;; }
7;; clang -cc1 -O0 -triple spir-unknown-unknown -cl-std=CL2.0 -x cl global_block.cl -emit-llvm -o - | opt -mem2reg -S > global_block.ll
8
9; RUN: llvm-as %s -o %t.bc
10; RUN: llvm-spirv %t.bc -spirv-text -o %t.txt
11; RUN: FileCheck < %t.txt %s --check-prefix=CHECK-SPIRV
12; RUN: llvm-spirv %t.bc -o %t.spv
13; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
14; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM
15
16; ModuleID = '<stdin>'
17target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
18target triple = "spir-unknown-unknown"
19
20; CHECK-SPIRV: TypeInt [[int:[0-9]+]] 32
21; CHECK-SPIRV: TypeInt [[int8:[0-9]+]] 8
22; CHECK-SPIRV: Constant [[int]] [[five:[0-9]+]] 5
23; CHECK-SPIRV: TypePointer [[void_ptr:[0-9]+]] {{.*}} [[int8]]
24
25%opencl.block = type opaque
26; CHECK-LLVM:  %opencl.block = type opaque
27; CHECK-SPIRV: ConstantNull [[void_ptr]] [[void_null_ptr:[0-9]+]]
28
29@block_kernel.b1 = internal addrspace(2) constant %opencl.block* bitcast (i32 (i8*, i32)* @_block_invoke to %opencl.block*), align 4
30; CHECK-LLVM:  @block_kernel.b1 = internal addrspace(2) constant %opencl.block* bitcast (i32 (i8*, i32)* @_block_invoke to %opencl.block*), align 4
31
32; CHECK-LLVM:  define internal spir_func i32 @_block_invoke(i8* %.block_descriptor, i32 %i)
33; CHECK-SPIRV: Function [[int]] [[_block_invoke:[0-9]+]]
34; CHECK-SPIRV: FunctionParameter [[void_ptr]]
35; CHECK-SPIRV: FunctionParameter [[int]]
36; CHECK-SPIRV: FunctionEnd
37
38; Function Attrs: nounwind
39define spir_kernel void @block_kernel(i32 addrspace(1)* %res) #0 {
40; CHECK-LLVM:  define spir_kernel void @block_kernel(i32 addrspace(1)* %res)
41; CHECK-SPIRV: Function
42; CHECK-SPIRV: FunctionParameter {{.*}} [[res:[0-9]+]]
43entry:
44%0 = load %opencl.block*, %opencl.block* addrspace(2)* @block_kernel.b1, align 4
45  %1 = call i8* @spir_get_block_invoke(%opencl.block* %0)
46  %2 = call i8* @spir_get_block_context(%opencl.block* %0)
47  %3 = bitcast i8* %1 to i32 (i8*, i32)*
48  %call = call spir_func i32 %3(i8* %2, i32 5)
49; CHECK-LLVM:  %call = call spir_func i32 @_block_invoke(i8* null, i32 5)
50; CHECK-SPIRV: FunctionCall [[int]] [[call_res:[0-9]+]] [[_block_invoke]] [[void_null_ptr]] [[five]]
51  store i32 %call, i32 addrspace(1)* %res, align 4
52; CHECK-LLVM:  store i32 %call, i32 addrspace(1)* %res, align 4
53; CHECK-SPIRV: Store [[res]] [[call_res]]
54  ret void
55}
56
57; Function Attrs: nounwind
58define internal spir_func i32 @_block_invoke(i8* %.block_descriptor, i32 %i) #0 {
59entry:
60  %block = bitcast i8* %.block_descriptor to <{}>*
61  %add = add nsw i32 %i, 1
62  ret i32 %add
63}
64
65declare i8* @spir_get_block_invoke(%opencl.block*)
66
67declare i8* @spir_get_block_context(%opencl.block*)
68
69attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
70
71!opencl.kernels = !{!0}
72!opencl.enable.FP_CONTRACT = !{}
73!opencl.spir.version = !{!6}
74!opencl.ocl.version = !{!7}
75!opencl.used.extensions = !{!8}
76!opencl.used.optional.core.features = !{!8}
77!opencl.compiler.options = !{!8}
78
79!0 = !{void (i32 addrspace(1)*)* @block_kernel, !1, !2, !3, !4, !5}
80!1 = !{!"kernel_arg_addr_space", i32 1}
81!2 = !{!"kernel_arg_access_qual", !"none"}
82!3 = !{!"kernel_arg_type", !"int*"}
83!4 = !{!"kernel_arg_base_type", !"int*"}
84!5 = !{!"kernel_arg_type_qual", !""}
85!6 = !{i32 1, i32 2}
86!7 = !{i32 2, i32 0}
87!8 = !{}
88