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: 37a1346347 ("meson: remove opencl-external-clang-headers option and rely on shared-llvm")
Signed-off-by: Karol Herbst <kherbst@redhat.com>
Acked-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Acked-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27663>
This commit is contained in:
Karol Herbst 2024-02-17 00:22:30 +01:00 committed by Marge Bot
parent 11dbdedf46
commit 6474f8c2ce
4 changed files with 22 additions and 9 deletions

View file

@ -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);

View file

@ -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

View file

@ -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],

View file

@ -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'],