clang 24.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 0, // hlsl_output
50 0, // hlsl_push_constant
51 20, // wasm_funcref
52};
53
54class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {
55
56 enum SIMDEnum {
57 NoSIMD,
58 SIMD128,
59 RelaxedSIMD,
60 } SIMDLevel = NoSIMD;
61
62 bool HasAtomics = false;
63 bool HasBulkMemory = false;
64 bool HasBulkMemoryOpt = false;
65 bool HasCallIndirectOverlong = false;
66 bool HasCooperativeThreading = false;
67 bool HasCompactImports = false;
68 bool HasExceptionHandling = false;
69 bool HasExtendedConst = false;
70 bool HasFP16 = false;
71 bool HasGC = false;
72 bool HasLibcallThreadContext = false;
73 bool HasMultiMemory = false;
74 bool HasMultivalue = false;
75 bool HasMutableGlobals = false;
76 bool HasNontrappingFPToInt = false;
77 bool HasReferenceTypes = false;
78 bool HasRelaxedAtomics = false;
79 bool HasSignExt = false;
80 bool HasTailCall = false;
81 bool HasWideArithmetic = false;
82
83 std::string ABI;
84
85public:
86 explicit WebAssemblyTargetInfo(const llvm::Triple &T, const TargetOptions &)
87 : TargetInfo(T) {
90 NoAsmVariants = true;
91 SuitableAlign = 128;
93 LargeArrayAlign = 128;
96 LongDoubleFormat = &llvm::APFloat::IEEEquad();
98 HasUnalignedAccess = true;
99 if (T.isWALI()) {
100 // The WALI ABI is documented here:
101 // https://doc.rust-lang.org/rustc/platform-support/wasm32-wali-linux.html
102 // Currently, this ABI only applies to wasm32 targets and notably requires
103 // 64-bit longs
104 LongAlign = LongWidth = 64;
108 } else {
109 // size_t being unsigned long for both wasm32 and wasm64 makes mangled
110 // names more consistent between the two.
114 }
115 if (T.getOS() == llvm::Triple::WASIp3) {
116 HasLibcallThreadContext = true;
117 HasCooperativeThreading = true;
118 }
119 }
120
121 StringRef getABI() const override;
122 bool setABI(const std::string &Name) override;
123
124protected:
125 void getTargetDefines(const LangOptions &Opts,
126 MacroBuilder &Builder) const override;
127
128private:
129 static void setSIMDLevel(llvm::StringMap<bool> &Features, SIMDEnum Level,
130 bool Enabled);
131
132 bool
133 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
134 StringRef CPU,
135 const std::vector<std::string> &FeaturesVec) const override;
136 bool hasFeature(StringRef Feature) const final;
137
138 void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name,
139 bool Enabled) const final;
140
141 bool handleTargetFeatures(std::vector<std::string> &Features,
142 DiagnosticsEngine &Diags) final;
143
144 bool isValidCPUName(StringRef Name) const final;
145 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const final;
146
147 bool setCPU(StringRef Name) final { return isValidCPUName(Name); }
148
149 llvm::SmallVector<Builtin::InfosShard> getTargetBuiltins() const final;
150
151 BuiltinVaListKind getBuiltinVaListKind() const final {
152 return VoidPtrBuiltinVaList;
153 }
154
155 ArrayRef<const char *> getGCCRegNames() const final { return {}; }
156
157 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const final {
158 return {};
159 }
160
161 bool validateAsmConstraint(const char *&Name,
162 TargetInfo::ConstraintInfo &Info) const final {
163 return false;
164 }
165
166 std::string_view getClobbers() const final { return ""; }
167
168 bool isCLZForZeroUndef() const final { return false; }
169
170 bool hasInt128Type() const final { return true; }
171
172 IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
173 // WebAssembly prefers long long for explicitly 64-bit integers.
174 return BitWidth == 64 ? (IsSigned ? SignedLongLong : UnsignedLongLong)
175 : TargetInfo::getIntTypeByWidth(BitWidth, IsSigned);
176 }
177
178 IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
179 // WebAssembly uses long long for int_least64_t and int_fast64_t.
180 return BitWidth == 64
181 ? (IsSigned ? SignedLongLong : UnsignedLongLong)
182 : TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned);
183 }
184
185 CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
186 switch (CC) {
187 case CC_C:
188 case CC_Swift:
189 return CCCR_OK;
190 case CC_SwiftAsync:
191 return HasTailCall ? CCCR_OK : CCCR_Error;
192 default:
193 return CCCR_Warning;
194 }
195 }
196
197 bool hasBitIntType() const override { return true; }
198
199 bool hasProtectedVisibility() const override { return false; }
200
201 void adjust(DiagnosticsEngine &Diags, LangOptions &Opts,
202 const TargetInfo *Aux) override;
203};
204
205class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo
206 : public WebAssemblyTargetInfo {
207public:
208 explicit WebAssembly32TargetInfo(const llvm::Triple &T,
209 const TargetOptions &Opts)
210 : WebAssemblyTargetInfo(T, Opts) {
212 }
213
214protected:
215 void getTargetDefines(const LangOptions &Opts,
216 MacroBuilder &Builder) const override;
217};
218
219class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo
220 : public WebAssemblyTargetInfo {
221public:
222 explicit WebAssembly64TargetInfo(const llvm::Triple &T,
223 const TargetOptions &Opts)
224 : WebAssemblyTargetInfo(T, Opts) {
225 LongAlign = LongWidth = 64;
231 }
232
233protected:
234 void getTargetDefines(const LangOptions &Opts,
235 MacroBuilder &Builder) const override;
236};
237} // namespace targets
238} // namespace clang
239#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:234
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:260
unsigned HasUnalignedAccess
Definition TargetInfo.h:288
unsigned char MaxAtomicPromoteWidth
Definition TargetInfo.h:253
void resetDataLayout(StringRef DL)
Set the data layout to the given string.
bool UseAddrSpaceMapMangling
Specify if mangling based on address space map should be used or not for language specific address sp...
Definition TargetInfo.h:389
unsigned char MaxAtomicInlineWidth
Definition TargetInfo.h:253
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:86
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.
@ CC_Swift
Definition Specifiers.h:294
@ CC_SwiftAsync
Definition Specifiers.h:295
const llvm::fltSemantics * LongDoubleFormat
Definition TargetInfo.h:144