clang  7.0.0svn
WebAssembly.h
Go to the documentation of this file.
1 //=== 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"
19 #include "llvm/ADT/Triple.h"
20 #include "llvm/Support/Compiler.h"
21 
22 namespace clang {
23 namespace targets {
24 
25 class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {
26  static const Builtin::Info BuiltinInfo[];
27 
28  enum SIMDEnum {
29  NoSIMD,
30  SIMD128,
31  } SIMDLevel;
32 
33  bool HasNontrappingFPToInt;
34  bool HasSignExt;
35  bool HasExceptionHandling;
36 
37 public:
38  explicit WebAssemblyTargetInfo(const llvm::Triple &T, const TargetOptions &)
39  : TargetInfo(T), SIMDLevel(NoSIMD), HasNontrappingFPToInt(false),
40  HasSignExt(false), HasExceptionHandling(false) {
41  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();
49  MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
50  SizeType = UnsignedInt;
51  PtrDiffType = SignedInt;
52  IntPtrType = SignedInt;
53  }
54 
55 protected:
56  void getTargetDefines(const LangOptions &Opts,
57  MacroBuilder &Builder) const override;
58 
59 private:
60  bool
61  initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
62  StringRef CPU,
63  const std::vector<std::string> &FeaturesVec) const override {
64  if (CPU == "bleeding-edge") {
65  Features["simd128"] = true;
66  Features["nontrapping-fptoint"] = true;
67  Features["sign-ext"] = true;
68  }
69  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;
78  void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const final;
79 
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 };
118 class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo
119  : public WebAssemblyTargetInfo {
120 public:
121  explicit WebAssembly32TargetInfo(const llvm::Triple &T,
122  const TargetOptions &Opts)
123  : WebAssemblyTargetInfo(T, Opts) {
124  resetDataLayout("e-m:e-p:32:32-i64:64-n32:64-S128");
125  }
126 
127 protected:
128  void getTargetDefines(const LangOptions &Opts,
129  MacroBuilder &Builder) const override;
130 };
131 
132 class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo
133  : public WebAssemblyTargetInfo {
134 public:
135  explicit WebAssembly64TargetInfo(const llvm::Triple &T,
136  const TargetOptions &Opts)
137  : WebAssemblyTargetInfo(T, Opts) {
138  LongAlign = LongWidth = 64;
139  PointerAlign = PointerWidth = 64;
140  SizeType = UnsignedLong;
141  PtrDiffType = SignedLong;
142  IntPtrType = SignedLong;
143  resetDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128");
144  }
145 
146 protected:
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
static const Builtin::Info BuiltinInfo[]
Definition: Builtins.cpp:21
virtual IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const
Return the smallest integer type with at least the specified width.
Definition: TargetInfo.cpp:243
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:76
Options for controlling the target.
Definition: TargetOptions.h:26
WebAssembly64TargetInfo(const llvm::Triple &T, const TargetOptions &Opts)
Definition: WebAssembly.h:135
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:50
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:149
WebAssemblyTargetInfo(const llvm::Triple &T, const TargetOptions &)
Definition: WebAssembly.h:38
Exposes information about the current target.
Definition: TargetInfo.h:54
virtual bool initFeatureMap(llvm::StringMap< bool > &Features, DiagnosticsEngine &Diags, StringRef CPU, const std::vector< std::string > &FeatureVec) const
Initialize the map with the default set of target features for the CPU this should include all legal ...
Definition: TargetInfo.cpp:384
#define false
Definition: stdbool.h:33
Defines the clang::TargetOptions class.
IntType
===-— Target Data Type Query Methods ----------------------------—===//
Definition: TargetInfo.h:157
Dataflow Directional Tag Classes.
virtual IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const
Return integer type with specified width.
Definition: TargetInfo.cpp:228
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition: TargetInfo.h:181
WebAssembly32TargetInfo(const llvm::Triple &T, const TargetOptions &Opts)
Definition: WebAssembly.h:121
Defines the clang::TargetInfo interface.