Skip to content

Commit bda7746

Browse files
author
Artem Gindinson
authored
Make feature macro undefs conditional on -cl-ext input (#435)
Cherry-pick commit 78c5e3f from `ocl-open-140` branch. Omit the Clang patch addition, as https://reviews.llvm.org/D141297 is part of LLVM 16. Signed-off-by: Artem Gindinson <[email protected]>
1 parent 1adc46e commit bda7746

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

options_compile.cpp

Lines changed: 20 additions & 0 deletions
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/SmallSet.h"
2324
#include "llvm/ADT/StringExtras.h"
2425
#include "llvm/Option/Arg.h"
2526
#include "llvm/Option/ArgList.h"
@@ -306,11 +307,30 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args,
306307
it->second = enabled;
307308
}
308309
};
310+
llvm::SmallSet<llvm::StringRef, 32> parsedOclCFeatures;
309311
std::for_each(effectiveArgs.begin(), effectiveArgs.end(),
310312
[&](const ArgsVector::value_type &a) {
311313
if (a.find("-cl-ext=") == 0)
312314
parseClExt(a);
315+
else if (a.find("-D__opencl_c_") == 0)
316+
parsedOclCFeatures.insert(a);
313317
});
318+
319+
// "opencl-c-base.h" unconditionally enables a list of so-called "optional
320+
// core" language features. We need to undef those that aren't explicitly
321+
// defined within the compilation command (which would suggest that the
322+
// target platform supports the corresponding feature).
323+
const char* optionalCoreOclCFeaturesList[] = {
324+
"__opencl_c_work_group_collective_functions",
325+
"__opencl_c_atomic_order_seq_cst",
326+
"__opencl_c_atomic_scope_device",
327+
"__opencl_c_atomic_scope_all_devices",
328+
"__opencl_c_read_write_images" };
329+
for (std::string OclCFeature : optionalCoreOclCFeaturesList) {
330+
if (!parsedOclCFeatures.contains(std::string("-D") + OclCFeature))
331+
effectiveArgs.push_back(std::string("-D__undef_") + OclCFeature);
332+
}
333+
314334
// extension is enabled in PCH but disabled or not specifed in options =>
315335
// disable pch
316336
bool useModules =

0 commit comments

Comments
 (0)