Coverage Report

Created: 2021-09-21 08:58

/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
  } SIMDLevel = NoSIMD;
31
32
  bool HasNontrappingFPToInt = false;
33
  bool HasSignExt = false;
34
  bool HasExceptionHandling = false;
35
  bool HasBulkMemory = false;
36
  bool HasAtomics = false;
37
  bool HasMutableGlobals = false;
38
  bool HasMultivalue = false;
39
  bool HasTailCall = false;
40
  bool HasReferenceTypes = false;
41
42
  std::string ABI;
43
44
public:
45
  explicit WebAssemblyTargetInfo(const llvm::Triple &T, const TargetOptions &)
46
96
      : TargetInfo(T) {
47
96
    NoAsmVariants = true;
48
96
    SuitableAlign = 128;
49
96
    LargeArrayMinWidth = 128;
50
96
    LargeArrayAlign = 128;
51
96
    SimdDefaultAlign = 128;
52
96
    SigAtomicType = SignedLong;
53
96
    LongDoubleWidth = LongDoubleAlign = 128;
54
96
    LongDoubleFormat = &llvm::APFloat::IEEEquad();
55
96
    MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
56
    // size_t being unsigned long for both wasm32 and wasm64 makes mangled names
57
    // more consistent between the two.
58
96
    SizeType = UnsignedLong;
59
96
    PtrDiffType = SignedLong;
60
96
    IntPtrType = SignedLong;
61
96
  }
62
63
  StringRef getABI() const override;
64
  bool setABI(const std::string &Name) override;
65
66
protected:
67
  void getTargetDefines(const LangOptions &Opts,
68
                        MacroBuilder &Builder) const override;
69
70
private:
71
  static void setSIMDLevel(llvm::StringMap<bool> &Features, SIMDEnum Level,
72
                           bool Enabled);
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
  void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name,
81
                         bool Enabled) const final;
82
83
  bool handleTargetFeatures(std::vector<std::string> &Features,
84
                            DiagnosticsEngine &Diags) final;
85
86
  bool isValidCPUName(StringRef Name) const final;
87
  void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const final;
88
89
35
  bool setCPU(const std::string &Name) final { return isValidCPUName(Name); }
90
91
  ArrayRef<Builtin::Info> getTargetBuiltins() const final;
92
93
57
  BuiltinVaListKind getBuiltinVaListKind() const final {
94
57
    return VoidPtrBuiltinVaList;
95
57
  }
96
97
0
  ArrayRef<const char *> getGCCRegNames() const final { return None; }
98
99
0
  ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const final {
100
0
    return None;
101
0
  }
102
103
  bool validateAsmConstraint(const char *&Name,
104
0
                             TargetInfo::ConstraintInfo &Info) const final {
105
0
    return false;
106
0
  }
107
108
0
  const char *getClobbers() const final { return ""; }
109
110
0
  bool isCLZForZeroUndef() const final { return false; }
111
112
275
  bool hasInt128Type() const final { return true; }
113
114
0
  IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
115
    // WebAssembly prefers long long for explicitly 64-bit integers.
116
0
    return BitWidth == 64 ? (IsSigned ? SignedLongLong : UnsignedLongLong)
117
0
                          : TargetInfo::getIntTypeByWidth(BitWidth, IsSigned);
118
0
  }
119
120
1.50k
  IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
121
    // WebAssembly uses long long for int_least64_t and int_fast64_t.
122
1.50k
    return BitWidth == 64
123
1.50k
               ? 
(376
IsSigned376
?
SignedLongLong188
:
UnsignedLongLong188
)
124
1.50k
               : 
TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned)1.12k
;
125
1.50k
  }
126
127
8
  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
128
8
    switch (CC) {
129
0
    case CC_C:
130
0
    case CC_Swift:
131
0
      return CCCR_OK;
132
8
    case CC_SwiftAsync:
133
8
      return CCCR_Error;
134
0
    default:
135
0
      return CCCR_Warning;
136
8
    }
137
8
  }
138
139
30
  bool hasExtIntType() const override { return true; }
140
141
0
  bool hasProtectedVisibility() const override { return false; }
142
143
  void adjust(DiagnosticsEngine &Diags, LangOptions &Opts) override;
144
};
145
146
class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo
147
    : public WebAssemblyTargetInfo {
148
public:
149
  explicit WebAssembly32TargetInfo(const llvm::Triple &T,
150
                                   const TargetOptions &Opts)
151
64
      : WebAssemblyTargetInfo(T, Opts) {
152
64
    if (T.isOSEmscripten())
153
4
      resetDataLayout("e-m:e-p:32:32-i64:64-f128:64-n32:64-S128-ni:1:10:20");
154
60
    else
155
60
      resetDataLayout("e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20");
156
64
  }
157
158
protected:
159
  void getTargetDefines(const LangOptions &Opts,
160
                        MacroBuilder &Builder) const override;
161
};
162
163
class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo
164
    : public WebAssemblyTargetInfo {
165
public:
166
  explicit WebAssembly64TargetInfo(const llvm::Triple &T,
167
                                   const TargetOptions &Opts)
168
32
      : WebAssemblyTargetInfo(T, Opts) {
169
32
    LongAlign = LongWidth = 64;
170
32
    PointerAlign = PointerWidth = 64;
171
32
    SizeType = UnsignedLong;
172
32
    PtrDiffType = SignedLong;
173
32
    IntPtrType = SignedLong;
174
32
    if (T.isOSEmscripten())
175
1
      resetDataLayout("e-m:e-p:64:64-i64:64-f128:64-n32:64-S128-ni:1:10:20");
176
31
    else
177
31
      resetDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128-ni:1:10:20");
178
32
  }
179
180
protected:
181
  void getTargetDefines(const LangOptions &Opts,
182
                        MacroBuilder &Builder) const override;
183
};
184
} // namespace targets
185
} // namespace clang
186
#endif // LLVM_CLANG_LIB_BASIC_TARGETS_WEBASSEMBLY_H