clang 23.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 HasCompactImports = false;
67 bool HasExceptionHandling = false;
68 bool HasExtendedConst = false;
69 bool HasFP16 = false;
70 bool HasGC = false;
71 bool HasLibcallThreadContext = false;
72 bool HasMultiMemory = false;
73 bool HasMultivalue = false;
74 bool HasMutableGlobals = false;
75 bool HasNontrappingFPToInt = false;
76 bool HasReferenceTypes = false;
77 bool HasRelaxedAtomics = false;
78 bool HasSignExt = false;
79 bool HasTailCall = false;
80 bool HasWideArithmetic = false;
81
82 std::string ABI;
83
84public:
85 explicit WebAssemblyTargetInfo(const llvm::Triple &T, const TargetOptions &)
86 : TargetInfo(T) {
89 NoAsmVariants = true;
90 SuitableAlign = 128;
92 LargeArrayAlign = 128;
95 LongDoubleFormat = &llvm::APFloat::IEEEquad();
97 HasUnalignedAccess = true;
98 if (T.isWALI()) {
99 // The WALI ABI is documented here:
100 // https://doc.rust-lang.org/rustc/platform-support/wasm32-wali-linux.html
101 // Currently, this ABI only applies to wasm32 targets and notably requires
102 // 64-bit longs
103 LongAlign = LongWidth = 64;
107 } else {
108 // size_t being unsigned long for both wasm32 and wasm64 makes mangled
109 // names more consistent between the two.
113 }
114 if (T.getOS() == llvm::Triple::WASIp3)
115 HasLibcallThreadContext = true;
116 }
117
118 StringRef getABI() const override;
119 bool setABI(const std::string &Name) override;
120 bool useFP16ConversionIntrinsics() const override { return !HasFP16; }
121
122protected:
123 void getTargetDefines(const LangOptions &Opts,
124 MacroBuilder &Builder) const override;
125
126private:
127 static void setSIMDLevel(llvm::StringMap<bool> &Features, SIMDEnum Level,
128 bool Enabled);
129
130 bool
131 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
132 StringRef CPU,
133 const std::vector<std::string> &FeaturesVec) const override;
134 bool hasFeature(StringRef Feature) const final;
135
136 void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name,
137 bool Enabled) const final;
138
139 bool handleTargetFeatures(std::vector<std::string> &Features,
140 DiagnosticsEngine &Diags) final;
141
142 bool isValidCPUName(StringRef Name) const final;
143 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const final;
144
145 bool setCPU(const std::string &Name) final { return isValidCPUName(Name); }
146
147 llvm::SmallVector<Builtin::InfosShard> getTargetBuiltins() const final;
148
149 BuiltinVaListKind getBuiltinVaListKind() const final {
150 return VoidPtrBuiltinVaList;
151 }
152
153 ArrayRef<const char *> getGCCRegNames() const final { return {}; }
154
155 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const final {
156 return {};
157 }
158
159 bool validateAsmConstraint(const char *&Name,
160 TargetInfo::ConstraintInfo &Info) const final {
161 return false;
162 }
163
164 std::string_view getClobbers() const final { return ""; }
165
166 bool isCLZForZeroUndef() const final { return false; }
167
168 bool hasInt128Type() const final { return true; }
169
170 IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
171 // WebAssembly prefers long long for explicitly 64-bit integers.
172 return BitWidth == 64 ? (IsSigned ? SignedLongLong : UnsignedLongLong)
173 : TargetInfo::getIntTypeByWidth(BitWidth, IsSigned);
174 }
175
176 IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
177 // WebAssembly uses long long for int_least64_t and int_fast64_t.
178 return BitWidth == 64
179 ? (IsSigned ? SignedLongLong : UnsignedLongLong)
180 : TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned);
181 }
182
183 CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
184 switch (CC) {
185 case CC_C:
186 case CC_Swift:
187 return CCCR_OK;
188 case CC_SwiftAsync:
189 return CCCR_Error;
190 default:
191 return CCCR_Warning;
192 }
193 }
194
195 bool hasBitIntType() const override { return true; }
196
197 bool hasProtectedVisibility() const override { return false; }
198
199 void adjust(DiagnosticsEngine &Diags, LangOptions &Opts,
200 const TargetInfo *Aux) override;
201};
202
203class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo
204 : public WebAssemblyTargetInfo {
205public:
206 explicit WebAssembly32TargetInfo(const llvm::Triple &T,
207 const TargetOptions &Opts)
208 : WebAssemblyTargetInfo(T, Opts) {
210 }
211
212protected:
213 void getTargetDefines(const LangOptions &Opts,
214 MacroBuilder &Builder) const override;
215};
216
217class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo
218 : public WebAssemblyTargetInfo {
219public:
220 explicit WebAssembly64TargetInfo(const llvm::Triple &T,
221 const TargetOptions &Opts)
222 : WebAssemblyTargetInfo(T, Opts) {
223 LongAlign = LongWidth = 64;
229 }
230
231protected:
232 void getTargetDefines(const LangOptions &Opts,
233 MacroBuilder &Builder) const override;
234};
235} // namespace targets
236} // namespace clang
237#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:233
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:285
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:386
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:85
bool useFP16ConversionIntrinsics() const override
Check whether conversions to and from __fp16 should go through an integer bitcast with i16.
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:297
@ CC_SwiftAsync
Definition Specifiers.h:298
const llvm::fltSemantics * LongDoubleFormat
Definition TargetInfo.h:144