From d2264489ce85f4cc265a906d0ca92acc7608748e Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Thu, 18 Feb 2021 23:28:48 -0600 Subject: [PATCH] compiler/clc: grab opencl-c.h from the system path by default By default we use the header installed opencl-c.h header. But in the case Mesa is compiled for microsoft clon12 we keep the injected file. Signed-off-by: Lionel Landwerlin Reviewed-by: Jesse Natalie Reviewed-by: Dylan Baker Part-of: --- src/compiler/clc/clc_helpers.cpp | 16 ++++++++++++++++ src/compiler/clc/meson.build | 7 ++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/compiler/clc/clc_helpers.cpp b/src/compiler/clc/clc_helpers.cpp index 86cdfa0d3e5..d66e45fcba0 100644 --- a/src/compiler/clc/clc_helpers.cpp +++ b/src/compiler/clc/clc_helpers.cpp @@ -53,8 +53,10 @@ #include "spirv.h" +#ifdef USE_STATIC_OPENCL_C_H #include "opencl-c.h.h" #include "opencl-c-base.h.h" +#endif #include "clc_helpers.h" @@ -785,6 +787,8 @@ clc_compile_to_llvm_module(const struct clc_compile_args *args, c->getDiagnostics(), c->getInvocation().TargetOpts)); c->getFrontendOpts().ProgramAction = clang::frontend::EmitLLVMOnly; + +#ifdef USE_STATIC_OPENCL_C_H c->getHeaderSearchOpts().UseBuiltinIncludes = false; c->getHeaderSearchOpts().UseStandardSystemIncludes = false; @@ -806,6 +810,18 @@ clc_compile_to_llvm_module(const struct clc_compile_args *args, c->getPreprocessorOpts().addRemappedFile(system_header_path.str(), ::llvm::MemoryBuffer::getMemBuffer(llvm::StringRef(opencl_c_base_source, ARRAY_SIZE(opencl_c_base_source) - 1)).release()); } +#else + c->getHeaderSearchOpts().UseBuiltinIncludes = true; + c->getHeaderSearchOpts().UseStandardSystemIncludes = true; + c->getHeaderSearchOpts().ResourceDir = CLANG_RESOURCE_DIR; + + // Add opencl-c generic search path + c->getHeaderSearchOpts().AddPath(CLANG_RESOURCE_DIR, + clang::frontend::Angled, + false, false); + // Add opencl include + c->getPreprocessorOpts().Includes.push_back("opencl-c.h"); +#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 cc4687b4c8c..d46f67c3e79 100644 --- a/src/compiler/clc/meson.build +++ b/src/compiler/clc/meson.build @@ -39,13 +39,18 @@ files_libclc = files( 'clc_helpers.cpp', ) +_libclc_cpp_args = ['-DCLANG_RESOURCE_DIR="@0@"'.format(clang_resource_dir)] +if with_microsoft_clc + _libclc_cpp_args += ['-DUSE_STATIC_OPENCL_C_H=1'] +endif + _libclc = static_library( 'libclc', files_libclc, opencl_c_h, opencl_c_base_h, include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_compiler, inc_spirv], - cpp_args : ['-DCLANG_RESOURCE_DIR="@0@"'.format(clang_resource_dir)], + cpp_args : _libclc_cpp_args, dependencies: [idep_nir_headers, dep_clang, dep_llvm, dep_llvmspirvlib, idep_mesautil, idep_nir, dep_spirv_tools] )