clang 23.0.0git
Hexagon.cpp
Go to the documentation of this file.
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"
16#include "llvm/ADT/StringSwitch.h"
17
18using namespace clang;
19using namespace clang::targets;
20
22 MacroBuilder &Builder) const {
23 Builder.defineMacro("__qdsp6__", "1");
24 Builder.defineMacro("__hexagon__", "1");
25
26 // The macro __HVXDBL__ is deprecated.
27 bool DefineHvxDbl = false;
28
29 if (CPU == "hexagonv5") {
30 Builder.defineMacro("__HEXAGON_V5__");
31 Builder.defineMacro("__HEXAGON_ARCH__", "5");
32 if (Opts.HexagonQdsp6Compat) {
33 Builder.defineMacro("__QDSP6_V5__");
34 Builder.defineMacro("__QDSP6_ARCH__", "5");
35 }
36 } else if (CPU == "hexagonv55") {
37 Builder.defineMacro("__HEXAGON_V55__");
38 Builder.defineMacro("__HEXAGON_ARCH__", "55");
39 Builder.defineMacro("__QDSP6_V55__");
40 Builder.defineMacro("__QDSP6_ARCH__", "55");
41 } else if (CPU == "hexagonv60") {
42 DefineHvxDbl = true;
43 Builder.defineMacro("__HEXAGON_V60__");
44 Builder.defineMacro("__HEXAGON_ARCH__", "60");
45 Builder.defineMacro("__QDSP6_V60__");
46 Builder.defineMacro("__QDSP6_ARCH__", "60");
47 } else if (CPU == "hexagonv62") {
48 DefineHvxDbl = true;
49 Builder.defineMacro("__HEXAGON_V62__");
50 Builder.defineMacro("__HEXAGON_ARCH__", "62");
51 } else if (CPU == "hexagonv65") {
52 DefineHvxDbl = true;
53 Builder.defineMacro("__HEXAGON_V65__");
54 Builder.defineMacro("__HEXAGON_ARCH__", "65");
55 } else if (CPU == "hexagonv66") {
56 DefineHvxDbl = true;
57 Builder.defineMacro("__HEXAGON_V66__");
58 Builder.defineMacro("__HEXAGON_ARCH__", "66");
59 } else if (CPU == "hexagonv67") {
60 Builder.defineMacro("__HEXAGON_V67__");
61 Builder.defineMacro("__HEXAGON_ARCH__", "67");
62 } else if (CPU == "hexagonv67t") {
63 Builder.defineMacro("__HEXAGON_V67T__");
64 Builder.defineMacro("__HEXAGON_ARCH__", "67");
65 } else if (CPU == "hexagonv68") {
66 Builder.defineMacro("__HEXAGON_V68__");
67 Builder.defineMacro("__HEXAGON_ARCH__", "68");
68 } else if (CPU == "hexagonv69") {
69 Builder.defineMacro("__HEXAGON_V69__");
70 Builder.defineMacro("__HEXAGON_ARCH__", "69");
71 } else if (CPU == "hexagonv71") {
72 Builder.defineMacro("__HEXAGON_V71__");
73 Builder.defineMacro("__HEXAGON_ARCH__", "71");
74 } else if (CPU == "hexagonv71t") {
75 Builder.defineMacro("__HEXAGON_V71T__");
76 Builder.defineMacro("__HEXAGON_ARCH__", "71");
77 } else if (CPU == "hexagonv73") {
78 Builder.defineMacro("__HEXAGON_V73__");
79 Builder.defineMacro("__HEXAGON_ARCH__", "73");
80 } else if (CPU == "hexagonv75") {
81 Builder.defineMacro("__HEXAGON_V75__");
82 Builder.defineMacro("__HEXAGON_ARCH__", "75");
83 } else if (CPU == "hexagonv79") {
84 Builder.defineMacro("__HEXAGON_V79__");
85 Builder.defineMacro("__HEXAGON_ARCH__", "79");
86 } else if (CPU == "hexagonv81") {
87 Builder.defineMacro("__HEXAGON_V81__");
88 Builder.defineMacro("__HEXAGON_ARCH__", "81");
89 }
90
91 if (hasFeature("hvx-length64b")) {
92 Builder.defineMacro("__HVX__");
93 Builder.defineMacro("__HVX_ARCH__", HVXVersion);
94 Builder.defineMacro("__HVX_LENGTH__", "64");
95 }
96
97 if (hasFeature("hvx-length128b")) {
98 Builder.defineMacro("__HVX__");
99 Builder.defineMacro("__HVX_ARCH__", HVXVersion);
100 Builder.defineMacro("__HVX_LENGTH__", "128");
101 if (DefineHvxDbl)
102 Builder.defineMacro("__HVXDBL__");
103 }
104
105 if (HasHVXIeeeFp)
106 Builder.defineMacro("__HVX_IEEE_FP__");
107
108 if (hasFeature("audio")) {
109 Builder.defineMacro("__HEXAGON_AUDIO__");
110 }
111
112 std::string NumPhySlots = isTinyCore() ? "3" : "4";
113 Builder.defineMacro("__HEXAGON_PHYSICAL_SLOTS__", NumPhySlots);
114
115 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
116 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
117 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
118 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
119
120 if (Opts.CPlusPlus && getTriple().getOS() == llvm::Triple::UnknownOS)
121 Builder.defineMacro("_GNU_SOURCE");
122}
123
125 llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
126 const std::vector<std::string> &FeaturesVec) const {
127 if (isTinyCore())
128 Features["audio"] = true;
129
130 StringRef CPUFeature = CPU;
131 CPUFeature.consume_front("hexagon");
132 CPUFeature.consume_back("t");
133 if (!CPUFeature.empty())
134 Features[CPUFeature] = true;
135
136 Features["long-calls"] = false;
137
138 return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
139}
140
141bool HexagonTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
142 DiagnosticsEngine &Diags) {
143 for (auto &F : Features) {
144 if (F == "+hvx-length64b")
145 HasHVX = HasHVX64B = true;
146 else if (F == "+hvx-length128b")
147 HasHVX = HasHVX128B = true;
148 else if (F.find("+hvxv") != std::string::npos) {
149 HasHVX = true;
150 HVXVersion = F.substr(std::string("+hvxv").length());
151 } else if (F == "-hvx")
152 HasHVX = HasHVX64B = HasHVX128B = false;
153 else if (F == "+long-calls")
154 UseLongCalls = true;
155 else if (F == "-long-calls")
156 UseLongCalls = false;
157 else if (F == "+hvx-ieee-fp")
158 HasHVXIeeeFp = true;
159 else if (F == "+audio")
160 HasAudio = true;
161 }
162 if (CPU.compare("hexagonv68") >= 0) {
163 HasFastHalfType = true;
164 HasFloat16 = true;
165 }
166 if (CPU.compare("hexagonv81") >= 0)
167 HasBFloat16 = true;
168
169 return true;
170}
171
173
174const char *const HexagonTargetInfo::GCCRegNames[] = {
175 // Scalar registers:
176 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11",
177 "r12", "r13", "r14", "r15", "r16", "r17", "r18", "r19", "r20", "r21",
178 "r22", "r23", "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
179 "r1:0", "r3:2", "r5:4", "r7:6", "r9:8", "r11:10", "r13:12", "r15:14",
180 "r17:16", "r19:18", "r21:20", "r23:22", "r25:24", "r27:26", "r29:28",
181 "r31:30",
182 // Predicate registers:
183 "p0", "p1", "p2", "p3",
184 // Control registers:
185 "c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10", "c11",
186 "c12", "c13", "c14", "c15", "c16", "c17", "c18", "c19", "c20", "c21",
187 "c22", "c23", "c24", "c25", "c26", "c27", "c28", "c29", "c30", "c31",
188 "c1:0", "c3:2", "c5:4", "c7:6", "c9:8", "c11:10", "c13:12", "c15:14",
189 "c17:16", "c19:18", "c21:20", "c23:22", "c25:24", "c27:26", "c29:28",
190 "c31:30",
191 // Control register aliases:
192 "sa0", "lc0", "sa1", "lc1", "p3:0", "m0", "m1", "usr", "pc", "ugp",
193 "gp", "cs0", "cs1", "upcyclelo", "upcyclehi", "framelimit", "framekey",
194 "pktcountlo", "pktcounthi", "utimerlo", "utimerhi",
195 "upcycle", "pktcount", "utimer",
196 // HVX vector registers:
197 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11",
198 "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21",
199 "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
200 "v1:0", "v3:2", "v5:4", "v7:6", "v9:8", "v11:10", "v13:12", "v15:14",
201 "v17:16", "v19:18", "v21:20", "v23:22", "v25:24", "v27:26", "v29:28",
202 "v31:30",
203 "v3:0", "v7:4", "v11:8", "v15:12", "v19:16", "v23:20", "v27:24", "v31:28",
204 // HVX vector predicates:
205 "q0", "q1", "q2", "q3",
206};
207
211
212const TargetInfo::GCCRegAlias HexagonTargetInfo::GCCRegAliases[] = {
213 {{"sp"}, "r29"},
214 {{"fp"}, "r30"},
215 {{"lr"}, "r31"},
216};
217
221
222static constexpr int NumBuiltins =
224
225#define GET_BUILTIN_STR_TABLE
226#include "clang/Basic/BuiltinsHexagon.inc"
227#undef GET_BUILTIN_STR_TABLE
228
229static constexpr Builtin::Info BuiltinInfos[] = {
230#define GET_BUILTIN_INFOS
231#include "clang/Basic/BuiltinsHexagon.inc"
232#undef GET_BUILTIN_INFOS
233};
234
236#define GET_BUILTIN_PREFIXED_INFOS
237#include "clang/Basic/BuiltinsHexagon.inc"
238#undef GET_BUILTIN_PREFIXED_INFOS
239};
240static_assert((std::size(BuiltinInfos) + std::size(PrefixedBuiltinInfos)) ==
242
244 std::string VS = "hvxv" + HVXVersion;
245 if (Feature == VS)
246 return true;
247
248 return llvm::StringSwitch<bool>(Feature)
249 .Case("hexagon", true)
250 .Case("hvx", HasHVX)
251 .Case("hvx-length64b", HasHVX64B)
252 .Case("hvx-length128b", HasHVX128B)
253 .Case("hvx-ieee-fp", HasHVXIeeeFp)
254 .Case("long-calls", UseLongCalls)
255 .Case("audio", HasAudio)
256 .Default(false);
257}
258
259struct CPUSuffix {
260 llvm::StringLiteral Name;
261 llvm::StringLiteral Suffix;
262};
263
264static constexpr CPUSuffix Suffixes[] = {
265 {{"hexagonv5"}, {"5"}}, {{"hexagonv55"}, {"55"}},
266 {{"hexagonv60"}, {"60"}}, {{"hexagonv62"}, {"62"}},
267 {{"hexagonv65"}, {"65"}}, {{"hexagonv66"}, {"66"}},
268 {{"hexagonv67"}, {"67"}}, {{"hexagonv67t"}, {"67t"}},
269 {{"hexagonv68"}, {"68"}}, {{"hexagonv69"}, {"69"}},
270 {{"hexagonv71"}, {"71"}}, {{"hexagonv71t"}, {"71t"}},
271 {{"hexagonv73"}, {"73"}}, {{"hexagonv75"}, {"75"}},
272 {{"hexagonv79"}, {"79"}}, {{"hexagonv81"}, {"81"}}};
273
274std::optional<unsigned> HexagonTargetInfo::getHexagonCPURev(StringRef Name) {
275 StringRef Arch = Name;
276 Arch.consume_front("hexagonv");
277 Arch.consume_back("t");
278
279 unsigned Val;
280 if (!Arch.getAsInteger(0, Val))
281 return Val;
282
283 return std::nullopt;
284}
285
286const char *HexagonTargetInfo::getHexagonCPUSuffix(StringRef Name) {
287 const CPUSuffix *Item = llvm::find_if(
288 Suffixes, [Name](const CPUSuffix &S) { return S.Name == Name; });
289 if (Item == std::end(Suffixes))
290 return nullptr;
291 return Item->Suffix.data();
292}
293
295 SmallVectorImpl<StringRef> &Values) const {
296 for (const CPUSuffix &Suffix : Suffixes)
297 Values.push_back(Suffix.Name);
298}
299
302 return {{&BuiltinStrings, BuiltinInfos},
303 {&BuiltinStrings, PrefixedBuiltinInfos, "__builtin_HEXAGON_"}};
304}
static constexpr llvm::StringTable BuiltinStrings
Definition ARM.cpp:1115
static constexpr CPUSuffix Suffixes[]
Definition Hexagon.cpp:264
static constexpr Builtin::Info PrefixedBuiltinInfos[]
Definition Hexagon.cpp:235
static constexpr Builtin::Info BuiltinInfos[]
Definition Builtins.cpp:39
static constexpr unsigned NumBuiltins
Definition Builtins.cpp:33
Defines the clang::MacroBuilder utility class.
Enumerates target-specific builtins in their own namespaces within namespace clang.
Concrete class used by the front-end to report problems and issues.
Definition Diagnostic.h:234
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
virtual bool initFeatureMap(llvm::StringMap< bool > &Features, DiagnosticsEngine &Diags, StringRef CPU, const std::vector< std::string > &FeatureVec) const
Initialize the map with the default set of target features for the CPU this should include all legal ...
bool handleTargetFeatures(std::vector< std::string > &Features, DiagnosticsEngine &Diags) override
Perform initialization based on the user configured set of features (e.g., +sse4).
Definition Hexagon.cpp:141
bool initFeatureMap(llvm::StringMap< bool > &Features, DiagnosticsEngine &Diags, StringRef CPU, const std::vector< std::string > &FeaturesVec) const override
Initialize the map with the default set of target features for the CPU this should include all legal ...
Definition Hexagon.cpp:124
static std::optional< unsigned > getHexagonCPURev(StringRef Name)
Definition Hexagon.cpp:274
llvm::SmallVector< Builtin::InfosShard > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
Definition Hexagon.cpp:301
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
Definition Hexagon.cpp:218
bool hasBFloat16Type() const override
Determine whether the _BFloat16 type is supported on this target.
Definition Hexagon.cpp:172
static const char * getHexagonCPUSuffix(StringRef Name)
Definition Hexagon.cpp:286
ArrayRef< const char * > getGCCRegNames() const override
Definition Hexagon.cpp:208
void fillValidCPUList(SmallVectorImpl< StringRef > &Values) const override
Fill a SmallVectorImpl with the valid values to setCPU.
Definition Hexagon.cpp:294
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition Hexagon.cpp:21
bool hasFeature(StringRef Feature) const override
Determine whether the given target has the given feature.
Definition Hexagon.cpp:243
static constexpr int NumBuiltins
Definition X86.cpp:30
The JSON file list parser is used to communicate input to InstallAPI.
float __ovld __cnfn length(float)
Return the length of vector p, i.e., sqrt(p.x2 + p.y 2 + ...)
llvm::StringLiteral Suffix
Definition Hexagon.cpp:261
llvm::StringLiteral Name
Definition Hexagon.cpp:260
The info used to represent each builtin.
Definition Builtins.h:80