Path: blob/main/contrib/llvm-project/clang/lib/Basic/Targets/NVPTX.h
35269 views
//===--- NVPTX.h - Declare NVPTX target feature support ---------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file declares NVPTX TargetInfo objects.9//10//===----------------------------------------------------------------------===//1112#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_NVPTX_H13#define LLVM_CLANG_LIB_BASIC_TARGETS_NVPTX_H1415#include "clang/Basic/Cuda.h"16#include "clang/Basic/TargetInfo.h"17#include "clang/Basic/TargetOptions.h"18#include "llvm/Support/Compiler.h"19#include "llvm/TargetParser/Triple.h"20#include <optional>2122namespace clang {23namespace targets {2425static const unsigned NVPTXAddrSpaceMap[] = {260, // Default271, // opencl_global283, // opencl_local294, // opencl_constant300, // opencl_private31// FIXME: generic has to be added to the target320, // opencl_generic331, // opencl_global_device341, // opencl_global_host351, // cuda_device364, // cuda_constant373, // cuda_shared381, // sycl_global391, // sycl_global_device401, // sycl_global_host413, // sycl_local420, // sycl_private430, // ptr32_sptr440, // ptr32_uptr450, // ptr64460, // hlsl_groupshared47// Wasm address space values for this target are dummy values,48// as it is only enabled for Wasm targets.4920, // wasm_funcref50};5152/// The DWARF address class. Taken from53/// https://docs.nvidia.com/cuda/archive/10.0/ptx-writers-guide-to-interoperability/index.html#cuda-specific-dwarf54static const int NVPTXDWARFAddrSpaceMap[] = {55-1, // Default, opencl_private or opencl_generic - not defined565, // opencl_global57-1,588, // opencl_local or cuda_shared594, // opencl_constant or cuda_constant60};6162class LLVM_LIBRARY_VISIBILITY NVPTXTargetInfo : public TargetInfo {63static const char *const GCCRegNames[];64OffloadArch GPU;65uint32_t PTXVersion;66std::unique_ptr<TargetInfo> HostTarget;6768public:69NVPTXTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts,70unsigned TargetPointerWidth);7172void getTargetDefines(const LangOptions &Opts,73MacroBuilder &Builder) const override;7475ArrayRef<Builtin::Info> getTargetBuiltins() const override;7677bool useFP16ConversionIntrinsics() const override { return false; }7879bool80initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,81StringRef CPU,82const std::vector<std::string> &FeaturesVec) const override {83if (GPU != OffloadArch::UNUSED)84Features[OffloadArchToString(GPU)] = true;85Features["ptx" + std::to_string(PTXVersion)] = true;86return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);87}8889bool hasFeature(StringRef Feature) const override;9091ArrayRef<const char *> getGCCRegNames() const override;9293ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {94// No aliases.95return std::nullopt;96}9798bool validateAsmConstraint(const char *&Name,99TargetInfo::ConstraintInfo &Info) const override {100switch (*Name) {101default:102return false;103case 'c':104case 'h':105case 'r':106case 'l':107case 'f':108case 'd':109case 'q':110Info.setAllowsRegister();111return true;112}113}114115std::string_view getClobbers() const override {116// FIXME: Is this really right?117return "";118}119120BuiltinVaListKind getBuiltinVaListKind() const override {121return TargetInfo::VoidPtrBuiltinVaList;122}123124bool isValidCPUName(StringRef Name) const override {125return StringToOffloadArch(Name) != OffloadArch::UNKNOWN;126}127128void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override {129for (int i = static_cast<int>(OffloadArch::SM_20);130i < static_cast<int>(OffloadArch::Generic); ++i)131Values.emplace_back(OffloadArchToString(static_cast<OffloadArch>(i)));132}133134bool setCPU(const std::string &Name) override {135GPU = StringToOffloadArch(Name);136return GPU != OffloadArch::UNKNOWN;137}138139void setSupportedOpenCLOpts() override {140auto &Opts = getSupportedOpenCLOpts();141Opts["cl_clang_storage_class_specifiers"] = true;142Opts["__cl_clang_function_pointers"] = true;143Opts["__cl_clang_variadic_functions"] = true;144Opts["__cl_clang_non_portable_kernel_param_types"] = true;145Opts["__cl_clang_bitfields"] = true;146147Opts["cl_khr_fp64"] = true;148Opts["__opencl_c_fp64"] = true;149Opts["cl_khr_byte_addressable_store"] = true;150Opts["cl_khr_global_int32_base_atomics"] = true;151Opts["cl_khr_global_int32_extended_atomics"] = true;152Opts["cl_khr_local_int32_base_atomics"] = true;153Opts["cl_khr_local_int32_extended_atomics"] = true;154}155156const llvm::omp::GV &getGridValue() const override {157return llvm::omp::NVPTXGridValues;158}159160/// \returns If a target requires an address within a target specific address161/// space \p AddressSpace to be converted in order to be used, then return the162/// corresponding target specific DWARF address space.163///164/// \returns Otherwise return std::nullopt and no conversion will be emitted165/// in the DWARF.166std::optional<unsigned>167getDWARFAddressSpace(unsigned AddressSpace) const override {168if (AddressSpace >= std::size(NVPTXDWARFAddrSpaceMap) ||169NVPTXDWARFAddrSpaceMap[AddressSpace] < 0)170return std::nullopt;171return NVPTXDWARFAddrSpaceMap[AddressSpace];172}173174CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {175// CUDA compilations support all of the host's calling conventions.176//177// TODO: We should warn if you apply a non-default CC to anything other than178// a host function.179if (HostTarget)180return HostTarget->checkCallingConvention(CC);181return CCCR_Warning;182}183184bool hasBitIntType() const override { return true; }185bool hasBFloat16Type() const override { return true; }186187OffloadArch getGPU() const { return GPU; }188};189} // namespace targets190} // namespace clang191#endif // LLVM_CLANG_LIB_BASIC_TARGETS_NVPTX_H192193194