Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/lib/Basic/Targets/Sparc.h
Line
Count
Source (jump to first uncovered line)
1
//===--- Sparc.h - declare sparc 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 Sparc TargetInfo objects.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_SPARC_H
14
#define LLVM_CLANG_LIB_BASIC_TARGETS_SPARC_H
15
#include "clang/Basic/TargetInfo.h"
16
#include "clang/Basic/TargetOptions.h"
17
#include "llvm/ADT/Triple.h"
18
#include "llvm/Support/Compiler.h"
19
namespace clang {
20
namespace targets {
21
// Shared base class for SPARC v8 (32-bit) and SPARC v9 (64-bit).
22
class LLVM_LIBRARY_VISIBILITY SparcTargetInfo : public TargetInfo {
23
  static const TargetInfo::GCCRegAlias GCCRegAliases[];
24
  static const char *const GCCRegNames[];
25
  bool SoftFloat;
26
27
public:
28
  SparcTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
29
63
      : TargetInfo(Triple), SoftFloat(false) {}
30
31
8
  int getEHDataRegisterNumber(unsigned RegNo) const override {
32
8
    if (RegNo == 0)
33
4
      return 24;
34
4
    if (RegNo == 1)
35
4
      return 25;
36
0
    return -1;
37
0
  }
38
39
  bool handleTargetFeatures(std::vector<std::string> &Features,
40
53
                            DiagnosticsEngine &Diags) override {
41
53
    // Check if software floating point is enabled
42
53
    auto Feature = llvm::find(Features, "+soft-float");
43
53
    if (Feature != Features.end()) {
44
1
      SoftFloat = true;
45
1
    }
46
53
    return true;
47
53
  }
48
  void getTargetDefines(const LangOptions &Opts,
49
                        MacroBuilder &Builder) const override;
50
51
  bool hasFeature(StringRef Feature) const override;
52
53
0
  bool hasSjLjLowering() const override { return true; }
54
55
53
  ArrayRef<Builtin::Info> getTargetBuiltins() const override {
56
53
    // FIXME: Implement!
57
53
    return None;
58
53
  }
59
23
  BuiltinVaListKind getBuiltinVaListKind() const override {
60
23
    return TargetInfo::VoidPtrBuiltinVaList;
61
23
  }
62
  ArrayRef<const char *> getGCCRegNames() const override;
63
  ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
64
  bool validateAsmConstraint(const char *&Name,
65
40
                             TargetInfo::ConstraintInfo &info) const override {
66
40
    // FIXME: Implement!
67
40
    switch (*Name) {
68
40
    case 'I': // Signed 13-bit constant
69
0
    case 'J': // Zero
70
0
    case 'K': // 32-bit constant with the low 12 bits clear
71
0
    case 'L': // A constant in the range supported by movcc (11-bit signed imm)
72
0
    case 'M': // A constant in the range supported by movrcc (19-bit signed imm)
73
0
    case 'N': // Same as 'K' but zext (required for SIMode)
74
0
    case 'O': // The constant 4096
75
0
      return true;
76
0
77
40
    case 'f':
78
40
    case 'e':
79
40
      info.setAllowsRegister();
80
40
      return true;
81
0
    }
82
0
    return false;
83
0
  }
84
91
  const char *getClobbers() const override {
85
91
    // FIXME: Implement!
86
91
    return "";
87
91
  }
88
89
  // No Sparc V7 for now, the backend doesn't support it anyway.
90
  enum CPUKind {
91
    CK_GENERIC,
92
    CK_V8,
93
    CK_SUPERSPARC,
94
    CK_SPARCLITE,
95
    CK_F934,
96
    CK_HYPERSPARC,
97
    CK_SPARCLITE86X,
98
    CK_SPARCLET,
99
    CK_TSC701,
100
    CK_V9,
101
    CK_ULTRASPARC,
102
    CK_ULTRASPARC3,
103
    CK_NIAGARA,
104
    CK_NIAGARA2,
105
    CK_NIAGARA3,
106
    CK_NIAGARA4,
107
    CK_MYRIAD2100,
108
    CK_MYRIAD2150,
109
    CK_MYRIAD2155,
110
    CK_MYRIAD2450,
111
    CK_MYRIAD2455,
112
    CK_MYRIAD2x5x,
113
    CK_MYRIAD2080,
114
    CK_MYRIAD2085,
115
    CK_MYRIAD2480,
116
    CK_MYRIAD2485,
117
    CK_MYRIAD2x8x,
118
    CK_LEON2,
119
    CK_LEON2_AT697E,
120
    CK_LEON2_AT697F,
121
    CK_LEON3,
122
    CK_LEON3_UT699,
123
    CK_LEON3_GR712RC,
124
    CK_LEON4,
125
    CK_LEON4_GR740
126
  } CPU = CK_GENERIC;
127
128
  enum CPUGeneration {
129
    CG_V8,
130
    CG_V9,
131
  };
132
133
  CPUGeneration getCPUGeneration(CPUKind Kind) const;
134
135
  CPUKind getCPUKind(StringRef Name) const;
136
137
0
  bool isValidCPUName(StringRef Name) const override {
138
0
    return getCPUKind(Name) != CK_GENERIC;
139
0
  }
140
141
  void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
142
143
26
  bool setCPU(const std::string &Name) override {
144
26
    CPU = getCPUKind(Name);
145
26
    return CPU != CK_GENERIC;
146
26
  }
147
};
148
149
// SPARC v8 is the 32-bit mode selected by Triple::sparc.
150
class LLVM_LIBRARY_VISIBILITY SparcV8TargetInfo : public SparcTargetInfo {
151
public:
152
  SparcV8TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
153
41
      : SparcTargetInfo(Triple, Opts) {
154
41
    resetDataLayout("E-m:e-p:32:32-i64:64-f128:64-n32-S64");
155
41
    // NetBSD / OpenBSD use long (same as llvm default); everyone else uses int.
156
41
    switch (getTriple().getOS()) {
157
41
    default:
158
37
      SizeType = UnsignedInt;
159
37
      IntPtrType = SignedInt;
160
37
      PtrDiffType = SignedInt;
161
37
      break;
162
41
    case llvm::Triple::NetBSD:
163
4
    case llvm::Triple::OpenBSD:
164
4
      SizeType = UnsignedLong;
165
4
      IntPtrType = SignedLong;
166
4
      PtrDiffType = SignedLong;
167
4
      break;
168
41
    }
169
41
    // Up to 32 bits are lock-free atomic, but we're willing to do atomic ops
170
41
    // on up to 64 bits.
171
41
    MaxAtomicPromoteWidth = 64;
172
41
    MaxAtomicInlineWidth = 32;
173
41
  }
clang::targets::SparcV8TargetInfo::SparcV8TargetInfo(llvm::Triple const&, clang::TargetOptions const&)
Line
Count
Source
153
15
      : SparcTargetInfo(Triple, Opts) {
154
15
    resetDataLayout("E-m:e-p:32:32-i64:64-f128:64-n32-S64");
155
15
    // NetBSD / OpenBSD use long (same as llvm default); everyone else uses int.
156
15
    switch (getTriple().getOS()) {
157
15
    default:
158
15
      SizeType = UnsignedInt;
159
15
      IntPtrType = SignedInt;
160
15
      PtrDiffType = SignedInt;
161
15
      break;
162
15
    case llvm::Triple::NetBSD:
163
0
    case llvm::Triple::OpenBSD:
164
0
      SizeType = UnsignedLong;
165
0
      IntPtrType = SignedLong;
166
0
      PtrDiffType = SignedLong;
167
0
      break;
168
15
    }
169
15
    // Up to 32 bits are lock-free atomic, but we're willing to do atomic ops
170
15
    // on up to 64 bits.
171
15
    MaxAtomicPromoteWidth = 64;
172
15
    MaxAtomicInlineWidth = 32;
173
15
  }
clang::targets::SparcV8TargetInfo::SparcV8TargetInfo(llvm::Triple const&, clang::TargetOptions const&)
Line
Count
Source
153
26
      : SparcTargetInfo(Triple, Opts) {
154
26
    resetDataLayout("E-m:e-p:32:32-i64:64-f128:64-n32-S64");
155
26
    // NetBSD / OpenBSD use long (same as llvm default); everyone else uses int.
156
26
    switch (getTriple().getOS()) {
157
26
    default:
158
22
      SizeType = UnsignedInt;
159
22
      IntPtrType = SignedInt;
160
22
      PtrDiffType = SignedInt;
161
22
      break;
162
26
    case llvm::Triple::NetBSD:
163
4
    case llvm::Triple::OpenBSD:
164
4
      SizeType = UnsignedLong;
165
4
      IntPtrType = SignedLong;
166
4
      PtrDiffType = SignedLong;
167
4
      break;
168
26
    }
169
26
    // Up to 32 bits are lock-free atomic, but we're willing to do atomic ops
170
26
    // on up to 64 bits.
171
26
    MaxAtomicPromoteWidth = 64;
172
26
    MaxAtomicInlineWidth = 32;
173
26
  }
174
175
  void getTargetDefines(const LangOptions &Opts,
176
                        MacroBuilder &Builder) const override;
177
178
2
  bool hasSjLjLowering() const override { return true; }
179
};
180
181
// SPARCV8el is the 32-bit little-endian mode selected by Triple::sparcel.
182
class LLVM_LIBRARY_VISIBILITY SparcV8elTargetInfo : public SparcV8TargetInfo {
183
public:
184
  SparcV8elTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
185
16
      : SparcV8TargetInfo(Triple, Opts) {
186
16
    resetDataLayout("e-m:e-p:32:32-i64:64-f128:64-n32-S64");
187
16
  }
clang::targets::SparcV8elTargetInfo::SparcV8elTargetInfo(llvm::Triple const&, clang::TargetOptions const&)
Line
Count
Source
185
15
      : SparcV8TargetInfo(Triple, Opts) {
186
15
    resetDataLayout("e-m:e-p:32:32-i64:64-f128:64-n32-S64");
187
15
  }
clang::targets::SparcV8elTargetInfo::SparcV8elTargetInfo(llvm::Triple const&, clang::TargetOptions const&)
Line
Count
Source
185
1
      : SparcV8TargetInfo(Triple, Opts) {
186
1
    resetDataLayout("e-m:e-p:32:32-i64:64-f128:64-n32-S64");
187
1
  }
188
};
189
190
// SPARC v9 is the 64-bit mode selected by Triple::sparcv9.
191
class LLVM_LIBRARY_VISIBILITY SparcV9TargetInfo : public SparcTargetInfo {
192
public:
193
  SparcV9TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
194
22
      : SparcTargetInfo(Triple, Opts) {
195
22
    // FIXME: Support Sparc quad-precision long double?
196
22
    resetDataLayout("E-m:e-i64:64-n32:64-S128");
197
22
    // This is an LP64 platform.
198
22
    LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
199
22
200
22
    // OpenBSD uses long long for int64_t and intmax_t.
201
22
    if (getTriple().isOSOpenBSD())
202
2
      IntMaxType = SignedLongLong;
203
20
    else
204
20
      IntMaxType = SignedLong;
205
22
    Int64Type = IntMaxType;
206
22
207
22
    // The SPARCv8 System V ABI has long double 128-bits in size, but 64-bit
208
22
    // aligned. The SPARCv9 SCD 2.4.1 says 16-byte aligned.
209
22
    LongDoubleWidth = 128;
210
22
    LongDoubleAlign = 128;
211
22
    SuitableAlign = 128;
212
22
    LongDoubleFormat = &llvm::APFloat::IEEEquad();
213
22
    MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
214
22
  }
clang::targets::SparcV9TargetInfo::SparcV9TargetInfo(llvm::Triple const&, clang::TargetOptions const&)
Line
Count
Source
194
9
      : SparcTargetInfo(Triple, Opts) {
195
9
    // FIXME: Support Sparc quad-precision long double?
196
9
    resetDataLayout("E-m:e-i64:64-n32:64-S128");
197
9
    // This is an LP64 platform.
198
9
    LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
199
9
200
9
    // OpenBSD uses long long for int64_t and intmax_t.
201
9
    if (getTriple().isOSOpenBSD())
202
0
      IntMaxType = SignedLongLong;
203
9
    else
204
9
      IntMaxType = SignedLong;
205
9
    Int64Type = IntMaxType;
206
9
207
9
    // The SPARCv8 System V ABI has long double 128-bits in size, but 64-bit
208
9
    // aligned. The SPARCv9 SCD 2.4.1 says 16-byte aligned.
209
9
    LongDoubleWidth = 128;
210
9
    LongDoubleAlign = 128;
211
9
    SuitableAlign = 128;
212
9
    LongDoubleFormat = &llvm::APFloat::IEEEquad();
213
9
    MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
214
9
  }
clang::targets::SparcV9TargetInfo::SparcV9TargetInfo(llvm::Triple const&, clang::TargetOptions const&)
Line
Count
Source
194
13
      : SparcTargetInfo(Triple, Opts) {
195
13
    // FIXME: Support Sparc quad-precision long double?
196
13
    resetDataLayout("E-m:e-i64:64-n32:64-S128");
197
13
    // This is an LP64 platform.
198
13
    LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
199
13
200
13
    // OpenBSD uses long long for int64_t and intmax_t.
201
13
    if (getTriple().isOSOpenBSD())
202
2
      IntMaxType = SignedLongLong;
203
11
    else
204
11
      IntMaxType = SignedLong;
205
13
    Int64Type = IntMaxType;
206
13
207
13
    // The SPARCv8 System V ABI has long double 128-bits in size, but 64-bit
208
13
    // aligned. The SPARCv9 SCD 2.4.1 says 16-byte aligned.
209
13
    LongDoubleWidth = 128;
210
13
    LongDoubleAlign = 128;
211
13
    SuitableAlign = 128;
212
13
    LongDoubleFormat = &llvm::APFloat::IEEEquad();
213
13
    MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
214
13
  }
215
216
  void getTargetDefines(const LangOptions &Opts,
217
                        MacroBuilder &Builder) const override;
218
219
0
  bool isValidCPUName(StringRef Name) const override {
220
0
    return getCPUGeneration(SparcTargetInfo::getCPUKind(Name)) == CG_V9;
221
0
  }
222
223
  void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
224
225
9
  bool setCPU(const std::string &Name) override {
226
9
    if (!SparcTargetInfo::setCPU(Name))
227
1
      return false;
228
8
    return getCPUGeneration(CPU) == CG_V9;
229
8
  }
230
};
231
} // namespace targets
232
} // namespace clang
233
#endif // LLVM_CLANG_LIB_BASIC_TARGETS_SPARC_H