blob: b0e466b8d8c24283643a5a06575975d3c4d37865 [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;
Erich Keaneebba5922017-07-21 22:37:03 +000050 SizeType = UnsignedInt;
51 PtrDiffType = SignedInt;
52 IntPtrType = SignedInt;
53 }
54
55protected:
56 void getTargetDefines(const LangOptions &Opts,
57 MacroBuilder &Builder) const override;
58
59private:
60 bool
61 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
62 StringRef CPU,
63 const std::vector<std::string> &FeaturesVec) const override {
Dan Gohman0811cd12017-11-28 01:13:45 +000064 if (CPU == "bleeding-edge") {
Erich Keaneebba5922017-07-21 22:37:03 +000065 Features["simd128"] = true;
Dan Gohman0811cd12017-11-28 01:13:45 +000066 Features["nontrapping-fptoint"] = true;
Dan Gohmand0c4e1e2018-01-19 17:16:32 +000067 Features["sign-ext"] = true;
Dan Gohman0811cd12017-11-28 01:13:45 +000068 }
Erich Keaneebba5922017-07-21 22:37:03 +000069 return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
70 }
71
72 bool hasFeature(StringRef Feature) const final;
73
74 bool handleTargetFeatures(std::vector<std::string> &Features,
75 DiagnosticsEngine &Diags) final;
76
77 bool isValidCPUName(StringRef Name) const final;
Erich Keanee44bdb32018-02-08 23:16:55 +000078 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const final;
Erich Keaneebba5922017-07-21 22:37:03 +000079
80 bool setCPU(const std::string &Name) final { return isValidCPUName(Name); }
81
82 ArrayRef<Builtin::Info> getTargetBuiltins() const final;
83
84 BuiltinVaListKind getBuiltinVaListKind() const final {
85 return VoidPtrBuiltinVaList;
86 }
87
88 ArrayRef<const char *> getGCCRegNames() const final { return None; }
89
90 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const final {
91 return None;
92 }
93
94 bool validateAsmConstraint(const char *&Name,
95 TargetInfo::ConstraintInfo &Info) const final {
96 return false;
97 }
98
99 const char *getClobbers() const final { return ""; }
100
101 bool isCLZForZeroUndef() const final { return false; }
102
103 bool hasInt128Type() const final { return true; }
104
105 IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
106 // WebAssembly prefers long long for explicitly 64-bit integers.
107 return BitWidth == 64 ? (IsSigned ? SignedLongLong : UnsignedLongLong)
108 : TargetInfo::getIntTypeByWidth(BitWidth, IsSigned);
109 }
110
111 IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
112 // WebAssembly uses long long for int_least64_t and int_fast64_t.
113 return BitWidth == 64
114 ? (IsSigned ? SignedLongLong : UnsignedLongLong)
115 : TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned);
116 }
117};
118class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo
119 : public WebAssemblyTargetInfo {
120public:
121 explicit WebAssembly32TargetInfo(const llvm::Triple &T,
122 const TargetOptions &Opts)
123 : WebAssemblyTargetInfo(T, Opts) {
Erich Keaneebba5922017-07-21 22:37:03 +0000124 resetDataLayout("e-m:e-p:32:32-i64:64-n32:64-S128");
125 }
126
127protected:
128 void getTargetDefines(const LangOptions &Opts,
129 MacroBuilder &Builder) const override;
130};
131
132class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo
133 : public WebAssemblyTargetInfo {
134public:
135 explicit WebAssembly64TargetInfo(const llvm::Triple &T,
136 const TargetOptions &Opts)
137 : WebAssemblyTargetInfo(T, Opts) {
138 LongAlign = LongWidth = 64;
139 PointerAlign = PointerWidth = 64;
Erich Keaneebba5922017-07-21 22:37:03 +0000140 SizeType = UnsignedLong;
141 PtrDiffType = SignedLong;
142 IntPtrType = SignedLong;
143 resetDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128");
144 }
145
146protected:
147 void getTargetDefines(const LangOptions &Opts,
148 MacroBuilder &Builder) const override;
149};
150} // namespace targets
151} // namespace clang
152#endif // LLVM_CLANG_LIB_BASIC_TARGETS_WEBASSEMBLY_H