Coverage Report

Created: 2022-07-16 07:03

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Basic/Targets/CSKY.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- CSKY.cpp - Implement CSKY target feature support -----------------===//
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 implements CSKY TargetInfo objects.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "CSKY.h"
14
15
using namespace clang;
16
using namespace clang::targets;
17
18
0
bool CSKYTargetInfo::isValidCPUName(StringRef Name) const {
19
0
  return llvm::CSKY::parseCPUArch(Name) != llvm::CSKY::ArchKind::INVALID;
20
0
}
21
22
1
bool CSKYTargetInfo::setCPU(const std::string &Name) {
23
1
  llvm::CSKY::ArchKind archKind = llvm::CSKY::parseCPUArch(Name);
24
1
  bool isValid = (archKind != llvm::CSKY::ArchKind::INVALID);
25
26
1
  if (isValid) {
27
1
    CPU = Name;
28
1
    Arch = archKind;
29
1
  }
30
31
1
  return isValid;
32
1
}
33
34
void CSKYTargetInfo::getTargetDefines(const LangOptions &Opts,
35
8
                                      MacroBuilder &Builder) const {
36
8
  Builder.defineMacro("__ELF__");
37
8
  Builder.defineMacro("__csky__", "2");
38
8
  Builder.defineMacro("__CSKY__", "2");
39
8
  Builder.defineMacro("__ckcore__", "2");
40
8
  Builder.defineMacro("__CKCORE__", "2");
41
42
8
  Builder.defineMacro("__CSKYABI__", ABI == "abiv2" ? "2" : 
"1"0
);
43
8
  Builder.defineMacro("__cskyabi__", ABI == "abiv2" ? "2" : 
"1"0
);
44
45
8
  StringRef ArchName = "ck810";
46
8
  StringRef CPUName = "ck810";
47
48
8
  if (Arch != llvm::CSKY::ArchKind::INVALID) {
49
1
    ArchName = llvm::CSKY::getArchName(Arch);
50
1
    CPUName = CPU;
51
1
  }
52
53
8
  Builder.defineMacro("__" + ArchName.upper() + "__");
54
8
  Builder.defineMacro("__" + ArchName.lower() + "__");
55
8
  Builder.defineMacro("__" + CPUName.upper() + "__");
56
8
  Builder.defineMacro("__" + CPUName.lower() + "__");
57
58
  // TODO: Add support for BE if BE was supported later
59
8
  StringRef endian = "__cskyLE__";
60
61
8
  Builder.defineMacro(endian);
62
8
  Builder.defineMacro(endian.upper());
63
8
  Builder.defineMacro(endian.lower());
64
65
8
  if (DSPV2) {
66
0
    StringRef dspv2 = "__CSKY_DSPV2__";
67
0
    Builder.defineMacro(dspv2);
68
0
    Builder.defineMacro(dspv2.lower());
69
0
  }
70
71
8
  if (VDSPV2) {
72
0
    StringRef vdspv2 = "__CSKY_VDSPV2__";
73
0
    Builder.defineMacro(vdspv2);
74
0
    Builder.defineMacro(vdspv2.lower());
75
76
0
    if (HardFloat) {
77
0
      StringRef vdspv2_f = "__CSKY_VDSPV2_F__";
78
0
      Builder.defineMacro(vdspv2_f);
79
0
      Builder.defineMacro(vdspv2_f.lower());
80
0
    }
81
0
  }
82
8
  if (VDSPV1) {
83
0
    StringRef vdspv1_64 = "__CSKY_VDSP64__";
84
0
    StringRef vdspv1_128 = "__CSKY_VDSP128__";
85
86
0
    Builder.defineMacro(vdspv1_64);
87
0
    Builder.defineMacro(vdspv1_64.lower());
88
0
    Builder.defineMacro(vdspv1_128);
89
0
    Builder.defineMacro(vdspv1_128.lower());
90
0
  }
91
8
  if (is3E3R1) {
92
0
    StringRef is3e3r1 = "__CSKY_3E3R1__";
93
0
    Builder.defineMacro(is3e3r1);
94
0
    Builder.defineMacro(is3e3r1.lower());
95
0
  }
96
8
}
97
98
13
bool CSKYTargetInfo::hasFeature(StringRef Feature) const {
99
13
  return llvm::StringSwitch<bool>(Feature)
100
13
      .Case("hard-float", HardFloat)
101
13
      .Case("hard-float-abi", HardFloatABI)
102
13
      .Case("fpuv2_sf", FPUV2_SF)
103
13
      .Case("fpuv2_df", FPUV2_DF)
104
13
      .Case("fpuv3_sf", FPUV3_SF)
105
13
      .Case("fpuv3_df", FPUV3_DF)
106
13
      .Case("vdspv2", VDSPV2)
107
13
      .Case("dspv2", DSPV2)
108
13
      .Case("vdspv1", VDSPV1)
109
13
      .Case("3e3r1", is3E3R1)
110
13
      .Default(false);
111
13
}
112
113
bool CSKYTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
114
8
                                          DiagnosticsEngine &Diags) {
115
28
  for (const auto &Feature : Features) {
116
28
    if (Feature == "+hard-float")
117
3
      HardFloat = true;
118
28
    if (Feature == "+hard-float-abi")
119
2
      HardFloatABI = true;
120
28
    if (Feature == "+fpuv2_sf")
121
3
      FPUV2_SF = true;
122
28
    if (Feature == "+fpuv2_df")
123
3
      FPUV2_DF = true;
124
28
    if (Feature == "+fpuv3_sf")
125
0
      FPUV3_SF = true;
126
28
    if (Feature == "+fpuv3_df")
127
0
      FPUV3_DF = true;
128
28
    if (Feature == "+vdspv2")
129
0
      VDSPV2 = true;
130
28
    if (Feature == "+dspv2")
131
0
      DSPV2 = true;
132
28
    if (Feature == "+vdspv1")
133
0
      VDSPV1 = true;
134
28
    if (Feature == "+3e3r1")
135
0
      is3E3R1 = true;
136
28
  }
137
138
8
  return true;
139
8
}
140
141
8
ArrayRef<Builtin::Info> CSKYTargetInfo::getTargetBuiltins() const {
142
8
  return ArrayRef<Builtin::Info>();
143
8
}
144
145
0
ArrayRef<const char *> CSKYTargetInfo::getGCCRegNames() const {
146
0
  static const char *const GCCRegNames[] = {
147
      // Integer registers
148
0
      "r0",
149
0
      "r1",
150
0
      "r2",
151
0
      "r3",
152
0
      "r4",
153
0
      "r5",
154
0
      "r6",
155
0
      "r7",
156
0
      "r8",
157
0
      "r9",
158
0
      "r10",
159
0
      "r11",
160
0
      "r12",
161
0
      "r13",
162
0
      "r14",
163
0
      "r15",
164
0
      "r16",
165
0
      "r17",
166
0
      "r18",
167
0
      "r19",
168
0
      "r20",
169
0
      "r21",
170
0
      "r22",
171
0
      "r23",
172
0
      "r24",
173
0
      "r25",
174
0
      "r26",
175
0
      "r27",
176
0
      "r28",
177
0
      "r29",
178
0
      "r30",
179
0
      "r31",
180
181
      // Floating point registers
182
0
      "fr0",
183
0
      "fr1",
184
0
      "fr2",
185
0
      "fr3",
186
0
      "fr4",
187
0
      "fr5",
188
0
      "fr6",
189
0
      "fr7",
190
0
      "fr8",
191
0
      "fr9",
192
0
      "fr10",
193
0
      "fr11",
194
0
      "fr12",
195
0
      "fr13",
196
0
      "fr14",
197
0
      "fr15",
198
0
      "fr16",
199
0
      "fr17",
200
0
      "fr18",
201
0
      "fr19",
202
0
      "fr20",
203
0
      "fr21",
204
0
      "fr22",
205
0
      "fr23",
206
0
      "fr24",
207
0
      "fr25",
208
0
      "fr26",
209
0
      "fr27",
210
0
      "fr28",
211
0
      "fr29",
212
0
      "fr30",
213
0
      "fr31",
214
215
0
  };
216
0
  return llvm::makeArrayRef(GCCRegNames);
217
0
}
218
219
0
ArrayRef<TargetInfo::GCCRegAlias> CSKYTargetInfo::getGCCRegAliases() const {
220
0
  static const TargetInfo::GCCRegAlias GCCRegAliases[] = {
221
0
      {{"a0"}, "r0"},
222
0
      {{"a1"}, "r1"},
223
0
      {{"a2"}, "r2"},
224
0
      {{"a3"}, "r3"},
225
0
      {{"l0"}, "r4"},
226
0
      {{"l1"}, "r5"},
227
0
      {{"l2"}, "r6"},
228
0
      {{"l3"}, "r7"},
229
0
      {{"l4"}, "r8"},
230
0
      {{"l5"}, "r9"},
231
0
      {{"l6"}, "r10"},
232
0
      {{"l7"}, "r11"},
233
0
      {{"t0"}, "r12"},
234
0
      {{"t1"}, "r13"},
235
0
      {{"sp"}, "r14"},
236
0
      {{"lr"}, "r15"},
237
0
      {{"l8"}, "r16"},
238
0
      {{"l9"}, "r17"},
239
0
      {{"t2"}, "r18"},
240
0
      {{"t3"}, "r19"},
241
0
      {{"t4"}, "r20"},
242
0
      {{"t5"}, "r21"},
243
0
      {{"t6"}, "r22"},
244
0
      {{"t7", "fp"}, "r23"},
245
0
      {{"t8", "top"}, "r24"},
246
0
      {{"t9", "bsp"}, "r25"},
247
0
      {{"r26"}, "r26"},
248
0
      {{"r27"}, "r27"},
249
0
      {{"gb", "rgb", "rdb"}, "r28"},
250
0
      {{"tb", "rtb"}, "r29"},
251
0
      {{"svbr"}, "r30"},
252
0
      {{"tls"}, "r31"},
253
254
0
      {{"vr0"}, "fr0"},
255
0
      {{"vr1"}, "fr1"},
256
0
      {{"vr2"}, "fr2"},
257
0
      {{"vr3"}, "fr3"},
258
0
      {{"vr4"}, "fr4"},
259
0
      {{"vr5"}, "fr5"},
260
0
      {{"vr6"}, "fr6"},
261
0
      {{"vr7"}, "fr7"},
262
0
      {{"vr8"}, "fr8"},
263
0
      {{"vr9"}, "fr9"},
264
0
      {{"vr10"}, "fr10"},
265
0
      {{"vr11"}, "fr11"},
266
0
      {{"vr12"}, "fr12"},
267
0
      {{"vr13"}, "fr13"},
268
0
      {{"vr14"}, "fr14"},
269
0
      {{"vr15"}, "fr15"},
270
0
      {{"vr16"}, "fr16"},
271
0
      {{"vr17"}, "fr17"},
272
0
      {{"vr18"}, "fr18"},
273
0
      {{"vr19"}, "fr19"},
274
0
      {{"vr20"}, "fr20"},
275
0
      {{"vr21"}, "fr21"},
276
0
      {{"vr22"}, "fr22"},
277
0
      {{"vr23"}, "fr23"},
278
0
      {{"vr24"}, "fr24"},
279
0
      {{"vr25"}, "fr25"},
280
0
      {{"vr26"}, "fr26"},
281
0
      {{"vr27"}, "fr27"},
282
0
      {{"vr28"}, "fr28"},
283
0
      {{"vr29"}, "fr29"},
284
0
      {{"vr30"}, "fr30"},
285
0
      {{"vr31"}, "fr31"},
286
287
0
  };
288
0
  return llvm::makeArrayRef(GCCRegAliases);
289
0
}
290
291
bool CSKYTargetInfo::validateAsmConstraint(
292
0
    const char *&Name, TargetInfo::ConstraintInfo &Info) const {
293
0
  switch (*Name) {
294
0
  default:
295
0
    return false;
296
0
  case 'a':
297
0
  case 'b':
298
0
  case 'c':
299
0
  case 'y':
300
0
  case 'l':
301
0
  case 'h':
302
0
  case 'w':
303
0
  case 'v': // A floating-point and vector register.
304
0
  case 'z':
305
0
    Info.setAllowsRegister();
306
0
    return true;
307
0
  }
308
0
}
309
310
0
unsigned CSKYTargetInfo::getMinGlobalAlign(uint64_t Size) const {
311
0
  if (Size >= 32)
312
0
    return 32;
313
0
  return 0;
314
0
}