Coverage Report

Created: 2022-01-18 06:27

/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
887k
bool OpenCLOptions::isKnown(llvm::StringRef Ext) const {
16
887k
  return OptMap.find(Ext) != OptMap.end();
17
887k
}
18
19
bool OpenCLOptions::isAvailableOption(llvm::StringRef Ext,
20
863k
                                      const LangOptions &LO) const {
21
863k
  if (!isKnown(Ext))
22
0
    return false;
23
24
863k
  auto &OptInfo = OptMap.find(Ext)->getValue();
25
863k
  if (OptInfo.isCoreIn(LO) || OptInfo.isOptionalCoreIn(LO))
26
12.1k
    return isSupported(Ext, LO);
27
28
850k
  return isEnabled(Ext);
29
863k
}
30
31
850k
bool OpenCLOptions::isEnabled(llvm::StringRef Ext) const {
32
850k
  auto I = OptMap.find(Ext);
33
850k
  return I != OptMap.end() && I->getValue().Enabled;
34
850k
}
35
36
1.08k
bool OpenCLOptions::isWithPragma(llvm::StringRef Ext) const {
37
1.08k
  auto E = OptMap.find(Ext);
38
1.08k
  return E != OptMap.end() && E->second.WithPragma;
39
1.08k
}
40
41
bool OpenCLOptions::isSupported(llvm::StringRef Ext,
42
79.9k
                                const LangOptions &LO) const {
43
79.9k
  auto I = OptMap.find(Ext);
44
79.9k
  return I != OptMap.end() && I->getValue().Supported &&
45
79.9k
         
I->getValue().isAvailableIn(LO)77.9k
;
46
79.9k
}
47
48
bool OpenCLOptions::isSupportedCore(llvm::StringRef Ext,
49
973
                                    const LangOptions &LO) const {
50
973
  auto I = OptMap.find(Ext);
51
973
  return I != OptMap.end() && I->getValue().Supported &&
52
973
         
I->getValue().isCoreIn(LO)894
;
53
973
}
54
55
bool OpenCLOptions::isSupportedOptionalCore(llvm::StringRef Ext,
56
855
                                            const LangOptions &LO) const {
57
855
  auto I = OptMap.find(Ext);
58
855
  return I != OptMap.end() && I->getValue().Supported &&
59
855
         
I->getValue().isOptionalCoreIn(LO)776
;
60
855
}
61
62
bool OpenCLOptions::isSupportedCoreOrOptionalCore(llvm::StringRef Ext,
63
973
                                                  const LangOptions &LO) const {
64
973
  return isSupportedCore(Ext, LO) || 
isSupportedOptionalCore(Ext, LO)855
;
65
973
}
66
67
bool OpenCLOptions::isSupportedExtension(llvm::StringRef Ext,
68
819
                                         const LangOptions &LO) const {
69
819
  auto I = OptMap.find(Ext);
70
819
  return I != OptMap.end() && I->getValue().Supported &&
71
819
         
I->getValue().isAvailableIn(LO)740
&&
72
819
         
!isSupportedCoreOrOptionalCore(Ext, LO)740
;
73
819
}
74
75
586
void OpenCLOptions::enable(llvm::StringRef Ext, bool V) {
76
586
  OptMap[Ext].Enabled = V;
77
586
}
78
79
16
void OpenCLOptions::acceptsPragma(llvm::StringRef Ext, bool V) {
80
16
  OptMap[Ext].WithPragma = V;
81
16
}
82
83
17.1k
void OpenCLOptions::support(llvm::StringRef Ext, bool V) {
84
17.1k
  assert(!Ext.empty() && "Extension is empty.");
85
0
  assert(Ext[0] != '+' && Ext[0] != '-');
86
0
  OptMap[Ext].Supported = V;
87
17.1k
}
88
89
99.1k
OpenCLOptions::OpenCLOptions() {
90
99.1k
#define OPENCL_GENERIC_EXTENSION(Ext, ...)                                     \
91
4.16M
  OptMap.insert_or_assign(#Ext, OpenCLOptionInfo{__VA_ARGS__});
92
99.1k
#include "clang/Basic/OpenCLExtensions.def"
93
99.1k
}
94
95
void OpenCLOptions::addSupport(const llvm::StringMap<bool> &FeaturesMap,
96
612
                               const LangOptions &Opts) {
97
23.7k
  for (const auto &F : FeaturesMap) {
98
23.7k
    const auto &Name = F.getKey();
99
23.7k
    if (F.getValue() && 
isKnown(Name)23.4k
&&
OptMap[Name].isAvailableIn(Opts)23.4k
)
100
17.1k
      support(Name);
101
23.7k
  }
102
612
}
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
123
    const TargetInfo &TI, DiagnosticsEngine &Diags) {
111
  // Feature pairs. First feature in a pair requires the second one to be
112
  // supported.
113
123
  static const llvm::StringMap<llvm::StringRef> DependentFeaturesMap = {
114
123
      {"__opencl_c_read_write_images", "__opencl_c_images"},
115
123
      {"__opencl_c_3d_image_writes", "__opencl_c_images"},
116
123
      {"__opencl_c_pipes", "__opencl_c_generic_address_space"}};
117
118
123
  auto OpenCLFeaturesMap = TI.getSupportedOpenCLOpts();
119
120
123
  bool IsValid = true;
121
123
  for (auto &FeaturePair : DependentFeaturesMap)
122
369
    if (TI.hasFeatureEnabled(OpenCLFeaturesMap, FeaturePair.getKey()) &&
123
369
        
!TI.hasFeatureEnabled(OpenCLFeaturesMap, FeaturePair.getValue())290
) {
124
10
      IsValid = false;
125
10
      Diags.Report(diag::err_opencl_feature_requires)
126
10
          << FeaturePair.getKey() << FeaturePair.getValue();
127
10
    }
128
123
  return IsValid;
129
123
}
130
131
bool OpenCLOptions::diagnoseFeatureExtensionDifferences(
132
117
    const TargetInfo &TI, DiagnosticsEngine &Diags) {
133
  // Extensions and equivalent feature pairs.
134
117
  static const llvm::StringMap<llvm::StringRef> FeatureExtensionMap = {
135
117
      {"cl_khr_fp64", "__opencl_c_fp64"},
136
117
      {"cl_khr_3d_image_writes", "__opencl_c_3d_image_writes"}};
137
138
117
  auto OpenCLFeaturesMap = TI.getSupportedOpenCLOpts();
139
140
117
  bool IsValid = true;
141
117
  for (auto &ExtAndFeat : FeatureExtensionMap)
142
234
    if (TI.hasFeatureEnabled(OpenCLFeaturesMap, ExtAndFeat.getKey()) !=
143
234
        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
117
  return IsValid;
149
117
}
150
151
} // end namespace clang