clang  9.0.0svn
NVPTX.h
Go to the documentation of this file.
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"
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 class LLVM_LIBRARY_VISIBILITY NVPTXTargetInfo : public TargetInfo {
39  static const char *const GCCRegNames[];
40  static const Builtin::Info BuiltinInfo[];
41  CudaArch GPU;
42  uint32_t PTXVersion;
43  std::unique_ptr<TargetInfo> HostTarget;
44 
45 public:
46  NVPTXTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts,
47  unsigned TargetPointerWidth);
48 
49  void getTargetDefines(const LangOptions &Opts,
50  MacroBuilder &Builder) const override;
51 
52  ArrayRef<Builtin::Info> getTargetBuiltins() const override;
53 
54  bool
55  initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
56  StringRef CPU,
57  const std::vector<std::string> &FeaturesVec) const override {
58  Features[CudaArchToString(GPU)] = true;
59  Features["ptx" + std::to_string(PTXVersion)] = true;
60  return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
61  }
62 
63  bool hasFeature(StringRef Feature) const override;
64 
65  ArrayRef<const char *> getGCCRegNames() const override;
66 
68  // No aliases.
69  return None;
70  }
71 
72  bool validateAsmConstraint(const char *&Name,
73  TargetInfo::ConstraintInfo &Info) const override {
74  switch (*Name) {
75  default:
76  return false;
77  case 'c':
78  case 'h':
79  case 'r':
80  case 'l':
81  case 'f':
82  case 'd':
83  Info.setAllowsRegister();
84  return true;
85  }
86  }
87 
88  const char *getClobbers() const override {
89  // FIXME: Is this really right?
90  return "";
91  }
92 
94  // FIXME: implement
96  }
97 
98  bool isValidCPUName(StringRef Name) const override {
99  return StringToCudaArch(Name) != CudaArch::UNKNOWN;
100  }
101 
102  void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override {
103  for (int i = static_cast<int>(CudaArch::SM_20);
104  i < static_cast<int>(CudaArch::LAST); ++i)
105  Values.emplace_back(CudaArchToString(static_cast<CudaArch>(i)));
106  }
107 
108  bool setCPU(const std::string &Name) override {
109  GPU = StringToCudaArch(Name);
110  return GPU != CudaArch::UNKNOWN;
111  }
112 
113  void setSupportedOpenCLOpts() override {
114  auto &Opts = getSupportedOpenCLOpts();
115  Opts.support("cl_clang_storage_class_specifiers");
116  Opts.support("cl_khr_gl_sharing");
117  Opts.support("cl_khr_icd");
118 
119  Opts.support("cl_khr_fp64");
120  Opts.support("cl_khr_byte_addressable_store");
121  Opts.support("cl_khr_global_int32_base_atomics");
122  Opts.support("cl_khr_global_int32_extended_atomics");
123  Opts.support("cl_khr_local_int32_base_atomics");
124  Opts.support("cl_khr_local_int32_extended_atomics");
125  }
126 
128  // CUDA compilations support all of the host's calling conventions.
129  //
130  // TODO: We should warn if you apply a non-default CC to anything other than
131  // a host function.
132  if (HostTarget)
133  return HostTarget->checkCallingConvention(CC);
134  return CCCR_Warning;
135  }
136 };
137 } // namespace targets
138 } // namespace clang
139 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_NVPTX_H
void fillValidCPUList(SmallVectorImpl< StringRef > &Values) const override
Fill a SmallVectorImpl with the valid values to setCPU.
Definition: NVPTX.h:102
CudaArch
Definition: Cuda.h:34
const char * CudaArchToString(CudaArch A)
Definition: Cuda.cpp:31
static const Builtin::Info BuiltinInfo[]
Definition: Builtins.cpp:20
static bool hasFeature(StringRef Feature, const LangOptions &LangOpts, const TargetInfo &Target)
Determine whether a translation unit built using the current language options has the given feature...
Definition: Module.cpp:106
CudaArch StringToCudaArch(llvm::StringRef S)
Definition: Cuda.cpp:103
Options for controlling the target.
Definition: TargetOptions.h:26
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override
Determines whether a given calling convention is valid for the target.
Definition: NVPTX.h:127
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &Info) const override
Definition: NVPTX.h:72
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:49
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:148
static const char *const GCCRegNames[]
Definition: X86.cpp:43
Exposes information about the current target.
Definition: TargetInfo.h:53
bool setCPU(const std::string &Name) override
Target the specified CPU.
Definition: NVPTX.h:108
virtual bool initFeatureMap(llvm::StringMap< bool > &Features, DiagnosticsEngine &Diags, StringRef CPU, const std::vector< std::string > &FeatureVec) const
Initialize the map with the default set of target features for the CPU this should include all legal ...
Definition: TargetInfo.cpp:384
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:235
void setSupportedOpenCLOpts() override
Set supported OpenCL extensions and optional core features.
Definition: NVPTX.h:113
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition: NVPTX.h:93
Defines the clang::TargetOptions class.
bool isValidCPUName(StringRef Name) const override
brief Determine whether this TargetInfo supports the given CPU name.
Definition: NVPTX.h:98
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
Definition: NVPTX.h:67
Dataflow Directional Tag Classes.
typedef char* __builtin_va_list;
Definition: TargetInfo.h:182
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition: TargetInfo.h:180
static const unsigned NVPTXAddrSpaceMap[]
Definition: NVPTX.h:25
Defines the clang::TargetInfo interface.
const char * getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition: NVPTX.h:88
bool initFeatureMap(llvm::StringMap< bool > &Features, DiagnosticsEngine &Diags, StringRef CPU, const std::vector< std::string > &FeaturesVec) const override
Initialize the map with the default set of target features for the CPU this should include all legal ...
Definition: NVPTX.h:55