Coverage Report

Created: 2020-09-22 08:39

/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
10.4M
      :Supported(S), Enabled(E), Avail(A), Core(C){}
32
  };
33
  llvm::StringMap<Info> OptMap;
34
public:
35
2.31k
  bool isKnown(llvm::StringRef Ext) const {
36
2.31k
    return OptMap.find(Ext) != OptMap.end();
37
2.31k
  }
38
39
111k
  bool isEnabled(llvm::StringRef Ext) const {
40
111k
    return OptMap.find(Ext)->second.Enabled;
41
111k
  }
42
43
  // Is supported as either an extension or an (optional) core feature for
44
  // OpenCL version \p CLVer.
45
31.8k
  bool isSupported(llvm::StringRef Ext, const LangOptions &LO) const {
46
    // In C++ mode all extensions should work at least as in v2.0.
47
28.2k
    auto CLVer = LO.OpenCLCPlusPlus ? 
2003.59k
: LO.OpenCLVersion;
48
31.8k
    auto I = OptMap.find(Ext)->getValue();
49
31.8k
    return I.Supported && 
I.Avail <= CLVer22.7k
;
50
31.8k
  }
51
52
  // Is supported (optional) OpenCL core features for OpenCL version \p CLVer.
53
  // For supported extension, return false.
54
30.3k
  bool isSupportedCore(llvm::StringRef Ext, const LangOptions &LO) const {
55
    // In C++ mode all extensions should work at least as in v2.0.
56
26.7k
    auto CLVer = LO.OpenCLCPlusPlus ? 
2003.65k
: LO.OpenCLVersion;
57
30.3k
    auto I = OptMap.find(Ext)->getValue();
58
30.3k
    return I.Supported && 
I.Avail <= CLVer22.6k
&&
I.Core != ~0U16.1k
&&
CLVer >= I.Core4.66k
;
59
30.3k
  }
60
61
  // Is supported OpenCL extension for OpenCL version \p CLVer.
62
  // For supported (optional) core feature, return false.
63
2.21k
  bool isSupportedExtension(llvm::StringRef Ext, const LangOptions &LO) const {
64
    // In C++ mode all extensions should work at least as in v2.0.
65
2.09k
    auto CLVer = LO.OpenCLCPlusPlus ? 
200125
: LO.OpenCLVersion;
66
2.21k
    auto I = OptMap.find(Ext)->getValue();
67
2.21k
    return I.Supported && 
I.Avail <= CLVer1.23k
&&
(1.08k
I.Core == ~0U1.08k
||
CLVer < I.Core425
);
68
2.21k
  }
69
70
812
  void enable(llvm::StringRef Ext, bool V = true) {
71
812
    OptMap[Ext].Enabled = V;
72
812
  }
73
74
  /// Enable or disable support for OpenCL extensions
75
  /// \param Ext name of the extension optionally prefixed with
76
  ///        '+' or '-'
77
  /// \param V used when \p Ext is not prefixed by '+' or '-'
78
8.53k
  void support(llvm::StringRef Ext, bool V = true) {
79
8.53k
    assert(!Ext.empty() && "Extension is empty.");
80
81
8.53k
    switch (Ext[0]) {
82
16
    case '+':
83
16
      V = true;
84
16
      Ext = Ext.drop_front();
85
16
      break;
86
12
    case '-':
87
12
      V = false;
88
12
      Ext = Ext.drop_front();
89
12
      break;
90
8.53k
    }
91
92
8.53k
    if (Ext.equals("all")) {
93
6
      supportAll(V);
94
6
      return;
95
6
    }
96
8.52k
    OptMap[Ext].Supported = V;
97
8.52k
  }
98
99
212k
  OpenCLOptions(){
100
212k
#define OPENCLEXT_INTERNAL(Ext, AvailVer, CoreVer) \
101
10.4M
    OptMap[#Ext].Avail = AvailVer; \
102
10.4M
    OptMap[#Ext].Core = CoreVer;
103
212k
#include "clang/Basic/OpenCLExtensions.def"
104
212k
  }
105
106
566
  void addSupport(const OpenCLOptions &Opts) {
107
566
    for (auto &I:Opts.OptMap)
108
27.7k
      if (I.second.Supported)
109
21.2k
        OptMap[I.getKey()].Supported = true;
110
566
  }
111
112
12.2k
  void copy(const OpenCLOptions &Opts) {
113
12.2k
    OptMap = Opts.OptMap;
114
12.2k
  }
115
116
  // Turn on or off support of all options.
117
79.7k
  void supportAll(bool On = true) {
118
79.7k
    for (llvm::StringMap<Info>::iterator I = OptMap.begin(),
119
3.98M
         E = OptMap.end(); I != E; 
++I3.90M
)
120
3.90M
      I->second.Supported = On;
121
79.7k
  }
122
123
25
  void disableAll() {
124
25
    for (llvm::StringMap<Info>::iterator I = OptMap.begin(),
125
1.26k
         E = OptMap.end(); I != E; 
++I1.24k
)
126
1.24k
      I->second.Enabled = false;
127
25
  }
128
129
591
  void enableSupportedCore(LangOptions LO) {
130
591
    for (llvm::StringMap<Info>::iterator I = OptMap.begin(), E = OptMap.end();
131
29.5k
         I != E; 
++I28.9k
)
132
28.9k
      if (isSupportedCore(I->getKey(), LO))
133
2.47k
        I->second.Enabled = true;
134
591
  }
135
136
  friend class ASTWriter;
137
  friend class ASTReader;
138
};
139
140
} // end namespace clang
141
142
#endif