Coverage Report

Created: 2018-07-22 10:17

/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
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
///
10
/// \file
11
/// Defines the clang::OpenCLOptions class.
12
///
13
//===----------------------------------------------------------------------===//
14
15
#ifndef LLVM_CLANG_BASIC_OPENCLOPTIONS_H
16
#define LLVM_CLANG_BASIC_OPENCLOPTIONS_H
17
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
3.39M
      :Supported(S), Enabled(E), Avail(A), Core(C){}
32
  };
33
  llvm::StringMap<Info> OptMap;
34
public:
35
1.92k
  bool isKnown(llvm::StringRef Ext) const {
36
1.92k
    return OptMap.find(Ext) != OptMap.end();
37
1.92k
  }
38
39
31.2k
  bool isEnabled(llvm::StringRef Ext) const {
40
31.2k
    return OptMap.find(Ext)->second.Enabled;
41
31.2k
  }
42
43
  // Is supported as either an extension or an (optional) core feature for
44
  // OpenCL version \p CLVer.
45
17.1k
  bool isSupported(llvm::StringRef Ext, unsigned CLVer) const {
46
17.1k
    auto I = OptMap.find(Ext)->getValue();
47
17.1k
    return I.Supported && 
I.Avail <= CLVer12.2k
;
48
17.1k
  }
49
50
  // Is supported (optional) OpenCL core features for OpenCL version \p CLVer.
51
  // For supported extension, return false.
52
16.6k
  bool isSupportedCore(llvm::StringRef Ext, unsigned CLVer) const {
53
16.6k
    auto I = OptMap.find(Ext)->getValue();
54
16.6k
    return I.Supported && 
I.Avail <= CLVer12.0k
&&
55
16.6k
      
I.Core != ~0U8.40k
&&
CLVer >= I.Core3.28k
;
56
16.6k
  }
57
58
  // Is supported OpenCL extension for OpenCL version \p CLVer.
59
  // For supported (optional) core feature, return false.
60
1.92k
 bool isSupportedExtension(llvm::StringRef Ext, unsigned CLVer) const {
61
1.92k
    auto I = OptMap.find(Ext)->getValue();
62
1.92k
    return I.Supported && 
I.Avail <= CLVer946
&&
63
1.92k
      
(852
I.Core == ~0U852
||
CLVer < I.Core387
);
64
1.92k
  }
65
66
605
  void enable(llvm::StringRef Ext, bool V = true) {
67
605
    OptMap[Ext].Enabled = V;
68
605
  }
69
70
  /// Enable or disable support for OpenCL extensions
71
  /// \param Ext name of the extension optionally prefixed with
72
  ///        '+' or '-'
73
  /// \param V used when \p Ext is not prefixed by '+' or '-'
74
4.65k
  void support(llvm::StringRef Ext, bool V = true) {
75
4.65k
    assert(!Ext.empty() && "Extension is empty.");
76
4.65k
77
4.65k
    switch (Ext[0]) {
78
4.65k
    case '+':
79
13
      V = true;
80
13
      Ext = Ext.drop_front();
81
13
      break;
82
4.65k
    case '-':
83
9
      V = false;
84
9
      Ext = Ext.drop_front();
85
9
      break;
86
4.65k
    }
87
4.65k
88
4.65k
    if (Ext.equals("all")) {
89
6
      supportAll(V);
90
6
      return;
91
6
    }
92
4.65k
    OptMap[Ext].Supported = V;
93
4.65k
  }
94
95
94.4k
  OpenCLOptions(){
96
94.4k
#define OPENCLEXT_INTERNAL(Ext, AvailVer, CoreVer) \
97
3.39M
    OptMap[#Ext].Avail = AvailVer; \
98
3.39M
    OptMap[#Ext].Core = CoreVer;
99
94.4k
#include "clang/Basic/OpenCLExtensions.def"
100
94.4k
  }
101
102
406
  void addSupport(const OpenCLOptions &Opts) {
103
406
    for (auto &I:Opts.OptMap)
104
14.6k
      if (I.second.Supported)
105
11.2k
        OptMap[I.getKey()].Supported = true;
106
406
  }
107
108
4.91k
  void copy(const OpenCLOptions &Opts) {
109
4.91k
    OptMap = Opts.OptMap;
110
4.91k
  }
111
112
  // Turn on or off support of all options.
113
28.8k
  void supportAll(bool On = true) {
114
28.8k
    for (llvm::StringMap<Info>::iterator I = OptMap.begin(),
115
1.06M
         E = OptMap.end(); I != E; 
++I1.03M
)
116
1.03M
      I->second.Supported = On;
117
28.8k
  }
118
119
19
  void disableAll() {
120
19
    for (llvm::StringMap<Info>::iterator I = OptMap.begin(),
121
703
         E = OptMap.end(); I != E; 
++I684
)
122
684
      I->second.Enabled = false;
123
19
  }
124
125
425
  void enableSupportedCore(unsigned CLVer) {
126
425
    for (llvm::StringMap<Info>::iterator I = OptMap.begin(),
127
15.7k
         E = OptMap.end(); I != E; 
++I15.3k
)
128
15.3k
      if (isSupportedCore(I->getKey(), CLVer))
129
1.43k
        I->second.Enabled = true;
130
425
  }
131
132
  friend class ASTWriter;
133
  friend class ASTReader;
134
};
135
136
}  // end namespace clang
137
138
#endif