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