Coverage Report

Created: 2020-09-19 12:23

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Basic/Targets/NVPTX.h
Line
Count
Source (jump to first uncovered line)
1
//===--- NVPTX.h - Declare NVPTX target feature support ---------*- 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
// This file declares NVPTX TargetInfo objects.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_NVPTX_H
14
#define LLVM_CLANG_LIB_BASIC_TARGETS_NVPTX_H
15
16
#include "clang/Basic/Cuda.h"
17
#include "clang/Basic/TargetInfo.h"
18
#include "clang/Basic/TargetOptions.h"
19
#include "llvm/ADT/Triple.h"
20
#include "llvm/Support/Compiler.h"
21
22
namespace clang {
23
namespace targets {
24
25
static const unsigned NVPTXAddrSpaceMap[] = {
26
    0, // Default
27
    1, // opencl_global
28
    3, // opencl_local
29
    4, // opencl_constant
30
    0, // opencl_private
31
    // FIXME: generic has to be added to the target
32
    0, // opencl_generic
33
    1, // opencl_global_device
34
    1, // opencl_global_host
35
    1, // cuda_device
36
    4, // cuda_constant
37
    3, // cuda_shared
38
    0, // ptr32_sptr
39
    0, // ptr32_uptr
40
    0  // ptr64
41
};
42
43
/// The DWARF address class. Taken from
44
/// https://docs.nvidia.com/cuda/archive/10.0/ptx-writers-guide-to-interoperability/index.html#cuda-specific-dwarf
45
static const int NVPTXDWARFAddrSpaceMap[] = {
46
    -1, // Default, opencl_private or opencl_generic - not defined
47
    5,  // opencl_global
48
    -1,
49
    8,  // opencl_local or cuda_shared
50
    4,  // opencl_constant or cuda_constant
51
};
52
53
class LLVM_LIBRARY_VISIBILITY NVPTXTargetInfo : public TargetInfo {
54
  static const char *const GCCRegNames[];
55
  static const Builtin::Info BuiltinInfo[];
56
  CudaArch GPU;
57
  uint32_t PTXVersion;
58
  std::unique_ptr<TargetInfo> HostTarget;
59
60
public:
61
  NVPTXTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts,
62
                  unsigned TargetPointerWidth);
63
64
  void getTargetDefines(const LangOptions &Opts,
65
                        MacroBuilder &Builder) const override;
66
67
  ArrayRef<Builtin::Info> getTargetBuiltins() const override;
68
69
  bool
70
  initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
71
                 StringRef CPU,
72
530
                 const std::vector<std::string> &FeaturesVec) const override {
73
530
    Features[CudaArchToString(GPU)] = true;
74
530
    Features["ptx" + std::to_string(PTXVersion)] = true;
75
530
    return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
76
530
  }
77
78
  bool hasFeature(StringRef Feature) const override;
79
80
  ArrayRef<const char *> getGCCRegNames() const override;
81
82
24
  ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
83
    // No aliases.
84
24
    return None;
85
24
  }
86
87
  bool validateAsmConstraint(const char *&Name,
88
132
                             TargetInfo::ConstraintInfo &Info) const override {
89
132
    switch (*Name) {
90
47
    default:
91
47
      return false;
92
85
    case 'c':
93
85
    case 'h':
94
85
    case 'r':
95
85
    case 'l':
96
85
    case 'f':
97
85
    case 'd':
98
85
      Info.setAllowsRegister();
99
85
      return true;
100
132
    }
101
132
  }
102
103
24
  const char *getClobbers() const override {
104
    // FIXME: Is this really right?
105
24
    return "";
106
24
  }
107
108
380
  BuiltinVaListKind getBuiltinVaListKind() const override {
109
    // FIXME: implement
110
380
    return TargetInfo::CharPtrBuiltinVaList;
111
380
  }
112
113
0
  bool isValidCPUName(StringRef Name) const override {
114
0
    return StringToCudaArch(Name) != CudaArch::UNKNOWN;
115
0
  }
116
117
1
  void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override {
118
1
    for (int i = static_cast<int>(CudaArch::SM_20);
119
39
         i < static_cast<int>(CudaArch::LAST); 
++i38
)
120
38
      Values.emplace_back(CudaArchToString(static_cast<CudaArch>(i)));
121
1
  }
122
123
64
  bool setCPU(const std::string &Name) override {
124
64
    GPU = StringToCudaArch(Name);
125
64
    return GPU != CudaArch::UNKNOWN;
126
64
  }
127
128
423
  void setSupportedOpenCLOpts() override {
129
423
    auto &Opts = getSupportedOpenCLOpts();
130
423
    Opts.support("cl_clang_storage_class_specifiers");
131
423
    Opts.support("cl_khr_gl_sharing");
132
423
    Opts.support("cl_khr_icd");
133
423
134
423
    Opts.support("cl_khr_fp64");
135
423
    Opts.support("cl_khr_byte_addressable_store");
136
423
    Opts.support("cl_khr_global_int32_base_atomics");
137
423
    Opts.support("cl_khr_global_int32_extended_atomics");
138
423
    Opts.support("cl_khr_local_int32_base_atomics");
139
423
    Opts.support("cl_khr_local_int32_extended_atomics");
140
423
  }
141
142
  /// \returns If a target requires an address within a target specific address
143
  /// space \p AddressSpace to be converted in order to be used, then return the
144
  /// corresponding target specific DWARF address space.
145
  ///
146
  /// \returns Otherwise return None and no conversion will be emitted in the
147
  /// DWARF.
148
  Optional<unsigned>
149
295
  getDWARFAddressSpace(unsigned AddressSpace) const override {
150
295
    if (AddressSpace >= llvm::array_lengthof(NVPTXDWARFAddrSpaceMap) ||
151
241
        NVPTXDWARFAddrSpaceMap[AddressSpace] < 0)
152
282
      return llvm::None;
153
13
    return NVPTXDWARFAddrSpaceMap[AddressSpace];
154
13
  }
155
156
0
  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
157
    // CUDA compilations support all of the host's calling conventions.
158
    //
159
    // TODO: We should warn if you apply a non-default CC to anything other than
160
    // a host function.
161
0
    if (HostTarget)
162
0
      return HostTarget->checkCallingConvention(CC);
163
0
    return CCCR_Warning;
164
0
  }
165
166
30
  bool hasExtIntType() const override { return true; }
167
};
168
} // namespace targets
169
} // namespace clang
170
#endif // LLVM_CLANG_LIB_BASIC_TARGETS_NVPTX_H