Skip to content

Commit de0ea6d

Browse files
authored
Update PCH enable logic (#396)
* Update PCH enable logic 1. Some extensions are GPU only, add macro to manage 2. Add corner cases that detects cl_khr_fp64 * Add CMake option to custom PCH extension map * Apply suggestions * Add comments * Update comments
1 parent 671615d commit de0ea6d

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ if (NOT DEFINED COMMON_CLANG_LIBRARY_NAME)
106106
endif()
107107
set(TARGET_NAME ${COMMON_CLANG_LIBRARY_NAME}${BUILD_PLATFORM} )
108108

109+
# PCH_EXTENSION can override PCH extension map in options_compile.cpp.
110+
# Example: "cl_khr_3d_image_writes,cl_khr_depth_images"
111+
set(PCH_EXTENSION "" CACHE STRING "Comma-separated list of OpenCL extensions")
112+
if (NOT "${PCH_EXTENSION}" STREQUAL "")
113+
add_definitions(-DPCH_EXTENSION="${PCH_EXTENSION}")
114+
endif()
115+
109116
if(NOT USE_PREBUILT_LLVM)
110117

111118
if(NOT LLVM_EXTERNAL_CLANG_SOURCE_DIR)

options_compile.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Copyright (c) Intel Corporation (2009-2017).
2020
#include "options.h"
2121

2222
#include "clang/Driver/Options.h"
23+
#include "llvm/ADT/StringExtras.h"
2324
#include "llvm/Option/Arg.h"
2425
#include "llvm/Option/ArgList.h"
2526
#include "llvm/Support/ManagedStatic.h"
@@ -237,10 +238,30 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args,
237238

238239
for (auto it = effectiveArgs.begin(), end = effectiveArgs.end(); it != end;
239240
++it) {
240-
if (it->compare("-Dcl_khr_fp64") == 0)
241+
if (it->compare("-Dcl_khr_fp64") == 0 || it->compare("-D cl_khr_fp64=1") == 0)
241242
fp64Enabled = true;
243+
else if (it->compare("-U cl_khr_fp64") == 0)
244+
fp64Enabled = false;
245+
// Find last position that enables or disables cl_khr_fp64
246+
else if (it->find("cl_khr_fp64") != std::string::npos) {
247+
auto NegFp64 = it->rfind("-cl_khr_fp64");
248+
auto PosFp64 = it->rfind("+cl_khr_fp64");
249+
if(NegFp64 != std::string::npos && PosFp64 != std::string::npos)
250+
fp64Enabled = PosFp64 > NegFp64;
251+
else if(NegFp64 != std::string::npos)
252+
fp64Enabled = false;
253+
else
254+
fp64Enabled = true;
255+
}
242256
}
243257

258+
#ifdef PCH_EXTENSION
259+
std::map<std::string, bool> extMap;
260+
llvm::SmallVector<llvm::StringRef> extVec;
261+
llvm::SplitString(PCH_EXTENSION, extVec, ",");
262+
for(auto ext : extVec)
263+
extMap.insert({ext.str(), true});
264+
#else
244265
std::map<std::string, bool> extMap{
245266
{"cl_khr_3d_image_writes", true},
246267
{"cl_khr_depth_images", true},
@@ -262,6 +283,7 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args,
262283
{"cl_intel_planar_yuv", true},
263284
{"cl_intel_subgroups", true},
264285
{"cl_intel_subgroups_short", true}};
286+
#endif
265287

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

0 commit comments

Comments
 (0)