blob: 7a2d177a562fd41d9c399201c730ae622a9134a8 [file] [log] [blame]
Renato Golinf5f373f2015-05-08 21:04:27 +00001//===-- TargetParser - Parser for target features ---------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements a target parser to recognise hardware features such as
11// FPU/CPU/ARCH names as well as specific support such as HDIV, etc.
12//
13//===----------------------------------------------------------------------===//
14
15#include "llvm/Support/ARMBuildAttributes.h"
16#include "llvm/Support/TargetParser.h"
17#include "llvm/ADT/StringExtras.h"
18#include "llvm/ADT/StringSwitch.h"
Renato Golinebdd12c2015-05-22 20:43:30 +000019#include <cctype>
Renato Golinf5f373f2015-05-08 21:04:27 +000020
21using namespace llvm;
Chandler Carruth799e8802015-08-30 05:27:31 +000022using namespace ARM;
Renato Golinf5f373f2015-05-08 21:04:27 +000023
24namespace {
25
John Brawnd03d2292015-06-05 13:29:24 +000026// List of canonical FPU names (use getFPUSynonym) and which architectural
27// features they correspond to (use getFPUFeatures).
Renato Golinf5f373f2015-05-08 21:04:27 +000028// FIXME: TableGen this.
Javed Absard5526302015-06-29 09:32:29 +000029// The entries must appear in the order listed in ARM::FPUKind for correct indexing
Renato Golinf5f373f2015-05-08 21:04:27 +000030struct {
Chandler Carruth3309ef62015-08-30 07:51:04 +000031 const char *NameCStr;
32 size_t NameLength;
Renato Golinf5f373f2015-05-08 21:04:27 +000033 ARM::FPUKind ID;
Javed Absard5526302015-06-29 09:32:29 +000034 ARM::FPUVersion FPUVersion;
John Brawnd03d2292015-06-05 13:29:24 +000035 ARM::NeonSupportLevel NeonSupport;
36 ARM::FPURestriction Restriction;
Chandler Carruth3309ef62015-08-30 07:51:04 +000037
38 StringRef getName() const { return StringRef(NameCStr, NameLength); }
Renato Golinf5f373f2015-05-08 21:04:27 +000039} FPUNames[] = {
Chandler Carruth799e8802015-08-30 05:27:31 +000040#define ARM_FPU(NAME, KIND, VERSION, NEON_SUPPORT, RESTRICTION) \
Chandler Carruth3309ef62015-08-30 07:51:04 +000041 { NAME, sizeof(NAME) - 1, KIND, VERSION, NEON_SUPPORT, RESTRICTION },
Chandler Carruth799e8802015-08-30 05:27:31 +000042#include "llvm/Support/ARMTargetParser.def"
Renato Golinf5f373f2015-05-08 21:04:27 +000043};
John Brawnd03d2292015-06-05 13:29:24 +000044
Renato Golinf7c0d5f2015-05-27 18:15:37 +000045// List of canonical arch names (use getArchSynonym).
46// This table also provides the build attribute fields for CPU arch
47// and Arch ID, according to the Addenda to the ARM ABI, chapters
48// 2.4 and 2.3.5.2 respectively.
Renato Golin42dad642015-05-28 15:05:18 +000049// FIXME: SubArch values were simplified to fit into the expectations
50// of the triples and are not conforming with their official names.
51// Check to see if the expectation should be changed.
Renato Golinf5f373f2015-05-08 21:04:27 +000052// FIXME: TableGen this.
53struct {
Chandler Carruth3309ef62015-08-30 07:51:04 +000054 const char *NameCStr;
55 size_t NameLength;
Renato Golinf5f373f2015-05-08 21:04:27 +000056 ARM::ArchKind ID;
Chandler Carruth3309ef62015-08-30 07:51:04 +000057 const char *CPUAttrCStr;
58 size_t CPUAttrLength;
59 const char *SubArchCStr;
60 size_t SubArchLength;
Renato Golinf7c0d5f2015-05-27 18:15:37 +000061 ARMBuildAttrs::CPUArch ArchAttr; // Arch ID in build attributes.
Alexandros Lamprineasea33e5e2015-09-05 17:05:33 +000062 unsigned ArchBaseExtensions;
Chandler Carruth3309ef62015-08-30 07:51:04 +000063
64 StringRef getName() const { return StringRef(NameCStr, NameLength); }
65
66 // CPU class in build attributes.
67 StringRef getCPUAttr() const { return StringRef(CPUAttrCStr, CPUAttrLength); }
68
69 // Sub-Arch name.
70 StringRef getSubArch() const { return StringRef(SubArchCStr, SubArchLength); }
Renato Golinf5f373f2015-05-08 21:04:27 +000071} ARCHNames[] = {
Alexandros Lamprineasea33e5e2015-09-05 17:05:33 +000072#define ARM_ARCH(NAME, ID, CPU_ATTR, SUB_ARCH, ARCH_ATTR, ARCH_BASE_EXT) \
Chandler Carruth3309ef62015-08-30 07:51:04 +000073 {NAME, sizeof(NAME) - 1, ID, CPU_ATTR, sizeof(CPU_ATTR) - 1, SUB_ARCH, \
Alexandros Lamprineasea33e5e2015-09-05 17:05:33 +000074 sizeof(SUB_ARCH) - 1, ARCH_ATTR, ARCH_BASE_EXT},
Chandler Carruth799e8802015-08-30 05:27:31 +000075#include "llvm/Support/ARMTargetParser.def"
Renato Golinf5f373f2015-05-08 21:04:27 +000076};
Chandler Carruth3309ef62015-08-30 07:51:04 +000077
Renato Goline1326ca2015-05-28 08:59:03 +000078// List of Arch Extension names.
Renato Golinf5f373f2015-05-08 21:04:27 +000079// FIXME: TableGen this.
80struct {
Chandler Carruth3309ef62015-08-30 07:51:04 +000081 const char *NameCStr;
82 size_t NameLength;
Alexandros Lamprineas4ea70752015-07-27 22:26:59 +000083 unsigned ID;
Chandler Carruth3309ef62015-08-30 07:51:04 +000084
85 StringRef getName() const { return StringRef(NameCStr, NameLength); }
Renato Golinf5f373f2015-05-08 21:04:27 +000086} ARCHExtNames[] = {
Chandler Carruth3309ef62015-08-30 07:51:04 +000087#define ARM_ARCH_EXT_NAME(NAME, ID) { NAME, sizeof(NAME) - 1, ID },
Chandler Carruth799e8802015-08-30 05:27:31 +000088#include "llvm/Support/ARMTargetParser.def"
Alexandros Lamprineas4ea70752015-07-27 22:26:59 +000089};
Chandler Carruth3309ef62015-08-30 07:51:04 +000090
Alexandros Lamprineas4ea70752015-07-27 22:26:59 +000091// List of HWDiv names (use getHWDivSynonym) and which architectural
92// features they correspond to (use getHWDivFeatures).
93// FIXME: TableGen this.
94struct {
Chandler Carruth3309ef62015-08-30 07:51:04 +000095 const char *NameCStr;
96 size_t NameLength;
Alexandros Lamprineas4ea70752015-07-27 22:26:59 +000097 unsigned ID;
Chandler Carruth3309ef62015-08-30 07:51:04 +000098
99 StringRef getName() const { return StringRef(NameCStr, NameLength); }
Alexandros Lamprineas4ea70752015-07-27 22:26:59 +0000100} HWDivNames[] = {
Chandler Carruth3309ef62015-08-30 07:51:04 +0000101#define ARM_HW_DIV_NAME(NAME, ID) { NAME, sizeof(NAME) - 1, ID },
Chandler Carruth799e8802015-08-30 05:27:31 +0000102#include "llvm/Support/ARMTargetParser.def"
Renato Golinf5f373f2015-05-08 21:04:27 +0000103};
Chandler Carruth3309ef62015-08-30 07:51:04 +0000104
Renato Goline8048f02015-05-20 15:05:07 +0000105// List of CPU names and their arches.
106// The same CPU can have multiple arches and can be default on multiple arches.
107// When finding the Arch for a CPU, first-found prevails. Sort them accordingly.
Renato Golin7374fcd2015-05-28 12:10:37 +0000108// When this becomes table-generated, we'd probably need two tables.
Renato Goline8048f02015-05-20 15:05:07 +0000109// FIXME: TableGen this.
110struct {
Chandler Carruth3309ef62015-08-30 07:51:04 +0000111 const char *NameCStr;
112 size_t NameLength;
Renato Goline8048f02015-05-20 15:05:07 +0000113 ARM::ArchKind ArchID;
Alexandros Lamprineasfcd93d52015-07-15 10:46:21 +0000114 bool Default; // is $Name the default CPU for $ArchID ?
Alexandros Lamprineasea33e5e2015-09-05 17:05:33 +0000115 unsigned DefaultExtensions;
Chandler Carruth3309ef62015-08-30 07:51:04 +0000116
117 StringRef getName() const { return StringRef(NameCStr, NameLength); }
Renato Goline8048f02015-05-20 15:05:07 +0000118} CPUNames[] = {
Alexandros Lamprineasea33e5e2015-09-05 17:05:33 +0000119#define ARM_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \
120 { NAME, sizeof(NAME) - 1, ID, IS_DEFAULT, DEFAULT_EXT },
Chandler Carruth799e8802015-08-30 05:27:31 +0000121#include "llvm/Support/ARMTargetParser.def"
Renato Goline8048f02015-05-20 15:05:07 +0000122};
Renato Golinf5f373f2015-05-08 21:04:27 +0000123
124} // namespace
125
Renato Golinf5f373f2015-05-08 21:04:27 +0000126// ======================================================= //
127// Information by ID
128// ======================================================= //
129
Chandler Carruth3309ef62015-08-30 07:51:04 +0000130StringRef llvm::ARM::getFPUName(unsigned FPUKind) {
Renato Goline8048f02015-05-20 15:05:07 +0000131 if (FPUKind >= ARM::FK_LAST)
Chandler Carruth3309ef62015-08-30 07:51:04 +0000132 return StringRef();
133 return FPUNames[FPUKind].getName();
Renato Golinf5f373f2015-05-08 21:04:27 +0000134}
135
Chandler Carruthbb47b9a2015-08-30 02:09:48 +0000136unsigned llvm::ARM::getFPUVersion(unsigned FPUKind) {
John Brawnd03d2292015-06-05 13:29:24 +0000137 if (FPUKind >= ARM::FK_LAST)
138 return 0;
139 return FPUNames[FPUKind].FPUVersion;
140}
141
Chandler Carruthbb47b9a2015-08-30 02:09:48 +0000142unsigned llvm::ARM::getFPUNeonSupportLevel(unsigned FPUKind) {
John Brawnd03d2292015-06-05 13:29:24 +0000143 if (FPUKind >= ARM::FK_LAST)
144 return 0;
145 return FPUNames[FPUKind].NeonSupport;
146}
147
Chandler Carruthbb47b9a2015-08-30 02:09:48 +0000148unsigned llvm::ARM::getFPURestriction(unsigned FPUKind) {
John Brawnd03d2292015-06-05 13:29:24 +0000149 if (FPUKind >= ARM::FK_LAST)
150 return 0;
151 return FPUNames[FPUKind].Restriction;
152}
153
Chandler Carruthbb47b9a2015-08-30 02:09:48 +0000154unsigned llvm::ARM::getDefaultFPU(StringRef CPU) {
Chandler Carruth822d54a2015-08-30 09:01:38 +0000155 return StringSwitch<unsigned>(CPU)
Alexandros Lamprineasea33e5e2015-09-05 17:05:33 +0000156#define ARM_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \
Chandler Carruth822d54a2015-08-30 09:01:38 +0000157 .Case(NAME, DEFAULT_FPU)
158#include "llvm/Support/ARMTargetParser.def"
159 .Default(ARM::FK_INVALID);
Alexandros Lamprineasfcd93d52015-07-15 10:46:21 +0000160}
161
Chandler Carruthbb47b9a2015-08-30 02:09:48 +0000162bool llvm::ARM::getHWDivFeatures(unsigned HWDivKind,
Chandler Carruth4fc3a982015-08-30 02:17:15 +0000163 std::vector<const char *> &Features) {
Alexandros Lamprineas4ea70752015-07-27 22:26:59 +0000164
165 if (HWDivKind == ARM::AEK_INVALID)
166 return false;
167
Chandler Carruth4fc3a982015-08-30 02:17:15 +0000168 if (HWDivKind & ARM::AEK_HWDIVARM)
Alexandros Lamprineas4ea70752015-07-27 22:26:59 +0000169 Features.push_back("+hwdiv-arm");
170 else
171 Features.push_back("-hwdiv-arm");
172
173 if (HWDivKind & ARM::AEK_HWDIV)
174 Features.push_back("+hwdiv");
175 else
176 Features.push_back("-hwdiv");
177
178 return true;
179}
180
Alexandros Lamprineasea33e5e2015-09-05 17:05:33 +0000181bool llvm::ARM::getExtensionFeatures(unsigned Extensions,
182 std::vector<const char *> &Features) {
183
184 if (Extensions == ARM::AEK_INVALID)
185 return false;
186
187 if (Extensions & ARM::AEK_CRC)
188 Features.push_back("+crc");
189 else
190 Features.push_back("-crc");
191
Artyom Skrobovcf296442015-09-24 17:31:16 +0000192 if (Extensions & ARM::AEK_DSP)
Artyom Skrobov5a6e3942015-10-23 17:19:19 +0000193 Features.push_back("+dsp");
Artyom Skrobovcf296442015-09-24 17:31:16 +0000194 else
Artyom Skrobov5a6e3942015-10-23 17:19:19 +0000195 Features.push_back("-dsp");
Artyom Skrobovcf296442015-09-24 17:31:16 +0000196
Alexandros Lamprineasea33e5e2015-09-05 17:05:33 +0000197 return getHWDivFeatures(Extensions, Features);
198}
199
Chandler Carruthbb47b9a2015-08-30 02:09:48 +0000200bool llvm::ARM::getFPUFeatures(unsigned FPUKind,
Chandler Carruth4fc3a982015-08-30 02:17:15 +0000201 std::vector<const char *> &Features) {
John Brawnd03d2292015-06-05 13:29:24 +0000202
203 if (FPUKind >= ARM::FK_LAST || FPUKind == ARM::FK_INVALID)
204 return false;
205
206 // fp-only-sp and d16 subtarget features are independent of each other, so we
207 // must enable/disable both.
208 switch (FPUNames[FPUKind].Restriction) {
209 case ARM::FR_SP_D16:
210 Features.push_back("+fp-only-sp");
211 Features.push_back("+d16");
212 break;
213 case ARM::FR_D16:
214 Features.push_back("-fp-only-sp");
215 Features.push_back("+d16");
216 break;
217 case ARM::FR_None:
218 Features.push_back("-fp-only-sp");
219 Features.push_back("-d16");
220 break;
221 }
222
223 // FPU version subtarget features are inclusive of lower-numbered ones, so
224 // enable the one corresponding to this version and disable all that are
John Brawnd9e39d52015-06-12 09:38:51 +0000225 // higher. We also have to make sure to disable fp16 when vfp4 is disabled,
226 // as +vfp4 implies +fp16 but -vfp4 does not imply -fp16.
John Brawnd03d2292015-06-05 13:29:24 +0000227 switch (FPUNames[FPUKind].FPUVersion) {
Javed Absard5526302015-06-29 09:32:29 +0000228 case ARM::FV_VFPV5:
John Brawnd03d2292015-06-05 13:29:24 +0000229 Features.push_back("+fp-armv8");
230 break;
Javed Absard5526302015-06-29 09:32:29 +0000231 case ARM::FV_VFPV4:
John Brawnd03d2292015-06-05 13:29:24 +0000232 Features.push_back("+vfp4");
233 Features.push_back("-fp-armv8");
234 break;
Javed Absard5526302015-06-29 09:32:29 +0000235 case ARM::FV_VFPV3_FP16:
236 Features.push_back("+vfp3");
237 Features.push_back("+fp16");
238 Features.push_back("-vfp4");
239 Features.push_back("-fp-armv8");
240 break;
241 case ARM::FV_VFPV3:
John Brawnd03d2292015-06-05 13:29:24 +0000242 Features.push_back("+vfp3");
John Brawnd9e39d52015-06-12 09:38:51 +0000243 Features.push_back("-fp16");
John Brawnd03d2292015-06-05 13:29:24 +0000244 Features.push_back("-vfp4");
245 Features.push_back("-fp-armv8");
246 break;
Javed Absard5526302015-06-29 09:32:29 +0000247 case ARM::FV_VFPV2:
John Brawnd03d2292015-06-05 13:29:24 +0000248 Features.push_back("+vfp2");
249 Features.push_back("-vfp3");
John Brawnd9e39d52015-06-12 09:38:51 +0000250 Features.push_back("-fp16");
John Brawnd03d2292015-06-05 13:29:24 +0000251 Features.push_back("-vfp4");
252 Features.push_back("-fp-armv8");
253 break;
Javed Absard5526302015-06-29 09:32:29 +0000254 case ARM::FV_NONE:
John Brawnd03d2292015-06-05 13:29:24 +0000255 Features.push_back("-vfp2");
256 Features.push_back("-vfp3");
John Brawnd9e39d52015-06-12 09:38:51 +0000257 Features.push_back("-fp16");
John Brawnd03d2292015-06-05 13:29:24 +0000258 Features.push_back("-vfp4");
259 Features.push_back("-fp-armv8");
260 break;
261 }
262
263 // crypto includes neon, so we handle this similarly to FPU version.
264 switch (FPUNames[FPUKind].NeonSupport) {
265 case ARM::NS_Crypto:
Alexandros Lamprineasea33e5e2015-09-05 17:05:33 +0000266 Features.push_back("+neon");
John Brawnd03d2292015-06-05 13:29:24 +0000267 Features.push_back("+crypto");
268 break;
269 case ARM::NS_Neon:
270 Features.push_back("+neon");
271 Features.push_back("-crypto");
272 break;
273 case ARM::NS_None:
274 Features.push_back("-neon");
275 Features.push_back("-crypto");
276 break;
277 }
278
279 return true;
280}
281
Chandler Carruth3309ef62015-08-30 07:51:04 +0000282StringRef llvm::ARM::getArchName(unsigned ArchKind) {
Renato Goline8048f02015-05-20 15:05:07 +0000283 if (ArchKind >= ARM::AK_LAST)
Chandler Carruth3309ef62015-08-30 07:51:04 +0000284 return StringRef();
285 return ARCHNames[ArchKind].getName();
Renato Golinf5f373f2015-05-08 21:04:27 +0000286}
287
Chandler Carruth3309ef62015-08-30 07:51:04 +0000288StringRef llvm::ARM::getCPUAttr(unsigned ArchKind) {
Renato Goline8048f02015-05-20 15:05:07 +0000289 if (ArchKind >= ARM::AK_LAST)
Chandler Carruth3309ef62015-08-30 07:51:04 +0000290 return StringRef();
291 return ARCHNames[ArchKind].getCPUAttr();
Renato Golinf5f373f2015-05-08 21:04:27 +0000292}
293
Chandler Carruth3309ef62015-08-30 07:51:04 +0000294StringRef llvm::ARM::getSubArch(unsigned ArchKind) {
Renato Golin42dad642015-05-28 15:05:18 +0000295 if (ArchKind >= ARM::AK_LAST)
Chandler Carruth3309ef62015-08-30 07:51:04 +0000296 return StringRef();
297 return ARCHNames[ArchKind].getSubArch();
Renato Golin42dad642015-05-28 15:05:18 +0000298}
299
Chandler Carruthbb47b9a2015-08-30 02:09:48 +0000300unsigned llvm::ARM::getArchAttr(unsigned ArchKind) {
Renato Goline8048f02015-05-20 15:05:07 +0000301 if (ArchKind >= ARM::AK_LAST)
302 return ARMBuildAttrs::CPUArch::Pre_v4;
Renato Golinf7c0d5f2015-05-27 18:15:37 +0000303 return ARCHNames[ArchKind].ArchAttr;
Renato Golinf5f373f2015-05-08 21:04:27 +0000304}
305
Chandler Carruth3309ef62015-08-30 07:51:04 +0000306StringRef llvm::ARM::getArchExtName(unsigned ArchExtKind) {
Alexandros Lamprineas4ea70752015-07-27 22:26:59 +0000307 for (const auto AE : ARCHExtNames) {
308 if (ArchExtKind == AE.ID)
Chandler Carruth3309ef62015-08-30 07:51:04 +0000309 return AE.getName();
Alexandros Lamprineas4ea70752015-07-27 22:26:59 +0000310 }
Chandler Carruth3309ef62015-08-30 07:51:04 +0000311 return StringRef();
Alexandros Lamprineas4ea70752015-07-27 22:26:59 +0000312}
313
Chandler Carruth3309ef62015-08-30 07:51:04 +0000314StringRef llvm::ARM::getHWDivName(unsigned HWDivKind) {
Alexandros Lamprineas4ea70752015-07-27 22:26:59 +0000315 for (const auto D : HWDivNames) {
316 if (HWDivKind == D.ID)
Chandler Carruth3309ef62015-08-30 07:51:04 +0000317 return D.getName();
Alexandros Lamprineas4ea70752015-07-27 22:26:59 +0000318 }
Chandler Carruth3309ef62015-08-30 07:51:04 +0000319 return StringRef();
Renato Goline8048f02015-05-20 15:05:07 +0000320}
321
Alexandros Lamprineasea33e5e2015-09-05 17:05:33 +0000322unsigned llvm::ARM::getDefaultExtensions(StringRef CPU) {
323 for (const auto C : CPUNames) {
324 if (CPU == C.getName())
325 return (ARCHNames[C.ArchID].ArchBaseExtensions | C.DefaultExtensions);
326 }
327 return ARM::AEK_INVALID;
328}
329
Chandler Carruth3309ef62015-08-30 07:51:04 +0000330StringRef llvm::ARM::getDefaultCPU(StringRef Arch) {
Renato Goline8048f02015-05-20 15:05:07 +0000331 unsigned AK = parseArch(Arch);
332 if (AK == ARM::AK_INVALID)
Chandler Carruth3309ef62015-08-30 07:51:04 +0000333 return StringRef();
Renato Goline8048f02015-05-20 15:05:07 +0000334
335 // Look for multiple AKs to find the default for pair AK+Name.
336 for (const auto CPU : CPUNames) {
337 if (CPU.ArchID == AK && CPU.Default)
Chandler Carruth3309ef62015-08-30 07:51:04 +0000338 return CPU.getName();
Renato Goline8048f02015-05-20 15:05:07 +0000339 }
Chandler Carruth3309ef62015-08-30 07:51:04 +0000340 return StringRef();
Renato Golinf5f373f2015-05-08 21:04:27 +0000341}
342
343// ======================================================= //
344// Parsers
345// ======================================================= //
346
Chandler Carruthbb47b9a2015-08-30 02:09:48 +0000347static StringRef getHWDivSynonym(StringRef HWDiv) {
Alexandros Lamprineas4ea70752015-07-27 22:26:59 +0000348 return StringSwitch<StringRef>(HWDiv)
Chandler Carruth4fc3a982015-08-30 02:17:15 +0000349 .Case("thumb,arm", "arm,thumb")
350 .Default(HWDiv);
Alexandros Lamprineas4ea70752015-07-27 22:26:59 +0000351}
352
Chandler Carruthbb47b9a2015-08-30 02:09:48 +0000353static StringRef getFPUSynonym(StringRef FPU) {
Renato Golinf5f373f2015-05-08 21:04:27 +0000354 return StringSwitch<StringRef>(FPU)
Chandler Carruth4fc3a982015-08-30 02:17:15 +0000355 .Cases("fpa", "fpe2", "fpe3", "maverick", "invalid") // Unsupported
356 .Case("vfp2", "vfpv2")
357 .Case("vfp3", "vfpv3")
358 .Case("vfp4", "vfpv4")
359 .Case("vfp3-d16", "vfpv3-d16")
360 .Case("vfp4-d16", "vfpv4-d16")
361 .Cases("fp4-sp-d16", "vfpv4-sp-d16", "fpv4-sp-d16")
362 .Cases("fp4-dp-d16", "fpv4-dp-d16", "vfpv4-d16")
363 .Case("fp5-sp-d16", "fpv5-sp-d16")
364 .Cases("fp5-dp-d16", "fpv5-dp-d16", "fpv5-d16")
365 // FIXME: Clang uses it, but it's bogus, since neon defaults to vfpv3.
366 .Case("neon-vfpv3", "neon")
367 .Default(FPU);
Renato Golinf5f373f2015-05-08 21:04:27 +0000368}
369
Chandler Carruthbb47b9a2015-08-30 02:09:48 +0000370static StringRef getArchSynonym(StringRef Arch) {
Renato Golinf5f373f2015-05-08 21:04:27 +0000371 return StringSwitch<StringRef>(Arch)
Artyom Skrobov2c2f3782015-11-12 15:51:41 +0000372 .Case("v5", "v5t")
373 .Case("v5e", "v5te")
374 .Case("v6hl", "v6k")
375 .Cases("v6m", "v6sm", "v6s-m", "v6-m")
376 .Cases("v7", "v7a", "v7hl", "v7l", "v7-a")
Chandler Carruth4fc3a982015-08-30 02:17:15 +0000377 .Case("v7r", "v7-r")
378 .Case("v7m", "v7-m")
379 .Case("v7em", "v7e-m")
380 .Cases("v8", "v8a", "aarch64", "arm64", "v8-a")
381 .Case("v8.1a", "v8.1-a")
382 .Default(Arch);
Renato Golinf5f373f2015-05-08 21:04:27 +0000383}
384
Renato Goline8048f02015-05-20 15:05:07 +0000385// MArch is expected to be of the form (arm|thumb)?(eb)?(v.+)?(eb)?, but
386// (iwmmxt|xscale)(eb)? is also permitted. If the former, return
Renato Golinebdd12c2015-05-22 20:43:30 +0000387// "v.+", if the latter, return unmodified string, minus 'eb'.
388// If invalid, return empty string.
Chandler Carruthbb47b9a2015-08-30 02:09:48 +0000389StringRef llvm::ARM::getCanonicalArchName(StringRef Arch) {
Renato Goline8048f02015-05-20 15:05:07 +0000390 size_t offset = StringRef::npos;
391 StringRef A = Arch;
Renato Golinb6b9e052015-05-21 13:52:20 +0000392 StringRef Error = "";
Renato Goline8048f02015-05-20 15:05:07 +0000393
394 // Begins with "arm" / "thumb", move past it.
Renato Golinebdd12c2015-05-22 20:43:30 +0000395 if (A.startswith("arm64"))
396 offset = 5;
397 else if (A.startswith("arm"))
Renato Goline8048f02015-05-20 15:05:07 +0000398 offset = 3;
399 else if (A.startswith("thumb"))
400 offset = 5;
Renato Golinb6b9e052015-05-21 13:52:20 +0000401 else if (A.startswith("aarch64")) {
402 offset = 7;
403 // AArch64 uses "_be", not "eb" suffix.
404 if (A.find("eb") != StringRef::npos)
405 return Error;
Chandler Carruth4fc3a982015-08-30 02:17:15 +0000406 if (A.substr(offset, 3) == "_be")
Renato Golinb6b9e052015-05-21 13:52:20 +0000407 offset += 3;
408 }
409
Renato Goline8048f02015-05-20 15:05:07 +0000410 // Ex. "armebv7", move past the "eb".
411 if (offset != StringRef::npos && A.substr(offset, 2) == "eb")
412 offset += 2;
413 // Or, if it ends with eb ("armv7eb"), chop it off.
414 else if (A.endswith("eb"))
415 A = A.substr(0, A.size() - 2);
Renato Golinebdd12c2015-05-22 20:43:30 +0000416 // Trim the head
417 if (offset != StringRef::npos)
Renato Goline8048f02015-05-20 15:05:07 +0000418 A = A.substr(offset);
419
Renato Golinebdd12c2015-05-22 20:43:30 +0000420 // Empty string means offset reached the end, which means it's valid.
Renato Goline8048f02015-05-20 15:05:07 +0000421 if (A.empty())
422 return Arch;
423
Renato Golinebdd12c2015-05-22 20:43:30 +0000424 // Only match non-marketing names
425 if (offset != StringRef::npos) {
Chandler Carruth4fc3a982015-08-30 02:17:15 +0000426 // Must start with 'vN'.
Renato Golinebdd12c2015-05-22 20:43:30 +0000427 if (A[0] != 'v' || !std::isdigit(A[1]))
428 return Error;
429 // Can't have an extra 'eb'.
430 if (A.find("eb") != StringRef::npos)
431 return Error;
432 }
Renato Goline8048f02015-05-20 15:05:07 +0000433
Renato Golinebdd12c2015-05-22 20:43:30 +0000434 // Arch will either be a 'v' name (v7a) or a marketing name (xscale).
Renato Goline8048f02015-05-20 15:05:07 +0000435 return A;
436}
437
Chandler Carruthbb47b9a2015-08-30 02:09:48 +0000438unsigned llvm::ARM::parseHWDiv(StringRef HWDiv) {
Alexandros Lamprineas4ea70752015-07-27 22:26:59 +0000439 StringRef Syn = getHWDivSynonym(HWDiv);
440 for (const auto D : HWDivNames) {
Chandler Carruth3309ef62015-08-30 07:51:04 +0000441 if (Syn == D.getName())
Alexandros Lamprineas4ea70752015-07-27 22:26:59 +0000442 return D.ID;
443 }
444 return ARM::AEK_INVALID;
445}
446
Chandler Carruthbb47b9a2015-08-30 02:09:48 +0000447unsigned llvm::ARM::parseFPU(StringRef FPU) {
Renato Golinf5f373f2015-05-08 21:04:27 +0000448 StringRef Syn = getFPUSynonym(FPU);
449 for (const auto F : FPUNames) {
Chandler Carruth3309ef62015-08-30 07:51:04 +0000450 if (Syn == F.getName())
Renato Golinf5f373f2015-05-08 21:04:27 +0000451 return F.ID;
452 }
Renato Golin35de35d2015-05-12 10:33:58 +0000453 return ARM::FK_INVALID;
Renato Golinf5f373f2015-05-08 21:04:27 +0000454}
455
Renato Goline8048f02015-05-20 15:05:07 +0000456// Allows partial match, ex. "v7a" matches "armv7a".
Chandler Carruthbb47b9a2015-08-30 02:09:48 +0000457unsigned llvm::ARM::parseArch(StringRef Arch) {
Artyom Skrobov85aebc82015-06-04 21:26:58 +0000458 Arch = getCanonicalArchName(Arch);
Renato Golinf5f373f2015-05-08 21:04:27 +0000459 StringRef Syn = getArchSynonym(Arch);
460 for (const auto A : ARCHNames) {
Chandler Carruth3309ef62015-08-30 07:51:04 +0000461 if (A.getName().endswith(Syn))
Renato Golinf5f373f2015-05-08 21:04:27 +0000462 return A.ID;
463 }
Renato Golin35de35d2015-05-12 10:33:58 +0000464 return ARM::AK_INVALID;
Renato Golinf5f373f2015-05-08 21:04:27 +0000465}
466
Chandler Carruthbb47b9a2015-08-30 02:09:48 +0000467unsigned llvm::ARM::parseArchExt(StringRef ArchExt) {
Renato Golinf5f373f2015-05-08 21:04:27 +0000468 for (const auto A : ARCHExtNames) {
Chandler Carruth3309ef62015-08-30 07:51:04 +0000469 if (ArchExt == A.getName())
Renato Golinf5f373f2015-05-08 21:04:27 +0000470 return A.ID;
471 }
Renato Golin35de35d2015-05-12 10:33:58 +0000472 return ARM::AEK_INVALID;
Renato Golinf5f373f2015-05-08 21:04:27 +0000473}
474
Chandler Carruthbb47b9a2015-08-30 02:09:48 +0000475unsigned llvm::ARM::parseCPUArch(StringRef CPU) {
Renato Goline8048f02015-05-20 15:05:07 +0000476 for (const auto C : CPUNames) {
Chandler Carruth3309ef62015-08-30 07:51:04 +0000477 if (CPU == C.getName())
Renato Goline8048f02015-05-20 15:05:07 +0000478 return C.ArchID;
479 }
480 return ARM::AK_INVALID;
481}
482
Renato Golinb6b9e052015-05-21 13:52:20 +0000483// ARM, Thumb, AArch64
Chandler Carruthbb47b9a2015-08-30 02:09:48 +0000484unsigned llvm::ARM::parseArchISA(StringRef Arch) {
Renato Golinb6b9e052015-05-21 13:52:20 +0000485 return StringSwitch<unsigned>(Arch)
486 .StartsWith("aarch64", ARM::IK_AARCH64)
Chandler Carruth4fc3a982015-08-30 02:17:15 +0000487 .StartsWith("arm64", ARM::IK_AARCH64)
488 .StartsWith("thumb", ARM::IK_THUMB)
489 .StartsWith("arm", ARM::IK_ARM)
Renato Golinb6b9e052015-05-21 13:52:20 +0000490 .Default(ARM::EK_INVALID);
491}
492
493// Little/Big endian
Chandler Carruthbb47b9a2015-08-30 02:09:48 +0000494unsigned llvm::ARM::parseArchEndian(StringRef Arch) {
Chandler Carruth4fc3a982015-08-30 02:17:15 +0000495 if (Arch.startswith("armeb") || Arch.startswith("thumbeb") ||
Renato Golinb6b9e052015-05-21 13:52:20 +0000496 Arch.startswith("aarch64_be"))
497 return ARM::EK_BIG;
498
499 if (Arch.startswith("arm") || Arch.startswith("thumb")) {
500 if (Arch.endswith("eb"))
501 return ARM::EK_BIG;
502 else
503 return ARM::EK_LITTLE;
504 }
505
506 if (Arch.startswith("aarch64"))
507 return ARM::EK_LITTLE;
508
509 return ARM::EK_INVALID;
510}
511
Renato Golinfadc2102015-05-22 18:17:55 +0000512// Profile A/R/M
Chandler Carruthbb47b9a2015-08-30 02:09:48 +0000513unsigned llvm::ARM::parseArchProfile(StringRef Arch) {
Renato Golinfadc2102015-05-22 18:17:55 +0000514 Arch = getCanonicalArchName(Arch);
Chandler Carruth4fc3a982015-08-30 02:17:15 +0000515 switch (parseArch(Arch)) {
Renato Golinfadc2102015-05-22 18:17:55 +0000516 case ARM::AK_ARMV6M:
517 case ARM::AK_ARMV7M:
Renato Golinfadc2102015-05-22 18:17:55 +0000518 case ARM::AK_ARMV7EM:
519 return ARM::PK_M;
520 case ARM::AK_ARMV7R:
521 return ARM::PK_R;
Renato Golinfadc2102015-05-22 18:17:55 +0000522 case ARM::AK_ARMV7A:
Tim Northover2d4d1612015-10-28 22:36:05 +0000523 case ARM::AK_ARMV7K:
Renato Golinfadc2102015-05-22 18:17:55 +0000524 case ARM::AK_ARMV8A:
525 case ARM::AK_ARMV8_1A:
526 return ARM::PK_A;
527 }
528 return ARM::PK_INVALID;
529}
530
Renato Golinebdd12c2015-05-22 20:43:30 +0000531// Version number (ex. v7 = 7).
Chandler Carruthbb47b9a2015-08-30 02:09:48 +0000532unsigned llvm::ARM::parseArchVersion(StringRef Arch) {
Renato Golinfadc2102015-05-22 18:17:55 +0000533 Arch = getCanonicalArchName(Arch);
Chandler Carruth4fc3a982015-08-30 02:17:15 +0000534 switch (parseArch(Arch)) {
Renato Golinfadc2102015-05-22 18:17:55 +0000535 case ARM::AK_ARMV2:
536 case ARM::AK_ARMV2A:
537 return 2;
538 case ARM::AK_ARMV3:
539 case ARM::AK_ARMV3M:
540 return 3;
541 case ARM::AK_ARMV4:
542 case ARM::AK_ARMV4T:
543 return 4;
Renato Golinfadc2102015-05-22 18:17:55 +0000544 case ARM::AK_ARMV5T:
545 case ARM::AK_ARMV5TE:
546 case ARM::AK_IWMMXT:
547 case ARM::AK_IWMMXT2:
548 case ARM::AK_XSCALE:
Renato Golinfadc2102015-05-22 18:17:55 +0000549 case ARM::AK_ARMV5TEJ:
550 return 5;
551 case ARM::AK_ARMV6:
552 case ARM::AK_ARMV6J:
553 case ARM::AK_ARMV6K:
554 case ARM::AK_ARMV6T2:
555 case ARM::AK_ARMV6Z:
556 case ARM::AK_ARMV6ZK:
557 case ARM::AK_ARMV6M:
Renato Golinfadc2102015-05-22 18:17:55 +0000558 return 6;
Renato Golinfadc2102015-05-22 18:17:55 +0000559 case ARM::AK_ARMV7A:
560 case ARM::AK_ARMV7R:
561 case ARM::AK_ARMV7M:
Renato Golinfadc2102015-05-22 18:17:55 +0000562 case ARM::AK_ARMV7S:
563 case ARM::AK_ARMV7EM:
Vedant Kumar366dd9fd2015-08-21 21:52:48 +0000564 case ARM::AK_ARMV7K:
Renato Golinfadc2102015-05-22 18:17:55 +0000565 return 7;
566 case ARM::AK_ARMV8A:
567 case ARM::AK_ARMV8_1A:
568 return 8;
569 }
570 return 0;
571}