File indexing completed on 2026-05-10 08:36:50
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_CLANG_BASIC_OPENCLOPTIONS_H
0015 #define LLVM_CLANG_BASIC_OPENCLOPTIONS_H
0016
0017 #include "clang/Basic/LangOptions.h"
0018 #include "llvm/ADT/StringMap.h"
0019
0020 namespace clang {
0021
0022 class DiagnosticsEngine;
0023 class TargetInfo;
0024
0025 namespace {
0026
0027
0028
0029 enum OpenCLVersionID : unsigned int {
0030 OCL_C_10 = 0x1,
0031 OCL_C_11 = 0x2,
0032 OCL_C_12 = 0x4,
0033 OCL_C_20 = 0x8,
0034 OCL_C_30 = 0x10,
0035 OCL_C_ALL = 0x1f,
0036 OCL_C_11P = OCL_C_ALL ^ OCL_C_10,
0037 OCL_C_12P = OCL_C_ALL ^ (OCL_C_10 | OCL_C_11),
0038 };
0039
0040 static inline OpenCLVersionID encodeOpenCLVersion(unsigned OpenCLVersion) {
0041 switch (OpenCLVersion) {
0042 default:
0043 llvm_unreachable("Unknown OpenCL version code");
0044 case 100:
0045 return OCL_C_10;
0046 case 110:
0047 return OCL_C_11;
0048 case 120:
0049 return OCL_C_12;
0050 case 200:
0051 return OCL_C_20;
0052 case 300:
0053 return OCL_C_30;
0054 }
0055 }
0056
0057
0058
0059 static inline bool isOpenCLVersionContainedInMask(const LangOptions &LO,
0060 unsigned Mask) {
0061 auto CLVer = LO.getOpenCLCompatibleVersion();
0062 OpenCLVersionID Code = encodeOpenCLVersion(CLVer);
0063 return Mask & Code;
0064 }
0065
0066 }
0067
0068
0069 class OpenCLOptions {
0070
0071 public:
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081 bool areProgramScopeVariablesSupported(const LangOptions &Opts) const {
0082 return Opts.getOpenCLCompatibleVersion() == 200 ||
0083 (Opts.getOpenCLCompatibleVersion() == 300 &&
0084 isSupported("__opencl_c_program_scope_global_variables", Opts));
0085 }
0086
0087 struct OpenCLOptionInfo {
0088
0089 bool WithPragma = false;
0090
0091
0092 unsigned Avail = 100U;
0093
0094
0095 unsigned Core = 0U;
0096
0097
0098 unsigned Opt = 0U;
0099
0100
0101 bool Supported = false;
0102
0103
0104 bool Enabled = false;
0105
0106 OpenCLOptionInfo() = default;
0107 OpenCLOptionInfo(bool Pragma, unsigned AvailV, unsigned CoreV,
0108 unsigned OptV)
0109 : WithPragma(Pragma), Avail(AvailV), Core(CoreV), Opt(OptV) {}
0110
0111 bool isCore() const { return Core != 0U; }
0112
0113 bool isOptionalCore() const { return Opt != 0U; }
0114
0115
0116 bool isAvailableIn(const LangOptions &LO) const {
0117
0118 return LO.getOpenCLCompatibleVersion() >= Avail;
0119 }
0120
0121
0122 bool isCoreIn(const LangOptions &LO) const {
0123 return isAvailableIn(LO) && isOpenCLVersionContainedInMask(LO, Core);
0124 }
0125
0126
0127 bool isOptionalCoreIn(const LangOptions &LO) const {
0128 return isAvailableIn(LO) && isOpenCLVersionContainedInMask(LO, Opt);
0129 }
0130 };
0131
0132 bool isKnown(llvm::StringRef Ext) const;
0133
0134
0135
0136
0137 bool isAvailableOption(llvm::StringRef Ext, const LangOptions &LO) const;
0138
0139 bool isWithPragma(llvm::StringRef Ext) const;
0140
0141
0142
0143 bool isSupported(llvm::StringRef Ext, const LangOptions &LO) const;
0144
0145
0146
0147 bool isSupportedCore(llvm::StringRef Ext, const LangOptions &LO) const;
0148
0149
0150
0151 bool isSupportedOptionalCore(llvm::StringRef Ext,
0152 const LangOptions &LO) const;
0153
0154
0155
0156 bool isSupportedCoreOrOptionalCore(llvm::StringRef Ext,
0157 const LangOptions &LO) const;
0158
0159
0160
0161 bool isSupportedExtension(llvm::StringRef Ext, const LangOptions &LO) const;
0162
0163
0164
0165
0166 void acceptsPragma(llvm::StringRef Ext, bool V = true);
0167
0168 void enable(llvm::StringRef Ext, bool V = true);
0169
0170
0171
0172
0173 void support(llvm::StringRef Ext, bool V = true);
0174
0175 OpenCLOptions();
0176
0177
0178 void addSupport(const llvm::StringMap<bool> &FeaturesMap,
0179 const LangOptions &Opts);
0180
0181
0182 void disableAll();
0183
0184 friend class ASTWriter;
0185 friend class ASTReader;
0186
0187 using OpenCLOptionInfoMap = llvm::StringMap<OpenCLOptionInfo>;
0188
0189 template <typename... Args>
0190 static bool isOpenCLOptionCoreIn(const LangOptions &LO, Args &&... args) {
0191 return OpenCLOptionInfo(std::forward<Args>(args)...).isCoreIn(LO);
0192 }
0193
0194 template <typename... Args>
0195 static bool isOpenCLOptionAvailableIn(const LangOptions &LO,
0196 Args &&... args) {
0197 return OpenCLOptionInfo(std::forward<Args>(args)...).isAvailableIn(LO);
0198 }
0199
0200
0201
0202 static bool diagnoseUnsupportedFeatureDependencies(const TargetInfo &TI,
0203 DiagnosticsEngine &Diags);
0204
0205
0206
0207 static bool diagnoseFeatureExtensionDifferences(const TargetInfo &TI,
0208 DiagnosticsEngine &Diags);
0209
0210 private:
0211
0212 bool isEnabled(llvm::StringRef Ext) const;
0213
0214 OpenCLOptionInfoMap OptMap;
0215 };
0216
0217 }
0218
0219 #endif