blob: 00cdf2eccdfd005c96191f937adfb3c0e687e67d [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 },
206 { "cortex-m4", ARM::AK_ARMV7EM, ARM::FK_NONE, true },
207 // FIXME cortex-m4f missing from ARM.td
208 { "cortex-m4f", ARM::AK_ARMV7EM, ARM::FK_FPV4_SP_D16, false },
209 { "cortex-m7", ARM::AK_ARMV7EM, ARM::FK_FPV5_D16, false },
210 { "cortex-a53", ARM::AK_ARMV8A, ARM::FK_CRYPTO_NEON_FP_ARMV8, true },
211 { "cortex-a57", ARM::AK_ARMV8A, ARM::FK_CRYPTO_NEON_FP_ARMV8, false },
212 { "cortex-a72", ARM::AK_ARMV8A, ARM::FK_CRYPTO_NEON_FP_ARMV8, false },
213 { "cyclone", ARM::AK_ARMV8A, ARM::FK_CRYPTO_NEON_FP_ARMV8, false },
214 { "generic", ARM::AK_ARMV8_1A, ARM::FK_NEON_FP_ARMV8, true },
Renato Goline8048f02015-05-20 15:05:07 +0000215 // Non-standard Arch names.
Alexandros Lamprineasfcd93d52015-07-15 10:46:21 +0000216 { "iwmmxt", ARM::AK_IWMMXT, ARM::FK_NONE, true },
217 { "xscale", ARM::AK_XSCALE, ARM::FK_NONE, true },
218 { "arm10tdmi", ARM::AK_ARMV5, ARM::FK_NONE, true },
219 { "arm1022e", ARM::AK_ARMV5E, ARM::FK_NONE, true },
220 { "arm1136j-s", ARM::AK_ARMV6J, ARM::FK_NONE, true },
221 { "arm1136jz-s", ARM::AK_ARMV6J, ARM::FK_NONE, false },
222 { "cortex-m0", ARM::AK_ARMV6SM, ARM::FK_NONE, true },
223 { "arm1176jzf-s", ARM::AK_ARMV6HL, ARM::FK_VFPV2, true },
224 { "cortex-a8", ARM::AK_ARMV7, ARM::FK_NEON, true },
225 { "cortex-a8", ARM::AK_ARMV7L, ARM::FK_NEON, true },
226 { "cortex-a8", ARM::AK_ARMV7HL, ARM::FK_NEON, true },
227 { "cortex-m4", ARM::AK_ARMV7EM, ARM::FK_NONE, true },
228 { "swift", ARM::AK_ARMV7S, ARM::FK_NEON_VFPV4, true },
Renato Goline8048f02015-05-20 15:05:07 +0000229 // Invalid CPU
Alexandros Lamprineasfcd93d52015-07-15 10:46:21 +0000230 { "invalid", ARM::AK_INVALID, ARM::FK_INVALID, true }
Renato Goline8048f02015-05-20 15:05:07 +0000231};
Renato Golinf5f373f2015-05-08 21:04:27 +0000232
233} // namespace
234
Renato Golinf5f373f2015-05-08 21:04:27 +0000235// ======================================================= //
236// Information by ID
237// ======================================================= //
238
Renato Goline8048f02015-05-20 15:05:07 +0000239const char *ARMTargetParser::getFPUName(unsigned FPUKind) {
240 if (FPUKind >= ARM::FK_LAST)
Renato Golinf5f373f2015-05-08 21:04:27 +0000241 return nullptr;
Renato Goline8048f02015-05-20 15:05:07 +0000242 return FPUNames[FPUKind].Name;
Renato Golinf5f373f2015-05-08 21:04:27 +0000243}
244
John Brawnd03d2292015-06-05 13:29:24 +0000245unsigned ARMTargetParser::getFPUVersion(unsigned FPUKind) {
246 if (FPUKind >= ARM::FK_LAST)
247 return 0;
248 return FPUNames[FPUKind].FPUVersion;
249}
250
Benjamin Kramerf2d06a52015-06-05 14:33:02 +0000251unsigned ARMTargetParser::getFPUNeonSupportLevel(unsigned FPUKind) {
John Brawnd03d2292015-06-05 13:29:24 +0000252 if (FPUKind >= ARM::FK_LAST)
253 return 0;
254 return FPUNames[FPUKind].NeonSupport;
255}
256
Benjamin Kramerf2d06a52015-06-05 14:33:02 +0000257unsigned ARMTargetParser::getFPURestriction(unsigned FPUKind) {
John Brawnd03d2292015-06-05 13:29:24 +0000258 if (FPUKind >= ARM::FK_LAST)
259 return 0;
260 return FPUNames[FPUKind].Restriction;
261}
262
Alexandros Lamprineasfcd93d52015-07-15 10:46:21 +0000263unsigned ARMTargetParser::getDefaultFPU(StringRef CPU) {
264 for (const auto C : CPUNames) {
265 if (CPU == C.Name)
266 return C.DefaultFPU;
267 }
268 return ARM::FK_INVALID;
269}
270
John Brawnd03d2292015-06-05 13:29:24 +0000271bool ARMTargetParser::getFPUFeatures(unsigned FPUKind,
272 std::vector<const char *> &Features) {
273
274 if (FPUKind >= ARM::FK_LAST || FPUKind == ARM::FK_INVALID)
275 return false;
276
277 // fp-only-sp and d16 subtarget features are independent of each other, so we
278 // must enable/disable both.
279 switch (FPUNames[FPUKind].Restriction) {
280 case ARM::FR_SP_D16:
281 Features.push_back("+fp-only-sp");
282 Features.push_back("+d16");
283 break;
284 case ARM::FR_D16:
285 Features.push_back("-fp-only-sp");
286 Features.push_back("+d16");
287 break;
288 case ARM::FR_None:
289 Features.push_back("-fp-only-sp");
290 Features.push_back("-d16");
291 break;
292 }
293
294 // FPU version subtarget features are inclusive of lower-numbered ones, so
295 // enable the one corresponding to this version and disable all that are
John Brawnd9e39d52015-06-12 09:38:51 +0000296 // higher. We also have to make sure to disable fp16 when vfp4 is disabled,
297 // as +vfp4 implies +fp16 but -vfp4 does not imply -fp16.
John Brawnd03d2292015-06-05 13:29:24 +0000298 switch (FPUNames[FPUKind].FPUVersion) {
Javed Absard5526302015-06-29 09:32:29 +0000299 case ARM::FV_VFPV5:
John Brawnd03d2292015-06-05 13:29:24 +0000300 Features.push_back("+fp-armv8");
301 break;
Javed Absard5526302015-06-29 09:32:29 +0000302 case ARM::FV_VFPV4:
John Brawnd03d2292015-06-05 13:29:24 +0000303 Features.push_back("+vfp4");
304 Features.push_back("-fp-armv8");
305 break;
Javed Absard5526302015-06-29 09:32:29 +0000306 case ARM::FV_VFPV3_FP16:
307 Features.push_back("+vfp3");
308 Features.push_back("+fp16");
309 Features.push_back("-vfp4");
310 Features.push_back("-fp-armv8");
311 break;
312 case ARM::FV_VFPV3:
John Brawnd03d2292015-06-05 13:29:24 +0000313 Features.push_back("+vfp3");
John Brawnd9e39d52015-06-12 09:38:51 +0000314 Features.push_back("-fp16");
John Brawnd03d2292015-06-05 13:29:24 +0000315 Features.push_back("-vfp4");
316 Features.push_back("-fp-armv8");
317 break;
Javed Absard5526302015-06-29 09:32:29 +0000318 case ARM::FV_VFPV2:
John Brawnd03d2292015-06-05 13:29:24 +0000319 Features.push_back("+vfp2");
320 Features.push_back("-vfp3");
John Brawnd9e39d52015-06-12 09:38:51 +0000321 Features.push_back("-fp16");
John Brawnd03d2292015-06-05 13:29:24 +0000322 Features.push_back("-vfp4");
323 Features.push_back("-fp-armv8");
324 break;
Javed Absard5526302015-06-29 09:32:29 +0000325 case ARM::FV_NONE:
John Brawnd03d2292015-06-05 13:29:24 +0000326 Features.push_back("-vfp2");
327 Features.push_back("-vfp3");
John Brawnd9e39d52015-06-12 09:38:51 +0000328 Features.push_back("-fp16");
John Brawnd03d2292015-06-05 13:29:24 +0000329 Features.push_back("-vfp4");
330 Features.push_back("-fp-armv8");
331 break;
332 }
333
334 // crypto includes neon, so we handle this similarly to FPU version.
335 switch (FPUNames[FPUKind].NeonSupport) {
336 case ARM::NS_Crypto:
337 Features.push_back("+crypto");
338 break;
339 case ARM::NS_Neon:
340 Features.push_back("+neon");
341 Features.push_back("-crypto");
342 break;
343 case ARM::NS_None:
344 Features.push_back("-neon");
345 Features.push_back("-crypto");
346 break;
347 }
348
349 return true;
350}
351
Renato Goline8048f02015-05-20 15:05:07 +0000352const char *ARMTargetParser::getArchName(unsigned ArchKind) {
353 if (ArchKind >= ARM::AK_LAST)
Renato Golinf5f373f2015-05-08 21:04:27 +0000354 return nullptr;
Renato Goline8048f02015-05-20 15:05:07 +0000355 return ARCHNames[ArchKind].Name;
Renato Golinf5f373f2015-05-08 21:04:27 +0000356}
357
Renato Golinf7c0d5f2015-05-27 18:15:37 +0000358const char *ARMTargetParser::getCPUAttr(unsigned ArchKind) {
Renato Goline8048f02015-05-20 15:05:07 +0000359 if (ArchKind >= ARM::AK_LAST)
Renato Golinf5f373f2015-05-08 21:04:27 +0000360 return nullptr;
Renato Golinf7c0d5f2015-05-27 18:15:37 +0000361 return ARCHNames[ArchKind].CPUAttr;
Renato Golinf5f373f2015-05-08 21:04:27 +0000362}
363
Renato Golin42dad642015-05-28 15:05:18 +0000364const char *ARMTargetParser::getSubArch(unsigned ArchKind) {
365 if (ArchKind >= ARM::AK_LAST)
366 return nullptr;
367 return ARCHNames[ArchKind].SubArch;
368}
369
Renato Golinf7c0d5f2015-05-27 18:15:37 +0000370unsigned ARMTargetParser::getArchAttr(unsigned ArchKind) {
Renato Goline8048f02015-05-20 15:05:07 +0000371 if (ArchKind >= ARM::AK_LAST)
372 return ARMBuildAttrs::CPUArch::Pre_v4;
Renato Golinf7c0d5f2015-05-27 18:15:37 +0000373 return ARCHNames[ArchKind].ArchAttr;
Renato Golinf5f373f2015-05-08 21:04:27 +0000374}
375
Renato Goline8048f02015-05-20 15:05:07 +0000376const char *ARMTargetParser::getArchExtName(unsigned ArchExtKind) {
377 if (ArchExtKind >= ARM::AEK_LAST)
Renato Golinf5f373f2015-05-08 21:04:27 +0000378 return nullptr;
Renato Goline8048f02015-05-20 15:05:07 +0000379 return ARCHExtNames[ArchExtKind].Name;
380}
381
382const char *ARMTargetParser::getDefaultCPU(StringRef Arch) {
383 unsigned AK = parseArch(Arch);
384 if (AK == ARM::AK_INVALID)
385 return nullptr;
386
387 // Look for multiple AKs to find the default for pair AK+Name.
388 for (const auto CPU : CPUNames) {
389 if (CPU.ArchID == AK && CPU.Default)
390 return CPU.Name;
391 }
392 return nullptr;
Renato Golinf5f373f2015-05-08 21:04:27 +0000393}
394
395// ======================================================= //
396// Parsers
397// ======================================================= //
398
399StringRef ARMTargetParser::getFPUSynonym(StringRef FPU) {
400 return StringSwitch<StringRef>(FPU)
401 .Cases("fpa", "fpe2", "fpe3", "maverick", "invalid") // Unsupported
402 .Case("vfp2", "vfpv2")
403 .Case("vfp3", "vfpv3")
404 .Case("vfp4", "vfpv4")
405 .Case("vfp3-d16", "vfpv3-d16")
406 .Case("vfp4-d16", "vfpv4-d16")
John Brawn985c04e2015-06-05 13:31:19 +0000407 .Cases("fp4-sp-d16", "vfpv4-sp-d16", "fpv4-sp-d16")
Renato Golinf5f373f2015-05-08 21:04:27 +0000408 .Cases("fp4-dp-d16", "fpv4-dp-d16", "vfpv4-d16")
John Brawn985c04e2015-06-05 13:31:19 +0000409 .Case("fp5-sp-d16", "fpv5-sp-d16")
Renato Golinf5f373f2015-05-08 21:04:27 +0000410 .Cases("fp5-dp-d16", "fpv5-dp-d16", "fpv5-d16")
411 // FIXME: Clang uses it, but it's bogus, since neon defaults to vfpv3.
412 .Case("neon-vfpv3", "neon")
413 .Default(FPU);
414}
415
416StringRef ARMTargetParser::getArchSynonym(StringRef Arch) {
417 return StringSwitch<StringRef>(Arch)
Artyom Skrobov85aebc82015-06-04 21:26:58 +0000418 .Case("v6sm", "v6s-m")
419 .Case("v6m", "v6-m")
420 .Case("v7a", "v7-a")
421 .Case("v7r", "v7-r")
422 .Case("v7m", "v7-m")
423 .Case("v7em", "v7e-m")
Artyom Skrobovacd1cd62015-06-05 12:39:28 +0000424 .Cases("v8", "v8a", "aarch64", "arm64", "v8-a")
Artyom Skrobov85aebc82015-06-04 21:26:58 +0000425 .Case("v8.1a", "v8.1-a")
Renato Golinf5f373f2015-05-08 21:04:27 +0000426 .Default(Arch);
427}
428
Renato Goline8048f02015-05-20 15:05:07 +0000429// MArch is expected to be of the form (arm|thumb)?(eb)?(v.+)?(eb)?, but
430// (iwmmxt|xscale)(eb)? is also permitted. If the former, return
Renato Golinebdd12c2015-05-22 20:43:30 +0000431// "v.+", if the latter, return unmodified string, minus 'eb'.
432// If invalid, return empty string.
Renato Goline8048f02015-05-20 15:05:07 +0000433StringRef ARMTargetParser::getCanonicalArchName(StringRef Arch) {
434 size_t offset = StringRef::npos;
435 StringRef A = Arch;
Renato Golinb6b9e052015-05-21 13:52:20 +0000436 StringRef Error = "";
Renato Goline8048f02015-05-20 15:05:07 +0000437
438 // Begins with "arm" / "thumb", move past it.
Renato Golinebdd12c2015-05-22 20:43:30 +0000439 if (A.startswith("arm64"))
440 offset = 5;
441 else if (A.startswith("arm"))
Renato Goline8048f02015-05-20 15:05:07 +0000442 offset = 3;
443 else if (A.startswith("thumb"))
444 offset = 5;
Renato Golinb6b9e052015-05-21 13:52:20 +0000445 else if (A.startswith("aarch64")) {
446 offset = 7;
447 // AArch64 uses "_be", not "eb" suffix.
448 if (A.find("eb") != StringRef::npos)
449 return Error;
450 if (A.substr(offset,3) == "_be")
451 offset += 3;
452 }
453
Renato Goline8048f02015-05-20 15:05:07 +0000454 // Ex. "armebv7", move past the "eb".
455 if (offset != StringRef::npos && A.substr(offset, 2) == "eb")
456 offset += 2;
457 // Or, if it ends with eb ("armv7eb"), chop it off.
458 else if (A.endswith("eb"))
459 A = A.substr(0, A.size() - 2);
Renato Golinebdd12c2015-05-22 20:43:30 +0000460 // Trim the head
461 if (offset != StringRef::npos)
Renato Goline8048f02015-05-20 15:05:07 +0000462 A = A.substr(offset);
463
Renato Golinebdd12c2015-05-22 20:43:30 +0000464 // Empty string means offset reached the end, which means it's valid.
Renato Goline8048f02015-05-20 15:05:07 +0000465 if (A.empty())
466 return Arch;
467
Renato Golinebdd12c2015-05-22 20:43:30 +0000468 // Only match non-marketing names
469 if (offset != StringRef::npos) {
470 // Must start with 'vN'.
471 if (A[0] != 'v' || !std::isdigit(A[1]))
472 return Error;
473 // Can't have an extra 'eb'.
474 if (A.find("eb") != StringRef::npos)
475 return Error;
476 }
Renato Goline8048f02015-05-20 15:05:07 +0000477
Renato Golinebdd12c2015-05-22 20:43:30 +0000478 // Arch will either be a 'v' name (v7a) or a marketing name (xscale).
Renato Goline8048f02015-05-20 15:05:07 +0000479 return A;
480}
481
Renato Golinf5f373f2015-05-08 21:04:27 +0000482unsigned ARMTargetParser::parseFPU(StringRef FPU) {
483 StringRef Syn = getFPUSynonym(FPU);
484 for (const auto F : FPUNames) {
485 if (Syn == F.Name)
486 return F.ID;
487 }
Renato Golin35de35d2015-05-12 10:33:58 +0000488 return ARM::FK_INVALID;
Renato Golinf5f373f2015-05-08 21:04:27 +0000489}
490
Renato Goline8048f02015-05-20 15:05:07 +0000491// Allows partial match, ex. "v7a" matches "armv7a".
Renato Golinf5f373f2015-05-08 21:04:27 +0000492unsigned ARMTargetParser::parseArch(StringRef Arch) {
Artyom Skrobov85aebc82015-06-04 21:26:58 +0000493 Arch = getCanonicalArchName(Arch);
Renato Golinf5f373f2015-05-08 21:04:27 +0000494 StringRef Syn = getArchSynonym(Arch);
495 for (const auto A : ARCHNames) {
Renato Goline8048f02015-05-20 15:05:07 +0000496 if (StringRef(A.Name).endswith(Syn))
Renato Golinf5f373f2015-05-08 21:04:27 +0000497 return A.ID;
498 }
Renato Golin35de35d2015-05-12 10:33:58 +0000499 return ARM::AK_INVALID;
Renato Golinf5f373f2015-05-08 21:04:27 +0000500}
501
502unsigned ARMTargetParser::parseArchExt(StringRef ArchExt) {
503 for (const auto A : ARCHExtNames) {
504 if (ArchExt == A.Name)
505 return A.ID;
506 }
Renato Golin35de35d2015-05-12 10:33:58 +0000507 return ARM::AEK_INVALID;
Renato Golinf5f373f2015-05-08 21:04:27 +0000508}
509
Renato Goline8048f02015-05-20 15:05:07 +0000510unsigned ARMTargetParser::parseCPUArch(StringRef CPU) {
511 for (const auto C : CPUNames) {
512 if (CPU == C.Name)
513 return C.ArchID;
514 }
515 return ARM::AK_INVALID;
516}
517
Renato Golinb6b9e052015-05-21 13:52:20 +0000518// ARM, Thumb, AArch64
519unsigned ARMTargetParser::parseArchISA(StringRef Arch) {
520 return StringSwitch<unsigned>(Arch)
521 .StartsWith("aarch64", ARM::IK_AARCH64)
522 .StartsWith("arm64", ARM::IK_AARCH64)
523 .StartsWith("thumb", ARM::IK_THUMB)
524 .StartsWith("arm", ARM::IK_ARM)
525 .Default(ARM::EK_INVALID);
526}
527
528// Little/Big endian
529unsigned ARMTargetParser::parseArchEndian(StringRef Arch) {
530 if (Arch.startswith("armeb") ||
531 Arch.startswith("thumbeb") ||
532 Arch.startswith("aarch64_be"))
533 return ARM::EK_BIG;
534
535 if (Arch.startswith("arm") || Arch.startswith("thumb")) {
536 if (Arch.endswith("eb"))
537 return ARM::EK_BIG;
538 else
539 return ARM::EK_LITTLE;
540 }
541
542 if (Arch.startswith("aarch64"))
543 return ARM::EK_LITTLE;
544
545 return ARM::EK_INVALID;
546}
547
Renato Golinfadc2102015-05-22 18:17:55 +0000548// Profile A/R/M
549unsigned ARMTargetParser::parseArchProfile(StringRef Arch) {
Renato Golinfadc2102015-05-22 18:17:55 +0000550 Arch = getCanonicalArchName(Arch);
551 switch(parseArch(Arch)) {
552 case ARM::AK_ARMV6M:
553 case ARM::AK_ARMV7M:
554 case ARM::AK_ARMV6SM:
555 case ARM::AK_ARMV7EM:
556 return ARM::PK_M;
557 case ARM::AK_ARMV7R:
558 return ARM::PK_R;
559 case ARM::AK_ARMV7:
560 case ARM::AK_ARMV7A:
561 case ARM::AK_ARMV8A:
562 case ARM::AK_ARMV8_1A:
563 return ARM::PK_A;
564 }
565 return ARM::PK_INVALID;
566}
567
Renato Golinebdd12c2015-05-22 20:43:30 +0000568// Version number (ex. v7 = 7).
Renato Golinfadc2102015-05-22 18:17:55 +0000569unsigned ARMTargetParser::parseArchVersion(StringRef Arch) {
Renato Golinfadc2102015-05-22 18:17:55 +0000570 Arch = getCanonicalArchName(Arch);
571 switch(parseArch(Arch)) {
572 case ARM::AK_ARMV2:
573 case ARM::AK_ARMV2A:
574 return 2;
575 case ARM::AK_ARMV3:
576 case ARM::AK_ARMV3M:
577 return 3;
578 case ARM::AK_ARMV4:
579 case ARM::AK_ARMV4T:
580 return 4;
581 case ARM::AK_ARMV5:
582 case ARM::AK_ARMV5T:
583 case ARM::AK_ARMV5TE:
584 case ARM::AK_IWMMXT:
585 case ARM::AK_IWMMXT2:
586 case ARM::AK_XSCALE:
587 case ARM::AK_ARMV5E:
588 case ARM::AK_ARMV5TEJ:
589 return 5;
590 case ARM::AK_ARMV6:
591 case ARM::AK_ARMV6J:
592 case ARM::AK_ARMV6K:
593 case ARM::AK_ARMV6T2:
594 case ARM::AK_ARMV6Z:
595 case ARM::AK_ARMV6ZK:
596 case ARM::AK_ARMV6M:
597 case ARM::AK_ARMV6SM:
598 case ARM::AK_ARMV6HL:
599 return 6;
600 case ARM::AK_ARMV7:
601 case ARM::AK_ARMV7A:
602 case ARM::AK_ARMV7R:
603 case ARM::AK_ARMV7M:
604 case ARM::AK_ARMV7L:
605 case ARM::AK_ARMV7HL:
606 case ARM::AK_ARMV7S:
607 case ARM::AK_ARMV7EM:
608 return 7;
609 case ARM::AK_ARMV8A:
610 case ARM::AK_ARMV8_1A:
611 return 8;
612 }
613 return 0;
614}