Coverage Report

Created: 2020-02-25 14:32

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Basic/Targets/WebAssembly.h
Line
Count
Source (jump to first uncovered line)
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"
17
#include "clang/Basic/TargetOptions.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
    UnimplementedSIMD128,
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
72
      : TargetInfo(T) {
48
72
    NoAsmVariants = true;
49
72
    SuitableAlign = 128;
50
72
    LargeArrayMinWidth = 128;
51
72
    LargeArrayAlign = 128;
52
72
    SimdDefaultAlign = 128;
53
72
    SigAtomicType = SignedLong;
54
72
    LongDoubleWidth = LongDoubleAlign = 128;
55
72
    LongDoubleFormat = &llvm::APFloat::IEEEquad();
56
72
    MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
57
72
    // size_t being unsigned long for both wasm32 and wasm64 makes mangled names
58
72
    // more consistent between the two.
59
72
    SizeType = UnsignedLong;
60
72
    PtrDiffType = SignedLong;
61
72
    IntPtrType = SignedLong;
62
72
  }
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
74
  bool
75
  initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
76
                 StringRef CPU,
77
                 const std::vector<std::string> &FeaturesVec) const override;
78
  bool hasFeature(StringRef Feature) const final;
79
80
  bool handleTargetFeatures(std::vector<std::string> &Features,
81
                            DiagnosticsEngine &Diags) final;
82
83
  bool isValidCPUName(StringRef Name) const final;
84
  void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const final;
85
86
35
  bool setCPU(const std::string &Name) final { return isValidCPUName(Name); }
87
88
  ArrayRef<Builtin::Info> getTargetBuiltins() const final;
89
90
37
  BuiltinVaListKind getBuiltinVaListKind() const final {
91
37
    return VoidPtrBuiltinVaList;
92
37
  }
93
94
0
  ArrayRef<const char *> getGCCRegNames() const final { return None; }
95
96
0
  ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const final {
97
0
    return None;
98
0
  }
99
100
  bool validateAsmConstraint(const char *&Name,
101
0
                             TargetInfo::ConstraintInfo &Info) const final {
102
0
    return false;
103
0
  }
104
105
0
  const char *getClobbers() const final { return ""; }
106
107
0
  bool isCLZForZeroUndef() const final { return false; }
108
109
179
  bool hasInt128Type() const final { return true; }
110
111
0
  IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
112
0
    // WebAssembly prefers long long for explicitly 64-bit integers.
113
0
    return BitWidth == 64 ? (IsSigned ? SignedLongLong : UnsignedLongLong)
114
0
                          : TargetInfo::getIntTypeByWidth(BitWidth, IsSigned);
115
0
  }
116
117
1.13k
  IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
118
1.13k
    // WebAssembly uses long long for int_least64_t and int_fast64_t.
119
1.13k
    return BitWidth == 64
120
1.13k
               ? 
(IsSigned 284
?
SignedLongLong142
:
UnsignedLongLong142
)
121
1.13k
               : 
TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned)852
;
122
1.13k
  }
123
124
0
  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
125
0
    switch (CC) {
126
0
    case CC_C:
127
0
    case CC_Swift:
128
0
      return CCCR_OK;
129
0
    default:
130
0
      return CCCR_Warning;
131
0
    }
132
0
  }
133
};
134
class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo
135
    : public WebAssemblyTargetInfo {
136
public:
137
  explicit WebAssembly32TargetInfo(const llvm::Triple &T,
138
                                   const TargetOptions &Opts)
139
41
      : WebAssemblyTargetInfo(T, Opts) {
140
41
    resetDataLayout("e-m:e-p:32:32-i64:64-n32:64-S128");
141
41
  }
142
143
protected:
144
  void getTargetDefines(const LangOptions &Opts,
145
                        MacroBuilder &Builder) const override;
146
};
147
148
class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo
149
    : public WebAssemblyTargetInfo {
150
public:
151
  explicit WebAssembly64TargetInfo(const llvm::Triple &T,
152
                                   const TargetOptions &Opts)
153
31
      : WebAssemblyTargetInfo(T, Opts) {
154
31
    LongAlign = LongWidth = 64;
155
31
    PointerAlign = PointerWidth = 64;
156
31
    SizeType = UnsignedLong;
157
31
    PtrDiffType = SignedLong;
158
31
    IntPtrType = SignedLong;
159
31
    resetDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128");
160
31
  }
161
162
protected:
163
  void getTargetDefines(const LangOptions &Opts,
164
                        MacroBuilder &Builder) const override;
165
};
166
} // namespace targets
167
} // namespace clang
168
#endif // LLVM_CLANG_LIB_BASIC_TARGETS_WEBASSEMBLY_H