1 //===--- OpenCLOptions.cpp---------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "clang/Basic/OpenCLOptions.h" 10 11 namespace clang { 12 13 bool OpenCLOptions::isKnown(llvm::StringRef Ext) const { 14 return OptMap.find(Ext) != OptMap.end(); 15 } 16 17 bool OpenCLOptions::isEnabled(llvm::StringRef Ext) const { 18 auto E = OptMap.find(Ext); 19 return E != OptMap.end() && E->second.Enabled; 20 } 21 22 bool OpenCLOptions::isSupported(llvm::StringRef Ext, 23 const LangOptions &LO) const { 24 auto E = OptMap.find(Ext); 25 if (E == OptMap.end()) { 26 return false; 27 } 28 auto I = OptMap.find(Ext)->getValue(); 29 return I.Supported && I.isAvailableIn(LO); 30 } 31 32 bool OpenCLOptions::isSupportedCore(llvm::StringRef Ext, 33 const LangOptions &LO) const { 34 auto E = OptMap.find(Ext); 35 if (E == OptMap.end()) { 36 return false; 37 } 38 auto I = OptMap.find(Ext)->getValue(); 39 return I.Supported && I.isCoreIn(LO); 40 } 41 42 bool OpenCLOptions::isSupportedOptionalCore(llvm::StringRef Ext, 43 const LangOptions &LO) const { 44 auto E = OptMap.find(Ext); 45 if (E == OptMap.end()) { 46 return false; 47 } 48 auto I = OptMap.find(Ext)->getValue(); 49 return I.Supported && I.isOptionalCoreIn(LO); 50 } 51 52 bool OpenCLOptions::isSupportedCoreOrOptionalCore(llvm::StringRef Ext, 53 const LangOptions &LO) const { 54 return isSupportedCore(Ext, LO) || isSupportedOptionalCore(Ext, LO); 55 } 56 57 bool OpenCLOptions::isSupportedExtension(llvm::StringRef Ext, 58 const LangOptions &LO) const { 59 auto E = OptMap.find(Ext); 60 if (E == OptMap.end()) { 61 return false; 62 } 63 auto I = OptMap.find(Ext)->getValue(); 64 return I.Supported && I.isAvailableIn(LO) && 65 !isSupportedCoreOrOptionalCore(Ext, LO); 66 } 67 68 void OpenCLOptions::enable(llvm::StringRef Ext, bool V) { 69 OptMap[Ext].Enabled = V; 70 } 71 72 void OpenCLOptions::support(llvm::StringRef Ext, bool V) { 73 assert(!Ext.empty() && "Extension is empty."); 74 assert(Ext[0] != '+' && Ext[0] != '-'); 75 OptMap[Ext].Supported = V; 76 } 77 78 OpenCLOptions::OpenCLOptions() { 79 #define OPENCL_GENERIC_EXTENSION(Ext, AvailVer, CoreVer, OptVer) \ 80 OptMap[#Ext].Avail = AvailVer; \ 81 OptMap[#Ext].Core = CoreVer; \ 82 OptMap[#Ext].Opt = OptVer; 83 #include "clang/Basic/OpenCLExtensions.def" 84 } 85 86 void OpenCLOptions::addSupport(const llvm::StringMap<bool> &FeaturesMap, 87 const LangOptions &Opts) { 88 for (const auto &F : FeaturesMap) { 89 const auto &Name = F.getKey(); 90 if (F.getValue() && isKnown(Name) && OptMap[Name].isAvailableIn(Opts)) 91 support(Name); 92 } 93 } 94 95 void OpenCLOptions::disableAll() { 96 for (auto &Opt : OptMap) 97 Opt.getValue().Enabled = false; 98 } 99 100 void OpenCLOptions::enableSupportedCore(const LangOptions &LO) { 101 for (auto &Opt : OptMap) 102 if (isSupportedCoreOrOptionalCore(Opt.getKey(), LO)) 103 Opt.getValue().Enabled = true; 104 } 105 106 } // end namespace clang 107