diff options
Diffstat (limited to 'contrib/llvm-project/clang/include/clang/Basic/OpenCLOptions.h')
-rw-r--r-- | contrib/llvm-project/clang/include/clang/Basic/OpenCLOptions.h | 213 |
1 files changed, 118 insertions, 95 deletions
diff --git a/contrib/llvm-project/clang/include/clang/Basic/OpenCLOptions.h b/contrib/llvm-project/clang/include/clang/Basic/OpenCLOptions.h index 15661154eab5..fe27ef19d4d5 100644 --- a/contrib/llvm-project/clang/include/clang/Basic/OpenCLOptions.h +++ b/contrib/llvm-project/clang/include/clang/Basic/OpenCLOptions.h @@ -19,122 +19,145 @@ namespace clang { +namespace { +// This enum maps OpenCL version(s) into value. These values are used as +// a mask to indicate in which OpenCL version(s) extension is a core or +// optional core feature. +enum OpenCLVersionID : unsigned int { + OCL_C_10 = 0x1, + OCL_C_11 = 0x2, + OCL_C_12 = 0x4, + OCL_C_20 = 0x8, + OCL_C_30 = 0x10, + OCL_C_ALL = 0x1f, + OCL_C_11P = OCL_C_ALL ^ OCL_C_10, // OpenCL C 1.1+ + OCL_C_12P = OCL_C_ALL ^ (OCL_C_10 | OCL_C_11), // OpenCL C 1.2+ +}; + +static inline OpenCLVersionID encodeOpenCLVersion(unsigned OpenCLVersion) { + switch (OpenCLVersion) { + default: + llvm_unreachable("Unknown OpenCL version code"); + case 100: + return OCL_C_10; + case 110: + return OCL_C_11; + case 120: + return OCL_C_12; + case 200: + return OCL_C_20; + case 300: + return OCL_C_30; + } +} + +// Simple helper to check if OpenCL C version is contained in a given encoded +// OpenCL C version mask +static inline bool isOpenCLVersionIsContainedInMask(const LangOptions &LO, + unsigned Mask) { + auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion; + OpenCLVersionID Code = encodeOpenCLVersion(CLVer); + return Mask & Code; +} +} // end anonymous namespace + /// OpenCL supported extensions and optional core features class OpenCLOptions { - struct Info { - bool Supported; // Is this option supported - bool Enabled; // Is this option enabled - unsigned Avail; // Option starts to be available in this OpenCL version - unsigned Core; // Option becomes (optional) core feature in this OpenCL - // version - Info(bool S = false, bool E = false, unsigned A = 100, unsigned C = ~0U) - :Supported(S), Enabled(E), Avail(A), Core(C){} - }; - llvm::StringMap<Info> OptMap; public: - bool isKnown(llvm::StringRef Ext) const { - return OptMap.find(Ext) != OptMap.end(); - } + struct OpenCLOptionInfo { + // Option starts to be available in this OpenCL version + unsigned Avail; - bool isEnabled(llvm::StringRef Ext) const { - return OptMap.find(Ext)->second.Enabled; - } + // Option becomes core feature in this OpenCL versions + unsigned Core; - // Is supported as either an extension or an (optional) core feature for - // OpenCL version \p CLVer. - bool isSupported(llvm::StringRef Ext, const LangOptions &LO) const { - // In C++ mode all extensions should work at least as in v2.0. - auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion; - auto I = OptMap.find(Ext)->getValue(); - return I.Supported && I.Avail <= CLVer; - } + // Option becomes optional core feature in this OpenCL versions + unsigned Opt; - // Is supported (optional) OpenCL core features for OpenCL version \p CLVer. - // For supported extension, return false. - bool isSupportedCore(llvm::StringRef Ext, const LangOptions &LO) const { - // In C++ mode all extensions should work at least as in v2.0. - auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion; - auto I = OptMap.find(Ext)->getValue(); - return I.Supported && I.Avail <= CLVer && I.Core != ~0U && CLVer >= I.Core; - } + // Is this option supported + bool Supported = false; - // Is supported OpenCL extension for OpenCL version \p CLVer. - // For supported (optional) core feature, return false. - bool isSupportedExtension(llvm::StringRef Ext, const LangOptions &LO) const { - // In C++ mode all extensions should work at least as in v2.0. - auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion; - auto I = OptMap.find(Ext)->getValue(); - return I.Supported && I.Avail <= CLVer && (I.Core == ~0U || CLVer < I.Core); - } + // Is this option enabled + bool Enabled = false; - void enable(llvm::StringRef Ext, bool V = true) { - OptMap[Ext].Enabled = V; - } + OpenCLOptionInfo(unsigned A = 100, unsigned C = 0U, unsigned O = 0U) + : Avail(A), Core(C), Opt(O) {} - /// Enable or disable support for OpenCL extensions - /// \param Ext name of the extension optionally prefixed with - /// '+' or '-' - /// \param V used when \p Ext is not prefixed by '+' or '-' - void support(llvm::StringRef Ext, bool V = true) { - assert(!Ext.empty() && "Extension is empty."); - - switch (Ext[0]) { - case '+': - V = true; - Ext = Ext.drop_front(); - break; - case '-': - V = false; - Ext = Ext.drop_front(); - break; + bool isCore() const { return Core != 0U; } + + bool isOptionalCore() const { return Opt != 0U; } + + // Is option available in OpenCL version \p LO. + bool isAvailableIn(const LangOptions &LO) const { + // In C++ mode all extensions should work at least as in v2.0. + auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion; + return CLVer >= Avail; } - if (Ext.equals("all")) { - supportAll(V); - return; + // Is core option in OpenCL version \p LO. + bool isCoreIn(const LangOptions &LO) const { + return isAvailableIn(LO) && isOpenCLVersionIsContainedInMask(LO, Core); } - OptMap[Ext].Supported = V; - } - OpenCLOptions(){ -#define OPENCLEXT_INTERNAL(Ext, AvailVer, CoreVer) \ - OptMap[#Ext].Avail = AvailVer; \ - OptMap[#Ext].Core = CoreVer; -#include "clang/Basic/OpenCLExtensions.def" - } + // Is optional core option in OpenCL version \p LO. + bool isOptionalCoreIn(const LangOptions &LO) const { + return isAvailableIn(LO) && isOpenCLVersionIsContainedInMask(LO, Opt); + } + }; - void addSupport(const OpenCLOptions &Opts) { - for (auto &I:Opts.OptMap) - if (I.second.Supported) - OptMap[I.getKey()].Supported = true; - } + bool isKnown(llvm::StringRef Ext) const; - void copy(const OpenCLOptions &Opts) { - OptMap = Opts.OptMap; - } + bool isEnabled(llvm::StringRef Ext) const; - // Turn on or off support of all options. - void supportAll(bool On = true) { - for (llvm::StringMap<Info>::iterator I = OptMap.begin(), - E = OptMap.end(); I != E; ++I) - I->second.Supported = On; - } + // Is supported as either an extension or an (optional) core feature for + // OpenCL version \p LO. + bool isSupported(llvm::StringRef Ext, const LangOptions &LO) const; - void disableAll() { - for (llvm::StringMap<Info>::iterator I = OptMap.begin(), - E = OptMap.end(); I != E; ++I) - I->second.Enabled = false; - } + // Is supported OpenCL core feature for OpenCL version \p LO. + // For supported extension, return false. + bool isSupportedCore(llvm::StringRef Ext, const LangOptions &LO) const; - void enableSupportedCore(LangOptions LO) { - for (llvm::StringMap<Info>::iterator I = OptMap.begin(), E = OptMap.end(); - I != E; ++I) - if (isSupportedCore(I->getKey(), LO)) - I->second.Enabled = true; - } + // Is supported optional core OpenCL feature for OpenCL version \p LO. + // For supported extension, return false. + bool isSupportedOptionalCore(llvm::StringRef Ext, + const LangOptions &LO) const; + + // Is supported optional core or core OpenCL feature for OpenCL version \p + // LO. For supported extension, return false. + bool isSupportedCoreOrOptionalCore(llvm::StringRef Ext, + const LangOptions &LO) const; + + // Is supported OpenCL extension for OpenCL version \p LO. + // For supported core or optional core feature, return false. + bool isSupportedExtension(llvm::StringRef Ext, const LangOptions &LO) const; + + void enable(llvm::StringRef Ext, bool V = true); + + /// Enable or disable support for OpenCL extensions + /// \param Ext name of the extension (not prefixed with '+' or '-') + /// \param V value to set for a extension + void support(llvm::StringRef Ext, bool V = true); + + OpenCLOptions(); + OpenCLOptions(const OpenCLOptions &) = default; + + // Set supported options based on target settings and language version + void addSupport(const llvm::StringMap<bool> &FeaturesMap, + const LangOptions &Opts); + + // Disable all extensions + void disableAll(); + + // Enable supported core and optional core features + void enableSupportedCore(const LangOptions &LO); friend class ASTWriter; friend class ASTReader; + + using OpenCLOptionInfoMap = llvm::StringMap<OpenCLOptionInfo>; + +private: + OpenCLOptionInfoMap OptMap; }; } // end namespace clang |