1 //===--- AMDGPU.h - Declare AMDGPU target feature support -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares AMDGPU TargetInfo objects.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_AMDGPU_H
15 #define LLVM_CLANG_LIB_BASIC_TARGETS_AMDGPU_H
17 #include "clang/Basic/TargetInfo.h"
18 #include "clang/Basic/TargetOptions.h"
19 #include "llvm/ADT/StringSet.h"
20 #include "llvm/ADT/Triple.h"
21 #include "llvm/Support/Compiler.h"
26 class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
28 static const Builtin::Info BuiltinInfo[];
29 static const char *const GCCRegNames[];
38 static const LangASMap AMDGPUDefIsGenMap;
39 static const LangASMap AMDGPUDefIsPrivMap;
41 /// GPU kinds supported by the AMDGPU target.
42 enum GPUKind : uint32_t {
43 // Not specified processor.
46 // R600-based processors.
64 GK_R600_FIRST = GK_R600,
65 GK_R600_LAST = GK_TURKS,
67 // AMDGCN-based processors.
84 GK_AMDGCN_FIRST = GK_GFX600,
85 GK_AMDGCN_LAST = GK_GFX906,
89 llvm::StringLiteral Name;
90 llvm::StringLiteral CanonicalName;
91 AMDGPUTargetInfo::GPUKind Kind;
99 static constexpr GPUInfo InvalidGPU =
100 {{""}, {""}, GK_NONE, false, false, false, false, false};
101 static constexpr GPUInfo R600GPUs[26] = {
102 // Name Canonical Kind Has Has Has Has Has
103 // Name FMAF Fast LDEXPF FP64 Fast
105 {{"r600"}, {"r600"}, GK_R600, false, false, false, false, false},
106 {{"rv630"}, {"r600"}, GK_R600, false, false, false, false, false},
107 {{"rv635"}, {"r600"}, GK_R600, false, false, false, false, false},
108 {{"r630"}, {"r630"}, GK_R630, false, false, false, false, false},
109 {{"rs780"}, {"rs880"}, GK_RS880, false, false, false, false, false},
110 {{"rs880"}, {"rs880"}, GK_RS880, false, false, false, false, false},
111 {{"rv610"}, {"rs880"}, GK_RS880, false, false, false, false, false},
112 {{"rv620"}, {"rs880"}, GK_RS880, false, false, false, false, false},
113 {{"rv670"}, {"rv670"}, GK_RV670, false, false, false, false, false},
114 {{"rv710"}, {"rv710"}, GK_RV710, false, false, false, false, false},
115 {{"rv730"}, {"rv730"}, GK_RV730, false, false, false, false, false},
116 {{"rv740"}, {"rv770"}, GK_RV770, false, false, false, false, false},
117 {{"rv770"}, {"rv770"}, GK_RV770, false, false, false, false, false},
118 {{"cedar"}, {"cedar"}, GK_CEDAR, false, false, false, false, false},
119 {{"palm"}, {"cedar"}, GK_CEDAR, false, false, false, false, false},
120 {{"cypress"}, {"cypress"}, GK_CYPRESS, true, false, false, false, false},
121 {{"hemlock"}, {"cypress"}, GK_CYPRESS, true, false, false, false, false},
122 {{"juniper"}, {"juniper"}, GK_JUNIPER, false, false, false, false, false},
123 {{"redwood"}, {"redwood"}, GK_REDWOOD, false, false, false, false, false},
124 {{"sumo"}, {"sumo"}, GK_SUMO, false, false, false, false, false},
125 {{"sumo2"}, {"sumo"}, GK_SUMO, false, false, false, false, false},
126 {{"barts"}, {"barts"}, GK_BARTS, false, false, false, false, false},
127 {{"caicos"}, {"caicos"}, GK_BARTS, false, false, false, false, false},
128 {{"aruba"}, {"cayman"}, GK_CAYMAN, true, false, false, false, false},
129 {{"cayman"}, {"cayman"}, GK_CAYMAN, true, false, false, false, false},
130 {{"turks"}, {"turks"}, GK_TURKS, false, false, false, false, false},
132 static constexpr GPUInfo AMDGCNGPUs[32] = {
133 // Name Canonical Kind Has Has Has Has Has
134 // Name FMAF Fast LDEXPF FP64 Fast
136 {{"gfx600"}, {"gfx600"}, GK_GFX600, true, true, true, true, true},
137 {{"tahiti"}, {"gfx600"}, GK_GFX600, true, true, true, true, true},
138 {{"gfx601"}, {"gfx601"}, GK_GFX601, true, false, true, true, true},
139 {{"hainan"}, {"gfx601"}, GK_GFX601, true, false, true, true, true},
140 {{"oland"}, {"gfx601"}, GK_GFX601, true, false, true, true, true},
141 {{"pitcairn"}, {"gfx601"}, GK_GFX601, true, false, true, true, true},
142 {{"verde"}, {"gfx601"}, GK_GFX601, true, false, true, true, true},
143 {{"gfx700"}, {"gfx700"}, GK_GFX700, true, false, true, true, true},
144 {{"kaveri"}, {"gfx700"}, GK_GFX700, true, false, true, true, true},
145 {{"gfx701"}, {"gfx701"}, GK_GFX701, true, true, true, true, true},
146 {{"hawaii"}, {"gfx701"}, GK_GFX701, true, true, true, true, true},
147 {{"gfx702"}, {"gfx702"}, GK_GFX702, true, true, true, true, true},
148 {{"gfx703"}, {"gfx703"}, GK_GFX703, true, false, true, true, true},
149 {{"kabini"}, {"gfx703"}, GK_GFX703, true, false, true, true, true},
150 {{"mullins"}, {"gfx703"}, GK_GFX703, true, false, true, true, true},
151 {{"gfx704"}, {"gfx704"}, GK_GFX704, true, false, true, true, true},
152 {{"bonaire"}, {"gfx704"}, GK_GFX704, true, false, true, true, true},
153 {{"gfx801"}, {"gfx801"}, GK_GFX801, true, true, true, true, true},
154 {{"carrizo"}, {"gfx801"}, GK_GFX801, true, true, true, true, true},
155 {{"gfx802"}, {"gfx802"}, GK_GFX802, true, false, true, true, true},
156 {{"iceland"}, {"gfx802"}, GK_GFX802, true, false, true, true, true},
157 {{"tonga"}, {"gfx802"}, GK_GFX802, true, false, true, true, true},
158 {{"gfx803"}, {"gfx803"}, GK_GFX803, true, false, true, true, true},
159 {{"fiji"}, {"gfx803"}, GK_GFX803, true, false, true, true, true},
160 {{"polaris10"}, {"gfx803"}, GK_GFX803, true, false, true, true, true},
161 {{"polaris11"}, {"gfx803"}, GK_GFX803, true, false, true, true, true},
162 {{"gfx810"}, {"gfx810"}, GK_GFX810, true, false, true, true, true},
163 {{"stoney"}, {"gfx810"}, GK_GFX810, true, false, true, true, true},
164 {{"gfx900"}, {"gfx900"}, GK_GFX900, true, true, true, true, true},
165 {{"gfx902"}, {"gfx902"}, GK_GFX900, true, true, true, true, true},
166 {{"gfx904"}, {"gfx904"}, GK_GFX904, true, true, true, true, true},
167 {{"gfx906"}, {"gfx906"}, GK_GFX906, true, true, true, true, true},
170 static GPUInfo parseR600Name(StringRef Name);
172 static GPUInfo parseAMDGCNName(StringRef Name);
174 GPUInfo parseGPUName(StringRef Name) const;
178 static bool isAMDGCN(const llvm::Triple &TT) {
179 return TT.getArch() == llvm::Triple::amdgcn;
183 AMDGPUTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
185 void setAddressSpaceMap(bool DefaultIsPrivate);
187 void adjust(LangOptions &Opts) override;
189 uint64_t getPointerWidthV(unsigned AddrSpace) const override {
190 if (GPU.Kind <= GK_R600_LAST)
192 if (AddrSpace == Private || AddrSpace == Local)
197 uint64_t getPointerAlignV(unsigned AddrSpace) const override {
198 return getPointerWidthV(AddrSpace);
201 uint64_t getMaxPointerWidth() const override {
202 return getTriple().getArch() == llvm::Triple::amdgcn ? 64 : 32;
205 const char *getClobbers() const override { return ""; }
207 ArrayRef<const char *> getGCCRegNames() const override;
209 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
213 /// Accepted register names: (n, m is unsigned integer, n < m)
218 /// {S} , where S is a special register name
221 bool validateAsmConstraint(const char *&Name,
222 TargetInfo::ConstraintInfo &Info) const override {
223 static const ::llvm::StringSet<> SpecialRegs({
224 "exec", "vcc", "flat_scratch", "m0", "scc", "tba", "tma",
225 "flat_scratch_lo", "flat_scratch_hi", "vcc_lo", "vcc_hi", "exec_lo",
226 "exec_hi", "tma_lo", "tma_hi", "tba_lo", "tba_hi",
230 bool HasLeftParen = false;
231 if (S.front() == '{') {
237 if (S.front() != 'v' && S.front() != 's') {
240 auto E = S.find('}');
241 if (!SpecialRegs.count(S.substr(0, E)))
243 S = S.drop_front(E + 1);
246 // Found {S} where S is a special register.
247 Info.setAllowsRegister();
256 Info.setAllowsRegister();
260 bool HasLeftBracket = false;
261 if (!S.empty() && S.front() == '[') {
262 HasLeftBracket = true;
265 unsigned long long N;
266 if (S.empty() || consumeUnsignedInteger(S, 10, N))
268 if (!S.empty() && S.front() == ':') {
272 unsigned long long M;
273 if (consumeUnsignedInteger(S, 10, M) || N >= M)
276 if (HasLeftBracket) {
277 if (S.empty() || S.front() != ']')
281 if (S.empty() || S.front() != '}')
286 // Found {vn}, {sn}, {v[n]}, {s[n]}, {v[n:m]}, or {s[n:m]}.
287 Info.setAllowsRegister();
292 // \p Constraint will be left pointing at the last character of
293 // the constraint. In practice, it won't be changed unless the
294 // constraint is longer than one character.
295 std::string convertConstraint(const char *&Constraint) const override {
296 const char *Begin = Constraint;
297 TargetInfo::ConstraintInfo Info("", "");
298 if (validateAsmConstraint(Constraint, Info))
299 return std::string(Begin).substr(0, Constraint - Begin + 1);
302 return std::string(1, *Constraint);
306 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
308 const std::vector<std::string> &FeatureVec) const override;
310 void adjustTargetOptions(const CodeGenOptions &CGOpts,
311 TargetOptions &TargetOpts) const override;
313 ArrayRef<Builtin::Info> getTargetBuiltins() const override;
315 void getTargetDefines(const LangOptions &Opts,
316 MacroBuilder &Builder) const override;
318 BuiltinVaListKind getBuiltinVaListKind() const override {
319 return TargetInfo::CharPtrBuiltinVaList;
322 bool isValidCPUName(StringRef Name) const override {
323 if (getTriple().getArch() == llvm::Triple::amdgcn)
324 return GK_NONE != parseAMDGCNName(Name).Kind;
326 return GK_NONE != parseR600Name(Name).Kind;
329 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
331 bool setCPU(const std::string &Name) override {
332 if (getTriple().getArch() == llvm::Triple::amdgcn)
333 GPU = parseAMDGCNName(Name);
335 GPU = parseR600Name(Name);
337 return GK_NONE != GPU.Kind;
340 void setSupportedOpenCLOpts() override {
341 auto &Opts = getSupportedOpenCLOpts();
342 Opts.support("cl_clang_storage_class_specifiers");
343 Opts.support("cl_khr_icd");
346 Opts.support("cl_khr_fp64");
347 if (GPU.Kind >= GK_CEDAR) {
348 Opts.support("cl_khr_byte_addressable_store");
349 Opts.support("cl_khr_global_int32_base_atomics");
350 Opts.support("cl_khr_global_int32_extended_atomics");
351 Opts.support("cl_khr_local_int32_base_atomics");
352 Opts.support("cl_khr_local_int32_extended_atomics");
354 if (GPU.Kind >= GK_AMDGCN_FIRST) {
355 Opts.support("cl_khr_fp16");
356 Opts.support("cl_khr_int64_base_atomics");
357 Opts.support("cl_khr_int64_extended_atomics");
358 Opts.support("cl_khr_mipmap_image");
359 Opts.support("cl_khr_subgroups");
360 Opts.support("cl_khr_3d_image_writes");
361 Opts.support("cl_amd_media_ops");
362 Opts.support("cl_amd_media_ops2");
366 LangAS getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const override {
369 return LangAS::opencl_constant;
373 case OCLTK_ReserveID:
374 return LangAS::opencl_global;
377 return TargetInfo::getOpenCLTypeAddrSpace(TK);
381 llvm::Optional<LangAS> getConstantAddressSpace() const override {
382 return getLangASFromTargetAS(Constant);
385 /// \returns Target specific vtbl ptr address space.
386 unsigned getVtblPtrAddressSpace() const override {
387 return static_cast<unsigned>(Constant);
390 /// \returns If a target requires an address within a target specific address
391 /// space \p AddressSpace to be converted in order to be used, then return the
392 /// corresponding target specific DWARF address space.
394 /// \returns Otherwise return None and no conversion will be emitted in the
397 getDWARFAddressSpace(unsigned AddressSpace) const override {
398 const unsigned DWARF_Private = 1;
399 const unsigned DWARF_Local = 2;
400 if (AddressSpace == Private) {
401 return DWARF_Private;
402 } else if (AddressSpace == Local) {
409 CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
414 case CC_OpenCLKernel:
419 // In amdgcn target the null pointer in global, constant, and generic
420 // address space has value 0 but in private and local address space has
422 uint64_t getNullPointerValue(LangAS AS) const override {
423 return AS == LangAS::opencl_local ? ~0 : 0;
427 } // namespace targets
430 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_AMDGPU_H