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 "armv8.1-a", "armv8.1a", "armv8.2-a", "armv8.2a", "armv8.3-a",
29 "armv8.3a", "armv8-r", "armv8r", "armv8-m.base", "armv8m.base",
30 "armv8-m.main", "armv8m.main", "iwmmxt", "iwmmxt2", "xscale"};
32 bool testARMCPU(StringRef CPUName, StringRef ExpectedArch,
33 StringRef ExpectedFPU, unsigned ExpectedFlags,
35 ARM::ArchKind AK = ARM::parseCPUArch(CPUName);
36 bool pass = ARM::getArchName(AK).equals(ExpectedArch);
37 unsigned FPUKind = ARM::getDefaultFPU(CPUName, AK);
38 pass &= ARM::getFPUName(FPUKind).equals(ExpectedFPU);
40 unsigned ExtKind = ARM::getDefaultExtensions(CPUName, AK);
41 if (ExtKind > 1 && (ExtKind & ARM::AEK_NONE))
42 pass &= ((ExtKind ^ ARM::AEK_NONE) == ExpectedFlags);
44 pass &= (ExtKind == ExpectedFlags);
46 pass &= ARM::getCPUAttr(AK).equals(CPUAttr);
51 TEST(TargetParserTest, testARMCPU) {
52 EXPECT_TRUE(testARMCPU("invalid", "invalid", "invalid",
54 EXPECT_TRUE(testARMCPU("generic", "invalid", "none",
57 EXPECT_TRUE(testARMCPU("arm2", "armv2", "none",
59 EXPECT_TRUE(testARMCPU("arm3", "armv2a", "none",
60 ARM::AEK_NONE, "2A"));
61 EXPECT_TRUE(testARMCPU("arm6", "armv3", "none",
63 EXPECT_TRUE(testARMCPU("arm7m", "armv3m", "none",
64 ARM::AEK_NONE, "3M"));
65 EXPECT_TRUE(testARMCPU("arm8", "armv4", "none",
67 EXPECT_TRUE(testARMCPU("arm810", "armv4", "none",
69 EXPECT_TRUE(testARMCPU("strongarm", "armv4", "none",
71 EXPECT_TRUE(testARMCPU("strongarm110", "armv4", "none",
73 EXPECT_TRUE(testARMCPU("strongarm1100", "armv4", "none",
75 EXPECT_TRUE(testARMCPU("strongarm1110", "armv4", "none",
77 EXPECT_TRUE(testARMCPU("arm7tdmi", "armv4t", "none",
78 ARM::AEK_NONE, "4T"));
79 EXPECT_TRUE(testARMCPU("arm7tdmi-s", "armv4t", "none",
80 ARM::AEK_NONE, "4T"));
81 EXPECT_TRUE(testARMCPU("arm710t", "armv4t", "none",
82 ARM::AEK_NONE, "4T"));
83 EXPECT_TRUE(testARMCPU("arm720t", "armv4t", "none",
84 ARM::AEK_NONE, "4T"));
85 EXPECT_TRUE(testARMCPU("arm9", "armv4t", "none",
86 ARM::AEK_NONE, "4T"));
87 EXPECT_TRUE(testARMCPU("arm9tdmi", "armv4t", "none",
88 ARM::AEK_NONE, "4T"));
89 EXPECT_TRUE(testARMCPU("arm920", "armv4t", "none",
90 ARM::AEK_NONE, "4T"));
91 EXPECT_TRUE(testARMCPU("arm920t", "armv4t", "none",
92 ARM::AEK_NONE, "4T"));
93 EXPECT_TRUE(testARMCPU("arm922t", "armv4t", "none",
94 ARM::AEK_NONE, "4T"));
95 EXPECT_TRUE(testARMCPU("arm9312", "armv4t", "none",
96 ARM::AEK_NONE, "4T"));
97 EXPECT_TRUE(testARMCPU("arm940t", "armv4t", "none",
98 ARM::AEK_NONE, "4T"));
99 EXPECT_TRUE(testARMCPU("ep9312", "armv4t", "none",
100 ARM::AEK_NONE, "4T"));
101 EXPECT_TRUE(testARMCPU("arm10tdmi", "armv5t", "none",
102 ARM::AEK_NONE, "5T"));
103 EXPECT_TRUE(testARMCPU("arm1020t", "armv5t", "none",
104 ARM::AEK_NONE, "5T"));
105 EXPECT_TRUE(testARMCPU("arm9e", "armv5te", "none",
106 ARM::AEK_DSP, "5TE"));
107 EXPECT_TRUE(testARMCPU("arm946e-s", "armv5te", "none",
108 ARM::AEK_DSP, "5TE"));
109 EXPECT_TRUE(testARMCPU("arm966e-s", "armv5te", "none",
110 ARM::AEK_DSP, "5TE"));
111 EXPECT_TRUE(testARMCPU("arm968e-s", "armv5te", "none",
112 ARM::AEK_DSP, "5TE"));
113 EXPECT_TRUE(testARMCPU("arm10e", "armv5te", "none",
114 ARM::AEK_DSP, "5TE"));
115 EXPECT_TRUE(testARMCPU("arm1020e", "armv5te", "none",
116 ARM::AEK_DSP, "5TE"));
117 EXPECT_TRUE(testARMCPU("arm1022e", "armv5te", "none",
118 ARM::AEK_DSP, "5TE"));
119 EXPECT_TRUE(testARMCPU("arm926ej-s", "armv5tej", "none",
120 ARM::AEK_DSP, "5TEJ"));
121 EXPECT_TRUE(testARMCPU("arm1136j-s", "armv6", "none",
123 EXPECT_TRUE(testARMCPU("arm1136jf-s", "armv6", "vfpv2",
125 EXPECT_TRUE(testARMCPU("arm1136jz-s", "armv6", "none",
127 EXPECT_TRUE(testARMCPU("arm1176j-s", "armv6k", "none",
128 ARM::AEK_DSP, "6K"));
129 EXPECT_TRUE(testARMCPU("arm1176jz-s", "armv6kz", "none",
130 ARM::AEK_SEC | ARM::AEK_DSP, "6KZ"));
131 EXPECT_TRUE(testARMCPU("mpcore", "armv6k", "vfpv2",
132 ARM::AEK_DSP, "6K"));
133 EXPECT_TRUE(testARMCPU("mpcorenovfp", "armv6k", "none",
134 ARM::AEK_DSP, "6K"));
135 EXPECT_TRUE(testARMCPU("arm1176jzf-s", "armv6kz", "vfpv2",
136 ARM::AEK_SEC | ARM::AEK_DSP, "6KZ"));
137 EXPECT_TRUE(testARMCPU("arm1156t2-s", "armv6t2", "none",
138 ARM::AEK_DSP, "6T2"));
139 EXPECT_TRUE(testARMCPU("arm1156t2f-s", "armv6t2", "vfpv2",
140 ARM::AEK_DSP, "6T2"));
141 EXPECT_TRUE(testARMCPU("cortex-m0", "armv6-m", "none",
142 ARM::AEK_NONE, "6-M"));
143 EXPECT_TRUE(testARMCPU("cortex-m0plus", "armv6-m", "none",
144 ARM::AEK_NONE, "6-M"));
145 EXPECT_TRUE(testARMCPU("cortex-m1", "armv6-m", "none",
146 ARM::AEK_NONE, "6-M"));
147 EXPECT_TRUE(testARMCPU("sc000", "armv6-m", "none",
148 ARM::AEK_NONE, "6-M"));
149 EXPECT_TRUE(testARMCPU("cortex-a5", "armv7-a", "neon-vfpv4",
150 ARM::AEK_MP | ARM::AEK_SEC | ARM::AEK_DSP, "7-A"));
151 EXPECT_TRUE(testARMCPU("cortex-a7", "armv7-a", "neon-vfpv4",
152 ARM::AEK_HWDIVTHUMB | ARM::AEK_HWDIVARM | ARM::AEK_MP |
153 ARM::AEK_SEC | ARM::AEK_VIRT | ARM::AEK_DSP,
155 EXPECT_TRUE(testARMCPU("cortex-a8", "armv7-a", "neon",
156 ARM::AEK_SEC | ARM::AEK_DSP, "7-A"));
157 EXPECT_TRUE(testARMCPU("cortex-a9", "armv7-a", "neon-fp16",
158 ARM::AEK_MP | ARM::AEK_SEC | ARM::AEK_DSP, "7-A"));
159 EXPECT_TRUE(testARMCPU("cortex-a12", "armv7-a", "neon-vfpv4",
160 ARM::AEK_SEC | ARM::AEK_MP | ARM::AEK_VIRT |
161 ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
164 EXPECT_TRUE(testARMCPU("cortex-a15", "armv7-a", "neon-vfpv4",
165 ARM::AEK_SEC | ARM::AEK_MP | ARM::AEK_VIRT |
166 ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
169 EXPECT_TRUE(testARMCPU("cortex-a17", "armv7-a", "neon-vfpv4",
170 ARM::AEK_SEC | ARM::AEK_MP | ARM::AEK_VIRT |
171 ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
174 EXPECT_TRUE(testARMCPU("krait", "armv7-a", "neon-vfpv4",
175 ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
177 EXPECT_TRUE(testARMCPU("cortex-r4", "armv7-r", "none",
178 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP, "7-R"));
179 EXPECT_TRUE(testARMCPU("cortex-r4f", "armv7-r", "vfpv3-d16",
180 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP, "7-R"));
181 EXPECT_TRUE(testARMCPU("cortex-r5", "armv7-r", "vfpv3-d16",
182 ARM::AEK_MP | ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
185 EXPECT_TRUE(testARMCPU("cortex-r7", "armv7-r", "vfpv3-d16-fp16",
186 ARM::AEK_MP | ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
189 EXPECT_TRUE(testARMCPU("cortex-r8", "armv7-r", "vfpv3-d16-fp16",
190 ARM::AEK_MP | ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
193 EXPECT_TRUE(testARMCPU("cortex-r52", "armv8-r", "neon-fp-armv8",
194 ARM::AEK_CRC | ARM::AEK_MP | ARM::AEK_VIRT |
195 ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
199 testARMCPU("sc300", "armv7-m", "none", ARM::AEK_HWDIVTHUMB, "7-M"));
201 testARMCPU("cortex-m3", "armv7-m", "none", ARM::AEK_HWDIVTHUMB, "7-M"));
202 EXPECT_TRUE(testARMCPU("cortex-m4", "armv7e-m", "fpv4-sp-d16",
203 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP, "7E-M"));
204 EXPECT_TRUE(testARMCPU("cortex-m7", "armv7e-m", "fpv5-d16",
205 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP, "7E-M"));
206 EXPECT_TRUE(testARMCPU("cortex-a32", "armv8-a", "crypto-neon-fp-armv8",
207 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
208 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
209 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
211 EXPECT_TRUE(testARMCPU("cortex-a35", "armv8-a", "crypto-neon-fp-armv8",
212 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
213 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
214 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
216 EXPECT_TRUE(testARMCPU("cortex-a53", "armv8-a", "crypto-neon-fp-armv8",
217 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
218 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
219 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
221 EXPECT_TRUE(testARMCPU("cortex-a55", "armv8.2-a", "crypto-neon-fp-armv8",
222 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
223 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
224 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP | ARM::AEK_FP16 |
225 ARM::AEK_RAS | ARM::AEK_DOTPROD,
227 EXPECT_TRUE(testARMCPU("cortex-a57", "armv8-a", "crypto-neon-fp-armv8",
228 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
229 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
230 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
232 EXPECT_TRUE(testARMCPU("cortex-a72", "armv8-a", "crypto-neon-fp-armv8",
233 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
234 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
235 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
237 EXPECT_TRUE(testARMCPU("cortex-a73", "armv8-a", "crypto-neon-fp-armv8",
238 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
239 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
240 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
242 EXPECT_TRUE(testARMCPU("cortex-a75", "armv8.2-a", "crypto-neon-fp-armv8",
243 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
244 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
245 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP | ARM::AEK_FP16 |
246 ARM::AEK_RAS | ARM::AEK_DOTPROD,
248 EXPECT_TRUE(testARMCPU("cyclone", "armv8-a", "crypto-neon-fp-armv8",
249 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
250 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
251 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
253 EXPECT_TRUE(testARMCPU("exynos-m1", "armv8-a", "crypto-neon-fp-armv8",
254 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
255 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
256 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
258 EXPECT_TRUE(testARMCPU("exynos-m2", "armv8-a", "crypto-neon-fp-armv8",
259 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
260 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
261 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
263 EXPECT_TRUE(testARMCPU("exynos-m3", "armv8-a", "crypto-neon-fp-armv8",
264 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
265 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
266 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
268 EXPECT_TRUE(testARMCPU("cortex-m23", "armv8-m.base", "none",
269 ARM::AEK_HWDIVTHUMB, "8-M.Baseline"));
270 EXPECT_TRUE(testARMCPU("cortex-m33", "armv8-m.main", "fpv5-sp-d16",
271 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP, "8-M.Mainline"));
272 EXPECT_TRUE(testARMCPU("iwmmxt", "iwmmxt", "none",
273 ARM::AEK_NONE, "iwmmxt"));
274 EXPECT_TRUE(testARMCPU("xscale", "xscale", "none",
275 ARM::AEK_NONE, "xscale"));
276 EXPECT_TRUE(testARMCPU("swift", "armv7s", "neon-vfpv4",
277 ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
281 TEST(TargetParserTest, testInvalidARMArch) {
282 auto InvalidArchStrings = {"armv", "armv99", "noarm"};
283 for (const char* InvalidArch : InvalidArchStrings)
284 EXPECT_EQ(ARM::parseArch(InvalidArch), ARM::ArchKind::INVALID);
287 bool testARMArch(StringRef Arch, StringRef DefaultCPU, StringRef SubArch,
289 ARM::ArchKind AK = ARM::parseArch(Arch);
290 return (AK!= ARM::ArchKind::INVALID) &
291 ARM::getDefaultCPU(Arch).equals(DefaultCPU) &
292 ARM::getSubArch(AK).equals(SubArch) &
293 (ARM::getArchAttr(AK) == ArchAttr);
296 TEST(TargetParserTest, testARMArch) {
298 testARMArch("armv2", "arm2", "v2",
299 ARMBuildAttrs::CPUArch::Pre_v4));
301 testARMArch("armv2a", "arm3", "v2a",
302 ARMBuildAttrs::CPUArch::Pre_v4));
304 testARMArch("armv3", "arm6", "v3",
305 ARMBuildAttrs::CPUArch::Pre_v4));
307 testARMArch("armv3m", "arm7m", "v3m",
308 ARMBuildAttrs::CPUArch::Pre_v4));
310 testARMArch("armv4", "strongarm", "v4",
311 ARMBuildAttrs::CPUArch::v4));
313 testARMArch("armv4t", "arm7tdmi", "v4t",
314 ARMBuildAttrs::CPUArch::v4T));
316 testARMArch("armv5t", "arm10tdmi", "v5",
317 ARMBuildAttrs::CPUArch::v5T));
319 testARMArch("armv5te", "arm1022e", "v5e",
320 ARMBuildAttrs::CPUArch::v5TE));
322 testARMArch("armv5tej", "arm926ej-s", "v5e",
323 ARMBuildAttrs::CPUArch::v5TEJ));
325 testARMArch("armv6", "arm1136jf-s", "v6",
326 ARMBuildAttrs::CPUArch::v6));
328 testARMArch("armv6k", "arm1176j-s", "v6k",
329 ARMBuildAttrs::CPUArch::v6K));
331 testARMArch("armv6t2", "arm1156t2-s", "v6t2",
332 ARMBuildAttrs::CPUArch::v6T2));
334 testARMArch("armv6kz", "arm1176jzf-s", "v6kz",
335 ARMBuildAttrs::CPUArch::v6KZ));
337 testARMArch("armv6-m", "cortex-m0", "v6m",
338 ARMBuildAttrs::CPUArch::v6_M));
340 testARMArch("armv7-a", "generic", "v7",
341 ARMBuildAttrs::CPUArch::v7));
343 testARMArch("armv7ve", "generic", "v7ve",
344 ARMBuildAttrs::CPUArch::v7));
346 testARMArch("armv7-r", "cortex-r4", "v7r",
347 ARMBuildAttrs::CPUArch::v7));
349 testARMArch("armv7-m", "cortex-m3", "v7m",
350 ARMBuildAttrs::CPUArch::v7));
352 testARMArch("armv7e-m", "cortex-m4", "v7em",
353 ARMBuildAttrs::CPUArch::v7E_M));
355 testARMArch("armv8-a", "generic", "v8",
356 ARMBuildAttrs::CPUArch::v8_A));
358 testARMArch("armv8.1-a", "generic", "v8.1a",
359 ARMBuildAttrs::CPUArch::v8_A));
361 testARMArch("armv8.2-a", "generic", "v8.2a",
362 ARMBuildAttrs::CPUArch::v8_A));
364 testARMArch("armv8.3-a", "generic", "v8.3a",
365 ARMBuildAttrs::CPUArch::v8_A));
367 testARMArch("armv8-r", "cortex-r52", "v8r",
368 ARMBuildAttrs::CPUArch::v8_R));
370 testARMArch("armv8-m.base", "generic", "v8m.base",
371 ARMBuildAttrs::CPUArch::v8_M_Base));
373 testARMArch("armv8-m.main", "generic", "v8m.main",
374 ARMBuildAttrs::CPUArch::v8_M_Main));
376 testARMArch("iwmmxt", "iwmmxt", "",
377 ARMBuildAttrs::CPUArch::v5TE));
379 testARMArch("iwmmxt2", "generic", "",
380 ARMBuildAttrs::CPUArch::v5TE));
382 testARMArch("xscale", "xscale", "v5e",
383 ARMBuildAttrs::CPUArch::v5TE));
385 testARMArch("armv7s", "swift", "v7s",
386 ARMBuildAttrs::CPUArch::v7));
388 testARMArch("armv7k", "generic", "v7k",
389 ARMBuildAttrs::CPUArch::v7));
392 bool testARMExtension(StringRef CPUName,ARM::ArchKind ArchKind, StringRef ArchExt) {
393 return ARM::getDefaultExtensions(CPUName, ArchKind) &
394 ARM::parseArchExt(ArchExt);
397 TEST(TargetParserTest, testARMExtension) {
398 EXPECT_FALSE(testARMExtension("arm2", ARM::ArchKind::INVALID, "thumb"));
399 EXPECT_FALSE(testARMExtension("arm3", ARM::ArchKind::INVALID, "thumb"));
400 EXPECT_FALSE(testARMExtension("arm6", ARM::ArchKind::INVALID, "thumb"));
401 EXPECT_FALSE(testARMExtension("arm7m", ARM::ArchKind::INVALID, "thumb"));
402 EXPECT_FALSE(testARMExtension("strongarm", ARM::ArchKind::INVALID, "dsp"));
403 EXPECT_FALSE(testARMExtension("arm7tdmi", ARM::ArchKind::INVALID, "dsp"));
404 EXPECT_FALSE(testARMExtension("arm10tdmi",
405 ARM::ArchKind::INVALID, "simd"));
406 EXPECT_FALSE(testARMExtension("arm1022e", ARM::ArchKind::INVALID, "simd"));
407 EXPECT_FALSE(testARMExtension("arm926ej-s",
408 ARM::ArchKind::INVALID, "simd"));
409 EXPECT_FALSE(testARMExtension("arm1136jf-s",
410 ARM::ArchKind::INVALID, "crypto"));
411 EXPECT_FALSE(testARMExtension("arm1176j-s",
412 ARM::ArchKind::INVALID, "crypto"));
413 EXPECT_FALSE(testARMExtension("arm1156t2-s",
414 ARM::ArchKind::INVALID, "crypto"));
415 EXPECT_FALSE(testARMExtension("arm1176jzf-s",
416 ARM::ArchKind::INVALID, "crypto"));
417 EXPECT_FALSE(testARMExtension("cortex-m0",
418 ARM::ArchKind::INVALID, "crypto"));
419 EXPECT_FALSE(testARMExtension("cortex-a8",
420 ARM::ArchKind::INVALID, "crypto"));
421 EXPECT_FALSE(testARMExtension("cortex-r4",
422 ARM::ArchKind::INVALID, "crypto"));
423 EXPECT_FALSE(testARMExtension("cortex-m3",
424 ARM::ArchKind::INVALID, "crypto"));
425 EXPECT_FALSE(testARMExtension("cortex-a53",
426 ARM::ArchKind::INVALID, "ras"));
427 EXPECT_FALSE(testARMExtension("cortex-r52",
428 ARM::ArchKind::INVALID, "ras"));
429 EXPECT_FALSE(testARMExtension("iwmmxt", ARM::ArchKind::INVALID, "crc"));
430 EXPECT_FALSE(testARMExtension("xscale", ARM::ArchKind::INVALID, "crc"));
431 EXPECT_FALSE(testARMExtension("swift", ARM::ArchKind::INVALID, "crc"));
433 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV2, "thumb"));
434 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV2A, "thumb"));
435 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV3, "thumb"));
436 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV3M, "thumb"));
437 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV4, "dsp"));
438 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV4T, "dsp"));
439 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV5T, "simd"));
440 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV5TE, "simd"));
441 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV5TEJ, "simd"));
442 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV6, "crypto"));
443 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV6K, "crypto"));
444 EXPECT_FALSE(testARMExtension("generic",
445 ARM::ArchKind::ARMV6T2, "crypto"));
446 EXPECT_FALSE(testARMExtension("generic",
447 ARM::ArchKind::ARMV6KZ, "crypto"));
448 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV6M, "crypto"));
449 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV7A, "crypto"));
450 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV7R, "crypto"));
451 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV7M, "crypto"));
452 EXPECT_FALSE(testARMExtension("generic",
453 ARM::ArchKind::ARMV7EM, "crypto"));
454 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8A, "ras"));
455 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8_1A, "ras"));
456 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8_2A, "spe"));
457 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8R, "ras"));
458 EXPECT_FALSE(testARMExtension("generic",
459 ARM::ArchKind::ARMV8MBaseline, "crc"));
460 EXPECT_FALSE(testARMExtension("generic",
461 ARM::ArchKind::ARMV8MMainline, "crc"));
462 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::IWMMXT, "crc"));
463 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::IWMMXT2, "crc"));
464 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::XSCALE, "crc"));
465 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV7S, "crypto"));
466 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV7K, "crypto"));
469 TEST(TargetParserTest, ARMFPUVersion) {
470 for (ARM::FPUKind FK = static_cast<ARM::FPUKind>(0);
471 FK <= ARM::FPUKind::FK_LAST;
472 FK = static_cast<ARM::FPUKind>(static_cast<unsigned>(FK) + 1))
473 if (FK == ARM::FK_LAST || ARM::getFPUName(FK) == "invalid" ||
474 ARM::getFPUName(FK) == "none" || ARM::getFPUName(FK) == "softvfp")
475 EXPECT_EQ(ARM::FPUVersion::NONE, ARM::getFPUVersion(FK));
477 EXPECT_NE(ARM::FPUVersion::NONE, ARM::getFPUVersion(FK));
480 TEST(TargetParserTest, ARMFPUNeonSupportLevel) {
481 for (ARM::FPUKind FK = static_cast<ARM::FPUKind>(0);
482 FK <= ARM::FPUKind::FK_LAST;
483 FK = static_cast<ARM::FPUKind>(static_cast<unsigned>(FK) + 1))
484 if (FK == ARM::FK_LAST ||
485 ARM::getFPUName(FK).find("neon") == std::string::npos)
486 EXPECT_EQ(ARM::NeonSupportLevel::None,
487 ARM::getFPUNeonSupportLevel(FK));
489 EXPECT_NE(ARM::NeonSupportLevel::None,
490 ARM::getFPUNeonSupportLevel(FK));
493 TEST(TargetParserTest, ARMFPURestriction) {
494 for (ARM::FPUKind FK = static_cast<ARM::FPUKind>(0);
495 FK <= ARM::FPUKind::FK_LAST;
496 FK = static_cast<ARM::FPUKind>(static_cast<unsigned>(FK) + 1)) {
497 if (FK == ARM::FK_LAST ||
498 (ARM::getFPUName(FK).find("d16") == std::string::npos &&
499 ARM::getFPUName(FK).find("vfpv3xd") == std::string::npos))
500 EXPECT_EQ(ARM::FPURestriction::None, ARM::getFPURestriction(FK));
502 EXPECT_NE(ARM::FPURestriction::None, ARM::getFPURestriction(FK));
506 TEST(TargetParserTest, ARMExtensionFeatures) {
507 std::vector<StringRef> Features;
508 unsigned Extensions = ARM::AEK_CRC | ARM::AEK_CRYPTO | ARM::AEK_DSP |
509 ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB | ARM::AEK_MP |
510 ARM::AEK_SEC | ARM::AEK_VIRT | ARM::AEK_RAS;
512 for (unsigned i = 0; i <= Extensions; i++)
513 EXPECT_TRUE(i == 0 ? !ARM::getExtensionFeatures(i, Features)
514 : ARM::getExtensionFeatures(i, Features));
517 TEST(TargetParserTest, ARMFPUFeatures) {
518 std::vector<StringRef> Features;
519 for (ARM::FPUKind FK = static_cast<ARM::FPUKind>(0);
520 FK <= ARM::FPUKind::FK_LAST;
521 FK = static_cast<ARM::FPUKind>(static_cast<unsigned>(FK) + 1))
522 EXPECT_TRUE((FK == ARM::FK_INVALID || FK >= ARM::FK_LAST)
523 ? !ARM::getFPUFeatures(FK, Features)
524 : ARM::getFPUFeatures(FK, Features));
527 TEST(TargetParserTest, ARMArchExtFeature) {
528 const char *ArchExt[][4] = {{"crc", "nocrc", "+crc", "-crc"},
529 {"crypto", "nocrypto", "+crypto", "-crypto"},
530 {"dsp", "nodsp", "+dsp", "-dsp"},
531 {"fp", "nofp", nullptr, nullptr},
532 {"idiv", "noidiv", nullptr, nullptr},
533 {"mp", "nomp", nullptr, nullptr},
534 {"simd", "nosimd", nullptr, nullptr},
535 {"sec", "nosec", nullptr, nullptr},
536 {"virt", "novirt", nullptr, nullptr},
537 {"fp16", "nofp16", "+fullfp16", "-fullfp16"},
538 {"ras", "noras", "+ras", "-ras"},
539 {"dotprod", "nodotprod", "+dotprod", "-dotprod"},
540 {"os", "noos", nullptr, nullptr},
541 {"iwmmxt", "noiwmmxt", nullptr, nullptr},
542 {"iwmmxt2", "noiwmmxt2", nullptr, nullptr},
543 {"maverick", "maverick", nullptr, nullptr},
544 {"xscale", "noxscale", nullptr, nullptr}};
546 for (unsigned i = 0; i < array_lengthof(ArchExt); i++) {
547 EXPECT_EQ(StringRef(ArchExt[i][2]), ARM::getArchExtFeature(ArchExt[i][0]));
548 EXPECT_EQ(StringRef(ArchExt[i][3]), ARM::getArchExtFeature(ArchExt[i][1]));
552 TEST(TargetParserTest, ARMparseHWDiv) {
553 const char *hwdiv[] = {"thumb", "arm", "arm,thumb", "thumb,arm"};
555 for (unsigned i = 0; i < array_lengthof(hwdiv); i++)
556 EXPECT_NE(ARM::AEK_INVALID, ARM::parseHWDiv((StringRef)hwdiv[i]));
559 TEST(TargetParserTest, ARMparseArchEndianAndISA) {
560 const char *Arch[] = {
561 "v2", "v2a", "v3", "v3m", "v4", "v4t", "v5", "v5t",
562 "v5e", "v5te", "v5tej", "v6", "v6j", "v6k", "v6hl", "v6t2",
563 "v6kz", "v6z", "v6zk", "v6-m", "v6m", "v6sm", "v6s-m", "v7-a",
564 "v7", "v7a", "v7ve", "v7hl", "v7l", "v7-r", "v7r", "v7-m",
565 "v7m", "v7k", "v7s", "v7e-m", "v7em", "v8-a", "v8", "v8a",
566 "v8.1-a", "v8.1a", "v8.2-a", "v8.2a", "v8.3-a", "v8.3a", "v8-r"};
568 for (unsigned i = 0; i < array_lengthof(Arch); i++) {
569 std::string arm_1 = "armeb" + (std::string)(Arch[i]);
570 std::string arm_2 = "arm" + (std::string)(Arch[i]) + "eb";
571 std::string arm_3 = "arm" + (std::string)(Arch[i]);
572 std::string thumb_1 = "thumbeb" + (std::string)(Arch[i]);
573 std::string thumb_2 = "thumb" + (std::string)(Arch[i]) + "eb";
574 std::string thumb_3 = "thumb" + (std::string)(Arch[i]);
576 EXPECT_EQ(ARM::EndianKind::BIG, ARM::parseArchEndian(arm_1));
577 EXPECT_EQ(ARM::EndianKind::BIG, ARM::parseArchEndian(arm_2));
578 EXPECT_EQ(ARM::EndianKind::LITTLE, ARM::parseArchEndian(arm_3));
580 EXPECT_EQ(ARM::ISAKind::ARM, ARM::parseArchISA(arm_1));
581 EXPECT_EQ(ARM::ISAKind::ARM, ARM::parseArchISA(arm_2));
582 EXPECT_EQ(ARM::ISAKind::ARM, ARM::parseArchISA(arm_3));
584 EXPECT_EQ(ARM::EndianKind::BIG, ARM::parseArchEndian(thumb_1));
585 EXPECT_EQ(ARM::EndianKind::BIG, ARM::parseArchEndian(thumb_2));
586 EXPECT_EQ(ARM::EndianKind::LITTLE, ARM::parseArchEndian(thumb_3));
588 EXPECT_EQ(ARM::ISAKind::THUMB, ARM::parseArchISA(thumb_1));
589 EXPECT_EQ(ARM::ISAKind::THUMB, ARM::parseArchISA(thumb_2));
590 EXPECT_EQ(ARM::ISAKind::THUMB, ARM::parseArchISA(thumb_3));
594 EXPECT_EQ(ARM::EndianKind::LITTLE, ARM::parseArchEndian("aarch64"));
595 EXPECT_EQ(ARM::EndianKind::BIG, ARM::parseArchEndian("aarch64_be"));
597 EXPECT_EQ(ARM::ISAKind::AARCH64, ARM::parseArchISA("aarch64"));
598 EXPECT_EQ(ARM::ISAKind::AARCH64, ARM::parseArchISA("aarch64_be"));
599 EXPECT_EQ(ARM::ISAKind::AARCH64, ARM::parseArchISA("arm64"));
600 EXPECT_EQ(ARM::ISAKind::AARCH64, ARM::parseArchISA("arm64_be"));
603 TEST(TargetParserTest, ARMparseArchProfile) {
604 for (unsigned i = 0; i < array_lengthof(ARMArch); i++) {
605 switch (ARM::parseArch(ARMArch[i])) {
606 case ARM::ArchKind::ARMV6M:
607 case ARM::ArchKind::ARMV7M:
608 case ARM::ArchKind::ARMV7EM:
609 case ARM::ArchKind::ARMV8MMainline:
610 case ARM::ArchKind::ARMV8MBaseline:
611 EXPECT_EQ(ARM::ProfileKind::M, ARM::parseArchProfile(ARMArch[i]));
613 case ARM::ArchKind::ARMV7R:
614 case ARM::ArchKind::ARMV8R:
615 EXPECT_EQ(ARM::ProfileKind::R, ARM::parseArchProfile(ARMArch[i]));
617 case ARM::ArchKind::ARMV7A:
618 case ARM::ArchKind::ARMV7VE:
619 case ARM::ArchKind::ARMV7K:
620 case ARM::ArchKind::ARMV8A:
621 case ARM::ArchKind::ARMV8_1A:
622 case ARM::ArchKind::ARMV8_2A:
623 case ARM::ArchKind::ARMV8_3A:
624 EXPECT_EQ(ARM::ProfileKind::A, ARM::parseArchProfile(ARMArch[i]));
627 EXPECT_EQ(ARM::ProfileKind::INVALID, ARM::parseArchProfile(ARMArch[i]));
633 TEST(TargetParserTest, ARMparseArchVersion) {
634 for (unsigned i = 0; i < array_lengthof(ARMArch); i++)
635 if (((std::string)ARMArch[i]).substr(0, 4) == "armv")
636 EXPECT_EQ((ARMArch[i][4] - 48u), ARM::parseArchVersion(ARMArch[i]));
638 EXPECT_EQ(5u, ARM::parseArchVersion(ARMArch[i]));
641 bool testAArch64CPU(StringRef CPUName, StringRef ExpectedArch,
642 StringRef ExpectedFPU, unsigned ExpectedFlags,
644 AArch64::ArchKind AK = AArch64::parseCPUArch(CPUName);
645 bool pass = AArch64::getArchName(AK).equals(ExpectedArch);
646 unsigned FPUKind = AArch64::getDefaultFPU(CPUName, AK);
647 pass &= AArch64::getFPUName(FPUKind).equals(ExpectedFPU);
649 unsigned ExtKind = AArch64::getDefaultExtensions(CPUName, AK);
650 if (ExtKind > 1 && (ExtKind & AArch64::AEK_NONE))
651 pass &= ((ExtKind ^ AArch64::AEK_NONE) == ExpectedFlags);
653 pass &= (ExtKind == ExpectedFlags);
655 pass &= AArch64::getCPUAttr(AK).equals(CPUAttr);
660 TEST(TargetParserTest, testAArch64CPU) {
661 EXPECT_TRUE(testAArch64CPU(
662 "invalid", "invalid", "invalid",
663 AArch64::AEK_NONE, ""));
664 EXPECT_TRUE(testAArch64CPU(
665 "generic", "invalid", "none",
666 AArch64::AEK_NONE, ""));
668 EXPECT_TRUE(testAArch64CPU(
669 "cortex-a35", "armv8-a", "crypto-neon-fp-armv8",
670 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
671 AArch64::AEK_SIMD, "8-A"));
672 EXPECT_TRUE(testAArch64CPU(
673 "cortex-a53", "armv8-a", "crypto-neon-fp-armv8",
674 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
675 AArch64::AEK_SIMD, "8-A"));
676 EXPECT_TRUE(testAArch64CPU(
677 "cortex-a55", "armv8.2-a", "crypto-neon-fp-armv8",
678 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
679 AArch64::AEK_SIMD | AArch64::AEK_RAS | AArch64::AEK_LSE |
680 AArch64::AEK_RDM | AArch64::AEK_FP16 | AArch64::AEK_DOTPROD |
681 AArch64::AEK_RCPC, "8.2-A"));
682 EXPECT_TRUE(testAArch64CPU(
683 "cortex-a57", "armv8-a", "crypto-neon-fp-armv8",
684 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
685 AArch64::AEK_SIMD, "8-A"));
686 EXPECT_TRUE(testAArch64CPU(
687 "cortex-a72", "armv8-a", "crypto-neon-fp-armv8",
688 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
689 AArch64::AEK_SIMD, "8-A"));
690 EXPECT_TRUE(testAArch64CPU(
691 "cortex-a73", "armv8-a", "crypto-neon-fp-armv8",
692 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
693 AArch64::AEK_SIMD, "8-A"));
694 EXPECT_TRUE(testAArch64CPU(
695 "cortex-a75", "armv8.2-a", "crypto-neon-fp-armv8",
696 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
697 AArch64::AEK_SIMD | AArch64::AEK_RAS | AArch64::AEK_LSE |
698 AArch64::AEK_RDM | AArch64::AEK_FP16 | AArch64::AEK_DOTPROD |
699 AArch64::AEK_RCPC, "8.2-A"));
700 EXPECT_TRUE(testAArch64CPU(
701 "cyclone", "armv8-a", "crypto-neon-fp-armv8",
702 AArch64::AEK_CRYPTO | AArch64::AEK_FP | AArch64::AEK_SIMD, "8-A"));
703 EXPECT_TRUE(testAArch64CPU(
704 "exynos-m1", "armv8-a", "crypto-neon-fp-armv8",
705 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
706 AArch64::AEK_SIMD, "8-A"));
707 EXPECT_TRUE(testAArch64CPU(
708 "exynos-m2", "armv8-a", "crypto-neon-fp-armv8",
709 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
710 AArch64::AEK_SIMD, "8-A"));
711 EXPECT_TRUE(testAArch64CPU(
712 "exynos-m3", "armv8-a", "crypto-neon-fp-armv8",
713 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
714 AArch64::AEK_SIMD, "8-A"));
715 EXPECT_TRUE(testAArch64CPU(
716 "falkor", "armv8-a", "crypto-neon-fp-armv8",
717 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
718 AArch64::AEK_SIMD | AArch64::AEK_RDM, "8-A"));
719 EXPECT_TRUE(testAArch64CPU(
720 "kryo", "armv8-a", "crypto-neon-fp-armv8",
721 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
722 AArch64::AEK_SIMD, "8-A"));
723 EXPECT_TRUE(testAArch64CPU(
724 "thunderx2t99", "armv8.1-a", "crypto-neon-fp-armv8",
725 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_LSE |
726 AArch64::AEK_RDM | AArch64::AEK_FP | AArch64::AEK_SIMD, "8.1-A"));
727 EXPECT_TRUE(testAArch64CPU(
728 "thunderx", "armv8-a", "crypto-neon-fp-armv8",
729 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_SIMD |
730 AArch64::AEK_FP | AArch64::AEK_PROFILE,
732 EXPECT_TRUE(testAArch64CPU(
733 "thunderxt81", "armv8-a", "crypto-neon-fp-armv8",
734 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_SIMD |
735 AArch64::AEK_FP | AArch64::AEK_PROFILE,
737 EXPECT_TRUE(testAArch64CPU(
738 "thunderxt83", "armv8-a", "crypto-neon-fp-armv8",
739 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_SIMD |
740 AArch64::AEK_FP | AArch64::AEK_PROFILE,
742 EXPECT_TRUE(testAArch64CPU(
743 "thunderxt88", "armv8-a", "crypto-neon-fp-armv8",
744 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_SIMD |
745 AArch64::AEK_FP | AArch64::AEK_PROFILE,
749 bool testAArch64Arch(StringRef Arch, StringRef DefaultCPU, StringRef SubArch,
751 AArch64::ArchKind AK = AArch64::parseArch(Arch);
752 return (AK != AArch64::ArchKind::INVALID) &
753 AArch64::getDefaultCPU(Arch).equals(DefaultCPU) &
754 AArch64::getSubArch(AK).equals(SubArch) &
755 (AArch64::getArchAttr(AK) == ArchAttr);
758 TEST(TargetParserTest, testAArch64Arch) {
759 EXPECT_TRUE(testAArch64Arch("armv8-a", "cortex-a53", "v8",
760 ARMBuildAttrs::CPUArch::v8_A));
761 EXPECT_TRUE(testAArch64Arch("armv8.1-a", "generic", "v8.1a",
762 ARMBuildAttrs::CPUArch::v8_A));
763 EXPECT_TRUE(testAArch64Arch("armv8.2-a", "generic", "v8.2a",
764 ARMBuildAttrs::CPUArch::v8_A));
765 EXPECT_TRUE(testAArch64Arch("armv8.3-a", "generic", "v8.3a",
766 ARMBuildAttrs::CPUArch::v8_A));
769 bool testAArch64Extension(StringRef CPUName, AArch64::ArchKind AK,
771 return AArch64::getDefaultExtensions(CPUName, AK) &
772 AArch64::parseArchExt(ArchExt);
775 TEST(TargetParserTest, testAArch64Extension) {
776 EXPECT_FALSE(testAArch64Extension("cortex-a35",
777 AArch64::ArchKind::INVALID, "ras"));
778 EXPECT_FALSE(testAArch64Extension("cortex-a53",
779 AArch64::ArchKind::INVALID, "ras"));
780 EXPECT_TRUE(testAArch64Extension("cortex-a55",
781 AArch64::ArchKind::INVALID, "ras"));
782 EXPECT_FALSE(testAArch64Extension("cortex-a57",
783 AArch64::ArchKind::INVALID, "ras"));
784 EXPECT_FALSE(testAArch64Extension("cortex-a72",
785 AArch64::ArchKind::INVALID, "ras"));
786 EXPECT_FALSE(testAArch64Extension("cortex-a73",
787 AArch64::ArchKind::INVALID, "ras"));
788 EXPECT_TRUE(testAArch64Extension("cortex-a75",
789 AArch64::ArchKind::INVALID, "ras"));
790 EXPECT_FALSE(testAArch64Extension("cyclone",
791 AArch64::ArchKind::INVALID, "ras"));
792 EXPECT_FALSE(testAArch64Extension("exynos-m1",
793 AArch64::ArchKind::INVALID, "ras"));
794 EXPECT_FALSE(testAArch64Extension("exynos-m2",
795 AArch64::ArchKind::INVALID, "ras"));
796 EXPECT_FALSE(testAArch64Extension("exynos-m3",
797 AArch64::ArchKind::INVALID, "ras"));
798 EXPECT_TRUE(testAArch64Extension("falkor",
799 AArch64::ArchKind::INVALID, "rdm"));
800 EXPECT_FALSE(testAArch64Extension("kryo",
801 AArch64::ArchKind::INVALID, "ras"));
802 EXPECT_TRUE(testAArch64Extension("saphira",
803 AArch64::ArchKind::INVALID, "crc"));
804 EXPECT_TRUE(testAArch64Extension("saphira",
805 AArch64::ArchKind::INVALID, "lse"));
806 EXPECT_TRUE(testAArch64Extension("saphira",
807 AArch64::ArchKind::INVALID, "rdm"));
808 EXPECT_TRUE(testAArch64Extension("saphira",
809 AArch64::ArchKind::INVALID, "ras"));
810 EXPECT_TRUE(testAArch64Extension("saphira",
811 AArch64::ArchKind::INVALID, "rcpc"));
812 EXPECT_TRUE(testAArch64Extension("saphira",
813 AArch64::ArchKind::INVALID, "profile"));
814 EXPECT_FALSE(testAArch64Extension("saphira",
815 AArch64::ArchKind::INVALID, "fullfp16"));
816 EXPECT_FALSE(testAArch64Extension("thunderx2t99",
817 AArch64::ArchKind::INVALID, "ras"));
818 EXPECT_FALSE(testAArch64Extension("thunderx",
819 AArch64::ArchKind::INVALID, "lse"));
820 EXPECT_FALSE(testAArch64Extension("thunderxt81",
821 AArch64::ArchKind::INVALID, "lse"));
822 EXPECT_FALSE(testAArch64Extension("thunderxt83",
823 AArch64::ArchKind::INVALID, "lse"));
824 EXPECT_FALSE(testAArch64Extension("thunderxt88",
825 AArch64::ArchKind::INVALID, "lse"));
827 EXPECT_FALSE(testAArch64Extension(
828 "generic", AArch64::ArchKind::ARMV8A, "ras"));
829 EXPECT_FALSE(testAArch64Extension(
830 "generic", AArch64::ArchKind::ARMV8_1A, "ras"));
831 EXPECT_FALSE(testAArch64Extension(
832 "generic", AArch64::ArchKind::ARMV8_2A, "spe"));
835 TEST(TargetParserTest, AArch64ExtensionFeatures) {
836 std::vector<StringRef> Features;
837 unsigned Extensions = AArch64::AEK_CRC | AArch64::AEK_CRYPTO |
838 AArch64::AEK_FP | AArch64::AEK_SIMD |
839 AArch64::AEK_FP16 | AArch64::AEK_PROFILE |
840 AArch64::AEK_RAS | AArch64::AEK_LSE |
841 AArch64::AEK_RDM | AArch64::AEK_SVE |
842 AArch64::AEK_DOTPROD | AArch64::AEK_RCPC;
844 for (unsigned i = 0; i <= Extensions; i++)
845 EXPECT_TRUE(i == 0 ? !AArch64::getExtensionFeatures(i, Features)
846 : AArch64::getExtensionFeatures(i, Features));
849 TEST(TargetParserTest, AArch64ArchFeatures) {
850 std::vector<StringRef> Features;
851 AArch64::ArchKind ArchKinds[] = {
852 #define AARCH64_ARCH(NAME, ID, CPU_ATTR, SUB_ARCH, ARCH_ATTR, ARCH_FPU, ARCH_BASE_EXT) \
853 AArch64::ArchKind::ID,
854 #include "llvm/Support/AArch64TargetParser.def"
857 for (auto AK : ArchKinds)
858 EXPECT_TRUE((AK == AArch64::ArchKind::INVALID)
859 ? !AArch64::getArchFeatures(AK, Features)
860 : AArch64::getArchFeatures(AK, Features));
863 TEST(TargetParserTest, AArch64ArchExtFeature) {
864 const char *ArchExt[][4] = {{"crc", "nocrc", "+crc", "-crc"},
865 {"crypto", "nocrypto", "+crypto", "-crypto"},
866 {"fp", "nofp", "+fp-armv8", "-fp-armv8"},
867 {"simd", "nosimd", "+neon", "-neon"},
868 {"fp16", "nofp16", "+fullfp16", "-fullfp16"},
869 {"profile", "noprofile", "+spe", "-spe"},
870 {"ras", "noras", "+ras", "-ras"},
871 {"lse", "nolse", "+lse", "-lse"},
872 {"rdm", "nordm", "+rdm", "-rdm"},
873 {"sve", "nosve", "+sve", "-sve"},
874 {"dotprod", "nodotprod", "+dotprod", "-dotprod"},
875 {"rcpc", "norcpc", "+rcpc", "-rcpc" }};
877 for (unsigned i = 0; i < array_lengthof(ArchExt); i++) {
878 EXPECT_EQ(StringRef(ArchExt[i][2]),
879 AArch64::getArchExtFeature(ArchExt[i][0]));
880 EXPECT_EQ(StringRef(ArchExt[i][3]),
881 AArch64::getArchExtFeature(ArchExt[i][1]));