1 //===----------- TargetParser.cpp - Target Parser -------------------------===//
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 #include "llvm/Support/TargetParser.h"
11 #include "llvm/ADT/STLExtras.h"
12 #include "llvm/Support/ARMBuildAttributes.h"
13 #include "gtest/gtest.h"
14 #include <string>
15
16 using namespace llvm;
17
18 namespace {
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",
31 "xscale"};
32
testARMCPU(StringRef CPUName,StringRef ExpectedArch,StringRef ExpectedFPU,unsigned ExpectedFlags,StringRef CPUAttr)33 bool testARMCPU(StringRef CPUName, StringRef ExpectedArch,
34 StringRef ExpectedFPU, unsigned ExpectedFlags,
35 StringRef CPUAttr) {
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);
40
41 unsigned ExtKind = ARM::getDefaultExtensions(CPUName, AK);
42 if (ExtKind > 1 && (ExtKind & ARM::AEK_NONE))
43 pass &= ((ExtKind ^ ARM::AEK_NONE) == ExpectedFlags);
44 else
45 pass &= (ExtKind == ExpectedFlags);
46
47 pass &= ARM::getCPUAttr(AK).equals(CPUAttr);
48
49 return pass;
50 }
51
TEST(TargetParserTest,testARMCPU)52 TEST(TargetParserTest, testARMCPU) {
53 EXPECT_TRUE(testARMCPU("invalid", "invalid", "invalid",
54 ARM::AEK_NONE, ""));
55 EXPECT_TRUE(testARMCPU("generic", "invalid", "none",
56 ARM::AEK_NONE, ""));
57
58 EXPECT_TRUE(testARMCPU("arm2", "armv2", "none",
59 ARM::AEK_NONE, "2"));
60 EXPECT_TRUE(testARMCPU("arm3", "armv2a", "none",
61 ARM::AEK_NONE, "2A"));
62 EXPECT_TRUE(testARMCPU("arm6", "armv3", "none",
63 ARM::AEK_NONE, "3"));
64 EXPECT_TRUE(testARMCPU("arm7m", "armv3m", "none",
65 ARM::AEK_NONE, "3M"));
66 EXPECT_TRUE(testARMCPU("arm8", "armv4", "none",
67 ARM::AEK_NONE, "4"));
68 EXPECT_TRUE(testARMCPU("arm810", "armv4", "none",
69 ARM::AEK_NONE, "4"));
70 EXPECT_TRUE(testARMCPU("strongarm", "armv4", "none",
71 ARM::AEK_NONE, "4"));
72 EXPECT_TRUE(testARMCPU("strongarm110", "armv4", "none",
73 ARM::AEK_NONE, "4"));
74 EXPECT_TRUE(testARMCPU("strongarm1100", "armv4", "none",
75 ARM::AEK_NONE, "4"));
76 EXPECT_TRUE(testARMCPU("strongarm1110", "armv4", "none",
77 ARM::AEK_NONE, "4"));
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",
123 ARM::AEK_DSP, "6"));
124 EXPECT_TRUE(testARMCPU("arm1136jf-s", "armv6", "vfpv2",
125 ARM::AEK_DSP, "6"));
126 EXPECT_TRUE(testARMCPU("arm1136jz-s", "armv6", "none",
127 ARM::AEK_DSP, "6"));
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,
155 "7-A"));
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 |
163 ARM::AEK_DSP,
164 "7-A"));
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 |
168 ARM::AEK_DSP,
169 "7-A"));
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 |
173 ARM::AEK_DSP,
174 "7-A"));
175 EXPECT_TRUE(testARMCPU("krait", "armv7-a", "neon-vfpv4",
176 ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
177 "7-A"));
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 |
184 ARM::AEK_DSP,
185 "7-R"));
186 EXPECT_TRUE(testARMCPU("cortex-r7", "armv7-r", "vfpv3-d16-fp16",
187 ARM::AEK_MP | ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
188 ARM::AEK_DSP,
189 "7-R"));
190 EXPECT_TRUE(testARMCPU("cortex-r8", "armv7-r", "vfpv3-d16-fp16",
191 ARM::AEK_MP | ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
192 ARM::AEK_DSP,
193 "7-R"));
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 |
197 ARM::AEK_DSP,
198 "8-R"));
199 EXPECT_TRUE(
200 testARMCPU("sc300", "armv7-m", "none", ARM::AEK_HWDIVTHUMB, "7-M"));
201 EXPECT_TRUE(
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,
211 "8-A"));
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,
216 "8-A"));
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,
221 "8-A"));
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,
227 "8.2-A"));
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,
232 "8-A"));
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,
237 "8-A"));
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,
242 "8-A"));
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,
248 "8.2-A"));
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,
253 "8-A"));
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,
258 "8-A"));
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,
263 "8-A"));
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,
268 "8-A"));
269 EXPECT_TRUE(testARMCPU("exynos-m4", "armv8-a", "crypto-neon-fp-armv8",
270 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
271 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
272 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
273 "8-A"));
274 EXPECT_TRUE(testARMCPU("cortex-m23", "armv8-m.base", "none",
275 ARM::AEK_HWDIVTHUMB, "8-M.Baseline"));
276 EXPECT_TRUE(testARMCPU("cortex-m33", "armv8-m.main", "fpv5-sp-d16",
277 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP, "8-M.Mainline"));
278 EXPECT_TRUE(testARMCPU("iwmmxt", "iwmmxt", "none",
279 ARM::AEK_NONE, "iwmmxt"));
280 EXPECT_TRUE(testARMCPU("xscale", "xscale", "none",
281 ARM::AEK_NONE, "xscale"));
282 EXPECT_TRUE(testARMCPU("swift", "armv7s", "neon-vfpv4",
283 ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
284 "7-S"));
285 }
286
287 static constexpr unsigned NumARMCPUArchs = 83;
288
TEST(TargetParserTest,testARMCPUArchList)289 TEST(TargetParserTest, testARMCPUArchList) {
290 SmallVector<StringRef, NumARMCPUArchs> List;
291 ARM::fillValidCPUArchList(List);
292
293 // No list exists for these in this test suite, so ensure all are
294 // valid, and match the expected 'magic' count.
295 EXPECT_EQ(List.size(), NumARMCPUArchs);
296 for(StringRef CPU : List) {
297 EXPECT_NE(ARM::parseCPUArch(CPU), ARM::ArchKind::INVALID);
298 }
299 }
300
TEST(TargetParserTest,testInvalidARMArch)301 TEST(TargetParserTest, testInvalidARMArch) {
302 auto InvalidArchStrings = {"armv", "armv99", "noarm"};
303 for (const char* InvalidArch : InvalidArchStrings)
304 EXPECT_EQ(ARM::parseArch(InvalidArch), ARM::ArchKind::INVALID);
305 }
306
testARMArch(StringRef Arch,StringRef DefaultCPU,StringRef SubArch,unsigned ArchAttr)307 bool testARMArch(StringRef Arch, StringRef DefaultCPU, StringRef SubArch,
308 unsigned ArchAttr) {
309 ARM::ArchKind AK = ARM::parseArch(Arch);
310 return (AK!= ARM::ArchKind::INVALID) &
311 ARM::getDefaultCPU(Arch).equals(DefaultCPU) &
312 ARM::getSubArch(AK).equals(SubArch) &
313 (ARM::getArchAttr(AK) == ArchAttr);
314 }
315
TEST(TargetParserTest,testARMArch)316 TEST(TargetParserTest, testARMArch) {
317 EXPECT_TRUE(
318 testARMArch("armv2", "arm2", "v2",
319 ARMBuildAttrs::CPUArch::Pre_v4));
320 EXPECT_TRUE(
321 testARMArch("armv2a", "arm3", "v2a",
322 ARMBuildAttrs::CPUArch::Pre_v4));
323 EXPECT_TRUE(
324 testARMArch("armv3", "arm6", "v3",
325 ARMBuildAttrs::CPUArch::Pre_v4));
326 EXPECT_TRUE(
327 testARMArch("armv3m", "arm7m", "v3m",
328 ARMBuildAttrs::CPUArch::Pre_v4));
329 EXPECT_TRUE(
330 testARMArch("armv4", "strongarm", "v4",
331 ARMBuildAttrs::CPUArch::v4));
332 EXPECT_TRUE(
333 testARMArch("armv4t", "arm7tdmi", "v4t",
334 ARMBuildAttrs::CPUArch::v4T));
335 EXPECT_TRUE(
336 testARMArch("armv5t", "arm10tdmi", "v5",
337 ARMBuildAttrs::CPUArch::v5T));
338 EXPECT_TRUE(
339 testARMArch("armv5te", "arm1022e", "v5e",
340 ARMBuildAttrs::CPUArch::v5TE));
341 EXPECT_TRUE(
342 testARMArch("armv5tej", "arm926ej-s", "v5e",
343 ARMBuildAttrs::CPUArch::v5TEJ));
344 EXPECT_TRUE(
345 testARMArch("armv6", "arm1136jf-s", "v6",
346 ARMBuildAttrs::CPUArch::v6));
347 EXPECT_TRUE(
348 testARMArch("armv6k", "arm1176j-s", "v6k",
349 ARMBuildAttrs::CPUArch::v6K));
350 EXPECT_TRUE(
351 testARMArch("armv6t2", "arm1156t2-s", "v6t2",
352 ARMBuildAttrs::CPUArch::v6T2));
353 EXPECT_TRUE(
354 testARMArch("armv6kz", "arm1176jzf-s", "v6kz",
355 ARMBuildAttrs::CPUArch::v6KZ));
356 EXPECT_TRUE(
357 testARMArch("armv6-m", "cortex-m0", "v6m",
358 ARMBuildAttrs::CPUArch::v6_M));
359 EXPECT_TRUE(
360 testARMArch("armv7-a", "generic", "v7",
361 ARMBuildAttrs::CPUArch::v7));
362 EXPECT_TRUE(
363 testARMArch("armv7ve", "generic", "v7ve",
364 ARMBuildAttrs::CPUArch::v7));
365 EXPECT_TRUE(
366 testARMArch("armv7-r", "cortex-r4", "v7r",
367 ARMBuildAttrs::CPUArch::v7));
368 EXPECT_TRUE(
369 testARMArch("armv7-m", "cortex-m3", "v7m",
370 ARMBuildAttrs::CPUArch::v7));
371 EXPECT_TRUE(
372 testARMArch("armv7e-m", "cortex-m4", "v7em",
373 ARMBuildAttrs::CPUArch::v7E_M));
374 EXPECT_TRUE(
375 testARMArch("armv8-a", "generic", "v8",
376 ARMBuildAttrs::CPUArch::v8_A));
377 EXPECT_TRUE(
378 testARMArch("armv8.1-a", "generic", "v8.1a",
379 ARMBuildAttrs::CPUArch::v8_A));
380 EXPECT_TRUE(
381 testARMArch("armv8.2-a", "generic", "v8.2a",
382 ARMBuildAttrs::CPUArch::v8_A));
383 EXPECT_TRUE(
384 testARMArch("armv8.3-a", "generic", "v8.3a",
385 ARMBuildAttrs::CPUArch::v8_A));
386 EXPECT_TRUE(
387 testARMArch("armv8-r", "cortex-r52", "v8r",
388 ARMBuildAttrs::CPUArch::v8_R));
389 EXPECT_TRUE(
390 testARMArch("armv8-m.base", "generic", "v8m.base",
391 ARMBuildAttrs::CPUArch::v8_M_Base));
392 EXPECT_TRUE(
393 testARMArch("armv8-m.main", "generic", "v8m.main",
394 ARMBuildAttrs::CPUArch::v8_M_Main));
395 EXPECT_TRUE(
396 testARMArch("iwmmxt", "iwmmxt", "",
397 ARMBuildAttrs::CPUArch::v5TE));
398 EXPECT_TRUE(
399 testARMArch("iwmmxt2", "generic", "",
400 ARMBuildAttrs::CPUArch::v5TE));
401 EXPECT_TRUE(
402 testARMArch("xscale", "xscale", "v5e",
403 ARMBuildAttrs::CPUArch::v5TE));
404 EXPECT_TRUE(
405 testARMArch("armv7s", "swift", "v7s",
406 ARMBuildAttrs::CPUArch::v7));
407 EXPECT_TRUE(
408 testARMArch("armv7k", "generic", "v7k",
409 ARMBuildAttrs::CPUArch::v7));
410 }
411
testARMExtension(StringRef CPUName,ARM::ArchKind ArchKind,StringRef ArchExt)412 bool testARMExtension(StringRef CPUName,ARM::ArchKind ArchKind, StringRef ArchExt) {
413 return ARM::getDefaultExtensions(CPUName, ArchKind) &
414 ARM::parseArchExt(ArchExt);
415 }
416
TEST(TargetParserTest,testARMExtension)417 TEST(TargetParserTest, testARMExtension) {
418 EXPECT_FALSE(testARMExtension("arm2", ARM::ArchKind::INVALID, "thumb"));
419 EXPECT_FALSE(testARMExtension("arm3", ARM::ArchKind::INVALID, "thumb"));
420 EXPECT_FALSE(testARMExtension("arm6", ARM::ArchKind::INVALID, "thumb"));
421 EXPECT_FALSE(testARMExtension("arm7m", ARM::ArchKind::INVALID, "thumb"));
422 EXPECT_FALSE(testARMExtension("strongarm", ARM::ArchKind::INVALID, "dsp"));
423 EXPECT_FALSE(testARMExtension("arm7tdmi", ARM::ArchKind::INVALID, "dsp"));
424 EXPECT_FALSE(testARMExtension("arm10tdmi",
425 ARM::ArchKind::INVALID, "simd"));
426 EXPECT_FALSE(testARMExtension("arm1022e", ARM::ArchKind::INVALID, "simd"));
427 EXPECT_FALSE(testARMExtension("arm926ej-s",
428 ARM::ArchKind::INVALID, "simd"));
429 EXPECT_FALSE(testARMExtension("arm1136jf-s",
430 ARM::ArchKind::INVALID, "crypto"));
431 EXPECT_FALSE(testARMExtension("arm1176j-s",
432 ARM::ArchKind::INVALID, "crypto"));
433 EXPECT_FALSE(testARMExtension("arm1156t2-s",
434 ARM::ArchKind::INVALID, "crypto"));
435 EXPECT_FALSE(testARMExtension("arm1176jzf-s",
436 ARM::ArchKind::INVALID, "crypto"));
437 EXPECT_FALSE(testARMExtension("cortex-m0",
438 ARM::ArchKind::INVALID, "crypto"));
439 EXPECT_FALSE(testARMExtension("cortex-a8",
440 ARM::ArchKind::INVALID, "crypto"));
441 EXPECT_FALSE(testARMExtension("cortex-r4",
442 ARM::ArchKind::INVALID, "crypto"));
443 EXPECT_FALSE(testARMExtension("cortex-m3",
444 ARM::ArchKind::INVALID, "crypto"));
445 EXPECT_FALSE(testARMExtension("cortex-a53",
446 ARM::ArchKind::INVALID, "ras"));
447 EXPECT_FALSE(testARMExtension("cortex-r52",
448 ARM::ArchKind::INVALID, "ras"));
449 EXPECT_FALSE(testARMExtension("iwmmxt", ARM::ArchKind::INVALID, "crc"));
450 EXPECT_FALSE(testARMExtension("xscale", ARM::ArchKind::INVALID, "crc"));
451 EXPECT_FALSE(testARMExtension("swift", ARM::ArchKind::INVALID, "crc"));
452
453 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV2, "thumb"));
454 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV2A, "thumb"));
455 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV3, "thumb"));
456 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV3M, "thumb"));
457 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV4, "dsp"));
458 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV4T, "dsp"));
459 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV5T, "simd"));
460 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV5TE, "simd"));
461 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV5TEJ, "simd"));
462 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV6, "crypto"));
463 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV6K, "crypto"));
464 EXPECT_FALSE(testARMExtension("generic",
465 ARM::ArchKind::ARMV6T2, "crypto"));
466 EXPECT_FALSE(testARMExtension("generic",
467 ARM::ArchKind::ARMV6KZ, "crypto"));
468 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV6M, "crypto"));
469 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV7A, "crypto"));
470 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV7R, "crypto"));
471 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV7M, "crypto"));
472 EXPECT_FALSE(testARMExtension("generic",
473 ARM::ArchKind::ARMV7EM, "crypto"));
474 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8A, "ras"));
475 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8_1A, "ras"));
476 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8_2A, "spe"));
477 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8R, "ras"));
478 EXPECT_FALSE(testARMExtension("generic",
479 ARM::ArchKind::ARMV8MBaseline, "crc"));
480 EXPECT_FALSE(testARMExtension("generic",
481 ARM::ArchKind::ARMV8MMainline, "crc"));
482 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::IWMMXT, "crc"));
483 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::IWMMXT2, "crc"));
484 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::XSCALE, "crc"));
485 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV7S, "crypto"));
486 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV7K, "crypto"));
487 }
488
TEST(TargetParserTest,ARMFPUVersion)489 TEST(TargetParserTest, ARMFPUVersion) {
490 for (ARM::FPUKind FK = static_cast<ARM::FPUKind>(0);
491 FK <= ARM::FPUKind::FK_LAST;
492 FK = static_cast<ARM::FPUKind>(static_cast<unsigned>(FK) + 1))
493 if (FK == ARM::FK_LAST || ARM::getFPUName(FK) == "invalid" ||
494 ARM::getFPUName(FK) == "none" || ARM::getFPUName(FK) == "softvfp")
495 EXPECT_EQ(ARM::FPUVersion::NONE, ARM::getFPUVersion(FK));
496 else
497 EXPECT_NE(ARM::FPUVersion::NONE, ARM::getFPUVersion(FK));
498 }
499
TEST(TargetParserTest,ARMFPUNeonSupportLevel)500 TEST(TargetParserTest, ARMFPUNeonSupportLevel) {
501 for (ARM::FPUKind FK = static_cast<ARM::FPUKind>(0);
502 FK <= ARM::FPUKind::FK_LAST;
503 FK = static_cast<ARM::FPUKind>(static_cast<unsigned>(FK) + 1))
504 if (FK == ARM::FK_LAST ||
505 ARM::getFPUName(FK).find("neon") == std::string::npos)
506 EXPECT_EQ(ARM::NeonSupportLevel::None,
507 ARM::getFPUNeonSupportLevel(FK));
508 else
509 EXPECT_NE(ARM::NeonSupportLevel::None,
510 ARM::getFPUNeonSupportLevel(FK));
511 }
512
TEST(TargetParserTest,ARMFPURestriction)513 TEST(TargetParserTest, ARMFPURestriction) {
514 for (ARM::FPUKind FK = static_cast<ARM::FPUKind>(0);
515 FK <= ARM::FPUKind::FK_LAST;
516 FK = static_cast<ARM::FPUKind>(static_cast<unsigned>(FK) + 1)) {
517 if (FK == ARM::FK_LAST ||
518 (ARM::getFPUName(FK).find("d16") == std::string::npos &&
519 ARM::getFPUName(FK).find("vfpv3xd") == std::string::npos))
520 EXPECT_EQ(ARM::FPURestriction::None, ARM::getFPURestriction(FK));
521 else
522 EXPECT_NE(ARM::FPURestriction::None, ARM::getFPURestriction(FK));
523 }
524 }
525
TEST(TargetParserTest,ARMExtensionFeatures)526 TEST(TargetParserTest, ARMExtensionFeatures) {
527 std::vector<StringRef> Features;
528 unsigned Extensions = ARM::AEK_CRC | ARM::AEK_CRYPTO | ARM::AEK_DSP |
529 ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB | ARM::AEK_MP |
530 ARM::AEK_SEC | ARM::AEK_VIRT | ARM::AEK_RAS;
531
532 for (unsigned i = 0; i <= Extensions; i++)
533 EXPECT_TRUE(i == 0 ? !ARM::getExtensionFeatures(i, Features)
534 : ARM::getExtensionFeatures(i, Features));
535 }
536
TEST(TargetParserTest,ARMFPUFeatures)537 TEST(TargetParserTest, ARMFPUFeatures) {
538 std::vector<StringRef> Features;
539 for (ARM::FPUKind FK = static_cast<ARM::FPUKind>(0);
540 FK <= ARM::FPUKind::FK_LAST;
541 FK = static_cast<ARM::FPUKind>(static_cast<unsigned>(FK) + 1))
542 EXPECT_TRUE((FK == ARM::FK_INVALID || FK >= ARM::FK_LAST)
543 ? !ARM::getFPUFeatures(FK, Features)
544 : ARM::getFPUFeatures(FK, Features));
545 }
546
TEST(TargetParserTest,ARMArchExtFeature)547 TEST(TargetParserTest, ARMArchExtFeature) {
548 const char *ArchExt[][4] = {{"crc", "nocrc", "+crc", "-crc"},
549 {"crypto", "nocrypto", "+crypto", "-crypto"},
550 {"dsp", "nodsp", "+dsp", "-dsp"},
551 {"fp", "nofp", nullptr, nullptr},
552 {"idiv", "noidiv", nullptr, nullptr},
553 {"mp", "nomp", nullptr, nullptr},
554 {"simd", "nosimd", nullptr, nullptr},
555 {"sec", "nosec", nullptr, nullptr},
556 {"virt", "novirt", nullptr, nullptr},
557 {"fp16", "nofp16", "+fullfp16", "-fullfp16"},
558 {"ras", "noras", "+ras", "-ras"},
559 {"dotprod", "nodotprod", "+dotprod", "-dotprod"},
560 {"os", "noos", nullptr, nullptr},
561 {"iwmmxt", "noiwmmxt", nullptr, nullptr},
562 {"iwmmxt2", "noiwmmxt2", nullptr, nullptr},
563 {"maverick", "maverick", nullptr, nullptr},
564 {"xscale", "noxscale", nullptr, nullptr}};
565
566 for (unsigned i = 0; i < array_lengthof(ArchExt); i++) {
567 EXPECT_EQ(StringRef(ArchExt[i][2]), ARM::getArchExtFeature(ArchExt[i][0]));
568 EXPECT_EQ(StringRef(ArchExt[i][3]), ARM::getArchExtFeature(ArchExt[i][1]));
569 }
570 }
571
TEST(TargetParserTest,ARMparseHWDiv)572 TEST(TargetParserTest, ARMparseHWDiv) {
573 const char *hwdiv[] = {"thumb", "arm", "arm,thumb", "thumb,arm"};
574
575 for (unsigned i = 0; i < array_lengthof(hwdiv); i++)
576 EXPECT_NE(ARM::AEK_INVALID, ARM::parseHWDiv((StringRef)hwdiv[i]));
577 }
578
TEST(TargetParserTest,ARMparseArchEndianAndISA)579 TEST(TargetParserTest, ARMparseArchEndianAndISA) {
580 const char *Arch[] = {
581 "v2", "v2a", "v3", "v3m", "v4", "v4t", "v5", "v5t",
582 "v5e", "v5te", "v5tej", "v6", "v6j", "v6k", "v6hl", "v6t2",
583 "v6kz", "v6z", "v6zk", "v6-m", "v6m", "v6sm", "v6s-m", "v7-a",
584 "v7", "v7a", "v7ve", "v7hl", "v7l", "v7-r", "v7r", "v7-m",
585 "v7m", "v7k", "v7s", "v7e-m", "v7em", "v8-a", "v8", "v8a",
586 "v8l", "v8.1-a", "v8.1a", "v8.2-a", "v8.2a", "v8.3-a", "v8.3a", "v8-r"};
587
588 for (unsigned i = 0; i < array_lengthof(Arch); i++) {
589 std::string arm_1 = "armeb" + (std::string)(Arch[i]);
590 std::string arm_2 = "arm" + (std::string)(Arch[i]) + "eb";
591 std::string arm_3 = "arm" + (std::string)(Arch[i]);
592 std::string thumb_1 = "thumbeb" + (std::string)(Arch[i]);
593 std::string thumb_2 = "thumb" + (std::string)(Arch[i]) + "eb";
594 std::string thumb_3 = "thumb" + (std::string)(Arch[i]);
595
596 EXPECT_EQ(ARM::EndianKind::BIG, ARM::parseArchEndian(arm_1));
597 EXPECT_EQ(ARM::EndianKind::BIG, ARM::parseArchEndian(arm_2));
598 EXPECT_EQ(ARM::EndianKind::LITTLE, ARM::parseArchEndian(arm_3));
599
600 EXPECT_EQ(ARM::ISAKind::ARM, ARM::parseArchISA(arm_1));
601 EXPECT_EQ(ARM::ISAKind::ARM, ARM::parseArchISA(arm_2));
602 EXPECT_EQ(ARM::ISAKind::ARM, ARM::parseArchISA(arm_3));
603 if (i >= 4) {
604 EXPECT_EQ(ARM::EndianKind::BIG, ARM::parseArchEndian(thumb_1));
605 EXPECT_EQ(ARM::EndianKind::BIG, ARM::parseArchEndian(thumb_2));
606 EXPECT_EQ(ARM::EndianKind::LITTLE, ARM::parseArchEndian(thumb_3));
607
608 EXPECT_EQ(ARM::ISAKind::THUMB, ARM::parseArchISA(thumb_1));
609 EXPECT_EQ(ARM::ISAKind::THUMB, ARM::parseArchISA(thumb_2));
610 EXPECT_EQ(ARM::ISAKind::THUMB, ARM::parseArchISA(thumb_3));
611 }
612 }
613
614 EXPECT_EQ(ARM::EndianKind::LITTLE, ARM::parseArchEndian("aarch64"));
615 EXPECT_EQ(ARM::EndianKind::BIG, ARM::parseArchEndian("aarch64_be"));
616
617 EXPECT_EQ(ARM::ISAKind::AARCH64, ARM::parseArchISA("aarch64"));
618 EXPECT_EQ(ARM::ISAKind::AARCH64, ARM::parseArchISA("aarch64_be"));
619 EXPECT_EQ(ARM::ISAKind::AARCH64, ARM::parseArchISA("arm64"));
620 EXPECT_EQ(ARM::ISAKind::AARCH64, ARM::parseArchISA("arm64_be"));
621 }
622
TEST(TargetParserTest,ARMparseArchProfile)623 TEST(TargetParserTest, ARMparseArchProfile) {
624 for (unsigned i = 0; i < array_lengthof(ARMArch); i++) {
625 switch (ARM::parseArch(ARMArch[i])) {
626 case ARM::ArchKind::ARMV6M:
627 case ARM::ArchKind::ARMV7M:
628 case ARM::ArchKind::ARMV7EM:
629 case ARM::ArchKind::ARMV8MMainline:
630 case ARM::ArchKind::ARMV8MBaseline:
631 EXPECT_EQ(ARM::ProfileKind::M, ARM::parseArchProfile(ARMArch[i]));
632 break;
633 case ARM::ArchKind::ARMV7R:
634 case ARM::ArchKind::ARMV8R:
635 EXPECT_EQ(ARM::ProfileKind::R, ARM::parseArchProfile(ARMArch[i]));
636 break;
637 case ARM::ArchKind::ARMV7A:
638 case ARM::ArchKind::ARMV7VE:
639 case ARM::ArchKind::ARMV7K:
640 case ARM::ArchKind::ARMV8A:
641 case ARM::ArchKind::ARMV8_1A:
642 case ARM::ArchKind::ARMV8_2A:
643 case ARM::ArchKind::ARMV8_3A:
644 EXPECT_EQ(ARM::ProfileKind::A, ARM::parseArchProfile(ARMArch[i]));
645 break;
646 default:
647 EXPECT_EQ(ARM::ProfileKind::INVALID, ARM::parseArchProfile(ARMArch[i]));
648 break;
649 }
650 }
651 }
652
TEST(TargetParserTest,ARMparseArchVersion)653 TEST(TargetParserTest, ARMparseArchVersion) {
654 for (unsigned i = 0; i < array_lengthof(ARMArch); i++)
655 if (((std::string)ARMArch[i]).substr(0, 4) == "armv")
656 EXPECT_EQ((ARMArch[i][4] - 48u), ARM::parseArchVersion(ARMArch[i]));
657 else
658 EXPECT_EQ(5u, ARM::parseArchVersion(ARMArch[i]));
659 }
660
testAArch64CPU(StringRef CPUName,StringRef ExpectedArch,StringRef ExpectedFPU,unsigned ExpectedFlags,StringRef CPUAttr)661 bool testAArch64CPU(StringRef CPUName, StringRef ExpectedArch,
662 StringRef ExpectedFPU, unsigned ExpectedFlags,
663 StringRef CPUAttr) {
664 AArch64::ArchKind AK = AArch64::parseCPUArch(CPUName);
665 bool pass = AArch64::getArchName(AK).equals(ExpectedArch);
666 unsigned FPUKind = AArch64::getDefaultFPU(CPUName, AK);
667 pass &= AArch64::getFPUName(FPUKind).equals(ExpectedFPU);
668
669 unsigned ExtKind = AArch64::getDefaultExtensions(CPUName, AK);
670 if (ExtKind > 1 && (ExtKind & AArch64::AEK_NONE))
671 pass &= ((ExtKind ^ AArch64::AEK_NONE) == ExpectedFlags);
672 else
673 pass &= (ExtKind == ExpectedFlags);
674
675 pass &= AArch64::getCPUAttr(AK).equals(CPUAttr);
676
677 return pass;
678 }
679
TEST(TargetParserTest,testAArch64CPU)680 TEST(TargetParserTest, testAArch64CPU) {
681 EXPECT_TRUE(testAArch64CPU(
682 "invalid", "invalid", "invalid",
683 AArch64::AEK_NONE, ""));
684 EXPECT_TRUE(testAArch64CPU(
685 "generic", "invalid", "none",
686 AArch64::AEK_NONE, ""));
687
688 EXPECT_TRUE(testAArch64CPU(
689 "cortex-a35", "armv8-a", "crypto-neon-fp-armv8",
690 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
691 AArch64::AEK_SIMD, "8-A"));
692 EXPECT_TRUE(testAArch64CPU(
693 "cortex-a53", "armv8-a", "crypto-neon-fp-armv8",
694 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
695 AArch64::AEK_SIMD, "8-A"));
696 EXPECT_TRUE(testAArch64CPU(
697 "cortex-a55", "armv8.2-a", "crypto-neon-fp-armv8",
698 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
699 AArch64::AEK_SIMD | AArch64::AEK_RAS | AArch64::AEK_LSE |
700 AArch64::AEK_RDM | AArch64::AEK_FP16 | AArch64::AEK_DOTPROD |
701 AArch64::AEK_RCPC, "8.2-A"));
702 EXPECT_TRUE(testAArch64CPU(
703 "cortex-a57", "armv8-a", "crypto-neon-fp-armv8",
704 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
705 AArch64::AEK_SIMD, "8-A"));
706 EXPECT_TRUE(testAArch64CPU(
707 "cortex-a72", "armv8-a", "crypto-neon-fp-armv8",
708 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
709 AArch64::AEK_SIMD, "8-A"));
710 EXPECT_TRUE(testAArch64CPU(
711 "cortex-a73", "armv8-a", "crypto-neon-fp-armv8",
712 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
713 AArch64::AEK_SIMD, "8-A"));
714 EXPECT_TRUE(testAArch64CPU(
715 "cortex-a75", "armv8.2-a", "crypto-neon-fp-armv8",
716 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
717 AArch64::AEK_SIMD | AArch64::AEK_RAS | AArch64::AEK_LSE |
718 AArch64::AEK_RDM | AArch64::AEK_FP16 | AArch64::AEK_DOTPROD |
719 AArch64::AEK_RCPC, "8.2-A"));
720 EXPECT_TRUE(testAArch64CPU(
721 "cyclone", "armv8-a", "crypto-neon-fp-armv8",
722 AArch64::AEK_CRYPTO | AArch64::AEK_FP | AArch64::AEK_SIMD, "8-A"));
723 EXPECT_TRUE(testAArch64CPU(
724 "exynos-m1", "armv8-a", "crypto-neon-fp-armv8",
725 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
726 AArch64::AEK_SIMD, "8-A"));
727 EXPECT_TRUE(testAArch64CPU(
728 "exynos-m2", "armv8-a", "crypto-neon-fp-armv8",
729 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
730 AArch64::AEK_SIMD, "8-A"));
731 EXPECT_TRUE(testAArch64CPU(
732 "exynos-m3", "armv8-a", "crypto-neon-fp-armv8",
733 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
734 AArch64::AEK_SIMD, "8-A"));
735 EXPECT_TRUE(testAArch64CPU(
736 "exynos-m4", "armv8-a", "crypto-neon-fp-armv8",
737 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
738 AArch64::AEK_SIMD, "8-A"));
739 EXPECT_TRUE(testAArch64CPU(
740 "falkor", "armv8-a", "crypto-neon-fp-armv8",
741 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
742 AArch64::AEK_SIMD | AArch64::AEK_RDM, "8-A"));
743 EXPECT_TRUE(testAArch64CPU(
744 "kryo", "armv8-a", "crypto-neon-fp-armv8",
745 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
746 AArch64::AEK_SIMD, "8-A"));
747 EXPECT_TRUE(testAArch64CPU(
748 "thunderx2t99", "armv8.1-a", "crypto-neon-fp-armv8",
749 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_LSE |
750 AArch64::AEK_RDM | AArch64::AEK_FP | AArch64::AEK_SIMD, "8.1-A"));
751 EXPECT_TRUE(testAArch64CPU(
752 "thunderx", "armv8-a", "crypto-neon-fp-armv8",
753 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_SIMD |
754 AArch64::AEK_FP | AArch64::AEK_PROFILE,
755 "8-A"));
756 EXPECT_TRUE(testAArch64CPU(
757 "thunderxt81", "armv8-a", "crypto-neon-fp-armv8",
758 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_SIMD |
759 AArch64::AEK_FP | AArch64::AEK_PROFILE,
760 "8-A"));
761 EXPECT_TRUE(testAArch64CPU(
762 "thunderxt83", "armv8-a", "crypto-neon-fp-armv8",
763 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_SIMD |
764 AArch64::AEK_FP | AArch64::AEK_PROFILE,
765 "8-A"));
766 EXPECT_TRUE(testAArch64CPU(
767 "thunderxt88", "armv8-a", "crypto-neon-fp-armv8",
768 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_SIMD |
769 AArch64::AEK_FP | AArch64::AEK_PROFILE,
770 "8-A"));
771 }
772
773 static constexpr unsigned NumAArch64CPUArchs = 20;
774
TEST(TargetParserTest,testAArch64CPUArchList)775 TEST(TargetParserTest, testAArch64CPUArchList) {
776 SmallVector<StringRef, NumAArch64CPUArchs> List;
777 AArch64::fillValidCPUArchList(List);
778
779 // No list exists for these in this test suite, so ensure all are
780 // valid, and match the expected 'magic' count.
781 EXPECT_EQ(List.size(), NumAArch64CPUArchs);
782 for(StringRef CPU : List) {
783 EXPECT_NE(AArch64::parseCPUArch(CPU), AArch64::ArchKind::INVALID);
784 }
785 }
786
testAArch64Arch(StringRef Arch,StringRef DefaultCPU,StringRef SubArch,unsigned ArchAttr)787 bool testAArch64Arch(StringRef Arch, StringRef DefaultCPU, StringRef SubArch,
788 unsigned ArchAttr) {
789 AArch64::ArchKind AK = AArch64::parseArch(Arch);
790 return (AK != AArch64::ArchKind::INVALID) &
791 AArch64::getDefaultCPU(Arch).equals(DefaultCPU) &
792 AArch64::getSubArch(AK).equals(SubArch) &
793 (AArch64::getArchAttr(AK) == ArchAttr);
794 }
795
TEST(TargetParserTest,testAArch64Arch)796 TEST(TargetParserTest, testAArch64Arch) {
797 EXPECT_TRUE(testAArch64Arch("armv8-a", "cortex-a53", "v8",
798 ARMBuildAttrs::CPUArch::v8_A));
799 EXPECT_TRUE(testAArch64Arch("armv8.1-a", "generic", "v8.1a",
800 ARMBuildAttrs::CPUArch::v8_A));
801 EXPECT_TRUE(testAArch64Arch("armv8.2-a", "generic", "v8.2a",
802 ARMBuildAttrs::CPUArch::v8_A));
803 EXPECT_TRUE(testAArch64Arch("armv8.3-a", "generic", "v8.3a",
804 ARMBuildAttrs::CPUArch::v8_A));
805 }
806
testAArch64Extension(StringRef CPUName,AArch64::ArchKind AK,StringRef ArchExt)807 bool testAArch64Extension(StringRef CPUName, AArch64::ArchKind AK,
808 StringRef ArchExt) {
809 return AArch64::getDefaultExtensions(CPUName, AK) &
810 AArch64::parseArchExt(ArchExt);
811 }
812
TEST(TargetParserTest,testAArch64Extension)813 TEST(TargetParserTest, testAArch64Extension) {
814 EXPECT_FALSE(testAArch64Extension("cortex-a35",
815 AArch64::ArchKind::INVALID, "ras"));
816 EXPECT_FALSE(testAArch64Extension("cortex-a53",
817 AArch64::ArchKind::INVALID, "ras"));
818 EXPECT_TRUE(testAArch64Extension("cortex-a55",
819 AArch64::ArchKind::INVALID, "ras"));
820 EXPECT_FALSE(testAArch64Extension("cortex-a57",
821 AArch64::ArchKind::INVALID, "ras"));
822 EXPECT_FALSE(testAArch64Extension("cortex-a72",
823 AArch64::ArchKind::INVALID, "ras"));
824 EXPECT_FALSE(testAArch64Extension("cortex-a73",
825 AArch64::ArchKind::INVALID, "ras"));
826 EXPECT_TRUE(testAArch64Extension("cortex-a75",
827 AArch64::ArchKind::INVALID, "ras"));
828 EXPECT_FALSE(testAArch64Extension("cyclone",
829 AArch64::ArchKind::INVALID, "ras"));
830 EXPECT_FALSE(testAArch64Extension("exynos-m1",
831 AArch64::ArchKind::INVALID, "ras"));
832 EXPECT_FALSE(testAArch64Extension("exynos-m2",
833 AArch64::ArchKind::INVALID, "ras"));
834 EXPECT_FALSE(testAArch64Extension("exynos-m3",
835 AArch64::ArchKind::INVALID, "ras"));
836 EXPECT_FALSE(testAArch64Extension("exynos-m4",
837 AArch64::ArchKind::INVALID, "ras"));
838 EXPECT_TRUE(testAArch64Extension("falkor",
839 AArch64::ArchKind::INVALID, "rdm"));
840 EXPECT_FALSE(testAArch64Extension("kryo",
841 AArch64::ArchKind::INVALID, "ras"));
842 EXPECT_TRUE(testAArch64Extension("saphira",
843 AArch64::ArchKind::INVALID, "crc"));
844 EXPECT_TRUE(testAArch64Extension("saphira",
845 AArch64::ArchKind::INVALID, "lse"));
846 EXPECT_TRUE(testAArch64Extension("saphira",
847 AArch64::ArchKind::INVALID, "rdm"));
848 EXPECT_TRUE(testAArch64Extension("saphira",
849 AArch64::ArchKind::INVALID, "ras"));
850 EXPECT_TRUE(testAArch64Extension("saphira",
851 AArch64::ArchKind::INVALID, "rcpc"));
852 EXPECT_TRUE(testAArch64Extension("saphira",
853 AArch64::ArchKind::INVALID, "profile"));
854 EXPECT_FALSE(testAArch64Extension("saphira",
855 AArch64::ArchKind::INVALID, "fullfp16"));
856 EXPECT_FALSE(testAArch64Extension("thunderx2t99",
857 AArch64::ArchKind::INVALID, "ras"));
858 EXPECT_FALSE(testAArch64Extension("thunderx",
859 AArch64::ArchKind::INVALID, "lse"));
860 EXPECT_FALSE(testAArch64Extension("thunderxt81",
861 AArch64::ArchKind::INVALID, "lse"));
862 EXPECT_FALSE(testAArch64Extension("thunderxt83",
863 AArch64::ArchKind::INVALID, "lse"));
864 EXPECT_FALSE(testAArch64Extension("thunderxt88",
865 AArch64::ArchKind::INVALID, "lse"));
866
867 EXPECT_FALSE(testAArch64Extension(
868 "generic", AArch64::ArchKind::ARMV8A, "ras"));
869 EXPECT_FALSE(testAArch64Extension(
870 "generic", AArch64::ArchKind::ARMV8_1A, "ras"));
871 EXPECT_FALSE(testAArch64Extension(
872 "generic", AArch64::ArchKind::ARMV8_2A, "spe"));
873 }
874
TEST(TargetParserTest,AArch64ExtensionFeatures)875 TEST(TargetParserTest, AArch64ExtensionFeatures) {
876 std::vector<StringRef> Features;
877 unsigned Extensions = AArch64::AEK_CRC | AArch64::AEK_CRYPTO |
878 AArch64::AEK_FP | AArch64::AEK_SIMD |
879 AArch64::AEK_FP16 | AArch64::AEK_PROFILE |
880 AArch64::AEK_RAS | AArch64::AEK_LSE |
881 AArch64::AEK_RDM | AArch64::AEK_SVE |
882 AArch64::AEK_DOTPROD | AArch64::AEK_RCPC;
883
884 for (unsigned i = 0; i <= Extensions; i++)
885 EXPECT_TRUE(i == 0 ? !AArch64::getExtensionFeatures(i, Features)
886 : AArch64::getExtensionFeatures(i, Features));
887 }
888
TEST(TargetParserTest,AArch64ArchFeatures)889 TEST(TargetParserTest, AArch64ArchFeatures) {
890 std::vector<StringRef> Features;
891 AArch64::ArchKind ArchKinds[] = {
892 #define AARCH64_ARCH(NAME, ID, CPU_ATTR, SUB_ARCH, ARCH_ATTR, ARCH_FPU, ARCH_BASE_EXT) \
893 AArch64::ArchKind::ID,
894 #include "llvm/Support/AArch64TargetParser.def"
895 };
896
897 for (auto AK : ArchKinds)
898 EXPECT_TRUE((AK == AArch64::ArchKind::INVALID)
899 ? !AArch64::getArchFeatures(AK, Features)
900 : AArch64::getArchFeatures(AK, Features));
901 }
902
TEST(TargetParserTest,AArch64ArchExtFeature)903 TEST(TargetParserTest, AArch64ArchExtFeature) {
904 const char *ArchExt[][4] = {{"crc", "nocrc", "+crc", "-crc"},
905 {"crypto", "nocrypto", "+crypto", "-crypto"},
906 {"fp", "nofp", "+fp-armv8", "-fp-armv8"},
907 {"simd", "nosimd", "+neon", "-neon"},
908 {"fp16", "nofp16", "+fullfp16", "-fullfp16"},
909 {"profile", "noprofile", "+spe", "-spe"},
910 {"ras", "noras", "+ras", "-ras"},
911 {"lse", "nolse", "+lse", "-lse"},
912 {"rdm", "nordm", "+rdm", "-rdm"},
913 {"sve", "nosve", "+sve", "-sve"},
914 {"dotprod", "nodotprod", "+dotprod", "-dotprod"},
915 {"rcpc", "norcpc", "+rcpc", "-rcpc" }};
916
917 for (unsigned i = 0; i < array_lengthof(ArchExt); i++) {
918 EXPECT_EQ(StringRef(ArchExt[i][2]),
919 AArch64::getArchExtFeature(ArchExt[i][0]));
920 EXPECT_EQ(StringRef(ArchExt[i][3]),
921 AArch64::getArchExtFeature(ArchExt[i][1]));
922 }
923 }
924 }
925