1 //===--- OpenCLOptions.h ----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief Defines the clang::OpenCLOptions class.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_BASIC_OPENCLOPTIONS_H
16 #define LLVM_CLANG_BASIC_OPENCLOPTIONS_H
18 #include "llvm/ADT/StringMap.h"
22 /// \brief OpenCL supported extensions and optional core features
25 bool Supported; // Is this option supported
26 bool Enabled; // Is this option enabled
27 unsigned Avail; // Option starts to be available in this OpenCL version
28 unsigned Core; // Option becomes (optional) core feature in this OpenCL
30 Info(bool S = false, bool E = false, unsigned A = 100, unsigned C = ~0U)
31 :Supported(S), Enabled(E), Avail(A), Core(C){}
33 llvm::StringMap<Info> OptMap;
35 bool isKnown(llvm::StringRef Ext) const {
36 return OptMap.find(Ext) != OptMap.end();
39 bool isEnabled(llvm::StringRef Ext) const {
40 return OptMap.find(Ext)->second.Enabled;
43 // Is supported as either an extension or an (optional) core feature for
44 // OpenCL version \p CLVer.
45 bool isSupported(llvm::StringRef Ext, unsigned CLVer) const {
46 auto I = OptMap.find(Ext)->getValue();
47 return I.Supported && I.Avail <= CLVer;
50 // Is supported (optional) OpenCL core features for OpenCL version \p CLVer.
51 // For supported extension, return false.
52 bool isSupportedCore(llvm::StringRef Ext, unsigned CLVer) const {
53 auto I = OptMap.find(Ext)->getValue();
54 return I.Supported && I.Avail <= CLVer &&
55 I.Core != ~0U && CLVer >= I.Core;
58 // Is supported OpenCL extension for OpenCL version \p CLVer.
59 // For supported (optional) core feature, return false.
60 bool isSupportedExtension(llvm::StringRef Ext, unsigned CLVer) const {
61 auto I = OptMap.find(Ext)->getValue();
62 return I.Supported && I.Avail <= CLVer &&
63 (I.Core == ~0U || CLVer < I.Core);
66 void enable(llvm::StringRef Ext, bool V = true) {
67 OptMap[Ext].Enabled = V;
70 /// \brief Enable or disable support for OpenCL extensions
71 /// \param Ext name of the extension optionally prefixed with
73 /// \param V used when \p Ext is not prefixed by '+' or '-'
74 void support(llvm::StringRef Ext, bool V = true) {
75 assert(!Ext.empty() && "Extension is empty.");
80 Ext = Ext.drop_front();
84 Ext = Ext.drop_front();
88 if (Ext.equals("all")) {
92 OptMap[Ext].Supported = V;
96 #define OPENCLEXT_INTERNAL(Ext, AvailVer, CoreVer) \
97 OptMap[#Ext].Avail = AvailVer; \
98 OptMap[#Ext].Core = CoreVer;
99 #include "clang/Basic/OpenCLExtensions.def"
102 void addSupport(const OpenCLOptions &Opts) {
103 for (auto &I:Opts.OptMap)
104 if (I.second.Supported)
105 OptMap[I.getKey()].Supported = true;
108 void copy(const OpenCLOptions &Opts) {
109 OptMap = Opts.OptMap;
112 // Turn on or off support of all options.
113 void supportAll(bool On = true) {
114 for (llvm::StringMap<Info>::iterator I = OptMap.begin(),
115 E = OptMap.end(); I != E; ++I)
116 I->second.Supported = On;
120 for (llvm::StringMap<Info>::iterator I = OptMap.begin(),
121 E = OptMap.end(); I != E; ++I)
122 I->second.Enabled = false;
125 void enableSupportedCore(unsigned CLVer) {
126 for (llvm::StringMap<Info>::iterator I = OptMap.begin(),
127 E = OptMap.end(); I != E; ++I)
128 if (isSupportedCore(I->getKey(), CLVer))
129 I->second.Enabled = true;
132 friend class ASTWriter;
133 friend class ASTReader;
136 } // end namespace clang