1 // RUN
: %clang_cc1 -no-opaque-pointers %s -emit-llvm -triple spir-unknown-unknown -o - -O0 | FileCheck %s
2 // RUN
: %clang_cc1 -no-opaque-pointers %s -cl-std
=CL2.0 -emit-llvm -triple spir-unknown-unknown -o - -O0 | FileCheck %s
3 // RUN
: %clang_cc1 -no-opaque-pointers %s -cl-std
=clc
++ -emit-llvm -triple spir-unknown-unknown -o - -O0 | FileCheck %s
5 // This test covers
5 cases of sampler initialzation
:
6 // 1. function argument passing
7 // 1a. argument is a file-scope variable
8 // 1b. argument is a function-scope variable
9 // 1c. argument is one of caller function
's parameters
10 // 2. variable initialization
11 // 2a. initializing a file-scope variable with constant addr space qualifier
12 // 2b. initializing a function-scope variable
13 // 2c. initializing a file-scope variable with const qualifier
15 #define CLK_ADDRESS_CLAMP_TO_EDGE
2
16 #define CLK_NORMALIZED_COORDS_TRUE
1
17 #define CLK_FILTER_NEAREST
0x10
18 #define CLK_FILTER_LINEAR
0x20
20 // CHECK
: %opencl.sampler_t
= type opaque
23 constant sampler_t glb_smp
= CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR
;
27 const sampler_t glb_smp_const
= CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR
;
28 // CHECK-NOT
: glb_smp_const
30 int get_sampler_initializer
(void);
32 void fnc4smp
(sampler_t s
) {}
33 // CHECK
: define
{{.
*}} spir_func void
[[FUNCNAME
:@.
*fnc4smp.
*]](%opencl.sampler_t addrspace
(2)* %
35 kernel void foo
(sampler_t smp_par
) {
36 // CHECK-LABEL
: define
{{.
*}} spir_kernel void
@foo
(%opencl.sampler_t addrspace
(2)* %smp_par
)
37 // CHECK
: [[smp_par_ptr
:%
[A-Za-z0-9_\.
]+]] = alloca %opencl.sampler_t addrspace
(2)*
40 sampler_t smp
= CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_NEAREST
;
41 // CHECK
: [[smp_ptr
:%
[A-Za-z0-9_\.
]+]] = alloca %opencl.sampler_t addrspace
(2)*
42 // CHECK
: [[SAMP
:%
[0-
9]+]] = call spir_func %opencl.sampler_t addrspace
(2)* @__translate_sampler_initializer
(i32 19)
43 // CHECK
: store %opencl.sampler_t addrspace
(2)* [[SAMP]], %opencl.sampler_t addrspace(2)** [[smp_ptr]]
47 // CHECK-NOT: call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 19)
48 // CHECK: [[SAMP:%[0-9]+]] = load %opencl.sampler_t addrspace(2)*, %opencl.sampler_t addrspace(2)** [[smp_ptr]]
49 // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* [[SAMP]])
53 // CHECK-NOT
: call %opencl.sampler_t addrspace
(2)* @__translate_sampler_initializer
(i32 19)
54 // CHECK
: [[SAMP
:%
[0-
9]+]] = load %opencl.sampler_t addrspace
(2)*, %opencl.sampler_t addrspace
(2)** [[smp_ptr]]
55 // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* [[SAMP]])
59 // CHECK: [[SAMP:%[0-9]+]] = call spir_func %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 35)
60 // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* [[SAMP]])
63 fnc4smp(glb_smp_const);
64 // CHECK: [[SAMP:%[0-9]+]] = call spir_func %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 35)
65 // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* [[SAMP]])
69 // CHECK: [[SAMP:%[0-9]+]] = load %opencl.sampler_t addrspace(2)*, %opencl.sampler_t addrspace(2)** [[smp_par_ptr]]
70 // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* [[SAMP]])
73 // CHECK: [[SAMP:%[0-9]+]] = call spir_func %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 5)
74 // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* [[SAMP]])
76 const sampler_t const_smp = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR;
78 // CHECK: [[CONST_SAMP:%[0-9]+]] = call spir_func %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 35)
79 // CHECK: store %opencl.sampler_t addrspace(2)* [[CONST_SAMP]], %opencl.sampler_t addrspace(2)** [[CONST_SMP_PTR:%[a-zA-Z0-9]+]]
81 // CHECK: [[SAMP:%[0-9]+]] = load %opencl.sampler_t addrspace(2)*, %opencl.sampler_t addrspace(2)** [[CONST_SMP_PTR]]
82 // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* [[SAMP]])
84 constant sampler_t constant_smp = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR;
85 fnc4smp(constant_smp);
86 // CHECK: [[SAMP:%[0-9]+]] = call spir_func %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 35)
87 // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* [[SAMP]])
89 // TODO: enable sampler initialization with non-constant integer.
90 //const sampler_t const_smp_func_init = get_sampler_initializer();