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/ADT/Triple.h"
19 #include "llvm/Support/Compiler.h"
24 class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {
25 static const Builtin::Info BuiltinInfo[];
33 bool HasNontrappingFPToInt = false;
34 bool HasSignExt = false;
35 bool HasExceptionHandling = false;
36 bool HasBulkMemory = false;
37 bool HasAtomics = false;
38 bool HasMutableGlobals = false;
39 bool HasMultivalue = false;
40 bool HasTailCall = false;
41 bool HasReferenceTypes = false;
46 explicit WebAssemblyTargetInfo(const llvm::Triple &T, const TargetOptions &)
50 LargeArrayMinWidth = 128;
51 LargeArrayAlign = 128;
52 SimdDefaultAlign = 128;
53 SigAtomicType = SignedLong;
54 LongDoubleWidth = LongDoubleAlign = 128;
55 LongDoubleFormat = &llvm::APFloat::IEEEquad();
56 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
57 // size_t being unsigned long for both wasm32 and wasm64 makes mangled names
58 // more consistent between the two.
59 SizeType = UnsignedLong;
60 PtrDiffType = SignedLong;
61 IntPtrType = SignedLong;
64 StringRef getABI() const override;
65 bool setABI(const std::string &Name) override;
68 void getTargetDefines(const LangOptions &Opts,
69 MacroBuilder &Builder) const override;
72 static void setSIMDLevel(llvm::StringMap<bool> &Features, SIMDEnum Level,
76 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
78 const std::vector<std::string> &FeaturesVec) const override;
79 bool hasFeature(StringRef Feature) const final;
81 void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name,
82 bool Enabled) const final;
84 bool handleTargetFeatures(std::vector<std::string> &Features,
85 DiagnosticsEngine &Diags) final;
87 bool isValidCPUName(StringRef Name) const final;
88 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const final;
90 bool setCPU(const std::string &Name) final { return isValidCPUName(Name); }
92 ArrayRef<Builtin::Info> getTargetBuiltins() const final;
94 BuiltinVaListKind getBuiltinVaListKind() const final {
95 return VoidPtrBuiltinVaList;
98 ArrayRef<const char *> getGCCRegNames() const final { return None; }
100 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const final {
104 bool validateAsmConstraint(const char *&Name,
105 TargetInfo::ConstraintInfo &Info) const final {
109 const char *getClobbers() const final { return ""; }
111 bool isCLZForZeroUndef() const final { return false; }
113 bool hasInt128Type() const final { return true; }
115 IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
116 // WebAssembly prefers long long for explicitly 64-bit integers.
117 return BitWidth == 64 ? (IsSigned ? SignedLongLong : UnsignedLongLong)
118 : TargetInfo::getIntTypeByWidth(BitWidth, IsSigned);
121 IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
122 // WebAssembly uses long long for int_least64_t and int_fast64_t.
123 return BitWidth == 64
124 ? (IsSigned ? SignedLongLong : UnsignedLongLong)
125 : TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned);
128 CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
138 bool hasExtIntType() const override { return true; }
140 bool hasProtectedVisibility() const override { return false; }
143 class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo
144 : public WebAssemblyTargetInfo {
146 explicit WebAssembly32TargetInfo(const llvm::Triple &T,
147 const TargetOptions &Opts)
148 : WebAssemblyTargetInfo(T, Opts) {
149 resetDataLayout("e-m:e-p:32:32-i64:64-n32:64-S128");
153 void getTargetDefines(const LangOptions &Opts,
154 MacroBuilder &Builder) const override;
157 class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo
158 : public WebAssemblyTargetInfo {
160 explicit WebAssembly64TargetInfo(const llvm::Triple &T,
161 const TargetOptions &Opts)
162 : WebAssemblyTargetInfo(T, Opts) {
163 LongAlign = LongWidth = 64;
164 PointerAlign = PointerWidth = 64;
165 SizeType = UnsignedLong;
166 PtrDiffType = SignedLong;
167 IntPtrType = SignedLong;
168 resetDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128");
172 void getTargetDefines(const LangOptions &Opts,
173 MacroBuilder &Builder) const override;
175 } // namespace targets
177 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_WEBASSEMBLY_H