13#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_AMDGPU_H
14#define LLVM_CLANG_LIB_BASIC_TARGETS_AMDGPU_H
19#include "llvm/ADT/StringSet.h"
20#include "llvm/Support/AMDGPUAddrSpace.h"
21#include "llvm/Support/Compiler.h"
22#include "llvm/TargetParser/TargetParser.h"
23#include "llvm/TargetParser/Triple.h"
31 static const char *
const GCCRegNames[];
34 static const LangASMap AMDGPUDefIsPrivMap;
36 llvm::AMDGPU::GPUKind GPUKind;
38 unsigned WavefrontSize;
44 bool HasImage =
false;
51 llvm::StringMap<bool> OffloadArchFeatures;
54 bool hasFP64()
const {
56 !!(GPUFeatures & llvm::AMDGPU::FEATURE_FP64);
60 bool hasFastFMAF()
const {
61 return !!(GPUFeatures & llvm::AMDGPU::FEATURE_FAST_FMA_F32);
65 bool hasFastFMA()
const {
return getTriple().isAMDGCN(); }
67 bool hasFMAF()
const {
69 !!(GPUFeatures & llvm::AMDGPU::FEATURE_FMA);
72 bool hasFullRateDenormalsF32()
const {
73 return !!(GPUFeatures & llvm::AMDGPU::FEATURE_FAST_DENORMAL_F32);
76 bool hasLDEXPF()
const {
78 !!(GPUFeatures & llvm::AMDGPU::FEATURE_LDEXP);
81 static bool isR600(
const llvm::Triple &TT) {
82 return TT.getArch() == llvm::Triple::r600;
85 bool hasFlatSupport()
const {
86 if (GPUKind >= llvm::AMDGPU::GK_GFX700)
90 if (GPUKind == llvm::AMDGPU::GK_NONE &&
91 getTriple().getOS() == llvm::Triple::AMDHSA)
110 if (TargetAS == llvm::AMDGPUAS::PRIVATE_ADDRESS ||
111 TargetAS == llvm::AMDGPUAS::LOCAL_ADDRESS)
161 static const ::llvm::StringSet<> SpecialRegs({
162 "exec",
"vcc",
"flat_scratch",
"m0",
"scc",
"tba",
"tma",
163 "flat_scratch_lo",
"flat_scratch_hi",
"vcc_lo",
"vcc_hi",
"exec_lo",
164 "exec_hi",
"tma_lo",
"tma_hi",
"tba_lo",
"tba_hi",
185 if (S ==
"DA" || S ==
"DB") {
191 bool HasLeftParen = S.consume_front(
"{");
194 if (S.front() !=
'v' && S.front() !=
's' && S.front() !=
'a') {
197 auto E = S.find(
'}');
198 if (!SpecialRegs.count(S.substr(0, E)))
200 S = S.drop_front(E + 1);
217 bool HasLeftBracket = S.consume_front(
"[");
218 unsigned long long N;
219 if (S.empty() || consumeUnsignedInteger(S, 10, N))
221 if (S.consume_front(
":")) {
224 unsigned long long M;
225 if (consumeUnsignedInteger(S, 10, M) || N >= M)
228 if (HasLeftBracket) {
229 if (!S.consume_front(
"]"))
232 if (!S.consume_front(
"}"))
248 StringRef S(Constraint);
249 if (S ==
"DA" || S ==
"DB") {
250 return std::string(
"^") + std::string(Constraint++, 2);
253 const char *Begin = Constraint;
256 return std::string(Begin).substr(0, Constraint - Begin + 1);
259 return std::string(1, *Constraint);
265 const std::vector<std::string> &FeatureVec)
const override;
280 return llvm::AMDGPU::parseArchAMDGCN(Name) != llvm::AMDGPU::GK_NONE;
281 return llvm::AMDGPU::parseArchR600(Name) != llvm::AMDGPU::GK_NONE;
286 bool setCPU(
const std::string &Name)
override {
288 GPUKind = llvm::AMDGPU::parseArchAMDGCN(Name);
289 GPUFeatures = llvm::AMDGPU::getArchAttrAMDGCN(GPUKind);
291 GPUKind = llvm::AMDGPU::parseArchR600(Name);
292 GPUFeatures = llvm::AMDGPU::getArchAttrR600(GPUKind);
295 return GPUKind != llvm::AMDGPU::GK_NONE;
300 Opts[
"cl_clang_storage_class_specifiers"] =
true;
301 Opts[
"__cl_clang_variadic_functions"] =
true;
302 Opts[
"__cl_clang_function_pointers"] =
true;
303 Opts[
"__cl_clang_function_scope_local_variables"] =
true;
304 Opts[
"__cl_clang_non_portable_kernel_param_types"] =
true;
305 Opts[
"__cl_clang_bitfields"] =
true;
309 Opts[
"cl_khr_fp64"] = hasFP64();
310 Opts[
"__opencl_c_fp64"] = hasFP64();
312 if (IsAMDGCN || GPUKind >= llvm::AMDGPU::GK_CEDAR) {
313 Opts[
"cl_khr_byte_addressable_store"] =
true;
314 Opts[
"cl_khr_global_int32_base_atomics"] =
true;
315 Opts[
"cl_khr_global_int32_extended_atomics"] =
true;
316 Opts[
"cl_khr_local_int32_base_atomics"] =
true;
317 Opts[
"cl_khr_local_int32_extended_atomics"] =
true;
321 Opts[
"cl_khr_fp16"] =
true;
322 Opts[
"cl_khr_int64_base_atomics"] =
true;
323 Opts[
"cl_khr_int64_extended_atomics"] =
true;
324 Opts[
"cl_khr_mipmap_image"] =
true;
325 Opts[
"cl_khr_mipmap_image_writes"] =
true;
326 Opts[
"cl_khr_subgroups"] =
true;
327 Opts[
"cl_amd_media_ops"] =
true;
328 Opts[
"cl_amd_media_ops2"] =
true;
331 Opts[
"__opencl_c_images"] =
true;
332 Opts[
"__opencl_c_3d_image_writes"] =
true;
333 Opts[
"__opencl_c_read_write_images"] =
true;
334 Opts[
"cl_khr_3d_image_writes"] =
true;
335 Opts[
"__opencl_c_program_scope_global_variables"] =
true;
336 Opts[
"__opencl_c_atomic_order_acq_rel"] =
true;
337 Opts[
"__opencl_c_atomic_order_seq_cst"] =
true;
338 Opts[
"__opencl_c_atomic_scope_device"] =
true;
339 Opts[
"__opencl_c_atomic_scope_all_devices"] =
true;
340 Opts[
"__opencl_c_work_group_collective_functions"] =
true;
342 if (hasFlatSupport()) {
343 Opts[
"__opencl_c_generic_address_space"] =
true;
344 Opts[
"__opencl_c_device_enqueue"] =
true;
345 Opts[
"__opencl_c_pipes"] =
true;
348 if (
getTriple().getEnvironment() == llvm::Triple::LLVM) {
349 Opts[
"cl_khr_subgroup_extended_types"] =
true;
406 switch (WavefrontSize) {
408 return llvm::omp::getAMDGPUGridValues<32>();
410 return llvm::omp::getAMDGPUGridValues<64>();
412 llvm_unreachable(
"getGridValue not implemented for this wavesize");
418 return static_cast<unsigned>(llvm::AMDGPUAS::CONSTANT_ADDRESS);
427 std::optional<unsigned>
429 int DWARFAS = llvm::AMDGPU::mapToDWARFAddrSpace(AddressSpace);
432 if (DWARFAS == -1 || DWARFAS == llvm::AMDGPU::DWARFAS::DEFAULT)
460 void setAuxTarget(
const TargetInfo *Aux)
override;
469 auto TargetIDFeatures =
471 for (
const auto &F : Features) {
472 assert(F.front() ==
'+' || F.front() ==
'-');
473 if (F ==
"+wavefrontsize64")
475 else if (F ==
"+cumode")
477 else if (F ==
"-cumode")
479 else if (F ==
"+image-insts")
481 bool IsOn = F.front() ==
'+';
482 StringRef Name = StringRef(F).drop_front();
483 if (!llvm::is_contained(TargetIDFeatures, Name))
485 assert(!OffloadArchFeatures.contains(Name));
486 OffloadArchFeatures[Name] = IsOn;
496 if (GPUKind == llvm::AMDGPU::GK_NONE)
497 return std::string(
"");
499 OffloadArchFeatures);
509 return std::make_pair(128, 128);
static StringRef getTriple(const Command &Job)
Defines the clang::TargetOptions class.
Concrete class used by the front-end to report problems and issues.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Exposes information about the current target.
TargetInfo(const llvm::Triple &T)
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
@ CharPtrBuiltinVaList
typedef char* __builtin_va_list;
virtual LangAS getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const
Get address space for OpenCL type.
llvm::StringMap< bool > & getSupportedOpenCLOpts()
Get supported OpenCL extensions and optional core features.
unsigned getTargetAddressSpace(LangAS AS) const
Options for controlling the target.
const llvm::omp::GV & getGridValue() const override
std::string_view getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
uint64_t getPointerAlignV(LangAS AddrSpace) const override
LangAS getOpenCLBuiltinAddressSpace(unsigned AS) const override
Map from the address space field in builtin description strings to the language address space.
AMDGPUTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
uint64_t getPointerWidthV(LangAS AS) const override
bool setCPU(const std::string &Name) override
Target the specified CPU.
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
bool hasBFloat16Type() const override
Determine whether the _BFloat16 type is supported on this target.
uint64_t getNullPointerValue(LangAS AS) const override
Get integer value for null pointer.
void adjust(DiagnosticsEngine &Diags, LangOptions &Opts, const TargetInfo *Aux) override
Set forced language options.
LangAS getCUDABuiltinAddressSpace(unsigned AS) const override
Map from the address space field in builtin description strings to the language address space.
virtual bool isAddressSpaceSupersetOf(LangAS A, LangAS B) const override
Returns true if an address space can be safely converted to another.
bool useFP16ConversionIntrinsics() const override
Check whether conversions to and from __fp16 should go through an integer bitcast with i16.
void setAddressSpaceMap(bool DefaultIsPrivate)
bool handleTargetFeatures(std::vector< std::string > &Features, DiagnosticsEngine &Diags) override
Perform initialization based on the user configured set of features (e.g., +sse4).
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &Info) const override
Accepted register names: (n, m is unsigned integer, n < m) v s a {vn}, {v[n]} {sn}...
std::optional< std::string > getTargetID() const override
Returns the target ID if supported.
std::optional< unsigned > getDWARFAddressSpace(unsigned AddressSpace) const override
std::string convertConstraint(const char *&Constraint) const override
std::pair< unsigned, unsigned > hardwareInterferenceSizes() const override
The first value in the pair is the minimum offset between two objects to avoid false sharing (destruc...
unsigned getVtblPtrAddressSpace() const override
std::optional< LangAS > getConstantAddressSpace() const override
Return an AST address space which can be used opportunistically for constant global memory.
bool isValidCPUName(StringRef Name) const override
Determine whether this TargetInfo supports the given CPU name.
bool hasBitIntType() const override
Determine whether the _BitInt type is supported on this target.
bool hasHIPImageSupport() const override
Whether to support HIP image/texture API's.
uint64_t getMaxPointerWidth() const override
Return the maximum width of pointers on this target.
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override
Determines whether a given calling convention is valid for the target.
LangAS getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const override
Get address space for OpenCL type.
void setSupportedOpenCLOpts() override
Set supported OpenCL extensions and optional core features.
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Defines the clang::TargetInfo interface.
The JSON file list parser is used to communicate input to InstallAPI.
bool isTargetAddressSpace(LangAS AS)
OpenCLTypeKind
OpenCL type kinds.
unsigned toTargetAddressSpace(LangAS AS)
llvm::SmallVector< llvm::StringRef, 4 > getAllPossibleTargetIDFeatures(const llvm::Triple &T, llvm::StringRef Processor)
Get all feature strings that can be used in target ID for Processor.
LangAS
Defines the address space values used by the address space qualifier of QualType.
std::string getCanonicalTargetID(llvm::StringRef Processor, const llvm::StringMap< bool > &Features)
Returns canonical target ID, assuming Processor is canonical and all entries in Features are valid.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
LangAS getLangASFromTargetAS(unsigned TargetAS)
unsigned[(unsigned) LangAS::FirstTargetAddressSpace] LangASMap
The type of a lookup table which maps from language-specific address spaces to target-specific ones.
void setRequiresImmediate(int Min, int Max)