Mesa (main): clc: speed up compilation by not relying on opencl-c.h

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sat May 21 12:59:28 UTC 2022


Module: Mesa
Branch: main
Commit: bcc2df489058f35fcb49f82c4069bcc756dfdd4e
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=bcc2df489058f35fcb49f82c4069bcc756dfdd4e

Author: Karol Herbst <kherbst at redhat.com>
Date:   Fri Apr 15 19:21:44 2022 +0200

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 <kherbst at redhat.com>
Reviewed-by: Jesse Natalie <jenatali at microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16479>

---

 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 15f34a0d59d..64d8c65dcf4 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,7 +854,11 @@ 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) {
diff --git a/src/compiler/clc/meson.build b/src/compiler/clc/meson.build
index d3c3286a7af..561f57152a9 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')],



More information about the mesa-commit mailing list