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/AMDGPUTargetParser.h"
23#include "llvm/TargetParser/Triple.h"
31 static const char *
const GCCRegNames[];
33 static const LangASMap AMDGPUAddrSpaceMap;
35 llvm::AMDGPU::GPUKind GPUKind;
36 unsigned WavefrontSize;
42 bool HasImage =
false;
49 llvm::StringMap<bool> OffloadArchFeatures;
53 bool hasFastFMAF()
const {
54 return llvm::AMDGPU::getFeatureBitset(GPUKind).test(
55 llvm::AMDGPU::FEAT_FAST_FMAF);
58 bool hasFlatSupport()
const {
59 if (GPUKind >= llvm::AMDGPU::GK_GFX700)
63 if (GPUKind == llvm::AMDGPU::GK_NONE &&
64 getTriple().getOS() == llvm::Triple::AMDHSA)
79 if (TargetAS == llvm::AMDGPUAS::PRIVATE_ADDRESS ||
80 TargetAS == llvm::AMDGPUAS::LOCAL_ADDRESS)
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",
150 if (S ==
"DA" || S ==
"DB") {
163 bool HasLeftParen = S.consume_front(
"{");
166 if (S.front() !=
'v' && S.front() !=
's' && S.front() !=
'a') {
169 auto E = S.find(
'}');
170 if (!SpecialRegs.count(S.substr(0, E)))
172 S = S.drop_front(E + 1);
189 bool HasLeftBracket = S.consume_front(
"[");
190 unsigned long long N;
191 if (S.empty() || consumeUnsignedInteger(S, 10, N))
193 if (S.consume_front(
":")) {
196 unsigned long long M;
197 if (consumeUnsignedInteger(S, 10, M) || N >= M)
200 if (HasLeftBracket) {
201 if (!S.consume_front(
"]"))
204 if (!S.consume_front(
"}"))
220 StringRef S(Constraint);
221 if (S ==
"DA" || S ==
"DB" || S ==
"RF") {
222 return std::string(
"^") + std::string(Constraint++, 2);
225 const char *Begin = Constraint;
228 return std::string(Begin).substr(0, Constraint - Begin + 1);
231 return std::string(1, *Constraint);
237 const std::vector<std::string> &FeatureVec)
const override;
249 return llvm::AMDGPU::isCPUValidForSubArch(
getTriple().getSubArch(), Name) &&
250 !llvm::AMDGPU::isPseudoTarget(Name);
256 GPUKind = llvm::AMDGPU::parseArchAMDGCN(Name);
257 return llvm::AMDGPU::isCPUValidForSubArch(
getTriple().getSubArch(),
259 !llvm::AMDGPU::isPseudoTarget(GPUKind);
264 Opts[
"cl_clang_storage_class_specifiers"] =
true;
265 Opts[
"__cl_clang_variadic_functions"] =
true;
266 Opts[
"__cl_clang_function_pointers"] =
true;
267 Opts[
"__cl_clang_function_scope_local_variables"] =
true;
268 Opts[
"__cl_clang_non_portable_kernel_param_types"] =
true;
269 Opts[
"__cl_clang_bitfields"] =
true;
271 Opts[
"cl_khr_fp64"] =
true;
272 Opts[
"__opencl_c_fp64"] =
true;
274 Opts[
"cl_khr_byte_addressable_store"] =
true;
275 Opts[
"cl_khr_global_int32_base_atomics"] =
true;
276 Opts[
"cl_khr_global_int32_extended_atomics"] =
true;
277 Opts[
"cl_khr_local_int32_base_atomics"] =
true;
278 Opts[
"cl_khr_local_int32_extended_atomics"] =
true;
280 Opts[
"cl_khr_fp16"] =
true;
281 Opts[
"cl_khr_int64_base_atomics"] =
true;
282 Opts[
"cl_khr_int64_extended_atomics"] =
true;
283 Opts[
"cl_khr_mipmap_image"] =
true;
284 Opts[
"cl_khr_mipmap_image_writes"] =
true;
285 Opts[
"cl_khr_subgroups"] =
true;
286 Opts[
"cl_amd_media_ops"] =
true;
287 Opts[
"cl_amd_media_ops2"] =
true;
290 Opts[
"__opencl_c_images"] =
true;
291 Opts[
"__opencl_c_3d_image_writes"] =
true;
292 Opts[
"__opencl_c_read_write_images"] =
true;
293 Opts[
"cl_khr_3d_image_writes"] =
true;
294 Opts[
"__opencl_c_program_scope_global_variables"] =
true;
295 Opts[
"__opencl_c_atomic_order_acq_rel"] =
true;
296 Opts[
"__opencl_c_atomic_order_seq_cst"] =
true;
297 Opts[
"__opencl_c_atomic_scope_device"] =
true;
298 Opts[
"__opencl_c_atomic_scope_all_devices"] =
true;
299 Opts[
"__opencl_c_work_group_collective_functions"] =
true;
301 if (hasFlatSupport()) {
302 Opts[
"__opencl_c_generic_address_space"] =
true;
303 Opts[
"__opencl_c_device_enqueue"] =
true;
304 Opts[
"__opencl_c_pipes"] =
true;
307 if (
getTriple().getEnvironment() == llvm::Triple::LLVM) {
308 Opts[
"cl_khr_subgroup_extended_types"] =
true;
364 switch (WavefrontSize) {
366 return llvm::omp::getAMDGPUGridValues<32>();
368 return llvm::omp::getAMDGPUGridValues<64>();
370 llvm_unreachable(
"getGridValue not implemented for this wavesize");
376 return static_cast<unsigned>(llvm::AMDGPUAS::CONSTANT_ADDRESS);
385 std::optional<unsigned>
387 int DWARFAS = llvm::AMDGPU::mapToDWARFAddrSpace(AddressSpace);
390 if (DWARFAS == -1 || DWARFAS == llvm::AMDGPU::DWARFAS::DEFAULT)
418 void setAuxTarget(
const TargetInfo *Aux)
override;
427 auto TargetIDFeatures =
429 for (
const auto &F : Features) {
430 assert(F.front() ==
'+' || F.front() ==
'-');
431 if (F ==
"+wavefrontsize64")
433 else if (F ==
"+cumode")
435 else if (F ==
"-cumode")
437 else if (F ==
"+image-insts")
439 bool IsOn = F.front() ==
'+';
440 StringRef Name = StringRef(F).drop_front();
441 if (!llvm::is_contained(TargetIDFeatures, Name))
443 assert(!OffloadArchFeatures.contains(Name));
444 OffloadArchFeatures[Name] = IsOn;
450 return llvm::AMDGPU::parseArchAMDGCN(Name) == GPUKind;
460 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.
The type of a lookup table which maps from language-specific address spaces to target-specific ones.
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 isProcessorName(StringRef Name) const override
Returns true if the target's processor is compatible with the processor named by Name,...
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
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 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< 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.
bool setCPU(StringRef Name) override
Target the specified CPU.
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.
Top level wrappers for InstallAPI frontend operations.
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.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
LangAS getLangASFromTargetAS(unsigned TargetAS)
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t uint64_t __builtin_riscv_ssha_i32 __builtin_riscv_sshl_u32 uint64_t
void setRequiresImmediate(int Min, int Max)