1 //=== WebAssembly.h - Declare WebAssembly target feature support *- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares WebAssembly TargetInfo objects.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_WEBASSEMBLY_H
15 #define LLVM_CLANG_LIB_BASIC_TARGETS_WEBASSEMBLY_H
17 #include "clang/Basic/TargetInfo.h"
18 #include "clang/Basic/TargetOptions.h"
19 #include "llvm/ADT/Triple.h"
20 #include "llvm/Support/Compiler.h"
25 class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {
26 static const Builtin::Info BuiltinInfo[];
33 bool HasNontrappingFPToInt;
35 bool HasExceptionHandling;
38 explicit WebAssemblyTargetInfo(const llvm::Triple &T, const TargetOptions &)
39 : TargetInfo(T), SIMDLevel(NoSIMD), HasNontrappingFPToInt(false),
40 HasSignExt(false), HasExceptionHandling(false) {
43 LargeArrayMinWidth = 128;
44 LargeArrayAlign = 128;
45 SimdDefaultAlign = 128;
46 SigAtomicType = SignedLong;
47 LongDoubleWidth = LongDoubleAlign = 128;
48 LongDoubleFormat = &llvm::APFloat::IEEEquad();
49 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
50 // size_t being unsigned long for both wasm32 and wasm64 makes mangled names
51 // more consistent between the two.
52 SizeType = UnsignedLong;
53 PtrDiffType = SignedLong;
54 IntPtrType = SignedLong;
58 void getTargetDefines(const LangOptions &Opts,
59 MacroBuilder &Builder) const override;
63 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
65 const std::vector<std::string> &FeaturesVec) const override {
66 if (CPU == "bleeding-edge") {
67 Features["simd128"] = true;
68 Features["nontrapping-fptoint"] = true;
69 Features["sign-ext"] = true;
71 return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
74 bool hasFeature(StringRef Feature) const final;
76 bool handleTargetFeatures(std::vector<std::string> &Features,
77 DiagnosticsEngine &Diags) final;
79 bool isValidCPUName(StringRef Name) const final;
80 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const final;
82 bool setCPU(const std::string &Name) final { return isValidCPUName(Name); }
84 ArrayRef<Builtin::Info> getTargetBuiltins() const final;
86 BuiltinVaListKind getBuiltinVaListKind() const final {
87 return VoidPtrBuiltinVaList;
90 ArrayRef<const char *> getGCCRegNames() const final { return None; }
92 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const final {
96 bool validateAsmConstraint(const char *&Name,
97 TargetInfo::ConstraintInfo &Info) const final {
101 const char *getClobbers() const final { return ""; }
103 bool isCLZForZeroUndef() const final { return false; }
105 bool hasInt128Type() const final { return true; }
107 IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
108 // WebAssembly prefers long long for explicitly 64-bit integers.
109 return BitWidth == 64 ? (IsSigned ? SignedLongLong : UnsignedLongLong)
110 : TargetInfo::getIntTypeByWidth(BitWidth, IsSigned);
113 IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
114 // WebAssembly uses long long for int_least64_t and int_fast64_t.
115 return BitWidth == 64
116 ? (IsSigned ? SignedLongLong : UnsignedLongLong)
117 : TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned);
120 class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo
121 : public WebAssemblyTargetInfo {
123 explicit WebAssembly32TargetInfo(const llvm::Triple &T,
124 const TargetOptions &Opts)
125 : WebAssemblyTargetInfo(T, Opts) {
126 resetDataLayout("e-m:e-p:32:32-i64:64-n32:64-S128");
130 void getTargetDefines(const LangOptions &Opts,
131 MacroBuilder &Builder) const override;
134 class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo
135 : public WebAssemblyTargetInfo {
137 explicit WebAssembly64TargetInfo(const llvm::Triple &T,
138 const TargetOptions &Opts)
139 : WebAssemblyTargetInfo(T, Opts) {
140 LongAlign = LongWidth = 64;
141 PointerAlign = PointerWidth = 64;
142 SizeType = UnsignedLong;
143 PtrDiffType = SignedLong;
144 IntPtrType = SignedLong;
145 resetDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128");
149 void getTargetDefines(const LangOptions &Opts,
150 MacroBuilder &Builder) const override;
152 } // namespace targets
154 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_WEBASSEMBLY_H