1// RUN: %clang_cc1 %s -emit-llvm -triple spir-unknown-unknown -o - -O0 | FileCheck %s
2//
3// This test covers 5 cases of sampler initialzation:
4//   1. function argument passing
5//      1a. argument is a file-scope variable
6//      1b. argument is a function-scope variable
7//      1c. argument is one of caller function's parameters
8//   2. variable initialization
9//      2a. initializing a file-scope variable
10//      2b. initializing a function-scope variable
11
12#define CLK_ADDRESS_CLAMP_TO_EDGE       2
13#define CLK_NORMALIZED_COORDS_TRUE      1
14#define CLK_FILTER_NEAREST              0x10
15#define CLK_FILTER_LINEAR               0x20
16
17// CHECK: %opencl.sampler_t = type opaque
18
19// Case 2a
20constant sampler_t glb_smp = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR;
21// CHECK-NOT: glb_smp
22
23void fnc4smp(sampler_t s) {}
24// CHECK: define spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* %
25
26kernel void foo(sampler_t smp_par) {
27  // CHECK-LABEL: define spir_kernel void @foo(%opencl.sampler_t addrspace(2)* %smp_par)
28  // CHECK: [[smp_par_ptr:%[A-Za-z0-9_\.]+]] = alloca %opencl.sampler_t addrspace(2)*
29
30  // Case 2b
31  sampler_t smp = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_NEAREST;
32  // CHECK: [[smp_ptr:%[A-Za-z0-9_\.]+]] = alloca %opencl.sampler_t addrspace(2)*
33  // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 19)
34  // CHECK: store %opencl.sampler_t addrspace(2)* [[SAMP]], %opencl.sampler_t addrspace(2)** [[smp_ptr]]
35
36  // Case 1b
37  fnc4smp(smp);
38  // CHECK-NOT: call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 19)
39  // CHECK: [[SAMP:%[0-9]+]] = load %opencl.sampler_t addrspace(2)*, %opencl.sampler_t addrspace(2)** [[smp_ptr]]
40  // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* [[SAMP]])
41
42  // Case 1b
43  fnc4smp(smp);
44  // CHECK-NOT: call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 19)
45  // CHECK: [[SAMP:%[0-9]+]] = load %opencl.sampler_t addrspace(2)*, %opencl.sampler_t addrspace(2)** [[smp_ptr]]
46  // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* [[SAMP]])
47
48  // Case 1a
49  fnc4smp(glb_smp);
50  // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 35)
51  // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* [[SAMP]])
52
53  // Case 1c
54  fnc4smp(smp_par);
55  // CHECK: [[SAMP:%[0-9]+]] = load %opencl.sampler_t addrspace(2)*, %opencl.sampler_t addrspace(2)** [[smp_par_ptr]]
56  // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* [[SAMP]])
57}
58