Coverage Report

Created: 2022-05-17 06:19

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