WebAssembly.h revision 326941
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" 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 33 bool HasNontrappingFPToInt; 34 35public: 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 51protected: 52 void getTargetDefines(const LangOptions &Opts, 53 MacroBuilder &Builder) const override; 54 55private: 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}; 112class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo 113 : public WebAssemblyTargetInfo { 114public: 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 122protected: 123 void getTargetDefines(const LangOptions &Opts, 124 MacroBuilder &Builder) const override; 125}; 126 127class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo 128 : public WebAssemblyTargetInfo { 129public: 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 142protected: 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 149