clang  14.0.0git
WebAssembly.h
Go to the documentation of this file.
1 //=== WebAssembly.h - Declare WebAssembly target feature support *- C++ -*-===//
2 //
3 // 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
6 //
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"
18 #include "llvm/ADT/Triple.h"
19 #include "llvm/Support/Compiler.h"
20 
21 namespace clang {
22 namespace targets {
23 
24 class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {
25  static const Builtin::Info BuiltinInfo[];
26 
27  enum SIMDEnum {
28  NoSIMD,
29  SIMD128,
30  RelaxedSIMD,
31  } SIMDLevel = NoSIMD;
32 
33  bool HasNontrappingFPToInt = false;
34  bool HasSignExt = false;
35  bool HasExceptionHandling = false;
36  bool HasBulkMemory = false;
37  bool HasAtomics = false;
38  bool HasMutableGlobals = false;
39  bool HasMultivalue = false;
40  bool HasTailCall = false;
41  bool HasReferenceTypes = false;
42 
43  std::string ABI;
44 
45 public:
46  explicit WebAssemblyTargetInfo(const llvm::Triple &T, const TargetOptions &)
47  : TargetInfo(T) {
48  NoAsmVariants = true;
49  SuitableAlign = 128;
50  LargeArrayMinWidth = 128;
51  LargeArrayAlign = 128;
52  SimdDefaultAlign = 128;
53  SigAtomicType = SignedLong;
54  LongDoubleWidth = LongDoubleAlign = 128;
55  LongDoubleFormat = &llvm::APFloat::IEEEquad();
56  MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
57  // size_t being unsigned long for both wasm32 and wasm64 makes mangled names
58  // more consistent between the two.
59  SizeType = UnsignedLong;
60  PtrDiffType = SignedLong;
61  IntPtrType = SignedLong;
62  }
63 
64  StringRef getABI() const override;
65  bool setABI(const std::string &Name) override;
66 
67 protected:
68  void getTargetDefines(const LangOptions &Opts,
69  MacroBuilder &Builder) const override;
70 
71 private:
72  static void setSIMDLevel(llvm::StringMap<bool> &Features, SIMDEnum Level,
73  bool Enabled);
74 
75  bool
76  initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
77  StringRef CPU,
78  const std::vector<std::string> &FeaturesVec) const override;
79  bool hasFeature(StringRef Feature) const final;
80 
81  void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name,
82  bool Enabled) const final;
83 
84  bool handleTargetFeatures(std::vector<std::string> &Features,
85  DiagnosticsEngine &Diags) final;
86 
87  bool isValidCPUName(StringRef Name) const final;
88  void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const final;
89 
90  bool setCPU(const std::string &Name) final { return isValidCPUName(Name); }
91 
92  ArrayRef<Builtin::Info> getTargetBuiltins() const final;
93 
94  BuiltinVaListKind getBuiltinVaListKind() const final {
95  return VoidPtrBuiltinVaList;
96  }
97 
98  ArrayRef<const char *> getGCCRegNames() const final { return None; }
99 
100  ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const final {
101  return None;
102  }
103 
104  bool validateAsmConstraint(const char *&Name,
105  TargetInfo::ConstraintInfo &Info) const final {
106  return false;
107  }
108 
109  const char *getClobbers() const final { return ""; }
110 
111  bool isCLZForZeroUndef() const final { return false; }
112 
113  bool hasInt128Type() const final { return true; }
114 
115  IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
116  // WebAssembly prefers long long for explicitly 64-bit integers.
117  return BitWidth == 64 ? (IsSigned ? SignedLongLong : UnsignedLongLong)
118  : TargetInfo::getIntTypeByWidth(BitWidth, IsSigned);
119  }
120 
121  IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
122  // WebAssembly uses long long for int_least64_t and int_fast64_t.
123  return BitWidth == 64
124  ? (IsSigned ? SignedLongLong : UnsignedLongLong)
125  : TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned);
126  }
127 
128  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
129  switch (CC) {
130  case CC_C:
131  case CC_Swift:
132  return CCCR_OK;
133  case CC_SwiftAsync:
134  return CCCR_Error;
135  default:
136  return CCCR_Warning;
137  }
138  }
139 
140  bool hasExtIntType() const override { return true; }
141 
142  bool hasProtectedVisibility() const override { return false; }
143 
144  void adjust(DiagnosticsEngine &Diags, LangOptions &Opts) override;
145 };
146 
147 class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo
148  : public WebAssemblyTargetInfo {
149 public:
150  explicit WebAssembly32TargetInfo(const llvm::Triple &T,
151  const TargetOptions &Opts)
152  : WebAssemblyTargetInfo(T, Opts) {
153  if (T.isOSEmscripten())
154  resetDataLayout("e-m:e-p:32:32-i64:64-f128:64-n32:64-S128-ni:1:10:20");
155  else
156  resetDataLayout("e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20");
157  }
158 
159 protected:
160  void getTargetDefines(const LangOptions &Opts,
161  MacroBuilder &Builder) const override;
162 };
163 
164 class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo
165  : public WebAssemblyTargetInfo {
166 public:
167  explicit WebAssembly64TargetInfo(const llvm::Triple &T,
168  const TargetOptions &Opts)
169  : WebAssemblyTargetInfo(T, Opts) {
170  LongAlign = LongWidth = 64;
171  PointerAlign = PointerWidth = 64;
172  SizeType = UnsignedLong;
173  PtrDiffType = SignedLong;
174  IntPtrType = SignedLong;
175  if (T.isOSEmscripten())
176  resetDataLayout("e-m:e-p:64:64-i64:64-f128:64-n32:64-S128-ni:1:10:20");
177  else
178  resetDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128-ni:1:10:20");
179  }
180 
181 protected:
182  void getTargetDefines(const LangOptions &Opts,
183  MacroBuilder &Builder) const override;
184 };
185 } // namespace targets
186 } // namespace clang
187 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_WEBASSEMBLY_H
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
TargetInfo.h
clang::targets::WebAssemblyTargetInfo
Definition: WebAssembly.h:24
clang::DiagnosticsEngine
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:191
clang::TargetInfo
Exposes information about the current target.
Definition: TargetInfo.h:189
clang::targets::WebAssembly64TargetInfo::WebAssembly64TargetInfo
WebAssembly64TargetInfo(const llvm::Triple &T, const TargetOptions &Opts)
Definition: WebAssembly.h:167
BuiltinInfo
static const Builtin::Info BuiltinInfo[]
Definition: Builtins.cpp:20
clang::CC_Swift
@ CC_Swift
Definition: Specifiers.h:278
clang::targets::WebAssemblyTargetInfo::WebAssemblyTargetInfo
WebAssemblyTargetInfo(const llvm::Triple &T, const TargetOptions &)
Definition: WebAssembly.h:46
clang::XRayInstrKind::None
constexpr XRayInstrMask None
Definition: XRayInstr.h:38
clang::targets::WebAssembly32TargetInfo
Definition: WebAssembly.h:147
clang::CallingConv
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:263
clang::TargetInfo::getLeastIntTypeByWidth
virtual IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const
Return the smallest integer type with at least the specified width.
Definition: TargetInfo.cpp:267
clang::targets::WebAssembly64TargetInfo
Definition: WebAssembly.h:164
clang::targets::WebAssembly32TargetInfo::WebAssembly32TargetInfo
WebAssembly32TargetInfo(const llvm::Triple &T, const TargetOptions &Opts)
Definition: WebAssembly.h:150
clang::CC_C
@ CC_C
Definition: Specifiers.h:264
TargetOptions.h
llvm::ArrayRef
Definition: LLVM.h:34
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:58
clang::TargetInfo::getIntTypeByWidth
virtual IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const
Return integer type with specified width.
Definition: TargetInfo.cpp:252
clang
Definition: CalledOnceCheck.h:17
clang::Builtin::Info
Definition: Builtins.h:55
clang::CC_SwiftAsync
@ CC_SwiftAsync
Definition: Specifiers.h:279
clang::prec::Level
Level
Definition: OperatorPrecedence.h:26
clang::TargetOptions
Options for controlling the target.
Definition: TargetOptions.h:26
llvm::SmallVectorImpl
Definition: LLVM.h:39
clang::MacroBuilder
Definition: MacroBuilder.h:23
hasFeature
static bool hasFeature(StringRef Feature, const LangOptions &LangOpts, const TargetInfo &Target)
Determine whether a translation unit built using the current language options has the given feature.
Definition: Module.cpp:101