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) {
82 AddrSpaceMap = &WebAssemblyAddrSpaceMap;
83 NoAsmVariants = true;
84 SuitableAlign = 128;
85 LargeArrayMinWidth = 128;
86 LargeArrayAlign = 128;
87 SigAtomicType = SignedLong;
88 LongDoubleWidth = LongDoubleAlign = 128;
89 LongDoubleFormat = &llvm::APFloat::IEEEquad();
90 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
91 // size_t being unsigned long for both wasm32 and wasm64 makes mangled names
92 // more consistent between the two.
93 SizeType = UnsignedLong;
94 PtrDiffType = SignedLong;
95 IntPtrType = SignedLong;
96 HasUnalignedAccess = true;
97 }
98
99 StringRef getABI() const override;
100 bool setABI(const std::string &Name) override;
101 bool useFP16ConversionIntrinsics() const override { return !HasFP16; }
102
103protected:
104 void getTargetDefines(const LangOptions &Opts,
105 MacroBuilder &Builder) const override;
106
107private:
108 static void setSIMDLevel(llvm::StringMap<bool> &Features, SIMDEnum Level,
109 bool Enabled);
110
111 bool
112 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
113 StringRef CPU,
114 const std::vector<std::string> &FeaturesVec) const override;
115 bool hasFeature(StringRef Feature) const final;
116
117 void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name,
118 bool Enabled) const final;
119
120 bool handleTargetFeatures(std::vector<std::string> &Features,
121 DiagnosticsEngine &Diags) final;
122
123 bool isValidCPUName(StringRef Name) const final;
124 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const final;
125
126 bool setCPU(const std::string &Name) final { return isValidCPUName(Name); }
127
128 llvm::SmallVector<Builtin::InfosShard> getTargetBuiltins() const final;
129
130 BuiltinVaListKind getBuiltinVaListKind() const final {
131 return VoidPtrBuiltinVaList;
132 }
133
134 ArrayRef<const char *> getGCCRegNames() const final { return {}; }
135
136 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const final {
137 return {};
138 }
139
140 bool validateAsmConstraint(const char *&Name,
141 TargetInfo::ConstraintInfo &Info) const final {
142 return false;
143 }
144
145 std::string_view getClobbers() const final { return ""; }
146
147 bool isCLZForZeroUndef() const final { return false; }
148
149 bool hasInt128Type() const final { return true; }
150
151 IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
152 // WebAssembly prefers long long for explicitly 64-bit integers.
153 return BitWidth == 64 ? (IsSigned ? SignedLongLong : UnsignedLongLong)
154 : TargetInfo::getIntTypeByWidth(BitWidth, IsSigned);
155 }
156
157 IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
158 // WebAssembly uses long long for int_least64_t and int_fast64_t.
159 return BitWidth == 64
160 ? (IsSigned ? SignedLongLong : UnsignedLongLong)
161 : TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned);
162 }
163
164 CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
165 switch (CC) {
166 case CC_C:
167 case CC_Swift:
168 return CCCR_OK;
169 case CC_SwiftAsync:
170 return CCCR_Error;
171 default:
172 return CCCR_Warning;
173 }
174 }
175
176 bool hasBitIntType() const override { return true; }
177
178 bool hasProtectedVisibility() const override { return false; }
179
180 void adjust(DiagnosticsEngine &Diags, LangOptions &Opts,
181 const TargetInfo *Aux) override;
182};
183
184class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo
185 : public WebAssemblyTargetInfo {
186public:
187 explicit WebAssembly32TargetInfo(const llvm::Triple &T,
188 const TargetOptions &Opts)
189 : WebAssemblyTargetInfo(T, Opts) {
190 if (T.isOSEmscripten())
191 resetDataLayout(
192 "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-i128:128-f128:64-n32:64-"
193 "S128-ni:1:10:20");
194 else
195 resetDataLayout("e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-i128:128-n32:64-"
196 "S128-ni:1:10:20");
197 }
198
199protected:
200 void getTargetDefines(const LangOptions &Opts,
201 MacroBuilder &Builder) const override;
202};
203
204class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo
205 : public WebAssemblyTargetInfo {
206public:
207 explicit WebAssembly64TargetInfo(const llvm::Triple &T,
208 const TargetOptions &Opts)
209 : WebAssemblyTargetInfo(T, Opts) {
210 LongAlign = LongWidth = 64;
211 PointerAlign = PointerWidth = 64;
212 SizeType = UnsignedLong;
213 PtrDiffType = SignedLong;
214 IntPtrType = SignedLong;
215 if (T.isOSEmscripten())
216 resetDataLayout(
217 "e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-i128:128-f128:64-n32:64-"
218 "S128-ni:1:10:20");
219 else
220 resetDataLayout("e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-i128:128-n32:64-"
221 "S128-ni:1:10:20");
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:231
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:434
Exposes information about the current target.
Definition: TargetInfo.h:226
Options for controlling the target.
Definition: TargetOptions.h:26
WebAssembly32TargetInfo(const llvm::Triple &T, const TargetOptions &Opts)
Definition: WebAssembly.h:187
WebAssembly64TargetInfo(const llvm::Triple &T, const TargetOptions &Opts)
Definition: WebAssembly.h:207
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...
Definition: WebAssembly.h:101
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_C
Definition: Specifiers.h:279
@ CC_SwiftAsync
Definition: Specifiers.h:294