1 //=== WebAssembly.h - Declare WebAssembly target feature support *- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file declares WebAssembly TargetInfo objects.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_WEBASSEMBLY_H
14 #define LLVM_CLANG_LIB_BASIC_TARGETS_WEBASSEMBLY_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"
24 static const unsigned WebAssemblyAddrSpaceMap
[] = {
31 0, // opencl_global_device
32 0, // opencl_global_host
37 0, // sycl_global_device
38 0, // sycl_global_host
44 0, // hlsl_groupshared
48 class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo
: public TargetInfo
{
56 bool HasNontrappingFPToInt
= false;
57 bool HasSignExt
= false;
58 bool HasExceptionHandling
= false;
59 bool HasBulkMemory
= false;
60 bool HasAtomics
= false;
61 bool HasMutableGlobals
= false;
62 bool HasMultivalue
= false;
63 bool HasTailCall
= false;
64 bool HasReferenceTypes
= false;
65 bool HasExtendedConst
= false;
66 bool HasMultiMemory
= false;
71 explicit WebAssemblyTargetInfo(const llvm::Triple
&T
, const TargetOptions
&)
73 AddrSpaceMap
= &WebAssemblyAddrSpaceMap
;
76 LargeArrayMinWidth
= 128;
77 LargeArrayAlign
= 128;
78 SigAtomicType
= SignedLong
;
79 LongDoubleWidth
= LongDoubleAlign
= 128;
80 LongDoubleFormat
= &llvm::APFloat::IEEEquad();
81 MaxAtomicPromoteWidth
= MaxAtomicInlineWidth
= 64;
82 // size_t being unsigned long for both wasm32 and wasm64 makes mangled names
83 // more consistent between the two.
84 SizeType
= UnsignedLong
;
85 PtrDiffType
= SignedLong
;
86 IntPtrType
= SignedLong
;
89 StringRef
getABI() const override
;
90 bool setABI(const std::string
&Name
) override
;
93 void getTargetDefines(const LangOptions
&Opts
,
94 MacroBuilder
&Builder
) const override
;
97 static void setSIMDLevel(llvm::StringMap
<bool> &Features
, SIMDEnum Level
,
101 initFeatureMap(llvm::StringMap
<bool> &Features
, DiagnosticsEngine
&Diags
,
103 const std::vector
<std::string
> &FeaturesVec
) const override
;
104 bool hasFeature(StringRef Feature
) const final
;
106 void setFeatureEnabled(llvm::StringMap
<bool> &Features
, StringRef Name
,
107 bool Enabled
) const final
;
109 bool handleTargetFeatures(std::vector
<std::string
> &Features
,
110 DiagnosticsEngine
&Diags
) final
;
112 bool isValidCPUName(StringRef Name
) const final
;
113 void fillValidCPUList(SmallVectorImpl
<StringRef
> &Values
) const final
;
115 bool setCPU(const std::string
&Name
) final
{ return isValidCPUName(Name
); }
117 ArrayRef
<Builtin::Info
> getTargetBuiltins() const final
;
119 BuiltinVaListKind
getBuiltinVaListKind() const final
{
120 return VoidPtrBuiltinVaList
;
123 ArrayRef
<const char *> getGCCRegNames() const final
{ return std::nullopt
; }
125 ArrayRef
<TargetInfo::GCCRegAlias
> getGCCRegAliases() const final
{
129 bool validateAsmConstraint(const char *&Name
,
130 TargetInfo::ConstraintInfo
&Info
) const final
{
134 std::string_view
getClobbers() const final
{ return ""; }
136 bool isCLZForZeroUndef() const final
{ return false; }
138 bool hasInt128Type() const final
{ return true; }
140 IntType
getIntTypeByWidth(unsigned BitWidth
, bool IsSigned
) const final
{
141 // WebAssembly prefers long long for explicitly 64-bit integers.
142 return BitWidth
== 64 ? (IsSigned
? SignedLongLong
: UnsignedLongLong
)
143 : TargetInfo::getIntTypeByWidth(BitWidth
, IsSigned
);
146 IntType
getLeastIntTypeByWidth(unsigned BitWidth
, bool IsSigned
) const final
{
147 // WebAssembly uses long long for int_least64_t and int_fast64_t.
148 return BitWidth
== 64
149 ? (IsSigned
? SignedLongLong
: UnsignedLongLong
)
150 : TargetInfo::getLeastIntTypeByWidth(BitWidth
, IsSigned
);
153 CallingConvCheckResult
checkCallingConvention(CallingConv CC
) const override
{
165 bool hasBitIntType() const override
{ return true; }
167 bool hasProtectedVisibility() const override
{ return false; }
169 void adjust(DiagnosticsEngine
&Diags
, LangOptions
&Opts
) override
;
172 class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo
173 : public WebAssemblyTargetInfo
{
175 explicit WebAssembly32TargetInfo(const llvm::Triple
&T
,
176 const TargetOptions
&Opts
)
177 : WebAssemblyTargetInfo(T
, Opts
) {
178 if (T
.isOSEmscripten())
179 resetDataLayout("e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-"
183 "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20");
187 void getTargetDefines(const LangOptions
&Opts
,
188 MacroBuilder
&Builder
) const override
;
191 class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo
192 : public WebAssemblyTargetInfo
{
194 explicit WebAssembly64TargetInfo(const llvm::Triple
&T
,
195 const TargetOptions
&Opts
)
196 : WebAssemblyTargetInfo(T
, Opts
) {
197 LongAlign
= LongWidth
= 64;
198 PointerAlign
= PointerWidth
= 64;
199 SizeType
= UnsignedLong
;
200 PtrDiffType
= SignedLong
;
201 IntPtrType
= SignedLong
;
202 if (T
.isOSEmscripten())
203 resetDataLayout("e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-"
207 "e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20");
211 void getTargetDefines(const LangOptions
&Opts
,
212 MacroBuilder
&Builder
) const override
;
214 } // namespace targets
216 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_WEBASSEMBLY_H