1 //===----------- TargetParser.cpp - Target Parser -------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/Support/TargetParser.h"
11 #include "llvm/ADT/STLExtras.h"
12 #include "llvm/Support/ARMBuildAttributes.h"
13 #include "gtest/gtest.h"
19 const char *ARMArch[] = {
20 "armv2", "armv2a", "armv3", "armv3m", "armv4",
21 "armv4t", "armv5", "armv5t", "armv5e", "armv5te",
22 "armv5tej", "armv6", "armv6j", "armv6k", "armv6hl",
23 "armv6t2", "armv6kz", "armv6z", "armv6zk", "armv6-m",
24 "armv6m", "armv6sm", "armv6s-m", "armv7-a", "armv7",
25 "armv7a", "armv7ve", "armv7hl", "armv7l", "armv7-r",
26 "armv7r", "armv7-m", "armv7m", "armv7k", "armv7s",
27 "armv7e-m", "armv7em", "armv8-a", "armv8", "armv8a",
28 "armv8l", "armv8.1-a", "armv8.1a", "armv8.2-a", "armv8.2a",
29 "armv8.3-a", "armv8.3a", "armv8-r", "armv8r", "armv8-m.base",
30 "armv8m.base", "armv8-m.main", "armv8m.main", "iwmmxt", "iwmmxt2",
33 bool testARMCPU(StringRef CPUName, StringRef ExpectedArch,
34 StringRef ExpectedFPU, unsigned ExpectedFlags,
36 ARM::ArchKind AK = ARM::parseCPUArch(CPUName);
37 bool pass = ARM::getArchName(AK).equals(ExpectedArch);
38 unsigned FPUKind = ARM::getDefaultFPU(CPUName, AK);
39 pass &= ARM::getFPUName(FPUKind).equals(ExpectedFPU);
41 unsigned ExtKind = ARM::getDefaultExtensions(CPUName, AK);
42 if (ExtKind > 1 && (ExtKind & ARM::AEK_NONE))
43 pass &= ((ExtKind ^ ARM::AEK_NONE) == ExpectedFlags);
45 pass &= (ExtKind == ExpectedFlags);
47 pass &= ARM::getCPUAttr(AK).equals(CPUAttr);
52 TEST(TargetParserTest, testARMCPU) {
53 EXPECT_TRUE(testARMCPU("invalid", "invalid", "invalid",
55 EXPECT_TRUE(testARMCPU("generic", "invalid", "none",
58 EXPECT_TRUE(testARMCPU("arm2", "armv2", "none",
60 EXPECT_TRUE(testARMCPU("arm3", "armv2a", "none",
61 ARM::AEK_NONE, "2A"));
62 EXPECT_TRUE(testARMCPU("arm6", "armv3", "none",
64 EXPECT_TRUE(testARMCPU("arm7m", "armv3m", "none",
65 ARM::AEK_NONE, "3M"));
66 EXPECT_TRUE(testARMCPU("arm8", "armv4", "none",
68 EXPECT_TRUE(testARMCPU("arm810", "armv4", "none",
70 EXPECT_TRUE(testARMCPU("strongarm", "armv4", "none",
72 EXPECT_TRUE(testARMCPU("strongarm110", "armv4", "none",
74 EXPECT_TRUE(testARMCPU("strongarm1100", "armv4", "none",
76 EXPECT_TRUE(testARMCPU("strongarm1110", "armv4", "none",
78 EXPECT_TRUE(testARMCPU("arm7tdmi", "armv4t", "none",
79 ARM::AEK_NONE, "4T"));
80 EXPECT_TRUE(testARMCPU("arm7tdmi-s", "armv4t", "none",
81 ARM::AEK_NONE, "4T"));
82 EXPECT_TRUE(testARMCPU("arm710t", "armv4t", "none",
83 ARM::AEK_NONE, "4T"));
84 EXPECT_TRUE(testARMCPU("arm720t", "armv4t", "none",
85 ARM::AEK_NONE, "4T"));
86 EXPECT_TRUE(testARMCPU("arm9", "armv4t", "none",
87 ARM::AEK_NONE, "4T"));
88 EXPECT_TRUE(testARMCPU("arm9tdmi", "armv4t", "none",
89 ARM::AEK_NONE, "4T"));
90 EXPECT_TRUE(testARMCPU("arm920", "armv4t", "none",
91 ARM::AEK_NONE, "4T"));
92 EXPECT_TRUE(testARMCPU("arm920t", "armv4t", "none",
93 ARM::AEK_NONE, "4T"));
94 EXPECT_TRUE(testARMCPU("arm922t", "armv4t", "none",
95 ARM::AEK_NONE, "4T"));
96 EXPECT_TRUE(testARMCPU("arm9312", "armv4t", "none",
97 ARM::AEK_NONE, "4T"));
98 EXPECT_TRUE(testARMCPU("arm940t", "armv4t", "none",
99 ARM::AEK_NONE, "4T"));
100 EXPECT_TRUE(testARMCPU("ep9312", "armv4t", "none",
101 ARM::AEK_NONE, "4T"));
102 EXPECT_TRUE(testARMCPU("arm10tdmi", "armv5t", "none",
103 ARM::AEK_NONE, "5T"));
104 EXPECT_TRUE(testARMCPU("arm1020t", "armv5t", "none",
105 ARM::AEK_NONE, "5T"));
106 EXPECT_TRUE(testARMCPU("arm9e", "armv5te", "none",
107 ARM::AEK_DSP, "5TE"));
108 EXPECT_TRUE(testARMCPU("arm946e-s", "armv5te", "none",
109 ARM::AEK_DSP, "5TE"));
110 EXPECT_TRUE(testARMCPU("arm966e-s", "armv5te", "none",
111 ARM::AEK_DSP, "5TE"));
112 EXPECT_TRUE(testARMCPU("arm968e-s", "armv5te", "none",
113 ARM::AEK_DSP, "5TE"));
114 EXPECT_TRUE(testARMCPU("arm10e", "armv5te", "none",
115 ARM::AEK_DSP, "5TE"));
116 EXPECT_TRUE(testARMCPU("arm1020e", "armv5te", "none",
117 ARM::AEK_DSP, "5TE"));
118 EXPECT_TRUE(testARMCPU("arm1022e", "armv5te", "none",
119 ARM::AEK_DSP, "5TE"));
120 EXPECT_TRUE(testARMCPU("arm926ej-s", "armv5tej", "none",
121 ARM::AEK_DSP, "5TEJ"));
122 EXPECT_TRUE(testARMCPU("arm1136j-s", "armv6", "none",
124 EXPECT_TRUE(testARMCPU("arm1136jf-s", "armv6", "vfpv2",
126 EXPECT_TRUE(testARMCPU("arm1136jz-s", "armv6", "none",
128 EXPECT_TRUE(testARMCPU("arm1176j-s", "armv6k", "none",
129 ARM::AEK_DSP, "6K"));
130 EXPECT_TRUE(testARMCPU("arm1176jz-s", "armv6kz", "none",
131 ARM::AEK_SEC | ARM::AEK_DSP, "6KZ"));
132 EXPECT_TRUE(testARMCPU("mpcore", "armv6k", "vfpv2",
133 ARM::AEK_DSP, "6K"));
134 EXPECT_TRUE(testARMCPU("mpcorenovfp", "armv6k", "none",
135 ARM::AEK_DSP, "6K"));
136 EXPECT_TRUE(testARMCPU("arm1176jzf-s", "armv6kz", "vfpv2",
137 ARM::AEK_SEC | ARM::AEK_DSP, "6KZ"));
138 EXPECT_TRUE(testARMCPU("arm1156t2-s", "armv6t2", "none",
139 ARM::AEK_DSP, "6T2"));
140 EXPECT_TRUE(testARMCPU("arm1156t2f-s", "armv6t2", "vfpv2",
141 ARM::AEK_DSP, "6T2"));
142 EXPECT_TRUE(testARMCPU("cortex-m0", "armv6-m", "none",
143 ARM::AEK_NONE, "6-M"));
144 EXPECT_TRUE(testARMCPU("cortex-m0plus", "armv6-m", "none",
145 ARM::AEK_NONE, "6-M"));
146 EXPECT_TRUE(testARMCPU("cortex-m1", "armv6-m", "none",
147 ARM::AEK_NONE, "6-M"));
148 EXPECT_TRUE(testARMCPU("sc000", "armv6-m", "none",
149 ARM::AEK_NONE, "6-M"));
150 EXPECT_TRUE(testARMCPU("cortex-a5", "armv7-a", "neon-vfpv4",
151 ARM::AEK_MP | ARM::AEK_SEC | ARM::AEK_DSP, "7-A"));
152 EXPECT_TRUE(testARMCPU("cortex-a7", "armv7-a", "neon-vfpv4",
153 ARM::AEK_HWDIVTHUMB | ARM::AEK_HWDIVARM | ARM::AEK_MP |
154 ARM::AEK_SEC | ARM::AEK_VIRT | ARM::AEK_DSP,
156 EXPECT_TRUE(testARMCPU("cortex-a8", "armv7-a", "neon",
157 ARM::AEK_SEC | ARM::AEK_DSP, "7-A"));
158 EXPECT_TRUE(testARMCPU("cortex-a9", "armv7-a", "neon-fp16",
159 ARM::AEK_MP | ARM::AEK_SEC | ARM::AEK_DSP, "7-A"));
160 EXPECT_TRUE(testARMCPU("cortex-a12", "armv7-a", "neon-vfpv4",
161 ARM::AEK_SEC | ARM::AEK_MP | ARM::AEK_VIRT |
162 ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
165 EXPECT_TRUE(testARMCPU("cortex-a15", "armv7-a", "neon-vfpv4",
166 ARM::AEK_SEC | ARM::AEK_MP | ARM::AEK_VIRT |
167 ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
170 EXPECT_TRUE(testARMCPU("cortex-a17", "armv7-a", "neon-vfpv4",
171 ARM::AEK_SEC | ARM::AEK_MP | ARM::AEK_VIRT |
172 ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
175 EXPECT_TRUE(testARMCPU("krait", "armv7-a", "neon-vfpv4",
176 ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
178 EXPECT_TRUE(testARMCPU("cortex-r4", "armv7-r", "none",
179 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP, "7-R"));
180 EXPECT_TRUE(testARMCPU("cortex-r4f", "armv7-r", "vfpv3-d16",
181 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP, "7-R"));
182 EXPECT_TRUE(testARMCPU("cortex-r5", "armv7-r", "vfpv3-d16",
183 ARM::AEK_MP | ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
186 EXPECT_TRUE(testARMCPU("cortex-r7", "armv7-r", "vfpv3-d16-fp16",
187 ARM::AEK_MP | ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
190 EXPECT_TRUE(testARMCPU("cortex-r8", "armv7-r", "vfpv3-d16-fp16",
191 ARM::AEK_MP | ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
194 EXPECT_TRUE(testARMCPU("cortex-r52", "armv8-r", "neon-fp-armv8",
195 ARM::AEK_CRC | ARM::AEK_MP | ARM::AEK_VIRT |
196 ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
200 testARMCPU("sc300", "armv7-m", "none", ARM::AEK_HWDIVTHUMB, "7-M"));
202 testARMCPU("cortex-m3", "armv7-m", "none", ARM::AEK_HWDIVTHUMB, "7-M"));
203 EXPECT_TRUE(testARMCPU("cortex-m4", "armv7e-m", "fpv4-sp-d16",
204 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP, "7E-M"));
205 EXPECT_TRUE(testARMCPU("cortex-m7", "armv7e-m", "fpv5-d16",
206 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP, "7E-M"));
207 EXPECT_TRUE(testARMCPU("cortex-a32", "armv8-a", "crypto-neon-fp-armv8",
208 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
209 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
210 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
212 EXPECT_TRUE(testARMCPU("cortex-a35", "armv8-a", "crypto-neon-fp-armv8",
213 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
214 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
215 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
217 EXPECT_TRUE(testARMCPU("cortex-a53", "armv8-a", "crypto-neon-fp-armv8",
218 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
219 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
220 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
222 EXPECT_TRUE(testARMCPU("cortex-a55", "armv8.2-a", "crypto-neon-fp-armv8",
223 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
224 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
225 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP | ARM::AEK_FP16 |
226 ARM::AEK_RAS | ARM::AEK_DOTPROD,
228 EXPECT_TRUE(testARMCPU("cortex-a57", "armv8-a", "crypto-neon-fp-armv8",
229 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
230 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
231 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
233 EXPECT_TRUE(testARMCPU("cortex-a72", "armv8-a", "crypto-neon-fp-armv8",
234 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
235 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
236 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
238 EXPECT_TRUE(testARMCPU("cortex-a73", "armv8-a", "crypto-neon-fp-armv8",
239 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
240 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
241 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
243 EXPECT_TRUE(testARMCPU("cortex-a75", "armv8.2-a", "crypto-neon-fp-armv8",
244 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
245 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
246 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP | ARM::AEK_FP16 |
247 ARM::AEK_RAS | ARM::AEK_DOTPROD,
249 EXPECT_TRUE(testARMCPU("cyclone", "armv8-a", "crypto-neon-fp-armv8",
250 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
251 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
252 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
254 EXPECT_TRUE(testARMCPU("exynos-m1", "armv8-a", "crypto-neon-fp-armv8",
255 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
256 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
257 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
259 EXPECT_TRUE(testARMCPU("exynos-m2", "armv8-a", "crypto-neon-fp-armv8",
260 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
261 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
262 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
264 EXPECT_TRUE(testARMCPU("exynos-m3", "armv8-a", "crypto-neon-fp-armv8",
265 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
266 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
267 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
269 EXPECT_TRUE(testARMCPU("cortex-m23", "armv8-m.base", "none",
270 ARM::AEK_HWDIVTHUMB, "8-M.Baseline"));
271 EXPECT_TRUE(testARMCPU("cortex-m33", "armv8-m.main", "fpv5-sp-d16",
272 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP, "8-M.Mainline"));
273 EXPECT_TRUE(testARMCPU("iwmmxt", "iwmmxt", "none",
274 ARM::AEK_NONE, "iwmmxt"));
275 EXPECT_TRUE(testARMCPU("xscale", "xscale", "none",
276 ARM::AEK_NONE, "xscale"));
277 EXPECT_TRUE(testARMCPU("swift", "armv7s", "neon-vfpv4",
278 ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
282 static constexpr unsigned NumARMCPUArchs = 82;
284 TEST(TargetParserTest, testARMCPUArchList) {
285 SmallVector<StringRef, NumARMCPUArchs> List;
286 ARM::fillValidCPUArchList(List);
288 // No list exists for these in this test suite, so ensure all are
289 // valid, and match the expected 'magic' count.
290 EXPECT_EQ(List.size(), NumARMCPUArchs);
291 for(StringRef CPU : List) {
292 EXPECT_NE(ARM::parseCPUArch(CPU), ARM::ArchKind::INVALID);
296 TEST(TargetParserTest, testInvalidARMArch) {
297 auto InvalidArchStrings = {"armv", "armv99", "noarm"};
298 for (const char* InvalidArch : InvalidArchStrings)
299 EXPECT_EQ(ARM::parseArch(InvalidArch), ARM::ArchKind::INVALID);
302 bool testARMArch(StringRef Arch, StringRef DefaultCPU, StringRef SubArch,
304 ARM::ArchKind AK = ARM::parseArch(Arch);
305 return (AK!= ARM::ArchKind::INVALID) &
306 ARM::getDefaultCPU(Arch).equals(DefaultCPU) &
307 ARM::getSubArch(AK).equals(SubArch) &
308 (ARM::getArchAttr(AK) == ArchAttr);
311 TEST(TargetParserTest, testARMArch) {
313 testARMArch("armv2", "arm2", "v2",
314 ARMBuildAttrs::CPUArch::Pre_v4));
316 testARMArch("armv2a", "arm3", "v2a",
317 ARMBuildAttrs::CPUArch::Pre_v4));
319 testARMArch("armv3", "arm6", "v3",
320 ARMBuildAttrs::CPUArch::Pre_v4));
322 testARMArch("armv3m", "arm7m", "v3m",
323 ARMBuildAttrs::CPUArch::Pre_v4));
325 testARMArch("armv4", "strongarm", "v4",
326 ARMBuildAttrs::CPUArch::v4));
328 testARMArch("armv4t", "arm7tdmi", "v4t",
329 ARMBuildAttrs::CPUArch::v4T));
331 testARMArch("armv5t", "arm10tdmi", "v5",
332 ARMBuildAttrs::CPUArch::v5T));
334 testARMArch("armv5te", "arm1022e", "v5e",
335 ARMBuildAttrs::CPUArch::v5TE));
337 testARMArch("armv5tej", "arm926ej-s", "v5e",
338 ARMBuildAttrs::CPUArch::v5TEJ));
340 testARMArch("armv6", "arm1136jf-s", "v6",
341 ARMBuildAttrs::CPUArch::v6));
343 testARMArch("armv6k", "arm1176j-s", "v6k",
344 ARMBuildAttrs::CPUArch::v6K));
346 testARMArch("armv6t2", "arm1156t2-s", "v6t2",
347 ARMBuildAttrs::CPUArch::v6T2));
349 testARMArch("armv6kz", "arm1176jzf-s", "v6kz",
350 ARMBuildAttrs::CPUArch::v6KZ));
352 testARMArch("armv6-m", "cortex-m0", "v6m",
353 ARMBuildAttrs::CPUArch::v6_M));
355 testARMArch("armv7-a", "generic", "v7",
356 ARMBuildAttrs::CPUArch::v7));
358 testARMArch("armv7ve", "generic", "v7ve",
359 ARMBuildAttrs::CPUArch::v7));
361 testARMArch("armv7-r", "cortex-r4", "v7r",
362 ARMBuildAttrs::CPUArch::v7));
364 testARMArch("armv7-m", "cortex-m3", "v7m",
365 ARMBuildAttrs::CPUArch::v7));
367 testARMArch("armv7e-m", "cortex-m4", "v7em",
368 ARMBuildAttrs::CPUArch::v7E_M));
370 testARMArch("armv8-a", "generic", "v8",
371 ARMBuildAttrs::CPUArch::v8_A));
373 testARMArch("armv8.1-a", "generic", "v8.1a",
374 ARMBuildAttrs::CPUArch::v8_A));
376 testARMArch("armv8.2-a", "generic", "v8.2a",
377 ARMBuildAttrs::CPUArch::v8_A));
379 testARMArch("armv8.3-a", "generic", "v8.3a",
380 ARMBuildAttrs::CPUArch::v8_A));
382 testARMArch("armv8-r", "cortex-r52", "v8r",
383 ARMBuildAttrs::CPUArch::v8_R));
385 testARMArch("armv8-m.base", "generic", "v8m.base",
386 ARMBuildAttrs::CPUArch::v8_M_Base));
388 testARMArch("armv8-m.main", "generic", "v8m.main",
389 ARMBuildAttrs::CPUArch::v8_M_Main));
391 testARMArch("iwmmxt", "iwmmxt", "",
392 ARMBuildAttrs::CPUArch::v5TE));
394 testARMArch("iwmmxt2", "generic", "",
395 ARMBuildAttrs::CPUArch::v5TE));
397 testARMArch("xscale", "xscale", "v5e",
398 ARMBuildAttrs::CPUArch::v5TE));
400 testARMArch("armv7s", "swift", "v7s",
401 ARMBuildAttrs::CPUArch::v7));
403 testARMArch("armv7k", "generic", "v7k",
404 ARMBuildAttrs::CPUArch::v7));
407 bool testARMExtension(StringRef CPUName,ARM::ArchKind ArchKind, StringRef ArchExt) {
408 return ARM::getDefaultExtensions(CPUName, ArchKind) &
409 ARM::parseArchExt(ArchExt);
412 TEST(TargetParserTest, testARMExtension) {
413 EXPECT_FALSE(testARMExtension("arm2", ARM::ArchKind::INVALID, "thumb"));
414 EXPECT_FALSE(testARMExtension("arm3", ARM::ArchKind::INVALID, "thumb"));
415 EXPECT_FALSE(testARMExtension("arm6", ARM::ArchKind::INVALID, "thumb"));
416 EXPECT_FALSE(testARMExtension("arm7m", ARM::ArchKind::INVALID, "thumb"));
417 EXPECT_FALSE(testARMExtension("strongarm", ARM::ArchKind::INVALID, "dsp"));
418 EXPECT_FALSE(testARMExtension("arm7tdmi", ARM::ArchKind::INVALID, "dsp"));
419 EXPECT_FALSE(testARMExtension("arm10tdmi",
420 ARM::ArchKind::INVALID, "simd"));
421 EXPECT_FALSE(testARMExtension("arm1022e", ARM::ArchKind::INVALID, "simd"));
422 EXPECT_FALSE(testARMExtension("arm926ej-s",
423 ARM::ArchKind::INVALID, "simd"));
424 EXPECT_FALSE(testARMExtension("arm1136jf-s",
425 ARM::ArchKind::INVALID, "crypto"));
426 EXPECT_FALSE(testARMExtension("arm1176j-s",
427 ARM::ArchKind::INVALID, "crypto"));
428 EXPECT_FALSE(testARMExtension("arm1156t2-s",
429 ARM::ArchKind::INVALID, "crypto"));
430 EXPECT_FALSE(testARMExtension("arm1176jzf-s",
431 ARM::ArchKind::INVALID, "crypto"));
432 EXPECT_FALSE(testARMExtension("cortex-m0",
433 ARM::ArchKind::INVALID, "crypto"));
434 EXPECT_FALSE(testARMExtension("cortex-a8",
435 ARM::ArchKind::INVALID, "crypto"));
436 EXPECT_FALSE(testARMExtension("cortex-r4",
437 ARM::ArchKind::INVALID, "crypto"));
438 EXPECT_FALSE(testARMExtension("cortex-m3",
439 ARM::ArchKind::INVALID, "crypto"));
440 EXPECT_FALSE(testARMExtension("cortex-a53",
441 ARM::ArchKind::INVALID, "ras"));
442 EXPECT_FALSE(testARMExtension("cortex-r52",
443 ARM::ArchKind::INVALID, "ras"));
444 EXPECT_FALSE(testARMExtension("iwmmxt", ARM::ArchKind::INVALID, "crc"));
445 EXPECT_FALSE(testARMExtension("xscale", ARM::ArchKind::INVALID, "crc"));
446 EXPECT_FALSE(testARMExtension("swift", ARM::ArchKind::INVALID, "crc"));
448 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV2, "thumb"));
449 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV2A, "thumb"));
450 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV3, "thumb"));
451 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV3M, "thumb"));
452 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV4, "dsp"));
453 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV4T, "dsp"));
454 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV5T, "simd"));
455 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV5TE, "simd"));
456 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV5TEJ, "simd"));
457 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV6, "crypto"));
458 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV6K, "crypto"));
459 EXPECT_FALSE(testARMExtension("generic",
460 ARM::ArchKind::ARMV6T2, "crypto"));
461 EXPECT_FALSE(testARMExtension("generic",
462 ARM::ArchKind::ARMV6KZ, "crypto"));
463 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV6M, "crypto"));
464 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV7A, "crypto"));
465 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV7R, "crypto"));
466 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV7M, "crypto"));
467 EXPECT_FALSE(testARMExtension("generic",
468 ARM::ArchKind::ARMV7EM, "crypto"));
469 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8A, "ras"));
470 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8_1A, "ras"));
471 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8_2A, "spe"));
472 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8R, "ras"));
473 EXPECT_FALSE(testARMExtension("generic",
474 ARM::ArchKind::ARMV8MBaseline, "crc"));
475 EXPECT_FALSE(testARMExtension("generic",
476 ARM::ArchKind::ARMV8MMainline, "crc"));
477 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::IWMMXT, "crc"));
478 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::IWMMXT2, "crc"));
479 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::XSCALE, "crc"));
480 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV7S, "crypto"));
481 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV7K, "crypto"));
484 TEST(TargetParserTest, ARMFPUVersion) {
485 for (ARM::FPUKind FK = static_cast<ARM::FPUKind>(0);
486 FK <= ARM::FPUKind::FK_LAST;
487 FK = static_cast<ARM::FPUKind>(static_cast<unsigned>(FK) + 1))
488 if (FK == ARM::FK_LAST || ARM::getFPUName(FK) == "invalid" ||
489 ARM::getFPUName(FK) == "none" || ARM::getFPUName(FK) == "softvfp")
490 EXPECT_EQ(ARM::FPUVersion::NONE, ARM::getFPUVersion(FK));
492 EXPECT_NE(ARM::FPUVersion::NONE, ARM::getFPUVersion(FK));
495 TEST(TargetParserTest, ARMFPUNeonSupportLevel) {
496 for (ARM::FPUKind FK = static_cast<ARM::FPUKind>(0);
497 FK <= ARM::FPUKind::FK_LAST;
498 FK = static_cast<ARM::FPUKind>(static_cast<unsigned>(FK) + 1))
499 if (FK == ARM::FK_LAST ||
500 ARM::getFPUName(FK).find("neon") == std::string::npos)
501 EXPECT_EQ(ARM::NeonSupportLevel::None,
502 ARM::getFPUNeonSupportLevel(FK));
504 EXPECT_NE(ARM::NeonSupportLevel::None,
505 ARM::getFPUNeonSupportLevel(FK));
508 TEST(TargetParserTest, ARMFPURestriction) {
509 for (ARM::FPUKind FK = static_cast<ARM::FPUKind>(0);
510 FK <= ARM::FPUKind::FK_LAST;
511 FK = static_cast<ARM::FPUKind>(static_cast<unsigned>(FK) + 1)) {
512 if (FK == ARM::FK_LAST ||
513 (ARM::getFPUName(FK).find("d16") == std::string::npos &&
514 ARM::getFPUName(FK).find("vfpv3xd") == std::string::npos))
515 EXPECT_EQ(ARM::FPURestriction::None, ARM::getFPURestriction(FK));
517 EXPECT_NE(ARM::FPURestriction::None, ARM::getFPURestriction(FK));
521 TEST(TargetParserTest, ARMExtensionFeatures) {
522 std::vector<StringRef> Features;
523 unsigned Extensions = ARM::AEK_CRC | ARM::AEK_CRYPTO | ARM::AEK_DSP |
524 ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB | ARM::AEK_MP |
525 ARM::AEK_SEC | ARM::AEK_VIRT | ARM::AEK_RAS;
527 for (unsigned i = 0; i <= Extensions; i++)
528 EXPECT_TRUE(i == 0 ? !ARM::getExtensionFeatures(i, Features)
529 : ARM::getExtensionFeatures(i, Features));
532 TEST(TargetParserTest, ARMFPUFeatures) {
533 std::vector<StringRef> Features;
534 for (ARM::FPUKind FK = static_cast<ARM::FPUKind>(0);
535 FK <= ARM::FPUKind::FK_LAST;
536 FK = static_cast<ARM::FPUKind>(static_cast<unsigned>(FK) + 1))
537 EXPECT_TRUE((FK == ARM::FK_INVALID || FK >= ARM::FK_LAST)
538 ? !ARM::getFPUFeatures(FK, Features)
539 : ARM::getFPUFeatures(FK, Features));
542 TEST(TargetParserTest, ARMArchExtFeature) {
543 const char *ArchExt[][4] = {{"crc", "nocrc", "+crc", "-crc"},
544 {"crypto", "nocrypto", "+crypto", "-crypto"},
545 {"dsp", "nodsp", "+dsp", "-dsp"},
546 {"fp", "nofp", nullptr, nullptr},
547 {"idiv", "noidiv", nullptr, nullptr},
548 {"mp", "nomp", nullptr, nullptr},
549 {"simd", "nosimd", nullptr, nullptr},
550 {"sec", "nosec", nullptr, nullptr},
551 {"virt", "novirt", nullptr, nullptr},
552 {"fp16", "nofp16", "+fullfp16", "-fullfp16"},
553 {"ras", "noras", "+ras", "-ras"},
554 {"dotprod", "nodotprod", "+dotprod", "-dotprod"},
555 {"os", "noos", nullptr, nullptr},
556 {"iwmmxt", "noiwmmxt", nullptr, nullptr},
557 {"iwmmxt2", "noiwmmxt2", nullptr, nullptr},
558 {"maverick", "maverick", nullptr, nullptr},
559 {"xscale", "noxscale", nullptr, nullptr}};
561 for (unsigned i = 0; i < array_lengthof(ArchExt); i++) {
562 EXPECT_EQ(StringRef(ArchExt[i][2]), ARM::getArchExtFeature(ArchExt[i][0]));
563 EXPECT_EQ(StringRef(ArchExt[i][3]), ARM::getArchExtFeature(ArchExt[i][1]));
567 TEST(TargetParserTest, ARMparseHWDiv) {
568 const char *hwdiv[] = {"thumb", "arm", "arm,thumb", "thumb,arm"};
570 for (unsigned i = 0; i < array_lengthof(hwdiv); i++)
571 EXPECT_NE(ARM::AEK_INVALID, ARM::parseHWDiv((StringRef)hwdiv[i]));
574 TEST(TargetParserTest, ARMparseArchEndianAndISA) {
575 const char *Arch[] = {
576 "v2", "v2a", "v3", "v3m", "v4", "v4t", "v5", "v5t",
577 "v5e", "v5te", "v5tej", "v6", "v6j", "v6k", "v6hl", "v6t2",
578 "v6kz", "v6z", "v6zk", "v6-m", "v6m", "v6sm", "v6s-m", "v7-a",
579 "v7", "v7a", "v7ve", "v7hl", "v7l", "v7-r", "v7r", "v7-m",
580 "v7m", "v7k", "v7s", "v7e-m", "v7em", "v8-a", "v8", "v8a",
581 "v8l", "v8.1-a", "v8.1a", "v8.2-a", "v8.2a", "v8.3-a", "v8.3a", "v8-r"};
583 for (unsigned i = 0; i < array_lengthof(Arch); i++) {
584 std::string arm_1 = "armeb" + (std::string)(Arch[i]);
585 std::string arm_2 = "arm" + (std::string)(Arch[i]) + "eb";
586 std::string arm_3 = "arm" + (std::string)(Arch[i]);
587 std::string thumb_1 = "thumbeb" + (std::string)(Arch[i]);
588 std::string thumb_2 = "thumb" + (std::string)(Arch[i]) + "eb";
589 std::string thumb_3 = "thumb" + (std::string)(Arch[i]);
591 EXPECT_EQ(ARM::EndianKind::BIG, ARM::parseArchEndian(arm_1));
592 EXPECT_EQ(ARM::EndianKind::BIG, ARM::parseArchEndian(arm_2));
593 EXPECT_EQ(ARM::EndianKind::LITTLE, ARM::parseArchEndian(arm_3));
595 EXPECT_EQ(ARM::ISAKind::ARM, ARM::parseArchISA(arm_1));
596 EXPECT_EQ(ARM::ISAKind::ARM, ARM::parseArchISA(arm_2));
597 EXPECT_EQ(ARM::ISAKind::ARM, ARM::parseArchISA(arm_3));
599 EXPECT_EQ(ARM::EndianKind::BIG, ARM::parseArchEndian(thumb_1));
600 EXPECT_EQ(ARM::EndianKind::BIG, ARM::parseArchEndian(thumb_2));
601 EXPECT_EQ(ARM::EndianKind::LITTLE, ARM::parseArchEndian(thumb_3));
603 EXPECT_EQ(ARM::ISAKind::THUMB, ARM::parseArchISA(thumb_1));
604 EXPECT_EQ(ARM::ISAKind::THUMB, ARM::parseArchISA(thumb_2));
605 EXPECT_EQ(ARM::ISAKind::THUMB, ARM::parseArchISA(thumb_3));
609 EXPECT_EQ(ARM::EndianKind::LITTLE, ARM::parseArchEndian("aarch64"));
610 EXPECT_EQ(ARM::EndianKind::BIG, ARM::parseArchEndian("aarch64_be"));
612 EXPECT_EQ(ARM::ISAKind::AARCH64, ARM::parseArchISA("aarch64"));
613 EXPECT_EQ(ARM::ISAKind::AARCH64, ARM::parseArchISA("aarch64_be"));
614 EXPECT_EQ(ARM::ISAKind::AARCH64, ARM::parseArchISA("arm64"));
615 EXPECT_EQ(ARM::ISAKind::AARCH64, ARM::parseArchISA("arm64_be"));
618 TEST(TargetParserTest, ARMparseArchProfile) {
619 for (unsigned i = 0; i < array_lengthof(ARMArch); i++) {
620 switch (ARM::parseArch(ARMArch[i])) {
621 case ARM::ArchKind::ARMV6M:
622 case ARM::ArchKind::ARMV7M:
623 case ARM::ArchKind::ARMV7EM:
624 case ARM::ArchKind::ARMV8MMainline:
625 case ARM::ArchKind::ARMV8MBaseline:
626 EXPECT_EQ(ARM::ProfileKind::M, ARM::parseArchProfile(ARMArch[i]));
628 case ARM::ArchKind::ARMV7R:
629 case ARM::ArchKind::ARMV8R:
630 EXPECT_EQ(ARM::ProfileKind::R, ARM::parseArchProfile(ARMArch[i]));
632 case ARM::ArchKind::ARMV7A:
633 case ARM::ArchKind::ARMV7VE:
634 case ARM::ArchKind::ARMV7K:
635 case ARM::ArchKind::ARMV8A:
636 case ARM::ArchKind::ARMV8_1A:
637 case ARM::ArchKind::ARMV8_2A:
638 case ARM::ArchKind::ARMV8_3A:
639 EXPECT_EQ(ARM::ProfileKind::A, ARM::parseArchProfile(ARMArch[i]));
642 EXPECT_EQ(ARM::ProfileKind::INVALID, ARM::parseArchProfile(ARMArch[i]));
648 TEST(TargetParserTest, ARMparseArchVersion) {
649 for (unsigned i = 0; i < array_lengthof(ARMArch); i++)
650 if (((std::string)ARMArch[i]).substr(0, 4) == "armv")
651 EXPECT_EQ((ARMArch[i][4] - 48u), ARM::parseArchVersion(ARMArch[i]));
653 EXPECT_EQ(5u, ARM::parseArchVersion(ARMArch[i]));
656 bool testAArch64CPU(StringRef CPUName, StringRef ExpectedArch,
657 StringRef ExpectedFPU, unsigned ExpectedFlags,
659 AArch64::ArchKind AK = AArch64::parseCPUArch(CPUName);
660 bool pass = AArch64::getArchName(AK).equals(ExpectedArch);
661 unsigned FPUKind = AArch64::getDefaultFPU(CPUName, AK);
662 pass &= AArch64::getFPUName(FPUKind).equals(ExpectedFPU);
664 unsigned ExtKind = AArch64::getDefaultExtensions(CPUName, AK);
665 if (ExtKind > 1 && (ExtKind & AArch64::AEK_NONE))
666 pass &= ((ExtKind ^ AArch64::AEK_NONE) == ExpectedFlags);
668 pass &= (ExtKind == ExpectedFlags);
670 pass &= AArch64::getCPUAttr(AK).equals(CPUAttr);
675 TEST(TargetParserTest, testAArch64CPU) {
676 EXPECT_TRUE(testAArch64CPU(
677 "invalid", "invalid", "invalid",
678 AArch64::AEK_NONE, ""));
679 EXPECT_TRUE(testAArch64CPU(
680 "generic", "invalid", "none",
681 AArch64::AEK_NONE, ""));
683 EXPECT_TRUE(testAArch64CPU(
684 "cortex-a35", "armv8-a", "crypto-neon-fp-armv8",
685 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
686 AArch64::AEK_SIMD, "8-A"));
687 EXPECT_TRUE(testAArch64CPU(
688 "cortex-a53", "armv8-a", "crypto-neon-fp-armv8",
689 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
690 AArch64::AEK_SIMD, "8-A"));
691 EXPECT_TRUE(testAArch64CPU(
692 "cortex-a55", "armv8.2-a", "crypto-neon-fp-armv8",
693 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
694 AArch64::AEK_SIMD | AArch64::AEK_RAS | AArch64::AEK_LSE |
695 AArch64::AEK_RDM | AArch64::AEK_FP16 | AArch64::AEK_DOTPROD |
696 AArch64::AEK_RCPC, "8.2-A"));
697 EXPECT_TRUE(testAArch64CPU(
698 "cortex-a57", "armv8-a", "crypto-neon-fp-armv8",
699 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
700 AArch64::AEK_SIMD, "8-A"));
701 EXPECT_TRUE(testAArch64CPU(
702 "cortex-a72", "armv8-a", "crypto-neon-fp-armv8",
703 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
704 AArch64::AEK_SIMD, "8-A"));
705 EXPECT_TRUE(testAArch64CPU(
706 "cortex-a73", "armv8-a", "crypto-neon-fp-armv8",
707 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
708 AArch64::AEK_SIMD, "8-A"));
709 EXPECT_TRUE(testAArch64CPU(
710 "cortex-a75", "armv8.2-a", "crypto-neon-fp-armv8",
711 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
712 AArch64::AEK_SIMD | AArch64::AEK_RAS | AArch64::AEK_LSE |
713 AArch64::AEK_RDM | AArch64::AEK_FP16 | AArch64::AEK_DOTPROD |
714 AArch64::AEK_RCPC, "8.2-A"));
715 EXPECT_TRUE(testAArch64CPU(
716 "cyclone", "armv8-a", "crypto-neon-fp-armv8",
717 AArch64::AEK_CRYPTO | AArch64::AEK_FP | AArch64::AEK_SIMD, "8-A"));
718 EXPECT_TRUE(testAArch64CPU(
719 "exynos-m1", "armv8-a", "crypto-neon-fp-armv8",
720 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
721 AArch64::AEK_SIMD, "8-A"));
722 EXPECT_TRUE(testAArch64CPU(
723 "exynos-m2", "armv8-a", "crypto-neon-fp-armv8",
724 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
725 AArch64::AEK_SIMD, "8-A"));
726 EXPECT_TRUE(testAArch64CPU(
727 "exynos-m3", "armv8-a", "crypto-neon-fp-armv8",
728 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
729 AArch64::AEK_SIMD, "8-A"));
730 EXPECT_TRUE(testAArch64CPU(
731 "falkor", "armv8-a", "crypto-neon-fp-armv8",
732 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
733 AArch64::AEK_SIMD | AArch64::AEK_RDM, "8-A"));
734 EXPECT_TRUE(testAArch64CPU(
735 "kryo", "armv8-a", "crypto-neon-fp-armv8",
736 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
737 AArch64::AEK_SIMD, "8-A"));
738 EXPECT_TRUE(testAArch64CPU(
739 "thunderx2t99", "armv8.1-a", "crypto-neon-fp-armv8",
740 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_LSE |
741 AArch64::AEK_RDM | AArch64::AEK_FP | AArch64::AEK_SIMD, "8.1-A"));
742 EXPECT_TRUE(testAArch64CPU(
743 "thunderx", "armv8-a", "crypto-neon-fp-armv8",
744 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_SIMD |
745 AArch64::AEK_FP | AArch64::AEK_PROFILE,
747 EXPECT_TRUE(testAArch64CPU(
748 "thunderxt81", "armv8-a", "crypto-neon-fp-armv8",
749 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_SIMD |
750 AArch64::AEK_FP | AArch64::AEK_PROFILE,
752 EXPECT_TRUE(testAArch64CPU(
753 "thunderxt83", "armv8-a", "crypto-neon-fp-armv8",
754 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_SIMD |
755 AArch64::AEK_FP | AArch64::AEK_PROFILE,
757 EXPECT_TRUE(testAArch64CPU(
758 "thunderxt88", "armv8-a", "crypto-neon-fp-armv8",
759 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_SIMD |
760 AArch64::AEK_FP | AArch64::AEK_PROFILE,
764 static constexpr unsigned NumAArch64CPUArchs = 19;
766 TEST(TargetParserTest, testAArch64CPUArchList) {
767 SmallVector<StringRef, NumAArch64CPUArchs> List;
768 AArch64::fillValidCPUArchList(List);
770 // No list exists for these in this test suite, so ensure all are
771 // valid, and match the expected 'magic' count.
772 EXPECT_EQ(List.size(), NumAArch64CPUArchs);
773 for(StringRef CPU : List) {
774 EXPECT_NE(AArch64::parseCPUArch(CPU), AArch64::ArchKind::INVALID);
778 bool testAArch64Arch(StringRef Arch, StringRef DefaultCPU, StringRef SubArch,
780 AArch64::ArchKind AK = AArch64::parseArch(Arch);
781 return (AK != AArch64::ArchKind::INVALID) &
782 AArch64::getDefaultCPU(Arch).equals(DefaultCPU) &
783 AArch64::getSubArch(AK).equals(SubArch) &
784 (AArch64::getArchAttr(AK) == ArchAttr);
787 TEST(TargetParserTest, testAArch64Arch) {
788 EXPECT_TRUE(testAArch64Arch("armv8-a", "cortex-a53", "v8",
789 ARMBuildAttrs::CPUArch::v8_A));
790 EXPECT_TRUE(testAArch64Arch("armv8.1-a", "generic", "v8.1a",
791 ARMBuildAttrs::CPUArch::v8_A));
792 EXPECT_TRUE(testAArch64Arch("armv8.2-a", "generic", "v8.2a",
793 ARMBuildAttrs::CPUArch::v8_A));
794 EXPECT_TRUE(testAArch64Arch("armv8.3-a", "generic", "v8.3a",
795 ARMBuildAttrs::CPUArch::v8_A));
798 bool testAArch64Extension(StringRef CPUName, AArch64::ArchKind AK,
800 return AArch64::getDefaultExtensions(CPUName, AK) &
801 AArch64::parseArchExt(ArchExt);
804 TEST(TargetParserTest, testAArch64Extension) {
805 EXPECT_FALSE(testAArch64Extension("cortex-a35",
806 AArch64::ArchKind::INVALID, "ras"));
807 EXPECT_FALSE(testAArch64Extension("cortex-a53",
808 AArch64::ArchKind::INVALID, "ras"));
809 EXPECT_TRUE(testAArch64Extension("cortex-a55",
810 AArch64::ArchKind::INVALID, "ras"));
811 EXPECT_FALSE(testAArch64Extension("cortex-a57",
812 AArch64::ArchKind::INVALID, "ras"));
813 EXPECT_FALSE(testAArch64Extension("cortex-a72",
814 AArch64::ArchKind::INVALID, "ras"));
815 EXPECT_FALSE(testAArch64Extension("cortex-a73",
816 AArch64::ArchKind::INVALID, "ras"));
817 EXPECT_TRUE(testAArch64Extension("cortex-a75",
818 AArch64::ArchKind::INVALID, "ras"));
819 EXPECT_FALSE(testAArch64Extension("cyclone",
820 AArch64::ArchKind::INVALID, "ras"));
821 EXPECT_FALSE(testAArch64Extension("exynos-m1",
822 AArch64::ArchKind::INVALID, "ras"));
823 EXPECT_FALSE(testAArch64Extension("exynos-m2",
824 AArch64::ArchKind::INVALID, "ras"));
825 EXPECT_FALSE(testAArch64Extension("exynos-m3",
826 AArch64::ArchKind::INVALID, "ras"));
827 EXPECT_TRUE(testAArch64Extension("falkor",
828 AArch64::ArchKind::INVALID, "rdm"));
829 EXPECT_FALSE(testAArch64Extension("kryo",
830 AArch64::ArchKind::INVALID, "ras"));
831 EXPECT_TRUE(testAArch64Extension("saphira",
832 AArch64::ArchKind::INVALID, "crc"));
833 EXPECT_TRUE(testAArch64Extension("saphira",
834 AArch64::ArchKind::INVALID, "lse"));
835 EXPECT_TRUE(testAArch64Extension("saphira",
836 AArch64::ArchKind::INVALID, "rdm"));
837 EXPECT_TRUE(testAArch64Extension("saphira",
838 AArch64::ArchKind::INVALID, "ras"));
839 EXPECT_TRUE(testAArch64Extension("saphira",
840 AArch64::ArchKind::INVALID, "rcpc"));
841 EXPECT_TRUE(testAArch64Extension("saphira",
842 AArch64::ArchKind::INVALID, "profile"));
843 EXPECT_FALSE(testAArch64Extension("saphira",
844 AArch64::ArchKind::INVALID, "fullfp16"));
845 EXPECT_FALSE(testAArch64Extension("thunderx2t99",
846 AArch64::ArchKind::INVALID, "ras"));
847 EXPECT_FALSE(testAArch64Extension("thunderx",
848 AArch64::ArchKind::INVALID, "lse"));
849 EXPECT_FALSE(testAArch64Extension("thunderxt81",
850 AArch64::ArchKind::INVALID, "lse"));
851 EXPECT_FALSE(testAArch64Extension("thunderxt83",
852 AArch64::ArchKind::INVALID, "lse"));
853 EXPECT_FALSE(testAArch64Extension("thunderxt88",
854 AArch64::ArchKind::INVALID, "lse"));
856 EXPECT_FALSE(testAArch64Extension(
857 "generic", AArch64::ArchKind::ARMV8A, "ras"));
858 EXPECT_FALSE(testAArch64Extension(
859 "generic", AArch64::ArchKind::ARMV8_1A, "ras"));
860 EXPECT_FALSE(testAArch64Extension(
861 "generic", AArch64::ArchKind::ARMV8_2A, "spe"));
864 TEST(TargetParserTest, AArch64ExtensionFeatures) {
865 std::vector<StringRef> Features;
866 unsigned Extensions = AArch64::AEK_CRC | AArch64::AEK_CRYPTO |
867 AArch64::AEK_FP | AArch64::AEK_SIMD |
868 AArch64::AEK_FP16 | AArch64::AEK_PROFILE |
869 AArch64::AEK_RAS | AArch64::AEK_LSE |
870 AArch64::AEK_RDM | AArch64::AEK_SVE |
871 AArch64::AEK_DOTPROD | AArch64::AEK_RCPC;
873 for (unsigned i = 0; i <= Extensions; i++)
874 EXPECT_TRUE(i == 0 ? !AArch64::getExtensionFeatures(i, Features)
875 : AArch64::getExtensionFeatures(i, Features));
878 TEST(TargetParserTest, AArch64ArchFeatures) {
879 std::vector<StringRef> Features;
880 AArch64::ArchKind ArchKinds[] = {
881 #define AARCH64_ARCH(NAME, ID, CPU_ATTR, SUB_ARCH, ARCH_ATTR, ARCH_FPU, ARCH_BASE_EXT) \
882 AArch64::ArchKind::ID,
883 #include "llvm/Support/AArch64TargetParser.def"
886 for (auto AK : ArchKinds)
887 EXPECT_TRUE((AK == AArch64::ArchKind::INVALID)
888 ? !AArch64::getArchFeatures(AK, Features)
889 : AArch64::getArchFeatures(AK, Features));
892 TEST(TargetParserTest, AArch64ArchExtFeature) {
893 const char *ArchExt[][4] = {{"crc", "nocrc", "+crc", "-crc"},
894 {"crypto", "nocrypto", "+crypto", "-crypto"},
895 {"fp", "nofp", "+fp-armv8", "-fp-armv8"},
896 {"simd", "nosimd", "+neon", "-neon"},
897 {"fp16", "nofp16", "+fullfp16", "-fullfp16"},
898 {"profile", "noprofile", "+spe", "-spe"},
899 {"ras", "noras", "+ras", "-ras"},
900 {"lse", "nolse", "+lse", "-lse"},
901 {"rdm", "nordm", "+rdm", "-rdm"},
902 {"sve", "nosve", "+sve", "-sve"},
903 {"dotprod", "nodotprod", "+dotprod", "-dotprod"},
904 {"rcpc", "norcpc", "+rcpc", "-rcpc" }};
906 for (unsigned i = 0; i < array_lengthof(ArchExt); i++) {
907 EXPECT_EQ(StringRef(ArchExt[i][2]),
908 AArch64::getArchExtFeature(ArchExt[i][0]));
909 EXPECT_EQ(StringRef(ArchExt[i][3]),
910 AArch64::getArchExtFeature(ArchExt[i][1]));