Coverage Report

Created: 2019-07-24 05:18

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