Coverage Report

Created: 2018-11-16 02:38

/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.62M
      :Supported(S), Enabled(E), Avail(A), Core(C){}
32
  };
33
  llvm::StringMap<Info> OptMap;
34
public:
35
1.99k
  bool isKnown(llvm::StringRef Ext) const {
36
1.99k
    return OptMap.find(Ext) != OptMap.end();
37
1.99k
  }
38
39
84.5k
  bool isEnabled(llvm::StringRef Ext) const {
40
84.5k
    return OptMap.find(Ext)->second.Enabled;
41
84.5k
  }
42
43
  // Is supported as either an extension or an (optional) core feature for
44
  // OpenCL version \p CLVer.
45
19.2k
  bool isSupported(llvm::StringRef Ext, unsigned CLVer) const {
46
19.2k
    auto I = OptMap.find(Ext)->getValue();
47
19.2k
    return I.Supported && 
I.Avail <= CLVer13.6k
;
48
19.2k
  }
49
50
  // Is supported (optional) OpenCL core features for OpenCL version \p CLVer.
51
  // For supported extension, return false.
52
18.7k
  bool isSupportedCore(llvm::StringRef Ext, unsigned CLVer) const {
53
18.7k
    auto I = OptMap.find(Ext)->getValue();
54
18.7k
    return I.Supported && 
I.Avail <= CLVer13.6k
&&
55
18.7k
      
I.Core != ~0U9.56k
&&
CLVer >= I.Core3.61k
;
56
18.7k
  }
57
58
  // Is supported OpenCL extension for OpenCL version \p CLVer.
59
  // For supported (optional) core feature, return false.
60
1.96k
 bool isSupportedExtension(llvm::StringRef Ext, unsigned CLVer) const {
61
1.96k
    auto I = OptMap.find(Ext)->getValue();
62
1.96k
    return I.Supported && 
I.Avail <= CLVer986
&&
63
1.96k
      
(884
I.Core == ~0U884
||
CLVer < I.Core387
);
64
1.96k
  }
65
66
636
  void enable(llvm::StringRef Ext, bool V = true) {
67
636
    OptMap[Ext].Enabled = V;
68
636
  }
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.26k
  void support(llvm::StringRef Ext, bool V = true) {
75
5.26k
    assert(!Ext.empty() && "Extension is empty.");
76
5.26k
77
5.26k
    switch (Ext[0]) {
78
5.26k
    case '+':
79
15
      V = true;
80
15
      Ext = Ext.drop_front();
81
15
      break;
82
5.26k
    case '-':
83
9
      V = false;
84
9
      Ext = Ext.drop_front();
85
9
      break;
86
5.26k
    }
87
5.26k
88
5.26k
    if (Ext.equals("all")) {
89
6
      supportAll(V);
90
6
      return;
91
6
    }
92
5.25k
    OptMap[Ext].Supported = V;
93
5.25k
  }
94
95
98.0k
  OpenCLOptions(){
96
98.0k
#define OPENCLEXT_INTERNAL(Ext, AvailVer, CoreVer) \
97
3.62M
    OptMap[#Ext].Avail = AvailVer; \
98
3.62M
    OptMap[#Ext].Core = CoreVer;
99
98.0k
#include "clang/Basic/OpenCLExtensions.def"
100
98.0k
  }
101
102
450
  void addSupport(const OpenCLOptions &Opts) {
103
450
    for (auto &I:Opts.OptMap)
104
16.6k
      if (I.second.Supported)
105
12.6k
        OptMap[I.getKey()].Supported = true;
106
450
  }
107
108
5.02k
  void copy(const OpenCLOptions &Opts) {
109
5.02k
    OptMap = Opts.OptMap;
110
5.02k
  }
111
112
  // Turn on or off support of all options.
113
30.0k
  void supportAll(bool On = true) {
114
30.0k
    for (llvm::StringMap<Info>::iterator I = OptMap.begin(),
115
1.13M
         E = OptMap.end(); I != E; 
++I1.10M
)
116
1.10M
      I->second.Supported = On;
117
30.0k
  }
118
119
21
  void disableAll() {
120
21
    for (llvm::StringMap<Info>::iterator I = OptMap.begin(),
121
812
         E = OptMap.end(); I != E; 
++I791
)
122
791
      I->second.Enabled = false;
123
21
  }
124
125
471
  void enableSupportedCore(unsigned CLVer) {
126
471
    for (llvm::StringMap<Info>::iterator I = OptMap.begin(),
127
17.9k
         E = OptMap.end(); I != E; 
++I17.4k
)
128
17.4k
      if (isSupportedCore(I->getKey(), CLVer))
129
1.63k
        I->second.Enabled = true;
130
471
  }
131
132
  friend class ASTWriter;
133
  friend class ASTReader;
134
};
135
136
}  // end namespace clang
137
138
#endif