[InstCombine] Remove insertRangeTest code that handles the equality case.
[llvm-complete.git] / unittests / Support / TargetParserTest.cpp
blob34c7a8a4fd1c8d8728d9d91798dafcff252b9884
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",
31 "armv8.1-m.main",
34 bool testARMCPU(StringRef CPUName, StringRef ExpectedArch,
35 StringRef ExpectedFPU, unsigned ExpectedFlags,
36 StringRef CPUAttr) {
37 ARM::ArchKind AK = ARM::parseCPUArch(CPUName);
38 bool pass = ARM::getArchName(AK).equals(ExpectedArch);
39 unsigned FPUKind = ARM::getDefaultFPU(CPUName, AK);
40 pass &= ARM::getFPUName(FPUKind).equals(ExpectedFPU);
42 unsigned ExtKind = ARM::getDefaultExtensions(CPUName, AK);
43 if (ExtKind > 1 && (ExtKind & ARM::AEK_NONE))
44 pass &= ((ExtKind ^ ARM::AEK_NONE) == ExpectedFlags);
45 else
46 pass &= (ExtKind == ExpectedFlags);
48 pass &= ARM::getCPUAttr(AK).equals(CPUAttr);
50 return pass;
53 TEST(TargetParserTest, testARMCPU) {
54 EXPECT_TRUE(testARMCPU("invalid", "invalid", "invalid",
55 ARM::AEK_NONE, ""));
56 EXPECT_TRUE(testARMCPU("generic", "invalid", "none",
57 ARM::AEK_NONE, ""));
59 EXPECT_TRUE(testARMCPU("arm2", "armv2", "none",
60 ARM::AEK_NONE, "2"));
61 EXPECT_TRUE(testARMCPU("arm3", "armv2a", "none",
62 ARM::AEK_NONE, "2A"));
63 EXPECT_TRUE(testARMCPU("arm6", "armv3", "none",
64 ARM::AEK_NONE, "3"));
65 EXPECT_TRUE(testARMCPU("arm7m", "armv3m", "none",
66 ARM::AEK_NONE, "3M"));
67 EXPECT_TRUE(testARMCPU("arm8", "armv4", "none",
68 ARM::AEK_NONE, "4"));
69 EXPECT_TRUE(testARMCPU("arm810", "armv4", "none",
70 ARM::AEK_NONE, "4"));
71 EXPECT_TRUE(testARMCPU("strongarm", "armv4", "none",
72 ARM::AEK_NONE, "4"));
73 EXPECT_TRUE(testARMCPU("strongarm110", "armv4", "none",
74 ARM::AEK_NONE, "4"));
75 EXPECT_TRUE(testARMCPU("strongarm1100", "armv4", "none",
76 ARM::AEK_NONE, "4"));
77 EXPECT_TRUE(testARMCPU("strongarm1110", "armv4", "none",
78 ARM::AEK_NONE, "4"));
79 EXPECT_TRUE(testARMCPU("arm7tdmi", "armv4t", "none",
80 ARM::AEK_NONE, "4T"));
81 EXPECT_TRUE(testARMCPU("arm7tdmi-s", "armv4t", "none",
82 ARM::AEK_NONE, "4T"));
83 EXPECT_TRUE(testARMCPU("arm710t", "armv4t", "none",
84 ARM::AEK_NONE, "4T"));
85 EXPECT_TRUE(testARMCPU("arm720t", "armv4t", "none",
86 ARM::AEK_NONE, "4T"));
87 EXPECT_TRUE(testARMCPU("arm9", "armv4t", "none",
88 ARM::AEK_NONE, "4T"));
89 EXPECT_TRUE(testARMCPU("arm9tdmi", "armv4t", "none",
90 ARM::AEK_NONE, "4T"));
91 EXPECT_TRUE(testARMCPU("arm920", "armv4t", "none",
92 ARM::AEK_NONE, "4T"));
93 EXPECT_TRUE(testARMCPU("arm920t", "armv4t", "none",
94 ARM::AEK_NONE, "4T"));
95 EXPECT_TRUE(testARMCPU("arm922t", "armv4t", "none",
96 ARM::AEK_NONE, "4T"));
97 EXPECT_TRUE(testARMCPU("arm9312", "armv4t", "none",
98 ARM::AEK_NONE, "4T"));
99 EXPECT_TRUE(testARMCPU("arm940t", "armv4t", "none",
100 ARM::AEK_NONE, "4T"));
101 EXPECT_TRUE(testARMCPU("ep9312", "armv4t", "none",
102 ARM::AEK_NONE, "4T"));
103 EXPECT_TRUE(testARMCPU("arm10tdmi", "armv5t", "none",
104 ARM::AEK_NONE, "5T"));
105 EXPECT_TRUE(testARMCPU("arm1020t", "armv5t", "none",
106 ARM::AEK_NONE, "5T"));
107 EXPECT_TRUE(testARMCPU("arm9e", "armv5te", "none",
108 ARM::AEK_DSP, "5TE"));
109 EXPECT_TRUE(testARMCPU("arm946e-s", "armv5te", "none",
110 ARM::AEK_DSP, "5TE"));
111 EXPECT_TRUE(testARMCPU("arm966e-s", "armv5te", "none",
112 ARM::AEK_DSP, "5TE"));
113 EXPECT_TRUE(testARMCPU("arm968e-s", "armv5te", "none",
114 ARM::AEK_DSP, "5TE"));
115 EXPECT_TRUE(testARMCPU("arm10e", "armv5te", "none",
116 ARM::AEK_DSP, "5TE"));
117 EXPECT_TRUE(testARMCPU("arm1020e", "armv5te", "none",
118 ARM::AEK_DSP, "5TE"));
119 EXPECT_TRUE(testARMCPU("arm1022e", "armv5te", "none",
120 ARM::AEK_DSP, "5TE"));
121 EXPECT_TRUE(testARMCPU("arm926ej-s", "armv5tej", "none",
122 ARM::AEK_DSP, "5TEJ"));
123 EXPECT_TRUE(testARMCPU("arm1136j-s", "armv6", "none",
124 ARM::AEK_DSP, "6"));
125 EXPECT_TRUE(testARMCPU("arm1136jf-s", "armv6", "vfpv2",
126 ARM::AEK_DSP, "6"));
127 EXPECT_TRUE(testARMCPU("arm1136jz-s", "armv6", "none",
128 ARM::AEK_DSP, "6"));
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,
154 "7-A"));
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 |
162 ARM::AEK_DSP,
163 "7-A"));
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 |
167 ARM::AEK_DSP,
168 "7-A"));
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 |
172 ARM::AEK_DSP,
173 "7-A"));
174 EXPECT_TRUE(testARMCPU("krait", "armv7-a", "neon-vfpv4",
175 ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
176 "7-A"));
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 |
183 ARM::AEK_DSP,
184 "7-R"));
185 EXPECT_TRUE(testARMCPU("cortex-r7", "armv7-r", "vfpv3-d16-fp16",
186 ARM::AEK_MP | ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
187 ARM::AEK_DSP,
188 "7-R"));
189 EXPECT_TRUE(testARMCPU("cortex-r8", "armv7-r", "vfpv3-d16-fp16",
190 ARM::AEK_MP | ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
191 ARM::AEK_DSP,
192 "7-R"));
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 |
196 ARM::AEK_DSP,
197 "8-R"));
198 EXPECT_TRUE(
199 testARMCPU("sc300", "armv7-m", "none", ARM::AEK_HWDIVTHUMB, "7-M"));
200 EXPECT_TRUE(
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,
210 "8-A"));
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,
215 "8-A"));
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,
220 "8-A"));
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,
226 "8.2-A"));
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,
231 "8-A"));
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,
236 "8-A"));
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,
241 "8-A"));
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,
247 "8.2-A"));
248 EXPECT_TRUE(testARMCPU("cortex-a76", "armv8.2-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 | ARM::AEK_FP16 |
252 ARM::AEK_RAS | ARM::AEK_DOTPROD,
253 "8.2-A"));
254 EXPECT_TRUE(testARMCPU("cortex-a76ae", "armv8.2-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 | ARM::AEK_FP16 |
258 ARM::AEK_RAS | ARM::AEK_DOTPROD,
259 "8.2-A"));
260 EXPECT_TRUE(testARMCPU("cyclone", "armv8-a", "crypto-neon-fp-armv8",
261 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
262 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
263 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
264 "8-A"));
265 EXPECT_TRUE(testARMCPU("exynos-m1", "armv8-a", "crypto-neon-fp-armv8",
266 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
267 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
268 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
269 "8-A"));
270 EXPECT_TRUE(testARMCPU("exynos-m2", "armv8-a", "crypto-neon-fp-armv8",
271 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
272 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
273 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
274 "8-A"));
275 EXPECT_TRUE(testARMCPU("exynos-m3", "armv8-a", "crypto-neon-fp-armv8",
276 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
277 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
278 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
279 "8-A"));
280 EXPECT_TRUE(testARMCPU("exynos-m4", "armv8.2-a", "crypto-neon-fp-armv8",
281 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
282 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
283 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP | ARM::AEK_DOTPROD |
284 ARM::AEK_FP16 | ARM::AEK_RAS,
285 "8.2-A"));
286 EXPECT_TRUE(testARMCPU("exynos-m5", "armv8.2-a", "crypto-neon-fp-armv8",
287 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
288 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
289 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP | ARM::AEK_DOTPROD |
290 ARM::AEK_FP16 | ARM::AEK_RAS,
291 "8.2-A"));
292 EXPECT_TRUE(testARMCPU("cortex-m23", "armv8-m.base", "none",
293 ARM::AEK_HWDIVTHUMB, "8-M.Baseline"));
294 EXPECT_TRUE(testARMCPU("cortex-m33", "armv8-m.main", "fpv5-sp-d16",
295 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP, "8-M.Mainline"));
296 EXPECT_TRUE(testARMCPU("cortex-m35p", "armv8-m.main", "fpv5-sp-d16",
297 ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP, "8-M.Mainline"));
298 EXPECT_TRUE(testARMCPU("iwmmxt", "iwmmxt", "none",
299 ARM::AEK_NONE, "iwmmxt"));
300 EXPECT_TRUE(testARMCPU("xscale", "xscale", "none",
301 ARM::AEK_NONE, "xscale"));
302 EXPECT_TRUE(testARMCPU("swift", "armv7s", "neon-vfpv4",
303 ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
304 "7-S"));
307 static constexpr unsigned NumARMCPUArchs = 86;
309 TEST(TargetParserTest, testARMCPUArchList) {
310 SmallVector<StringRef, NumARMCPUArchs> List;
311 ARM::fillValidCPUArchList(List);
313 // No list exists for these in this test suite, so ensure all are
314 // valid, and match the expected 'magic' count.
315 EXPECT_EQ(List.size(), NumARMCPUArchs);
316 for(StringRef CPU : List) {
317 EXPECT_NE(ARM::parseCPUArch(CPU), ARM::ArchKind::INVALID);
321 TEST(TargetParserTest, testInvalidARMArch) {
322 auto InvalidArchStrings = {"armv", "armv99", "noarm"};
323 for (const char* InvalidArch : InvalidArchStrings)
324 EXPECT_EQ(ARM::parseArch(InvalidArch), ARM::ArchKind::INVALID);
327 bool testARMArch(StringRef Arch, StringRef DefaultCPU, StringRef SubArch,
328 unsigned ArchAttr) {
329 ARM::ArchKind AK = ARM::parseArch(Arch);
330 return (AK!= ARM::ArchKind::INVALID) &
331 ARM::getDefaultCPU(Arch).equals(DefaultCPU) &
332 ARM::getSubArch(AK).equals(SubArch) &
333 (ARM::getArchAttr(AK) == ArchAttr);
336 TEST(TargetParserTest, testARMArch) {
337 EXPECT_TRUE(
338 testARMArch("armv2", "arm2", "v2",
339 ARMBuildAttrs::CPUArch::Pre_v4));
340 EXPECT_TRUE(
341 testARMArch("armv2a", "arm3", "v2a",
342 ARMBuildAttrs::CPUArch::Pre_v4));
343 EXPECT_TRUE(
344 testARMArch("armv3", "arm6", "v3",
345 ARMBuildAttrs::CPUArch::Pre_v4));
346 EXPECT_TRUE(
347 testARMArch("armv3m", "arm7m", "v3m",
348 ARMBuildAttrs::CPUArch::Pre_v4));
349 EXPECT_TRUE(
350 testARMArch("armv4", "strongarm", "v4",
351 ARMBuildAttrs::CPUArch::v4));
352 EXPECT_TRUE(
353 testARMArch("armv4t", "arm7tdmi", "v4t",
354 ARMBuildAttrs::CPUArch::v4T));
355 EXPECT_TRUE(
356 testARMArch("armv5t", "arm10tdmi", "v5",
357 ARMBuildAttrs::CPUArch::v5T));
358 EXPECT_TRUE(
359 testARMArch("armv5te", "arm1022e", "v5e",
360 ARMBuildAttrs::CPUArch::v5TE));
361 EXPECT_TRUE(
362 testARMArch("armv5tej", "arm926ej-s", "v5e",
363 ARMBuildAttrs::CPUArch::v5TEJ));
364 EXPECT_TRUE(
365 testARMArch("armv6", "arm1136jf-s", "v6",
366 ARMBuildAttrs::CPUArch::v6));
367 EXPECT_TRUE(
368 testARMArch("armv6k", "mpcore", "v6k",
369 ARMBuildAttrs::CPUArch::v6K));
370 EXPECT_TRUE(
371 testARMArch("armv6t2", "arm1156t2-s", "v6t2",
372 ARMBuildAttrs::CPUArch::v6T2));
373 EXPECT_TRUE(
374 testARMArch("armv6kz", "arm1176jzf-s", "v6kz",
375 ARMBuildAttrs::CPUArch::v6KZ));
376 EXPECT_TRUE(
377 testARMArch("armv6-m", "cortex-m0", "v6m",
378 ARMBuildAttrs::CPUArch::v6_M));
379 EXPECT_TRUE(
380 testARMArch("armv7-a", "generic", "v7",
381 ARMBuildAttrs::CPUArch::v7));
382 EXPECT_TRUE(
383 testARMArch("armv7ve", "generic", "v7ve",
384 ARMBuildAttrs::CPUArch::v7));
385 EXPECT_TRUE(
386 testARMArch("armv7-r", "cortex-r4", "v7r",
387 ARMBuildAttrs::CPUArch::v7));
388 EXPECT_TRUE(
389 testARMArch("armv7-m", "cortex-m3", "v7m",
390 ARMBuildAttrs::CPUArch::v7));
391 EXPECT_TRUE(
392 testARMArch("armv7e-m", "cortex-m4", "v7em",
393 ARMBuildAttrs::CPUArch::v7E_M));
394 EXPECT_TRUE(
395 testARMArch("armv8-a", "generic", "v8",
396 ARMBuildAttrs::CPUArch::v8_A));
397 EXPECT_TRUE(
398 testARMArch("armv8.1-a", "generic", "v8.1a",
399 ARMBuildAttrs::CPUArch::v8_A));
400 EXPECT_TRUE(
401 testARMArch("armv8.2-a", "generic", "v8.2a",
402 ARMBuildAttrs::CPUArch::v8_A));
403 EXPECT_TRUE(
404 testARMArch("armv8.3-a", "generic", "v8.3a",
405 ARMBuildAttrs::CPUArch::v8_A));
406 EXPECT_TRUE(
407 testARMArch("armv8.4-a", "generic", "v8.4a",
408 ARMBuildAttrs::CPUArch::v8_A));
409 EXPECT_TRUE(
410 testARMArch("armv8.5-a", "generic", "v8.5a",
411 ARMBuildAttrs::CPUArch::v8_A));
412 EXPECT_TRUE(
413 testARMArch("armv8-r", "cortex-r52", "v8r",
414 ARMBuildAttrs::CPUArch::v8_R));
415 EXPECT_TRUE(
416 testARMArch("armv8-m.base", "generic", "v8m.base",
417 ARMBuildAttrs::CPUArch::v8_M_Base));
418 EXPECT_TRUE(
419 testARMArch("armv8-m.main", "generic", "v8m.main",
420 ARMBuildAttrs::CPUArch::v8_M_Main));
421 EXPECT_TRUE(
422 testARMArch("armv8.1-m.main", "generic", "v8.1m.main",
423 ARMBuildAttrs::CPUArch::v8_1_M_Main));
424 EXPECT_TRUE(
425 testARMArch("iwmmxt", "iwmmxt", "",
426 ARMBuildAttrs::CPUArch::v5TE));
427 EXPECT_TRUE(
428 testARMArch("iwmmxt2", "generic", "",
429 ARMBuildAttrs::CPUArch::v5TE));
430 EXPECT_TRUE(
431 testARMArch("xscale", "xscale", "v5e",
432 ARMBuildAttrs::CPUArch::v5TE));
433 EXPECT_TRUE(
434 testARMArch("armv7s", "swift", "v7s",
435 ARMBuildAttrs::CPUArch::v7));
436 EXPECT_TRUE(
437 testARMArch("armv7k", "generic", "v7k",
438 ARMBuildAttrs::CPUArch::v7));
441 bool testARMExtension(StringRef CPUName,ARM::ArchKind ArchKind, StringRef ArchExt) {
442 return ARM::getDefaultExtensions(CPUName, ArchKind) &
443 ARM::parseArchExt(ArchExt);
446 TEST(TargetParserTest, testARMExtension) {
447 EXPECT_FALSE(testARMExtension("arm2", ARM::ArchKind::INVALID, "thumb"));
448 EXPECT_FALSE(testARMExtension("arm3", ARM::ArchKind::INVALID, "thumb"));
449 EXPECT_FALSE(testARMExtension("arm6", ARM::ArchKind::INVALID, "thumb"));
450 EXPECT_FALSE(testARMExtension("arm7m", ARM::ArchKind::INVALID, "thumb"));
451 EXPECT_FALSE(testARMExtension("strongarm", ARM::ArchKind::INVALID, "dsp"));
452 EXPECT_FALSE(testARMExtension("arm7tdmi", ARM::ArchKind::INVALID, "dsp"));
453 EXPECT_FALSE(testARMExtension("arm10tdmi",
454 ARM::ArchKind::INVALID, "simd"));
455 EXPECT_FALSE(testARMExtension("arm1022e", ARM::ArchKind::INVALID, "simd"));
456 EXPECT_FALSE(testARMExtension("arm926ej-s",
457 ARM::ArchKind::INVALID, "simd"));
458 EXPECT_FALSE(testARMExtension("arm1136jf-s",
459 ARM::ArchKind::INVALID, "crypto"));
460 EXPECT_FALSE(testARMExtension("arm1176j-s",
461 ARM::ArchKind::INVALID, "crypto"));
462 EXPECT_FALSE(testARMExtension("arm1156t2-s",
463 ARM::ArchKind::INVALID, "crypto"));
464 EXPECT_FALSE(testARMExtension("arm1176jzf-s",
465 ARM::ArchKind::INVALID, "crypto"));
466 EXPECT_FALSE(testARMExtension("cortex-m0",
467 ARM::ArchKind::INVALID, "crypto"));
468 EXPECT_FALSE(testARMExtension("cortex-a8",
469 ARM::ArchKind::INVALID, "crypto"));
470 EXPECT_FALSE(testARMExtension("cortex-r4",
471 ARM::ArchKind::INVALID, "crypto"));
472 EXPECT_FALSE(testARMExtension("cortex-m3",
473 ARM::ArchKind::INVALID, "crypto"));
474 EXPECT_FALSE(testARMExtension("cortex-a53",
475 ARM::ArchKind::INVALID, "ras"));
476 EXPECT_FALSE(testARMExtension("cortex-a53",
477 ARM::ArchKind::INVALID, "fp16"));
478 EXPECT_TRUE(testARMExtension("cortex-a55",
479 ARM::ArchKind::INVALID, "fp16"));
480 EXPECT_FALSE(testARMExtension("cortex-a55",
481 ARM::ArchKind::INVALID, "fp16fml"));
482 EXPECT_TRUE(testARMExtension("cortex-a75",
483 ARM::ArchKind::INVALID, "fp16"));
484 EXPECT_FALSE(testARMExtension("cortex-a75",
485 ARM::ArchKind::INVALID, "fp16fml"));
486 EXPECT_FALSE(testARMExtension("cortex-r52",
487 ARM::ArchKind::INVALID, "ras"));
488 EXPECT_FALSE(testARMExtension("iwmmxt", ARM::ArchKind::INVALID, "crc"));
489 EXPECT_FALSE(testARMExtension("xscale", ARM::ArchKind::INVALID, "crc"));
490 EXPECT_FALSE(testARMExtension("swift", ARM::ArchKind::INVALID, "crc"));
492 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV2, "thumb"));
493 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV2A, "thumb"));
494 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV3, "thumb"));
495 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV3M, "thumb"));
496 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV4, "dsp"));
497 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV4T, "dsp"));
498 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV5T, "simd"));
499 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV5TE, "simd"));
500 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV5TEJ, "simd"));
501 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV6, "crypto"));
502 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV6K, "crypto"));
503 EXPECT_FALSE(testARMExtension("generic",
504 ARM::ArchKind::ARMV6T2, "crypto"));
505 EXPECT_FALSE(testARMExtension("generic",
506 ARM::ArchKind::ARMV6KZ, "crypto"));
507 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV6M, "crypto"));
508 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV7A, "crypto"));
509 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV7R, "crypto"));
510 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV7M, "crypto"));
511 EXPECT_FALSE(testARMExtension("generic",
512 ARM::ArchKind::ARMV7EM, "crypto"));
513 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8A, "ras"));
514 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8_1A, "ras"));
515 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8_2A, "profile"));
516 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8_2A, "fp16"));
517 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8_2A, "fp16fml"));
518 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8_3A, "fp16"));
519 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8_3A, "fp16fml"));
520 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8_4A, "fp16"));
521 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8_4A, "fp16fml"));
522 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV8R, "ras"));
523 EXPECT_FALSE(testARMExtension("generic",
524 ARM::ArchKind::ARMV8MBaseline, "crc"));
525 EXPECT_FALSE(testARMExtension("generic",
526 ARM::ArchKind::ARMV8MMainline, "crc"));
527 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::IWMMXT, "crc"));
528 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::IWMMXT2, "crc"));
529 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::XSCALE, "crc"));
530 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV7S, "crypto"));
531 EXPECT_FALSE(testARMExtension("generic", ARM::ArchKind::ARMV7K, "crypto"));
534 TEST(TargetParserTest, ARMFPUVersion) {
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 || ARM::getFPUName(FK) == "invalid" ||
539 ARM::getFPUName(FK) == "none" || ARM::getFPUName(FK) == "softvfp")
540 EXPECT_EQ(ARM::FPUVersion::NONE, ARM::getFPUVersion(FK));
541 else
542 EXPECT_NE(ARM::FPUVersion::NONE, ARM::getFPUVersion(FK));
545 TEST(TargetParserTest, ARMFPUNeonSupportLevel) {
546 for (ARM::FPUKind FK = static_cast<ARM::FPUKind>(0);
547 FK <= ARM::FPUKind::FK_LAST;
548 FK = static_cast<ARM::FPUKind>(static_cast<unsigned>(FK) + 1))
549 if (FK == ARM::FK_LAST ||
550 ARM::getFPUName(FK).find("neon") == std::string::npos)
551 EXPECT_EQ(ARM::NeonSupportLevel::None,
552 ARM::getFPUNeonSupportLevel(FK));
553 else
554 EXPECT_NE(ARM::NeonSupportLevel::None,
555 ARM::getFPUNeonSupportLevel(FK));
558 TEST(TargetParserTest, ARMFPURestriction) {
559 for (ARM::FPUKind FK = static_cast<ARM::FPUKind>(0);
560 FK <= ARM::FPUKind::FK_LAST;
561 FK = static_cast<ARM::FPUKind>(static_cast<unsigned>(FK) + 1)) {
562 if (FK == ARM::FK_LAST ||
563 (ARM::getFPUName(FK).find("d16") == std::string::npos &&
564 ARM::getFPUName(FK).find("vfpv3xd") == std::string::npos))
565 EXPECT_EQ(ARM::FPURestriction::None, ARM::getFPURestriction(FK));
566 else
567 EXPECT_NE(ARM::FPURestriction::None, ARM::getFPURestriction(FK));
571 TEST(TargetParserTest, ARMExtensionFeatures) {
572 std::map<unsigned, std::vector<StringRef>> Extensions;
574 for (auto &Ext : ARM::ARCHExtNames) {
575 if (Ext.Feature && Ext.NegFeature)
576 Extensions[Ext.ID] = { StringRef(Ext.Feature),
577 StringRef(Ext.NegFeature) };
580 Extensions[ARM::AEK_HWDIVARM] = { "+hwdiv-arm", "-hwdiv-arm" };
581 Extensions[ARM::AEK_HWDIVTHUMB] = { "+hwdiv", "-hwdiv" };
583 std::vector<StringRef> Features;
585 EXPECT_FALSE(ARM::getExtensionFeatures(ARM::AEK_INVALID, Features));
587 for (auto &E : Extensions) {
588 // test +extension
589 Features.clear();
590 ARM::getExtensionFeatures(E.first, Features);
591 auto Found =
592 std::find(std::begin(Features), std::end(Features), E.second.at(0));
593 EXPECT_TRUE(Found != std::end(Features));
594 EXPECT_TRUE(Extensions.size() == Features.size());
596 // test -extension
597 Features.clear();
598 ARM::getExtensionFeatures(~E.first, Features);
599 Found = std::find(std::begin(Features), std::end(Features), E.second.at(1));
600 EXPECT_TRUE(Found != std::end(Features));
601 EXPECT_TRUE(Extensions.size() == Features.size());
605 TEST(TargetParserTest, ARMFPUFeatures) {
606 std::vector<StringRef> Features;
607 for (ARM::FPUKind FK = static_cast<ARM::FPUKind>(0);
608 FK <= ARM::FPUKind::FK_LAST;
609 FK = static_cast<ARM::FPUKind>(static_cast<unsigned>(FK) + 1))
610 EXPECT_TRUE((FK == ARM::FK_INVALID || FK >= ARM::FK_LAST)
611 ? !ARM::getFPUFeatures(FK, Features)
612 : ARM::getFPUFeatures(FK, Features));
615 TEST(TargetParserTest, ARMArchExtFeature) {
616 const char *ArchExt[][4] = {{"crc", "nocrc", "+crc", "-crc"},
617 {"crypto", "nocrypto", "+crypto", "-crypto"},
618 {"dsp", "nodsp", "+dsp", "-dsp"},
619 {"fp", "nofp", nullptr, nullptr},
620 {"idiv", "noidiv", nullptr, nullptr},
621 {"mp", "nomp", nullptr, nullptr},
622 {"simd", "nosimd", nullptr, nullptr},
623 {"sec", "nosec", nullptr, nullptr},
624 {"virt", "novirt", nullptr, nullptr},
625 {"fp16", "nofp16", "+fullfp16", "-fullfp16"},
626 {"fp16fml", "nofp16fml", "+fp16fml", "-fp16fml"},
627 {"ras", "noras", "+ras", "-ras"},
628 {"dotprod", "nodotprod", "+dotprod", "-dotprod"},
629 {"os", "noos", nullptr, nullptr},
630 {"iwmmxt", "noiwmmxt", nullptr, nullptr},
631 {"iwmmxt2", "noiwmmxt2", nullptr, nullptr},
632 {"maverick", "maverick", nullptr, nullptr},
633 {"xscale", "noxscale", nullptr, nullptr},
634 {"sb", "nosb", "+sb", "-sb"},
635 {"mve", "nomve", "+mve", "-mve"},
636 {"mve.fp", "nomve.fp", "+mve.fp", "-mve.fp"}};
638 for (unsigned i = 0; i < array_lengthof(ArchExt); i++) {
639 EXPECT_EQ(StringRef(ArchExt[i][2]), ARM::getArchExtFeature(ArchExt[i][0]));
640 EXPECT_EQ(StringRef(ArchExt[i][3]), ARM::getArchExtFeature(ArchExt[i][1]));
644 TEST(TargetParserTest, ARMparseHWDiv) {
645 const char *hwdiv[] = {"thumb", "arm", "arm,thumb", "thumb,arm"};
647 for (unsigned i = 0; i < array_lengthof(hwdiv); i++)
648 EXPECT_NE(ARM::AEK_INVALID, ARM::parseHWDiv((StringRef)hwdiv[i]));
651 TEST(TargetParserTest, ARMparseArchEndianAndISA) {
652 const char *Arch[] = {
653 "v2", "v2a", "v3", "v3m", "v4", "v4t", "v5", "v5t",
654 "v5e", "v5te", "v5tej", "v6", "v6j", "v6k", "v6hl", "v6t2",
655 "v6kz", "v6z", "v6zk", "v6-m", "v6m", "v6sm", "v6s-m", "v7-a",
656 "v7", "v7a", "v7ve", "v7hl", "v7l", "v7-r", "v7r", "v7-m",
657 "v7m", "v7k", "v7s", "v7e-m", "v7em", "v8-a", "v8", "v8a",
658 "v8l", "v8.1-a", "v8.1a", "v8.2-a", "v8.2a", "v8.3-a", "v8.3a", "v8.4-a",
659 "v8.4a", "v8.5-a","v8.5a", "v8-r", "v8m.base", "v8m.main", "v8.1m.main"
662 for (unsigned i = 0; i < array_lengthof(Arch); i++) {
663 std::string arm_1 = "armeb" + (std::string)(Arch[i]);
664 std::string arm_2 = "arm" + (std::string)(Arch[i]) + "eb";
665 std::string arm_3 = "arm" + (std::string)(Arch[i]);
666 std::string thumb_1 = "thumbeb" + (std::string)(Arch[i]);
667 std::string thumb_2 = "thumb" + (std::string)(Arch[i]) + "eb";
668 std::string thumb_3 = "thumb" + (std::string)(Arch[i]);
670 EXPECT_EQ(ARM::EndianKind::BIG, ARM::parseArchEndian(arm_1));
671 EXPECT_EQ(ARM::EndianKind::BIG, ARM::parseArchEndian(arm_2));
672 EXPECT_EQ(ARM::EndianKind::LITTLE, ARM::parseArchEndian(arm_3));
674 EXPECT_EQ(ARM::ISAKind::ARM, ARM::parseArchISA(arm_1));
675 EXPECT_EQ(ARM::ISAKind::ARM, ARM::parseArchISA(arm_2));
676 EXPECT_EQ(ARM::ISAKind::ARM, ARM::parseArchISA(arm_3));
677 if (i >= 4) {
678 EXPECT_EQ(ARM::EndianKind::BIG, ARM::parseArchEndian(thumb_1));
679 EXPECT_EQ(ARM::EndianKind::BIG, ARM::parseArchEndian(thumb_2));
680 EXPECT_EQ(ARM::EndianKind::LITTLE, ARM::parseArchEndian(thumb_3));
682 EXPECT_EQ(ARM::ISAKind::THUMB, ARM::parseArchISA(thumb_1));
683 EXPECT_EQ(ARM::ISAKind::THUMB, ARM::parseArchISA(thumb_2));
684 EXPECT_EQ(ARM::ISAKind::THUMB, ARM::parseArchISA(thumb_3));
688 EXPECT_EQ(ARM::EndianKind::LITTLE, ARM::parseArchEndian("aarch64"));
689 EXPECT_EQ(ARM::EndianKind::LITTLE, ARM::parseArchEndian("arm64_32"));
690 EXPECT_EQ(ARM::EndianKind::BIG, ARM::parseArchEndian("aarch64_be"));
692 EXPECT_EQ(ARM::ISAKind::AARCH64, ARM::parseArchISA("aarch64"));
693 EXPECT_EQ(ARM::ISAKind::AARCH64, ARM::parseArchISA("aarch64_be"));
694 EXPECT_EQ(ARM::ISAKind::AARCH64, ARM::parseArchISA("arm64"));
695 EXPECT_EQ(ARM::ISAKind::AARCH64, ARM::parseArchISA("arm64_be"));
696 EXPECT_EQ(ARM::ISAKind::AARCH64, ARM::parseArchISA("arm64_32"));
697 EXPECT_EQ(ARM::ISAKind::AARCH64, ARM::parseArchISA("aarch64_32"));
700 TEST(TargetParserTest, ARMparseArchProfile) {
701 for (unsigned i = 0; i < array_lengthof(ARMArch); i++) {
702 switch (ARM::parseArch(ARMArch[i])) {
703 case ARM::ArchKind::ARMV6M:
704 case ARM::ArchKind::ARMV7M:
705 case ARM::ArchKind::ARMV7EM:
706 case ARM::ArchKind::ARMV8MMainline:
707 case ARM::ArchKind::ARMV8MBaseline:
708 case ARM::ArchKind::ARMV8_1MMainline:
709 EXPECT_EQ(ARM::ProfileKind::M, ARM::parseArchProfile(ARMArch[i]));
710 break;
711 case ARM::ArchKind::ARMV7R:
712 case ARM::ArchKind::ARMV8R:
713 EXPECT_EQ(ARM::ProfileKind::R, ARM::parseArchProfile(ARMArch[i]));
714 break;
715 case ARM::ArchKind::ARMV7A:
716 case ARM::ArchKind::ARMV7VE:
717 case ARM::ArchKind::ARMV7K:
718 case ARM::ArchKind::ARMV8A:
719 case ARM::ArchKind::ARMV8_1A:
720 case ARM::ArchKind::ARMV8_2A:
721 case ARM::ArchKind::ARMV8_3A:
722 case ARM::ArchKind::ARMV8_4A:
723 case ARM::ArchKind::ARMV8_5A:
724 EXPECT_EQ(ARM::ProfileKind::A, ARM::parseArchProfile(ARMArch[i]));
725 break;
726 default:
727 EXPECT_EQ(ARM::ProfileKind::INVALID, ARM::parseArchProfile(ARMArch[i]));
728 break;
733 TEST(TargetParserTest, ARMparseArchVersion) {
734 for (unsigned i = 0; i < array_lengthof(ARMArch); i++)
735 if (((std::string)ARMArch[i]).substr(0, 4) == "armv")
736 EXPECT_EQ((ARMArch[i][4] - 48u), ARM::parseArchVersion(ARMArch[i]));
737 else
738 EXPECT_EQ(5u, ARM::parseArchVersion(ARMArch[i]));
741 bool testAArch64CPU(StringRef CPUName, StringRef ExpectedArch,
742 StringRef ExpectedFPU, unsigned ExpectedFlags,
743 StringRef CPUAttr) {
744 AArch64::ArchKind AK = AArch64::parseCPUArch(CPUName);
745 bool pass = AArch64::getArchName(AK).equals(ExpectedArch);
747 unsigned ExtKind = AArch64::getDefaultExtensions(CPUName, AK);
748 if (ExtKind > 1 && (ExtKind & AArch64::AEK_NONE))
749 pass &= ((ExtKind ^ AArch64::AEK_NONE) == ExpectedFlags);
750 else
751 pass &= (ExtKind == ExpectedFlags);
753 pass &= AArch64::getCPUAttr(AK).equals(CPUAttr);
755 return pass;
758 TEST(TargetParserTest, testAArch64CPU) {
759 EXPECT_TRUE(testAArch64CPU(
760 "invalid", "invalid", "invalid",
761 AArch64::AEK_NONE, ""));
762 EXPECT_TRUE(testAArch64CPU(
763 "generic", "invalid", "none",
764 AArch64::AEK_NONE, ""));
766 EXPECT_TRUE(testAArch64CPU(
767 "cortex-a35", "armv8-a", "crypto-neon-fp-armv8",
768 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
769 AArch64::AEK_SIMD, "8-A"));
770 EXPECT_TRUE(testAArch64CPU(
771 "cortex-a53", "armv8-a", "crypto-neon-fp-armv8",
772 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
773 AArch64::AEK_SIMD, "8-A"));
774 EXPECT_TRUE(testAArch64CPU(
775 "cortex-a55", "armv8.2-a", "crypto-neon-fp-armv8",
776 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
777 AArch64::AEK_SIMD | AArch64::AEK_RAS | AArch64::AEK_LSE |
778 AArch64::AEK_RDM | AArch64::AEK_FP16 | AArch64::AEK_DOTPROD |
779 AArch64::AEK_RCPC, "8.2-A"));
780 EXPECT_TRUE(testAArch64CPU(
781 "cortex-a57", "armv8-a", "crypto-neon-fp-armv8",
782 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
783 AArch64::AEK_SIMD, "8-A"));
784 EXPECT_TRUE(testAArch64CPU(
785 "cortex-a72", "armv8-a", "crypto-neon-fp-armv8",
786 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
787 AArch64::AEK_SIMD, "8-A"));
788 EXPECT_TRUE(testAArch64CPU(
789 "cortex-a73", "armv8-a", "crypto-neon-fp-armv8",
790 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
791 AArch64::AEK_SIMD, "8-A"));
792 EXPECT_TRUE(testAArch64CPU(
793 "cortex-a75", "armv8.2-a", "crypto-neon-fp-armv8",
794 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
795 AArch64::AEK_SIMD | AArch64::AEK_RAS | AArch64::AEK_LSE |
796 AArch64::AEK_RDM | AArch64::AEK_FP16 | AArch64::AEK_DOTPROD |
797 AArch64::AEK_RCPC, "8.2-A"));
798 EXPECT_TRUE(testAArch64CPU(
799 "cortex-a76", "armv8.2-a", "crypto-neon-fp-armv8",
800 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
801 AArch64::AEK_RDM | AArch64::AEK_SIMD | AArch64::AEK_RAS |
802 AArch64::AEK_LSE | AArch64::AEK_FP16 | AArch64::AEK_DOTPROD |
803 AArch64::AEK_RCPC| AArch64::AEK_SSBS, "8.2-A"));
804 EXPECT_TRUE(testAArch64CPU(
805 "cortex-a76ae", "armv8.2-a", "crypto-neon-fp-armv8",
806 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
807 AArch64::AEK_RDM | AArch64::AEK_SIMD | AArch64::AEK_RAS |
808 AArch64::AEK_LSE | AArch64::AEK_FP16 | AArch64::AEK_DOTPROD |
809 AArch64::AEK_RCPC| AArch64::AEK_SSBS, "8.2-A"));
810 EXPECT_TRUE(testAArch64CPU(
811 "cyclone", "armv8-a", "crypto-neon-fp-armv8",
812 AArch64::AEK_CRYPTO | AArch64::AEK_FP | AArch64::AEK_SIMD, "8-A"));
813 EXPECT_TRUE(testAArch64CPU(
814 "exynos-m1", "armv8-a", "crypto-neon-fp-armv8",
815 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
816 AArch64::AEK_SIMD, "8-A"));
817 EXPECT_TRUE(testAArch64CPU(
818 "exynos-m2", "armv8-a", "crypto-neon-fp-armv8",
819 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
820 AArch64::AEK_SIMD, "8-A"));
821 EXPECT_TRUE(testAArch64CPU(
822 "exynos-m3", "armv8-a", "crypto-neon-fp-armv8",
823 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
824 AArch64::AEK_SIMD, "8-A"));
825 EXPECT_TRUE(testAArch64CPU(
826 "exynos-m4", "armv8.2-a", "crypto-neon-fp-armv8",
827 AArch64::AEK_CRC | AArch64::AEK_CRYPTO |
828 AArch64::AEK_DOTPROD | AArch64::AEK_FP | AArch64::AEK_FP16 |
829 AArch64::AEK_LSE | AArch64::AEK_RAS | AArch64::AEK_RDM |
830 AArch64::AEK_SIMD, "8.2-A"));
831 EXPECT_TRUE(testAArch64CPU(
832 "exynos-m5", "armv8.2-a", "crypto-neon-fp-armv8",
833 AArch64::AEK_CRC | AArch64::AEK_CRYPTO |
834 AArch64::AEK_DOTPROD | AArch64::AEK_FP | AArch64::AEK_FP16 |
835 AArch64::AEK_LSE | AArch64::AEK_RAS | AArch64::AEK_RDM |
836 AArch64::AEK_SIMD, "8.2-A"));
837 EXPECT_TRUE(testAArch64CPU(
838 "falkor", "armv8-a", "crypto-neon-fp-armv8",
839 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
840 AArch64::AEK_SIMD | AArch64::AEK_RDM, "8-A"));
841 EXPECT_TRUE(testAArch64CPU(
842 "kryo", "armv8-a", "crypto-neon-fp-armv8",
843 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
844 AArch64::AEK_SIMD, "8-A"));
845 EXPECT_TRUE(testAArch64CPU(
846 "thunderx2t99", "armv8.1-a", "crypto-neon-fp-armv8",
847 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_LSE |
848 AArch64::AEK_RDM | AArch64::AEK_FP | AArch64::AEK_SIMD, "8.1-A"));
849 EXPECT_TRUE(testAArch64CPU(
850 "thunderx", "armv8-a", "crypto-neon-fp-armv8",
851 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_SIMD |
852 AArch64::AEK_FP | AArch64::AEK_PROFILE,
853 "8-A"));
854 EXPECT_TRUE(testAArch64CPU(
855 "thunderxt81", "armv8-a", "crypto-neon-fp-armv8",
856 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_SIMD |
857 AArch64::AEK_FP | AArch64::AEK_PROFILE,
858 "8-A"));
859 EXPECT_TRUE(testAArch64CPU(
860 "thunderxt83", "armv8-a", "crypto-neon-fp-armv8",
861 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_SIMD |
862 AArch64::AEK_FP | AArch64::AEK_PROFILE,
863 "8-A"));
864 EXPECT_TRUE(testAArch64CPU(
865 "thunderxt88", "armv8-a", "crypto-neon-fp-armv8",
866 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_SIMD |
867 AArch64::AEK_FP | AArch64::AEK_PROFILE,
868 "8-A"));
869 EXPECT_TRUE(testAArch64CPU(
870 "tsv110", "armv8.2-a", "crypto-neon-fp-armv8",
871 AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
872 AArch64::AEK_SIMD | AArch64::AEK_RAS | AArch64::AEK_LSE |
873 AArch64::AEK_RDM | AArch64::AEK_PROFILE | AArch64::AEK_FP16 |
874 AArch64::AEK_FP16FML | AArch64::AEK_DOTPROD,
875 "8.2-A"));
878 static constexpr unsigned NumAArch64CPUArchs = 24;
880 TEST(TargetParserTest, testAArch64CPUArchList) {
881 SmallVector<StringRef, NumAArch64CPUArchs> List;
882 AArch64::fillValidCPUArchList(List);
884 // No list exists for these in this test suite, so ensure all are
885 // valid, and match the expected 'magic' count.
886 EXPECT_EQ(List.size(), NumAArch64CPUArchs);
887 for(StringRef CPU : List) {
888 EXPECT_NE(AArch64::parseCPUArch(CPU), AArch64::ArchKind::INVALID);
892 bool testAArch64Arch(StringRef Arch, StringRef DefaultCPU, StringRef SubArch,
893 unsigned ArchAttr) {
894 AArch64::ArchKind AK = AArch64::parseArch(Arch);
895 return (AK != AArch64::ArchKind::INVALID) &
896 AArch64::getDefaultCPU(Arch).equals(DefaultCPU) &
897 AArch64::getSubArch(AK).equals(SubArch) &
898 (AArch64::getArchAttr(AK) == ArchAttr);
901 TEST(TargetParserTest, testAArch64Arch) {
902 EXPECT_TRUE(testAArch64Arch("armv8-a", "cortex-a53", "v8",
903 ARMBuildAttrs::CPUArch::v8_A));
904 EXPECT_TRUE(testAArch64Arch("armv8.1-a", "generic", "v8.1a",
905 ARMBuildAttrs::CPUArch::v8_A));
906 EXPECT_TRUE(testAArch64Arch("armv8.2-a", "generic", "v8.2a",
907 ARMBuildAttrs::CPUArch::v8_A));
908 EXPECT_TRUE(testAArch64Arch("armv8.3-a", "generic", "v8.3a",
909 ARMBuildAttrs::CPUArch::v8_A));
910 EXPECT_TRUE(testAArch64Arch("armv8.4-a", "generic", "v8.4a",
911 ARMBuildAttrs::CPUArch::v8_A));
912 EXPECT_TRUE(testAArch64Arch("armv8.5-a", "generic", "v8.5a",
913 ARMBuildAttrs::CPUArch::v8_A));
916 bool testAArch64Extension(StringRef CPUName, AArch64::ArchKind AK,
917 StringRef ArchExt) {
918 return AArch64::getDefaultExtensions(CPUName, AK) &
919 AArch64::parseArchExt(ArchExt);
922 TEST(TargetParserTest, testAArch64Extension) {
923 EXPECT_FALSE(testAArch64Extension("cortex-a35",
924 AArch64::ArchKind::INVALID, "ras"));
925 EXPECT_FALSE(testAArch64Extension("cortex-a53",
926 AArch64::ArchKind::INVALID, "ras"));
927 EXPECT_TRUE(testAArch64Extension("cortex-a55",
928 AArch64::ArchKind::INVALID, "ras"));
929 EXPECT_FALSE(testAArch64Extension("cortex-a57",
930 AArch64::ArchKind::INVALID, "ras"));
931 EXPECT_FALSE(testAArch64Extension("cortex-a72",
932 AArch64::ArchKind::INVALID, "ras"));
933 EXPECT_FALSE(testAArch64Extension("cortex-a73",
934 AArch64::ArchKind::INVALID, "ras"));
935 EXPECT_TRUE(testAArch64Extension("cortex-a75",
936 AArch64::ArchKind::INVALID, "ras"));
937 EXPECT_FALSE(testAArch64Extension("cyclone",
938 AArch64::ArchKind::INVALID, "ras"));
939 EXPECT_FALSE(testAArch64Extension("exynos-m1",
940 AArch64::ArchKind::INVALID, "ras"));
941 EXPECT_FALSE(testAArch64Extension("exynos-m2",
942 AArch64::ArchKind::INVALID, "ras"));
943 EXPECT_FALSE(testAArch64Extension("exynos-m3",
944 AArch64::ArchKind::INVALID, "ras"));
945 EXPECT_TRUE(testAArch64Extension("exynos-m4",
946 AArch64::ArchKind::INVALID, "dotprod"));
947 EXPECT_TRUE(testAArch64Extension("exynos-m4",
948 AArch64::ArchKind::INVALID, "fp16"));
949 EXPECT_TRUE(testAArch64Extension("exynos-m4",
950 AArch64::ArchKind::INVALID, "lse"));
951 EXPECT_TRUE(testAArch64Extension("exynos-m4",
952 AArch64::ArchKind::INVALID, "ras"));
953 EXPECT_TRUE(testAArch64Extension("exynos-m4",
954 AArch64::ArchKind::INVALID, "rdm"));
955 EXPECT_TRUE(testAArch64Extension("exynos-m5",
956 AArch64::ArchKind::INVALID, "dotprod"));
957 EXPECT_TRUE(testAArch64Extension("exynos-m5",
958 AArch64::ArchKind::INVALID, "fp16"));
959 EXPECT_TRUE(testAArch64Extension("exynos-m5",
960 AArch64::ArchKind::INVALID, "lse"));
961 EXPECT_TRUE(testAArch64Extension("exynos-m5",
962 AArch64::ArchKind::INVALID, "ras"));
963 EXPECT_TRUE(testAArch64Extension("exynos-m5",
964 AArch64::ArchKind::INVALID, "rdm"));
965 EXPECT_TRUE(testAArch64Extension("falkor",
966 AArch64::ArchKind::INVALID, "rdm"));
967 EXPECT_FALSE(testAArch64Extension("kryo",
968 AArch64::ArchKind::INVALID, "ras"));
969 EXPECT_TRUE(testAArch64Extension("saphira",
970 AArch64::ArchKind::INVALID, "crc"));
971 EXPECT_TRUE(testAArch64Extension("saphira",
972 AArch64::ArchKind::INVALID, "lse"));
973 EXPECT_TRUE(testAArch64Extension("saphira",
974 AArch64::ArchKind::INVALID, "rdm"));
975 EXPECT_TRUE(testAArch64Extension("saphira",
976 AArch64::ArchKind::INVALID, "ras"));
977 EXPECT_TRUE(testAArch64Extension("saphira",
978 AArch64::ArchKind::INVALID, "rcpc"));
979 EXPECT_TRUE(testAArch64Extension("saphira",
980 AArch64::ArchKind::INVALID, "profile"));
981 EXPECT_FALSE(testAArch64Extension("saphira",
982 AArch64::ArchKind::INVALID, "fp16"));
983 EXPECT_TRUE(testAArch64Extension("cortex-a55",
984 AArch64::ArchKind::INVALID, "fp16"));
985 EXPECT_FALSE(testAArch64Extension("cortex-a55",
986 AArch64::ArchKind::INVALID, "fp16fml"));
987 EXPECT_TRUE(testAArch64Extension("cortex-a55",
988 AArch64::ArchKind::INVALID, "dotprod"));
989 EXPECT_TRUE(testAArch64Extension("cortex-a75",
990 AArch64::ArchKind::INVALID, "fp16"));
991 EXPECT_FALSE(testAArch64Extension("cortex-a75",
992 AArch64::ArchKind::INVALID, "fp16fml"));
993 EXPECT_TRUE(testAArch64Extension("cortex-a75",
994 AArch64::ArchKind::INVALID, "dotprod"));
995 EXPECT_FALSE(testAArch64Extension("thunderx2t99",
996 AArch64::ArchKind::INVALID, "ras"));
997 EXPECT_FALSE(testAArch64Extension("thunderx",
998 AArch64::ArchKind::INVALID, "lse"));
999 EXPECT_FALSE(testAArch64Extension("thunderxt81",
1000 AArch64::ArchKind::INVALID, "lse"));
1001 EXPECT_FALSE(testAArch64Extension("thunderxt83",
1002 AArch64::ArchKind::INVALID, "lse"));
1003 EXPECT_FALSE(testAArch64Extension("thunderxt88",
1004 AArch64::ArchKind::INVALID, "lse"));
1005 EXPECT_TRUE(testAArch64Extension("tsv110",
1006 AArch64::ArchKind::INVALID, "crypto"));
1007 EXPECT_FALSE(testAArch64Extension("tsv110",
1008 AArch64::ArchKind::INVALID, "sha3"));
1009 EXPECT_FALSE(testAArch64Extension("tsv110",
1010 AArch64::ArchKind::INVALID, "sm4"));
1011 EXPECT_TRUE(testAArch64Extension("tsv110",
1012 AArch64::ArchKind::INVALID, "ras"));
1013 EXPECT_TRUE(testAArch64Extension("tsv110",
1014 AArch64::ArchKind::INVALID, "profile"));
1015 EXPECT_TRUE(testAArch64Extension("tsv110",
1016 AArch64::ArchKind::INVALID, "fp16"));
1017 EXPECT_TRUE(testAArch64Extension("tsv110",
1018 AArch64::ArchKind::INVALID, "fp16fml"));
1019 EXPECT_TRUE(testAArch64Extension("tsv110",
1020 AArch64::ArchKind::INVALID, "dotprod"));
1022 EXPECT_FALSE(testAArch64Extension(
1023 "generic", AArch64::ArchKind::ARMV8A, "ras"));
1024 EXPECT_FALSE(testAArch64Extension(
1025 "generic", AArch64::ArchKind::ARMV8_1A, "ras"));
1026 EXPECT_FALSE(testAArch64Extension(
1027 "generic", AArch64::ArchKind::ARMV8_2A, "profile"));
1028 EXPECT_FALSE(testAArch64Extension(
1029 "generic", AArch64::ArchKind::ARMV8_2A, "fp16"));
1030 EXPECT_FALSE(testAArch64Extension(
1031 "generic", AArch64::ArchKind::ARMV8_2A, "fp16fml"));
1032 EXPECT_FALSE(testAArch64Extension(
1033 "generic", AArch64::ArchKind::ARMV8_3A, "fp16"));
1034 EXPECT_FALSE(testAArch64Extension(
1035 "generic", AArch64::ArchKind::ARMV8_3A, "fp16fml"));
1036 EXPECT_FALSE(testAArch64Extension(
1037 "generic", AArch64::ArchKind::ARMV8_4A, "fp16"));
1038 EXPECT_FALSE(testAArch64Extension(
1039 "generic", AArch64::ArchKind::ARMV8_4A, "fp16fml"));
1042 TEST(TargetParserTest, AArch64ExtensionFeatures) {
1043 std::vector<unsigned> Extensions = {
1044 AArch64::AEK_CRC, AArch64::AEK_CRYPTO,
1045 AArch64::AEK_FP, AArch64::AEK_SIMD,
1046 AArch64::AEK_FP16, AArch64::AEK_PROFILE,
1047 AArch64::AEK_RAS, AArch64::AEK_LSE,
1048 AArch64::AEK_RDM, AArch64::AEK_DOTPROD,
1049 AArch64::AEK_SVE, AArch64::AEK_SVE2,
1050 AArch64::AEK_SVE2AES, AArch64::AEK_SVE2SM4,
1051 AArch64::AEK_SVE2SHA3, AArch64::AEK_BITPERM,
1052 AArch64::AEK_RCPC, AArch64::AEK_FP16FML };
1054 std::vector<StringRef> Features;
1056 unsigned ExtVal = 0;
1057 for (auto Ext : Extensions)
1058 ExtVal |= Ext;
1060 EXPECT_FALSE(AArch64::getExtensionFeatures(AArch64::AEK_INVALID, Features));
1061 EXPECT_TRUE(!Features.size());
1063 AArch64::getExtensionFeatures(ExtVal, Features);
1064 EXPECT_TRUE(Extensions.size() == Features.size());
1066 auto B = std::begin(Features);
1067 auto E = std::end(Features);
1069 EXPECT_TRUE(std::find(B, E, "+crc") != E);
1070 EXPECT_TRUE(std::find(B, E, "+crypto") != E);
1071 EXPECT_TRUE(std::find(B, E, "+fp-armv8") != E);
1072 EXPECT_TRUE(std::find(B, E, "+neon") != E);
1073 EXPECT_TRUE(std::find(B, E, "+fullfp16") != E);
1074 EXPECT_TRUE(std::find(B, E, "+spe") != E);
1075 EXPECT_TRUE(std::find(B, E, "+ras") != E);
1076 EXPECT_TRUE(std::find(B, E, "+lse") != E);
1077 EXPECT_TRUE(std::find(B, E, "+rdm") != E);
1078 EXPECT_TRUE(std::find(B, E, "+dotprod") != E);
1079 EXPECT_TRUE(std::find(B, E, "+rcpc") != E);
1080 EXPECT_TRUE(std::find(B, E, "+fp16fml") != E);
1081 EXPECT_TRUE(std::find(B, E, "+sve") != E);
1082 EXPECT_TRUE(std::find(B, E, "+sve2") != E);
1083 EXPECT_TRUE(std::find(B, E, "+sve2-aes") != E);
1084 EXPECT_TRUE(std::find(B, E, "+sve2-sm4") != E);
1085 EXPECT_TRUE(std::find(B, E, "+sve2-sha3") != E);
1086 EXPECT_TRUE(std::find(B, E, "+bitperm") != E);
1089 TEST(TargetParserTest, AArch64ArchFeatures) {
1090 std::vector<StringRef> Features;
1092 for (auto AK : AArch64::ArchKinds)
1093 EXPECT_TRUE((AK == AArch64::ArchKind::INVALID)
1094 ? !AArch64::getArchFeatures(AK, Features)
1095 : AArch64::getArchFeatures(AK, Features));
1098 TEST(TargetParserTest, AArch64ArchExtFeature) {
1099 const char *ArchExt[][4] = {{"crc", "nocrc", "+crc", "-crc"},
1100 {"crypto", "nocrypto", "+crypto", "-crypto"},
1101 {"fp", "nofp", "+fp-armv8", "-fp-armv8"},
1102 {"simd", "nosimd", "+neon", "-neon"},
1103 {"fp16", "nofp16", "+fullfp16", "-fullfp16"},
1104 {"fp16fml", "nofp16fml", "+fp16fml", "-fp16fml"},
1105 {"profile", "noprofile", "+spe", "-spe"},
1106 {"ras", "noras", "+ras", "-ras"},
1107 {"lse", "nolse", "+lse", "-lse"},
1108 {"rdm", "nordm", "+rdm", "-rdm"},
1109 {"sve", "nosve", "+sve", "-sve"},
1110 {"sve2", "nosve2", "+sve2", "-sve2"},
1111 {"sve2-aes", "nosve2-aes", "+sve2-aes",
1112 "-sve2-aes"},
1113 {"sve2-sm4", "nosve2-sm4", "+sve2-sm4",
1114 "-sve2-sm4"},
1115 {"sve2-sha3", "nosve2-sha3", "+sve2-sha3",
1116 "-sve2-sha3"},
1117 {"bitperm", "nobitperm", "+bitperm", "-bitperm"},
1118 {"dotprod", "nodotprod", "+dotprod", "-dotprod"},
1119 {"rcpc", "norcpc", "+rcpc", "-rcpc" },
1120 {"rng", "norng", "+rand", "-rand"},
1121 {"memtag", "nomemtag", "+mte", "-mte"},
1122 {"ssbs", "nossbs", "+ssbs", "-ssbs"},
1123 {"sb", "nosb", "+sb", "-sb"},
1124 {"predres", "nopredres", "+predres", "-predres"}
1127 for (unsigned i = 0; i < array_lengthof(ArchExt); i++) {
1128 EXPECT_EQ(StringRef(ArchExt[i][2]),
1129 AArch64::getArchExtFeature(ArchExt[i][0]));
1130 EXPECT_EQ(StringRef(ArchExt[i][3]),
1131 AArch64::getArchExtFeature(ArchExt[i][1]));