clang 22.0.0git
WebAssembly.h
Go to the documentation of this file.
1//=== WebAssembly.h - Declare WebAssembly target feature support *- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file declares WebAssembly TargetInfo objects.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_WEBASSEMBLY_H
14#define LLVM_CLANG_LIB_BASIC_TARGETS_WEBASSEMBLY_H
15
18#include "llvm/Support/Compiler.h"
19#include "llvm/TargetParser/Triple.h"
20
21namespace clang {
22namespace targets {
23
24static const unsigned WebAssemblyAddrSpaceMap[] = {
25 0, // Default
26 0, // opencl_global
27 0, // opencl_local
28 0, // opencl_constant
29 0, // opencl_private
30 0, // opencl_generic
31 0, // opencl_global_device
32 0, // opencl_global_host
33 0, // cuda_device
34 0, // cuda_constant
35 0, // cuda_shared
36 0, // sycl_global
37 0, // sycl_global_device
38 0, // sycl_global_host
39 0, // sycl_local
40 0, // sycl_private
41 0, // ptr32_sptr
42 0, // ptr32_uptr
43 0, // ptr64
44 0, // hlsl_groupshared
45 0, // hlsl_constant
46 0, // hlsl_private
47 0, // hlsl_device
48 0, // hlsl_input
49 20, // wasm_funcref
50};
51
52class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {
53
54 enum SIMDEnum {
55 NoSIMD,
56 SIMD128,
57 RelaxedSIMD,
58 } SIMDLevel = NoSIMD;
59
60 bool HasAtomics = false;
61 bool HasBulkMemory = false;
62 bool HasBulkMemoryOpt = false;
63 bool HasCallIndirectOverlong = false;
64 bool HasExceptionHandling = false;
65 bool HasExtendedConst = false;
66 bool HasFP16 = false;
67 bool HasGC = false;
68 bool HasMultiMemory = false;
69 bool HasMultivalue = false;
70 bool HasMutableGlobals = false;
71 bool HasNontrappingFPToInt = false;
72 bool HasReferenceTypes = false;
73 bool HasSignExt = false;
74 bool HasTailCall = false;
75 bool HasWideArithmetic = false;
76
77 std::string ABI;
78
79public:
80 explicit WebAssemblyTargetInfo(const llvm::Triple &T, const TargetOptions &)
81 : TargetInfo(T) {
83 NoAsmVariants = true;
84 SuitableAlign = 128;
86 LargeArrayAlign = 128;
89 LongDoubleFormat = &llvm::APFloat::IEEEquad();
91 HasUnalignedAccess = true;
92 if (T.isWALI()) {
93 // The WALI ABI is documented here:
94 // https://doc.rust-lang.org/rustc/platform-support/wasm32-wali-linux.html
95 // Currently, this ABI only applies to wasm32 targets and notably requires
96 // 64-bit longs
97 LongAlign = LongWidth = 64;
101 } else {
102 // size_t being unsigned long for both wasm32 and wasm64 makes mangled
103 // names more consistent between the two.
107 }
108 }
109
110 StringRef getABI() const override;
111 bool setABI(const std::string &Name) override;
112 bool useFP16ConversionIntrinsics() const override { return !HasFP16; }
113
114protected:
115 void getTargetDefines(const LangOptions &Opts,
116 MacroBuilder &Builder) const override;
117
118private:
119 static void setSIMDLevel(llvm::StringMap<bool> &Features, SIMDEnum Level,
120 bool Enabled);
121
122 bool
123 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
124 StringRef CPU,
125 const std::vector<std::string> &FeaturesVec) const override;
126 bool hasFeature(StringRef Feature) const final;
127
128 void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name,
129 bool Enabled) const final;
130
131 bool handleTargetFeatures(std::vector<std::string> &Features,
132 DiagnosticsEngine &Diags) final;
133
134 bool isValidCPUName(StringRef Name) const final;
135 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const final;
136
137 bool setCPU(const std::string &Name) final { return isValidCPUName(Name); }
138
139 llvm::SmallVector<Builtin::InfosShard> getTargetBuiltins() const final;
140
141 BuiltinVaListKind getBuiltinVaListKind() const final {
142 return VoidPtrBuiltinVaList;
143 }
144
145 ArrayRef<const char *> getGCCRegNames() const final { return {}; }
146
147 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const final {
148 return {};
149 }
150
151 bool validateAsmConstraint(const char *&Name,
152 TargetInfo::ConstraintInfo &Info) const final {
153 return false;
154 }
155
156 std::string_view getClobbers() const final { return ""; }
157
158 bool isCLZForZeroUndef() const final { return false; }
159
160 bool hasInt128Type() const final { return true; }
161
162 IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
163 // WebAssembly prefers long long for explicitly 64-bit integers.
164 return BitWidth == 64 ? (IsSigned ? SignedLongLong : UnsignedLongLong)
165 : TargetInfo::getIntTypeByWidth(BitWidth, IsSigned);
166 }
167
168 IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
169 // WebAssembly uses long long for int_least64_t and int_fast64_t.
170 return BitWidth == 64
171 ? (IsSigned ? SignedLongLong : UnsignedLongLong)
172 : TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned);
173 }
174
175 CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
176 switch (CC) {
177 case CC_C:
178 case CC_Swift:
179 return CCCR_OK;
180 case CC_SwiftAsync:
181 return CCCR_Error;
182 default:
183 return CCCR_Warning;
184 }
185 }
186
187 bool hasBitIntType() const override { return true; }
188
189 bool hasProtectedVisibility() const override { return false; }
190
191 void adjust(DiagnosticsEngine &Diags, LangOptions &Opts,
192 const TargetInfo *Aux) override;
193};
194
195class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo
196 : public WebAssemblyTargetInfo {
197public:
198 explicit WebAssembly32TargetInfo(const llvm::Triple &T,
199 const TargetOptions &Opts)
200 : WebAssemblyTargetInfo(T, Opts) {
201 if (T.isOSEmscripten())
203 "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-i128:128-f128:64-n32:64-"
204 "S128-ni:1:10:20");
205 else
206 resetDataLayout("e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-i128:128-n32:64-"
207 "S128-ni:1:10:20");
208 }
209
210protected:
211 void getTargetDefines(const LangOptions &Opts,
212 MacroBuilder &Builder) const override;
213};
214
215class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo
216 : public WebAssemblyTargetInfo {
217public:
218 explicit WebAssembly64TargetInfo(const llvm::Triple &T,
219 const TargetOptions &Opts)
220 : WebAssemblyTargetInfo(T, Opts) {
221 LongAlign = LongWidth = 64;
226 if (T.isOSEmscripten())
228 "e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-i128:128-f128:64-n32:64-"
229 "S128-ni:1:10:20");
230 else
231 resetDataLayout("e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-i128:128-n32:64-"
232 "S128-ni:1:10:20");
233 }
234
235protected:
236 void getTargetDefines(const LangOptions &Opts,
237 MacroBuilder &Builder) const override;
238};
239} // namespace targets
240} // namespace clang
241#endif // LLVM_CLANG_LIB_BASIC_TARGETS_WEBASSEMBLY_H
static bool hasFeature(StringRef Feature, const LangOptions &LangOpts, const TargetInfo &Target)
Determine whether a translation unit built using the current language options has the given feature.
Definition Module.cpp:95
Defines the clang::TargetOptions class.
Concrete class used by the front-end to report problems and issues.
Definition Diagnostic.h:232
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
TargetInfo(const llvm::Triple &T)
const LangASMap * AddrSpaceMap
Definition TargetInfo.h:258
void resetDataLayout(StringRef DL, const char *UserLabelPrefix="")
unsigned HasUnalignedAccess
Definition TargetInfo.h:283
unsigned char MaxAtomicPromoteWidth
Definition TargetInfo.h:251
unsigned char MaxAtomicInlineWidth
Definition TargetInfo.h:251
Options for controlling the target.
WebAssembly32TargetInfo(const llvm::Triple &T, const TargetOptions &Opts)
WebAssembly64TargetInfo(const llvm::Triple &T, const TargetOptions &Opts)
WebAssemblyTargetInfo(const llvm::Triple &T, const TargetOptions &)
Definition WebAssembly.h:80
bool useFP16ConversionIntrinsics() const override
Check whether llvm intrinsics such as llvm.convert.to.fp16 should be used to convert to and from __fp...
Defines the clang::TargetInfo interface.
static const unsigned WebAssemblyAddrSpaceMap[]
Definition WebAssembly.h:24
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
@ CC_Swift
Definition Specifiers.h:293
@ CC_SwiftAsync
Definition Specifiers.h:294
const llvm::fltSemantics * LongDoubleFormat
Definition TargetInfo.h:143