clang  6.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  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["satom"] = GPU >= CudaArch::SM_60;
59  return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
60  }
61 
62  bool hasFeature(StringRef Feature) const override;
63 
64  ArrayRef<const char *> getGCCRegNames() const override;
65 
67  // No aliases.
68  return None;
69  }
70 
71  bool validateAsmConstraint(const char *&Name,
72  TargetInfo::ConstraintInfo &Info) const override {
73  switch (*Name) {
74  default:
75  return false;
76  case 'c':
77  case 'h':
78  case 'r':
79  case 'l':
80  case 'f':
81  case 'd':
82  Info.setAllowsRegister();
83  return true;
84  }
85  }
86 
87  const char *getClobbers() const override {
88  // FIXME: Is this really right?
89  return "";
90  }
91 
93  // FIXME: implement
95  }
96 
97  bool isValidCPUName(StringRef Name) const override {
98  return StringToCudaArch(Name) != CudaArch::UNKNOWN;
99  }
100 
101  bool setCPU(const std::string &Name) override {
102  GPU = StringToCudaArch(Name);
103  return GPU != CudaArch::UNKNOWN;
104  }
105 
106  void setSupportedOpenCLOpts() override {
107  auto &Opts = getSupportedOpenCLOpts();
108  Opts.support("cl_clang_storage_class_specifiers");
109  Opts.support("cl_khr_gl_sharing");
110  Opts.support("cl_khr_icd");
111 
112  Opts.support("cl_khr_fp64");
113  Opts.support("cl_khr_byte_addressable_store");
114  Opts.support("cl_khr_global_int32_base_atomics");
115  Opts.support("cl_khr_global_int32_extended_atomics");
116  Opts.support("cl_khr_local_int32_base_atomics");
117  Opts.support("cl_khr_local_int32_extended_atomics");
118  }
119 
121  // CUDA compilations support all of the host's calling conventions.
122  //
123  // TODO: We should warn if you apply a non-default CC to anything other than
124  // a host function.
125  if (HostTarget)
126  return HostTarget->checkCallingConvention(CC);
127  return CCCR_Warning;
128  }
129 };
130 } // namespace targets
131 } // namespace clang
132 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_NVPTX_H
CudaArch
Definition: Cuda.h:32
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:73
CudaArch StringToCudaArch(llvm::StringRef S)
Definition: Cuda.cpp:59
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:120
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &Info) const override
Definition: NVPTX.h:71
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:147
static const char *const GCCRegNames[]
Definition: X86.cpp:42
Exposes information about the current target.
Definition: TargetInfo.h:54
bool setCPU(const std::string &Name) override
Target the specified CPU.
Definition: NVPTX.h:101
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:347
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:233
void setSupportedOpenCLOpts() override
Set supported OpenCL extensions and optional core features.
Definition: NVPTX.h:106
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition: NVPTX.h:92
Defines the clang::TargetOptions class.
bool isValidCPUName(StringRef Name) const override
brief Determine whether this TargetInfo supports the given CPU name.
Definition: NVPTX.h:97
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
Definition: NVPTX.h:66
Dataflow Directional Tag Classes.
typedef char* __builtin_va_list;
Definition: TargetInfo.h:154
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition: TargetInfo.h:152
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:87
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