aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Basic/OpenCLOptions.cpp
diff options
context:
space:
mode:
authorAnton Zabaznov <anton.zabaznov@intel.com>2021-01-25 19:23:58 +0300
committerAnton Zabaznov <anton.zabaznov@intel.com>2021-01-25 19:50:23 +0300
commite123cd674c0209c80bc6225bb9e3a2d1d2ee418b (patch)
tree82bbba9d986dbe8b4ea2455a550e9edbe234d420 /clang/lib/Basic/OpenCLOptions.cpp
parent17c3538aef656178b342573043eff328f5cf2673 (diff)
downloadllvm-e123cd674c0209c80bc6225bb9e3a2d1d2ee418b.zip
llvm-e123cd674c0209c80bc6225bb9e3a2d1d2ee418b.tar.gz
llvm-e123cd674c0209c80bc6225bb9e3a2d1d2ee418b.tar.bz2
[OpenCL] Refactor of targets OpenCL option settings
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
Diffstat (limited to 'clang/lib/Basic/OpenCLOptions.cpp')
-rw-r--r--clang/lib/Basic/OpenCLOptions.cpp106
1 files changed, 106 insertions, 0 deletions
diff --git a/clang/lib/Basic/OpenCLOptions.cpp b/clang/lib/Basic/OpenCLOptions.cpp
new file mode 100644
index 0000000..266acc5
--- /dev/null
+++ b/clang/lib/Basic/OpenCLOptions.cpp
@@ -0,0 +1,106 @@
+//===--- 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