clang 20.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 20, // wasm_funcref
46};
47
48class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {
49
50 enum SIMDEnum {
51 NoSIMD,
52 SIMD128,
53 RelaxedSIMD,
54 } SIMDLevel = NoSIMD;
55
56 bool HasAtomics = false;
57 bool HasBulkMemory = false;
58 bool HasBulkMemoryOpt = false;
59 bool HasCallIndirectOverlong = false;
60 bool HasExceptionHandling = false;
61 bool HasExtendedConst = false;
62 bool HasFP16 = false;
63 bool HasMultiMemory = false;
64 bool HasMultivalue = false;
65 bool HasMutableGlobals = false;
66 bool HasNontrappingFPToInt = false;
67 bool HasReferenceTypes = false;
68 bool HasSignExt = false;
69 bool HasTailCall = false;
70 bool HasWideArithmetic = false;
71
72 std::string ABI;
73
74public:
75 explicit WebAssemblyTargetInfo(const llvm::Triple &T, const TargetOptions &)
76 : TargetInfo(T) {
77 AddrSpaceMap = &WebAssemblyAddrSpaceMap;
78 NoAsmVariants = true;
79 SuitableAlign = 128;
80 LargeArrayMinWidth = 128;
81 LargeArrayAlign = 128;
82 SigAtomicType = SignedLong;
83 LongDoubleWidth = LongDoubleAlign = 128;
84 LongDoubleFormat = &llvm::APFloat::IEEEquad();
85 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
86 // size_t being unsigned long for both wasm32 and wasm64 makes mangled names
87 // more consistent between the two.
88 SizeType = UnsignedLong;
89 PtrDiffType = SignedLong;
90 IntPtrType = SignedLong;
91 HasUnalignedAccess = true;
92 }
93
94 StringRef getABI() const override;
95 bool setABI(const std::string &Name) override;
96 bool useFP16ConversionIntrinsics() const override { return !HasFP16; }
97
98protected:
99 void getTargetDefines(const LangOptions &Opts,
100 MacroBuilder &Builder) const override;
101
102private:
103 static void setSIMDLevel(llvm::StringMap<bool> &Features, SIMDEnum Level,
104 bool Enabled);
105
106 bool
107 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
108 StringRef CPU,
109 const std::vector<std::string> &FeaturesVec) const override;
110 bool hasFeature(StringRef Feature) const final;
111
112 void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name,
113 bool Enabled) const final;
114
115 bool handleTargetFeatures(std::vector<std::string> &Features,
116 DiagnosticsEngine &Diags) final;
117
118 bool isValidCPUName(StringRef Name) const final;
119 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const final;
120
121 bool setCPU(const std::string &Name) final { return isValidCPUName(Name); }
122
123 ArrayRef<Builtin::Info> getTargetBuiltins() const final;
124
125 BuiltinVaListKind getBuiltinVaListKind() const final {
126 return VoidPtrBuiltinVaList;
127 }
128
129 ArrayRef<const char *> getGCCRegNames() const final { return {}; }
130
131 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const final {
132 return {};
133 }
134
135 bool validateAsmConstraint(const char *&Name,
136 TargetInfo::ConstraintInfo &Info) const final {
137 return false;
138 }
139
140 std::string_view getClobbers() const final { return ""; }
141
142 bool isCLZForZeroUndef() const final { return false; }
143
144 bool hasInt128Type() const final { return true; }
145
146 IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
147 // WebAssembly prefers long long for explicitly 64-bit integers.
148 return BitWidth == 64 ? (IsSigned ? SignedLongLong : UnsignedLongLong)
149 : TargetInfo::getIntTypeByWidth(BitWidth, IsSigned);
150 }
151
152 IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
153 // WebAssembly uses long long for int_least64_t and int_fast64_t.
154 return BitWidth == 64
155 ? (IsSigned ? SignedLongLong : UnsignedLongLong)
156 : TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned);
157 }
158
159 CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
160 switch (CC) {
161 case CC_C:
162 case CC_Swift:
163 return CCCR_OK;
164 case CC_SwiftAsync:
165 return CCCR_Error;
166 default:
167 return CCCR_Warning;
168 }
169 }
170
171 bool hasBitIntType() const override { return true; }
172
173 bool hasProtectedVisibility() const override { return false; }
174
175 void adjust(DiagnosticsEngine &Diags, LangOptions &Opts) override;
176};
177
178class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo
179 : public WebAssemblyTargetInfo {
180public:
181 explicit WebAssembly32TargetInfo(const llvm::Triple &T,
182 const TargetOptions &Opts)
183 : WebAssemblyTargetInfo(T, Opts) {
184 if (T.isOSEmscripten())
185 resetDataLayout(
186 "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-i128:128-f128:64-n32:64-"
187 "S128-ni:1:10:20");
188 else
189 resetDataLayout("e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-i128:128-n32:64-"
190 "S128-ni:1:10:20");
191 }
192
193protected:
194 void getTargetDefines(const LangOptions &Opts,
195 MacroBuilder &Builder) const override;
196};
197
198class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo
199 : public WebAssemblyTargetInfo {
200public:
201 explicit WebAssembly64TargetInfo(const llvm::Triple &T,
202 const TargetOptions &Opts)
203 : WebAssemblyTargetInfo(T, Opts) {
204 LongAlign = LongWidth = 64;
205 PointerAlign = PointerWidth = 64;
206 SizeType = UnsignedLong;
207 PtrDiffType = SignedLong;
208 IntPtrType = SignedLong;
209 if (T.isOSEmscripten())
210 resetDataLayout(
211 "e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-i128:128-f128:64-n32:64-"
212 "S128-ni:1:10:20");
213 else
214 resetDataLayout("e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-i128:128-n32:64-"
215 "S128-ni:1:10:20");
216 }
217
218protected:
219 void getTargetDefines(const LangOptions &Opts,
220 MacroBuilder &Builder) const override;
221};
222} // namespace targets
223} // namespace clang
224#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:96
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:499
Exposes information about the current target.
Definition: TargetInfo.h:220
Options for controlling the target.
Definition: TargetOptions.h:26
WebAssembly32TargetInfo(const llvm::Triple &T, const TargetOptions &Opts)
Definition: WebAssembly.h:181
WebAssembly64TargetInfo(const llvm::Triple &T, const TargetOptions &Opts)
Definition: WebAssembly.h:201
WebAssemblyTargetInfo(const llvm::Triple &T, const TargetOptions &)
Definition: WebAssembly.h:75
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:96
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