18 #include "llvm/ADT/StringExtras.h" 19 #include "llvm/ADT/StringRef.h" 20 #include "llvm/ADT/StringSwitch.h" 21 #include "llvm/Support/TargetParser.h" 27 #define BUILTIN(ID, TYPE, ATTRS) \ 28 {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr}, 29 #define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) \ 30 {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, FEATURE}, 31 #define TARGET_HEADER_BUILTIN(ID, TYPE, ATTRS, HEADER, LANGS, FEATURE) \ 32 {#ID, TYPE, ATTRS, HEADER, LANGS, FEATURE}, 33 #include "clang/Basic/BuiltinsX86.def" 35 #define BUILTIN(ID, TYPE, ATTRS) \ 36 {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr}, 37 #define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) \ 38 {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, FEATURE}, 39 #define TARGET_HEADER_BUILTIN(ID, TYPE, ATTRS, HEADER, LANGS, FEATURE) \ 40 {#ID, TYPE, ATTRS, HEADER, LANGS, FEATURE}, 41 #include "clang/Basic/BuiltinsX86_64.def" 45 "ax",
"dx",
"cx",
"bx",
"si",
"di",
"bp",
"sp",
46 "st",
"st(1)",
"st(2)",
"st(3)",
"st(4)",
"st(5)",
"st(6)",
"st(7)",
47 "argp",
"flags",
"fpcr",
"fpsr",
"dirflag",
"frame",
"xmm0",
"xmm1",
48 "xmm2",
"xmm3",
"xmm4",
"xmm5",
"xmm6",
"xmm7",
"mm0",
"mm1",
49 "mm2",
"mm3",
"mm4",
"mm5",
"mm6",
"mm7",
"r8",
"r9",
50 "r10",
"r11",
"r12",
"r13",
"r14",
"r15",
"xmm8",
"xmm9",
51 "xmm10",
"xmm11",
"xmm12",
"xmm13",
"xmm14",
"xmm15",
"ymm0",
"ymm1",
52 "ymm2",
"ymm3",
"ymm4",
"ymm5",
"ymm6",
"ymm7",
"ymm8",
"ymm9",
53 "ymm10",
"ymm11",
"ymm12",
"ymm13",
"ymm14",
"ymm15",
"xmm16",
"xmm17",
54 "xmm18",
"xmm19",
"xmm20",
"xmm21",
"xmm22",
"xmm23",
"xmm24",
"xmm25",
55 "xmm26",
"xmm27",
"xmm28",
"xmm29",
"xmm30",
"xmm31",
"ymm16",
"ymm17",
56 "ymm18",
"ymm19",
"ymm20",
"ymm21",
"ymm22",
"ymm23",
"ymm24",
"ymm25",
57 "ymm26",
"ymm27",
"ymm28",
"ymm29",
"ymm30",
"ymm31",
"zmm0",
"zmm1",
58 "zmm2",
"zmm3",
"zmm4",
"zmm5",
"zmm6",
"zmm7",
"zmm8",
"zmm9",
59 "zmm10",
"zmm11",
"zmm12",
"zmm13",
"zmm14",
"zmm15",
"zmm16",
"zmm17",
60 "zmm18",
"zmm19",
"zmm20",
"zmm21",
"zmm22",
"zmm23",
"zmm24",
"zmm25",
61 "zmm26",
"zmm27",
"zmm28",
"zmm29",
"zmm30",
"zmm31",
"k0",
"k1",
62 "k2",
"k3",
"k4",
"k5",
"k6",
"k7",
63 "cr0",
"cr2",
"cr3",
"cr4",
"cr8",
64 "dr0",
"dr1",
"dr2",
"dr3",
"dr6",
"dr7",
65 "bnd0",
"bnd1",
"bnd2",
"bnd3",
69 {{
"al",
"ah",
"eax",
"rax"}, 0},
70 {{
"bl",
"bh",
"ebx",
"rbx"}, 3},
71 {{
"cl",
"ch",
"ecx",
"rcx"}, 2},
72 {{
"dl",
"dh",
"edx",
"rdx"}, 1},
77 {{
"r8d",
"r8w",
"r8b"}, 38},
78 {{
"r9d",
"r9w",
"r9b"}, 39},
79 {{
"r10d",
"r10w",
"r10b"}, 40},
80 {{
"r11d",
"r11w",
"r11b"}, 41},
81 {{
"r12d",
"r12w",
"r12b"}, 42},
82 {{
"r13d",
"r13w",
"r13b"}, 43},
83 {{
"r14d",
"r14w",
"r14b"}, 44},
84 {{
"r15d",
"r15w",
"r15b"}, 45},
90 using namespace clang;
107 const std::vector<std::string> &FeaturesVec)
const {
110 if (getTriple().getArch() == llvm::Triple::x86_64)
111 setFeatureEnabledImpl(Features,
"sse2",
true);
116 if (Kind != CK_Lakemont)
117 setFeatureEnabledImpl(Features,
"x87",
true);
133 setFeatureEnabledImpl(Features,
"mmx",
true);
136 case CK_IcelakeServer:
137 setFeatureEnabledImpl(Features,
"pconfig",
true);
138 setFeatureEnabledImpl(Features,
"wbnoinvd",
true);
140 case CK_IcelakeClient:
141 setFeatureEnabledImpl(Features,
"vaes",
true);
142 setFeatureEnabledImpl(Features,
"gfni",
true);
143 setFeatureEnabledImpl(Features,
"vpclmulqdq",
true);
144 setFeatureEnabledImpl(Features,
"avx512bitalg",
true);
145 setFeatureEnabledImpl(Features,
"avx512vnni",
true);
146 setFeatureEnabledImpl(Features,
"avx512vbmi2",
true);
147 setFeatureEnabledImpl(Features,
"avx512vpopcntdq",
true);
148 setFeatureEnabledImpl(Features,
"rdpid",
true);
151 setFeatureEnabledImpl(Features,
"avx512ifma",
true);
152 setFeatureEnabledImpl(Features,
"avx512vbmi",
true);
153 setFeatureEnabledImpl(Features,
"sha",
true);
155 case CK_SkylakeServer:
156 setFeatureEnabledImpl(Features,
"avx512f",
true);
157 setFeatureEnabledImpl(Features,
"avx512cd",
true);
158 setFeatureEnabledImpl(Features,
"avx512dq",
true);
159 setFeatureEnabledImpl(Features,
"avx512bw",
true);
160 setFeatureEnabledImpl(Features,
"avx512vl",
true);
161 setFeatureEnabledImpl(Features,
"pku",
true);
162 if (Kind != CK_Cannonlake)
163 setFeatureEnabledImpl(Features,
"clwb",
true);
165 case CK_SkylakeClient:
166 setFeatureEnabledImpl(Features,
"xsavec",
true);
167 setFeatureEnabledImpl(Features,
"xsaves",
true);
168 setFeatureEnabledImpl(Features,
"mpx",
true);
169 if (Kind != CK_SkylakeServer)
170 setFeatureEnabledImpl(Features,
"sgx",
true);
171 setFeatureEnabledImpl(Features,
"clflushopt",
true);
172 setFeatureEnabledImpl(Features,
"rtm",
true);
175 setFeatureEnabledImpl(Features,
"rdseed",
true);
176 setFeatureEnabledImpl(Features,
"adx",
true);
177 setFeatureEnabledImpl(Features,
"prfchw",
true);
180 setFeatureEnabledImpl(Features,
"avx2",
true);
181 setFeatureEnabledImpl(Features,
"lzcnt",
true);
182 setFeatureEnabledImpl(Features,
"bmi",
true);
183 setFeatureEnabledImpl(Features,
"bmi2",
true);
184 setFeatureEnabledImpl(Features,
"fma",
true);
185 setFeatureEnabledImpl(Features,
"invpcid",
true);
186 setFeatureEnabledImpl(Features,
"movbe",
true);
189 setFeatureEnabledImpl(Features,
"rdrnd",
true);
190 setFeatureEnabledImpl(Features,
"f16c",
true);
191 setFeatureEnabledImpl(Features,
"fsgsbase",
true);
194 setFeatureEnabledImpl(Features,
"avx",
true);
195 setFeatureEnabledImpl(Features,
"xsave",
true);
196 setFeatureEnabledImpl(Features,
"xsaveopt",
true);
199 setFeatureEnabledImpl(Features,
"aes",
true);
200 setFeatureEnabledImpl(Features,
"pclmul",
true);
203 setFeatureEnabledImpl(Features,
"sse4.2",
true);
206 setFeatureEnabledImpl(Features,
"sse4.1",
true);
209 setFeatureEnabledImpl(Features,
"ssse3",
true);
210 setFeatureEnabledImpl(Features,
"sahf",
true);
215 setFeatureEnabledImpl(Features,
"sse3",
true);
216 setFeatureEnabledImpl(Features,
"cx16",
true);
221 setFeatureEnabledImpl(Features,
"sse2",
true);
225 setFeatureEnabledImpl(Features,
"sse",
true);
226 setFeatureEnabledImpl(Features,
"fxsr",
true);
230 setFeatureEnabledImpl(Features,
"cldemote",
true);
231 setFeatureEnabledImpl(Features,
"movdiri",
true);
232 setFeatureEnabledImpl(Features,
"movdir64b",
true);
233 setFeatureEnabledImpl(Features,
"gfni",
true);
234 setFeatureEnabledImpl(Features,
"waitpkg",
true);
236 case CK_GoldmontPlus:
237 setFeatureEnabledImpl(Features,
"ptwrite",
true);
238 setFeatureEnabledImpl(Features,
"rdpid",
true);
239 setFeatureEnabledImpl(Features,
"sgx",
true);
242 setFeatureEnabledImpl(Features,
"sha",
true);
243 setFeatureEnabledImpl(Features,
"rdseed",
true);
244 setFeatureEnabledImpl(Features,
"xsave",
true);
245 setFeatureEnabledImpl(Features,
"xsaveopt",
true);
246 setFeatureEnabledImpl(Features,
"xsavec",
true);
247 setFeatureEnabledImpl(Features,
"xsaves",
true);
248 setFeatureEnabledImpl(Features,
"clflushopt",
true);
249 setFeatureEnabledImpl(Features,
"mpx",
true);
250 setFeatureEnabledImpl(Features,
"fsgsbase",
true);
253 setFeatureEnabledImpl(Features,
"rdrnd",
true);
254 setFeatureEnabledImpl(Features,
"aes",
true);
255 setFeatureEnabledImpl(Features,
"pclmul",
true);
256 setFeatureEnabledImpl(Features,
"sse4.2",
true);
257 setFeatureEnabledImpl(Features,
"prfchw",
true);
260 setFeatureEnabledImpl(Features,
"movbe",
true);
261 setFeatureEnabledImpl(Features,
"ssse3",
true);
262 setFeatureEnabledImpl(Features,
"fxsr",
true);
263 setFeatureEnabledImpl(Features,
"cx16",
true);
264 setFeatureEnabledImpl(Features,
"sahf",
true);
269 setFeatureEnabledImpl(Features,
"avx512vpopcntdq",
true);
272 setFeatureEnabledImpl(Features,
"avx512f",
true);
273 setFeatureEnabledImpl(Features,
"avx512cd",
true);
274 setFeatureEnabledImpl(Features,
"avx512er",
true);
275 setFeatureEnabledImpl(Features,
"avx512pf",
true);
276 setFeatureEnabledImpl(Features,
"prfchw",
true);
277 setFeatureEnabledImpl(Features,
"prefetchwt1",
true);
278 setFeatureEnabledImpl(Features,
"fxsr",
true);
279 setFeatureEnabledImpl(Features,
"rdseed",
true);
280 setFeatureEnabledImpl(Features,
"adx",
true);
281 setFeatureEnabledImpl(Features,
"lzcnt",
true);
282 setFeatureEnabledImpl(Features,
"bmi",
true);
283 setFeatureEnabledImpl(Features,
"bmi2",
true);
284 setFeatureEnabledImpl(Features,
"rtm",
true);
285 setFeatureEnabledImpl(Features,
"fma",
true);
286 setFeatureEnabledImpl(Features,
"rdrnd",
true);
287 setFeatureEnabledImpl(Features,
"f16c",
true);
288 setFeatureEnabledImpl(Features,
"fsgsbase",
true);
289 setFeatureEnabledImpl(Features,
"aes",
true);
290 setFeatureEnabledImpl(Features,
"pclmul",
true);
291 setFeatureEnabledImpl(Features,
"cx16",
true);
292 setFeatureEnabledImpl(Features,
"xsaveopt",
true);
293 setFeatureEnabledImpl(Features,
"xsave",
true);
294 setFeatureEnabledImpl(Features,
"movbe",
true);
295 setFeatureEnabledImpl(Features,
"sahf",
true);
302 setFeatureEnabledImpl(Features,
"3dnow",
true);
306 setFeatureEnabledImpl(Features,
"sse4a",
true);
307 setFeatureEnabledImpl(Features,
"lzcnt",
true);
308 setFeatureEnabledImpl(Features,
"popcnt",
true);
309 setFeatureEnabledImpl(Features,
"sahf",
true);
312 setFeatureEnabledImpl(Features,
"sse3",
true);
315 setFeatureEnabledImpl(Features,
"sse2",
true);
318 setFeatureEnabledImpl(Features,
"sse",
true);
319 setFeatureEnabledImpl(Features,
"fxsr",
true);
323 setFeatureEnabledImpl(Features,
"3dnowa",
true);
327 setFeatureEnabledImpl(Features,
"avx",
true);
328 setFeatureEnabledImpl(Features,
"aes",
true);
329 setFeatureEnabledImpl(Features,
"pclmul",
true);
330 setFeatureEnabledImpl(Features,
"bmi",
true);
331 setFeatureEnabledImpl(Features,
"f16c",
true);
332 setFeatureEnabledImpl(Features,
"xsaveopt",
true);
333 setFeatureEnabledImpl(Features,
"movbe",
true);
336 setFeatureEnabledImpl(Features,
"ssse3",
true);
337 setFeatureEnabledImpl(Features,
"sse4a",
true);
338 setFeatureEnabledImpl(Features,
"lzcnt",
true);
339 setFeatureEnabledImpl(Features,
"popcnt",
true);
340 setFeatureEnabledImpl(Features,
"prfchw",
true);
341 setFeatureEnabledImpl(Features,
"cx16",
true);
342 setFeatureEnabledImpl(Features,
"fxsr",
true);
343 setFeatureEnabledImpl(Features,
"sahf",
true);
347 setFeatureEnabledImpl(Features,
"adx",
true);
348 setFeatureEnabledImpl(Features,
"aes",
true);
349 setFeatureEnabledImpl(Features,
"avx2",
true);
350 setFeatureEnabledImpl(Features,
"bmi",
true);
351 setFeatureEnabledImpl(Features,
"bmi2",
true);
352 setFeatureEnabledImpl(Features,
"clflushopt",
true);
353 setFeatureEnabledImpl(Features,
"clzero",
true);
354 setFeatureEnabledImpl(Features,
"cx16",
true);
355 setFeatureEnabledImpl(Features,
"f16c",
true);
356 setFeatureEnabledImpl(Features,
"fma",
true);
357 setFeatureEnabledImpl(Features,
"fsgsbase",
true);
358 setFeatureEnabledImpl(Features,
"fxsr",
true);
359 setFeatureEnabledImpl(Features,
"lzcnt",
true);
360 setFeatureEnabledImpl(Features,
"mwaitx",
true);
361 setFeatureEnabledImpl(Features,
"movbe",
true);
362 setFeatureEnabledImpl(Features,
"pclmul",
true);
363 setFeatureEnabledImpl(Features,
"popcnt",
true);
364 setFeatureEnabledImpl(Features,
"prfchw",
true);
365 setFeatureEnabledImpl(Features,
"rdrnd",
true);
366 setFeatureEnabledImpl(Features,
"rdseed",
true);
367 setFeatureEnabledImpl(Features,
"sahf",
true);
368 setFeatureEnabledImpl(Features,
"sha",
true);
369 setFeatureEnabledImpl(Features,
"sse4a",
true);
370 setFeatureEnabledImpl(Features,
"xsave",
true);
371 setFeatureEnabledImpl(Features,
"xsavec",
true);
372 setFeatureEnabledImpl(Features,
"xsaveopt",
true);
373 setFeatureEnabledImpl(Features,
"xsaves",
true);
377 setFeatureEnabledImpl(Features,
"avx2",
true);
378 setFeatureEnabledImpl(Features,
"bmi2",
true);
379 setFeatureEnabledImpl(Features,
"mwaitx",
true);
382 setFeatureEnabledImpl(Features,
"fsgsbase",
true);
383 setFeatureEnabledImpl(Features,
"xsaveopt",
true);
386 setFeatureEnabledImpl(Features,
"bmi",
true);
387 setFeatureEnabledImpl(Features,
"fma",
true);
388 setFeatureEnabledImpl(Features,
"f16c",
true);
389 setFeatureEnabledImpl(Features,
"tbm",
true);
393 setFeatureEnabledImpl(Features,
"xop",
true);
394 setFeatureEnabledImpl(Features,
"lwp",
true);
395 setFeatureEnabledImpl(Features,
"lzcnt",
true);
396 setFeatureEnabledImpl(Features,
"aes",
true);
397 setFeatureEnabledImpl(Features,
"pclmul",
true);
398 setFeatureEnabledImpl(Features,
"prfchw",
true);
399 setFeatureEnabledImpl(Features,
"cx16",
true);
400 setFeatureEnabledImpl(Features,
"fxsr",
true);
401 setFeatureEnabledImpl(Features,
"xsave",
true);
402 setFeatureEnabledImpl(Features,
"sahf",
true);
412 auto I = Features.find(
"sse4.2");
413 if (I != Features.end() && I->getValue() &&
414 std::find(FeaturesVec.begin(), FeaturesVec.end(),
"-popcnt") ==
416 Features[
"popcnt"] =
true;
419 I = Features.find(
"3dnow");
420 if (I != Features.end() && I->getValue() &&
421 std::find(FeaturesVec.begin(), FeaturesVec.end(),
"-prfchw") ==
423 Features[
"prfchw"] =
true;
427 I = Features.find(
"sse");
428 if (I != Features.end() && I->getValue() &&
429 std::find(FeaturesVec.begin(), FeaturesVec.end(),
"-mmx") ==
431 Features[
"mmx"] =
true;
437 X86SSEEnum
Level,
bool Enabled) {
441 Features[
"avx512f"] = Features[
"fma"] = Features[
"f16c"] =
true;
444 Features[
"avx2"] =
true;
447 Features[
"avx"] =
true;
448 Features[
"xsave"] =
true;
451 Features[
"sse4.2"] =
true;
454 Features[
"sse4.1"] =
true;
457 Features[
"ssse3"] =
true;
460 Features[
"sse3"] =
true;
463 Features[
"sse2"] =
true;
466 Features[
"sse"] =
true;
477 Features[
"sse"] =
false;
480 Features[
"sse2"] = Features[
"pclmul"] = Features[
"aes"] = Features[
"sha"] =
481 Features[
"gfni"] =
false;
484 Features[
"sse3"] =
false;
485 setXOPLevel(Features, NoXOP,
false);
488 Features[
"ssse3"] =
false;
491 Features[
"sse4.1"] =
false;
494 Features[
"sse4.2"] =
false;
497 Features[
"fma"] = Features[
"avx"] = Features[
"f16c"] = Features[
"xsave"] =
498 Features[
"xsaveopt"] = Features[
"vaes"] = Features[
"vpclmulqdq"] =
false;
499 setXOPLevel(Features, FMA4,
false);
502 Features[
"avx2"] =
false;
505 Features[
"avx512f"] = Features[
"avx512cd"] = Features[
"avx512er"] =
506 Features[
"avx512pf"] = Features[
"avx512dq"] = Features[
"avx512bw"] =
507 Features[
"avx512vl"] = Features[
"avx512vbmi"] =
508 Features[
"avx512ifma"] = Features[
"avx512vpopcntdq"] =
509 Features[
"avx512bitalg"] = Features[
"avx512vnni"] =
510 Features[
"avx512vbmi2"] =
false;
516 MMX3DNowEnum
Level,
bool Enabled) {
520 Features[
"3dnowa"] =
true;
523 Features[
"3dnow"] =
true;
526 Features[
"mmx"] =
true;
537 Features[
"mmx"] =
false;
540 Features[
"3dnow"] =
false;
543 Features[
"3dnowa"] =
false;
553 Features[
"xop"] =
true;
556 Features[
"fma4"] =
true;
557 setSSELevel(Features, AVX,
true);
560 Features[
"sse4a"] =
true;
561 setSSELevel(Features, SSE3,
true);
572 Features[
"sse4a"] =
false;
575 Features[
"fma4"] =
false;
578 Features[
"xop"] =
false;
584 StringRef Name,
bool Enabled) {
589 Features[Name] = Enabled;
592 setMMXLevel(Features, MMX, Enabled);
593 }
else if (Name ==
"sse") {
594 setSSELevel(Features, SSE1, Enabled);
595 }
else if (Name ==
"sse2") {
596 setSSELevel(Features, SSE2, Enabled);
597 }
else if (Name ==
"sse3") {
598 setSSELevel(Features, SSE3, Enabled);
599 }
else if (Name ==
"ssse3") {
600 setSSELevel(Features, SSSE3, Enabled);
601 }
else if (Name ==
"sse4.2") {
602 setSSELevel(Features, SSE42, Enabled);
603 }
else if (Name ==
"sse4.1") {
604 setSSELevel(Features, SSE41, Enabled);
605 }
else if (Name ==
"3dnow") {
606 setMMXLevel(Features, AMD3DNow, Enabled);
607 }
else if (Name ==
"3dnowa") {
608 setMMXLevel(Features, AMD3DNowAthlon, Enabled);
609 }
else if (Name ==
"aes") {
611 setSSELevel(Features, SSE2, Enabled);
613 Features[
"vaes"] =
false;
614 }
else if (Name ==
"vaes") {
616 setSSELevel(Features, AVX, Enabled);
617 Features[
"aes"] =
true;
619 }
else if (Name ==
"pclmul") {
621 setSSELevel(Features, SSE2, Enabled);
623 Features[
"vpclmulqdq"] =
false;
624 }
else if (Name ==
"vpclmulqdq") {
626 setSSELevel(Features, AVX, Enabled);
627 Features[
"pclmul"] =
true;
629 }
else if (Name ==
"gfni") {
631 setSSELevel(Features, SSE2, Enabled);
632 }
else if (Name ==
"avx") {
633 setSSELevel(Features, AVX, Enabled);
634 }
else if (Name ==
"avx2") {
635 setSSELevel(Features, AVX2, Enabled);
636 }
else if (Name ==
"avx512f") {
637 setSSELevel(Features, AVX512F, Enabled);
638 }
else if (Name ==
"avx512cd" || Name ==
"avx512er" || Name ==
"avx512pf" ||
639 Name ==
"avx512dq" || Name ==
"avx512bw" || Name ==
"avx512vl" ||
640 Name ==
"avx512vbmi" || Name ==
"avx512ifma" ||
641 Name ==
"avx512vpopcntdq" || Name ==
"avx512bitalg" ||
642 Name ==
"avx512vnni" || Name ==
"avx512vbmi2") {
644 setSSELevel(Features, AVX512F, Enabled);
646 if ((Name.startswith(
"avx512vbmi") || Name ==
"avx512bitalg") && Enabled)
647 Features[
"avx512bw"] =
true;
649 if (Name ==
"avx512bw" && !Enabled)
650 Features[
"avx512vbmi"] = Features[
"avx512vbmi2"] =
651 Features[
"avx512bitalg"] =
false;
652 }
else if (Name ==
"fma") {
654 setSSELevel(Features, AVX, Enabled);
656 setSSELevel(Features, AVX512F, Enabled);
657 }
else if (Name ==
"fma4") {
658 setXOPLevel(Features, FMA4, Enabled);
659 }
else if (Name ==
"xop") {
660 setXOPLevel(Features, XOP, Enabled);
661 }
else if (Name ==
"sse4a") {
662 setXOPLevel(Features, SSE4A, Enabled);
663 }
else if (Name ==
"f16c") {
665 setSSELevel(Features, AVX, Enabled);
667 setSSELevel(Features, AVX512F, Enabled);
668 }
else if (Name ==
"sha") {
670 setSSELevel(Features, SSE2, Enabled);
671 }
else if (Name ==
"sse4") {
677 setSSELevel(Features, SSE42, Enabled);
679 setSSELevel(Features, SSE41, Enabled);
680 }
else if (Name ==
"xsave") {
682 Features[
"xsaveopt"] =
false;
683 }
else if (Name ==
"xsaveopt" || Name ==
"xsavec" || Name ==
"xsaves") {
685 Features[
"xsave"] =
true;
693 for (
const auto &Feature : Features) {
694 if (Feature[0] !=
'+')
697 if (Feature ==
"+aes") {
699 }
else if (Feature ==
"+vaes") {
701 }
else if (Feature ==
"+pclmul") {
703 }
else if (Feature ==
"+vpclmulqdq") {
704 HasVPCLMULQDQ =
true;
705 }
else if (Feature ==
"+lzcnt") {
707 }
else if (Feature ==
"+rdrnd") {
709 }
else if (Feature ==
"+fsgsbase") {
711 }
else if (Feature ==
"+bmi") {
713 }
else if (Feature ==
"+bmi2") {
715 }
else if (Feature ==
"+popcnt") {
717 }
else if (Feature ==
"+rtm") {
719 }
else if (Feature ==
"+prfchw") {
721 }
else if (Feature ==
"+rdseed") {
723 }
else if (Feature ==
"+adx") {
725 }
else if (Feature ==
"+tbm") {
727 }
else if (Feature ==
"+lwp") {
729 }
else if (Feature ==
"+fma") {
731 }
else if (Feature ==
"+f16c") {
733 }
else if (Feature ==
"+gfni") {
735 }
else if (Feature ==
"+avx512cd") {
737 }
else if (Feature ==
"+avx512vpopcntdq") {
738 HasAVX512VPOPCNTDQ =
true;
739 }
else if (Feature ==
"+avx512vnni") {
740 HasAVX512VNNI =
true;
741 }
else if (Feature ==
"+avx512er") {
743 }
else if (Feature ==
"+avx512pf") {
745 }
else if (Feature ==
"+avx512dq") {
747 }
else if (Feature ==
"+avx512bitalg") {
748 HasAVX512BITALG =
true;
749 }
else if (Feature ==
"+avx512bw") {
751 }
else if (Feature ==
"+avx512vl") {
753 }
else if (Feature ==
"+avx512vbmi") {
754 HasAVX512VBMI =
true;
755 }
else if (Feature ==
"+avx512vbmi2") {
756 HasAVX512VBMI2 =
true;
757 }
else if (Feature ==
"+avx512ifma") {
758 HasAVX512IFMA =
true;
759 }
else if (Feature ==
"+sha") {
761 }
else if (Feature ==
"+mpx") {
763 }
else if (Feature ==
"+shstk") {
765 }
else if (Feature ==
"+movbe") {
767 }
else if (Feature ==
"+sgx") {
769 }
else if (Feature ==
"+cx16") {
771 }
else if (Feature ==
"+fxsr") {
773 }
else if (Feature ==
"+xsave") {
775 }
else if (Feature ==
"+xsaveopt") {
777 }
else if (Feature ==
"+xsavec") {
779 }
else if (Feature ==
"+xsaves") {
781 }
else if (Feature ==
"+mwaitx") {
783 }
else if (Feature ==
"+pku") {
785 }
else if (Feature ==
"+clflushopt") {
786 HasCLFLUSHOPT =
true;
787 }
else if (Feature ==
"+clwb") {
789 }
else if (Feature ==
"+wbnoinvd") {
791 }
else if (Feature ==
"+prefetchwt1") {
792 HasPREFETCHWT1 =
true;
793 }
else if (Feature ==
"+clzero") {
795 }
else if (Feature ==
"+cldemote") {
797 }
else if (Feature ==
"+rdpid") {
799 }
else if (Feature ==
"+retpoline") {
801 }
else if (Feature ==
"+retpoline-external-thunk") {
802 HasRetpolineExternalThunk =
true;
803 }
else if (Feature ==
"+sahf") {
805 }
else if (Feature ==
"+waitpkg") {
807 }
else if (Feature ==
"+movdiri") {
809 }
else if (Feature ==
"+movdir64b") {
811 }
else if (Feature ==
"+pconfig") {
813 }
else if (Feature ==
"+ptwrite") {
815 }
else if (Feature ==
"+invpcid") {
819 X86SSEEnum
Level = llvm::StringSwitch<X86SSEEnum>(Feature)
820 .Case(
"+avx512f", AVX512F)
823 .Case(
"+sse4.2", SSE42)
824 .Case(
"+sse4.1", SSE41)
825 .Case(
"+ssse3", SSSE3)
830 SSELevel =
std::max(SSELevel, Level);
832 MMX3DNowEnum ThreeDNowLevel = llvm::StringSwitch<MMX3DNowEnum>(Feature)
833 .Case(
"+3dnowa", AMD3DNowAthlon)
834 .Case(
"+3dnow", AMD3DNow)
836 .Default(NoMMX3DNow);
837 MMX3DNowLevel =
std::max(MMX3DNowLevel, ThreeDNowLevel);
839 XOPEnum XLevel = llvm::StringSwitch<XOPEnum>(Feature)
842 .Case(
"+sse4a", SSE4A)
844 XOPLevel =
std::max(XOPLevel, XLevel);
849 if ((FPMath == FP_SSE && SSELevel < SSE1) ||
850 (FPMath == FP_387 && SSELevel >= SSE1)) {
851 Diags.
Report(diag::err_target_unsupported_fpmath)
852 << (FPMath == FP_SSE ?
"sse" :
"387");
866 if (getTriple().getArch() == llvm::Triple::x86_64) {
871 if (getTriple().getArchName() ==
"x86_64h") {
937 case CK_GoldmontPlus:
949 case CK_SkylakeClient:
950 case CK_SkylakeServer:
952 case CK_IcelakeClient:
953 case CK_IcelakeServer:
974 if (CPU != CK_K6_2) {
988 if (SSELevel != NoSSE) {
1111 if (HasAVX512VPOPCNTDQ)
1121 if (HasAVX512BITALG)
1217 if (Opts.MicrosoftExt && getTriple().getArch() == llvm::Triple::x86) {
1239 switch (MMX3DNowLevel) {
1240 case AMD3DNowAthlon:
1253 if (CPU >= CK_i486) {
1254 Builder.
defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
1255 Builder.
defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
1256 Builder.
defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
1259 Builder.
defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
1261 Builder.
defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16");
1268 return llvm::StringSwitch<bool>(Name)
1269 .Case(
"3dnow",
true)
1270 .Case(
"3dnowa",
true)
1275 .Case(
"avx512f",
true)
1276 .Case(
"avx512cd",
true)
1277 .Case(
"avx512vpopcntdq",
true)
1278 .Case(
"avx512vnni",
true)
1279 .Case(
"avx512er",
true)
1280 .Case(
"avx512pf",
true)
1281 .Case(
"avx512dq",
true)
1282 .Case(
"avx512bitalg",
true)
1283 .Case(
"avx512bw",
true)
1284 .Case(
"avx512vl",
true)
1285 .Case(
"avx512vbmi",
true)
1286 .Case(
"avx512vbmi2",
true)
1287 .Case(
"avx512ifma",
true)
1290 .Case(
"cldemote",
true)
1291 .Case(
"clflushopt",
true)
1293 .Case(
"clzero",
true)
1298 .Case(
"fsgsbase",
true)
1301 .Case(
"invpcid",
true)
1303 .Case(
"lzcnt",
true)
1305 .Case(
"movbe",
true)
1306 .Case(
"movdiri",
true)
1307 .Case(
"movdir64b",
true)
1309 .Case(
"mwaitx",
true)
1310 .Case(
"pclmul",
true)
1311 .Case(
"pconfig",
true)
1313 .Case(
"popcnt",
true)
1314 .Case(
"prefetchwt1",
true)
1315 .Case(
"prfchw",
true)
1316 .Case(
"ptwrite",
true)
1317 .Case(
"rdpid",
true)
1318 .Case(
"rdrnd",
true)
1319 .Case(
"rdseed",
true)
1324 .Case(
"shstk",
true)
1328 .Case(
"ssse3",
true)
1330 .Case(
"sse4.1",
true)
1331 .Case(
"sse4.2",
true)
1332 .Case(
"sse4a",
true)
1335 .Case(
"vpclmulqdq",
true)
1336 .Case(
"wbnoinvd",
true)
1337 .Case(
"waitpkg",
true)
1340 .Case(
"xsave",
true)
1341 .Case(
"xsavec",
true)
1342 .Case(
"xsaves",
true)
1343 .Case(
"xsaveopt",
true)
1348 return llvm::StringSwitch<bool>(Feature)
1349 .Case(
"adx", HasADX)
1350 .Case(
"aes", HasAES)
1351 .Case(
"avx", SSELevel >= AVX)
1352 .Case(
"avx2", SSELevel >= AVX2)
1353 .Case(
"avx512f", SSELevel >= AVX512F)
1354 .Case(
"avx512cd", HasAVX512CD)
1355 .Case(
"avx512vpopcntdq", HasAVX512VPOPCNTDQ)
1356 .Case(
"avx512vnni", HasAVX512VNNI)
1357 .Case(
"avx512er", HasAVX512ER)
1358 .Case(
"avx512pf", HasAVX512PF)
1359 .Case(
"avx512dq", HasAVX512DQ)
1360 .Case(
"avx512bitalg", HasAVX512BITALG)
1361 .Case(
"avx512bw", HasAVX512BW)
1362 .Case(
"avx512vl", HasAVX512VL)
1363 .Case(
"avx512vbmi", HasAVX512VBMI)
1364 .Case(
"avx512vbmi2", HasAVX512VBMI2)
1365 .Case(
"avx512ifma", HasAVX512IFMA)
1366 .Case(
"bmi", HasBMI)
1367 .Case(
"bmi2", HasBMI2)
1368 .Case(
"cldemote", HasCLDEMOTE)
1369 .Case(
"clflushopt", HasCLFLUSHOPT)
1370 .Case(
"clwb", HasCLWB)
1371 .Case(
"clzero", HasCLZERO)
1372 .Case(
"cx16", HasCX16)
1373 .Case(
"f16c", HasF16C)
1374 .Case(
"fma", HasFMA)
1375 .Case(
"fma4", XOPLevel >= FMA4)
1376 .Case(
"fsgsbase", HasFSGSBASE)
1377 .Case(
"fxsr", HasFXSR)
1378 .Case(
"gfni", HasGFNI)
1379 .Case(
"invpcid", HasINVPCID)
1380 .Case(
"lwp", HasLWP)
1381 .Case(
"lzcnt", HasLZCNT)
1382 .Case(
"mm3dnow", MMX3DNowLevel >= AMD3DNow)
1383 .Case(
"mm3dnowa", MMX3DNowLevel >= AMD3DNowAthlon)
1384 .Case(
"mmx", MMX3DNowLevel >= MMX)
1385 .Case(
"movbe", HasMOVBE)
1386 .Case(
"movdiri", HasMOVDIRI)
1387 .Case(
"movdir64b", HasMOVDIR64B)
1388 .Case(
"mpx", HasMPX)
1389 .Case(
"mwaitx", HasMWAITX)
1390 .Case(
"pclmul", HasPCLMUL)
1391 .Case(
"pconfig", HasPCONFIG)
1392 .Case(
"pku", HasPKU)
1393 .Case(
"popcnt", HasPOPCNT)
1394 .Case(
"prefetchwt1", HasPREFETCHWT1)
1395 .Case(
"prfchw", HasPRFCHW)
1396 .Case(
"ptwrite", HasPTWRITE)
1397 .Case(
"rdpid", HasRDPID)
1398 .Case(
"rdrnd", HasRDRND)
1399 .Case(
"rdseed", HasRDSEED)
1400 .Case(
"retpoline", HasRetpoline)
1401 .Case(
"retpoline-external-thunk", HasRetpolineExternalThunk)
1402 .Case(
"rtm", HasRTM)
1403 .Case(
"sahf", HasLAHFSAHF)
1404 .Case(
"sgx", HasSGX)
1405 .Case(
"sha", HasSHA)
1406 .Case(
"shstk", HasSHSTK)
1407 .Case(
"sse", SSELevel >= SSE1)
1408 .Case(
"sse2", SSELevel >= SSE2)
1409 .Case(
"sse3", SSELevel >= SSE3)
1410 .Case(
"ssse3", SSELevel >= SSSE3)
1411 .Case(
"sse4.1", SSELevel >= SSE41)
1412 .Case(
"sse4.2", SSELevel >= SSE42)
1413 .Case(
"sse4a", XOPLevel >= SSE4A)
1414 .Case(
"tbm", HasTBM)
1415 .Case(
"vaes", HasVAES)
1416 .Case(
"vpclmulqdq", HasVPCLMULQDQ)
1417 .Case(
"wbnoinvd", HasWBNOINVD)
1418 .Case(
"waitpkg", HasWAITPKG)
1420 .Case(
"x86_32", getTriple().getArch() == llvm::Triple::x86)
1421 .Case(
"x86_64", getTriple().getArch() == llvm::Triple::x86_64)
1422 .Case(
"xop", XOPLevel >= XOP)
1423 .Case(
"xsave", HasXSAVE)
1424 .Case(
"xsavec", HasXSAVEC)
1425 .Case(
"xsaves", HasXSAVES)
1426 .Case(
"xsaveopt", HasXSAVEOPT)
1436 return llvm::StringSwitch<bool>(FeatureStr)
1438 #include "llvm/Support/X86TargetParser.def" 1443 return llvm::StringSwitch<llvm::X86::ProcessorFeatures>(Name)
1445 #include "llvm/Support/X86TargetParser.def" 1452 enum class FeatPriority {
1453 #define FEATURE(FEAT) FEAT, 1454 #include "clang/Basic/X86Target.def" 1457 #define FEATURE(FEAT) \ 1458 case llvm::X86::FEAT: \ 1459 return static_cast<unsigned>(FeatPriority::FEAT); 1460 #include "clang/Basic/X86Target.def" 1462 llvm_unreachable(
"No Feature Priority for non-CPUSupports Features");
1470 if (Kind != CK_Generic) {
1474 "CPU Type without a key feature used in 'target' attribute");
1475 #define PROC_WITH_FEAT(ENUM, STR, IS64, KEY_FEAT) \ 1477 return (getFeaturePriority(llvm::X86::KEY_FEAT) << 1) + 1; 1478 #include "clang/Basic/X86Target.def" 1488 return llvm::StringSwitch<bool>(Name)
1489 #define
CPU_SPECIFIC(NAME, MANGLING, FEATURES) .Case(NAME,
true)
1490 #define CPU_SPECIFIC_ALIAS(NEW_NAME, NAME) .Case(NEW_NAME, true) 1491 #include "clang/Basic/X86Target.def" 1496 return llvm::StringSwitch<StringRef>(Name)
1498 #include "clang/Basic/X86Target.def" 1504 #define
CPU_SPECIFIC(NAME, MANGLING, FEATURES) .Case(NAME, MANGLING)
1505 #include "clang/Basic/X86Target.def" 1511 StringRef WholeList =
1513 #define
CPU_SPECIFIC(NAME, MANGLING, FEATURES) .Case(NAME, FEATURES)
1514 #include "clang/Basic/X86Target.def" 1516 WholeList.split(Features,
',', -1,
false);
1523 #define PROC(ENUM, STRING, IS64BIT) \ 1526 #include "clang/Basic/X86Target.def" 1528 llvm_unreachable(
"Invalid CPUKind");
1536 return llvm::StringSwitch<bool>(FeatureStr)
1537 #define
X86_VENDOR(ENUM, STRING) .Case(STRING,
true)
1538 #define X86_CPU_TYPE_COMPAT_WITH_ALIAS(ARCHNAME, ENUM, STR, ALIAS) \ 1539 .Cases(STR, ALIAS, true) 1540 #define X86_CPU_TYPE_COMPAT(ARCHNAME, ENUM, STR) .Case(STR, true) 1541 #define X86_CPU_SUBTYPE_COMPAT(ARCHNAME, ENUM, STR) .Case(STR, true) 1542 #include "llvm/Support/X86TargetParser.def" 1632 unsigned Size)
const {
1634 while (Constraint[0] ==
'=' || Constraint[0] ==
'+' || Constraint[0] ==
'&')
1635 Constraint = Constraint.substr(1);
1637 return validateOperandSize(Constraint, Size);
1641 unsigned Size)
const {
1642 return validateOperandSize(Constraint, Size);
1646 unsigned Size)
const {
1647 switch (Constraint[0]) {
1660 switch (Constraint[1]) {
1670 if (SSELevel >= SSE1)
1671 return Size <= 128U;
1677 if (SSELevel < SSE2)
1683 if (SSELevel >= AVX512F)
1685 return Size <= 512U;
1686 else if (SSELevel >= AVX)
1688 return Size <= 256U;
1689 return Size <= 128U;
1697 switch (*Constraint) {
1699 return std::string(
"{ax}");
1701 return std::string(
"{bx}");
1703 return std::string(
"{cx}");
1705 return std::string(
"{dx}");
1707 return std::string(
"{si}");
1709 return std::string(
"{di}");
1711 return std::string(
"im");
1713 return std::string(
"{st}");
1715 return std::string(
"{st(1)}");
1717 switch (Constraint[1]) {
1733 return std::string(
"^") + std::string(Constraint++, 2);
1737 return std::string(1, *Constraint);
1748 #define PROC(ENUM, STRING, IS64BIT) \ 1750 return IS64BIT || getTriple().getArch() == llvm::Triple::x86; 1751 #include "clang/Basic/X86Target.def" 1753 llvm_unreachable(
"Unhandled CPU kind");
1757 #define PROC(ENUM, STRING, IS64BIT) \ 1758 if (IS64BIT || getTriple().getArch() == llvm::Triple::x86) \ 1759 Values.emplace_back(STRING); 1762 #define PROC_ALIAS(ENUM, ALIAS) \ 1763 if (checkCPUKind(getCPUKind(ALIAS))) \ 1764 Values.emplace_back(ALIAS); 1765 #include "clang/Basic/X86Target.def" 1769 return llvm::StringSwitch<CPUKind>(CPU)
1770 #define
PROC(ENUM, STRING, IS64BIT) .Case(STRING, CK_##ENUM)
1771 #define PROC_ALIAS(ENUM, ALIAS) .Case(ALIAS, CK_##ENUM) 1772 #include "clang/Basic/X86Target.def" 1773 .Default(CK_Generic);
void DefineStd(MacroBuilder &Builder, StringRef MacroName, const LangOptions &Opts)
DefineStd - Define a macro name and standard variants.
static bool hasFeature(StringRef Feature, const LangOptions &LangOpts, const TargetInfo &Target)
Determine whether a translation unit built using the current language options has the given feature...
bool setFPMath(StringRef Name) override
Use the specified unit for FP math.
const Builtin::Info BuiltinInfoX86[]
static void setMMXLevel(llvm::StringMap< bool > &Features, MMX3DNowEnum Level, bool Enabled)
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
bool validateOutputSize(StringRef Constraint, unsigned Size) const override
ArrayRef< TargetInfo::AddlRegName > getGCCAddlRegNames() const override
void setRequiresImmediate(int Min, int Max)
virtual bool validateOperandSize(StringRef Constraint, unsigned Size) const
void fillValidCPUList(SmallVectorImpl< StringRef > &Values) const override
Fill a SmallVectorImpl with the valid values to setCPU.
std::string getCPUKindCanonicalName(CPUKind Kind) const
static void setXOPLevel(llvm::StringMap< bool > &Features, XOPEnum Level, bool Enabled)
const TargetInfo::AddlRegName AddlRegNames[]
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
bool validateCpuSupports(StringRef Name) const override
void getCPUSpecificCPUDispatchFeatures(StringRef Name, llvm::SmallVectorImpl< StringRef > &Features) const override
#define X86_FEATURE_COMPAT(VAL, ENUM, STR)
Concrete class used by the front-end to report problems and issues.
Defines the Diagnostic-related interfaces.
static llvm::X86::ProcessorFeatures getFeature(StringRef Name)
#define CPU_SPECIFIC_ALIAS(NEW_NAME, NAME)
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &info) const override
static const char *const GCCRegNames[]
bool validateCPUSpecificCPUDispatch(StringRef Name) const override
bool isValidFeatureName(StringRef Name) const override
Determine whether this TargetInfo supports the given feature.
#define X86_VENDOR(ENUM, STRING)
virtual bool initFeatureMap(llvm::StringMap< bool > &Features, DiagnosticsEngine &Diags, StringRef CPU, const std::vector< std::string > &FeatureVec) const
Initialize the map with the default set of target features for the CPU this should include all legal ...
static StringRef CPUSpecificCPUDispatchNameDealias(StringRef Name)
std::string ConstraintStr
CPUKind getCPUKind(StringRef CPU) const
bool hasFeature(StringRef Feature) const override
Determine whether the given target has the given feature.
static void setSSELevel(llvm::StringMap< bool > &Features, X86SSEEnum Level, bool Enabled)
Enumerates target-specific builtins in their own namespaces within namespace clang.
CPUKind
Enumeration of all of the X86 CPUs supported by Clang.
ArrayRef< Builtin::Info > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
static unsigned getFeaturePriority(llvm::X86::ProcessorFeatures Feat)
std::string convertConstraint(const char *&Constraint) const override
ArrayRef< Builtin::Info > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
char CPUSpecificManglingCharacter(StringRef Name) const override
Dataflow Directional Tag Classes.
unsigned multiVersionSortPriority(StringRef Name) const override
#define CPU_SPECIFIC(NAME, MANGLING, FEATURES)
bool handleTargetFeatures(std::vector< std::string > &Features, DiagnosticsEngine &Diags) override
handleTargetFeatures - Perform initialization based on the user configured set of features...
bool validateInputSize(StringRef Constraint, unsigned Size) const override
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
X86TargetInfo::getTargetDefines - Return the set of the X86-specific macro definitions for this parti...
#define PROC(ENUM, STRING, IS64BIT)
__DEVICE__ int max(int __a, int __b)
bool checkCPUKind(CPUKind Kind) const
void defineCPUMacros(MacroBuilder &Builder, StringRef CPUName, bool Tuning)
void defineMacro(const Twine &Name, const Twine &Value="1")
Append a #define line for macro of the form "\#define Name Value\n".
static void setFeatureEnabledImpl(llvm::StringMap< bool > &Features, StringRef Name, bool Enabled)
bool validateCpuIs(StringRef Name) const override
ArrayRef< const char * > getGCCRegNames() const override
Defines enum values for all the target-independent builtin functions.
bool initFeatureMap(llvm::StringMap< bool > &Features, DiagnosticsEngine &Diags, StringRef CPU, const std::vector< std::string > &FeaturesVec) const override
Initialize the map with the default set of target features for the CPU this should include all legal ...