clang 10.0.0git

AMDGPU.h
Go to the documentation of this file.
1 //===--- AMDGPU.h - Declare AMDGPU 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 AMDGPU TargetInfo objects.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_AMDGPU_H
14 #define LLVM_CLANG_LIB_BASIC_TARGETS_AMDGPU_H
15
16 #include "clang/Basic/TargetInfo.h"
17 #include "clang/Basic/TargetOptions.h"
18 #include "llvm/ADT/StringSet.h"
19 #include "llvm/ADT/Triple.h"
20 #include "llvm/Support/Compiler.h"
21 #include "llvm/Support/TargetParser.h"
22
23 namespace clang {
24 namespace targets {
25
26 class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
27
28 static const Builtin::Info BuiltinInfo[];
29 static const char *const GCCRegNames[];
30
31 enum AddrSpace {
32 Generic = 0,
33 Global = 1,
34 Local = 3,
35 Constant = 4,
36 Private = 5
37 };
38 static const LangASMap AMDGPUDefIsGenMap;
39 static const LangASMap AMDGPUDefIsPrivMap;
40
41 llvm::AMDGPU::GPUKind GPUKind;
42 unsigned GPUFeatures;
43
44 bool hasFP64() const {
45 return getTriple().getArch() == llvm::Triple::amdgcn ||
46 !!(GPUFeatures & llvm::AMDGPU::FEATURE_FP64);
47 }
48
49 /// Has fast fma f32
50 bool hasFastFMAF() const {
51 return !!(GPUFeatures & llvm::AMDGPU::FEATURE_FAST_FMA_F32);
52 }
53
54 /// Has fast fma f64
55 bool hasFastFMA() const {
56 return getTriple().getArch() == llvm::Triple::amdgcn;
57 }
58
59 bool hasFMAF() const {
60 return getTriple().getArch() == llvm::Triple::amdgcn ||
61 !!(GPUFeatures & llvm::AMDGPU::FEATURE_FMA);
62 }
63
64 bool hasFullRateDenormalsF32() const {
65 return !!(GPUFeatures & llvm::AMDGPU::FEATURE_FAST_DENORMAL_F32);
66 }
67
68 bool hasLDEXPF() const {
69 return getTriple().getArch() == llvm::Triple::amdgcn ||
70 !!(GPUFeatures & llvm::AMDGPU::FEATURE_LDEXP);
71 }
72
73 static bool isAMDGCN(const llvm::Triple &TT) {
74 return TT.getArch() == llvm::Triple::amdgcn;
75 }
76
77 static bool isR600(const llvm::Triple &TT) {
78 return TT.getArch() == llvm::Triple::r600;
79 }
80
81 public:
82 AMDGPUTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
83
84 void setAddressSpaceMap(bool DefaultIsPrivate);
85
86 void adjust(LangOptions &Opts) override;
87
88 uint64_t getPointerWidthV(unsigned AddrSpace) const override {
89 if (isR600(getTriple()))
90 return 32;
91
92 if (AddrSpace == Private || AddrSpace == Local)
93 return 32;
94
95 return 64;
96 }
97
98 uint64_t getPointerAlignV(unsigned AddrSpace) const override {
99 return getPointerWidthV(AddrSpace);
100 }
101
102 uint64_t getMaxPointerWidth() const override {
103 return getTriple().getArch() == llvm::Triple::amdgcn ? 64 : 32;
104 }
105
106 const char *getClobbers() const override { return ""; }
107
108 ArrayRef<const char *> getGCCRegNames() const override;
109
110 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
111 return None;
112 }
113
114 /// Accepted register names: (n, m is unsigned integer, n < m)
115 /// v
116 /// s
117 /// {vn}, {v[n]}
118 /// {sn}, {s[n]}
119 /// {S} , where S is a special register name
120 ////{v[n:m]}
121 /// {s[n:m]}
122 bool validateAsmConstraint(const char *&Name,
123 TargetInfo::ConstraintInfo &Info) const override {
124 static const ::llvm::StringSet<> SpecialRegs({
125 "exec", "vcc", "flat_scratch", "m0", "scc", "tba", "tma",
126 "flat_scratch_lo", "flat_scratch_hi", "vcc_lo", "vcc_hi", "exec_lo",
127 "exec_hi", "tma_lo", "tma_hi", "tba_lo", "tba_hi",
128 });
129
130 StringRef S(Name);
131 bool HasLeftParen = false;
132 if (S.front() == '{') {
133 HasLeftParen = true;
134 S = S.drop_front();
135 }
136 if (S.empty())
137 return false;
138 if (S.front() != 'v' && S.front() != 's') {
139 if (!HasLeftParen)
140 return false;
141 auto E = S.find('}');
142 if (!SpecialRegs.count(S.substr(0, E)))
143 return false;
144 S = S.drop_front(E + 1);
145 if (!S.empty())
146 return false;
147 // Found {S} where S is a special register.
148 Info.setAllowsRegister();
149 Name = S.data() - 1;
150 return true;
151 }
152 S = S.drop_front();
153 if (!HasLeftParen) {
154 if (!S.empty())
155 return false;
156 // Found s or v.
157 Info.setAllowsRegister();
158 Name = S.data() - 1;
159 return true;
160 }
161 bool HasLeftBracket = false;
162 if (!S.empty() && S.front() == '[') {
163 HasLeftBracket = true;
164 S = S.drop_front();
165 }
166 unsigned long long N;
167 if (S.empty() || consumeUnsignedInteger(S, 10, N))
168 return false;
169 if (!S.empty() && S.front() == ':') {
170 if (!HasLeftBracket)
171 return false;
172 S = S.drop_front();
173 unsigned long long M;
174 if (consumeUnsignedInteger(S, 10, M) || N >= M)
175 return false;
176 }
177 if (HasLeftBracket) {
178 if (S.empty() || S.front() != ']')
179 return false;
180 S = S.drop_front();
181 }
182 if (S.empty() || S.front() != '}')
183 return false;
184 S = S.drop_front();
185 if (!S.empty())
186 return false;
187 // Found {vn}, {sn}, {v[n]}, {s[n]}, {v[n:m]}, or {s[n:m]}.
188 Info.setAllowsRegister();
189 Name = S.data() - 1;
190 return true;
191 }
192
193 // \p Constraint will be left pointing at the last character of
194 // the constraint. In practice, it won't be changed unless the
195 // constraint is longer than one character.
196 std::string convertConstraint(const char *&Constraint) const override {
197 const char *Begin = Constraint;
198 TargetInfo::ConstraintInfo Info("", "");
199 if (validateAsmConstraint(Constraint, Info))
200 return std::string(Begin).substr(0, Constraint - Begin + 1);
201
202 Constraint = Begin;
203 return std::string(1, *Constraint);
204 }
205
206 bool
207 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
208 StringRef CPU,
209 const std::vector<std::string> &FeatureVec) const override;
210
211 void adjustTargetOptions(const CodeGenOptions &CGOpts,
212 TargetOptions &TargetOpts) const override;
213
214 ArrayRef<Builtin::Info> getTargetBuiltins() const override;
215
216 void getTargetDefines(const LangOptions &Opts,
217 MacroBuilder &Builder) const override;
218
219 BuiltinVaListKind getBuiltinVaListKind() const override {
220 return TargetInfo::CharPtrBuiltinVaList;
221 }
222
223 bool isValidCPUName(StringRef Name) const override {
224 if (getTriple().getArch() == llvm::Triple::amdgcn)
225 return llvm::AMDGPU::parseArchAMDGCN(Name) != llvm::AMDGPU::GK_NONE;
226 return llvm::AMDGPU::parseArchR600(Name) != llvm::AMDGPU::GK_NONE;
227 }
228
229 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
230
231 bool setCPU(const std::string &Name) override {
232 if (getTriple().getArch() == llvm::Triple::amdgcn) {
233 GPUKind = llvm::AMDGPU::parseArchAMDGCN(Name);
234 GPUFeatures = llvm::AMDGPU::getArchAttrAMDGCN(GPUKind);
235 } else {
236 GPUKind = llvm::AMDGPU::parseArchR600(Name);
237 GPUFeatures = llvm::AMDGPU::getArchAttrR600(GPUKind);
238 }
239
240 return GPUKind != llvm::AMDGPU::GK_NONE;
241 }
242
243 void setSupportedOpenCLOpts() override {
244 auto &Opts = getSupportedOpenCLOpts();
245 Opts.support("cl_clang_storage_class_specifiers");
246 Opts.support("cl_khr_icd");
247
248 bool IsAMDGCN = isAMDGCN(getTriple());
249
250 if (hasFP64())
251 Opts.support("cl_khr_fp64");
252
253 if (IsAMDGCN || GPUKind >= llvm::AMDGPU::GK_CEDAR) {
254 Opts.support("cl_khr_byte_addressable_store");
255 Opts.support("cl_khr_global_int32_base_atomics");
256 Opts.support("cl_khr_global_int32_extended_atomics");
257 Opts.support("cl_khr_local_int32_base_atomics");
258 Opts.support("cl_khr_local_int32_extended_atomics");
259 }
260
261 if (IsAMDGCN) {
262 Opts.support("cl_khr_fp16");
263 Opts.support("cl_khr_int64_base_atomics");
264 Opts.support("cl_khr_int64_extended_atomics");
265 Opts.support("cl_khr_mipmap_image");
266 Opts.support("cl_khr_subgroups");
267 Opts.support("cl_khr_3d_image_writes");
268 Opts.support("cl_amd_media_ops");
269 Opts.support("cl_amd_media_ops2");
270 }
271 }
272
273 LangAS getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const override {
274 switch (TK) {
275 case OCLTK_Image:
276 return LangAS::opencl_constant;
277
278 case OCLTK_ClkEvent:
279 case OCLTK_Queue:
280 case OCLTK_ReserveID:
281 return LangAS::opencl_global;
282
283 default:
284 return TargetInfo::getOpenCLTypeAddrSpace(TK);
285 }
286 }
287
288 LangAS getOpenCLBuiltinAddressSpace(unsigned AS) const override {
289 switch (AS) {
290 case 0:
291 return LangAS::opencl_generic;
292 case 1:
293 return LangAS::opencl_global;
294 case 3:
295 return LangAS::opencl_local;
296 case 4:
297 return LangAS::opencl_constant;
298 case 5:
299 return LangAS::opencl_private;
300 default:
301 return getLangASFromTargetAS(AS);
302 }
303 }
304
305 LangAS getCUDABuiltinAddressSpace(unsigned AS) const override {
306 return LangAS::Default;
307 }
308
309 llvm::Optional<LangAS> getConstantAddressSpace() const override {
310 return getLangASFromTargetAS(Constant);
311 }
312
313 /// \returns Target specific vtbl ptr address space.
314 unsigned getVtblPtrAddressSpace() const override {
315 return static_cast<unsigned>(Constant);
316 }
317
318 /// \returns If a target requires an address within a target specific address
319 /// space \p AddressSpace to be converted in order to be used, then return the
320 /// corresponding target specific DWARF address space.
321 ///
322 /// \returns Otherwise return None and no conversion will be emitted in the
323 /// DWARF.
324 Optional<unsigned>
325 getDWARFAddressSpace(unsigned AddressSpace) const override {
326 const unsigned DWARF_Private = 1;
327 const unsigned DWARF_Local = 2;
328 if (AddressSpace == Private) {
329 return DWARF_Private;
330 } else if (AddressSpace == Local) {
331 return DWARF_Local;
332 } else {
333 return None;
334 }
335 }
336
337 CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
338 switch (CC) {
339 default:
340 return CCCR_Warning;
341 case CC_C:
342 case CC_OpenCLKernel:
343 return CCCR_OK;
344 }
345 }
346
347 // In amdgcn target the null pointer in global, constant, and generic
348 // address space has value 0 but in private and local address space has
349 // value ~0.
350 uint64_t getNullPointerValue(LangAS AS) const override {
351 return AS == LangAS::opencl_local ? ~0 : 0;
352 }
353
354 void setAuxTarget(const TargetInfo *Aux) override;
355 };
356
357 } // namespace targets
358 } // namespace clang
359
360 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_AMDGPU_H
clang::CC_OpenCLKernel
Definition: Specifiers.h:279
clang::targets::AMDGPUTargetInfo::convertConstraint
std::string convertConstraint(const char *&Constraint) const override
Definition: AMDGPU.h:196
clang::targets::AMDGPUTargetInfo::checkCallingConvention
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override
Determines whether a given calling convention is valid for the target.
Definition: AMDGPU.h:337
clang::targets::AMDGPUTargetInfo::getGCCRegAliases
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
Definition: AMDGPU.h:110
clang::targets::AMDGPUTargetInfo::getPointerWidthV
uint64_t getPointerWidthV(unsigned AddrSpace) const override
Definition: AMDGPU.h:88
clang::targets::AMDGPUTargetInfo::setSupportedOpenCLOpts
void setSupportedOpenCLOpts() override
Set supported OpenCL extensions and optional core features.
Definition: AMDGPU.h:243
BuiltinInfo
static const Builtin::Info BuiltinInfo[]
Definition: Builtins.cpp:20
clang::TargetInfo::getOpenCLTypeAddrSpace
virtual LangAS getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const
Get address space for OpenCL type.
Definition: TargetInfo.cpp:422
clang::getLangASFromTargetAS
LangAS getLangASFromTargetAS(unsigned TargetAS)
Definition: AddressSpaces.h:71
clang::TargetOptions
Options for controlling the target.
Definition: TargetOptions.h:26
clang::LangAS
LangAS
Defines the address space values used by the address space qualifier of QualType. ...
Definition: AddressSpaces.h:25
clang::targets::AMDGPUTargetInfo::getDWARFAddressSpace
Optional< unsigned > getDWARFAddressSpace(unsigned AddressSpace) const override
Definition: AMDGPU.h:325
clang::targets::AMDGPUTargetInfo::getPointerAlignV
uint64_t getPointerAlignV(unsigned AddrSpace) const override
Definition: AMDGPU.h:98
clang::Builtin::Info
Definition: Builtins.h:53
llvm::Optional
Definition: LLVM.h:37
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:53
llvm::SmallVectorImpl
Definition: LLVM.h:36
clang::targets::AMDGPUTargetInfo::getCUDABuiltinAddressSpace
LangAS getCUDABuiltinAddressSpace(unsigned AS) const override
Map from the address space field in builtin description strings to the language address space...
Definition: AMDGPU.h:305
clang::DiagnosticsEngine
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:149
clang::LangAS::opencl_private
clang::targets::AMDGPUTargetInfo::getOpenCLTypeAddrSpace
LangAS getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const override
Get address space for OpenCL type.
Definition: AMDGPU.h:273
clang::targets::AMDGPUTargetInfo::getNullPointerValue
uint64_t getNullPointerValue(LangAS AS) const override
Get integer value for null pointer.
Definition: AMDGPU.h:350
llvm::ArrayRef
Definition: LLVM.h:31
clang::targets::GCCRegNames
static const char *const GCCRegNames[]
Definition: X86.cpp:43
clang::targets::AMDGPUTargetInfo::validateAsmConstraint
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &Info) const override
Accepted register names: (n, m is unsigned integer, n < m) v s {vn}, {v[n]} {sn}, {s[n]} {S} ...
Definition: AMDGPU.h:122
clang::TargetInfo
Exposes information about the current target.
Definition: TargetInfo.h:164
clang::LangAS::opencl_local
clang::targets::AMDGPUTargetInfo::getVtblPtrAddressSpace
unsigned getVtblPtrAddressSpace() const override
Definition: AMDGPU.h:314
clang::targets::AMDGPUTargetInfo::setCPU
bool setCPU(const std::string &Name) override
Target the specified CPU.
Definition: AMDGPU.h:231
Begin
SourceLocation Begin
Definition: USRLocFinder.cpp:164
clang::CallingConv
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:265
clang::TargetInfo::ConstraintInfo
Definition: TargetInfo.h:830
clang::targets::AMDGPUTargetInfo::getClobbers
const char * getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition: AMDGPU.h:106
clang::TargetInfo::ConstraintInfo::setAllowsRegister
void setAllowsRegister()
Definition: TargetInfo.h:895
clang::LangAS::opencl_generic
clang::LangAS::Default
clang::targets::AMDGPUTargetInfo::getBuiltinVaListKind
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition: AMDGPU.h:219
TargetOptions.h
Defines the clang::TargetOptions class.
clang::targets::AMDGPUTargetInfo::getConstantAddressSpace
llvm::Optional< LangAS > getConstantAddressSpace() const override
Return an AST address space which can be used opportunistically for constant global memory...
Definition: AMDGPU.h:309
clang::targets::AMDGPUTargetInfo::isValidCPUName
bool isValidCPUName(StringRef Name) const override
brief Determine whether this TargetInfo supports the given CPU name.
Definition: AMDGPU.h:223
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:21
clang::TargetInfo::CharPtrBuiltinVaList
typedef char* __builtin_va_list;
Definition: TargetInfo.h:228
clang::LangASMap
unsigned[(unsigned) LangAS::FirstTargetAddressSpace] LangASMap
The type of a lookup table which maps from language-specific address spaces to target-specific ones...
Definition: AddressSpaces.h:58
clang::targets::AMDGPUTargetInfo::getOpenCLBuiltinAddressSpace
LangAS getOpenCLBuiltinAddressSpace(unsigned AS) const override
Map from the address space field in builtin description strings to the language address space...
Definition: AMDGPU.h:288
clang::CC_C
Definition: Specifiers.h:266
clang::LangAS::opencl_global
clang::targets::AMDGPUTargetInfo
Definition: AMDGPU.h:26
clang::CodeGenOptions
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
Definition: CodeGenOptions.h:46
clang::MacroBuilder
Definition: MacroBuilder.h:23
clang::TargetInfo::BuiltinVaListKind
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition: TargetInfo.h:226
clang::TargetInfo::OpenCLTypeKind
OpenCLTypeKind
Definition: TargetInfo.h:1348
TargetInfo.h
Defines the clang::TargetInfo interface.
clang::LangAS::opencl_constant
clang::TargetInfo::CallingConvCheckResult
CallingConvCheckResult
Definition: TargetInfo.h:1283
clang::targets::AMDGPUTargetInfo::getMaxPointerWidth
uint64_t getMaxPointerWidth() const override
Return the maximum width of pointers on this target.
Definition: AMDGPU.h:102