clang 24.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 StringRef CPUSuffix = CPU;
27 CPUSuffix.consume_front("hexagonv");
28
29 StringRef ArchVersion = CPUSuffix;
30 ArchVersion.consume_back("t");
31
32 // The macro __HVXDBL__ is deprecated.
33 bool DefineHvxDbl = ArchVersion == "60" || ArchVersion == "62" ||
34 ArchVersion == "65" || ArchVersion == "66";
35
36 auto DefineArchMacros = [=, &Builder](StringRef Prefix) {
37 Builder.defineMacro(Prefix + "V" + CPUSuffix.upper() + "__");
38 Builder.defineMacro(Prefix + "ARCH__", ArchVersion);
39 };
40
41 DefineArchMacros("__HEXAGON_");
42 if ((Opts.HexagonQdsp6Compat && ArchVersion == "5") || ArchVersion == "55" ||
43 ArchVersion == "60")
44 DefineArchMacros("__QDSP6_");
45
46 if (hasFeature("hvx-length64b")) {
47 Builder.defineMacro("__HVX__");
48 Builder.defineMacro("__HVX_ARCH__", HVXVersion);
49 Builder.defineMacro("__HVX_LENGTH__", "64");
50 }
51
52 if (hasFeature("hvx-length128b")) {
53 Builder.defineMacro("__HVX__");
54 Builder.defineMacro("__HVX_ARCH__", HVXVersion);
55 Builder.defineMacro("__HVX_LENGTH__", "128");
56 if (DefineHvxDbl)
57 Builder.defineMacro("__HVXDBL__");
58 }
59
60 if (HasHVXIeeeFp)
61 Builder.defineMacro("__HVX_IEEE_FP__");
62
63 if (hasFeature("hlx")) {
64 Builder.defineMacro("__HLX__");
65 Builder.defineMacro("__HLX_ARCH__", "85");
66 Builder.defineMacro("__HLX_LENGTH__", "2048");
67 }
68
69 if (hasFeature("audio")) {
70 Builder.defineMacro("__HEXAGON_AUDIO__");
71 }
72
73 std::string NumPhySlots = isTinyCore() ? "3" : "4";
74 Builder.defineMacro("__HEXAGON_PHYSICAL_SLOTS__", NumPhySlots);
75
76 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
77 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
78 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
79 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
80
81 if (Opts.CPlusPlus && getTriple().getOS() == llvm::Triple::UnknownOS)
82 Builder.defineMacro("_GNU_SOURCE");
83}
84
86 llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
87 const std::vector<std::string> &FeaturesVec) const {
88 if (isTinyCore())
89 Features["audio"] = true;
90
91 StringRef CPUFeature = CPU;
92 CPUFeature.consume_front("hexagon");
93 CPUFeature.consume_back("t");
94 if (!CPUFeature.empty())
95 Features[CPUFeature] = true;
96
97 Features["long-calls"] = false;
98
99 return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
100}
101
102bool HexagonTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
103 DiagnosticsEngine &Diags) {
104 for (auto &F : Features) {
105 if (F == "+hvx-length64b")
106 HasHVX = HasHVX64B = true;
107 else if (F == "+hvx-length128b")
108 HasHVX = HasHVX128B = true;
109 else if (F.find("+hvxv") != std::string::npos) {
110 HasHVX = true;
111 HVXVersion = F.substr(std::string("+hvxv").length());
112 } else if (F == "-hvx")
113 HasHVX = HasHVX64B = HasHVX128B = false;
114 else if (F == "+long-calls")
115 UseLongCalls = true;
116 else if (F == "-long-calls")
117 UseLongCalls = false;
118 else if (F == "+hvx-ieee-fp")
119 HasHVXIeeeFp = true;
120 else if (F == "+audio")
121 HasAudio = true;
122 else if (F == "+hlx")
123 HasHLX = true;
124 else if (F == "-hlx")
125 HasHLX = false;
126 }
127 if (CPU.compare("hexagonv68") >= 0) {
128 HasFastHalfType = true;
129 HasFloat16 = true;
130 }
131 if (CPU.compare("hexagonv81") >= 0)
132 HasBFloat16 = true;
133
134 return true;
135}
136
138
139const char *const HexagonTargetInfo::GCCRegNames[] = {
140 // Scalar registers:
141 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11",
142 "r12", "r13", "r14", "r15", "r16", "r17", "r18", "r19", "r20", "r21",
143 "r22", "r23", "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
144 "r1:0", "r3:2", "r5:4", "r7:6", "r9:8", "r11:10", "r13:12", "r15:14",
145 "r17:16", "r19:18", "r21:20", "r23:22", "r25:24", "r27:26", "r29:28",
146 "r31:30",
147 // Predicate registers:
148 "p0", "p1", "p2", "p3",
149 // Control registers:
150 "c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10", "c11",
151 "c12", "c13", "c14", "c15", "c16", "c17", "c18", "c19", "c20", "c21",
152 "c22", "c23", "c24", "c25", "c26", "c27", "c28", "c29", "c30", "c31",
153 "c1:0", "c3:2", "c5:4", "c7:6", "c9:8", "c11:10", "c13:12", "c15:14",
154 "c17:16", "c19:18", "c21:20", "c23:22", "c25:24", "c27:26", "c29:28",
155 "c31:30",
156 // Control register aliases:
157 "sa0", "lc0", "sa1", "lc1", "p3:0", "m0", "m1", "usr", "pc", "ugp",
158 "gp", "cs0", "cs1", "upcyclelo", "upcyclehi", "framelimit", "framekey",
159 "pktcountlo", "pktcounthi", "utimerlo", "utimerhi",
160 "upcycle", "pktcount", "utimer",
161 // HVX vector registers:
162 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11",
163 "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21",
164 "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
165 "v1:0", "v3:2", "v5:4", "v7:6", "v9:8", "v11:10", "v13:12", "v15:14",
166 "v17:16", "v19:18", "v21:20", "v23:22", "v25:24", "v27:26", "v29:28",
167 "v31:30",
168 "v3:0", "v7:4", "v11:8", "v15:12", "v19:16", "v23:20", "v27:24", "v31:28",
169 // HVX vector predicates:
170 "q0", "q1", "q2", "q3",
171};
172
176
177const TargetInfo::GCCRegAlias HexagonTargetInfo::GCCRegAliases[] = {
178 {{"sp"}, "r29"},
179 {{"fp"}, "r30"},
180 {{"lr"}, "r31"},
181};
182
186
187static constexpr int NumBuiltins =
189
190#define GET_BUILTIN_STR_TABLE
191#include "clang/Basic/BuiltinsHexagon.inc"
192#undef GET_BUILTIN_STR_TABLE
193
194static constexpr Builtin::Info BuiltinInfos[] = {
195#define GET_BUILTIN_INFOS
196#include "clang/Basic/BuiltinsHexagon.inc"
197#undef GET_BUILTIN_INFOS
198};
199
201#define GET_BUILTIN_PREFIXED_INFOS
202#include "clang/Basic/BuiltinsHexagon.inc"
203#undef GET_BUILTIN_PREFIXED_INFOS
204};
205static_assert((std::size(BuiltinInfos) + std::size(PrefixedBuiltinInfos)) ==
207
209 std::string VS = "hvxv" + HVXVersion;
210 if (Feature == VS)
211 return true;
212
213 return llvm::StringSwitch<bool>(Feature)
214 .Case("hexagon", true)
215 .Case("hvx", HasHVX)
216 .Case("hvx-length64b", HasHVX64B)
217 .Case("hvx-length128b", HasHVX128B)
218 .Case("hvx-ieee-fp", HasHVXIeeeFp)
219 .Case("long-calls", UseLongCalls)
220 .Case("audio", HasAudio)
221 .Case("hlx", HasHLX)
222 .Default(false);
223}
224
225struct CPUSuffix {
226 llvm::StringLiteral Name;
227 llvm::StringLiteral Suffix;
228};
229
230static constexpr CPUSuffix Suffixes[] = {
231 {{"hexagonv5"}, {"5"}}, {{"hexagonv55"}, {"55"}},
232 {{"hexagonv60"}, {"60"}}, {{"hexagonv62"}, {"62"}},
233 {{"hexagonv65"}, {"65"}}, {{"hexagonv66"}, {"66"}},
234 {{"hexagonv67"}, {"67"}}, {{"hexagonv67t"}, {"67t"}},
235 {{"hexagonv68"}, {"68"}}, {{"hexagonv69"}, {"69"}},
236 {{"hexagonv71"}, {"71"}}, {{"hexagonv71t"}, {"71t"}},
237 {{"hexagonv73"}, {"73"}}, {{"hexagonv75"}, {"75"}},
238 {{"hexagonv79"}, {"79"}}, {{"hexagonv81"}, {"81"}},
239 {{"hexagonv83"}, {"83"}}, {{"hexagonv85"}, {"85"}}};
240
241std::optional<unsigned> HexagonTargetInfo::getHexagonCPURev(StringRef Name) {
242 StringRef Arch = Name;
243 Arch.consume_front("hexagonv");
244 Arch.consume_back("t");
245
246 unsigned Val;
247 if (!Arch.getAsInteger(0, Val))
248 return Val;
249
250 return std::nullopt;
251}
252
253const char *HexagonTargetInfo::getHexagonCPUSuffix(StringRef Name) {
254 const CPUSuffix *Item = llvm::find_if(
255 Suffixes, [Name](const CPUSuffix &S) { return S.Name == Name; });
256 if (Item == std::end(Suffixes))
257 return nullptr;
258 return Item->Suffix.data();
259}
260
262 SmallVectorImpl<StringRef> &Values) const {
263 for (const CPUSuffix &Suffix : Suffixes)
264 Values.push_back(Suffix.Name);
265}
266
269 return {{&BuiltinStrings, BuiltinInfos},
270 {&BuiltinStrings, PrefixedBuiltinInfos, "__builtin_HEXAGON_"}};
271}
static constexpr CPUSuffix Suffixes[]
Definition Hexagon.cpp:230
static constexpr Builtin::Info PrefixedBuiltinInfos[]
Definition Hexagon.cpp:200
static constexpr llvm::StringTable BuiltinStrings
Definition Mips.cpp:25
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:241
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:102
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:85
static std::optional< unsigned > getHexagonCPURev(StringRef Name)
Definition Hexagon.cpp:241
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:268
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
Definition Hexagon.cpp:183
bool hasBFloat16Type() const override
Determine whether the _BFloat16 type is supported on this target.
Definition Hexagon.cpp:137
static const char * getHexagonCPUSuffix(StringRef Name)
Definition Hexagon.cpp:253
ArrayRef< const char * > getGCCRegNames() const override
Definition Hexagon.cpp:173
void fillValidCPUList(SmallVectorImpl< StringRef > &Values) const override
Fill a SmallVectorImpl with the valid values to setCPU.
Definition Hexagon.cpp:261
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:208
static constexpr int NumBuiltins
Definition X86.cpp:30
Top level wrappers for InstallAPI frontend operations.
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:227
llvm::StringLiteral Name
Definition Hexagon.cpp:226
The info used to represent each builtin.
Definition Builtins.h:82