blob: c04c5cb6fb3a9d282c7139fafe9b86ed0c6ba46e [file] [log] [blame]
Erich Keaneebba5922017-07-21 22:37:03 +00001//=== WebAssembly.h - Declare WebAssembly target feature support *- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file declares WebAssembly TargetInfo objects.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_WEBASSEMBLY_H
15#define LLVM_CLANG_LIB_BASIC_TARGETS_WEBASSEMBLY_H
16
17#include "clang/Basic/TargetInfo.h"
18#include "clang/Basic/TargetOptions.h"
19#include "llvm/ADT/Triple.h"
20#include "llvm/Support/Compiler.h"
21
22namespace clang {
23namespace targets {
24
25class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {
26 static const Builtin::Info BuiltinInfo[];
27
28 enum SIMDEnum {
29 NoSIMD,
30 SIMD128,
31 } SIMDLevel;
32
Dan Gohman0811cd12017-11-28 01:13:45 +000033 bool HasNontrappingFPToInt;
Dan Gohmand0c4e1e2018-01-19 17:16:32 +000034 bool HasSignExt;
Heejin Ahn8b6af222018-03-02 00:39:16 +000035 bool HasExceptionHandling;
Dan Gohman0811cd12017-11-28 01:13:45 +000036
Erich Keaneebba5922017-07-21 22:37:03 +000037public:
38 explicit WebAssemblyTargetInfo(const llvm::Triple &T, const TargetOptions &)
Dan Gohmand0c4e1e2018-01-19 17:16:32 +000039 : TargetInfo(T), SIMDLevel(NoSIMD), HasNontrappingFPToInt(false),
Heejin Ahn8b6af222018-03-02 00:39:16 +000040 HasSignExt(false), HasExceptionHandling(false) {
Erich Keaneebba5922017-07-21 22:37:03 +000041 NoAsmVariants = true;
42 SuitableAlign = 128;
43 LargeArrayMinWidth = 128;
44 LargeArrayAlign = 128;
45 SimdDefaultAlign = 128;
46 SigAtomicType = SignedLong;
47 LongDoubleWidth = LongDoubleAlign = 128;
48 LongDoubleFormat = &llvm::APFloat::IEEEquad();
Dan Gohman59f169912018-01-23 20:22:12 +000049 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
Dan Gohmandf07a352018-07-24 00:29:58 +000050 // 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;
Erich Keaneebba5922017-07-21 22:37:03 +000055 }
56
57protected:
58 void getTargetDefines(const LangOptions &Opts,
59 MacroBuilder &Builder) const override;
60
61private:
62 bool
63 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
64 StringRef CPU,
65 const std::vector<std::string> &FeaturesVec) const override {
Dan Gohman0811cd12017-11-28 01:13:45 +000066 if (CPU == "bleeding-edge") {
Erich Keaneebba5922017-07-21 22:37:03 +000067 Features["simd128"] = true;
Dan Gohman0811cd12017-11-28 01:13:45 +000068 Features["nontrapping-fptoint"] = true;
Dan Gohmand0c4e1e2018-01-19 17:16:32 +000069 Features["sign-ext"] = true;
Dan Gohman0811cd12017-11-28 01:13:45 +000070 }
Erich Keaneebba5922017-07-21 22:37:03 +000071 return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
72 }
73
74 bool hasFeature(StringRef Feature) const final;
75
76 bool handleTargetFeatures(std::vector<std::string> &Features,
77 DiagnosticsEngine &Diags) final;
78
79 bool isValidCPUName(StringRef Name) const final;
Erich Keanee44bdb32018-02-08 23:16:55 +000080 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const final;
Erich Keaneebba5922017-07-21 22:37:03 +000081
82 bool setCPU(const std::string &Name) final { return isValidCPUName(Name); }
83
84 ArrayRef<Builtin::Info> getTargetBuiltins() const final;
85
86 BuiltinVaListKind getBuiltinVaListKind() const final {
87 return VoidPtrBuiltinVaList;
88 }
89
90 ArrayRef<const char *> getGCCRegNames() const final { return None; }
91
92 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const final {
93 return None;
94 }
95
96 bool validateAsmConstraint(const char *&Name,
97 TargetInfo::ConstraintInfo &Info) const final {
98 return false;
99 }
100
101 const char *getClobbers() const final { return ""; }
102
103 bool isCLZForZeroUndef() const final { return false; }
104
105 bool hasInt128Type() const final { return true; }
106
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);
111 }
112
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);
118 }
119};
120class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo
121 : public WebAssemblyTargetInfo {
122public:
123 explicit WebAssembly32TargetInfo(const llvm::Triple &T,
124 const TargetOptions &Opts)
125 : WebAssemblyTargetInfo(T, Opts) {
Erich Keaneebba5922017-07-21 22:37:03 +0000126 resetDataLayout("e-m:e-p:32:32-i64:64-n32:64-S128");
127 }
128
129protected:
130 void getTargetDefines(const LangOptions &Opts,
131 MacroBuilder &Builder) const override;
132};
133
134class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo
135 : public WebAssemblyTargetInfo {
136public:
137 explicit WebAssembly64TargetInfo(const llvm::Triple &T,
138 const TargetOptions &Opts)
139 : WebAssemblyTargetInfo(T, Opts) {
140 LongAlign = LongWidth = 64;
141 PointerAlign = PointerWidth = 64;
Erich Keaneebba5922017-07-21 22:37:03 +0000142 SizeType = UnsignedLong;
143 PtrDiffType = SignedLong;
144 IntPtrType = SignedLong;
145 resetDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128");
146 }
147
148protected:
149 void getTargetDefines(const LangOptions &Opts,
150 MacroBuilder &Builder) const override;
151};
152} // namespace targets
153} // namespace clang
154#endif // LLVM_CLANG_LIB_BASIC_TARGETS_WEBASSEMBLY_H