1 // RUN
: %clang_cc1 %s -emit-llvm -triple spir-unknown-unknown -o - -O0 | FileCheck --check-prefixes
=CHECK-COMMON
,CHECK-SPIR %s
2 // RUN
: %clang_cc1 %s -cl-std
=CL2.0 -emit-llvm -triple spir-unknown-unknown -o - -O0 | FileCheck --check-prefixes
=CHECK-COMMON
,CHECK-SPIR %s
3 // RUN
: %clang_cc1 %s -cl-std
=clc
++ -emit-llvm -triple spir-unknown-unknown -o - -O0 | FileCheck --check-prefixes
=CHECK-COMMON
,CHECK-SPIR %s
4 // RUN
: %clang_cc1 %s -emit-llvm -triple x86_64-unknown-linux-gnu -o - -O0 | FileCheck --check-prefixes
=CHECK-COMMON
,CHECK-X86 %s
5 // RUN
: %clang_cc1 %s -cl-std
=CL2.0 -emit-llvm -triple x86_64-unknown-linux-gnu -o - -O0 | FileCheck --check-prefixes
=CHECK-COMMON
,CHECK-X86 %s
6 // RUN
: %clang_cc1 %s -cl-std
=clc
++ -emit-llvm -triple x86_64-unknown-linux-gnu -o - -O0 | FileCheck --check-prefixes
=CHECK-COMMON
,CHECK-X86 %s
8 // This test covers
5 cases of sampler initialzation
:
9 // 1. function argument passing
10 // 1a. argument is a file-scope variable
11 // 1b. argument is a function-scope variable
12 // 1c. argument is one of caller function
's parameters
13 // 2. variable initialization
14 // 2a. initializing a file-scope variable with constant addr space qualifier
15 // 2b. initializing a function-scope variable
16 // 2c. initializing a file-scope variable with const qualifier
18 #define CLK_ADDRESS_CLAMP_TO_EDGE
2
19 #define CLK_NORMALIZED_COORDS_TRUE
1
20 #define CLK_FILTER_NEAREST
0x10
21 #define CLK_FILTER_LINEAR
0x20
24 constant sampler_t glb_smp
= CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR
;
25 // CHECK-COMMON-NOT
: glb_smp
28 const sampler_t glb_smp_const
= CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR
;
29 // CHECK-COMMON-NOT
: glb_smp_const
31 int get_sampler_initializer
(void);
33 void fnc4smp
(sampler_t s
) {}
34 // CHECK-SPIR
: define
{{.
*}} spir_func void
[[FUNCNAME
:@.
*fnc4smp.
*]](target("spirv.Sampler") %
35 // CHECK-X86
: define
{{.
*}} void
[[FUNCNAME
:@.
*fnc4smp.
*]](ptr %
37 kernel void foo
(sampler_t smp_par
) {
38 // CHECK-SPIR-LABEL
: define
{{.
*}} spir_kernel void
@foo
(target("spirv.Sampler") %smp_par
)
39 // CHECK-SPIR
: [[smp_par_ptr
:%
[A-Za-z0-9_\.
]+]] = alloca target
("spirv.Sampler")
40 // CHECK-X86-LABEL
: define
{{.
*}} spir_kernel void
@foo
(ptr %smp_par
)
41 // CHECK-X86
: [[smp_par_ptr
:%
[A-Za-z0-9_\.
]+]] = alloca ptr
44 sampler_t smp
= CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_NEAREST
;
45 // CHECK-SPIR
: [[smp_ptr
:%
[A-Za-z0-9_\.
]+]] = alloca target
("spirv.Sampler")
46 // CHECK-SPIR
: [[SAMP
:%
[0-
9]+]] = call spir_func target
("spirv.Sampler") @__translate_sampler_initializer
(i32 19)
47 // CHECK-SPIR
: store target
("spirv.Sampler") [[SAMP]], ptr [[smp_ptr]]
48 // CHECK-X86: [[smp_ptr:%[A-Za-z0-9_\.]+]] = alloca ptr
49 // CHECK-X86: [[SAMP:%[0-9]+]] = call ptr @__translate_sampler_initializer(i32 19)
50 // CHECK-X86: store ptr [[SAMP]], ptr
[[smp_ptr]]
54 // CHECK-SPIR-NOT: call target("spirv.Sampler") @__translate_sampler_initializer(i32 19)
55 // CHECK-SPIR: [[SAMP:%[0-9]+]] = load target("spirv.Sampler"), ptr [[smp_ptr]]
56 // CHECK-SPIR
: call spir_func void
[[FUNCNAME]](target("spirv.Sampler") [[SAMP]])
57 // CHECK-X86-NOT: call ptr @__translate_sampler_initializer(i32 19)
58 // CHECK-X86: [[SAMP:%[0-9]+]] = load ptr, ptr [[smp_ptr]]
59 // CHECK-X86: call void [[FUNCNAME]](ptr [[SAMP]])
63 // CHECK-SPIR-NOT: call target("spirv.Sampler") @__translate_sampler_initializer(i32 19)
64 // CHECK-SPIR: [[SAMP:%[0-9]+]] = load target("spirv.Sampler"), ptr [[smp_ptr]]
65 // CHECK-SPIR: call spir_func void [[FUNCNAME]](target("spirv.Sampler") [[SAMP]])
66 // CHECK-X86-NOT
: call ptr
@__translate_sampler_initializer
(i32 19)
67 // CHECK-X86
: [[SAMP
:%
[0-
9]+]] = load ptr
, ptr
[[smp_ptr]]
68 // CHECK-X86: call void [[FUNCNAME]](ptr [[SAMP]])
72 // CHECK-SPIR: [[SAMP:%[0-9]+]] = call spir_func target("spirv.Sampler") @__translate_sampler_initializer(i32 35)
73 // CHECK-SPIR: call spir_func void [[FUNCNAME]](target("spirv.Sampler") [[SAMP]])
74 // CHECK-X86: [[SAMP:%[0-9]+]] = call ptr @__translate_sampler_initializer(i32 35)
75 // CHECK-X86: call void [[FUNCNAME]](ptr [[SAMP]])
78 fnc4smp(glb_smp_const);
79 // CHECK-SPIR: [[SAMP:%[0-9]+]] = call spir_func target("spirv.Sampler") @__translate_sampler_initializer(i32 35)
80 // CHECK-SPIR: call spir_func void [[FUNCNAME]](target("spirv.Sampler") [[SAMP]])
81 // CHECK-X86: [[SAMP:%[0-9]+]] = call ptr @__translate_sampler_initializer(i32 35)
82 // CHECK-X86: call void [[FUNCNAME]](ptr [[SAMP]])
86 // CHECK-SPIR: [[SAMP:%[0-9]+]] = load target("spirv.Sampler"), ptr [[smp_par_ptr]]
87 // CHECK-SPIR: call spir_func void [[FUNCNAME]](target("spirv.Sampler") [[SAMP]])
88 // CHECK-X86: [[SAMP:%[0-9]+]] = load ptr, ptr [[smp_par_ptr]]
89 // CHECK-X86: call void [[FUNCNAME]](ptr [[SAMP]])
92 // CHECK-SPIR: [[SAMP:%[0-9]+]] = call spir_func target("spirv.Sampler") @__translate_sampler_initializer(i32 5)
93 // CHECK-SPIR: call spir_func void [[FUNCNAME]](target("spirv.Sampler") [[SAMP]])
94 // CHECK-X86: [[SAMP:%[0-9]+]] = call ptr @__translate_sampler_initializer(i32 5)
95 // CHECK-X86: call void [[FUNCNAME]](ptr [[SAMP]])
97 const sampler_t const_smp = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR;
99 // CHECK-SPIR: [[CONST_SAMP:%[0-9]+]] = call spir_func target("spirv.Sampler") @__translate_sampler_initializer(i32 35)
100 // CHECK-SPIR: store target("spirv.Sampler") [[CONST_SAMP]], ptr [[CONST_SMP_PTR:%[a-zA-Z0-9]+]]
101 // CHECK-X86: [[CONST_SAMP:%[0-9]+]] = call ptr @__translate_sampler_initializer(i32 35)
102 // CHECK-X86: store ptr [[CONST_SAMP]], ptr [[CONST_SMP_PTR:%[a-zA-Z0-9]+]]
104 // CHECK-SPIR: [[SAMP:%[0-9]+]] = load target("spirv.Sampler"), ptr [[CONST_SMP_PTR]]
105 // CHECK-SPIR: call spir_func void [[FUNCNAME]](target("spirv.Sampler") [[SAMP]])
106 // CHECK-X86: [[SAMP:%[0-9]+]] = load ptr, ptr [[CONST_SMP_PTR]]
107 // CHECK-X86: call void [[FUNCNAME]](ptr [[SAMP]])
109 constant sampler_t constant_smp = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR;
110 fnc4smp(constant_smp);
111 // CHECK-SPIR: [[SAMP:%[0-9]+]] = call spir_func target("spirv.Sampler") @__translate_sampler_initializer(i32 35)
112 // CHECK-SPIR: call spir_func void [[FUNCNAME]](target("spirv.Sampler") [[SAMP]])
113 // CHECK-X86: [[SAMP:%[0-9]+]] = call ptr @__translate_sampler_initializer(i32 35)
114 // CHECK-X86: call void [[FUNCNAME]](ptr [[SAMP]])
116 // TODO: enable sampler initialization with non-constant integer.
117 //const sampler_t const_smp_func_init = get_sampler_initializer();