clang  8.0.0svn
NVPTX.h
Go to the documentation of this file.
1 //===--- NVPTX.h - Declare NVPTX target feature support ---------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares NVPTX TargetInfo objects.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_NVPTX_H
15 #define LLVM_CLANG_LIB_BASIC_TARGETS_NVPTX_H
16 
17 #include "clang/Basic/Cuda.h"
18 #include "clang/Basic/TargetInfo.h"
20 #include "llvm/ADT/Triple.h"
21 #include "llvm/Support/Compiler.h"
22 
23 namespace clang {
24 namespace targets {
25 
26 static const unsigned NVPTXAddrSpaceMap[] = {
27  0, // Default
28  1, // opencl_global
29  3, // opencl_local
30  4, // opencl_constant
31  0, // opencl_private
32  // FIXME: generic has to be added to the target
33  0, // opencl_generic
34  1, // cuda_device
35  4, // cuda_constant
36  3, // cuda_shared
37 };
38 
39 class LLVM_LIBRARY_VISIBILITY NVPTXTargetInfo : public TargetInfo {
40  static const char *const GCCRegNames[];
41  static const Builtin::Info BuiltinInfo[];
42  CudaArch GPU;
43  uint32_t PTXVersion;
44  std::unique_ptr<TargetInfo> HostTarget;
45 
46 public:
47  NVPTXTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts,
48  unsigned TargetPointerWidth);
49 
50  void getTargetDefines(const LangOptions &Opts,
51  MacroBuilder &Builder) const override;
52 
53  ArrayRef<Builtin::Info> getTargetBuiltins() const override;
54 
55  bool
56  initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
57  StringRef CPU,
58  const std::vector<std::string> &FeaturesVec) const override {
59  Features[CudaArchToString(GPU)] = true;
60  Features["ptx" + std::to_string(PTXVersion)] = true;
61  return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
62  }
63 
64  bool hasFeature(StringRef Feature) const override;
65 
66  ArrayRef<const char *> getGCCRegNames() const override;
67 
69  // No aliases.
70  return None;
71  }
72 
73  bool validateAsmConstraint(const char *&Name,
74  TargetInfo::ConstraintInfo &Info) const override {
75  switch (*Name) {
76  default:
77  return false;
78  case 'c':
79  case 'h':
80  case 'r':
81  case 'l':
82  case 'f':
83  case 'd':
84  Info.setAllowsRegister();
85  return true;
86  }
87  }
88 
89  const char *getClobbers() const override {
90  // FIXME: Is this really right?
91  return "";
92  }
93 
95  // FIXME: implement
97  }
98 
99  bool isValidCPUName(StringRef Name) const override {
100  return StringToCudaArch(Name) != CudaArch::UNKNOWN;
101  }
102 
103  void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override {
104  for (int i = static_cast<int>(CudaArch::SM_20);
105  i < static_cast<int>(CudaArch::LAST); ++i)
106  Values.emplace_back(CudaArchToString(static_cast<CudaArch>(i)));
107  }
108 
109  bool setCPU(const std::string &Name) override {
110  GPU = StringToCudaArch(Name);
111  return GPU != CudaArch::UNKNOWN;
112  }
113 
114  void setSupportedOpenCLOpts() override {
115  auto &Opts = getSupportedOpenCLOpts();
116  Opts.support("cl_clang_storage_class_specifiers");
117  Opts.support("cl_khr_gl_sharing");
118  Opts.support("cl_khr_icd");
119 
120  Opts.support("cl_khr_fp64");
121  Opts.support("cl_khr_byte_addressable_store");
122  Opts.support("cl_khr_global_int32_base_atomics");
123  Opts.support("cl_khr_global_int32_extended_atomics");
124  Opts.support("cl_khr_local_int32_base_atomics");
125  Opts.support("cl_khr_local_int32_extended_atomics");
126  }
127 
129  // CUDA compilations support all of the host's calling conventions.
130  //
131  // TODO: We should warn if you apply a non-default CC to anything other than
132  // a host function.
133  if (HostTarget)
134  return HostTarget->checkCallingConvention(CC);
135  return CCCR_Warning;
136  }
137 };
138 } // namespace targets
139 } // namespace clang
140 #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:103
CudaArch
Definition: Cuda.h:34
const char * CudaArchToString(CudaArch A)
Definition: Cuda.cpp:29
static const Builtin::Info BuiltinInfo[]
Definition: Builtins.cpp:21
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:76
CudaArch StringToCudaArch(llvm::StringRef S)
Definition: Cuda.cpp:93
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:128
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &Info) const override
Definition: NVPTX.h:73
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:50
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:149
static const char *const GCCRegNames[]
Definition: X86.cpp:44
Exposes information about the current target.
Definition: TargetInfo.h:54
bool setCPU(const std::string &Name) override
Target the specified CPU.
Definition: NVPTX.h:109
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:385
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:236
void setSupportedOpenCLOpts() override
Set supported OpenCL extensions and optional core features.
Definition: NVPTX.h:114
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition: NVPTX.h:94
Defines the clang::TargetOptions class.
bool isValidCPUName(StringRef Name) const override
brief Determine whether this TargetInfo supports the given CPU name.
Definition: NVPTX.h:99
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
Definition: NVPTX.h:68
Dataflow Directional Tag Classes.
typedef char* __builtin_va_list;
Definition: TargetInfo.h:183
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition: TargetInfo.h:181
static const unsigned NVPTXAddrSpaceMap[]
Definition: NVPTX.h:26
Defines the clang::TargetInfo interface.
const char * getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition: NVPTX.h:89
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:56