Module: Mesa Branch: main Commit: b6ed3c6ea2b02f67ae3aa0512678e0492f8e4df2 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=b6ed3c6ea2b02f67ae3aa0512678e0492f8e4df2
Author: Karol Herbst <[email protected]> Date: Thu May 12 19:26:31 2022 +0200 clc: fix compiler features_macro CTS Test Even with that alone we can't pass the test, as LLVM enables some extensions based on the SPIR target we choose. Signed-off-by: Karol Herbst <[email protected]> Reviewed-by: Jesse Natalie <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16479> --- src/compiler/clc/clc.h | 9 +++++++++ src/compiler/clc/clc_helpers.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/compiler/clc/clc.h b/src/compiler/clc/clc.h index 0431643c00d..c5c3a2b1c18 100644 --- a/src/compiler/clc/clc.h +++ b/src/compiler/clc/clc.h @@ -49,6 +49,14 @@ enum clc_spirv_version { CLC_SPIRV_VERSION_1_4, }; +struct clc_optional_features { + bool fp64; + bool int64; + bool images; + bool images_read_write; + bool images_write_3d; +}; + struct clc_compile_args { const struct clc_named_value *headers; unsigned num_headers; @@ -58,6 +66,7 @@ struct clc_compile_args { /* SPIRV version to target. */ enum clc_spirv_version spirv_version; + struct clc_optional_features features; /* Allowed extensions SPIRV extensions the OpenCL->SPIRV translation can * enable. A pointer to a NULL terminated array of strings, allow any diff --git a/src/compiler/clc/clc_helpers.cpp b/src/compiler/clc/clc_helpers.cpp index 64d8c65dcf4..53ccb1ebca3 100644 --- a/src/compiler/clc/clc_helpers.cpp +++ b/src/compiler/clc/clc_helpers.cpp @@ -861,6 +861,33 @@ clc_compile_to_llvm_module(LLVMContext &llvm_ctx, #endif #endif +#if LLVM_VERSION_MAJOR >= 14 + c->getTargetOpts().OpenCLExtensionsAsWritten.push_back("-all"); + c->getTargetOpts().OpenCLExtensionsAsWritten.push_back("+cl_khr_byte_addressable_store"); + c->getTargetOpts().OpenCLExtensionsAsWritten.push_back("+cl_khr_global_int32_base_atomics"); + c->getTargetOpts().OpenCLExtensionsAsWritten.push_back("+cl_khr_global_int32_extended_atomics"); + c->getTargetOpts().OpenCLExtensionsAsWritten.push_back("+cl_khr_local_int32_base_atomics"); + c->getTargetOpts().OpenCLExtensionsAsWritten.push_back("+cl_khr_local_int32_extended_atomics"); + if (args->features.fp64) { + c->getTargetOpts().OpenCLExtensionsAsWritten.push_back("+cl_khr_fp64"); + c->getTargetOpts().OpenCLExtensionsAsWritten.push_back("+__opencl_c_fp64"); + } + if (args->features.int64) { + c->getTargetOpts().OpenCLExtensionsAsWritten.push_back("+cles_khr_int64"); + c->getTargetOpts().OpenCLExtensionsAsWritten.push_back("+__opencl_c_int64"); + } + if (args->features.images) { + c->getTargetOpts().OpenCLExtensionsAsWritten.push_back("+__opencl_c_images"); + } + if (args->features.images_read_write) { + c->getTargetOpts().OpenCLExtensionsAsWritten.push_back("+__opencl_c_read_write_images"); + } + if (args->features.images_write_3d) { + c->getTargetOpts().OpenCLExtensionsAsWritten.push_back("+cl_khr_3d_image_writes"); + c->getTargetOpts().OpenCLExtensionsAsWritten.push_back("+__opencl_c_3d_image_writes"); + } +#endif + if (args->num_headers) { ::llvm::SmallString<128> tmp_header_path; ::llvm::sys::path::system_temp_directory(true, tmp_header_path);
