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;
36 explicit WebAssemblyTargetInfo(const llvm::Triple &T, const TargetOptions &)
37 : TargetInfo(T), SIMDLevel(NoSIMD), HasNontrappingFPToInt(false) {
40 LargeArrayMinWidth = 128;
41 LargeArrayAlign = 128;
42 SimdDefaultAlign = 128;
43 SigAtomicType = SignedLong;
44 LongDoubleWidth = LongDoubleAlign = 128;
45 LongDoubleFormat = &llvm::APFloat::IEEEquad();
46 SizeType = UnsignedInt;
47 PtrDiffType = SignedInt;
48 IntPtrType = SignedInt;
52 void getTargetDefines(const LangOptions &Opts,
53 MacroBuilder &Builder) const override;
57 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
59 const std::vector<std::string> &FeaturesVec) const override {
60 if (CPU == "bleeding-edge") {
61 Features["simd128"] = true;
62 Features["nontrapping-fptoint"] = true;
64 return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
67 bool hasFeature(StringRef Feature) const final;
69 bool handleTargetFeatures(std::vector<std::string> &Features,
70 DiagnosticsEngine &Diags) final;
72 bool isValidCPUName(StringRef Name) const final;
74 bool setCPU(const std::string &Name) final { return isValidCPUName(Name); }
76 ArrayRef<Builtin::Info> getTargetBuiltins() const final;
78 BuiltinVaListKind getBuiltinVaListKind() const final {
79 return VoidPtrBuiltinVaList;
82 ArrayRef<const char *> getGCCRegNames() const final { return None; }
84 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const final {
88 bool validateAsmConstraint(const char *&Name,
89 TargetInfo::ConstraintInfo &Info) const final {
93 const char *getClobbers() const final { return ""; }
95 bool isCLZForZeroUndef() const final { return false; }
97 bool hasInt128Type() const final { return true; }
99 IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
100 // WebAssembly prefers long long for explicitly 64-bit integers.
101 return BitWidth == 64 ? (IsSigned ? SignedLongLong : UnsignedLongLong)
102 : TargetInfo::getIntTypeByWidth(BitWidth, IsSigned);
105 IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
106 // WebAssembly uses long long for int_least64_t and int_fast64_t.
107 return BitWidth == 64
108 ? (IsSigned ? SignedLongLong : UnsignedLongLong)
109 : TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned);
112 class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo
113 : public WebAssemblyTargetInfo {
115 explicit WebAssembly32TargetInfo(const llvm::Triple &T,
116 const TargetOptions &Opts)
117 : WebAssemblyTargetInfo(T, Opts) {
118 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
119 resetDataLayout("e-m:e-p:32:32-i64:64-n32:64-S128");
123 void getTargetDefines(const LangOptions &Opts,
124 MacroBuilder &Builder) const override;
127 class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo
128 : public WebAssemblyTargetInfo {
130 explicit WebAssembly64TargetInfo(const llvm::Triple &T,
131 const TargetOptions &Opts)
132 : WebAssemblyTargetInfo(T, Opts) {
133 LongAlign = LongWidth = 64;
134 PointerAlign = PointerWidth = 64;
135 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
136 SizeType = UnsignedLong;
137 PtrDiffType = SignedLong;
138 IntPtrType = SignedLong;
139 resetDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128");
143 void getTargetDefines(const LangOptions &Opts,
144 MacroBuilder &Builder) const override;
146 } // namespace targets
148 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_WEBASSEMBLY_H