blob: 315e0f793ade6cb335b2f4318a37992a801e611a [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;
22
23namespace {
24
John Brawnd03d2292015-06-05 13:29:24 +000025// List of canonical FPU names (use getFPUSynonym) and which architectural
26// features they correspond to (use getFPUFeatures).
Renato Golinf5f373f2015-05-08 21:04:27 +000027// FIXME: TableGen this.
Javed Absard5526302015-06-29 09:32:29 +000028// The entries must appear in the order listed in ARM::FPUKind for correct indexing
Renato Golinf5f373f2015-05-08 21:04:27 +000029struct {
30 const char * Name;
31 ARM::FPUKind ID;
Javed Absard5526302015-06-29 09:32:29 +000032 ARM::FPUVersion FPUVersion;
John Brawnd03d2292015-06-05 13:29:24 +000033 ARM::NeonSupportLevel NeonSupport;
34 ARM::FPURestriction Restriction;
Renato Golinf5f373f2015-05-08 21:04:27 +000035} FPUNames[] = {
Javed Absard5526302015-06-29 09:32:29 +000036 { "invalid", ARM::FK_INVALID, ARM::FV_NONE, ARM::NS_None, ARM::FR_None},
37 { "none", ARM::FK_NONE, ARM::FV_NONE, ARM::NS_None, ARM::FR_None},
38 { "vfp", ARM::FK_VFP, ARM::FV_VFPV2, ARM::NS_None, ARM::FR_None},
39 { "vfpv2", ARM::FK_VFPV2, ARM::FV_VFPV2, ARM::NS_None, ARM::FR_None},
40 { "vfpv3", ARM::FK_VFPV3, ARM::FV_VFPV3, ARM::NS_None, ARM::FR_None},
41 { "vfpv3-fp16", ARM::FK_VFPV3_FP16, ARM::FV_VFPV3_FP16, ARM::NS_None, ARM::FR_None},
42 { "vfpv3-d16", ARM::FK_VFPV3_D16, ARM::FV_VFPV3, ARM::NS_None, ARM::FR_D16},
43 { "vfpv3-d16-fp16", ARM::FK_VFPV3_D16_FP16, ARM::FV_VFPV3_FP16, ARM::NS_None, ARM::FR_D16},
44 { "vfpv3xd", ARM::FK_VFPV3XD, ARM::FV_VFPV3, ARM::NS_None, ARM::FR_SP_D16},
45 { "vfpv3xd-fp16", ARM::FK_VFPV3XD_FP16, ARM::FV_VFPV3_FP16, ARM::NS_None, ARM::FR_SP_D16},
46 { "vfpv4", ARM::FK_VFPV4, ARM::FV_VFPV4, ARM::NS_None, ARM::FR_None},
47 { "vfpv4-d16", ARM::FK_VFPV4_D16, ARM::FV_VFPV4, ARM::NS_None, ARM::FR_D16},
48 { "fpv4-sp-d16", ARM::FK_FPV4_SP_D16, ARM::FV_VFPV4, ARM::NS_None, ARM::FR_SP_D16},
49 { "fpv5-d16", ARM::FK_FPV5_D16, ARM::FV_VFPV5, ARM::NS_None, ARM::FR_D16},
50 { "fpv5-sp-d16", ARM::FK_FPV5_SP_D16, ARM::FV_VFPV5, ARM::NS_None, ARM::FR_SP_D16},
51 { "fp-armv8", ARM::FK_FP_ARMV8, ARM::FV_VFPV5, ARM::NS_None, ARM::FR_None},
52 { "neon", ARM::FK_NEON, ARM::FV_VFPV3, ARM::NS_Neon, ARM::FR_None},
53 { "neon-fp16", ARM::FK_NEON_FP16, ARM::FV_VFPV3_FP16, ARM::NS_Neon, ARM::FR_None},
54 { "neon-vfpv4", ARM::FK_NEON_VFPV4, ARM::FV_VFPV4, ARM::NS_Neon, ARM::FR_None},
55 { "neon-fp-armv8", ARM::FK_NEON_FP_ARMV8, ARM::FV_VFPV5, ARM::NS_Neon, ARM::FR_None},
John Brawnd03d2292015-06-05 13:29:24 +000056 { "crypto-neon-fp-armv8",
Javed Absard5526302015-06-29 09:32:29 +000057 ARM::FK_CRYPTO_NEON_FP_ARMV8, ARM::FV_VFPV5, ARM::NS_Crypto, ARM::FR_None},
58 { "softvfp", ARM::FK_SOFTVFP, ARM::FV_NONE, ARM::NS_None, ARM::FR_None},
Renato Golinf5f373f2015-05-08 21:04:27 +000059};
John Brawnd03d2292015-06-05 13:29:24 +000060
Renato Golinf7c0d5f2015-05-27 18:15:37 +000061// List of canonical arch names (use getArchSynonym).
62// This table also provides the build attribute fields for CPU arch
63// and Arch ID, according to the Addenda to the ARM ABI, chapters
64// 2.4 and 2.3.5.2 respectively.
Renato Golin42dad642015-05-28 15:05:18 +000065// FIXME: SubArch values were simplified to fit into the expectations
66// of the triples and are not conforming with their official names.
67// Check to see if the expectation should be changed.
Renato Golinf5f373f2015-05-08 21:04:27 +000068// FIXME: TableGen this.
69struct {
70 const char *Name;
71 ARM::ArchKind ID;
Renato Golinf7c0d5f2015-05-27 18:15:37 +000072 const char *CPUAttr; // CPU class in build attributes.
Renato Golin42dad642015-05-28 15:05:18 +000073 const char *SubArch; // Sub-Arch name.
Renato Golinf7c0d5f2015-05-27 18:15:37 +000074 ARMBuildAttrs::CPUArch ArchAttr; // Arch ID in build attributes.
Renato Golinf5f373f2015-05-08 21:04:27 +000075} ARCHNames[] = {
Renato Golin42dad642015-05-28 15:05:18 +000076 { "invalid", ARM::AK_INVALID, nullptr, nullptr, ARMBuildAttrs::CPUArch::Pre_v4 },
77 { "armv2", ARM::AK_ARMV2, "2", "v2", ARMBuildAttrs::CPUArch::Pre_v4 },
78 { "armv2a", ARM::AK_ARMV2A, "2A", "v2a", ARMBuildAttrs::CPUArch::Pre_v4 },
79 { "armv3", ARM::AK_ARMV3, "3", "v3", ARMBuildAttrs::CPUArch::Pre_v4 },
80 { "armv3m", ARM::AK_ARMV3M, "3M", "v3m", ARMBuildAttrs::CPUArch::Pre_v4 },
81 { "armv4", ARM::AK_ARMV4, "4", "v4", ARMBuildAttrs::CPUArch::v4 },
82 { "armv4t", ARM::AK_ARMV4T, "4T", "v4t", ARMBuildAttrs::CPUArch::v4T },
83 { "armv5t", ARM::AK_ARMV5T, "5T", "v5", ARMBuildAttrs::CPUArch::v5T },
84 { "armv5te", ARM::AK_ARMV5TE, "5TE", "v5e", ARMBuildAttrs::CPUArch::v5TE },
85 { "armv5tej", ARM::AK_ARMV5TEJ, "5TEJ", "v5e", ARMBuildAttrs::CPUArch::v5TEJ },
86 { "armv6", ARM::AK_ARMV6, "6", "v6", ARMBuildAttrs::CPUArch::v6 },
87 { "armv6k", ARM::AK_ARMV6K, "6K", "v6k", ARMBuildAttrs::CPUArch::v6K },
88 { "armv6t2", ARM::AK_ARMV6T2, "6T2", "v6t2", ARMBuildAttrs::CPUArch::v6T2 },
89 { "armv6z", ARM::AK_ARMV6Z, "6Z", "v6z", ARMBuildAttrs::CPUArch::v6KZ },
90 { "armv6zk", ARM::AK_ARMV6ZK, "6ZK", "v6zk", ARMBuildAttrs::CPUArch::v6KZ },
91 { "armv6-m", ARM::AK_ARMV6M, "6-M", "v6m", ARMBuildAttrs::CPUArch::v6_M },
92 { "armv6s-m", ARM::AK_ARMV6SM, "6S-M", "v6sm", ARMBuildAttrs::CPUArch::v6S_M },
93 { "armv7-a", ARM::AK_ARMV7A, "7-A", "v7", ARMBuildAttrs::CPUArch::v7 },
94 { "armv7-r", ARM::AK_ARMV7R, "7-R", "v7r", ARMBuildAttrs::CPUArch::v7 },
95 { "armv7-m", ARM::AK_ARMV7M, "7-M", "v7m", ARMBuildAttrs::CPUArch::v7 },
96 { "armv7e-m", ARM::AK_ARMV7EM, "7E-M", "v7em", ARMBuildAttrs::CPUArch::v7E_M },
97 { "armv8-a", ARM::AK_ARMV8A, "8-A", "v8", ARMBuildAttrs::CPUArch::v8 },
98 { "armv8.1-a", ARM::AK_ARMV8_1A, "8.1-A", "v8.1a", ARMBuildAttrs::CPUArch::v8 },
Renato Goline8048f02015-05-20 15:05:07 +000099 // Non-standard Arch names.
Renato Golin42dad642015-05-28 15:05:18 +0000100 { "iwmmxt", ARM::AK_IWMMXT, "iwmmxt", "", ARMBuildAttrs::CPUArch::v5TE },
101 { "iwmmxt2", ARM::AK_IWMMXT2, "iwmmxt2", "", ARMBuildAttrs::CPUArch::v5TE },
102 { "xscale", ARM::AK_XSCALE, "xscale", "", ARMBuildAttrs::CPUArch::v5TE },
103 { "armv5", ARM::AK_ARMV5, "5T", "v5", ARMBuildAttrs::CPUArch::v5T },
104 { "armv5e", ARM::AK_ARMV5E, "5TE", "v5e", ARMBuildAttrs::CPUArch::v5TE },
105 { "armv6j", ARM::AK_ARMV6J, "6J", "v6", ARMBuildAttrs::CPUArch::v6 },
106 { "armv6hl", ARM::AK_ARMV6HL, "6-M", "v6hl", ARMBuildAttrs::CPUArch::v6_M },
107 { "armv7", ARM::AK_ARMV7, "7", "v7", ARMBuildAttrs::CPUArch::v7 },
108 { "armv7l", ARM::AK_ARMV7L, "7-L", "v7l", ARMBuildAttrs::CPUArch::v7 },
109 { "armv7hl", ARM::AK_ARMV7HL, "7-L", "v7hl", ARMBuildAttrs::CPUArch::v7 },
110 { "armv7s", ARM::AK_ARMV7S, "7-S", "v7s", ARMBuildAttrs::CPUArch::v7 }
Renato Golinf5f373f2015-05-08 21:04:27 +0000111};
Renato Goline1326ca2015-05-28 08:59:03 +0000112// List of Arch Extension names.
Renato Golinf5f373f2015-05-08 21:04:27 +0000113// FIXME: TableGen this.
114struct {
115 const char *Name;
116 ARM::ArchExtKind ID;
117} ARCHExtNames[] = {
Renato Golin35de35d2015-05-12 10:33:58 +0000118 { "invalid", ARM::AEK_INVALID },
119 { "crc", ARM::AEK_CRC },
120 { "crypto", ARM::AEK_CRYPTO },
121 { "fp", ARM::AEK_FP },
122 { "idiv", ARM::AEK_HWDIV },
123 { "mp", ARM::AEK_MP },
Renato Golin230d2982015-05-30 10:30:02 +0000124 { "simd", ARM::AEK_SIMD },
Renato Golin35de35d2015-05-12 10:33:58 +0000125 { "sec", ARM::AEK_SEC },
Renato Golin230d2982015-05-30 10:30:02 +0000126 { "virt", ARM::AEK_VIRT },
127 { "os", ARM::AEK_OS },
128 { "iwmmxt", ARM::AEK_IWMMXT },
129 { "iwmmxt2", ARM::AEK_IWMMXT2 },
130 { "maverick", ARM::AEK_MAVERICK },
131 { "xscale", ARM::AEK_XSCALE }
Renato Golinf5f373f2015-05-08 21:04:27 +0000132};
Renato Goline8048f02015-05-20 15:05:07 +0000133// List of CPU names and their arches.
134// The same CPU can have multiple arches and can be default on multiple arches.
135// When finding the Arch for a CPU, first-found prevails. Sort them accordingly.
Renato Golin7374fcd2015-05-28 12:10:37 +0000136// When this becomes table-generated, we'd probably need two tables.
Renato Goline8048f02015-05-20 15:05:07 +0000137// FIXME: TableGen this.
138struct {
139 const char *Name;
140 ARM::ArchKind ArchID;
Alexandros Lamprineasfcd93d52015-07-15 10:46:21 +0000141 ARM::FPUKind DefaultFPU;
142 bool Default; // is $Name the default CPU for $ArchID ?
Renato Goline8048f02015-05-20 15:05:07 +0000143} CPUNames[] = {
Alexandros Lamprineasfcd93d52015-07-15 10:46:21 +0000144 { "arm2", ARM::AK_ARMV2, ARM::FK_NONE, true },
145 { "arm3", ARM::AK_ARMV2A, ARM::FK_NONE, true },
146 { "arm6", ARM::AK_ARMV3, ARM::FK_NONE, true },
147 { "arm7m", ARM::AK_ARMV3M, ARM::FK_NONE, true },
148 { "arm8", ARM::AK_ARMV4, ARM::FK_NONE, false },
149 { "arm810", ARM::AK_ARMV4, ARM::FK_NONE, false },
150 { "strongarm", ARM::AK_ARMV4, ARM::FK_NONE, true },
151 { "strongarm110", ARM::AK_ARMV4, ARM::FK_NONE, false },
152 { "strongarm1100", ARM::AK_ARMV4, ARM::FK_NONE, false },
153 { "strongarm1110", ARM::AK_ARMV4, ARM::FK_NONE, false },
154 { "arm7tdmi", ARM::AK_ARMV4T, ARM::FK_NONE, true },
155 { "arm7tdmi-s", ARM::AK_ARMV4T, ARM::FK_NONE, false },
156 { "arm710t", ARM::AK_ARMV4T, ARM::FK_NONE, false },
157 { "arm720t", ARM::AK_ARMV4T, ARM::FK_NONE, false },
158 { "arm9", ARM::AK_ARMV4T, ARM::FK_NONE, false },
159 { "arm9tdmi", ARM::AK_ARMV4T, ARM::FK_NONE, false },
160 { "arm920", ARM::AK_ARMV4T, ARM::FK_NONE, false },
161 { "arm920t", ARM::AK_ARMV4T, ARM::FK_NONE, false },
162 { "arm922t", ARM::AK_ARMV4T, ARM::FK_NONE, false },
163 { "arm9312", ARM::AK_ARMV4T, ARM::FK_NONE, false },
164 { "arm940t", ARM::AK_ARMV4T, ARM::FK_NONE, false },
165 { "ep9312", ARM::AK_ARMV4T, ARM::FK_NONE, false },
166 { "arm10tdmi", ARM::AK_ARMV5T, ARM::FK_NONE, true },
167 { "arm1020t", ARM::AK_ARMV5T, ARM::FK_NONE, false },
168 { "arm9e", ARM::AK_ARMV5TE, ARM::FK_NONE, false },
169 { "arm946e-s", ARM::AK_ARMV5TE, ARM::FK_NONE, false },
170 { "arm966e-s", ARM::AK_ARMV5TE, ARM::FK_NONE, false },
171 { "arm968e-s", ARM::AK_ARMV5TE, ARM::FK_NONE, false },
172 { "arm10e", ARM::AK_ARMV5TE, ARM::FK_NONE, false },
173 { "arm1020e", ARM::AK_ARMV5TE, ARM::FK_NONE, false },
174 { "arm1022e", ARM::AK_ARMV5TE, ARM::FK_NONE, true },
175 { "iwmmxt", ARM::AK_ARMV5TE, ARM::FK_NONE, false },
176 { "xscale", ARM::AK_ARMV5TE, ARM::FK_NONE, false },
177 { "arm926ej-s", ARM::AK_ARMV5TEJ, ARM::FK_NONE, true },
178 { "arm1136jf-s", ARM::AK_ARMV6, ARM::FK_VFPV2, true },
179 { "arm1176j-s", ARM::AK_ARMV6K, ARM::FK_NONE, false },
180 { "arm1176jz-s", ARM::AK_ARMV6K, ARM::FK_NONE, false },
181 { "mpcore", ARM::AK_ARMV6K, ARM::FK_VFPV2, false },
182 { "mpcorenovfp", ARM::AK_ARMV6K, ARM::FK_NONE, false },
183 { "arm1176jzf-s", ARM::AK_ARMV6K, ARM::FK_VFPV2, true },
184 { "arm1176jzf-s", ARM::AK_ARMV6Z, ARM::FK_VFPV2, true },
185 { "arm1176jzf-s", ARM::AK_ARMV6ZK, ARM::FK_VFPV2, true },
186 { "arm1156t2-s", ARM::AK_ARMV6T2, ARM::FK_NONE, true },
187 { "arm1156t2f-s", ARM::AK_ARMV6T2, ARM::FK_VFPV2, false },
188 { "cortex-m0", ARM::AK_ARMV6M, ARM::FK_NONE, true },
189 { "cortex-m0plus", ARM::AK_ARMV6M, ARM::FK_NONE, false },
190 { "cortex-m1", ARM::AK_ARMV6M, ARM::FK_NONE, false },
191 { "sc000", ARM::AK_ARMV6M, ARM::FK_NONE, false },
192 { "cortex-a5", ARM::AK_ARMV7A, ARM::FK_NEON_VFPV4, false },
193 { "cortex-a7", ARM::AK_ARMV7A, ARM::FK_NEON_VFPV4, false },
194 { "cortex-a8", ARM::AK_ARMV7A, ARM::FK_NEON, true },
195 { "cortex-a9", ARM::AK_ARMV7A, ARM::FK_NEON_FP16, false },
196 { "cortex-a12", ARM::AK_ARMV7A, ARM::FK_NEON_VFPV4, false },
197 { "cortex-a15", ARM::AK_ARMV7A, ARM::FK_NEON_VFPV4, false },
198 { "cortex-a17", ARM::AK_ARMV7A, ARM::FK_NEON_VFPV4, false },
199 { "krait", ARM::AK_ARMV7A, ARM::FK_NEON_VFPV4, false },
200 { "cortex-r4", ARM::AK_ARMV7R, ARM::FK_NONE, true },
201 { "cortex-r4f", ARM::AK_ARMV7R, ARM::FK_VFPV3_D16, false },
202 { "cortex-r5", ARM::AK_ARMV7R, ARM::FK_VFPV3_D16, false },
203 { "cortex-r7", ARM::AK_ARMV7R, ARM::FK_VFPV3_D16_FP16, false },
204 { "sc300", ARM::AK_ARMV7M, ARM::FK_NONE, false },
205 { "cortex-m3", ARM::AK_ARMV7M, ARM::FK_NONE, true },
Alexandros Lamprineas69718d22015-07-17 15:49:32 +0000206 { "cortex-m4", ARM::AK_ARMV7EM, ARM::FK_FPV4_SP_D16, true },
Alexandros Lamprineasfcd93d52015-07-15 10:46:21 +0000207 { "cortex-m7", ARM::AK_ARMV7EM, ARM::FK_FPV5_D16, false },
208 { "cortex-a53", ARM::AK_ARMV8A, ARM::FK_CRYPTO_NEON_FP_ARMV8, true },
209 { "cortex-a57", ARM::AK_ARMV8A, ARM::FK_CRYPTO_NEON_FP_ARMV8, false },
210 { "cortex-a72", ARM::AK_ARMV8A, ARM::FK_CRYPTO_NEON_FP_ARMV8, false },
211 { "cyclone", ARM::AK_ARMV8A, ARM::FK_CRYPTO_NEON_FP_ARMV8, false },
212 { "generic", ARM::AK_ARMV8_1A, ARM::FK_NEON_FP_ARMV8, true },
Renato Goline8048f02015-05-20 15:05:07 +0000213 // Non-standard Arch names.
Alexandros Lamprineasfcd93d52015-07-15 10:46:21 +0000214 { "iwmmxt", ARM::AK_IWMMXT, ARM::FK_NONE, true },
215 { "xscale", ARM::AK_XSCALE, ARM::FK_NONE, true },
216 { "arm10tdmi", ARM::AK_ARMV5, ARM::FK_NONE, true },
217 { "arm1022e", ARM::AK_ARMV5E, ARM::FK_NONE, true },
218 { "arm1136j-s", ARM::AK_ARMV6J, ARM::FK_NONE, true },
219 { "arm1136jz-s", ARM::AK_ARMV6J, ARM::FK_NONE, false },
220 { "cortex-m0", ARM::AK_ARMV6SM, ARM::FK_NONE, true },
221 { "arm1176jzf-s", ARM::AK_ARMV6HL, ARM::FK_VFPV2, true },
222 { "cortex-a8", ARM::AK_ARMV7, ARM::FK_NEON, true },
223 { "cortex-a8", ARM::AK_ARMV7L, ARM::FK_NEON, true },
224 { "cortex-a8", ARM::AK_ARMV7HL, ARM::FK_NEON, true },
225 { "cortex-m4", ARM::AK_ARMV7EM, ARM::FK_NONE, true },
226 { "swift", ARM::AK_ARMV7S, ARM::FK_NEON_VFPV4, true },
Renato Goline8048f02015-05-20 15:05:07 +0000227 // Invalid CPU
Alexandros Lamprineasfcd93d52015-07-15 10:46:21 +0000228 { "invalid", ARM::AK_INVALID, ARM::FK_INVALID, true }
Renato Goline8048f02015-05-20 15:05:07 +0000229};
Renato Golinf5f373f2015-05-08 21:04:27 +0000230
231} // namespace
232
Renato Golinf5f373f2015-05-08 21:04:27 +0000233// ======================================================= //
234// Information by ID
235// ======================================================= //
236
Renato Goline8048f02015-05-20 15:05:07 +0000237const char *ARMTargetParser::getFPUName(unsigned FPUKind) {
238 if (FPUKind >= ARM::FK_LAST)
Renato Golinf5f373f2015-05-08 21:04:27 +0000239 return nullptr;
Renato Goline8048f02015-05-20 15:05:07 +0000240 return FPUNames[FPUKind].Name;
Renato Golinf5f373f2015-05-08 21:04:27 +0000241}
242
John Brawnd03d2292015-06-05 13:29:24 +0000243unsigned ARMTargetParser::getFPUVersion(unsigned FPUKind) {
244 if (FPUKind >= ARM::FK_LAST)
245 return 0;
246 return FPUNames[FPUKind].FPUVersion;
247}
248
Benjamin Kramerf2d06a52015-06-05 14:33:02 +0000249unsigned ARMTargetParser::getFPUNeonSupportLevel(unsigned FPUKind) {
John Brawnd03d2292015-06-05 13:29:24 +0000250 if (FPUKind >= ARM::FK_LAST)
251 return 0;
252 return FPUNames[FPUKind].NeonSupport;
253}
254
Benjamin Kramerf2d06a52015-06-05 14:33:02 +0000255unsigned ARMTargetParser::getFPURestriction(unsigned FPUKind) {
John Brawnd03d2292015-06-05 13:29:24 +0000256 if (FPUKind >= ARM::FK_LAST)
257 return 0;
258 return FPUNames[FPUKind].Restriction;
259}
260
Alexandros Lamprineasfcd93d52015-07-15 10:46:21 +0000261unsigned ARMTargetParser::getDefaultFPU(StringRef CPU) {
262 for (const auto C : CPUNames) {
263 if (CPU == C.Name)
264 return C.DefaultFPU;
265 }
266 return ARM::FK_INVALID;
267}
268
John Brawnd03d2292015-06-05 13:29:24 +0000269bool ARMTargetParser::getFPUFeatures(unsigned FPUKind,
270 std::vector<const char *> &Features) {
271
272 if (FPUKind >= ARM::FK_LAST || FPUKind == ARM::FK_INVALID)
273 return false;
274
275 // fp-only-sp and d16 subtarget features are independent of each other, so we
276 // must enable/disable both.
277 switch (FPUNames[FPUKind].Restriction) {
278 case ARM::FR_SP_D16:
279 Features.push_back("+fp-only-sp");
280 Features.push_back("+d16");
281 break;
282 case ARM::FR_D16:
283 Features.push_back("-fp-only-sp");
284 Features.push_back("+d16");
285 break;
286 case ARM::FR_None:
287 Features.push_back("-fp-only-sp");
288 Features.push_back("-d16");
289 break;
290 }
291
292 // FPU version subtarget features are inclusive of lower-numbered ones, so
293 // enable the one corresponding to this version and disable all that are
John Brawnd9e39d52015-06-12 09:38:51 +0000294 // higher. We also have to make sure to disable fp16 when vfp4 is disabled,
295 // as +vfp4 implies +fp16 but -vfp4 does not imply -fp16.
John Brawnd03d2292015-06-05 13:29:24 +0000296 switch (FPUNames[FPUKind].FPUVersion) {
Javed Absard5526302015-06-29 09:32:29 +0000297 case ARM::FV_VFPV5:
John Brawnd03d2292015-06-05 13:29:24 +0000298 Features.push_back("+fp-armv8");
299 break;
Javed Absard5526302015-06-29 09:32:29 +0000300 case ARM::FV_VFPV4:
John Brawnd03d2292015-06-05 13:29:24 +0000301 Features.push_back("+vfp4");
302 Features.push_back("-fp-armv8");
303 break;
Javed Absard5526302015-06-29 09:32:29 +0000304 case ARM::FV_VFPV3_FP16:
305 Features.push_back("+vfp3");
306 Features.push_back("+fp16");
307 Features.push_back("-vfp4");
308 Features.push_back("-fp-armv8");
309 break;
310 case ARM::FV_VFPV3:
John Brawnd03d2292015-06-05 13:29:24 +0000311 Features.push_back("+vfp3");
John Brawnd9e39d52015-06-12 09:38:51 +0000312 Features.push_back("-fp16");
John Brawnd03d2292015-06-05 13:29:24 +0000313 Features.push_back("-vfp4");
314 Features.push_back("-fp-armv8");
315 break;
Javed Absard5526302015-06-29 09:32:29 +0000316 case ARM::FV_VFPV2:
John Brawnd03d2292015-06-05 13:29:24 +0000317 Features.push_back("+vfp2");
318 Features.push_back("-vfp3");
John Brawnd9e39d52015-06-12 09:38:51 +0000319 Features.push_back("-fp16");
John Brawnd03d2292015-06-05 13:29:24 +0000320 Features.push_back("-vfp4");
321 Features.push_back("-fp-armv8");
322 break;
Javed Absard5526302015-06-29 09:32:29 +0000323 case ARM::FV_NONE:
John Brawnd03d2292015-06-05 13:29:24 +0000324 Features.push_back("-vfp2");
325 Features.push_back("-vfp3");
John Brawnd9e39d52015-06-12 09:38:51 +0000326 Features.push_back("-fp16");
John Brawnd03d2292015-06-05 13:29:24 +0000327 Features.push_back("-vfp4");
328 Features.push_back("-fp-armv8");
329 break;
330 }
331
332 // crypto includes neon, so we handle this similarly to FPU version.
333 switch (FPUNames[FPUKind].NeonSupport) {
334 case ARM::NS_Crypto:
335 Features.push_back("+crypto");
336 break;
337 case ARM::NS_Neon:
338 Features.push_back("+neon");
339 Features.push_back("-crypto");
340 break;
341 case ARM::NS_None:
342 Features.push_back("-neon");
343 Features.push_back("-crypto");
344 break;
345 }
346
347 return true;
348}
349
Renato Goline8048f02015-05-20 15:05:07 +0000350const char *ARMTargetParser::getArchName(unsigned ArchKind) {
351 if (ArchKind >= ARM::AK_LAST)
Renato Golinf5f373f2015-05-08 21:04:27 +0000352 return nullptr;
Renato Goline8048f02015-05-20 15:05:07 +0000353 return ARCHNames[ArchKind].Name;
Renato Golinf5f373f2015-05-08 21:04:27 +0000354}
355
Renato Golinf7c0d5f2015-05-27 18:15:37 +0000356const char *ARMTargetParser::getCPUAttr(unsigned ArchKind) {
Renato Goline8048f02015-05-20 15:05:07 +0000357 if (ArchKind >= ARM::AK_LAST)
Renato Golinf5f373f2015-05-08 21:04:27 +0000358 return nullptr;
Renato Golinf7c0d5f2015-05-27 18:15:37 +0000359 return ARCHNames[ArchKind].CPUAttr;
Renato Golinf5f373f2015-05-08 21:04:27 +0000360}
361
Renato Golin42dad642015-05-28 15:05:18 +0000362const char *ARMTargetParser::getSubArch(unsigned ArchKind) {
363 if (ArchKind >= ARM::AK_LAST)
364 return nullptr;
365 return ARCHNames[ArchKind].SubArch;
366}
367
Renato Golinf7c0d5f2015-05-27 18:15:37 +0000368unsigned ARMTargetParser::getArchAttr(unsigned ArchKind) {
Renato Goline8048f02015-05-20 15:05:07 +0000369 if (ArchKind >= ARM::AK_LAST)
370 return ARMBuildAttrs::CPUArch::Pre_v4;
Renato Golinf7c0d5f2015-05-27 18:15:37 +0000371 return ARCHNames[ArchKind].ArchAttr;
Renato Golinf5f373f2015-05-08 21:04:27 +0000372}
373
Renato Goline8048f02015-05-20 15:05:07 +0000374const char *ARMTargetParser::getArchExtName(unsigned ArchExtKind) {
375 if (ArchExtKind >= ARM::AEK_LAST)
Renato Golinf5f373f2015-05-08 21:04:27 +0000376 return nullptr;
Renato Goline8048f02015-05-20 15:05:07 +0000377 return ARCHExtNames[ArchExtKind].Name;
378}
379
380const char *ARMTargetParser::getDefaultCPU(StringRef Arch) {
381 unsigned AK = parseArch(Arch);
382 if (AK == ARM::AK_INVALID)
383 return nullptr;
384
385 // Look for multiple AKs to find the default for pair AK+Name.
386 for (const auto CPU : CPUNames) {
387 if (CPU.ArchID == AK && CPU.Default)
388 return CPU.Name;
389 }
390 return nullptr;
Renato Golinf5f373f2015-05-08 21:04:27 +0000391}
392
393// ======================================================= //
394// Parsers
395// ======================================================= //
396
397StringRef ARMTargetParser::getFPUSynonym(StringRef FPU) {
398 return StringSwitch<StringRef>(FPU)
399 .Cases("fpa", "fpe2", "fpe3", "maverick", "invalid") // Unsupported
400 .Case("vfp2", "vfpv2")
401 .Case("vfp3", "vfpv3")
402 .Case("vfp4", "vfpv4")
403 .Case("vfp3-d16", "vfpv3-d16")
404 .Case("vfp4-d16", "vfpv4-d16")
John Brawn985c04e2015-06-05 13:31:19 +0000405 .Cases("fp4-sp-d16", "vfpv4-sp-d16", "fpv4-sp-d16")
Renato Golinf5f373f2015-05-08 21:04:27 +0000406 .Cases("fp4-dp-d16", "fpv4-dp-d16", "vfpv4-d16")
John Brawn985c04e2015-06-05 13:31:19 +0000407 .Case("fp5-sp-d16", "fpv5-sp-d16")
Renato Golinf5f373f2015-05-08 21:04:27 +0000408 .Cases("fp5-dp-d16", "fpv5-dp-d16", "fpv5-d16")
409 // FIXME: Clang uses it, but it's bogus, since neon defaults to vfpv3.
410 .Case("neon-vfpv3", "neon")
411 .Default(FPU);
412}
413
414StringRef ARMTargetParser::getArchSynonym(StringRef Arch) {
415 return StringSwitch<StringRef>(Arch)
Artyom Skrobov85aebc82015-06-04 21:26:58 +0000416 .Case("v6sm", "v6s-m")
417 .Case("v6m", "v6-m")
418 .Case("v7a", "v7-a")
419 .Case("v7r", "v7-r")
420 .Case("v7m", "v7-m")
421 .Case("v7em", "v7e-m")
Artyom Skrobovacd1cd62015-06-05 12:39:28 +0000422 .Cases("v8", "v8a", "aarch64", "arm64", "v8-a")
Artyom Skrobov85aebc82015-06-04 21:26:58 +0000423 .Case("v8.1a", "v8.1-a")
Renato Golinf5f373f2015-05-08 21:04:27 +0000424 .Default(Arch);
425}
426
Renato Goline8048f02015-05-20 15:05:07 +0000427// MArch is expected to be of the form (arm|thumb)?(eb)?(v.+)?(eb)?, but
428// (iwmmxt|xscale)(eb)? is also permitted. If the former, return
Renato Golinebdd12c2015-05-22 20:43:30 +0000429// "v.+", if the latter, return unmodified string, minus 'eb'.
430// If invalid, return empty string.
Renato Goline8048f02015-05-20 15:05:07 +0000431StringRef ARMTargetParser::getCanonicalArchName(StringRef Arch) {
432 size_t offset = StringRef::npos;
433 StringRef A = Arch;
Renato Golinb6b9e052015-05-21 13:52:20 +0000434 StringRef Error = "";
Renato Goline8048f02015-05-20 15:05:07 +0000435
436 // Begins with "arm" / "thumb", move past it.
Renato Golinebdd12c2015-05-22 20:43:30 +0000437 if (A.startswith("arm64"))
438 offset = 5;
439 else if (A.startswith("arm"))
Renato Goline8048f02015-05-20 15:05:07 +0000440 offset = 3;
441 else if (A.startswith("thumb"))
442 offset = 5;
Renato Golinb6b9e052015-05-21 13:52:20 +0000443 else if (A.startswith("aarch64")) {
444 offset = 7;
445 // AArch64 uses "_be", not "eb" suffix.
446 if (A.find("eb") != StringRef::npos)
447 return Error;
448 if (A.substr(offset,3) == "_be")
449 offset += 3;
450 }
451
Renato Goline8048f02015-05-20 15:05:07 +0000452 // Ex. "armebv7", move past the "eb".
453 if (offset != StringRef::npos && A.substr(offset, 2) == "eb")
454 offset += 2;
455 // Or, if it ends with eb ("armv7eb"), chop it off.
456 else if (A.endswith("eb"))
457 A = A.substr(0, A.size() - 2);
Renato Golinebdd12c2015-05-22 20:43:30 +0000458 // Trim the head
459 if (offset != StringRef::npos)
Renato Goline8048f02015-05-20 15:05:07 +0000460 A = A.substr(offset);
461
Renato Golinebdd12c2015-05-22 20:43:30 +0000462 // Empty string means offset reached the end, which means it's valid.
Renato Goline8048f02015-05-20 15:05:07 +0000463 if (A.empty())
464 return Arch;
465
Renato Golinebdd12c2015-05-22 20:43:30 +0000466 // Only match non-marketing names
467 if (offset != StringRef::npos) {
468 // Must start with 'vN'.
469 if (A[0] != 'v' || !std::isdigit(A[1]))
470 return Error;
471 // Can't have an extra 'eb'.
472 if (A.find("eb") != StringRef::npos)
473 return Error;
474 }
Renato Goline8048f02015-05-20 15:05:07 +0000475
Renato Golinebdd12c2015-05-22 20:43:30 +0000476 // Arch will either be a 'v' name (v7a) or a marketing name (xscale).
Renato Goline8048f02015-05-20 15:05:07 +0000477 return A;
478}
479
Renato Golinf5f373f2015-05-08 21:04:27 +0000480unsigned ARMTargetParser::parseFPU(StringRef FPU) {
481 StringRef Syn = getFPUSynonym(FPU);
482 for (const auto F : FPUNames) {
483 if (Syn == F.Name)
484 return F.ID;
485 }
Renato Golin35de35d2015-05-12 10:33:58 +0000486 return ARM::FK_INVALID;
Renato Golinf5f373f2015-05-08 21:04:27 +0000487}
488
Renato Goline8048f02015-05-20 15:05:07 +0000489// Allows partial match, ex. "v7a" matches "armv7a".
Renato Golinf5f373f2015-05-08 21:04:27 +0000490unsigned ARMTargetParser::parseArch(StringRef Arch) {
Artyom Skrobov85aebc82015-06-04 21:26:58 +0000491 Arch = getCanonicalArchName(Arch);
Renato Golinf5f373f2015-05-08 21:04:27 +0000492 StringRef Syn = getArchSynonym(Arch);
493 for (const auto A : ARCHNames) {
Renato Goline8048f02015-05-20 15:05:07 +0000494 if (StringRef(A.Name).endswith(Syn))
Renato Golinf5f373f2015-05-08 21:04:27 +0000495 return A.ID;
496 }
Renato Golin35de35d2015-05-12 10:33:58 +0000497 return ARM::AK_INVALID;
Renato Golinf5f373f2015-05-08 21:04:27 +0000498}
499
500unsigned ARMTargetParser::parseArchExt(StringRef ArchExt) {
501 for (const auto A : ARCHExtNames) {
502 if (ArchExt == A.Name)
503 return A.ID;
504 }
Renato Golin35de35d2015-05-12 10:33:58 +0000505 return ARM::AEK_INVALID;
Renato Golinf5f373f2015-05-08 21:04:27 +0000506}
507
Renato Goline8048f02015-05-20 15:05:07 +0000508unsigned ARMTargetParser::parseCPUArch(StringRef CPU) {
509 for (const auto C : CPUNames) {
510 if (CPU == C.Name)
511 return C.ArchID;
512 }
513 return ARM::AK_INVALID;
514}
515
Renato Golinb6b9e052015-05-21 13:52:20 +0000516// ARM, Thumb, AArch64
517unsigned ARMTargetParser::parseArchISA(StringRef Arch) {
518 return StringSwitch<unsigned>(Arch)
519 .StartsWith("aarch64", ARM::IK_AARCH64)
520 .StartsWith("arm64", ARM::IK_AARCH64)
521 .StartsWith("thumb", ARM::IK_THUMB)
522 .StartsWith("arm", ARM::IK_ARM)
523 .Default(ARM::EK_INVALID);
524}
525
526// Little/Big endian
527unsigned ARMTargetParser::parseArchEndian(StringRef Arch) {
528 if (Arch.startswith("armeb") ||
529 Arch.startswith("thumbeb") ||
530 Arch.startswith("aarch64_be"))
531 return ARM::EK_BIG;
532
533 if (Arch.startswith("arm") || Arch.startswith("thumb")) {
534 if (Arch.endswith("eb"))
535 return ARM::EK_BIG;
536 else
537 return ARM::EK_LITTLE;
538 }
539
540 if (Arch.startswith("aarch64"))
541 return ARM::EK_LITTLE;
542
543 return ARM::EK_INVALID;
544}
545
Renato Golinfadc2102015-05-22 18:17:55 +0000546// Profile A/R/M
547unsigned ARMTargetParser::parseArchProfile(StringRef Arch) {
Renato Golinfadc2102015-05-22 18:17:55 +0000548 Arch = getCanonicalArchName(Arch);
549 switch(parseArch(Arch)) {
550 case ARM::AK_ARMV6M:
551 case ARM::AK_ARMV7M:
552 case ARM::AK_ARMV6SM:
553 case ARM::AK_ARMV7EM:
554 return ARM::PK_M;
555 case ARM::AK_ARMV7R:
556 return ARM::PK_R;
557 case ARM::AK_ARMV7:
558 case ARM::AK_ARMV7A:
Alexandros Lamprineas0e20b8d2015-07-16 14:54:41 +0000559 case ARM::AK_ARMV7L:
Renato Golinfadc2102015-05-22 18:17:55 +0000560 case ARM::AK_ARMV8A:
561 case ARM::AK_ARMV8_1A:
562 return ARM::PK_A;
563 }
564 return ARM::PK_INVALID;
565}
566
Renato Golinebdd12c2015-05-22 20:43:30 +0000567// Version number (ex. v7 = 7).
Renato Golinfadc2102015-05-22 18:17:55 +0000568unsigned ARMTargetParser::parseArchVersion(StringRef Arch) {
Renato Golinfadc2102015-05-22 18:17:55 +0000569 Arch = getCanonicalArchName(Arch);
570 switch(parseArch(Arch)) {
571 case ARM::AK_ARMV2:
572 case ARM::AK_ARMV2A:
573 return 2;
574 case ARM::AK_ARMV3:
575 case ARM::AK_ARMV3M:
576 return 3;
577 case ARM::AK_ARMV4:
578 case ARM::AK_ARMV4T:
579 return 4;
580 case ARM::AK_ARMV5:
581 case ARM::AK_ARMV5T:
582 case ARM::AK_ARMV5TE:
583 case ARM::AK_IWMMXT:
584 case ARM::AK_IWMMXT2:
585 case ARM::AK_XSCALE:
586 case ARM::AK_ARMV5E:
587 case ARM::AK_ARMV5TEJ:
588 return 5;
589 case ARM::AK_ARMV6:
590 case ARM::AK_ARMV6J:
591 case ARM::AK_ARMV6K:
592 case ARM::AK_ARMV6T2:
593 case ARM::AK_ARMV6Z:
594 case ARM::AK_ARMV6ZK:
595 case ARM::AK_ARMV6M:
596 case ARM::AK_ARMV6SM:
597 case ARM::AK_ARMV6HL:
598 return 6;
599 case ARM::AK_ARMV7:
600 case ARM::AK_ARMV7A:
601 case ARM::AK_ARMV7R:
602 case ARM::AK_ARMV7M:
603 case ARM::AK_ARMV7L:
604 case ARM::AK_ARMV7HL:
605 case ARM::AK_ARMV7S:
606 case ARM::AK_ARMV7EM:
607 return 7;
608 case ARM::AK_ARMV8A:
609 case ARM::AK_ARMV8_1A:
610 return 8;
611 }
612 return 0;
613}