Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/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
42
public:
43
  explicit WebAssemblyTargetInfo(const llvm::Triple &T, const TargetOptions &)
44
66
      : TargetInfo(T) {
45
66
    NoAsmVariants = true;
46
66
    SuitableAlign = 128;
47
66
    LargeArrayMinWidth = 128;
48
66
    LargeArrayAlign = 128;
49
66
    SimdDefaultAlign = 128;
50
66
    SigAtomicType = SignedLong;
51
66
    LongDoubleWidth = LongDoubleAlign = 128;
52
66
    LongDoubleFormat = &llvm::APFloat::IEEEquad();
53
66
    MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
54
66
    // size_t being unsigned long for both wasm32 and wasm64 makes mangled names
55
66
    // more consistent between the two.
56
66
    SizeType = UnsignedLong;
57
66
    PtrDiffType = SignedLong;
58
66
    IntPtrType = SignedLong;
59
66
  }
60
61
protected:
62
  void getTargetDefines(const LangOptions &Opts,
63
                        MacroBuilder &Builder) const override;
64
65
private:
66
  static void setSIMDLevel(llvm::StringMap<bool> &Features, SIMDEnum Level);
67
68
  bool
69
  initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
70
                 StringRef CPU,
71
                 const std::vector<std::string> &FeaturesVec) const override;
72
  bool hasFeature(StringRef Feature) const final;
73
74
  bool handleTargetFeatures(std::vector<std::string> &Features,
75
                            DiagnosticsEngine &Diags) final;
76
77
  bool isValidCPUName(StringRef Name) const final;
78
  void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const final;
79
80
33
  bool setCPU(const std::string &Name) final { return isValidCPUName(Name); }
81
82
  ArrayRef<Builtin::Info> getTargetBuiltins() const final;
83
84
33
  BuiltinVaListKind getBuiltinVaListKind() const final {
85
33
    return VoidPtrBuiltinVaList;
86
33
  }
87
88
0
  ArrayRef<const char *> getGCCRegNames() const final { return None; }
89
90
0
  ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const final {
91
0
    return None;
92
0
  }
93
94
  bool validateAsmConstraint(const char *&Name,
95
0
                             TargetInfo::ConstraintInfo &Info) const final {
96
0
    return false;
97
0
  }
98
99
0
  const char *getClobbers() const final { return ""; }
100
101
0
  bool isCLZForZeroUndef() const final { return false; }
102
103
163
  bool hasInt128Type() const final { return true; }
104
105
0
  IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
106
0
    // WebAssembly prefers long long for explicitly 64-bit integers.
107
0
    return BitWidth == 64 ? (IsSigned ? SignedLongLong : UnsignedLongLong)
108
0
                          : TargetInfo::getIntTypeByWidth(BitWidth, IsSigned);
109
0
  }
110
111
1.04k
  IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
112
1.04k
    // WebAssembly uses long long for int_least64_t and int_fast64_t.
113
1.04k
    return BitWidth == 64
114
1.04k
               ? 
(IsSigned 260
?
SignedLongLong130
:
UnsignedLongLong130
)
115
1.04k
               : 
TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned)780
;
116
1.04k
  }
117
};
118
class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo
119
    : public WebAssemblyTargetInfo {
120
public:
121
  explicit WebAssembly32TargetInfo(const llvm::Triple &T,
122
                                   const TargetOptions &Opts)
123
36
      : WebAssemblyTargetInfo(T, Opts) {
124
36
    resetDataLayout("e-m:e-p:32:32-i64:64-n32:64-S128");
125
36
  }
126
127
protected:
128
  void getTargetDefines(const LangOptions &Opts,
129
                        MacroBuilder &Builder) const override;
130
};
131
132
class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo
133
    : public WebAssemblyTargetInfo {
134
public:
135
  explicit WebAssembly64TargetInfo(const llvm::Triple &T,
136
                                   const TargetOptions &Opts)
137
30
      : WebAssemblyTargetInfo(T, Opts) {
138
30
    LongAlign = LongWidth = 64;
139
30
    PointerAlign = PointerWidth = 64;
140
30
    SizeType = UnsignedLong;
141
30
    PtrDiffType = SignedLong;
142
30
    IntPtrType = SignedLong;
143
30
    resetDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128");
144
30
  }
145
146
protected:
147
  void getTargetDefines(const LangOptions &Opts,
148
                        MacroBuilder &Builder) const override;
149
};
150
} // namespace targets
151
} // namespace clang
152
#endif // LLVM_CLANG_LIB_BASIC_TARGETS_WEBASSEMBLY_H