Coverage Report

Created: 2022-01-25 06:29

/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
    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
105
      : TargetInfo(T) {
48
105
    NoAsmVariants = true;
49
105
    SuitableAlign = 128;
50
105
    LargeArrayMinWidth = 128;
51
105
    LargeArrayAlign = 128;
52
105
    SimdDefaultAlign = 128;
53
105
    SigAtomicType = SignedLong;
54
105
    LongDoubleWidth = LongDoubleAlign = 128;
55
105
    LongDoubleFormat = &llvm::APFloat::IEEEquad();
56
105
    MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
57
    // size_t being unsigned long for both wasm32 and wasm64 makes mangled names
58
    // more consistent between the two.
59
105
    SizeType = UnsignedLong;
60
105
    PtrDiffType = SignedLong;
61
105
    IntPtrType = SignedLong;
62
105
  }
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
53
  bool setCPU(const std::string &Name) final { return isValidCPUName(Name); }
91
92
  ArrayRef<Builtin::Info> getTargetBuiltins() const final;
93
94
65
  BuiltinVaListKind getBuiltinVaListKind() const final {
95
65
    return VoidPtrBuiltinVaList;
96
65
  }
97
98
0
  ArrayRef<const char *> getGCCRegNames() const final { return None; }
99
100
0
  ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const final {
101
0
    return None;
102
0
  }
103
104
  bool validateAsmConstraint(const char *&Name,
105
0
                             TargetInfo::ConstraintInfo &Info) const final {
106
0
    return false;
107
0
  }
108
109
0
  const char *getClobbers() const final { return ""; }
110
111
0
  bool isCLZForZeroUndef() const final { return false; }
112
113
303
  bool hasInt128Type() const final { return true; }
114
115
20
  IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
116
    // WebAssembly prefers long long for explicitly 64-bit integers.
117
20
    return BitWidth == 64 ? 
(4
IsSigned4
?
SignedLongLong0
:
UnsignedLongLong4
)
118
20
                          : 
TargetInfo::getIntTypeByWidth(BitWidth, IsSigned)16
;
119
20
  }
120
121
1.66k
  IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
122
    // WebAssembly uses long long for int_least64_t and int_fast64_t.
123
1.66k
    return BitWidth == 64
124
1.66k
               ? 
(416
IsSigned416
?
SignedLongLong208
:
UnsignedLongLong208
)
125
1.66k
               : 
TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned)1.24k
;
126
1.66k
  }
127
128
8
  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
129
8
    switch (CC) {
130
0
    case CC_C:
131
0
    case CC_Swift:
132
0
      return CCCR_OK;
133
8
    case CC_SwiftAsync:
134
8
      return CCCR_Error;
135
0
    default:
136
0
      return CCCR_Warning;
137
8
    }
138
8
  }
139
140
30
  bool hasBitIntType() const override { return true; }
141
142
0
  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
64
      : WebAssemblyTargetInfo(T, Opts) {
153
64
    if (T.isOSEmscripten())
154
4
      resetDataLayout("e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-"
155
4
                      "S128-ni:1:10:20");
156
60
    else
157
60
      resetDataLayout(
158
60
          "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20");
159
64
  }
160
161
protected:
162
  void getTargetDefines(const LangOptions &Opts,
163
                        MacroBuilder &Builder) const override;
164
};
165
166
class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo
167
    : public WebAssemblyTargetInfo {
168
public:
169
  explicit WebAssembly64TargetInfo(const llvm::Triple &T,
170
                                   const TargetOptions &Opts)
171
41
      : WebAssemblyTargetInfo(T, Opts) {
172
41
    LongAlign = LongWidth = 64;
173
41
    PointerAlign = PointerWidth = 64;
174
41
    SizeType = UnsignedLong;
175
41
    PtrDiffType = SignedLong;
176
41
    IntPtrType = SignedLong;
177
41
    if (T.isOSEmscripten())
178
1
      resetDataLayout("e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-"
179
1
                      "S128-ni:1:10:20");
180
40
    else
181
40
      resetDataLayout(
182
40
          "e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20");
183
41
  }
184
185
protected:
186
  void getTargetDefines(const LangOptions &Opts,
187
                        MacroBuilder &Builder) const override;
188
};
189
} // namespace targets
190
} // namespace clang
191
#endif // LLVM_CLANG_LIB_BASIC_TARGETS_WEBASSEMBLY_H