From bcc2df489058f35fcb49f82c4069bcc756dfdd4e Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Fri, 15 Apr 2022 19:21:44 +0200 Subject: [PATCH] clc: speed up compilation by not relying on opencl-c.h This depends on LLVM change: https://reviews.llvm.org/D125401 Signed-off-by: Karol Herbst Reviewed-by: Jesse Natalie Part-of: --- src/compiler/clc/clc_helpers.cpp | 12 ++++++++++++ src/compiler/clc/meson.build | 15 +++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/compiler/clc/clc_helpers.cpp b/src/compiler/clc/clc_helpers.cpp index 15f34a0..64d8c65 100644 --- a/src/compiler/clc/clc_helpers.cpp +++ b/src/compiler/clc/clc_helpers.cpp @@ -55,7 +55,9 @@ #include "spirv.h" #ifdef USE_STATIC_OPENCL_C_H +#if LLVM_VERSION_MAJOR < 15 #include "opencl-c.h.h" +#endif #include "opencl-c-base.h.h" #endif @@ -767,7 +769,11 @@ clc_compile_to_llvm_module(LLVMContext &llvm_ctx, "-triple", "spir64-unknown-unknown", // By default, clang prefers to use modules to pull in the default headers, // which doesn't work with our technique of embedding the headers in our binary +#if LLVM_VERSION_MAJOR >= 15 + "-fdeclare-opencl-builtins", +#else "-finclude-default-header", +#endif // Add a default CL compiler version. Clang will pick the last one specified // on the command line, so the app can override this one. "-cl-std=cl1.2", @@ -827,9 +833,11 @@ clc_compile_to_llvm_module(LLVMContext &llvm_ctx, clang::frontend::Angled, false, false); +#if LLVM_VERSION_MAJOR < 15 ::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()); +#endif ::llvm::sys::path::remove_filename(system_header_path); ::llvm::sys::path::append(system_header_path, "opencl-c-base.h"); @@ -846,8 +854,12 @@ clc_compile_to_llvm_module(LLVMContext &llvm_ctx, clang::frontend::Angled, false, false); // Add opencl include +#if LLVM_VERSION_MAJOR >= 15 + c->getPreprocessorOpts().Includes.push_back("opencl-c-base.h"); +#else c->getPreprocessorOpts().Includes.push_back("opencl-c.h"); #endif +#endif if (args->num_headers) { ::llvm::SmallString<128> tmp_header_path; diff --git a/src/compiler/clc/meson.build b/src/compiler/clc/meson.build index d3c3286..561f571 100644 --- a/src/compiler/clc/meson.build +++ b/src/compiler/clc/meson.build @@ -21,12 +21,15 @@ clang_resource_dir = join_paths(llvm_libdir, 'clang', dep_llvm.version(), 'include') -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'], -) +if dep_llvm.version().version_compare('< 15.0') + 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'], + ) +endif + opencl_c_base_h = custom_target( 'opencl-c-base.h', input : [files_xxd, join_paths(clang_resource_dir, 'opencl-c-base.h')], -- 2.7.4