clang 8.0.0

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"
19 #include "clang/Basic/TargetOptions.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
68 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
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
94 BuiltinVaListKind getBuiltinVaListKind() const override {
95 // FIXME: implement
96 return TargetInfo::CharPtrBuiltinVaList;
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
128 CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
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
clang::targets::NVPTXTargetInfo::fillValidCPUList
void fillValidCPUList(SmallVectorImpl< StringRef > &Values) const override
Fill a SmallVectorImpl with the valid values to setCPU.
Definition: NVPTX.h:103
clang::targets::NVPTXTargetInfo
Definition: NVPTX.h:39
clang::CudaArch
CudaArch
Definition: Cuda.h:35
clang::CudaArchToString
const char * CudaArchToString(CudaArch A)
Definition: Cuda.cpp:31
clang::CudaVersion::UNKNOWN
BuiltinInfo
static const Builtin::Info BuiltinInfo[]
Definition: Builtins.cpp:21
hasFeature
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:107
clang::StringToCudaArch
CudaArch StringToCudaArch(llvm::StringRef S)
Definition: Cuda.cpp:103
clang::TargetOptions
Options for controlling the target.
Definition: TargetOptions.h:27
clang::Builtin::Info
Definition: Builtins.h:56
clang::targets::NVPTXTargetInfo::checkCallingConvention
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override
Determines whether a given calling convention is valid for the target.
Definition: NVPTX.h:128
clang::targets::NVPTXTargetInfo::validateAsmConstraint
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &Info) const override
Definition: NVPTX.h:73
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:50
llvm::SmallVectorImpl
Definition: LLVM.h:37
clang::CudaArch::SM_20
clang::DiagnosticsEngine
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:149
llvm::ArrayRef
Definition: LLVM.h:32
clang::targets::GCCRegNames
static const char *const GCCRegNames[]
Definition: X86.cpp:44
clang::TargetInfo
Exposes information about the current target.
Definition: TargetInfo.h:54
clang::targets::NVPTXTargetInfo::setCPU
bool setCPU(const std::string &Name) override
Target the specified CPU.
Definition: NVPTX.h:109
clang::TargetInfo::initFeatureMap
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:386
Cuda.h
clang::CallingConv
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:236
clang::TargetInfo::ConstraintInfo
Definition: TargetInfo.h:795
clang::targets::NVPTXTargetInfo::setSupportedOpenCLOpts
void setSupportedOpenCLOpts() override
Set supported OpenCL extensions and optional core features.
Definition: NVPTX.h:114
clang::TargetInfo::ConstraintInfo::setAllowsRegister
void setAllowsRegister()
Definition: TargetInfo.h:855
clang::targets::NVPTXTargetInfo::getBuiltinVaListKind
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition: NVPTX.h:94
TargetOptions.h
Defines the clang::TargetOptions class.
clang::targets::NVPTXTargetInfo::isValidCPUName
bool isValidCPUName(StringRef Name) const override
brief Determine whether this TargetInfo supports the given CPU name.
Definition: NVPTX.h:99
clang::targets::NVPTXTargetInfo::getGCCRegAliases
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
Definition: NVPTX.h:68
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::TargetInfo::CharPtrBuiltinVaList
typedef char* __builtin_va_list;
Definition: TargetInfo.h:184
clang::CudaArch::LAST
clang::MacroBuilder
Definition: MacroBuilder.h:24
clang::TargetInfo::BuiltinVaListKind
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition: TargetInfo.h:182
clang::targets::NVPTXAddrSpaceMap
static const unsigned NVPTXAddrSpaceMap[]
Definition: NVPTX.h:26
TargetInfo.h
Defines the clang::TargetInfo interface.
clang::targets::NVPTXTargetInfo::getClobbers
const char * getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition: NVPTX.h:89
clang::TargetInfo::CallingConvCheckResult
CallingConvCheckResult
Definition: TargetInfo.h:1235
clang::targets::NVPTXTargetInfo::initFeatureMap
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