Revert r354244 "[DAGCombiner] Eliminate dead stores to stack."
[llvm-complete.git] / unittests / Support / TargetParserTest.cpp
blob53ccc8dd2b80a4b5238461cc5129ff4876d06488
1 //===----------- TargetParser.cpp - Target Parser -------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/Support/TargetParser.h"
10 #include "llvm/ADT/STLExtras.h"
11 #include "llvm/Support/ARMBuildAttributes.h"
12 #include "gtest/gtest.h"
13 #include <string>
15 using namespace llvm;
17 namespace {
18 const char *ARMArch[] = {
19 "armv2", "armv2a", "armv3", "armv3m", "armv4",
20 "armv4t", "armv5", "armv5t", "armv5e", "armv5te",
21 "armv5tej", "armv6", "armv6j", "armv6k", "armv6hl",
22 "armv6t2", "armv6kz", "armv6z", "armv6zk", "armv6-m",
23 "armv6m", "armv6sm", "armv6s-m", "armv7-a", "armv7",
24 "armv7a", "armv7ve", "armv7hl", "armv7l", "armv7-r",
25 "armv7r", "armv7-m", "armv7m", "armv7k", "armv7s",
26 "armv7e-m", "armv7em", "armv8-a", "armv8", "armv8a",
27 "armv8l", "armv8.1-a", "armv8.1a", "armv8.2-a", "armv8.2a",
28 "armv8.3-a", "armv8.3a", "armv8.4-a", "armv8.4a", "armv8.5-a",
29 "armv8.5a", "armv8-r", "armv8r", "armv8-m.base", "armv8m.base",
30 "armv8-m.main", "armv8m.main", "iwmmxt", "iwmmxt2", "xscale"
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);
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);
47 pass &= ARM::getCPUAttr(AK).equals(CPUAttr);
49 return pass;
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, ""));
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("arm1176jz-s", "armv6kz", "none",
129 ARM::AEK_SEC | ARM::AEK_DSP, "6KZ"));
130 EXPECT_TRUE(testARMCPU("mpcore", "armv6k", "vfpv2",
131 ARM::AEK_DSP, "6K"));
132 EXPECT_TRUE(testARMCPU("mpcorenovfp", "armv6k", "none",
133 ARM::AEK_DSP, "6K"));
134 EXPECT_TRUE(testARMCPU("arm1176jzf-s", "armv6kz", "vfpv2",
135 ARM::AEK_SEC | ARM::AEK_DSP, "6KZ"));
136 EXPECT_TRUE(testARMCPU("arm1156t2-s", "armv6t2", "none",
137 ARM::AEK_DSP, "6T2"));
138 EXPECT_TRUE(testARMCPU("arm1156t2f-s", "armv6t2", "vfpv2",
139 ARM::AEK_DSP, "6T2"));
140 EXPECT_TRUE(testARMCPU("cortex-m0", "armv6-m", "none",
141 ARM::AEK_NONE, "6-M"));
142 EXPECT_TRUE(testARMCPU("cortex-m0plus", "armv6-m", "none",
143 ARM::AEK_NONE, "6-M"));
144 EXPECT_TRUE(testARMCPU("cortex-m1", "armv6-m", "none",
145 ARM::AEK_NONE, "6-M"));
146 EXPECT_TRUE(testARMCPU("sc000", "armv6-m", "none",
147 ARM::AEK_NONE, "6-M"));
148 EXPECT_TRUE(testARMCPU("cortex-a5", "armv7-a", "neon-vfpv4",
149 ARM::AEK_MP | ARM::AEK_SEC | ARM::AEK_DSP, "7-A"));
150 EXPECT_TRUE(testARMCPU("cortex-a7", "armv7-a", "neon-vfpv4",
151 ARM::AEK_HWDIVTHUMB | ARM::AEK_HWDIVARM | ARM::AEK_MP |
152 ARM::AEK_SEC | ARM::AEK_VIRT | ARM::AEK_DSP,
153 "7-A"));
154 EXPECT_TRUE(testARMCPU("cortex-a8", "armv7-a", "neon",
155 ARM::AEK_SEC | ARM::AEK_DSP, "7-A"));
156 EXPECT_TRUE(testARMCPU("cortex-a9", "armv7-a", "neon-fp16",
157 ARM::AEK_MP | ARM::AEK_SEC | ARM::AEK_DSP, "7-A"));
158 EXPECT_TRUE(testARMCPU("cortex-a12", "armv7-a", "neon-vfpv4",
159 ARM::AEK_SEC | ARM::AEK_MP | ARM::AEK_VIRT |
160 ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
161 ARM::AEK_DSP,
162 "7-A"));
163 EXPECT_TRUE(testARMCPU("cortex-a15", "armv7-a", "neon-vfpv4",
164 ARM::AEK_SEC | ARM::AEK_MP | ARM::AEK_VIRT |
165 ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
166 ARM::AEK_DSP,
167 "7-A"));
168 EXPECT_TRUE(testARMCPU("cortex-a17", "armv7-a", "neon-vfpv4",
169 ARM::AEK_SEC | ARM::AEK_MP | ARM::AEK_VIRT |
170 ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
171 ARM::AEK_DSP,
172 "7-A"));
173 EXPECT_TRUE(testARMCPU("krait", "armv7-a", "neon-vfpv4",
174 ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
175 "7-A"));
176 EXPECT_TRUE(testARMCPU("cortex-r4", "armv7-r", "none",
177 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP, "7-R"));
178 EXPECT_TRUE(testARMCPU("cortex-r4f", "armv7-r", "vfpv3-d16",
179 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP, "7-R"));
180 EXPECT_TRUE(testARMCPU("cortex-r5", "armv7-r", "vfpv3-d16",
181 ARM::AEK_MP | ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
182 ARM::AEK_DSP,
183 "7-R"));
184 EXPECT_TRUE(testARMCPU("cortex-r7", "armv7-r", "vfpv3-d16-fp16",
185 ARM::AEK_MP | ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
186 ARM::AEK_DSP,
187 "7-R"));
188 EXPECT_TRUE(testARMCPU("cortex-r8", "armv7-r", "vfpv3-d16-fp16",
189 ARM::AEK_MP | ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
190 ARM::AEK_DSP,
191 "7-R"));
192 EXPECT_TRUE(testARMCPU("cortex-r52", "armv8-r", "neon-fp-armv8",
193 ARM::AEK_CRC | ARM::AEK_MP | ARM::AEK_VIRT |
194 ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
195 ARM::AEK_DSP,
196 "8-R"));
197 EXPECT_TRUE(
198 testARMCPU("sc300", "armv7-m", "none", ARM::AEK_HWDIVTHUMB, "7-M"));
199 EXPECT_TRUE(
200 testARMCPU("cortex-m3", "armv7-m", "none", ARM::AEK_HWDIVTHUMB, "7-M"));
201 EXPECT_TRUE(testARMCPU("cortex-m4", "armv7e-m", "fpv4-sp-d16",
202 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP, "7E-M"));
203 EXPECT_TRUE(testARMCPU("cortex-m7", "armv7e-m", "fpv5-d16",
204 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP, "7E-M"));
205 EXPECT_TRUE(testARMCPU("cortex-a32", "armv8-a", "crypto-neon-fp-armv8",
206 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
207 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
208 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
209 "8-A"));
210 EXPECT_TRUE(testARMCPU("cortex-a35", "armv8-a", "crypto-neon-fp-armv8",
211 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
212 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
213 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
214 "8-A"));
215 EXPECT_TRUE(testARMCPU("cortex-a53", "armv8-a", "crypto-neon-fp-armv8",
216 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
217 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
218 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
219 "8-A"));
220 EXPECT_TRUE(testARMCPU("cortex-a55", "armv8.2-a", "crypto-neon-fp-armv8",
221 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
222 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
223 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP | ARM::AEK_FP16 |
224 ARM::AEK_RAS | ARM::AEK_DOTPROD,
225 "8.2-A"));
226 EXPECT_TRUE(testARMCPU("cortex-a57", "armv8-a", "crypto-neon-fp-armv8",
227 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
228 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
229 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
230 "8-A"));
231 EXPECT_TRUE(testARMCPU("cortex-a72", "armv8-a", "crypto-neon-fp-armv8",
232 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
233 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
234 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
235 "8-A"));
236 EXPECT_TRUE(testARMCPU("cortex-a73", "armv8-a", "crypto-neon-fp-armv8",
237 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
238 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
239 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
240 "8-A"));
241 EXPECT_TRUE(testARMCPU("cortex-a75", "armv8.2-a", "crypto-neon-fp-armv8",
242 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
243 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
244 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP | ARM::AEK_FP16 |
245 ARM::AEK_RAS | ARM::AEK_DOTPROD,
246 "8.2-A"));
247 EXPECT_TRUE(testARMCPU("cyclone", "armv8-a", "crypto-neon-fp-armv8",
248 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
249 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
250 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
251 "8-A"));
252 EXPECT_TRUE(testARMCPU("exynos-m1", "armv8-a", "crypto-neon-fp-armv8",
253 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
254 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
255 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
256 "8-A"));
257 EXPECT_TRUE(testARMCPU("exynos-m2", "armv8-a", "crypto-neon-fp-armv8",
258 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
259 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
260 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
261 "8-A"));
262 EXPECT_TRUE(testARMCPU("exynos-m3", "armv8-a", "crypto-neon-fp-armv8",
263 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
264 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
265 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
266 "8-A"));
267 EXPECT_TRUE(testARMCPU("exynos-m4", "armv8.2-a", "crypto-neon-fp-armv8",
268 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
269 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
270 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP | ARM::AEK_DOTPROD |
271 ARM::AEK_FP16 | ARM::AEK_RAS,
272 "8.2-A"));
273 EXPECT_TRUE(testARMCPU("cortex-m23", "armv8-m.base", "none",
274 ARM::AEK_HWDIVTHUMB, "8-M.Baseline"));
275 EXPECT_TRUE(testARMCPU("cortex-m33", "armv8-m.main", "fpv5-sp-d16",
276 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP, "8-M.Mainline"));
277 EXPECT_TRUE(testARMCPU("iwmmxt", "iwmmxt", "none",
278 ARM::AEK_NONE, "iwmmxt"));
279 EXPECT_TRUE(testARMCPU("xscale", "xscale", "none",
280 ARM::AEK_NONE, "xscale"));
281 EXPECT_TRUE(testARMCPU("swift", "armv7s", "neon-vfpv4",
282 ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
283 "7-S"));
286 static constexpr unsigned NumARMCPUArchs = 82;
288 TEST(TargetParserTest, testARMCPUArchList) {
289 SmallVector<StringRef, NumARMCPUArchs> List;
290 ARM::fillValidCPUArchList(List);
292 // No list exists for these in this test suite, so ensure all are
293 // valid, and match the expected 'magic' count.
294 EXPECT_EQ(List.size(), NumARMCPUArchs);
295 for(StringRef CPU : List) {
296 EXPECT_NE(ARM::parseCPUArch(CPU), ARM::ArchKind::INVALID);
300 TEST(TargetParserTest, testInvalidARMArch) {
301 auto InvalidArchStrings = {"armv", "armv99", "noarm"};
302 for (const char* InvalidArch : InvalidArchStrings)
303 EXPECT_EQ(ARM::parseArch(InvalidArch), ARM::ArchKind::INVALID);
306 bool testARMArch(StringRef Arch, StringRef DefaultCPU, StringRef SubArch,
307 unsigned ArchAttr) {
308 ARM::ArchKind AK = ARM::parseArch(Arch);
309 return (AK!= ARM::ArchKind::INVALID) &
310 ARM::getDefaultCPU(Arch).equals(DefaultCPU) &
311 ARM::getSubArch(AK).equals(SubArch) &
312 (ARM::getArchAttr(AK) == ArchAttr);
315 TEST(TargetParserTest, testARMArch) {
316 EXPECT_TRUE(
317 testARMArch("armv2", "arm2", "v2",
318 ARMBuildAttrs::CPUArch::Pre_v4));
319 EXPECT_TRUE(
320 testARMArch("armv2a", "arm3", "v2a",
321 ARMBuildAttrs::CPUArch::Pre_v4));
322 EXPECT_TRUE(
323 testARMArch("armv3", "arm6", "v3",
324 ARMBuildAttrs::CPUArch::Pre_v4));
325 EXPECT_TRUE(
326 testARMArch("armv3m", "arm7m", "v3m",
327 ARMBuildAttrs::CPUArch::Pre_v4));
328 EXPECT_TRUE(
329 testARMArch("armv4", "strongarm", "v4",
330 ARMBuildAttrs::CPUArch::v4));
331 EXPECT_TRUE(
332 testARMArch("armv4t", "arm7tdmi", "v4t",
333 ARMBuildAttrs::CPUArch::v4T));
334 EXPECT_TRUE(
335 testARMArch("armv5t", "arm10tdmi", "v5",
336 ARMBuildAttrs::CPUArch::v5T));
337 EXPECT_TRUE(
338 testARMArch("armv5te", "arm1022e", "v5e",
339 ARMBuildAttrs::CPUArch::v5TE));
340 EXPECT_TRUE(
341 testARMArch("armv5tej", "arm926ej-s", "v5e",
342 ARMBuildAttrs::CPUArch::v5TEJ));
343 EXPECT_TRUE(
344 testARMArch("armv6", "arm1136jf-s", "v6",
345 ARMBuildAttrs::CPUArch::v6));
346 EXPECT_TRUE(
347 testARMArch("armv6k", "mpcore", "v6k",
348 ARMBuildAttrs::CPUArch::v6K));
349 EXPECT_TRUE(
350 testARMArch("armv6t2", "arm1156t2-s", "v6t2",
351 ARMBuildAttrs::CPUArch::v6T2));
352 EXPECT_TRUE(
353 testARMArch("armv6kz", "arm1176jzf-s", "v6kz",
354 ARMBuildAttrs::CPUArch::v6KZ));
355 EXPECT_TRUE(
356 testARMArch("armv6-m", "cortex-m0", "v6m",
357 ARMBuildAttrs::CPUArch::v6_M));
358 EXPECT_TRUE(
359 testARMArch("armv7-a", "generic", "v7",
360 ARMBuildAttrs::CPUArch::v7));
361 EXPECT_TRUE(
362 testARMArch("armv7ve", "generic", "v7ve",
363 ARMBuildAttrs::CPUArch::v7));
364 EXPECT_TRUE(
365 testARMArch("armv7-r", "cortex-r4", "v7r",
366 ARMBuildAttrs::CPUArch::v7));
367 EXPECT_TRUE(
368 testARMArch("armv7-m", "cortex-m3", "v7m",
369 ARMBuildAttrs::CPUArch::v7));
370 EXPECT_TRUE(
371 testARMArch("armv7e-m", "cortex-m4", "v7em",
372 ARMBuildAttrs::CPUArch::v7E_M));
373 EXPECT_TRUE(
374 testARMArch("armv8-a", "generic", "v8",
375 ARMBuildAttrs::CPUArch::v8_A));
376 EXPECT_TRUE(
377 testARMArch("armv8.1-a", "generic", "v8.1a",
378 ARMBuildAttrs::CPUArch::v8_A));
379 EXPECT_TRUE(
380 testARMArch("armv8.2-a", "generic", "v8.2a",
381 ARMBuildAttrs::CPUArch::v8_A));
382 EXPECT_TRUE(
383 testARMArch("armv8.3-a", "generic", "v8.3a",
384 ARMBuildAttrs::CPUArch::v8_A));
385 EXPECT_TRUE(
386 testARMArch("armv8.4-a", "generic", "v8.4a",
387 ARMBuildAttrs::CPUArch::v8_A));
388 EXPECT_TRUE(
389 testARMArch("armv8.5-a", "generic", "v8.5a",
390 ARMBuildAttrs::CPUArch::v8_A));
391 EXPECT_TRUE(
392 testARMArch("armv8-r", "cortex-r52", "v8r",
393 ARMBuildAttrs::CPUArch::v8_R));
394 EXPECT_TRUE(
395 testARMArch("armv8-m.base", "generic", "v8m.base",
396 ARMBuildAttrs::CPUArch::v8_M_Base));
397 EXPECT_TRUE(
398 testARMArch("armv8-m.main", "generic", "v8m.main",
399 ARMBuildAttrs::CPUArch::v8_M_Main));
400 EXPECT_TRUE(
401 testARMArch("iwmmxt", "iwmmxt", "",
402 ARMBuildAttrs::CPUArch::v5TE));
403 EXPECT_TRUE(
404 testARMArch("iwmmxt2", "generic", "",
405 ARMBuildAttrs::CPUArch::v5TE));
406 EXPECT_TRUE(
407 testARMArch("xscale", "xscale", "v5e",
408 ARMBuildAttrs::CPUArch::v5TE));
409 EXPECT_TRUE(
410 testARMArch("armv7s", "swift", "v7s",
411 ARMBuildAttrs::CPUArch::v7));
412 EXPECT_TRUE(
413 testARMArch("armv7k", "generic", "v7k",
414 ARMBuildAttrs::CPUArch::v7));
417 bool testARMExtension(StringRef CPUName,ARM::ArchKind ArchKind, StringRef ArchExt) {
418 return ARM::getDefaultExtensions(CPUName, ArchKind) &
419 ARM::parseArchExt(ArchExt);
422 TEST(TargetParserTest, testARMExtension) {
423 EXPECT_FALSE(testARMExtension("arm2", ARM::ArchKind::INVALID, "thumb"));
424 EXPECT_FALSE(testARMExtension("arm3", ARM::ArchKind::INVALID, "thumb"));
425 EXPECT_FALSE(testARMExtension("arm6", ARM::ArchKind::INVALID, "thumb"));
426 EXPECT_FALSE(testARMExtension("arm7m", ARM::ArchKind::INVALID, "thumb"));
427 EXPECT_FALSE(testARMExtension("strongarm", ARM::ArchKind::INVALID, "dsp"));
428 EXPECT_FALSE(testARMExtension("arm7tdmi", ARM::ArchKind::INVALID, "dsp"));
429 EXPECT_FALSE(testARMExtension("arm10tdmi",
430 ARM::ArchKind::INVALID, "simd"));
431 EXPECT_FALSE(testARMExtension("arm1022e", ARM::ArchKind::INVALID, "simd"));
432 EXPECT_FALSE(testARMExtension("arm926ej-s",
433 ARM::ArchKind::INVALID, "simd"));
434 EXPECT_FALSE(testARMExtension("arm1136jf-s",
435 ARM::ArchKind::INVALID, "crypto"));
436 EXPECT_FALSE(testARMExtension("arm1176j-s",
437 ARM::ArchKind::INVALID, "crypto"));
438 EXPECT_FALSE(testARMExtension("arm1156t2-s",
439 ARM::ArchKind::INVALID, "crypto"));
440 EXPECT_FALSE(testARMExtension("arm1176jzf-s",
441 ARM::ArchKind::INVALID, "crypto"));
442 EXPECT_FALSE(testARMExtension("cortex-m0",
443 ARM::ArchKind::INVALID, "crypto"));
444 EXPECT_FALSE(testARMExtension("cortex-a8",
445 ARM::ArchKind::INVALID, "crypto"));
446 EXPECT_FALSE(testARMExtension("cortex-r4",
447 ARM::ArchKind::INVALID, "crypto"));
448 EXPECT_FALSE(testARMExtension("cortex-m3",
449 ARM::ArchKind::INVALID, "crypto"));
450 EXPECT_FALSE(testARMExtension("cortex-a53",
451 ARM::ArchKind::INVALID, "ras"));
452 EXPECT_FALSE(testARMExtension("cortex-a53",
453 ARM::ArchKind::INVALID, "fp16"));
454 EXPECT_TRUE(testARMExtension("cortex-a55",
455 ARM::ArchKind::INVALID, "fp16"));
456 EXPECT_FALSE(testARMExtension("cortex-a55",
457 ARM::ArchKind::INVALID, "fp16fml"));
458 EXPECT_TRUE(testARMExtension("cortex-a75",
459 ARM::ArchKind::INVALID, "fp16"));
460 EXPECT_FALSE(testARMExtension("cortex-a75",
461 ARM::ArchKind::INVALID, "fp16fml"));
462 EXPECT_FALSE(testARMExtension("cortex-r52",
463 ARM::ArchKind::INVALID, "ras"));
464 EXPECT_FALSE(testARMExtension("iwmmxt", ARM::ArchKind::INVALID, "crc"));
465 EXPECT_FALSE(testARMExtension("xscale", ARM::ArchKind::INVALID, "crc"));
466 EXPECT_FALSE(testARMExtension("swift", ARM::ArchKind::INVALID, "crc"));
468 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV2, "thumb"));
469 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV2A, "thumb"));
470 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV3, "thumb"));
471 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV3M, "thumb"));
472 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV4, "dsp"));
473 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV4T, "dsp"));
474 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV5T, "simd"));
475 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV5TE, "simd"));
476 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV5TEJ, "simd"));
477 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV6, "crypto"));
478 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV6K, "crypto"));
479 EXPECT_FALSE(testARMExtension("generic",
480 ARM::ArchKind::ARMV6T2, "crypto"));
481 EXPECT_FALSE(testARMExtension("generic",
482 ARM::ArchKind::ARMV6KZ, "crypto"));
483 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV6M, "crypto"));
484 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV7A, "crypto"));
485 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV7R, "crypto"));
486 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV7M, "crypto"));
487 EXPECT_FALSE(testARMExtension("generic",
488 ARM::ArchKind::ARMV7EM, "crypto"));
489 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8A, "ras"));
490 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8_1A, "ras"));
491 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8_2A, "profile"));
492 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8_2A, "fp16"));
493 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8_2A, "fp16fml"));
494 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8_3A, "fp16"));
495 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8_3A, "fp16fml"));
496 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8_4A, "fp16"));
497 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8_4A, "fp16fml"));
498 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8R, "ras"));
499 EXPECT_FALSE(testARMExtension("generic",
500 ARM::ArchKind::ARMV8MBaseline, "crc"));
501 EXPECT_FALSE(testARMExtension("generic",
502 ARM::ArchKind::ARMV8MMainline, "crc"));
503 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::IWMMXT, "crc"));
504 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::IWMMXT2, "crc"));
505 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::XSCALE, "crc"));
506 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV7S, "crypto"));
507 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV7K, "crypto"));
510 TEST(TargetParserTest, ARMFPUVersion) {
511 for (ARM::FPUKind FK = static_cast<ARM::FPUKind>(0);
512 FK <= ARM::FPUKind::FK_LAST;
513 FK = static_cast<ARM::FPUKind>(static_cast<unsigned>(FK) + 1))
514 if (FK == ARM::FK_LAST || ARM::getFPUName(FK) == "invalid" ||
515 ARM::getFPUName(FK) == "none" || ARM::getFPUName(FK) == "softvfp")
516 EXPECT_EQ(ARM::FPUVersion::NONE, ARM::getFPUVersion(FK));
517 else
518 EXPECT_NE(ARM::FPUVersion::NONE, ARM::getFPUVersion(FK));
521 TEST(TargetParserTest, ARMFPUNeonSupportLevel) {
522 for (ARM::FPUKind FK = static_cast<ARM::FPUKind>(0);
523 FK <= ARM::FPUKind::FK_LAST;
524 FK = static_cast<ARM::FPUKind>(static_cast<unsigned>(FK) + 1))
525 if (FK == ARM::FK_LAST ||
526 ARM::getFPUName(FK).find("neon") == std::string::npos)
527 EXPECT_EQ(ARM::NeonSupportLevel::None,
528 ARM::getFPUNeonSupportLevel(FK));
529 else
530 EXPECT_NE(ARM::NeonSupportLevel::None,
531 ARM::getFPUNeonSupportLevel(FK));
534 TEST(TargetParserTest, ARMFPURestriction) {
535 for (ARM::FPUKind FK = static_cast<ARM::FPUKind>(0);
536 FK <= ARM::FPUKind::FK_LAST;
537 FK = static_cast<ARM::FPUKind>(static_cast<unsigned>(FK) + 1)) {
538 if (FK == ARM::FK_LAST ||
539 (ARM::getFPUName(FK).find("d16") == std::string::npos &&
540 ARM::getFPUName(FK).find("vfpv3xd") == std::string::npos))
541 EXPECT_EQ(ARM::FPURestriction::None, ARM::getFPURestriction(FK));
542 else
543 EXPECT_NE(ARM::FPURestriction::None, ARM::getFPURestriction(FK));
547 TEST(TargetParserTest, ARMExtensionFeatures) {
548 std::vector<StringRef> Features;
549 unsigned Extensions = ARM::AEK_CRC | ARM::AEK_CRYPTO | ARM::AEK_DSP |
550 ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB | ARM::AEK_MP |
551 ARM::AEK_SEC | ARM::AEK_VIRT | ARM::AEK_RAS | ARM::AEK_FP16 |
552 ARM::AEK_FP16FML;
554 for (unsigned i = 0; i <= Extensions; i++)
555 EXPECT_TRUE(i == 0 ? !ARM::getExtensionFeatures(i, Features)
556 : ARM::getExtensionFeatures(i, Features));
559 TEST(TargetParserTest, ARMFPUFeatures) {
560 std::vector<StringRef> Features;
561 for (ARM::FPUKind FK = static_cast<ARM::FPUKind>(0);
562 FK <= ARM::FPUKind::FK_LAST;
563 FK = static_cast<ARM::FPUKind>(static_cast<unsigned>(FK) + 1))
564 EXPECT_TRUE((FK == ARM::FK_INVALID || FK >= ARM::FK_LAST)
565 ? !ARM::getFPUFeatures(FK, Features)
566 : ARM::getFPUFeatures(FK, Features));
569 TEST(TargetParserTest, ARMArchExtFeature) {
570 const char *ArchExt[][4] = {{"crc", "nocrc", "+crc", "-crc"},
571 {"crypto", "nocrypto", "+crypto", "-crypto"},
572 {"dsp", "nodsp", "+dsp", "-dsp"},
573 {"fp", "nofp", nullptr, nullptr},
574 {"idiv", "noidiv", nullptr, nullptr},
575 {"mp", "nomp", nullptr, nullptr},
576 {"simd", "nosimd", nullptr, nullptr},
577 {"sec", "nosec", nullptr, nullptr},
578 {"virt", "novirt", nullptr, nullptr},
579 {"fp16", "nofp16", "+fullfp16", "-fullfp16"},
580 {"fp16fml", "nofp16fml", "+fp16fml", "-fp16fml"},
581 {"ras", "noras", "+ras", "-ras"},
582 {"dotprod", "nodotprod", "+dotprod", "-dotprod"},
583 {"os", "noos", nullptr, nullptr},
584 {"iwmmxt", "noiwmmxt", nullptr, nullptr},
585 {"iwmmxt2", "noiwmmxt2", nullptr, nullptr},
586 {"maverick", "maverick", nullptr, nullptr},
587 {"xscale", "noxscale", nullptr, nullptr},
588 {"sb", "nosb", "+sb", "-sb"}};
590 for (unsigned i = 0; i < array_lengthof(ArchExt); i++) {
591 EXPECT_EQ(StringRef(ArchExt[i][2]), ARM::getArchExtFeature(ArchExt[i][0]));
592 EXPECT_EQ(StringRef(ArchExt[i][3]), ARM::getArchExtFeature(ArchExt[i][1]));
596 TEST(TargetParserTest, ARMparseHWDiv) {
597 const char *hwdiv[] = {"thumb", "arm", "arm,thumb", "thumb,arm"};
599 for (unsigned i = 0; i < array_lengthof(hwdiv); i++)
600 EXPECT_NE(ARM::AEK_INVALID, ARM::parseHWDiv((StringRef)hwdiv[i]));
603 TEST(TargetParserTest, ARMparseArchEndianAndISA) {
604 const char *Arch[] = {
605 "v2", "v2a", "v3", "v3m", "v4", "v4t", "v5", "v5t",
606 "v5e", "v5te", "v5tej", "v6", "v6j", "v6k", "v6hl", "v6t2",
607 "v6kz", "v6z", "v6zk", "v6-m", "v6m", "v6sm", "v6s-m", "v7-a",
608 "v7", "v7a", "v7ve", "v7hl", "v7l", "v7-r", "v7r", "v7-m",
609 "v7m", "v7k", "v7s", "v7e-m", "v7em", "v8-a", "v8", "v8a",
610 "v8l", "v8.1-a", "v8.1a", "v8.2-a", "v8.2a", "v8.3-a", "v8.3a", "v8.4-a",
611 "v8.4a", "v8.5-a","v8.5a", "v8-r"
614 for (unsigned i = 0; i < array_lengthof(Arch); i++) {
615 std::string arm_1 = "armeb" + (std::string)(Arch[i]);
616 std::string arm_2 = "arm" + (std::string)(Arch[i]) + "eb";
617 std::string arm_3 = "arm" + (std::string)(Arch[i]);
618 std::string thumb_1 = "thumbeb" + (std::string)(Arch[i]);
619 std::string thumb_2 = "thumb" + (std::string)(Arch[i]) + "eb";
620 std::string thumb_3 = "thumb" + (std::string)(Arch[i]);
622 EXPECT_EQ(ARM::EndianKind::BIG, ARM::parseArchEndian(arm_1));
623 EXPECT_EQ(ARM::EndianKind::BIG, ARM::parseArchEndian(arm_2));
624 EXPECT_EQ(ARM::EndianKind::LITTLE, ARM::parseArchEndian(arm_3));
626 EXPECT_EQ(ARM::ISAKind::ARM, ARM::parseArchISA(arm_1));
627 EXPECT_EQ(ARM::ISAKind::ARM, ARM::parseArchISA(arm_2));
628 EXPECT_EQ(ARM::ISAKind::ARM, ARM::parseArchISA(arm_3));
629 if (i >= 4) {
630 EXPECT_EQ(ARM::EndianKind::BIG, ARM::parseArchEndian(thumb_1));
631 EXPECT_EQ(ARM::EndianKind::BIG, ARM::parseArchEndian(thumb_2));
632 EXPECT_EQ(ARM::EndianKind::LITTLE, ARM::parseArchEndian(thumb_3));
634 EXPECT_EQ(ARM::ISAKind::THUMB, ARM::parseArchISA(thumb_1));
635 EXPECT_EQ(ARM::ISAKind::THUMB, ARM::parseArchISA(thumb_2));
636 EXPECT_EQ(ARM::ISAKind::THUMB, ARM::parseArchISA(thumb_3));
640 EXPECT_EQ(ARM::EndianKind::LITTLE, ARM::parseArchEndian("aarch64"));
641 EXPECT_EQ(ARM::EndianKind::BIG, ARM::parseArchEndian("aarch64_be"));
643 EXPECT_EQ(ARM::ISAKind::AARCH64, ARM::parseArchISA("aarch64"));
644 EXPECT_EQ(ARM::ISAKind::AARCH64, ARM::parseArchISA("aarch64_be"));
645 EXPECT_EQ(ARM::ISAKind::AARCH64, ARM::parseArchISA("arm64"));
646 EXPECT_EQ(ARM::ISAKind::AARCH64, ARM::parseArchISA("arm64_be"));
649 TEST(TargetParserTest, ARMparseArchProfile) {
650 for (unsigned i = 0; i < array_lengthof(ARMArch); i++) {
651 switch (ARM::parseArch(ARMArch[i])) {
652 case ARM::ArchKind::ARMV6M:
653 case ARM::ArchKind::ARMV7M:
654 case ARM::ArchKind::ARMV7EM:
655 case ARM::ArchKind::ARMV8MMainline:
656 case ARM::ArchKind::ARMV8MBaseline:
657 EXPECT_EQ(ARM::ProfileKind::M, ARM::parseArchProfile(ARMArch[i]));
658 break;
659 case ARM::ArchKind::ARMV7R:
660 case ARM::ArchKind::ARMV8R:
661 EXPECT_EQ(ARM::ProfileKind::R, ARM::parseArchProfile(ARMArch[i]));
662 break;
663 case ARM::ArchKind::ARMV7A:
664 case ARM::ArchKind::ARMV7VE:
665 case ARM::ArchKind::ARMV7K:
666 case ARM::ArchKind::ARMV8A:
667 case ARM::ArchKind::ARMV8_1A:
668 case ARM::ArchKind::ARMV8_2A:
669 case ARM::ArchKind::ARMV8_3A:
670 case ARM::ArchKind::ARMV8_4A:
671 case ARM::ArchKind::ARMV8_5A:
672 EXPECT_EQ(ARM::ProfileKind::A, ARM::parseArchProfile(ARMArch[i]));
673 break;
674 default:
675 EXPECT_EQ(ARM::ProfileKind::INVALID, ARM::parseArchProfile(ARMArch[i]));
676 break;
681 TEST(TargetParserTest, ARMparseArchVersion) {
682 for (unsigned i = 0; i < array_lengthof(ARMArch); i++)
683 if (((std::string)ARMArch[i]).substr(0, 4) == "armv")
684 EXPECT_EQ((ARMArch[i][4] - 48u), ARM::parseArchVersion(ARMArch[i]));
685 else
686 EXPECT_EQ(5u, ARM::parseArchVersion(ARMArch[i]));
689 bool testAArch64CPU(StringRef CPUName, StringRef ExpectedArch,
690 StringRef ExpectedFPU, unsigned ExpectedFlags,
691 StringRef CPUAttr) {
692 AArch64::ArchKind AK = AArch64::parseCPUArch(CPUName);
693 bool pass = AArch64::getArchName(AK).equals(ExpectedArch);
695 unsigned ExtKind = AArch64::getDefaultExtensions(CPUName, AK);
696 if (ExtKind > 1 && (ExtKind & AArch64::AEK_NONE))
697 pass &= ((ExtKind ^ AArch64::AEK_NONE) == ExpectedFlags);
698 else
699 pass &= (ExtKind == ExpectedFlags);
701 pass &= AArch64::getCPUAttr(AK).equals(CPUAttr);
703 return pass;
706 TEST(TargetParserTest, testAArch64CPU) {
707 EXPECT_TRUE(testAArch64CPU(
708 "invalid", "invalid", "invalid",
709 AArch64::AEK_NONE, ""));
710 EXPECT_TRUE(testAArch64CPU(
711 "generic", "invalid", "none",
712 AArch64::AEK_NONE, ""));
714 EXPECT_TRUE(testAArch64CPU(
715 "cortex-a35", "armv8-a", "crypto-neon-fp-armv8",
716 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
717 AArch64::AEK_SIMD, "8-A"));
718 EXPECT_TRUE(testAArch64CPU(
719 "cortex-a53", "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 "cortex-a55", "armv8.2-a", "crypto-neon-fp-armv8",
724 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
725 AArch64::AEK_SIMD | AArch64::AEK_RAS | AArch64::AEK_LSE |
726 AArch64::AEK_RDM | AArch64::AEK_FP16 | AArch64::AEK_DOTPROD |
727 AArch64::AEK_RCPC, "8.2-A"));
728 EXPECT_TRUE(testAArch64CPU(
729 "cortex-a57", "armv8-a", "crypto-neon-fp-armv8",
730 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
731 AArch64::AEK_SIMD, "8-A"));
732 EXPECT_TRUE(testAArch64CPU(
733 "cortex-a72", "armv8-a", "crypto-neon-fp-armv8",
734 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
735 AArch64::AEK_SIMD, "8-A"));
736 EXPECT_TRUE(testAArch64CPU(
737 "cortex-a73", "armv8-a", "crypto-neon-fp-armv8",
738 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
739 AArch64::AEK_SIMD, "8-A"));
740 EXPECT_TRUE(testAArch64CPU(
741 "cortex-a75", "armv8.2-a", "crypto-neon-fp-armv8",
742 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
743 AArch64::AEK_SIMD | AArch64::AEK_RAS | AArch64::AEK_LSE |
744 AArch64::AEK_RDM | AArch64::AEK_FP16 | AArch64::AEK_DOTPROD |
745 AArch64::AEK_RCPC, "8.2-A"));
746 EXPECT_TRUE(testAArch64CPU(
747 "cyclone", "armv8-a", "crypto-neon-fp-armv8",
748 AArch64::AEK_CRYPTO | AArch64::AEK_FP | AArch64::AEK_SIMD, "8-A"));
749 EXPECT_TRUE(testAArch64CPU(
750 "exynos-m1", "armv8-a", "crypto-neon-fp-armv8",
751 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
752 AArch64::AEK_SIMD, "8-A"));
753 EXPECT_TRUE(testAArch64CPU(
754 "exynos-m2", "armv8-a", "crypto-neon-fp-armv8",
755 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
756 AArch64::AEK_SIMD, "8-A"));
757 EXPECT_TRUE(testAArch64CPU(
758 "exynos-m3", "armv8-a", "crypto-neon-fp-armv8",
759 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
760 AArch64::AEK_SIMD, "8-A"));
761 EXPECT_TRUE(testAArch64CPU(
762 "exynos-m4", "armv8.2-a", "crypto-neon-fp-armv8",
763 AArch64::AEK_CRC | AArch64::AEK_CRYPTO |
764 AArch64::AEK_DOTPROD | AArch64::AEK_FP | AArch64::AEK_FP16 |
765 AArch64::AEK_LSE | AArch64::AEK_RAS | AArch64::AEK_RDM |
766 AArch64::AEK_SIMD, "8.2-A"));
767 EXPECT_TRUE(testAArch64CPU(
768 "falkor", "armv8-a", "crypto-neon-fp-armv8",
769 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
770 AArch64::AEK_SIMD | AArch64::AEK_RDM, "8-A"));
771 EXPECT_TRUE(testAArch64CPU(
772 "kryo", "armv8-a", "crypto-neon-fp-armv8",
773 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
774 AArch64::AEK_SIMD, "8-A"));
775 EXPECT_TRUE(testAArch64CPU(
776 "thunderx2t99", "armv8.1-a", "crypto-neon-fp-armv8",
777 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_LSE |
778 AArch64::AEK_RDM | AArch64::AEK_FP | AArch64::AEK_SIMD, "8.1-A"));
779 EXPECT_TRUE(testAArch64CPU(
780 "thunderx", "armv8-a", "crypto-neon-fp-armv8",
781 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_SIMD |
782 AArch64::AEK_FP | AArch64::AEK_PROFILE,
783 "8-A"));
784 EXPECT_TRUE(testAArch64CPU(
785 "thunderxt81", "armv8-a", "crypto-neon-fp-armv8",
786 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_SIMD |
787 AArch64::AEK_FP | AArch64::AEK_PROFILE,
788 "8-A"));
789 EXPECT_TRUE(testAArch64CPU(
790 "thunderxt83", "armv8-a", "crypto-neon-fp-armv8",
791 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_SIMD |
792 AArch64::AEK_FP | AArch64::AEK_PROFILE,
793 "8-A"));
794 EXPECT_TRUE(testAArch64CPU(
795 "thunderxt88", "armv8-a", "crypto-neon-fp-armv8",
796 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_SIMD |
797 AArch64::AEK_FP | AArch64::AEK_PROFILE,
798 "8-A"));
799 EXPECT_TRUE(testAArch64CPU(
800 "tsv110", "armv8.2-a", "crypto-neon-fp-armv8",
801 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
802 AArch64::AEK_SIMD | AArch64::AEK_RAS | AArch64::AEK_LSE |
803 AArch64::AEK_RDM | AArch64::AEK_PROFILE | AArch64::AEK_FP16 |
804 AArch64::AEK_FP16FML | AArch64::AEK_DOTPROD,
805 "8.2-A"));
808 static constexpr unsigned NumAArch64CPUArchs = 21;
810 TEST(TargetParserTest, testAArch64CPUArchList) {
811 SmallVector<StringRef, NumAArch64CPUArchs> List;
812 AArch64::fillValidCPUArchList(List);
814 // No list exists for these in this test suite, so ensure all are
815 // valid, and match the expected 'magic' count.
816 EXPECT_EQ(List.size(), NumAArch64CPUArchs);
817 for(StringRef CPU : List) {
818 EXPECT_NE(AArch64::parseCPUArch(CPU), AArch64::ArchKind::INVALID);
822 bool testAArch64Arch(StringRef Arch, StringRef DefaultCPU, StringRef SubArch,
823 unsigned ArchAttr) {
824 AArch64::ArchKind AK = AArch64::parseArch(Arch);
825 return (AK != AArch64::ArchKind::INVALID) &
826 AArch64::getDefaultCPU(Arch).equals(DefaultCPU) &
827 AArch64::getSubArch(AK).equals(SubArch) &
828 (AArch64::getArchAttr(AK) == ArchAttr);
831 TEST(TargetParserTest, testAArch64Arch) {
832 EXPECT_TRUE(testAArch64Arch("armv8-a", "cortex-a53", "v8",
833 ARMBuildAttrs::CPUArch::v8_A));
834 EXPECT_TRUE(testAArch64Arch("armv8.1-a", "generic", "v8.1a",
835 ARMBuildAttrs::CPUArch::v8_A));
836 EXPECT_TRUE(testAArch64Arch("armv8.2-a", "generic", "v8.2a",
837 ARMBuildAttrs::CPUArch::v8_A));
838 EXPECT_TRUE(testAArch64Arch("armv8.3-a", "generic", "v8.3a",
839 ARMBuildAttrs::CPUArch::v8_A));
840 EXPECT_TRUE(testAArch64Arch("armv8.4-a", "generic", "v8.4a",
841 ARMBuildAttrs::CPUArch::v8_A));
842 EXPECT_TRUE(testAArch64Arch("armv8.5-a", "generic", "v8.5a",
843 ARMBuildAttrs::CPUArch::v8_A));
846 bool testAArch64Extension(StringRef CPUName, AArch64::ArchKind AK,
847 StringRef ArchExt) {
848 return AArch64::getDefaultExtensions(CPUName, AK) &
849 AArch64::parseArchExt(ArchExt);
852 TEST(TargetParserTest, testAArch64Extension) {
853 EXPECT_FALSE(testAArch64Extension("cortex-a35",
854 AArch64::ArchKind::INVALID, "ras"));
855 EXPECT_FALSE(testAArch64Extension("cortex-a53",
856 AArch64::ArchKind::INVALID, "ras"));
857 EXPECT_TRUE(testAArch64Extension("cortex-a55",
858 AArch64::ArchKind::INVALID, "ras"));
859 EXPECT_FALSE(testAArch64Extension("cortex-a57",
860 AArch64::ArchKind::INVALID, "ras"));
861 EXPECT_FALSE(testAArch64Extension("cortex-a72",
862 AArch64::ArchKind::INVALID, "ras"));
863 EXPECT_FALSE(testAArch64Extension("cortex-a73",
864 AArch64::ArchKind::INVALID, "ras"));
865 EXPECT_TRUE(testAArch64Extension("cortex-a75",
866 AArch64::ArchKind::INVALID, "ras"));
867 EXPECT_FALSE(testAArch64Extension("cyclone",
868 AArch64::ArchKind::INVALID, "ras"));
869 EXPECT_FALSE(testAArch64Extension("exynos-m1",
870 AArch64::ArchKind::INVALID, "ras"));
871 EXPECT_FALSE(testAArch64Extension("exynos-m2",
872 AArch64::ArchKind::INVALID, "ras"));
873 EXPECT_FALSE(testAArch64Extension("exynos-m3",
874 AArch64::ArchKind::INVALID, "ras"));
875 EXPECT_TRUE(testAArch64Extension("exynos-m4",
876 AArch64::ArchKind::INVALID, "lse"));
877 EXPECT_TRUE(testAArch64Extension("exynos-m4",
878 AArch64::ArchKind::INVALID, "rdm"));
879 EXPECT_TRUE(testAArch64Extension("exynos-m4",
880 AArch64::ArchKind::INVALID, "ras"));
881 EXPECT_FALSE(testAArch64Extension("exynos-m4",
882 AArch64::ArchKind::INVALID, "fullfp16"));
883 EXPECT_TRUE(testAArch64Extension("exynos-m4",
884 AArch64::ArchKind::INVALID, "dotprod"));
885 EXPECT_TRUE(testAArch64Extension("falkor",
886 AArch64::ArchKind::INVALID, "rdm"));
887 EXPECT_FALSE(testAArch64Extension("kryo",
888 AArch64::ArchKind::INVALID, "ras"));
889 EXPECT_TRUE(testAArch64Extension("saphira",
890 AArch64::ArchKind::INVALID, "crc"));
891 EXPECT_TRUE(testAArch64Extension("saphira",
892 AArch64::ArchKind::INVALID, "lse"));
893 EXPECT_TRUE(testAArch64Extension("saphira",
894 AArch64::ArchKind::INVALID, "rdm"));
895 EXPECT_TRUE(testAArch64Extension("saphira",
896 AArch64::ArchKind::INVALID, "ras"));
897 EXPECT_TRUE(testAArch64Extension("saphira",
898 AArch64::ArchKind::INVALID, "rcpc"));
899 EXPECT_TRUE(testAArch64Extension("saphira",
900 AArch64::ArchKind::INVALID, "profile"));
901 EXPECT_FALSE(testAArch64Extension("saphira",
902 AArch64::ArchKind::INVALID, "fp16"));
903 EXPECT_TRUE(testAArch64Extension("cortex-a55",
904 AArch64::ArchKind::INVALID, "fp16"));
905 EXPECT_FALSE(testAArch64Extension("cortex-a55",
906 AArch64::ArchKind::INVALID, "fp16fml"));
907 EXPECT_TRUE(testAArch64Extension("cortex-a55",
908 AArch64::ArchKind::INVALID, "dotprod"));
909 EXPECT_TRUE(testAArch64Extension("cortex-a75",
910 AArch64::ArchKind::INVALID, "fp16"));
911 EXPECT_FALSE(testAArch64Extension("cortex-a75",
912 AArch64::ArchKind::INVALID, "fp16fml"));
913 EXPECT_TRUE(testAArch64Extension("cortex-a75",
914 AArch64::ArchKind::INVALID, "dotprod"));
915 EXPECT_FALSE(testAArch64Extension("thunderx2t99",
916 AArch64::ArchKind::INVALID, "ras"));
917 EXPECT_FALSE(testAArch64Extension("thunderx",
918 AArch64::ArchKind::INVALID, "lse"));
919 EXPECT_FALSE(testAArch64Extension("thunderxt81",
920 AArch64::ArchKind::INVALID, "lse"));
921 EXPECT_FALSE(testAArch64Extension("thunderxt83",
922 AArch64::ArchKind::INVALID, "lse"));
923 EXPECT_FALSE(testAArch64Extension("thunderxt88",
924 AArch64::ArchKind::INVALID, "lse"));
925 EXPECT_TRUE(testAArch64Extension("tsv110",
926 AArch64::ArchKind::INVALID, "crypto"));
927 EXPECT_FALSE(testAArch64Extension("tsv110",
928 AArch64::ArchKind::INVALID, "sha3"));
929 EXPECT_FALSE(testAArch64Extension("tsv110",
930 AArch64::ArchKind::INVALID, "sm4"));
931 EXPECT_TRUE(testAArch64Extension("tsv110",
932 AArch64::ArchKind::INVALID, "ras"));
933 EXPECT_TRUE(testAArch64Extension("tsv110",
934 AArch64::ArchKind::INVALID, "profile"));
935 EXPECT_TRUE(testAArch64Extension("tsv110",
936 AArch64::ArchKind::INVALID, "fp16"));
937 EXPECT_TRUE(testAArch64Extension("tsv110",
938 AArch64::ArchKind::INVALID, "fp16fml"));
939 EXPECT_TRUE(testAArch64Extension("tsv110",
940 AArch64::ArchKind::INVALID, "dotprod"));
942 EXPECT_FALSE(testAArch64Extension(
943 "generic", AArch64::ArchKind::ARMV8A, "ras"));
944 EXPECT_FALSE(testAArch64Extension(
945 "generic", AArch64::ArchKind::ARMV8_1A, "ras"));
946 EXPECT_FALSE(testAArch64Extension(
947 "generic", AArch64::ArchKind::ARMV8_2A, "profile"));
948 EXPECT_FALSE(testAArch64Extension(
949 "generic", AArch64::ArchKind::ARMV8_2A, "fp16"));
950 EXPECT_FALSE(testAArch64Extension(
951 "generic", AArch64::ArchKind::ARMV8_2A, "fp16fml"));
952 EXPECT_FALSE(testAArch64Extension(
953 "generic", AArch64::ArchKind::ARMV8_3A, "fp16"));
954 EXPECT_FALSE(testAArch64Extension(
955 "generic", AArch64::ArchKind::ARMV8_3A, "fp16fml"));
956 EXPECT_FALSE(testAArch64Extension(
957 "generic", AArch64::ArchKind::ARMV8_4A, "fp16"));
958 EXPECT_FALSE(testAArch64Extension(
959 "generic", AArch64::ArchKind::ARMV8_4A, "fp16fml"));
962 TEST(TargetParserTest, AArch64ExtensionFeatures) {
963 std::vector<StringRef> Features;
964 unsigned Extensions = AArch64::AEK_CRC | AArch64::AEK_CRYPTO |
965 AArch64::AEK_FP | AArch64::AEK_SIMD |
966 AArch64::AEK_FP16 | AArch64::AEK_PROFILE |
967 AArch64::AEK_RAS | AArch64::AEK_LSE |
968 AArch64::AEK_RDM | AArch64::AEK_SVE |
969 AArch64::AEK_DOTPROD | AArch64::AEK_RCPC |
970 AArch64::AEK_FP16FML;
972 for (unsigned i = 0; i <= Extensions; i++)
973 EXPECT_TRUE(i == 0 ? !AArch64::getExtensionFeatures(i, Features)
974 : AArch64::getExtensionFeatures(i, Features));
977 TEST(TargetParserTest, AArch64ArchFeatures) {
978 std::vector<StringRef> Features;
980 for (auto AK : AArch64::ArchKinds)
981 EXPECT_TRUE((AK == AArch64::ArchKind::INVALID)
982 ? !AArch64::getArchFeatures(AK, Features)
983 : AArch64::getArchFeatures(AK, Features));
986 TEST(TargetParserTest, AArch64ArchExtFeature) {
987 const char *ArchExt[][4] = {{"crc", "nocrc", "+crc", "-crc"},
988 {"crypto", "nocrypto", "+crypto", "-crypto"},
989 {"fp", "nofp", "+fp-armv8", "-fp-armv8"},
990 {"simd", "nosimd", "+neon", "-neon"},
991 {"fp16", "nofp16", "+fullfp16", "-fullfp16"},
992 {"fp16fml", "nofp16fml", "+fp16fml", "-fp16fml"},
993 {"profile", "noprofile", "+spe", "-spe"},
994 {"ras", "noras", "+ras", "-ras"},
995 {"lse", "nolse", "+lse", "-lse"},
996 {"rdm", "nordm", "+rdm", "-rdm"},
997 {"sve", "nosve", "+sve", "-sve"},
998 {"dotprod", "nodotprod", "+dotprod", "-dotprod"},
999 {"rcpc", "norcpc", "+rcpc", "-rcpc" },
1000 {"rng", "norng", "+rand", "-rand"},
1001 {"memtag", "nomemtag", "+mte", "-mte"},
1002 {"ssbs", "nossbs", "+ssbs", "-ssbs"},
1003 {"sb", "nosb", "+sb", "-sb"},
1004 {"predres", "nopredres", "+predres", "-predres"}
1007 for (unsigned i = 0; i < array_lengthof(ArchExt); i++) {
1008 EXPECT_EQ(StringRef(ArchExt[i][2]),
1009 AArch64::getArchExtFeature(ArchExt[i][0]));
1010 EXPECT_EQ(StringRef(ArchExt[i][3]),
1011 AArch64::getArchExtFeature(ArchExt[i][1]));