Coverage Report

Created: 2020-02-25 14:32

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Basic/Targets/Hexagon.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- Hexagon.cpp - Implement Hexagon 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 Hexagon TargetInfo objects.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "Hexagon.h"
14
#include "Targets.h"
15
#include "clang/Basic/MacroBuilder.h"
16
#include "clang/Basic/TargetBuiltins.h"
17
#include "llvm/ADT/StringSwitch.h"
18
19
using namespace clang;
20
using namespace clang::targets;
21
22
void HexagonTargetInfo::getTargetDefines(const LangOptions &Opts,
23
54
                                         MacroBuilder &Builder) const {
24
54
  Builder.defineMacro("__qdsp6__", "1");
25
54
  Builder.defineMacro("__hexagon__", "1");
26
54
27
54
  Builder.defineMacro("__ELF__");
28
54
29
54
  // The macro __HVXDBL__ is deprecated.
30
54
  bool DefineHvxDbl = false;
31
54
32
54
  if (CPU == "hexagonv5") {
33
1
    Builder.defineMacro("__HEXAGON_V5__");
34
1
    Builder.defineMacro("__HEXAGON_ARCH__", "5");
35
1
    if (Opts.HexagonQdsp6Compat) {
36
0
      Builder.defineMacro("__QDSP6_V5__");
37
0
      Builder.defineMacro("__QDSP6_ARCH__", "5");
38
0
    }
39
53
  } else if (CPU == "hexagonv55") {
40
4
    Builder.defineMacro("__HEXAGON_V55__");
41
4
    Builder.defineMacro("__HEXAGON_ARCH__", "55");
42
4
    Builder.defineMacro("__QDSP6_V55__");
43
4
    Builder.defineMacro("__QDSP6_ARCH__", "55");
44
49
  } else if (CPU == "hexagonv60") {
45
15
    DefineHvxDbl = true;
46
15
    Builder.defineMacro("__HEXAGON_V60__");
47
15
    Builder.defineMacro("__HEXAGON_ARCH__", "60");
48
15
    Builder.defineMacro("__QDSP6_V60__");
49
15
    Builder.defineMacro("__QDSP6_ARCH__", "60");
50
34
  } else if (CPU == "hexagonv62") {
51
7
    DefineHvxDbl = true;
52
7
    Builder.defineMacro("__HEXAGON_V62__");
53
7
    Builder.defineMacro("__HEXAGON_ARCH__", "62");
54
27
  } else if (CPU == "hexagonv65") {
55
6
    DefineHvxDbl = true;
56
6
    Builder.defineMacro("__HEXAGON_V65__");
57
6
    Builder.defineMacro("__HEXAGON_ARCH__", "65");
58
21
  } else if (CPU == "hexagonv66") {
59
7
    DefineHvxDbl = true;
60
7
    Builder.defineMacro("__HEXAGON_V66__");
61
7
    Builder.defineMacro("__HEXAGON_ARCH__", "66");
62
14
  } else if (CPU == "hexagonv67") {
63
4
    Builder.defineMacro("__HEXAGON_V67__");
64
4
    Builder.defineMacro("__HEXAGON_ARCH__", "67");
65
10
  } else if (CPU == "hexagonv67t") {
66
1
    Builder.defineMacro("__HEXAGON_V67T__");
67
1
    Builder.defineMacro("__HEXAGON_ARCH__", "67");
68
1
  }
69
54
70
54
  if (hasFeature("hvx-length64b")) {
71
6
    Builder.defineMacro("__HVX__");
72
6
    Builder.defineMacro("__HVX_ARCH__", HVXVersion);
73
6
    Builder.defineMacro("__HVX_LENGTH__", "64");
74
6
  }
75
54
76
54
  if (hasFeature("hvx-length128b")) {
77
14
    Builder.defineMacro("__HVX__");
78
14
    Builder.defineMacro("__HVX_ARCH__", HVXVersion);
79
14
    Builder.defineMacro("__HVX_LENGTH__", "128");
80
14
    if (DefineHvxDbl)
81
12
      Builder.defineMacro("__HVXDBL__");
82
14
  }
83
54
84
54
  if (hasFeature("audio")) {
85
2
    Builder.defineMacro("__HEXAGON_AUDIO__");
86
2
  }
87
54
88
54
  std::string NumPhySlots = isTinyCore() ? 
"3"1
:
"4"53
;
89
54
  Builder.defineMacro("__HEXAGON_PHYSICAL_SLOTS__", NumPhySlots);
90
54
}
91
92
bool HexagonTargetInfo::initFeatureMap(
93
    llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
94
1.84k
    const std::vector<std::string> &FeaturesVec) const {
95
1.84k
  if (isTinyCore())
96
23
    Features["audio"] = true;
97
1.84k
98
1.84k
  StringRef CPUFeature = CPU;
99
1.84k
  CPUFeature.consume_front("hexagon");
100
1.84k
  CPUFeature.consume_back("t");
101
1.84k
  Features[CPUFeature] = true;
102
1.84k
103
1.84k
  Features["long-calls"] = false;
104
1.84k
105
1.84k
  return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
106
1.84k
}
107
108
bool HexagonTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
109
54
                                             DiagnosticsEngine &Diags) {
110
151
  for (auto &F : Features) {
111
151
    if (F == "+hvx-length64b")
112
6
      HasHVX = HasHVX64B = true;
113
145
    else if (F == "+hvx-length128b")
114
14
      HasHVX = HasHVX128B = true;
115
131
    else if (F.find("+hvxv") != std::string::npos) {
116
20
      HasHVX = true;
117
20
      HVXVersion = F.substr(std::string("+hvxv").length());
118
111
    } else if (F == "-hvx")
119
0
      HasHVX = HasHVX64B = HasHVX128B = false;
120
111
    else if (F == "+long-calls")
121
0
      UseLongCalls = true;
122
111
    else if (F == "-long-calls")
123
54
      UseLongCalls = false;
124
57
    else if (F == "+audio")
125
2
      HasAudio = true;
126
151
  }
127
54
  return true;
128
54
}
129
130
const char *const HexagonTargetInfo::GCCRegNames[] = {
131
    "r0",  "r1",  "r2",  "r3",  "r4",  "r5",  "r6",  "r7",  "r8",
132
    "r9",  "r10", "r11", "r12", "r13", "r14", "r15", "r16", "r17",
133
    "r18", "r19", "r20", "r21", "r22", "r23", "r24", "r25", "r26",
134
    "r27", "r28", "r29", "r30", "r31", "p0",  "p1",  "p2",  "p3",
135
    "sa0", "lc0", "sa1", "lc1", "m0",  "m1",  "usr", "ugp",
136
    "r1:0", "r3:2", "r5:4", "r7:6", "r9:8", "r11:10", "r13:12", "r15:14",
137
    "r17:16", "r19:18", "r21:20", "r23:22", "r25:24", "r27:26", "r29:28",
138
    "r31:30"
139
};
140
141
1
ArrayRef<const char *> HexagonTargetInfo::getGCCRegNames() const {
142
1
  return llvm::makeArrayRef(GCCRegNames);
143
1
}
144
145
const TargetInfo::GCCRegAlias HexagonTargetInfo::GCCRegAliases[] = {
146
    {{"sp"}, "r29"},
147
    {{"fp"}, "r30"},
148
    {{"lr"}, "r31"},
149
};
150
151
1
ArrayRef<TargetInfo::GCCRegAlias> HexagonTargetInfo::getGCCRegAliases() const {
152
1
  return llvm::makeArrayRef(GCCRegAliases);
153
1
}
154
155
const Builtin::Info HexagonTargetInfo::BuiltinInfo[] = {
156
#define BUILTIN(ID, TYPE, ATTRS)                                               \
157
  {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr},
158
#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER)                                    \
159
  {#ID, TYPE, ATTRS, HEADER, ALL_LANGUAGES, nullptr},
160
#define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE)                               \
161
  {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, FEATURE},
162
#include "clang/Basic/BuiltinsHexagon.def"
163
};
164
165
217
bool HexagonTargetInfo::hasFeature(StringRef Feature) const {
166
217
  std::string VS = "hvxv" + HVXVersion;
167
217
  if (Feature == VS)
168
0
    return true;
169
217
170
217
  return llvm::StringSwitch<bool>(Feature)
171
217
      .Case("hexagon", true)
172
217
      .Case("hvx", HasHVX)
173
217
      .Case("hvx-length64b", HasHVX64B)
174
217
      .Case("hvx-length128b", HasHVX128B)
175
217
      .Case("long-calls", UseLongCalls)
176
217
      .Case("audio", HasAudio)
177
217
      .Default(false);
178
217
}
179
180
struct CPUSuffix {
181
  llvm::StringLiteral Name;
182
  llvm::StringLiteral Suffix;
183
};
184
185
static constexpr CPUSuffix Suffixes[] = {
186
    {{"hexagonv5"},  {"5"}},  {{"hexagonv55"},  {"55"}},
187
    {{"hexagonv60"}, {"60"}}, {{"hexagonv62"},  {"62"}},
188
    {{"hexagonv65"}, {"65"}}, {{"hexagonv66"},  {"66"}},
189
    {{"hexagonv67"}, {"67"}}, {{"hexagonv67t"}, {"67t"}},
190
};
191
192
46
const char *HexagonTargetInfo::getHexagonCPUSuffix(StringRef Name) {
193
46
  const CPUSuffix *Item = llvm::find_if(
194
198
      Suffixes, [Name](const CPUSuffix &S) { return S.Name == Name; });
195
46
  if (Item == std::end(Suffixes))
196
1
    return nullptr;
197
45
  return Item->Suffix.data();
198
45
}
199
200
void HexagonTargetInfo::fillValidCPUList(
201
1
    SmallVectorImpl<StringRef> &Values) const {
202
1
  for (const CPUSuffix &Suffix : Suffixes)
203
8
    Values.push_back(Suffix.Name);
204
1
}
205
206
54
ArrayRef<Builtin::Info> HexagonTargetInfo::getTargetBuiltins() const {
207
54
  return llvm::makeArrayRef(BuiltinInfo, clang::Hexagon::LastTSBuiltin -
208
54
                                             Builtin::FirstTSBuiltin);
209
54
}