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 class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo
: public TargetInfo
{
32 bool HasNontrappingFPToInt
= false;
33 bool HasSignExt
= false;
34 bool HasExceptionHandling
= false;
35 bool HasBulkMemory
= false;
36 bool HasAtomics
= false;
37 bool HasMutableGlobals
= false;
38 bool HasMultivalue
= false;
39 bool HasTailCall
= false;
40 bool HasReferenceTypes
= false;
41 bool HasExtendedConst
= false;
46 explicit WebAssemblyTargetInfo(const llvm::Triple
&T
, const TargetOptions
&)
50 LargeArrayMinWidth
= 128;
51 LargeArrayAlign
= 128;
52 SigAtomicType
= SignedLong
;
53 LongDoubleWidth
= LongDoubleAlign
= 128;
54 LongDoubleFormat
= &llvm::APFloat::IEEEquad();
55 MaxAtomicPromoteWidth
= MaxAtomicInlineWidth
= 64;
56 // size_t being unsigned long for both wasm32 and wasm64 makes mangled names
57 // more consistent between the two.
58 SizeType
= UnsignedLong
;
59 PtrDiffType
= SignedLong
;
60 IntPtrType
= SignedLong
;
63 StringRef
getABI() const override
;
64 bool setABI(const std::string
&Name
) override
;
67 void getTargetDefines(const LangOptions
&Opts
,
68 MacroBuilder
&Builder
) const override
;
71 static void setSIMDLevel(llvm::StringMap
<bool> &Features
, SIMDEnum Level
,
75 initFeatureMap(llvm::StringMap
<bool> &Features
, DiagnosticsEngine
&Diags
,
77 const std::vector
<std::string
> &FeaturesVec
) const override
;
78 bool hasFeature(StringRef Feature
) const final
;
80 void setFeatureEnabled(llvm::StringMap
<bool> &Features
, StringRef Name
,
81 bool Enabled
) const final
;
83 bool handleTargetFeatures(std::vector
<std::string
> &Features
,
84 DiagnosticsEngine
&Diags
) final
;
86 bool isValidCPUName(StringRef Name
) const final
;
87 void fillValidCPUList(SmallVectorImpl
<StringRef
> &Values
) const final
;
89 bool setCPU(const std::string
&Name
) final
{ return isValidCPUName(Name
); }
91 ArrayRef
<Builtin::Info
> getTargetBuiltins() const final
;
93 BuiltinVaListKind
getBuiltinVaListKind() const final
{
94 return VoidPtrBuiltinVaList
;
97 ArrayRef
<const char *> getGCCRegNames() const final
{ return std::nullopt
; }
99 ArrayRef
<TargetInfo::GCCRegAlias
> getGCCRegAliases() const final
{
103 bool validateAsmConstraint(const char *&Name
,
104 TargetInfo::ConstraintInfo
&Info
) const final
{
108 const char *getClobbers() const final
{ return ""; }
110 bool isCLZForZeroUndef() const final
{ return false; }
112 bool hasInt128Type() const final
{ return true; }
114 IntType
getIntTypeByWidth(unsigned BitWidth
, bool IsSigned
) const final
{
115 // WebAssembly prefers long long for explicitly 64-bit integers.
116 return BitWidth
== 64 ? (IsSigned
? SignedLongLong
: UnsignedLongLong
)
117 : TargetInfo::getIntTypeByWidth(BitWidth
, IsSigned
);
120 IntType
getLeastIntTypeByWidth(unsigned BitWidth
, bool IsSigned
) const final
{
121 // WebAssembly uses long long for int_least64_t and int_fast64_t.
122 return BitWidth
== 64
123 ? (IsSigned
? SignedLongLong
: UnsignedLongLong
)
124 : TargetInfo::getLeastIntTypeByWidth(BitWidth
, IsSigned
);
127 CallingConvCheckResult
checkCallingConvention(CallingConv CC
) const override
{
139 bool hasBitIntType() const override
{ return true; }
141 bool hasProtectedVisibility() const override
{ return false; }
143 void adjust(DiagnosticsEngine
&Diags
, LangOptions
&Opts
) override
;
146 class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo
147 : public WebAssemblyTargetInfo
{
149 explicit WebAssembly32TargetInfo(const llvm::Triple
&T
,
150 const TargetOptions
&Opts
)
151 : WebAssemblyTargetInfo(T
, Opts
) {
152 if (T
.isOSEmscripten())
153 resetDataLayout("e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-"
157 "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20");
161 void getTargetDefines(const LangOptions
&Opts
,
162 MacroBuilder
&Builder
) const override
;
165 class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo
166 : public WebAssemblyTargetInfo
{
168 explicit WebAssembly64TargetInfo(const llvm::Triple
&T
,
169 const TargetOptions
&Opts
)
170 : WebAssemblyTargetInfo(T
, Opts
) {
171 LongAlign
= LongWidth
= 64;
172 PointerAlign
= PointerWidth
= 64;
173 SizeType
= UnsignedLong
;
174 PtrDiffType
= SignedLong
;
175 IntPtrType
= SignedLong
;
176 if (T
.isOSEmscripten())
177 resetDataLayout("e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-"
181 "e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20");
185 void getTargetDefines(const LangOptions
&Opts
,
186 MacroBuilder
&Builder
) const override
;
188 } // namespace targets
190 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_WEBASSEMBLY_H