[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / lib / Basic / Targets / WebAssembly.h
blobaeebc840a8ecdf14055626435fbeff8f6eac8d14
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.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_WEBASSEMBLY_H
14 #define LLVM_CLANG_LIB_BASIC_TARGETS_WEBASSEMBLY_H
16 #include "clang/Basic/TargetInfo.h"
17 #include "clang/Basic/TargetOptions.h"
18 #include "llvm/Support/Compiler.h"
19 #include "llvm/TargetParser/Triple.h"
21 namespace clang {
22 namespace targets {
24 class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {
26 enum SIMDEnum {
27 NoSIMD,
28 SIMD128,
29 RelaxedSIMD,
30 } SIMDLevel = NoSIMD;
32 bool HasNontrappingFPToInt = false;
33 bool HasSignExt = false;
34 bool HasExceptionHandling = false;
35 bool HasBulkMemory = false;
36 bool HasAtomics = false;
37 bool HasMutableGlobals = false;
38 bool HasMultivalue = false;
39 bool HasTailCall = false;
40 bool HasReferenceTypes = false;
41 bool HasExtendedConst = false;
43 std::string ABI;
45 public:
46 explicit WebAssemblyTargetInfo(const llvm::Triple &T, const TargetOptions &)
47 : TargetInfo(T) {
48 NoAsmVariants = true;
49 SuitableAlign = 128;
50 LargeArrayMinWidth = 128;
51 LargeArrayAlign = 128;
52 SigAtomicType = SignedLong;
53 LongDoubleWidth = LongDoubleAlign = 128;
54 LongDoubleFormat = &llvm::APFloat::IEEEquad();
55 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
56 // size_t being unsigned long for both wasm32 and wasm64 makes mangled names
57 // more consistent between the two.
58 SizeType = UnsignedLong;
59 PtrDiffType = SignedLong;
60 IntPtrType = SignedLong;
63 StringRef getABI() const override;
64 bool setABI(const std::string &Name) override;
66 protected:
67 void getTargetDefines(const LangOptions &Opts,
68 MacroBuilder &Builder) const override;
70 private:
71 static void setSIMDLevel(llvm::StringMap<bool> &Features, SIMDEnum Level,
72 bool Enabled);
74 bool
75 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
76 StringRef CPU,
77 const std::vector<std::string> &FeaturesVec) const override;
78 bool hasFeature(StringRef Feature) const final;
80 void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name,
81 bool Enabled) const final;
83 bool handleTargetFeatures(std::vector<std::string> &Features,
84 DiagnosticsEngine &Diags) final;
86 bool isValidCPUName(StringRef Name) const final;
87 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const final;
89 bool setCPU(const std::string &Name) final { return isValidCPUName(Name); }
91 ArrayRef<Builtin::Info> getTargetBuiltins() const final;
93 BuiltinVaListKind getBuiltinVaListKind() const final {
94 return VoidPtrBuiltinVaList;
97 ArrayRef<const char *> getGCCRegNames() const final { return std::nullopt; }
99 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const final {
100 return std::nullopt;
103 bool validateAsmConstraint(const char *&Name,
104 TargetInfo::ConstraintInfo &Info) const final {
105 return false;
108 const char *getClobbers() const final { return ""; }
110 bool isCLZForZeroUndef() const final { return false; }
112 bool hasInt128Type() const final { return true; }
114 IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
115 // WebAssembly prefers long long for explicitly 64-bit integers.
116 return BitWidth == 64 ? (IsSigned ? SignedLongLong : UnsignedLongLong)
117 : TargetInfo::getIntTypeByWidth(BitWidth, IsSigned);
120 IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
121 // WebAssembly uses long long for int_least64_t and int_fast64_t.
122 return BitWidth == 64
123 ? (IsSigned ? SignedLongLong : UnsignedLongLong)
124 : TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned);
127 CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
128 switch (CC) {
129 case CC_C:
130 case CC_Swift:
131 return CCCR_OK;
132 case CC_SwiftAsync:
133 return CCCR_Error;
134 default:
135 return CCCR_Warning;
139 bool hasBitIntType() const override { return true; }
141 bool hasProtectedVisibility() const override { return false; }
143 void adjust(DiagnosticsEngine &Diags, LangOptions &Opts) override;
146 class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo
147 : public WebAssemblyTargetInfo {
148 public:
149 explicit WebAssembly32TargetInfo(const llvm::Triple &T,
150 const TargetOptions &Opts)
151 : WebAssemblyTargetInfo(T, Opts) {
152 if (T.isOSEmscripten())
153 resetDataLayout("e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-"
154 "S128-ni:1:10:20");
155 else
156 resetDataLayout(
157 "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20");
160 protected:
161 void getTargetDefines(const LangOptions &Opts,
162 MacroBuilder &Builder) const override;
165 class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo
166 : public WebAssemblyTargetInfo {
167 public:
168 explicit WebAssembly64TargetInfo(const llvm::Triple &T,
169 const TargetOptions &Opts)
170 : WebAssemblyTargetInfo(T, Opts) {
171 LongAlign = LongWidth = 64;
172 PointerAlign = PointerWidth = 64;
173 SizeType = UnsignedLong;
174 PtrDiffType = SignedLong;
175 IntPtrType = SignedLong;
176 if (T.isOSEmscripten())
177 resetDataLayout("e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-"
178 "S128-ni:1:10:20");
179 else
180 resetDataLayout(
181 "e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20");
184 protected:
185 void getTargetDefines(const LangOptions &Opts,
186 MacroBuilder &Builder) const override;
188 } // namespace targets
189 } // namespace clang
190 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_WEBASSEMBLY_H