/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/Basic/OpenCLOptions.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===--- OpenCLOptions.h ----------------------------------------*- 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 | | /// \file |
10 | | /// Defines the clang::OpenCLOptions class. |
11 | | /// |
12 | | //===----------------------------------------------------------------------===// |
13 | | |
14 | | #ifndef LLVM_CLANG_BASIC_OPENCLOPTIONS_H |
15 | | #define LLVM_CLANG_BASIC_OPENCLOPTIONS_H |
16 | | |
17 | | #include "clang/Basic/LangOptions.h" |
18 | | #include "llvm/ADT/StringMap.h" |
19 | | |
20 | | namespace clang { |
21 | | |
22 | | /// OpenCL supported extensions and optional core features |
23 | | class OpenCLOptions { |
24 | | struct Info { |
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 |
29 | | // version |
30 | | Info(bool S = false, bool E = false, unsigned A = 100, unsigned C = ~0U) |
31 | 6.27M | :Supported(S), Enabled(E), Avail(A), Core(C){} |
32 | | }; |
33 | | llvm::StringMap<Info> OptMap; |
34 | | public: |
35 | | /// Check if \c Ext is a recognized OpenCL extension. |
36 | | /// |
37 | | /// \param Ext - Extension to look up. |
38 | | /// \returns \c true if \c Ext is known, \c false otherwise. |
39 | 1.56k | bool isKnown(llvm::StringRef Ext) const { |
40 | 1.56k | return OptMap.find(Ext) != OptMap.end(); |
41 | 1.56k | } |
42 | | |
43 | | /// Check if \c Ext is an enabled OpenCL extension. |
44 | | /// |
45 | | /// \param Ext - Extension to look up. |
46 | | /// \returns \c true if \c Ext is known and enabled, \c false otherwise. |
47 | 115k | bool isEnabled(llvm::StringRef Ext) const { |
48 | 115k | auto E = OptMap.find(Ext); |
49 | 115k | return E != OptMap.end() && E->second.Enabled; |
50 | 115k | } |
51 | | |
52 | | /// Check if \c Ext is supported as either an extension or an (optional) core |
53 | | /// feature for the given OpenCL version. |
54 | | /// |
55 | | /// \param Ext - Extension to look up. |
56 | | /// \param LO - \c LangOptions specifying the OpenCL version. |
57 | | /// \returns \c true if \c Ext is known and supported, \c false otherwise. |
58 | 20.1k | bool isSupported(llvm::StringRef Ext, const LangOptions &LO) const { |
59 | 20.1k | auto E = OptMap.find(Ext); |
60 | 20.1k | if (E == OptMap.end()) { |
61 | 0 | return false; |
62 | 0 | } |
63 | | // In C++ mode all extensions should work at least as in v2.0. |
64 | 20.1k | auto CLVer = LO.OpenCLCPlusPlus ? 2002.24k : LO.OpenCLVersion17.8k ; |
65 | 20.1k | auto I = E->getValue(); |
66 | 20.1k | return I.Supported && I.Avail <= CLVer16.0k ; |
67 | 20.1k | } |
68 | | |
69 | | /// Check if \c Ext is supported as an (optional) OpenCL core features for |
70 | | /// the given OpenCL version. |
71 | | /// |
72 | | /// \param Ext - Extension to look up. |
73 | | /// \param LO - \c LangOptions specifying the OpenCL version. |
74 | | /// \returns \c true if \c Ext is known and supported, \c false otherwise. |
75 | 19.4k | bool isSupportedCore(llvm::StringRef Ext, const LangOptions &LO) const { |
76 | 19.4k | auto E = OptMap.find(Ext); |
77 | 19.4k | if (E == OptMap.end()) { |
78 | 0 | return false; |
79 | 0 | } |
80 | | // In C++ mode all extensions should work at least as in v2.0. |
81 | 19.4k | auto CLVer = LO.OpenCLCPlusPlus ? 2002.37k : LO.OpenCLVersion17.1k ; |
82 | 19.4k | auto I = E->getValue(); |
83 | 19.4k | return I.Supported && I.Avail <= CLVer16.1k && I.Core != ~0U13.1k && CLVer >= I.Core4.68k ; |
84 | 19.4k | } |
85 | | |
86 | | /// Check if \c Ext is a supported OpenCL extension for the given OpenCL |
87 | | /// version. |
88 | | /// |
89 | | /// \param Ext - Extension to look up. |
90 | | /// \param LO - \c LangOptions specifying the OpenCL version. |
91 | | /// \returns \c true if \c Ext is known and supported, \c false otherwise. |
92 | 1.46k | bool isSupportedExtension(llvm::StringRef Ext, const LangOptions &LO) const { |
93 | 1.46k | auto E = OptMap.find(Ext); |
94 | 1.46k | if (E == OptMap.end()) { |
95 | 0 | return false; |
96 | 0 | } |
97 | | // In C++ mode all extensions should work at least as in v2.0. |
98 | 1.46k | auto CLVer = LO.OpenCLCPlusPlus ? 20093 : LO.OpenCLVersion1.37k ; |
99 | 1.46k | auto I = E->getValue(); |
100 | 1.46k | return I.Supported && I.Avail <= CLVer1.13k && (1.07k I.Core == ~0U1.07k || CLVer < I.Core448 ); |
101 | 1.46k | } |
102 | | |
103 | 780 | void enable(llvm::StringRef Ext, bool V = true) { |
104 | 780 | OptMap[Ext].Enabled = V; |
105 | 780 | } |
106 | | |
107 | | /// Enable or disable support for OpenCL extensions |
108 | | /// \param Ext name of the extension optionally prefixed with |
109 | | /// '+' or '-' |
110 | | /// \param V used when \p Ext is not prefixed by '+' or '-' |
111 | 10.0k | void support(llvm::StringRef Ext, bool V = true) { |
112 | 10.0k | assert(!Ext.empty() && "Extension is empty."); |
113 | | |
114 | 10.0k | switch (Ext[0]) { |
115 | 16 | case '+': |
116 | 16 | V = true; |
117 | 16 | Ext = Ext.drop_front(); |
118 | 16 | break; |
119 | 12 | case '-': |
120 | 12 | V = false; |
121 | 12 | Ext = Ext.drop_front(); |
122 | 12 | break; |
123 | 10.0k | } |
124 | | |
125 | 10.0k | if (Ext.equals("all")) { |
126 | 6 | supportAll(V); |
127 | 6 | return; |
128 | 6 | } |
129 | 10.0k | OptMap[Ext].Supported = V; |
130 | 10.0k | } |
131 | | |
132 | 216k | OpenCLOptions(){ |
133 | 216k | #define OPENCLEXT_INTERNAL(Ext, AvailVer, CoreVer) \ |
134 | 6.27M | OptMap[#Ext].Avail = AvailVer; \ |
135 | 6.27M | OptMap[#Ext].Core = CoreVer; |
136 | 216k | #include "clang/Basic/OpenCLExtensions.def" |
137 | 216k | } |
138 | | |
139 | 593 | void addSupport(const OpenCLOptions &Opts) { |
140 | 593 | for (auto &I:Opts.OptMap) |
141 | 17.1k | if (I.second.Supported) |
142 | 14.3k | OptMap[I.getKey()].Supported = true; |
143 | 593 | } |
144 | | |
145 | 12.8k | void copy(const OpenCLOptions &Opts) { |
146 | 12.8k | OptMap = Opts.OptMap; |
147 | 12.8k | } |
148 | | |
149 | | // Turn on or off support of all options. |
150 | 79.7k | void supportAll(bool On = true) { |
151 | 79.7k | for (llvm::StringMap<Info>::iterator I = OptMap.begin(), |
152 | 2.39M | E = OptMap.end(); I != E; ++I2.31M ) |
153 | 2.31M | I->second.Supported = On; |
154 | 79.7k | } |
155 | | |
156 | 55 | void disableAll() { |
157 | 55 | for (llvm::StringMap<Info>::iterator I = OptMap.begin(), |
158 | 1.66k | E = OptMap.end(); I != E; ++I1.61k ) |
159 | 1.61k | I->second.Enabled = false; |
160 | 55 | } |
161 | | |
162 | 648 | void enableSupportedCore(LangOptions LO) { |
163 | 648 | for (llvm::StringMap<Info>::iterator I = OptMap.begin(), E = OptMap.end(); |
164 | 19.4k | I != E; ++I18.8k ) |
165 | 18.8k | if (isSupportedCore(I->getKey(), LO)) |
166 | 2.42k | I->second.Enabled = true; |
167 | 648 | } |
168 | | |
169 | | friend class ASTWriter; |
170 | | friend class ASTReader; |
171 | | }; |
172 | | |
173 | | } // end namespace clang |
174 | | |
175 | | #endif |