Path: blob/main/contrib/llvm-project/clang/lib/Basic/Targets/WebAssembly.h
213799 views
//=== WebAssembly.h - Declare WebAssembly 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 WebAssembly TargetInfo objects.9//10//===----------------------------------------------------------------------===//1112#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_WEBASSEMBLY_H13#define LLVM_CLANG_LIB_BASIC_TARGETS_WEBASSEMBLY_H1415#include "clang/Basic/TargetInfo.h"16#include "clang/Basic/TargetOptions.h"17#include "llvm/Support/Compiler.h"18#include "llvm/TargetParser/Triple.h"1920namespace clang {21namespace targets {2223static const unsigned WebAssemblyAddrSpaceMap[] = {240, // Default250, // opencl_global260, // opencl_local270, // opencl_constant280, // opencl_private290, // opencl_generic300, // opencl_global_device310, // opencl_global_host320, // cuda_device330, // cuda_constant340, // cuda_shared350, // sycl_global360, // sycl_global_device370, // sycl_global_host380, // sycl_local390, // sycl_private400, // ptr32_sptr410, // ptr32_uptr420, // ptr64430, // hlsl_groupshared440, // hlsl_constant450, // hlsl_private460, // hlsl_device470, // hlsl_input4820, // wasm_funcref49};5051class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {5253enum SIMDEnum {54NoSIMD,55SIMD128,56RelaxedSIMD,57} SIMDLevel = NoSIMD;5859bool HasAtomics = false;60bool HasBulkMemory = false;61bool HasBulkMemoryOpt = false;62bool HasCallIndirectOverlong = false;63bool HasExceptionHandling = false;64bool HasExtendedConst = false;65bool HasFP16 = false;66bool HasMultiMemory = false;67bool HasMultivalue = false;68bool HasMutableGlobals = false;69bool HasNontrappingFPToInt = false;70bool HasReferenceTypes = false;71bool HasSignExt = false;72bool HasTailCall = false;73bool HasWideArithmetic = false;7475std::string ABI;7677public:78explicit WebAssemblyTargetInfo(const llvm::Triple &T, const TargetOptions &)79: TargetInfo(T) {80AddrSpaceMap = &WebAssemblyAddrSpaceMap;81NoAsmVariants = true;82SuitableAlign = 128;83LargeArrayMinWidth = 128;84LargeArrayAlign = 128;85SigAtomicType = SignedLong;86LongDoubleWidth = LongDoubleAlign = 128;87LongDoubleFormat = &llvm::APFloat::IEEEquad();88MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;89// size_t being unsigned long for both wasm32 and wasm64 makes mangled names90// more consistent between the two.91SizeType = UnsignedLong;92PtrDiffType = SignedLong;93IntPtrType = SignedLong;94HasUnalignedAccess = true;95}9697StringRef getABI() const override;98bool setABI(const std::string &Name) override;99bool useFP16ConversionIntrinsics() const override { return !HasFP16; }100101protected:102void getTargetDefines(const LangOptions &Opts,103MacroBuilder &Builder) const override;104105private:106static void setSIMDLevel(llvm::StringMap<bool> &Features, SIMDEnum Level,107bool Enabled);108109bool110initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,111StringRef CPU,112const std::vector<std::string> &FeaturesVec) const override;113bool hasFeature(StringRef Feature) const final;114115void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name,116bool Enabled) const final;117118bool handleTargetFeatures(std::vector<std::string> &Features,119DiagnosticsEngine &Diags) final;120121bool isValidCPUName(StringRef Name) const final;122void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const final;123124bool setCPU(const std::string &Name) final { return isValidCPUName(Name); }125126llvm::SmallVector<Builtin::InfosShard> getTargetBuiltins() const final;127128BuiltinVaListKind getBuiltinVaListKind() const final {129return VoidPtrBuiltinVaList;130}131132ArrayRef<const char *> getGCCRegNames() const final { return {}; }133134ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const final {135return {};136}137138bool validateAsmConstraint(const char *&Name,139TargetInfo::ConstraintInfo &Info) const final {140return false;141}142143std::string_view getClobbers() const final { return ""; }144145bool isCLZForZeroUndef() const final { return false; }146147bool hasInt128Type() const final { return true; }148149IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {150// WebAssembly prefers long long for explicitly 64-bit integers.151return BitWidth == 64 ? (IsSigned ? SignedLongLong : UnsignedLongLong)152: TargetInfo::getIntTypeByWidth(BitWidth, IsSigned);153}154155IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {156// WebAssembly uses long long for int_least64_t and int_fast64_t.157return BitWidth == 64158? (IsSigned ? SignedLongLong : UnsignedLongLong)159: TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned);160}161162CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {163switch (CC) {164case CC_C:165case CC_Swift:166return CCCR_OK;167case CC_SwiftAsync:168return CCCR_Error;169default:170return CCCR_Warning;171}172}173174bool hasBitIntType() const override { return true; }175176bool hasProtectedVisibility() const override { return false; }177178void adjust(DiagnosticsEngine &Diags, LangOptions &Opts,179const TargetInfo *Aux) override;180};181182class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo183: public WebAssemblyTargetInfo {184public:185explicit WebAssembly32TargetInfo(const llvm::Triple &T,186const TargetOptions &Opts)187: WebAssemblyTargetInfo(T, Opts) {188if (T.isOSEmscripten())189resetDataLayout(190"e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-i128:128-f128:64-n32:64-"191"S128-ni:1:10:20");192else193resetDataLayout("e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-i128:128-n32:64-"194"S128-ni:1:10:20");195}196197protected:198void getTargetDefines(const LangOptions &Opts,199MacroBuilder &Builder) const override;200};201202class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo203: public WebAssemblyTargetInfo {204public:205explicit WebAssembly64TargetInfo(const llvm::Triple &T,206const TargetOptions &Opts)207: WebAssemblyTargetInfo(T, Opts) {208LongAlign = LongWidth = 64;209PointerAlign = PointerWidth = 64;210SizeType = UnsignedLong;211PtrDiffType = SignedLong;212IntPtrType = SignedLong;213if (T.isOSEmscripten())214resetDataLayout(215"e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-i128:128-f128:64-n32:64-"216"S128-ni:1:10:20");217else218resetDataLayout("e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-i128:128-n32:64-"219"S128-ni:1:10:20");220}221222protected:223void getTargetDefines(const LangOptions &Opts,224MacroBuilder &Builder) const override;225};226} // namespace targets227} // namespace clang228#endif // LLVM_CLANG_LIB_BASIC_TARGETS_WEBASSEMBLY_H229230231