Skip to content

Update PCH enable logic #396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ if (NOT DEFINED COMMON_CLANG_LIBRARY_NAME)
endif()
set(TARGET_NAME ${COMMON_CLANG_LIBRARY_NAME}${BUILD_PLATFORM} )

# PCH_EXTENSION can override PCH extension map in options_compile.cpp.
# Example: "cl_khr_3d_image_writes,cl_khr_depth_images"
set(PCH_EXTENSION "" CACHE STRING "Comma-separated list of OpenCL extensions")
if (NOT "${PCH_EXTENSION}" STREQUAL "")
add_definitions(-DPCH_EXTENSION="${PCH_EXTENSION}")
endif()

if(NOT USE_PREBUILT_LLVM)

if(NOT LLVM_EXTERNAL_CLANG_SOURCE_DIR)
Expand Down
24 changes: 23 additions & 1 deletion options_compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Copyright (c) Intel Corporation (2009-2017).
#include "options.h"

#include "clang/Driver/Options.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Support/ManagedStatic.h"
Expand Down Expand Up @@ -237,10 +238,30 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args,

for (auto it = effectiveArgs.begin(), end = effectiveArgs.end(); it != end;
++it) {
if (it->compare("-Dcl_khr_fp64") == 0)
if (it->compare("-Dcl_khr_fp64") == 0 || it->compare("-D cl_khr_fp64=1") == 0)
fp64Enabled = true;
else if (it->compare("-U cl_khr_fp64") == 0)
fp64Enabled = false;
// Find last position that enables or disables cl_khr_fp64
else if (it->find("cl_khr_fp64") != std::string::npos) {
auto NegFp64 = it->rfind("-cl_khr_fp64");
auto PosFp64 = it->rfind("+cl_khr_fp64");
if(NegFp64 != std::string::npos && PosFp64 != std::string::npos)
fp64Enabled = PosFp64 > NegFp64;
else if(NegFp64 != std::string::npos)
fp64Enabled = false;
else
fp64Enabled = true;
}
}

#ifdef PCH_EXTENSION
std::map<std::string, bool> extMap;
llvm::SmallVector<llvm::StringRef> extVec;
llvm::SplitString(PCH_EXTENSION, extVec, ",");
for(auto ext : extVec)
extMap.insert({ext.str(), true});
#else
std::map<std::string, bool> extMap{
{"cl_khr_3d_image_writes", true},
{"cl_khr_depth_images", true},
Expand All @@ -262,6 +283,7 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args,
{"cl_intel_planar_yuv", true},
{"cl_intel_subgroups", true},
{"cl_intel_subgroups_short", true}};
#endif

auto parseClExt = [&](const std::string &clExtStr) {
llvm::StringRef clExtRef(clExtStr);
Expand Down