Skip to content

Make feature macro undefs conditional on -cl-ext input #435

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 1 commit into from
May 17, 2023
Merged
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
20 changes: 20 additions & 0 deletions 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/SmallSet.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
Expand Down Expand Up @@ -306,11 +307,30 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args,
it->second = enabled;
}
};
llvm::SmallSet<llvm::StringRef, 32> parsedOclCFeatures;
std::for_each(effectiveArgs.begin(), effectiveArgs.end(),
[&](const ArgsVector::value_type &a) {
if (a.find("-cl-ext=") == 0)
parseClExt(a);
else if (a.find("-D__opencl_c_") == 0)
parsedOclCFeatures.insert(a);
});

// "opencl-c-base.h" unconditionally enables a list of so-called "optional
// core" language features. We need to undef those that aren't explicitly
// defined within the compilation command (which would suggest that the
// target platform supports the corresponding feature).
const char* optionalCoreOclCFeaturesList[] = {
"__opencl_c_work_group_collective_functions",
"__opencl_c_atomic_order_seq_cst",
"__opencl_c_atomic_scope_device",
"__opencl_c_atomic_scope_all_devices",
"__opencl_c_read_write_images" };
for (std::string OclCFeature : optionalCoreOclCFeaturesList) {
if (!parsedOclCFeatures.contains(std::string("-D") + OclCFeature))
effectiveArgs.push_back(std::string("-D__undef_") + OclCFeature);
}

// extension is enabled in PCH but disabled or not specifed in options =>
// disable pch
bool useModules =
Expand Down