Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/Basic/OpenCLOptions.h
Line
Count
Source
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
4.44M
      :Supported(S), Enabled(E), Avail(A), Core(C){}
32
  };
33
  llvm::StringMap<Info> OptMap;
34
public:
35
2.18k
  bool isKnown(llvm::StringRef Ext) const {
36
2.18k
    return OptMap.find(Ext) != OptMap.end();
37
2.18k
  }
38
39
92.7k
  bool isEnabled(llvm::StringRef Ext) const {
40
92.7k
    return OptMap.find(Ext)->second.Enabled;
41
92.7k
  }
42
43
  // Is supported as either an extension or an (optional) core feature for
44
  // OpenCL version \p CLVer.
45
25.0k
  bool isSupported(llvm::StringRef Ext, LangOptions LO) const {
46
25.0k
    // In C++ mode all extensions should work at least as in v2.0.
47
25.0k
    auto CLVer = LO.OpenCLCPlusPlus ? 
2002.26k
:
LO.OpenCLVersion22.8k
;
48
25.0k
    auto I = OptMap.find(Ext)->getValue();
49
25.0k
    return I.Supported && 
I.Avail <= CLVer17.8k
;
50
25.0k
  }
51
52
  // Is supported (optional) OpenCL core features for OpenCL version \p CLVer.
53
  // For supported extension, return false.
54
24.2k
  bool isSupportedCore(llvm::StringRef Ext, LangOptions LO) const {
55
24.2k
    // In C++ mode all extensions should work at least as in v2.0.
56
24.2k
    auto CLVer = LO.OpenCLCPlusPlus ? 
2002.31k
:
LO.OpenCLVersion21.8k
;
57
24.2k
    auto I = OptMap.find(Ext)->getValue();
58
24.2k
    return I.Supported && 
I.Avail <= CLVer17.7k
&&
I.Core != ~0U13.3k
&&
CLVer >= I.Core4.37k
;
59
24.2k
  }
60
61
  // Is supported OpenCL extension for OpenCL version \p CLVer.
62
  // For supported (optional) core feature, return false.
63
2.08k
  bool isSupportedExtension(llvm::StringRef Ext, LangOptions LO) const {
64
2.08k
    // In C++ mode all extensions should work at least as in v2.0.
65
2.08k
    auto CLVer = LO.OpenCLCPlusPlus ? 
20096
:
LO.OpenCLVersion1.98k
;
66
2.08k
    auto I = OptMap.find(Ext)->getValue();
67
2.08k
    return I.Supported && 
I.Avail <= CLVer1.10k
&&
(1.00k
I.Core == ~0U1.00k
||
CLVer < I.Core404
);
68
2.08k
  }
69
70
738
  void enable(llvm::StringRef Ext, bool V = true) {
71
738
    OptMap[Ext].Enabled = V;
72
738
  }
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
6.47k
  void support(llvm::StringRef Ext, bool V = true) {
79
6.47k
    assert(!Ext.empty() && "Extension is empty.");
80
6.47k
81
6.47k
    switch (Ext[0]) {
82
6.47k
    case '+':
83
16
      V = true;
84
16
      Ext = Ext.drop_front();
85
16
      break;
86
6.47k
    case '-':
87
12
      V = false;
88
12
      Ext = Ext.drop_front();
89
12
      break;
90
6.47k
    }
91
6.47k
92
6.47k
    if (Ext.equals("all")) {
93
6
      supportAll(V);
94
6
      return;
95
6
    }
96
6.47k
    OptMap[Ext].Supported = V;
97
6.47k
  }
98
99
108k
  OpenCLOptions(){
100
108k
#define OPENCLEXT_INTERNAL(Ext, AvailVer, CoreVer) \
101
4.44M
    OptMap[#Ext].Avail = AvailVer; \
102
4.44M
    OptMap[#Ext].Core = CoreVer;
103
108k
#include "clang/Basic/OpenCLExtensions.def"
104
108k
  }
105
106
535
  void addSupport(const OpenCLOptions &Opts) {
107
535
    for (auto &I:Opts.OptMap)
108
21.9k
      if (I.second.Supported)
109
16.5k
        OptMap[I.getKey()].Supported = true;
110
535
  }
111
112
5.36k
  void copy(const OpenCLOptions &Opts) {
113
5.36k
    OptMap = Opts.OptMap;
114
5.36k
  }
115
116
  // Turn on or off support of all options.
117
33.3k
  void supportAll(bool On = true) {
118
33.3k
    for (llvm::StringMap<Info>::iterator I = OptMap.begin(),
119
1.40M
         E = OptMap.end(); I != E; 
++I1.36M
)
120
1.36M
      I->second.Supported = On;
121
33.3k
  }
122
123
22
  void disableAll() {
124
22
    for (llvm::StringMap<Info>::iterator I = OptMap.begin(),
125
941
         E = OptMap.end(); I != E; 
++I919
)
126
919
      I->second.Enabled = false;
127
22
  }
128
129
557
  void enableSupportedCore(LangOptions LO) {
130
557
    for (llvm::StringMap<Info>::iterator I = OptMap.begin(), E = OptMap.end();
131
23.4k
         I != E; 
++I22.8k
)
132
22.8k
      if (isSupportedCore(I->getKey(), LO))
133
2.21k
        I->second.Enabled = true;
134
557
  }
135
136
  friend class ASTWriter;
137
  friend class ASTReader;
138
};
139
140
} // end namespace clang
141
142
#endif