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 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) {
84 NoAsmVariants = true;
85 SuitableAlign = 128;
87 LargeArrayAlign = 128;
90 LongDoubleFormat = &llvm::APFloat::IEEEquad();
92 HasUnalignedAccess = true;
93 if (T.isWALI()) {
94 // The WALI ABI is documented here:
95 // https://doc.rust-lang.org/rustc/platform-support/wasm32-wali-linux.html
96 // Currently, this ABI only applies to wasm32 targets and notably requires
97 // 64-bit longs
98 LongAlign = LongWidth = 64;
102 } else {
103 // size_t being unsigned long for both wasm32 and wasm64 makes mangled
104 // names more consistent between the two.
108 }
109 }
110
111 StringRef getABI() const override;
112 bool setABI(const std::string &Name) override;
113 bool useFP16ConversionIntrinsics() const override { return !HasFP16; }
114
115protected:
116 void getTargetDefines(const LangOptions &Opts,
117 MacroBuilder &Builder) const override;
118
119private:
120 static void setSIMDLevel(llvm::StringMap<bool> &Features, SIMDEnum Level,
121 bool Enabled);
122
123 bool
124 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
125 StringRef CPU,
126 const std::vector<std::string> &FeaturesVec) const override;
127 bool hasFeature(StringRef Feature) const final;
128
129 void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name,
130 bool Enabled) const final;
131
132 bool handleTargetFeatures(std::vector<std::string> &Features,
133 DiagnosticsEngine &Diags) final;
134
135 bool isValidCPUName(StringRef Name) const final;
136 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const final;
137
138 bool setCPU(const std::string &Name) final { return isValidCPUName(Name); }
139
140 llvm::SmallVector<Builtin::InfosShard> getTargetBuiltins() const final;
141
142 BuiltinVaListKind getBuiltinVaListKind() const final {
143 return VoidPtrBuiltinVaList;
144 }
145
146 ArrayRef<const char *> getGCCRegNames() const final { return {}; }
147
148 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const final {
149 return {};
150 }
151
152 bool validateAsmConstraint(const char *&Name,
153 TargetInfo::ConstraintInfo &Info) const final {
154 return false;
155 }
156
157 std::string_view getClobbers() const final { return ""; }
158
159 bool isCLZForZeroUndef() const final { return false; }
160
161 bool hasInt128Type() const final { return true; }
162
163 IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
164 // WebAssembly prefers long long for explicitly 64-bit integers.
165 return BitWidth == 64 ? (IsSigned ? SignedLongLong : UnsignedLongLong)
166 : TargetInfo::getIntTypeByWidth(BitWidth, IsSigned);
167 }
168
169 IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
170 // WebAssembly uses long long for int_least64_t and int_fast64_t.
171 return BitWidth == 64
172 ? (IsSigned ? SignedLongLong : UnsignedLongLong)
173 : TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned);
174 }
175
176 CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
177 switch (CC) {
178 case CC_C:
179 case CC_Swift:
180 return CCCR_OK;
181 case CC_SwiftAsync:
182 return CCCR_Error;
183 default:
184 return CCCR_Warning;
185 }
186 }
187
188 bool hasBitIntType() const override { return true; }
189
190 bool hasProtectedVisibility() const override { return false; }
191
192 void adjust(DiagnosticsEngine &Diags, LangOptions &Opts,
193 const TargetInfo *Aux) override;
194};
195
196class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo
197 : public WebAssemblyTargetInfo {
198public:
199 explicit WebAssembly32TargetInfo(const llvm::Triple &T,
200 const TargetOptions &Opts)
201 : WebAssemblyTargetInfo(T, Opts) {
203 }
204
205protected:
206 void getTargetDefines(const LangOptions &Opts,
207 MacroBuilder &Builder) const override;
208};
209
210class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo
211 : public WebAssemblyTargetInfo {
212public:
213 explicit WebAssembly64TargetInfo(const llvm::Triple &T,
214 const TargetOptions &Opts)
215 : WebAssemblyTargetInfo(T, Opts) {
216 LongAlign = LongWidth = 64;
222 }
223
224protected:
225 void getTargetDefines(const LangOptions &Opts,
226 MacroBuilder &Builder) const override;
227};
228} // namespace targets
229} // namespace clang
230#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.
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 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