summaryrefslogtreecommitdiffstats
path: root/include/clang/Basic/OpenCLOptions.h
diff options
context:
space:
mode:
authorAlexey Bader <aleksey.bader@mail.ru>2016-11-01 15:50:52 +0000
committerAlexey Bader <aleksey.bader@mail.ru>2016-11-01 15:50:52 +0000
commit63cbcdadcc74a3a6e0ff9f76028758ce97741203 (patch)
treed554412ac39a4551ca9cd3b2b8260d1dc2f97389 /include/clang/Basic/OpenCLOptions.h
parent1cd2ec853d7d1b67c182989921a27fc875e36ffb (diff)
[OpenCL] Override supported OpenCL extensions with -cl-ext option
Summary: This patch adds a command line option '-cl-ext' to control a set of supported OpenCL extensions. Option accepts a comma-separated list of extensions prefixed with '+' or '-'. It can be used together with a target triple to override support for some extensions: // spir target supports all extensions, but we want to disable fp64 clang -cc1 -triple spir-unknown-unknown -cl-ext=-cl_khr_fp64 Special 'all' extension allows to enable or disable all possible extensions: // only fp64 will be supported clang -cc1 -triple spir-unknown-unknown -cl-ext=-all,+cl_khr_fp64 Patch by asavonic (Andrew Savonichev). Reviewers: joey, yaxunl Subscribers: yaxunl, bader, Anastasia, cfe-commits Differential Revision: https://reviews.llvm.org/D23712 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285700 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic/OpenCLOptions.h')
-rw-r--r--include/clang/Basic/OpenCLOptions.h38
1 files changed, 35 insertions, 3 deletions
diff --git a/include/clang/Basic/OpenCLOptions.h b/include/clang/Basic/OpenCLOptions.h
index 4a629c97ff..fa52ae723f 100644
--- a/include/clang/Basic/OpenCLOptions.h
+++ b/include/clang/Basic/OpenCLOptions.h
@@ -15,6 +15,8 @@
#ifndef LLVM_CLANG_BASIC_OPENCLOPTIONS_H
#define LLVM_CLANG_BASIC_OPENCLOPTIONS_H
+#include "llvm/ADT/StringRef.h"
+
namespace clang {
/// \brief OpenCL supported extensions and optional core features
@@ -28,9 +30,39 @@ public:
#include "clang/Basic/OpenCLExtensions.def"
}
- // Enable all options.
- void setAll() {
-#define OPENCLEXT(nm) nm = 1;
+ // Enable or disable all options.
+ void setAll(bool Enable = true) {
+#define OPENCLEXT(nm) nm = Enable;
+#include "clang/Basic/OpenCLExtensions.def"
+ }
+
+ /// \brief Enable or disable support for OpenCL extensions
+ /// \param Ext name of the extension optionally prefixed with
+ /// '+' or '-'
+ /// \param Enable used when \p Ext is not prefixed by '+' or '-'
+ void set(llvm::StringRef Ext, bool Enable = true) {
+ assert(!Ext.empty() && "Extension is empty.");
+
+ switch (Ext[0]) {
+ case '+':
+ Enable = true;
+ Ext = Ext.drop_front();
+ break;
+ case '-':
+ Enable = false;
+ Ext = Ext.drop_front();
+ break;
+ }
+
+ if (Ext.equals("all")) {
+ setAll(Enable);
+ return;
+ }
+
+#define OPENCLEXT(nm) \
+ if (Ext.equals(#nm)) { \
+ nm = Enable; \
+ }
#include "clang/Basic/OpenCLExtensions.def"
}