1// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify | FileCheck %s 2// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL1.1 | FileCheck %s 3// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL1.2 | FileCheck %s 4// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=clc++ | FileCheck %s --check-prefix=CHECK20 5// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL3.0 | FileCheck %s 6 7// Test including the default header as a module. 8// The module should be compiled only once and loaded from cache afterwards. 9// Change the directory mode to read only to make sure no new modules are created. 10// Check time report to make sure module is used. 11// Check that some builtins occur in the generated IR when called. 12 13// === 14// Clear current directory. 15// RUN: rm -rf %t 16// RUN: mkdir -p %t 17 18// === 19// Compile for OpenCL 1.0 for the first time. A module should be generated. 20// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm -o - -finclude-default-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -fdisable-module-hash -ftime-report %s 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=CHECK-MOD %s 21// RUN: chmod u-w %t/opencl_c.pcm 22 23// === 24// Compile for OpenCL 1.0 for the second time. The module should not be re-created. 25// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm -o - -finclude-default-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -fdisable-module-hash -ftime-report %s 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=CHECK-MOD %s 26// RUN: chmod u+w %t/opencl_c.pcm 27// RUN: mv %t/opencl_c.pcm %t/1_0.pcm 28 29// === 30// Compile for OpenCL 2.0 for the first time. The module should change. 31// RUN: %clang_cc1 -triple spir-unknown-unknown -O0 -emit-llvm -o - -cl-std=CL2.0 -finclude-default-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -fdisable-module-hash -ftime-report %s 2>&1 | FileCheck --check-prefix=CHECK20 --check-prefix=CHECK-MOD %s 32// RUN: not diff %t/1_0.pcm %t/opencl_c.pcm 33// RUN: chmod u-w %t/opencl_c.pcm 34 35// === 36// Compile for OpenCL 2.0 for the second time. The module should not change. 37// RUN: %clang_cc1 -triple spir-unknown-unknown -O0 -emit-llvm -o - -cl-std=CL2.0 -finclude-default-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -fdisable-module-hash -ftime-report %s 2>&1 | FileCheck --check-prefix=CHECK20 --check-prefix=CHECK-MOD %s 38 39// Check cached module works for different OpenCL versions. 40// RUN: rm -rf %t 41// RUN: mkdir -p %t 42// RUN: %clang_cc1 -triple spir64-unknown-unknown -emit-llvm -o - -cl-std=CL1.2 -finclude-default-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -ftime-report %s 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=CHECK-MOD %s 43// RUN: %clang_cc1 -triple amdgcn--amdhsa -O0 -emit-llvm -o - -cl-std=CL2.0 -finclude-default-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -ftime-report %s 2>&1 | FileCheck --check-prefix=CHECK20 --check-prefix=CHECK-MOD %s 44// RUN: chmod u-w %t 45// RUN: %clang_cc1 -triple spir64-unknown-unknown -emit-llvm -o - -cl-std=CL1.2 -finclude-default-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -ftime-report %s 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=CHECK-MOD %s 46// RUN: %clang_cc1 -triple amdgcn--amdhsa -O0 -emit-llvm -o - -cl-std=CL2.0 -finclude-default-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -ftime-report %s 2>&1 | FileCheck --check-prefix=CHECK20 --check-prefix=CHECK-MOD %s 47// RUN: chmod u+w %t 48 49// Verify that called builtins occur in the generated IR. 50 51// CHECK-NOT: intel_sub_group_avc_mce_get_default_inter_base_multi_reference_penalty 52// CHECK-NOT: ndrange_t 53// CHECK20: ndrange_t 54// CHECK: _Z16convert_char_rtec 55// CHECK-NOT: _Z3ctzc 56// CHECK20: _Z3ctzc 57// CHECK20: _Z16convert_char_rtec 58char f(char x) { 59// Check functionality from OpenCL 2.0 onwards 60#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ == CL_VERSION_2_0) 61 ndrange_t t; 62 x = ctz(x); 63#endif //__OPENCL_C_VERSION__ 64 return convert_char_rte(x); 65} 66 67// Verify that a builtin using a write_only image3d_t type is available 68// from OpenCL 2.0 onwards. 69 70// CHECK20: _Z12write_imagef14ocl_image3d_wo 71#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0) 72void test_image3dwo(write_only image3d_t img) { 73 write_imagef(img, (0), (0.0f)); 74} 75#endif //__OPENCL_C_VERSION__ 76 77#if defined(__OPENCL_CPP_VERSION__) 78// Test old atomic overloaded with generic addr space. 79void test_atomics(__generic volatile unsigned int* a) { 80 atomic_add(a, 1); 81} 82#endif 83 84// Verify that ATOMIC_VAR_INIT is defined. 85#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ == CL_VERSION_2_0) 86global atomic_int z = ATOMIC_VAR_INIT(99); 87#endif //__OPENCL_C_VERSION__ 88// CHECK-MOD: Reading modules 89 90// Check that extension macros are defined correctly. 91 92// For SPIR all extensions are supported. 93#if defined(__SPIR__) 94 95// Verify that cl_intel_planar_yuv extension is defined from OpenCL 1.2 onwards. 96#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_1_2) 97// expected-no-diagnostics 98#else //__OPENCL_C_VERSION__ 99// expected-warning@+2{{unknown OpenCL extension 'cl_intel_planar_yuv' - ignoring}} 100#endif //__OPENCL_C_VERSION__ 101#pragma OPENCL EXTENSION cl_intel_planar_yuv : enable 102 103#if (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200) 104 105#if cl_khr_subgroup_extended_types != 1 106#error "Incorrectly defined cl_khr_subgroup_extended_types" 107#endif 108#if cl_khr_subgroup_non_uniform_vote != 1 109#error "Incorrectly defined cl_khr_subgroup_non_uniform_vote" 110#endif 111#if cl_khr_subgroup_ballot != 1 112#error "Incorrectly defined cl_khr_subgroup_ballot" 113#endif 114#if cl_khr_subgroup_non_uniform_arithmetic != 1 115#error "Incorrectly defined cl_khr_subgroup_non_uniform_arithmetic" 116#endif 117#if cl_khr_subgroup_shuffle != 1 118#error "Incorrectly defined cl_khr_subgroup_shuffle" 119#endif 120#if cl_khr_subgroup_shuffle_relative != 1 121#error "Incorrectly defined cl_khr_subgroup_shuffle_relative" 122#endif 123#if cl_khr_subgroup_clustered_reduce != 1 124#error "Incorrectly defined cl_khr_subgroup_clustered_reduce" 125#endif 126#if cl_khr_extended_bit_ops != 1 127#error "Incorrectly defined cl_khr_extended_bit_ops" 128#endif 129#if cl_khr_integer_dot_product != 1 130#error "Incorrectly defined cl_khr_integer_dot_product" 131#endif 132#if __opencl_c_integer_dot_product_input_4x8bit != 1 133#error "Incorrectly defined __opencl_c_integer_dot_product_input_4x8bit" 134#endif 135#if __opencl_c_integer_dot_product_input_4x8bit_packed != 1 136#error "Incorrectly defined __opencl_c_integer_dot_product_input_4x8bit_packed" 137#endif 138 139#else 140 141#ifdef cl_khr_subgroup_extended_types 142#error "Incorrect cl_khr_subgroup_extended_types define" 143#endif 144#ifdef cl_khr_subgroup_non_uniform_vote 145#error "Incorrect cl_khr_subgroup_non_uniform_vote define" 146#endif 147#ifdef cl_khr_subgroup_ballot 148#error "Incorrect cl_khr_subgroup_ballot define" 149#endif 150#ifdef cl_khr_subgroup_non_uniform_arithmetic 151#error "Incorrect cl_khr_subgroup_non_uniform_arithmetic define" 152#endif 153#ifdef cl_khr_subgroup_shuffle 154#error "Incorrect cl_khr_subgroup_shuffle define" 155#endif 156#ifdef cl_khr_subgroup_shuffle_relative 157#error "Incorrect cl_khr_subgroup_shuffle_relative define" 158#endif 159#ifdef cl_khr_subgroup_clustered_reduce 160#error "Incorrect cl_khr_subgroup_clustered_reduce define" 161#endif 162#ifdef cl_khr_extended_bit_ops 163#error "Incorrect cl_khr_extended_bit_ops define" 164#endif 165#ifdef cl_khr_integer_dot_product 166#error "Incorrect cl_khr_integer_dot_product define" 167#endif 168#ifdef __opencl_c_integer_dot_product_input_4x8bit 169#error "Incorrect __opencl_c_integer_dot_product_input_4x8bit define" 170#endif 171#ifdef __opencl_c_integer_dot_product_input_4x8bit_packed 172#error "Incorrect __opencl_c_integer_dot_product_input_4x8bit_packed define" 173#endif 174 175#endif //(defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200) 176 177// OpenCL C features. 178#if (__OPENCL_C_VERSION__ == 300) 179 180#if __opencl_c_atomic_scope_all_devices != 1 181#error "Incorrectly defined feature macro __opencl_c_atomic_scope_all_devices" 182#endif 183 184#elif (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ == 200) 185 186#ifndef __opencl_c_pipes 187#error "Feature macro __opencl_c_pipes should be defined" 188#endif 189#ifndef __opencl_c_generic_address_space 190#error "Feature macro __opencl_c_generic_address_space should be defined" 191#endif 192#ifndef __opencl_c_work_group_collective_functions 193#error "Feature macro __opencl_c_work_group_collective_functions should be defined" 194#endif 195#ifndef __opencl_c_atomic_order_acq_rel 196#error "Feature macro __opencl_c_atomic_order_acq_rel should be defined" 197#endif 198#ifndef __opencl_c_atomic_order_seq_cst 199#error "Feature macro __opencl_c_atomic_order_seq_cst should be defined" 200#endif 201#ifndef __opencl_c_atomic_scope_device 202#error "Feature macro __opencl_c_atomic_scope_device should be defined" 203#endif 204#ifndef __opencl_c_atomic_scope_all_devices 205#error "Feature macro __opencl_c_atomic_scope_all_devices should be defined" 206#endif 207#ifndef __opencl_c_device_enqueue 208#error "Feature macro __opencl_c_device_enqueue should be defined" 209#endif 210#ifndef __opencl_c_read_write_images 211#error "Feature macro __opencl_c_read_write_images should be defined" 212#endif 213#ifndef __opencl_c_program_scope_global_variables 214#error "Feature macro __opencl_c_program_scope_global_variables should be defined" 215#endif 216#ifndef __opencl_c_images 217#error "Feature macro __opencl_c_images should be defined" 218#endif 219 220#elif (__OPENCL_C_VERSION__ < 200) 221 222#ifdef __opencl_c_pipes 223#error "Incorrect feature macro __opencl_c_pipes define" 224#endif 225#ifdef __opencl_c_generic_address_space 226#error "Incorrect feature macro __opencl_c_generic_address_space define" 227#endif 228#ifdef __opencl_c_work_group_collective_functions 229#error "Incorrect feature macro __opencl_c_work_group_collective_functions define" 230#endif 231#ifdef __opencl_c_atomic_order_acq_rel 232#error "Incorrect feature macro __opencl_c_atomic_order_acq_rel define" 233#endif 234#ifdef __opencl_c_atomic_order_seq_cst 235#error "Incorrect feature macro __opencl_c_atomic_order_seq_cst define" 236#endif 237#ifdef __opencl_c_atomic_scope_device 238#error "Incorrect feature macro __opencl_c_atomic_scope_device define" 239#endif 240#ifdef __opencl_c_atomic_scope_all_devices 241#error "Incorrect feature macro __opencl_c_atomic_scope_all_devices define" 242#endif 243#ifdef __opencl_c_device_enqueue 244#error "Incorrect feature macro __opencl_c_device_enqueue define" 245#endif 246#ifdef __opencl_c_read_write_images 247#error "Incorrect feature macro __opencl_c_read_write_images define" 248#endif 249#ifdef __opencl_c_program_scope_global_variables 250#error "Incorrect feature macro __opencl_c_program_scope_global_variables define" 251#endif 252#ifdef __opencl_c_images 253#error "Incorrect feature macro __opencl_c_images define" 254#endif 255#ifdef __opencl_c_3d_image_writes 256#error "Incorrect feature macro __opencl_c_3d_image_writes define" 257#endif 258#ifdef __opencl_c_fp64 259#error "Incorrect feature macro __opencl_c_fp64 define" 260#endif 261#ifdef __opencl_c_subgroups 262#error "Incorrect feature macro __opencl_c_subgroups define" 263#endif 264 265#endif //(defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ == 200) 266 267#endif // defined(__SPIR__) 268