blob: 9665156b143f1c354d22cb89e9ca6ee498549099 [file] [log] [blame]
Erich Keaneebba5922017-07-21 22:37:03 +00001//=== WebAssembly.h - Declare WebAssembly target feature support *- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Erich Keaneebba5922017-07-21 22:37:03 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This file declares WebAssembly TargetInfo objects.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_WEBASSEMBLY_H
14#define LLVM_CLANG_LIB_BASIC_TARGETS_WEBASSEMBLY_H
15
16#include "clang/Basic/TargetInfo.h"
17#include "clang/Basic/TargetOptions.h"
18#include "llvm/ADT/Triple.h"
19#include "llvm/Support/Compiler.h"
20
21namespace clang {
22namespace targets {
23
24class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {
25 static const Builtin::Info BuiltinInfo[];
26
27 enum SIMDEnum {
28 NoSIMD,
29 SIMD128,
Thomas Livelyb7b9fdc2019-01-10 23:49:00 +000030 UnimplementedSIMD128,
31 } SIMDLevel = NoSIMD;
Erich Keaneebba5922017-07-21 22:37:03 +000032
Thomas Lively88058d42019-01-31 21:02:19 +000033 bool HasNontrappingFPToInt = false;
34 bool HasSignExt = false;
35 bool HasExceptionHandling = false;
36 bool HasBulkMemory = false;
Heejin Ahnbab85972019-02-06 01:41:26 +000037 bool HasAtomics = false;
Thomas Lively5f0c4c62019-03-29 22:00:18 +000038 bool HasMutableGlobals = false;
Thomas Livelyeafe8ef2019-05-23 17:26:47 +000039 bool HasMultivalue = false;
40 bool HasTailCall = false;
Dan Gohman0811cd12017-11-28 01:13:45 +000041
Erich Keaneebba5922017-07-21 22:37:03 +000042public:
43 explicit WebAssemblyTargetInfo(const llvm::Triple &T, const TargetOptions &)
Thomas Lively88058d42019-01-31 21:02:19 +000044 : TargetInfo(T) {
Erich Keaneebba5922017-07-21 22:37:03 +000045 NoAsmVariants = true;
46 SuitableAlign = 128;
47 LargeArrayMinWidth = 128;
48 LargeArrayAlign = 128;
49 SimdDefaultAlign = 128;
50 SigAtomicType = SignedLong;
51 LongDoubleWidth = LongDoubleAlign = 128;
52 LongDoubleFormat = &llvm::APFloat::IEEEquad();
Dan Gohman59f169912018-01-23 20:22:12 +000053 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
Dan Gohmandf07a352018-07-24 00:29:58 +000054 // size_t being unsigned long for both wasm32 and wasm64 makes mangled names
55 // more consistent between the two.
56 SizeType = UnsignedLong;
57 PtrDiffType = SignedLong;
58 IntPtrType = SignedLong;
Erich Keaneebba5922017-07-21 22:37:03 +000059 }
60
61protected:
62 void getTargetDefines(const LangOptions &Opts,
63 MacroBuilder &Builder) const override;
64
65private:
Thomas Livelyb7b9fdc2019-01-10 23:49:00 +000066 static void setSIMDLevel(llvm::StringMap<bool> &Features, SIMDEnum Level);
67
Erich Keaneebba5922017-07-21 22:37:03 +000068 bool
69 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
70 StringRef CPU,
Thomas Livelyb7b9fdc2019-01-10 23:49:00 +000071 const std::vector<std::string> &FeaturesVec) const override;
Erich Keaneebba5922017-07-21 22:37:03 +000072 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