From 6474f8c2ce107c566090bdacea1eb74f58b088d6 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Sat, 17 Feb 2024 00:22:30 +0100 Subject: [PATCH] clc: include opencl-c.h for extensions needing it This also allows tools build on clc to drop their workaround to include it themselves. Rusticl might need it once it supports extensions which need this file pulled in. Later if the need to include it changes based on llvm version, we can easily handle this in clc. The main reason to include it only conditionally is the massively reduction in compilation time. It also removes the mental burden from users of clc to deal with any of this themselves. Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/10633 Fixes: 37a13463478 ("meson: remove opencl-external-clang-headers option and rely on shared-llvm") Signed-off-by: Karol Herbst Acked-by: Lionel Landwerlin Acked-by: Jesse Natalie Part-of: --- src/compiler/clc/clc_helpers.cpp | 18 ++++++++++++++---- src/compiler/clc/meson.build | 9 ++++++++- src/intel/shaders/meson.build | 1 - src/intel/vulkan/grl/meson.build | 3 --- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/compiler/clc/clc_helpers.cpp b/src/compiler/clc/clc_helpers.cpp index b074596ad73..530196b8328 100644 --- a/src/compiler/clc/clc_helpers.cpp +++ b/src/compiler/clc/clc_helpers.cpp @@ -67,6 +67,7 @@ #ifdef USE_STATIC_OPENCL_C_H #include "opencl-c-base.h.h" +#include "opencl-c.h.h" #endif #include "clc_helpers.h" @@ -855,8 +856,11 @@ clc_compile_to_llvm_module(LLVMContext &llvm_ctx, ::llvm::sys::path::append(system_header_path, "opencl-c-base.h"); c->getPreprocessorOpts().addRemappedFile(system_header_path.str(), ::llvm::MemoryBuffer::getMemBuffer(llvm::StringRef(opencl_c_base_source, ARRAY_SIZE(opencl_c_base_source) - 1)).release()); - - c->getPreprocessorOpts().Includes.push_back("opencl-c-base.h"); + // this line is actually important to make it include `opencl-c.h` + ::llvm::sys::path::remove_filename(system_header_path); + ::llvm::sys::path::append(system_header_path, "opencl-c.h"); + c->getPreprocessorOpts().addRemappedFile(system_header_path.str(), + ::llvm::MemoryBuffer::getMemBuffer(llvm::StringRef(opencl_c_source, ARRAY_SIZE(opencl_c_source) - 1)).release()); } #else @@ -886,8 +890,6 @@ clc_compile_to_llvm_module(LLVMContext &llvm_ctx, c->getHeaderSearchOpts().AddPath(clang_res_path.string(), clang::frontend::Angled, false, false); - // Add opencl include - c->getPreprocessorOpts().Includes.push_back("opencl-c-base.h"); #endif // Enable/Disable optional OpenCL C features. Some can be toggled via `OpenCLExtensionsAsWritten` @@ -905,6 +907,7 @@ clc_compile_to_llvm_module(LLVMContext &llvm_ctx, c->getTargetOpts().OpenCLExtensionsAsWritten.push_back("+cl_khr_local_int32_extended_atomics"); c->getPreprocessorOpts().addMacroDef("cl_khr_expect_assume=1"); + bool needs_opencl_c_h = false; if (args->features.fp16) { c->getTargetOpts().OpenCLExtensionsAsWritten.push_back("+cl_khr_fp16"); } @@ -934,6 +937,7 @@ clc_compile_to_llvm_module(LLVMContext &llvm_ctx, } if (args->features.intel_subgroups) { c->getTargetOpts().OpenCLExtensionsAsWritten.push_back("+cl_intel_subgroups"); + needs_opencl_c_h = true; } if (args->features.subgroups) { c->getTargetOpts().OpenCLExtensionsAsWritten.push_back("+__opencl_c_subgroups"); @@ -954,6 +958,12 @@ clc_compile_to_llvm_module(LLVMContext &llvm_ctx, c->getPreprocessorOpts().addMacroDef("__opencl_c_integer_dot_product_input_4x8bit=1"); } + // Add opencl include + c->getPreprocessorOpts().Includes.push_back("opencl-c-base.h"); + if (needs_opencl_c_h) { + c->getPreprocessorOpts().Includes.push_back("opencl-c.h"); + } + if (args->num_headers) { ::llvm::SmallString<128> tmp_header_path; ::llvm::sys::path::system_temp_directory(true, tmp_header_path); diff --git a/src/compiler/clc/meson.build b/src/compiler/clc/meson.build index 69bd04bad04..f7de55809a3 100644 --- a/src/compiler/clc/meson.build +++ b/src/compiler/clc/meson.build @@ -48,7 +48,14 @@ if not _shared_llvm command : [prog_python, '@INPUT@', '@OUTPUT@', '-n', 'opencl_c_base_source'], ) - _libmesaclc_sources += [opencl_c_base_h] + opencl_c_h = custom_target( + 'opencl-c.h', + input : [files_xxd, join_paths(clang_resource_dir, 'opencl-c.h')], + output : 'opencl-c.h.h', + command : [prog_python, '@INPUT@', '@OUTPUT@', '-n', 'opencl_c_source'], + ) + + _libmesaclc_sources += [opencl_c_base_h, opencl_c_h] _libmesaclc_cpp_args += ['-DUSE_STATIC_OPENCL_C_H=1'] endif diff --git a/src/intel/shaders/meson.build b/src/intel/shaders/meson.build index b5db9779a90..2b613ddc5c4 100644 --- a/src/intel/shaders/meson.build +++ b/src/intel/shaders/meson.build @@ -64,7 +64,6 @@ foreach gen : intel_shaders_gens '-I' + join_paths(dir_source_root, 'src/intel'), '-I' + join_paths(meson.project_build_root(), 'src/intel'), '-I' + join_paths(dir_source_root, 'src/intel/genxml'), - '-include', 'opencl-c.h', ], env: ['MESA_SHADER_CACHE_DISABLE=true'], depends : [dep_prog_intel_clc, gen_cl_xml_pack], diff --git a/src/intel/vulkan/grl/meson.build b/src/intel/vulkan/grl/meson.build index c4461ff18f4..ed7ac56f998 100644 --- a/src/intel/vulkan/grl/meson.build +++ b/src/intel/vulkan/grl/meson.build @@ -138,9 +138,6 @@ foreach t : [['125', 'gfx125', 'dg2']] '-DMAX_HW_SIMD_WIDTH=16', '-DMAX_WORKGROUP_SIZE=16', '-I' + join_paths(meson.current_source_dir(), 'gpu'), '-I' + join_paths(meson.current_source_dir(), 'include'), - '-include', 'opencl-c.h', # added to bypass build failure from clang15 - # without modifying grl source code, remove - # if fixed there ], env: ['MESA_SHADER_CACHE_DISABLE=true', 'MESA_SPIRV_LOG_LEVEL=error'],