clang  6.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 
35 public:
36  explicit WebAssemblyTargetInfo(const llvm::Triple &T, const TargetOptions &)
37  : TargetInfo(T), SIMDLevel(NoSIMD), HasNontrappingFPToInt(false) {
38  NoAsmVariants = true;
39  SuitableAlign = 128;
40  LargeArrayMinWidth = 128;
41  LargeArrayAlign = 128;
42  SimdDefaultAlign = 128;
43  SigAtomicType = SignedLong;
44  LongDoubleWidth = LongDoubleAlign = 128;
45  LongDoubleFormat = &llvm::APFloat::IEEEquad();
46  SizeType = UnsignedInt;
47  PtrDiffType = SignedInt;
48  IntPtrType = SignedInt;
49  }
50 
51 protected:
52  void getTargetDefines(const LangOptions &Opts,
53  MacroBuilder &Builder) const override;
54 
55 private:
56  bool
57  initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
58  StringRef CPU,
59  const std::vector<std::string> &FeaturesVec) const override {
60  if (CPU == "bleeding-edge") {
61  Features["simd128"] = true;
62  Features["nontrapping-fptoint"] = true;
63  }
64  return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
65  }
66 
67  bool hasFeature(StringRef Feature) const final;
68 
69  bool handleTargetFeatures(std::vector<std::string> &Features,
70  DiagnosticsEngine &Diags) final;
71 
72  bool isValidCPUName(StringRef Name) const final;
73 
74  bool setCPU(const std::string &Name) final { return isValidCPUName(Name); }
75 
76  ArrayRef<Builtin::Info> getTargetBuiltins() const final;
77 
78  BuiltinVaListKind getBuiltinVaListKind() const final {
79  return VoidPtrBuiltinVaList;
80  }
81 
82  ArrayRef<const char *> getGCCRegNames() const final { return None; }
83 
84  ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const final {
85  return None;
86  }
87 
88  bool validateAsmConstraint(const char *&Name,
89  TargetInfo::ConstraintInfo &Info) const final {
90  return false;
91  }
92 
93  const char *getClobbers() const final { return ""; }
94 
95  bool isCLZForZeroUndef() const final { return false; }
96 
97  bool hasInt128Type() const final { return true; }
98 
99  IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
100  // WebAssembly prefers long long for explicitly 64-bit integers.
101  return BitWidth == 64 ? (IsSigned ? SignedLongLong : UnsignedLongLong)
102  : TargetInfo::getIntTypeByWidth(BitWidth, IsSigned);
103  }
104 
105  IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
106  // WebAssembly uses long long for int_least64_t and int_fast64_t.
107  return BitWidth == 64
108  ? (IsSigned ? SignedLongLong : UnsignedLongLong)
109  : TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned);
110  }
111 };
112 class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo
113  : public WebAssemblyTargetInfo {
114 public:
115  explicit WebAssembly32TargetInfo(const llvm::Triple &T,
116  const TargetOptions &Opts)
117  : WebAssemblyTargetInfo(T, Opts) {
118  MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
119  resetDataLayout("e-m:e-p:32:32-i64:64-n32:64-S128");
120  }
121 
122 protected:
123  void getTargetDefines(const LangOptions &Opts,
124  MacroBuilder &Builder) const override;
125 };
126 
127 class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo
128  : public WebAssemblyTargetInfo {
129 public:
130  explicit WebAssembly64TargetInfo(const llvm::Triple &T,
131  const TargetOptions &Opts)
132  : WebAssemblyTargetInfo(T, Opts) {
133  LongAlign = LongWidth = 64;
134  PointerAlign = PointerWidth = 64;
135  MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
136  SizeType = UnsignedLong;
137  PtrDiffType = SignedLong;
138  IntPtrType = SignedLong;
139  resetDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128");
140  }
141 
142 protected:
143  void getTargetDefines(const LangOptions &Opts,
144  MacroBuilder &Builder) const override;
145 };
146 } // namespace targets
147 } // namespace clang
148 #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:211
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:73
Options for controlling the target.
Definition: TargetOptions.h:26
WebAssembly64TargetInfo(const llvm::Triple &T, const TargetOptions &Opts)
Definition: WebAssembly.h:130
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:147
WebAssemblyTargetInfo(const llvm::Triple &T, const TargetOptions &)
Definition: WebAssembly.h:36
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:347
const FunctionProtoType * T
#define false
Definition: stdbool.h:33
Defines the clang::TargetOptions class.
IntType
===-— Target Data Type Query Methods ----------------------------—===//
Definition: TargetInfo.h:128
Dataflow Directional Tag Classes.
virtual IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const
Return integer type with specified width.
Definition: TargetInfo.cpp:196
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition: TargetInfo.h:152
WebAssembly32TargetInfo(const llvm::Triple &T, const TargetOptions &Opts)
Definition: WebAssembly.h:115
Defines the clang::TargetInfo interface.