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