Coverage Report

Created: 2021-09-21 08:58

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Basic/OpenCLOptions.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- OpenCLOptions.cpp---------------------------------------*- 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
#include "clang/Basic/OpenCLOptions.h"
10
#include "clang/Basic/Diagnostic.h"
11
#include "clang/Basic/TargetInfo.h"
12
13
namespace clang {
14
15
895k
bool OpenCLOptions::isKnown(llvm::StringRef Ext) const {
16
895k
  return OptMap.find(Ext) != OptMap.end();
17
895k
}
18
19
bool OpenCLOptions::isAvailableOption(llvm::StringRef Ext,
20
867k
                                      const LangOptions &LO) const {
21
867k
  if (!isKnown(Ext))
22
0
    return false;
23
24
867k
  auto &OptInfo = OptMap.find(Ext)->getValue();
25
867k
  if (OptInfo.isCoreIn(LO) || OptInfo.isOptionalCoreIn(LO))
26
11.7k
    return isSupported(Ext, LO);
27
28
855k
  return isEnabled(Ext);
29
867k
}
30
31
855k
bool OpenCLOptions::isEnabled(llvm::StringRef Ext) const {
32
855k
  auto I = OptMap.find(Ext);
33
855k
  return I != OptMap.end() && I->getValue().Enabled;
34
855k
}
35
36
1.79k
bool OpenCLOptions::isWithPragma(llvm::StringRef Ext) const {
37
1.79k
  auto E = OptMap.find(Ext);
38
1.79k
  return E != OptMap.end() && E->second.WithPragma;
39
1.79k
}
40
41
bool OpenCLOptions::isSupported(llvm::StringRef Ext,
42
80.0k
                                const LangOptions &LO) const {
43
80.0k
  auto I = OptMap.find(Ext);
44
80.0k
  return I != OptMap.end() && I->getValue().Supported &&
45
80.0k
         
I->getValue().isAvailableIn(LO)76.3k
;
46
80.0k
}
47
48
bool OpenCLOptions::isSupportedCore(llvm::StringRef Ext,
49
1.83k
                                    const LangOptions &LO) const {
50
1.83k
  auto I = OptMap.find(Ext);
51
1.83k
  return I != OptMap.end() && I->getValue().Supported &&
52
1.83k
         
I->getValue().isCoreIn(LO)1.49k
;
53
1.83k
}
54
55
bool OpenCLOptions::isSupportedOptionalCore(llvm::StringRef Ext,
56
1.44k
                                            const LangOptions &LO) const {
57
1.44k
  auto I = OptMap.find(Ext);
58
1.44k
  return I != OptMap.end() && I->getValue().Supported &&
59
1.44k
         
I->getValue().isOptionalCoreIn(LO)1.11k
;
60
1.44k
}
61
62
bool OpenCLOptions::isSupportedCoreOrOptionalCore(llvm::StringRef Ext,
63
1.83k
                                                  const LangOptions &LO) const {
64
1.83k
  return isSupportedCore(Ext, LO) || 
isSupportedOptionalCore(Ext, LO)1.44k
;
65
1.83k
}
66
67
bool OpenCLOptions::isSupportedExtension(llvm::StringRef Ext,
68
1.53k
                                         const LangOptions &LO) const {
69
1.53k
  auto I = OptMap.find(Ext);
70
1.53k
  return I != OptMap.end() && I->getValue().Supported &&
71
1.53k
         
I->getValue().isAvailableIn(LO)1.19k
&&
72
1.53k
         
!isSupportedCoreOrOptionalCore(Ext, LO)1.19k
;
73
1.53k
}
74
75
899
void OpenCLOptions::enable(llvm::StringRef Ext, bool V) {
76
899
  OptMap[Ext].Enabled = V;
77
899
}
78
79
15
void OpenCLOptions::acceptsPragma(llvm::StringRef Ext, bool V) {
80
15
  OptMap[Ext].WithPragma = V;
81
15
}
82
83
19.2k
void OpenCLOptions::support(llvm::StringRef Ext, bool V) {
84
19.2k
  assert(!Ext.empty() && "Extension is empty.");
85
0
  assert(Ext[0] != '+' && Ext[0] != '-');
86
0
  OptMap[Ext].Supported = V;
87
19.2k
}
88
89
109k
OpenCLOptions::OpenCLOptions() {
90
109k
#define OPENCL_GENERIC_EXTENSION(Ext, ...)                                     \
91
4.58M
  OptMap.insert_or_assign(#Ext, OpenCLOptionInfo{__VA_ARGS__});
92
109k
#include "clang/Basic/OpenCLExtensions.def"
93
109k
}
94
95
void OpenCLOptions::addSupport(const llvm::StringMap<bool> &FeaturesMap,
96
752
                               const LangOptions &Opts) {
97
26.5k
  for (const auto &F : FeaturesMap) {
98
26.5k
    const auto &Name = F.getKey();
99
26.5k
    if (F.getValue() && 
isKnown(Name)26.1k
&&
OptMap[Name].isAvailableIn(Opts)26.1k
)
100
19.2k
      support(Name);
101
26.5k
  }
102
752
}
103
104
75
void OpenCLOptions::disableAll() {
105
75
  for (auto &Opt : OptMap)
106
3.16k
    Opt.getValue().Enabled = false;
107
75
}
108
109
bool OpenCLOptions::diagnoseUnsupportedFeatureDependencies(
110
119
    const TargetInfo &TI, DiagnosticsEngine &Diags) {
111
  // Feature pairs. First feature in a pair requires the second one to be
112
  // supported.
113
119
  static const llvm::StringMap<llvm::StringRef> DependentFeaturesMap = {
114
119
      {"__opencl_c_read_write_images", "__opencl_c_images"},
115
119
      {"__opencl_c_3d_image_writes", "__opencl_c_images"},
116
119
      {"__opencl_c_pipes", "__opencl_c_generic_address_space"}};
117
118
119
  auto OpenCLFeaturesMap = TI.getSupportedOpenCLOpts();
119
120
119
  bool IsValid = true;
121
119
  for (auto &FeaturePair : DependentFeaturesMap)
122
357
    if (TI.hasFeatureEnabled(OpenCLFeaturesMap, FeaturePair.getKey()) &&
123
357
        
!TI.hasFeatureEnabled(OpenCLFeaturesMap, FeaturePair.getValue())280
) {
124
10
      IsValid = false;
125
10
      Diags.Report(diag::err_opencl_feature_requires)
126
10
          << FeaturePair.getKey() << FeaturePair.getValue();
127
10
    }
128
119
  return IsValid;
129
119
}
130
131
bool OpenCLOptions::diagnoseFeatureExtensionDifferences(
132
113
    const TargetInfo &TI, DiagnosticsEngine &Diags) {
133
  // Extensions and equivalent feature pairs.
134
113
  static const llvm::StringMap<llvm::StringRef> FeatureExtensionMap = {
135
113
      {"cl_khr_fp64", "__opencl_c_fp64"},
136
113
      {"cl_khr_3d_image_writes", "__opencl_c_3d_image_writes"}};
137
138
113
  auto OpenCLFeaturesMap = TI.getSupportedOpenCLOpts();
139
140
113
  bool IsValid = true;
141
113
  for (auto &ExtAndFeat : FeatureExtensionMap)
142
226
    if (TI.hasFeatureEnabled(OpenCLFeaturesMap, ExtAndFeat.getKey()) !=
143
226
        TI.hasFeatureEnabled(OpenCLFeaturesMap, ExtAndFeat.getValue())) {
144
6
      IsValid = false;
145
6
      Diags.Report(diag::err_opencl_extension_and_feature_differs)
146
6
          << ExtAndFeat.getKey() << ExtAndFeat.getValue();
147
6
    }
148
113
  return IsValid;
149
113
}
150
151
} // end namespace clang