Coverage Report

Created: 2018-09-21 05:35

/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.49M
      :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
71.8k
  bool isEnabled(llvm::StringRef Ext) const {
40
71.8k
    return OptMap.find(Ext)->second.Enabled;
41
71.8k
  }
42
43
  // Is supported as either an extension or an (optional) core feature for
44
  // OpenCL version \p CLVer.
45
18.2k
  bool isSupported(llvm::StringRef Ext, unsigned CLVer) const {
46
18.2k
    auto I = OptMap.find(Ext)->getValue();
47
18.2k
    return I.Supported && 
I.Avail <= CLVer12.9k
;
48
18.2k
  }
49
50
  // Is supported (optional) OpenCL core features for OpenCL version \p CLVer.
51
  // For supported extension, return false.
52
17.8k
  bool isSupportedCore(llvm::StringRef Ext, unsigned CLVer) const {
53
17.8k
    auto I = OptMap.find(Ext)->getValue();
54
17.8k
    return I.Supported && 
I.Avail <= CLVer12.8k
&&
55
17.8k
      
I.Core != ~0U9.10k
&&
CLVer >= I.Core3.53k
;
56
17.8k
  }
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.Core386
);
64
1.92k
  }
65
66
604
  void enable(llvm::StringRef Ext, bool V = true) {
67
604
    OptMap[Ext].Enabled = V;
68
604
  }
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
5.09k
  void support(llvm::StringRef Ext, bool V = true) {
75
5.09k
    assert(!Ext.empty() && "Extension is empty.");
76
5.09k
77
5.09k
    switch (Ext[0]) {
78
5.09k
    case '+':
79
13
      V = true;
80
13
      Ext = Ext.drop_front();
81
13
      break;
82
5.09k
    case '-':
83
9
      V = false;
84
9
      Ext = Ext.drop_front();
85
9
      break;
86
5.09k
    }
87
5.09k
88
5.09k
    if (Ext.equals("all")) {
89
6
      supportAll(V);
90
6
      return;
91
6
    }
92
5.09k
    OptMap[Ext].Supported = V;
93
5.09k
  }
94
95
97.1k
  OpenCLOptions(){
96
97.1k
#define OPENCLEXT_INTERNAL(Ext, AvailVer, CoreVer) \
97
3.49M
    OptMap[#Ext].Avail = AvailVer; \
98
3.49M
    OptMap[#Ext].Core = CoreVer;
99
97.1k
#include "clang/Basic/OpenCLExtensions.def"
100
97.1k
  }
101
102
439
  void addSupport(const OpenCLOptions &Opts) {
103
439
    for (auto &I:Opts.OptMap)
104
15.8k
      if (I.second.Supported)
105
11.9k
        OptMap[I.getKey()].Supported = true;
106
439
  }
107
108
4.98k
  void copy(const OpenCLOptions &Opts) {
109
4.98k
    OptMap = Opts.OptMap;
110
4.98k
  }
111
112
  // Turn on or off support of all options.
113
29.6k
  void supportAll(bool On = true) {
114
29.6k
    for (llvm::StringMap<Info>::iterator I = OptMap.begin(),
115
1.09M
         E = OptMap.end(); I != E; 
++I1.06M
)
116
1.06M
      I->second.Supported = On;
117
29.6k
  }
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
458
  void enableSupportedCore(unsigned CLVer) {
126
458
    for (llvm::StringMap<Info>::iterator I = OptMap.begin(),
127
16.9k
         E = OptMap.end(); I != E; 
++I16.4k
)
128
16.4k
      if (isSupportedCore(I->getKey(), CLVer))
129
1.55k
        I->second.Enabled = true;
130
458
  }
131
132
  friend class ASTWriter;
133
  friend class ASTReader;
134
};
135
136
}  // end namespace clang
137
138
#endif