From 8de97537e0f56f0e91130f04717d42b454adbb83 Mon Sep 17 00:00:00 2001 From: Yifei1 He Date: Wed, 24 Jun 2020 22:45:04 +0800 Subject: [PATCH] Enable precompiled headers --- cl_headers/CMakeLists.txt | 79 +++++++++++++++++++++++- cl_headers/OpenCL.rc | 11 ++++ cl_headers/module.modulemap | 32 ++++++++++ cl_headers/resource.h | 11 +++- common_clang.cpp | 77 ++++++++++++++---------- common_clang.map | 9 +++ options_compile.cpp | 117 ++++++++++++++++++++++++++++++++---- 7 files changed, 290 insertions(+), 46 deletions(-) create mode 100644 cl_headers/module.modulemap diff --git a/cl_headers/CMakeLists.txt b/cl_headers/CMakeLists.txt index 3dd2ea4c..c3c1d76d 100644 --- a/cl_headers/CMakeLists.txt +++ b/cl_headers/CMakeLists.txt @@ -18,11 +18,66 @@ else(USE_PREBUILT_LLVM) set(OPENCL_HEADERS_DIR "${CLANG_SOURCE_DIR}/lib/Headers") endif(USE_PREBUILT_LLVM) copy_file(${OPENCL_HEADERS_DIR}/opencl-c.h opencl-c.h) +copy_file(${CMAKE_CURRENT_SOURCE_DIR}/module.modulemap module.modulemap) add_custom_target ( opencl.headers.target DEPENDS opencl-c.h + module.modulemap +) + +function(create_pcm DST MODULE HEADER OPTS DEPS) + add_custom_command ( + OUTPUT ${DST} + MAIN_DEPENDENCY ${MODMAP} + DEPENDS ${HEADER} ${DEPS} + COMMAND + ${CLANG_COMMAND} -cc1 -x cl + -I. -O0 ${OPTS} + -fmodules -fmodule-name=${MODULE} -fmodule-map-file-home-is-cwd + -emit-module "module.modulemap" + -fno-validate-pch + -o ${DST} + VERBATIM + COMMENT "Generating ${DST}" + ) +endfunction(create_pcm) + +set(CL12 "-cl-std=CL1.2") +set(CL20 "-cl-std=CL2.0") + +set(SPIR_TRIPLE "-triple;spir-unknown-unknown") +set(SPIR64_TRIPLE "-triple;spir64-unknown-unknown") +if (BUILD_X64) + set(HOST_TRIPLE "${SPIR64_TRIPLE}") +else() + set(HOST_TRIPLE "${SPIR_TRIPLE}") +endif() + +set(OPTS -cl-ext=-cl_khr_fp64) +create_pcm(opencl-c-12-spir.pcm cl12spir opencl-c.h "${SPIR_TRIPLE};${CL12};${OPTS}" "${DEPS}") +create_pcm(opencl-c-20-spir.pcm cl20spir opencl-c.h "${SPIR_TRIPLE};${CL20};${OPTS}" "${DEPS}") +create_pcm(opencl-c-12-spir64.pcm cl12spir64 opencl-c.h "${SPIR64_TRIPLE};${CL12};${OPTS}" "${DEPS}") +create_pcm(opencl-c-20-spir64.pcm cl20spir64 opencl-c.h "${SPIR64_TRIPLE};${CL20};${OPTS}" "${DEPS}") +set(OPTS -cl-ext=+cl_khr_fp64) +create_pcm(opencl-c-12-spir-fp64.pcm cl12spirfp64 opencl-c.h "${SPIR_TRIPLE};${CL12};${OPTS}" "${DEPS}") +create_pcm(opencl-c-20-spir-fp64.pcm cl20spirfp64 opencl-c.h "${SPIR_TRIPLE};${CL20};${OPTS}" "${DEPS}") +create_pcm(opencl-c-12-spir64-fp64.pcm cl12spir64fp64 opencl-c.h "${SPIR64_TRIPLE};${CL12};${OPTS}" "${DEPS}") +create_pcm(opencl-c-20-spir64-fp64.pcm cl20spir64fp64 opencl-c.h "${SPIR64_TRIPLE};${CL20};${OPTS}" "${DEPS}") + +add_custom_target ( + opencl.pcm.target + DEPENDS + opencl.headers.target + opencl-c-12-spir.pcm + opencl-c-20-spir.pcm + opencl-c-12-spir64.pcm + opencl-c-20-spir64.pcm + opencl-c-12-spir-fp64.pcm + opencl-c-20-spir-fp64.pcm + opencl-c-12-spir64-fp64.pcm + opencl-c-20-spir64-fp64.pcm ) @@ -41,11 +96,33 @@ else() pack_to_obj(opencl-c.h opencl-c.h.cpp "PCM_OPENCL_C_H") list(APPEND CL_HEADERS_SRC opencl-c.h.cpp + opencl-c-12-spir.mod.cpp + opencl-c-20-spir.mod.cpp + opencl-c-12-spir64.mod.cpp + opencl-c-20-spir64.mod.cpp + opencl-c-12-spir-fp64.mod.cpp + opencl-c-20-spir-fp64.mod.cpp + opencl-c-12-spir64-fp64.mod.cpp + opencl-c-20-spir64-fp64.mod.cpp + module.modulemap.cpp ) + # note the .pcm -> .mod extension change + # this is a workaround for CMake bug that caused + # dependency cycle in generated build rules + pack_to_obj(opencl-c-12-spir.pcm opencl-c-12-spir.mod.cpp "PCM_OPENCL_C_12_SPIR_PCM") + pack_to_obj(opencl-c-20-spir.pcm opencl-c-20-spir.mod.cpp "PCM_OPENCL_C_20_SPIR_PCM") + pack_to_obj(opencl-c-12-spir64.pcm opencl-c-12-spir64.mod.cpp "PCM_OPENCL_C_12_SPIR64_PCM") + pack_to_obj(opencl-c-20-spir64.pcm opencl-c-20-spir64.mod.cpp "PCM_OPENCL_C_20_SPIR64_PCM") + pack_to_obj(opencl-c-12-spir-fp64.pcm opencl-c-12-spir-fp64.mod.cpp "PCM_OPENCL_C_12_SPIR_FP64_PCM") + pack_to_obj(opencl-c-20-spir-fp64.pcm opencl-c-20-spir-fp64.mod.cpp "PCM_OPENCL_C_20_SPIR_FP64_PCM") + pack_to_obj(opencl-c-12-spir64-fp64.pcm opencl-c-12-spir64-fp64.mod.cpp "PCM_OPENCL_C_12_SPIR64_FP64_PCM") + pack_to_obj(opencl-c-20-spir64-fp64.pcm opencl-c-20-spir64-fp64.mod.cpp "PCM_OPENCL_C_20_SPIR64_FP64_PCM") + pack_to_obj(module.modulemap module.modulemap.cpp "PCM_OPENCL_C_MODULE_MAP") + endif() add_library(${CL_HEADERS_LIB} OBJECT ${CL_HEADERS_SRC} ) -add_dependencies(${CL_HEADERS_LIB} opencl.headers.target) +add_dependencies(${CL_HEADERS_LIB} opencl.pcm.target) diff --git a/cl_headers/OpenCL.rc b/cl_headers/OpenCL.rc index 955c3c3a..6fff1221 100644 --- a/cl_headers/OpenCL.rc +++ b/cl_headers/OpenCL.rc @@ -12,3 +12,14 @@ END // OPENCL_C_H PCM "opencl-c.h" + +OPENCL_C_12_SPIR_PCM PCM "opencl-c-12-spir.pcm" +OPENCL_C_20_SPIR_PCM PCM "opencl-c-20-spir.pcm" +OPENCL_C_12_SPIR64_PCM PCM "opencl-c-12-spir64.pcm" +OPENCL_C_20_SPIR64_PCM PCM "opencl-c-20-spir64.pcm" +OPENCL_C_12_SPIR_FP64_PCM PCM "opencl-c-12-spir-fp64.pcm" +OPENCL_C_20_SPIR_FP64_PCM PCM "opencl-c-20-spir-fp64.pcm" +OPENCL_C_12_SPIR64_FP64_PCM PCM "opencl-c-12-spir64-fp64.pcm" +OPENCL_C_20_SPIR64_FP64_PCM PCM "opencl-c-20-spir64-fp64.pcm" + +OPENCL_C_MODULE_MAP PCM "module.modulemap" diff --git a/cl_headers/module.modulemap b/cl_headers/module.modulemap new file mode 100644 index 00000000..11ccc2a6 --- /dev/null +++ b/cl_headers/module.modulemap @@ -0,0 +1,32 @@ +module cl12spir { + header "opencl-c.h" + export * +} +module cl20spir { + header "opencl-c.h" + export * +} +module cl12spir64 { + header "opencl-c.h" + export * +} +module cl20spir64 { + header "opencl-c.h" + export * +} +module cl12spirfp64 { + header "opencl-c.h" + export * +} +module cl20spirfp64 { + header "opencl-c.h" + export * +} +module cl12spir64fp64 { + header "opencl-c.h" + export * +} +module cl20spir64fp64 { + header "opencl-c.h" + export * +} diff --git a/cl_headers/resource.h b/cl_headers/resource.h index c03b11bc..7b80b51b 100644 --- a/cl_headers/resource.h +++ b/cl_headers/resource.h @@ -19,6 +19,15 @@ Copyright (c) Intel Corporation (2009-2017). #ifndef __RESOURCE__ #define __RESOURCE__ -#define OPENCL_C_H "OPENCL_C_H" +#define OPENCL_C_H "OPENCL_C_H" +#define OPENCL_C_12_SPIR_PCM "OPENCL_C_12_SPIR_PCM" +#define OPENCL_C_20_SPIR_PCM "OPENCL_C_20_SPIR_PCM" +#define OPENCL_C_12_SPIR64_PCM "OPENCL_C_12_SPIR64_PCM" +#define OPENCL_C_20_SPIR64_PCM "OPENCL_C_20_SPIR64_PCM" +#define OPENCL_C_12_SPIR_FP64_PCM "OPENCL_C_12_SPIR_FP64_PCM" +#define OPENCL_C_20_SPIR_FP64_PCM "OPENCL_C_20_SPIR_FP64_PCM" +#define OPENCL_C_12_SPIR64_FP64_PCM "OPENCL_C_12_SPIR64_FP64_PCM" +#define OPENCL_C_20_SPIR64_FP64_PCM "OPENCL_C_20_SPIR64_FP64_PCM" +#define OPENCL_C_MODULE_MAP "OPENCL_C_MODULE_MAP" #endif /* __RESOURCE__ */ diff --git a/common_clang.cpp b/common_clang.cpp index 40045e06..667c269d 100644 --- a/common_clang.cpp +++ b/common_clang.cpp @@ -85,7 +85,7 @@ static volatile bool lazyCCInit = true; // the flag must be 'volatile' to prevent caching in a CPU register static llvm::sys::Mutex lazyCCInitMutex; -static llvm::ManagedStatic > compileMutex; +static llvm::ManagedStatic> compileMutex; void CommonClangTerminate() { llvm::llvm_shutdown(); } @@ -113,16 +113,26 @@ void CommonClangInitialize() { } static bool GetHeaders(std::vector &Result) { - struct {const char *ID; const char *Name;} Headers[] = { - {OPENCL_C_H, "opencl-c.h"}, - }; + struct { + const char *ID; + const char *Name; + } Headers[] = {{OPENCL_C_H, "opencl-c.h"}, + {OPENCL_C_12_SPIR_PCM, "opencl-c-12-spir.pcm"}, + {OPENCL_C_20_SPIR_PCM, "opencl-c-20-spir.pcm"}, + {OPENCL_C_12_SPIR64_PCM, "opencl-c-12-spir64.pcm"}, + {OPENCL_C_20_SPIR64_PCM, "opencl-c-20-spir64.pcm"}, + {OPENCL_C_12_SPIR_FP64_PCM, "opencl-c-12-spir-fp64.pcm"}, + {OPENCL_C_20_SPIR_FP64_PCM, "opencl-c-20-spir-fp64.pcm"}, + {OPENCL_C_12_SPIR64_FP64_PCM, "opencl-c-12-spir64-fp64.pcm"}, + {OPENCL_C_20_SPIR64_FP64_PCM, "opencl-c-20-spir64-fp64.pcm"}, + {OPENCL_C_MODULE_MAP, "module.modulemap"}}; Result.clear(); Result.reserve(sizeof(Headers) / sizeof(*Headers)); ResourceManager &RM = ResourceManager::instance(); - for (auto Header:Headers) { + for (auto Header : Headers) { Resource R = RM.get_resource(Header.Name, Header.ID, "PCM", true); if (!R) { assert(0 && "Resource not found"); @@ -135,17 +145,21 @@ static bool GetHeaders(std::vector &Result) { return true; } -static void PrintCompileOptions(const char *pszOptions, const char *pszOptionsEx, - const char *pszOpenCLVer, const char * pszSource) { +static void PrintCompileOptions(const char *pszOptions, + const char *pszOptionsEx, + const char *pszOpenCLVer, + const char *pszSource) { #ifdef _DEBUG static int ID = 0; - if (!getenv("CCLANG_OPTIONS_DIR")) return; + if (!getenv("CCLANG_OPTIONS_DIR")) + return; std::string OptionsDir = getenv("CCLANG_OPTIONS_DIR"); std::stringstream logPath; - logPath << OptionsDir << "/log_" << std::this_thread::get_id() << "_" << ID << ".txt"; + logPath << OptionsDir << "/log_" << std::this_thread::get_id() << "_" << ID + << ".txt"; std::cout << logPath.str() << std::endl; // Creating log file @@ -165,22 +179,21 @@ static void PrintCompileOptions(const char *pszOptions, const char *pszOptionsEx #endif } -class SmallVectorBuffer : public std::streambuf -{ +class SmallVectorBuffer : public std::streambuf { // All memory management is delegated to llvm::SmallVectorImpl llvm::SmallVectorImpl &OS; // Since we don't touch any pointer in streambuf(pbase, pptr, epptr) this is // the only method we need to override. - virtual std::streamsize xsputn(const char *s, std::streamsize n) override { + virtual std::streamsize xsputn(const char *s, std::streamsize n) override { OS.append(s, s + n); return n; } public: SmallVectorBuffer() = delete; - SmallVectorBuffer(const SmallVectorBuffer&) = delete; - SmallVectorBuffer &operator=(const SmallVectorBuffer&) = delete; + SmallVectorBuffer(const SmallVectorBuffer &) = delete; + SmallVectorBuffer &operator=(const SmallVectorBuffer &) = delete; SmallVectorBuffer(llvm::SmallVectorImpl &O) : OS(O) {} }; @@ -202,7 +215,7 @@ Compile(const char *pszProgramSource, const char **pInputHeaders, // LLVM doesn't guarantee thread safety, // therefore we serialize execution of LLVM code. - llvm::sys::SmartScopedLock compileGuard {*compileMutex}; + llvm::sys::SmartScopedLock compileGuard{*compileMutex}; // Parse options CompileOptionsParser optionsParser(pszOpenCLVer); @@ -227,16 +240,16 @@ Compile(const char *pszProgramSource, const char **pInputHeaders, new clang::CompilerInstance()); // Prepare output buffer - std::unique_ptr - ir_ostream(new llvm::raw_svector_ostream(pResult->getIRBufferRef())); + std::unique_ptr ir_ostream( + new llvm::raw_svector_ostream(pResult->getIRBufferRef())); // Set buffers // CompilerInstance takes ownership over output stream compiler->setOutputStream(std::move(ir_ostream)); compiler->setDiagnostics(&*Diags); - auto OverlayFS = new llvm::vfs::OverlayFileSystem( - llvm::vfs::getRealFileSystem()); + auto OverlayFS = + new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()); auto MemFS = new llvm::vfs::InMemoryFileSystem(); OverlayFS->pushOverlay(MemFS); @@ -258,8 +271,8 @@ Compile(const char *pszProgramSource, const char **pInputHeaders, // Source file MemFS->addFile( optionsParser.getSourceName(), (time_t)0, - llvm::MemoryBuffer::getMemBuffer( - llvm::StringRef(pszProgramSource), optionsParser.getSourceName())); + llvm::MemoryBuffer::getMemBuffer(llvm::StringRef(pszProgramSource), + optionsParser.getSourceName())); // Input header with OpenCL defines. std::vector vHeaderWithDefs; @@ -267,22 +280,20 @@ Compile(const char *pszProgramSource, const char **pInputHeaders, return CL_COMPILE_PROGRAM_FAILURE; } - for (const auto &Header:vHeaderWithDefs) { + for (const auto &Header : vHeaderWithDefs) { auto Buf = llvm::MemoryBuffer::getMemBuffer( - llvm::StringRef(Header.m_data, Header.m_size), - Header.m_name); + llvm::StringRef(Header.m_data, Header.m_size), Header.m_name); - MemFS->addFile(Header.m_name,(time_t)0, std::move(Buf)); + MemFS->addFile(Header.m_name, (time_t)0, std::move(Buf)); } // Input Headers for (unsigned int i = 0; i < uiNumInputHeaders; ++i) { - auto Header = llvm::MemoryBuffer::getMemBuffer( - pInputHeaders[i], pInputHeadersNames[i]); + auto Header = llvm::MemoryBuffer::getMemBuffer(pInputHeaders[i], + pInputHeadersNames[i]); MemFS->addFile(pInputHeadersNames[i], (time_t)0, std::move(Header)); } - // Execute the frontend actions. bool success = false; try { @@ -303,12 +314,14 @@ Compile(const char *pszProgramSource, const char **pInputHeaders, if (success && optionsParser.hasEmitSPIRV()) { // Translate LLVM IR to SPIR-V. - llvm::StringRef LLVM_IR(static_cast(pResult->GetIR()), + llvm::StringRef LLVM_IR(static_cast(pResult->GetIR()), pResult->GetIRSize()); - std::unique_ptr MB = llvm::MemoryBuffer::getMemBuffer(LLVM_IR, pResult->GetIRName(), false); + std::unique_ptr MB = llvm::MemoryBuffer::getMemBuffer( + LLVM_IR, pResult->GetIRName(), false); llvm::LLVMContext Context; - auto E = llvm::getOwningLazyBitcodeModule(std::move(MB), Context, - /*ShouldLazyLoadMetadata=*/true); + auto E = + llvm::getOwningLazyBitcodeModule(std::move(MB), Context, + /*ShouldLazyLoadMetadata=*/true); llvm::logAllUnhandledErrors(E.takeError(), err_ostream, "error: "); std::unique_ptr M = std::move(*E); diff --git a/common_clang.map b/common_clang.map index 7dea9161..459f0e10 100644 --- a/common_clang.map +++ b/common_clang.map @@ -7,6 +7,15 @@ global: Link; GetKernelArgInfo; PCM_OPENCL_C_H*; + PCM_OPENCL_C_12_SPIR_PCM*; + PCM_OPENCL_C_20_SPIR_PCM*; + PCM_OPENCL_C_12_SPIR64_PCM*; + PCM_OPENCL_C_20_SPIR64_PCM*; + PCM_OPENCL_C_12_SPIR_FP64_PCM*; + PCM_OPENCL_C_20_SPIR_FP64_PCM*; + PCM_OPENCL_C_12_SPIR64_FP64_PCM*; + PCM_OPENCL_C_20_SPIR64_FP64_PCM*; + PCM_OPENCL_C_MODULE_MAP*; }; local: *; }; diff --git a/options_compile.cpp b/options_compile.cpp index 89364e44..55236f44 100644 --- a/options_compile.cpp +++ b/options_compile.cpp @@ -25,6 +25,8 @@ Copyright (c) Intel Corporation (2009-2017). #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/Mutex.h" +#include +#include #include #define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE; @@ -36,7 +38,7 @@ Copyright (c) Intel Corporation (2009-2017). using namespace llvm::opt; -static llvm::ManagedStatic > compileOptionsMutex; +static llvm::ManagedStatic> compileOptionsMutex; static const OptTable::Info ClangOptionsInfoTable[] = { #define PREFIX(NAME, VALUE) @@ -64,6 +66,7 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args, ArgsVector &effectiveArgs) { // Reset args int iCLStdSet = 0; + int fp64Enable = 0; std::string szTriple; std::string sourceName(llvm::Twine(s_progID++).str()); @@ -146,11 +149,11 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args, // TODO: move the validation of the value to the check section of the // option processing to be reported as an unknown option break; - // Just ignore the unknown options ( they will be listed in the unknown - // list inside the ArgsList anyway) - // The below assert is usable for manual debugging only - // default: - // assert(false && "some unknown argument"); + // Just ignore the unknown options ( they will be listed in the unknown + // list inside the ArgsList anyway) + // The below assert is usable for manual debugging only + // default: + // assert(false && "some unknown argument"); case OPT_COMPILE_profiling: case OPT_COMPILE_g_Flag: effectiveArgs.push_back("-debug-info-kind=limited"); @@ -179,7 +182,7 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args, effectiveArgs.push_back("-dwarf-column-info"); if (std::find_if(effectiveArgs.begin(), effectiveArgs.end(), - [](const ArgsVector::value_type& a) { + [](const ArgsVector::value_type &a) { return a == "-S" || a.find("-emit") == 0; }) == effectiveArgs.end()) { effectiveArgs.push_back("-emit-llvm-bc"); @@ -190,8 +193,7 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args, #if defined(_WIN64) || defined(__x86_64__) || defined(_M_AMD64) || \ defined(_M_X64) szTriple = "spir64-unknown-unknown"; -#elif defined(_WIN32) || defined(i386) || defined(__i386__) || \ - defined(__x86__) +#elif defined(_WIN32) || defined(i386) || defined(__i386__) || defined(__x86__) szTriple = "spir-unknown-unknown"; #else #error "Can't define target triple: unknown architecture." @@ -221,6 +223,98 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args, std::back_insert_iterator it(std::back_inserter(effectiveArgs)); quoted_tokenize(it, pszOptionsEx, " \t", '"', '\x00'); + for (ArgsVector::iterator it = effectiveArgs.begin(), + end = effectiveArgs.end(); + it != end; ++it) { + if (it->compare("-Dcl_khr_fp64") == 0) { + fp64Enable = true; + } + } + + std::map extMap{ + {"cl_khr_3d_image_writes", true}, + {"cl_khr_depth_images", true}, + {"cl_khr_fp16", true}, + {"cl_khr_gl_msaa_sharing", true}, + {"cl_khr_global_int32_base_atomics", true}, + {"cl_khr_global_int32_extended_atomics", true}, + {"cl_khr_int64_base_atomics", true}, + {"cl_khr_int64_extended_atomics", true}, + {"cl_khr_local_int32_base_atomics", true}, + {"cl_khr_local_int32_extended_atomics", true}, + {"cl_khr_mipmap_image", true}, + {"cl_khr_mipmap_image_writes", true}, + {"cl_khr_subgroups", true}, + {"cl_intel_device_side_avc_motion_estimation", true}, + {"cl_intel_planar_yuv", true}, + {"cl_intel_subgroups", true}, + {"cl_intel_subgroups_short", true}}; + auto parseClExt = [&](const std::string &clExtStr) { + llvm::StringRef clExtRef(clExtStr); + clExtRef.consume_front("-cl-ext="); + llvm::SmallVector parsedExt; + clExtRef.split(parsedExt, ','); + for (llvm::StringRef ext : parsedExt) { + char sign = ext.front(); + bool enabled = sign != '-'; + llvm::StringRef extName = ext; + if (sign == '+' || sign == '-') + extName = extName.drop_front(); + if (extName == "all") { + for (auto &p : extMap) + p.second = enabled; + continue; + } + auto it = extMap.find(extName); + if (it != extMap.end()) + it->second = enabled; + } + }; + std::for_each(effectiveArgs.begin(), effectiveArgs.end(), + [&](const ArgsVector::value_type &a) { + if (a.find("-cl-ext=") == 0) + parseClExt(a); + }); + + // extension is enabled in PCH but disabled or not specifed in options => + // disable pch + bool useModules = !std::any_of( + extMap.begin(), extMap.end(), + [](decltype(*begin(extMap)) p) { return p.second == false; }); + + if (useModules) { + effectiveArgs.push_back("-fmodules"); + if (fp64Enable == 0) { + if (szTriple.find("spir64") != szTriple.npos) { + if (iCLStdSet <= 120) { + effectiveArgs.push_back("-fmodule-file=opencl-c-12-spir64.pcm"); + } else { + effectiveArgs.push_back("-fmodule-file=opencl-c-20-spir64.pcm"); + } + } else if (szTriple.find("spir") != szTriple.npos) { + if (iCLStdSet <= 120) { + effectiveArgs.push_back("-fmodule-file=opencl-c-12-spir.pcm"); + } else { + effectiveArgs.push_back("-fmodule-file=opencl-c-20-spir.pcm"); + } + } + } else if (fp64Enable == 1) { + if (szTriple.find("spir64") != szTriple.npos) { + if (iCLStdSet <= 120) { + effectiveArgs.push_back("-fmodule-file=opencl-c-12-spir64-fp64.pcm"); + } else { + effectiveArgs.push_back("-fmodule-file=opencl-c-20-spir64-fp64.pcm"); + } + } else if (szTriple.find("spir") != szTriple.npos) { + if (iCLStdSet <= 120) { + effectiveArgs.push_back("-fmodule-file=opencl-c-12-spir-fp64.pcm"); + } else { + effectiveArgs.push_back("-fmodule-file=opencl-c-20-spir-fp64.pcm"); + } + } + } + } + // add source name to options as an input file assert(!sourceName.empty() && "Empty source name."); effectiveArgs.push_back(sourceName); @@ -245,8 +339,7 @@ void CompileOptionsParser::processOptions(const char *pszOptions, it != end; ++it) { if (it->compare("-cl-opt-disable") == 0) { m_optDisable = true; - } - else if (it->compare("-emit-spirv") == 0) { + } else if (it->compare("-emit-spirv") == 0) { m_effectiveArgsRaw.push_back("-emit-llvm-bc"); m_emitSPIRV = true; continue; @@ -306,7 +399,7 @@ extern "C" CC_DLL_EXPORT bool CheckCompileOptions(const char *pszOptions, size_t uiUnknownOptionsSize) { // LLVM doesn't guarantee thread safety, // therefore we serialize execution of LLVM code. - llvm::sys::SmartScopedLock compileOptionsGuard {*compileOptionsMutex}; + llvm::sys::SmartScopedLock compileOptionsGuard{*compileOptionsMutex}; try { CompileOptionsParser optionsParser("200");