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"
22 #include "llvm/Support/TargetParser.h"
27 class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
29 static const Builtin::Info BuiltinInfo[];
30 static const char *const GCCRegNames[];
39 static const LangASMap AMDGPUDefIsGenMap;
40 static const LangASMap AMDGPUDefIsPrivMap;
42 llvm::AMDGPU::GPUKind GPUKind;
46 bool hasFP64() const {
47 return getTriple().getArch() == llvm::Triple::amdgcn ||
48 !!(GPUFeatures & llvm::AMDGPU::FEATURE_FP64);
52 bool hasFastFMAF() const {
53 return !!(GPUFeatures & llvm::AMDGPU::FEATURE_FAST_FMA_F32);
57 bool hasFastFMA() const {
58 return getTriple().getArch() == llvm::Triple::amdgcn;
61 bool hasFMAF() const {
62 return getTriple().getArch() == llvm::Triple::amdgcn ||
63 !!(GPUFeatures & llvm::AMDGPU::FEATURE_FMA);
66 bool hasFullRateDenormalsF32() const {
67 return !!(GPUFeatures & llvm::AMDGPU::FEATURE_FAST_DENORMAL_F32);
70 bool hasLDEXPF() const {
71 return getTriple().getArch() == llvm::Triple::amdgcn ||
72 !!(GPUFeatures & llvm::AMDGPU::FEATURE_LDEXP);
75 static bool isAMDGCN(const llvm::Triple &TT) {
76 return TT.getArch() == llvm::Triple::amdgcn;
79 static bool isR600(const llvm::Triple &TT) {
80 return TT.getArch() == llvm::Triple::r600;
84 AMDGPUTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
86 void setAddressSpaceMap(bool DefaultIsPrivate);
88 void adjust(LangOptions &Opts) override;
90 uint64_t getPointerWidthV(unsigned AddrSpace) const override {
91 if (isR600(getTriple()))
94 if (AddrSpace == Private || AddrSpace == Local)
100 uint64_t getPointerAlignV(unsigned AddrSpace) const override {
101 return getPointerWidthV(AddrSpace);
104 uint64_t getMaxPointerWidth() const override {
105 return getTriple().getArch() == llvm::Triple::amdgcn ? 64 : 32;
108 const char *getClobbers() const override { return ""; }
110 ArrayRef<const char *> getGCCRegNames() const override;
112 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
116 /// Accepted register names: (n, m is unsigned integer, n < m)
121 /// {S} , where S is a special register name
124 bool validateAsmConstraint(const char *&Name,
125 TargetInfo::ConstraintInfo &Info) const override {
126 static const ::llvm::StringSet<> SpecialRegs({
127 "exec", "vcc", "flat_scratch", "m0", "scc", "tba", "tma",
128 "flat_scratch_lo", "flat_scratch_hi", "vcc_lo", "vcc_hi", "exec_lo",
129 "exec_hi", "tma_lo", "tma_hi", "tba_lo", "tba_hi",
133 bool HasLeftParen = false;
134 if (S.front() == '{') {
140 if (S.front() != 'v' && S.front() != 's') {
143 auto E = S.find('}');
144 if (!SpecialRegs.count(S.substr(0, E)))
146 S = S.drop_front(E + 1);
149 // Found {S} where S is a special register.
150 Info.setAllowsRegister();
159 Info.setAllowsRegister();
163 bool HasLeftBracket = false;
164 if (!S.empty() && S.front() == '[') {
165 HasLeftBracket = true;
168 unsigned long long N;
169 if (S.empty() || consumeUnsignedInteger(S, 10, N))
171 if (!S.empty() && S.front() == ':') {
175 unsigned long long M;
176 if (consumeUnsignedInteger(S, 10, M) || N >= M)
179 if (HasLeftBracket) {
180 if (S.empty() || S.front() != ']')
184 if (S.empty() || S.front() != '}')
189 // Found {vn}, {sn}, {v[n]}, {s[n]}, {v[n:m]}, or {s[n:m]}.
190 Info.setAllowsRegister();
195 // \p Constraint will be left pointing at the last character of
196 // the constraint. In practice, it won't be changed unless the
197 // constraint is longer than one character.
198 std::string convertConstraint(const char *&Constraint) const override {
199 const char *Begin = Constraint;
200 TargetInfo::ConstraintInfo Info("", "");
201 if (validateAsmConstraint(Constraint, Info))
202 return std::string(Begin).substr(0, Constraint - Begin + 1);
205 return std::string(1, *Constraint);
209 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
211 const std::vector<std::string> &FeatureVec) const override;
213 void adjustTargetOptions(const CodeGenOptions &CGOpts,
214 TargetOptions &TargetOpts) const override;
216 ArrayRef<Builtin::Info> getTargetBuiltins() const override;
218 void getTargetDefines(const LangOptions &Opts,
219 MacroBuilder &Builder) const override;
221 BuiltinVaListKind getBuiltinVaListKind() const override {
222 return TargetInfo::CharPtrBuiltinVaList;
225 bool isValidCPUName(StringRef Name) const override {
226 if (getTriple().getArch() == llvm::Triple::amdgcn)
227 return llvm::AMDGPU::parseArchAMDGCN(Name) != llvm::AMDGPU::GK_NONE;
228 return llvm::AMDGPU::parseArchR600(Name) != llvm::AMDGPU::GK_NONE;
231 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
233 bool setCPU(const std::string &Name) override {
234 if (getTriple().getArch() == llvm::Triple::amdgcn) {
235 GPUKind = llvm::AMDGPU::parseArchAMDGCN(Name);
236 GPUFeatures = llvm::AMDGPU::getArchAttrAMDGCN(GPUKind);
238 GPUKind = llvm::AMDGPU::parseArchR600(Name);
239 GPUFeatures = llvm::AMDGPU::getArchAttrR600(GPUKind);
242 return GPUKind != llvm::AMDGPU::GK_NONE;
245 void setSupportedOpenCLOpts() override {
246 auto &Opts = getSupportedOpenCLOpts();
247 Opts.support("cl_clang_storage_class_specifiers");
248 Opts.support("cl_khr_icd");
250 bool IsAMDGCN = isAMDGCN(getTriple());
253 Opts.support("cl_khr_fp64");
255 if (IsAMDGCN || GPUKind >= llvm::AMDGPU::GK_CEDAR) {
256 Opts.support("cl_khr_byte_addressable_store");
257 Opts.support("cl_khr_global_int32_base_atomics");
258 Opts.support("cl_khr_global_int32_extended_atomics");
259 Opts.support("cl_khr_local_int32_base_atomics");
260 Opts.support("cl_khr_local_int32_extended_atomics");
264 Opts.support("cl_khr_fp16");
265 Opts.support("cl_khr_int64_base_atomics");
266 Opts.support("cl_khr_int64_extended_atomics");
267 Opts.support("cl_khr_mipmap_image");
268 Opts.support("cl_khr_subgroups");
269 Opts.support("cl_khr_3d_image_writes");
270 Opts.support("cl_amd_media_ops");
271 Opts.support("cl_amd_media_ops2");
275 LangAS getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const override {
278 return LangAS::opencl_constant;
282 case OCLTK_ReserveID:
283 return LangAS::opencl_global;
286 return TargetInfo::getOpenCLTypeAddrSpace(TK);
290 LangAS getOpenCLBuiltinAddressSpace(unsigned AS) const override {
293 return LangAS::opencl_generic;
295 return LangAS::opencl_global;
297 return LangAS::opencl_local;
299 return LangAS::opencl_constant;
301 return LangAS::opencl_private;
303 return getLangASFromTargetAS(AS);
307 LangAS getCUDABuiltinAddressSpace(unsigned AS) const override {
308 return LangAS::Default;
311 llvm::Optional<LangAS> getConstantAddressSpace() const override {
312 return getLangASFromTargetAS(Constant);
315 /// \returns Target specific vtbl ptr address space.
316 unsigned getVtblPtrAddressSpace() const override {
317 return static_cast<unsigned>(Constant);
320 /// \returns If a target requires an address within a target specific address
321 /// space \p AddressSpace to be converted in order to be used, then return the
322 /// corresponding target specific DWARF address space.
324 /// \returns Otherwise return None and no conversion will be emitted in the
327 getDWARFAddressSpace(unsigned AddressSpace) const override {
328 const unsigned DWARF_Private = 1;
329 const unsigned DWARF_Local = 2;
330 if (AddressSpace == Private) {
331 return DWARF_Private;
332 } else if (AddressSpace == Local) {
339 CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
344 case CC_OpenCLKernel:
349 // In amdgcn target the null pointer in global, constant, and generic
350 // address space has value 0 but in private and local address space has
352 uint64_t getNullPointerValue(LangAS AS) const override {
353 return AS == LangAS::opencl_local ? ~0 : 0;
357 } // namespace targets
360 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_AMDGPU_H