
Currently, there is some refactoring needed in existing interface of OpenCL option settings to support OpenCL C 3.0. The problem is that OpenCL extensions and features are not only determined by the target platform but also by the OpenCL version. Also, there are core extensions/features which are supported unconditionally in specific OpenCL C version. In fact, these rules are not being followed for all targets. For example, there are some targets (as nvptx and r600) which don't support OpenCL C 2.0 core features (nvptx.languageOptsOpenCL.cl, r600.languageOptsOpenCL.cl). After the change there will be explicit differentiation between optional core and core OpenCL features which allows giving diagnostics if target doesn't support any of necessary core features for specific OpenCL version. This patch also eliminates `OpenCLOptions` instance duplication from `TargetOptions`. `OpenCLOptions` instance should take place in `Sema` as it's going to be modified during parsing. Removing this duplication will also allow to generally simplify `OpenCLOptions` class for parsing purposes. Reviewed By: Anastasia Differential Revision: https://reviews.llvm.org/D92277
107 lines
3.3 KiB
C++
107 lines
3.3 KiB
C++
//===--- OpenCLOptions.cpp---------------------------------------*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "clang/Basic/OpenCLOptions.h"
|
|
|
|
namespace clang {
|
|
|
|
bool OpenCLOptions::isKnown(llvm::StringRef Ext) const {
|
|
return OptMap.find(Ext) != OptMap.end();
|
|
}
|
|
|
|
bool OpenCLOptions::isEnabled(llvm::StringRef Ext) const {
|
|
auto E = OptMap.find(Ext);
|
|
return E != OptMap.end() && E->second.Enabled;
|
|
}
|
|
|
|
bool OpenCLOptions::isSupported(llvm::StringRef Ext,
|
|
const LangOptions &LO) const {
|
|
auto E = OptMap.find(Ext);
|
|
if (E == OptMap.end()) {
|
|
return false;
|
|
}
|
|
auto I = OptMap.find(Ext)->getValue();
|
|
return I.Supported && I.isAvailableIn(LO);
|
|
}
|
|
|
|
bool OpenCLOptions::isSupportedCore(llvm::StringRef Ext,
|
|
const LangOptions &LO) const {
|
|
auto E = OptMap.find(Ext);
|
|
if (E == OptMap.end()) {
|
|
return false;
|
|
}
|
|
auto I = OptMap.find(Ext)->getValue();
|
|
return I.Supported && I.isCoreIn(LO);
|
|
}
|
|
|
|
bool OpenCLOptions::isSupportedOptionalCore(llvm::StringRef Ext,
|
|
const LangOptions &LO) const {
|
|
auto E = OptMap.find(Ext);
|
|
if (E == OptMap.end()) {
|
|
return false;
|
|
}
|
|
auto I = OptMap.find(Ext)->getValue();
|
|
return I.Supported && I.isOptionalCoreIn(LO);
|
|
}
|
|
|
|
bool OpenCLOptions::isSupportedCoreOrOptionalCore(llvm::StringRef Ext,
|
|
const LangOptions &LO) const {
|
|
return isSupportedCore(Ext, LO) || isSupportedOptionalCore(Ext, LO);
|
|
}
|
|
|
|
bool OpenCLOptions::isSupportedExtension(llvm::StringRef Ext,
|
|
const LangOptions &LO) const {
|
|
auto E = OptMap.find(Ext);
|
|
if (E == OptMap.end()) {
|
|
return false;
|
|
}
|
|
auto I = OptMap.find(Ext)->getValue();
|
|
return I.Supported && I.isAvailableIn(LO) &&
|
|
!isSupportedCoreOrOptionalCore(Ext, LO);
|
|
}
|
|
|
|
void OpenCLOptions::enable(llvm::StringRef Ext, bool V) {
|
|
OptMap[Ext].Enabled = V;
|
|
}
|
|
|
|
void OpenCLOptions::support(llvm::StringRef Ext, bool V) {
|
|
assert(!Ext.empty() && "Extension is empty.");
|
|
assert(Ext[0] != '+' && Ext[0] != '-');
|
|
OptMap[Ext].Supported = V;
|
|
}
|
|
|
|
OpenCLOptions::OpenCLOptions() {
|
|
#define OPENCL_GENERIC_EXTENSION(Ext, AvailVer, CoreVer, OptVer) \
|
|
OptMap[#Ext].Avail = AvailVer; \
|
|
OptMap[#Ext].Core = CoreVer; \
|
|
OptMap[#Ext].Opt = OptVer;
|
|
#include "clang/Basic/OpenCLExtensions.def"
|
|
}
|
|
|
|
void OpenCLOptions::addSupport(const llvm::StringMap<bool> &FeaturesMap,
|
|
const LangOptions &Opts) {
|
|
for (const auto &F : FeaturesMap) {
|
|
const auto &Name = F.getKey();
|
|
if (F.getValue() && isKnown(Name) && OptMap[Name].isAvailableIn(Opts))
|
|
support(Name);
|
|
}
|
|
}
|
|
|
|
void OpenCLOptions::disableAll() {
|
|
for (auto &Opt : OptMap)
|
|
Opt.getValue().Enabled = false;
|
|
}
|
|
|
|
void OpenCLOptions::enableSupportedCore(const LangOptions &LO) {
|
|
for (auto &Opt : OptMap)
|
|
if (isSupportedCoreOrOptionalCore(Opt.getKey(), LO))
|
|
Opt.getValue().Enabled = true;
|
|
}
|
|
|
|
} // end namespace clang
|