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,
"avx512vbmi2",
true);
146 setFeatureEnabledImpl(Features,
"avx512vpopcntdq",
true);
147 setFeatureEnabledImpl(Features,
"rdpid",
true);
150 setFeatureEnabledImpl(Features,
"avx512ifma",
true);
151 setFeatureEnabledImpl(Features,
"avx512vbmi",
true);
152 setFeatureEnabledImpl(Features,
"sha",
true);
156 if (Kind != CK_Cannonlake)
158 setFeatureEnabledImpl(Features,
"avx512vnni",
true);
160 case CK_SkylakeServer:
161 setFeatureEnabledImpl(Features,
"avx512f",
true);
162 setFeatureEnabledImpl(Features,
"avx512cd",
true);
163 setFeatureEnabledImpl(Features,
"avx512dq",
true);
164 setFeatureEnabledImpl(Features,
"avx512bw",
true);
165 setFeatureEnabledImpl(Features,
"avx512vl",
true);
166 setFeatureEnabledImpl(Features,
"pku",
true);
167 if (Kind != CK_Cannonlake)
168 setFeatureEnabledImpl(Features,
"clwb",
true);
170 case CK_SkylakeClient:
171 setFeatureEnabledImpl(Features,
"xsavec",
true);
172 setFeatureEnabledImpl(Features,
"xsaves",
true);
173 setFeatureEnabledImpl(Features,
"mpx",
true);
174 if (Kind != CK_SkylakeServer
175 && Kind != CK_Cascadelake)
177 setFeatureEnabledImpl(Features,
"sgx",
true);
178 setFeatureEnabledImpl(Features,
"clflushopt",
true);
179 setFeatureEnabledImpl(Features,
"aes",
true);
182 setFeatureEnabledImpl(Features,
"rdseed",
true);
183 setFeatureEnabledImpl(Features,
"adx",
true);
184 setFeatureEnabledImpl(Features,
"prfchw",
true);
187 setFeatureEnabledImpl(Features,
"avx2",
true);
188 setFeatureEnabledImpl(Features,
"lzcnt",
true);
189 setFeatureEnabledImpl(Features,
"bmi",
true);
190 setFeatureEnabledImpl(Features,
"bmi2",
true);
191 setFeatureEnabledImpl(Features,
"fma",
true);
192 setFeatureEnabledImpl(Features,
"invpcid",
true);
193 setFeatureEnabledImpl(Features,
"movbe",
true);
196 setFeatureEnabledImpl(Features,
"rdrnd",
true);
197 setFeatureEnabledImpl(Features,
"f16c",
true);
198 setFeatureEnabledImpl(Features,
"fsgsbase",
true);
201 setFeatureEnabledImpl(Features,
"avx",
true);
202 setFeatureEnabledImpl(Features,
"xsave",
true);
203 setFeatureEnabledImpl(Features,
"xsaveopt",
true);
206 setFeatureEnabledImpl(Features,
"pclmul",
true);
209 setFeatureEnabledImpl(Features,
"sse4.2",
true);
212 setFeatureEnabledImpl(Features,
"sse4.1",
true);
215 setFeatureEnabledImpl(Features,
"ssse3",
true);
216 setFeatureEnabledImpl(Features,
"sahf",
true);
221 setFeatureEnabledImpl(Features,
"sse3",
true);
222 setFeatureEnabledImpl(Features,
"cx16",
true);
227 setFeatureEnabledImpl(Features,
"sse2",
true);
231 setFeatureEnabledImpl(Features,
"sse",
true);
232 setFeatureEnabledImpl(Features,
"fxsr",
true);
236 setFeatureEnabledImpl(Features,
"cldemote",
true);
237 setFeatureEnabledImpl(Features,
"movdiri",
true);
238 setFeatureEnabledImpl(Features,
"movdir64b",
true);
239 setFeatureEnabledImpl(Features,
"gfni",
true);
240 setFeatureEnabledImpl(Features,
"waitpkg",
true);
242 case CK_GoldmontPlus:
243 setFeatureEnabledImpl(Features,
"ptwrite",
true);
244 setFeatureEnabledImpl(Features,
"rdpid",
true);
245 setFeatureEnabledImpl(Features,
"sgx",
true);
248 setFeatureEnabledImpl(Features,
"sha",
true);
249 setFeatureEnabledImpl(Features,
"rdseed",
true);
250 setFeatureEnabledImpl(Features,
"xsave",
true);
251 setFeatureEnabledImpl(Features,
"xsaveopt",
true);
252 setFeatureEnabledImpl(Features,
"xsavec",
true);
253 setFeatureEnabledImpl(Features,
"xsaves",
true);
254 setFeatureEnabledImpl(Features,
"clflushopt",
true);
255 setFeatureEnabledImpl(Features,
"mpx",
true);
256 setFeatureEnabledImpl(Features,
"fsgsbase",
true);
257 setFeatureEnabledImpl(Features,
"aes",
true);
260 setFeatureEnabledImpl(Features,
"rdrnd",
true);
261 setFeatureEnabledImpl(Features,
"pclmul",
true);
262 setFeatureEnabledImpl(Features,
"sse4.2",
true);
263 setFeatureEnabledImpl(Features,
"prfchw",
true);
266 setFeatureEnabledImpl(Features,
"movbe",
true);
267 setFeatureEnabledImpl(Features,
"ssse3",
true);
268 setFeatureEnabledImpl(Features,
"fxsr",
true);
269 setFeatureEnabledImpl(Features,
"cx16",
true);
270 setFeatureEnabledImpl(Features,
"sahf",
true);
275 setFeatureEnabledImpl(Features,
"avx512vpopcntdq",
true);
278 setFeatureEnabledImpl(Features,
"avx512f",
true);
279 setFeatureEnabledImpl(Features,
"avx512cd",
true);
280 setFeatureEnabledImpl(Features,
"avx512er",
true);
281 setFeatureEnabledImpl(Features,
"avx512pf",
true);
282 setFeatureEnabledImpl(Features,
"prfchw",
true);
283 setFeatureEnabledImpl(Features,
"prefetchwt1",
true);
284 setFeatureEnabledImpl(Features,
"fxsr",
true);
285 setFeatureEnabledImpl(Features,
"rdseed",
true);
286 setFeatureEnabledImpl(Features,
"adx",
true);
287 setFeatureEnabledImpl(Features,
"lzcnt",
true);
288 setFeatureEnabledImpl(Features,
"bmi",
true);
289 setFeatureEnabledImpl(Features,
"bmi2",
true);
290 setFeatureEnabledImpl(Features,
"fma",
true);
291 setFeatureEnabledImpl(Features,
"rdrnd",
true);
292 setFeatureEnabledImpl(Features,
"f16c",
true);
293 setFeatureEnabledImpl(Features,
"fsgsbase",
true);
294 setFeatureEnabledImpl(Features,
"aes",
true);
295 setFeatureEnabledImpl(Features,
"pclmul",
true);
296 setFeatureEnabledImpl(Features,
"cx16",
true);
297 setFeatureEnabledImpl(Features,
"xsaveopt",
true);
298 setFeatureEnabledImpl(Features,
"xsave",
true);
299 setFeatureEnabledImpl(Features,
"movbe",
true);
300 setFeatureEnabledImpl(Features,
"sahf",
true);
307 setFeatureEnabledImpl(Features,
"3dnow",
true);
311 setFeatureEnabledImpl(Features,
"sse4a",
true);
312 setFeatureEnabledImpl(Features,
"lzcnt",
true);
313 setFeatureEnabledImpl(Features,
"popcnt",
true);
314 setFeatureEnabledImpl(Features,
"sahf",
true);
317 setFeatureEnabledImpl(Features,
"sse3",
true);
320 setFeatureEnabledImpl(Features,
"sse2",
true);
323 setFeatureEnabledImpl(Features,
"sse",
true);
324 setFeatureEnabledImpl(Features,
"fxsr",
true);
328 setFeatureEnabledImpl(Features,
"3dnowa",
true);
332 setFeatureEnabledImpl(Features,
"avx",
true);
333 setFeatureEnabledImpl(Features,
"aes",
true);
334 setFeatureEnabledImpl(Features,
"pclmul",
true);
335 setFeatureEnabledImpl(Features,
"bmi",
true);
336 setFeatureEnabledImpl(Features,
"f16c",
true);
337 setFeatureEnabledImpl(Features,
"xsaveopt",
true);
338 setFeatureEnabledImpl(Features,
"movbe",
true);
341 setFeatureEnabledImpl(Features,
"ssse3",
true);
342 setFeatureEnabledImpl(Features,
"sse4a",
true);
343 setFeatureEnabledImpl(Features,
"lzcnt",
true);
344 setFeatureEnabledImpl(Features,
"popcnt",
true);
345 setFeatureEnabledImpl(Features,
"prfchw",
true);
346 setFeatureEnabledImpl(Features,
"cx16",
true);
347 setFeatureEnabledImpl(Features,
"fxsr",
true);
348 setFeatureEnabledImpl(Features,
"sahf",
true);
352 setFeatureEnabledImpl(Features,
"adx",
true);
353 setFeatureEnabledImpl(Features,
"aes",
true);
354 setFeatureEnabledImpl(Features,
"avx2",
true);
355 setFeatureEnabledImpl(Features,
"bmi",
true);
356 setFeatureEnabledImpl(Features,
"bmi2",
true);
357 setFeatureEnabledImpl(Features,
"clflushopt",
true);
358 setFeatureEnabledImpl(Features,
"clzero",
true);
359 setFeatureEnabledImpl(Features,
"cx16",
true);
360 setFeatureEnabledImpl(Features,
"f16c",
true);
361 setFeatureEnabledImpl(Features,
"fma",
true);
362 setFeatureEnabledImpl(Features,
"fsgsbase",
true);
363 setFeatureEnabledImpl(Features,
"fxsr",
true);
364 setFeatureEnabledImpl(Features,
"lzcnt",
true);
365 setFeatureEnabledImpl(Features,
"mwaitx",
true);
366 setFeatureEnabledImpl(Features,
"movbe",
true);
367 setFeatureEnabledImpl(Features,
"pclmul",
true);
368 setFeatureEnabledImpl(Features,
"popcnt",
true);
369 setFeatureEnabledImpl(Features,
"prfchw",
true);
370 setFeatureEnabledImpl(Features,
"rdrnd",
true);
371 setFeatureEnabledImpl(Features,
"rdseed",
true);
372 setFeatureEnabledImpl(Features,
"sahf",
true);
373 setFeatureEnabledImpl(Features,
"sha",
true);
374 setFeatureEnabledImpl(Features,
"sse4a",
true);
375 setFeatureEnabledImpl(Features,
"xsave",
true);
376 setFeatureEnabledImpl(Features,
"xsavec",
true);
377 setFeatureEnabledImpl(Features,
"xsaveopt",
true);
378 setFeatureEnabledImpl(Features,
"xsaves",
true);
382 setFeatureEnabledImpl(Features,
"avx2",
true);
383 setFeatureEnabledImpl(Features,
"bmi2",
true);
384 setFeatureEnabledImpl(Features,
"mwaitx",
true);
387 setFeatureEnabledImpl(Features,
"fsgsbase",
true);
388 setFeatureEnabledImpl(Features,
"xsaveopt",
true);
391 setFeatureEnabledImpl(Features,
"bmi",
true);
392 setFeatureEnabledImpl(Features,
"fma",
true);
393 setFeatureEnabledImpl(Features,
"f16c",
true);
394 setFeatureEnabledImpl(Features,
"tbm",
true);
398 setFeatureEnabledImpl(Features,
"xop",
true);
399 setFeatureEnabledImpl(Features,
"lwp",
true);
400 setFeatureEnabledImpl(Features,
"lzcnt",
true);
401 setFeatureEnabledImpl(Features,
"aes",
true);
402 setFeatureEnabledImpl(Features,
"pclmul",
true);
403 setFeatureEnabledImpl(Features,
"prfchw",
true);
404 setFeatureEnabledImpl(Features,
"cx16",
true);
405 setFeatureEnabledImpl(Features,
"fxsr",
true);
406 setFeatureEnabledImpl(Features,
"xsave",
true);
407 setFeatureEnabledImpl(Features,
"sahf",
true);
417 auto I = Features.find(
"sse4.2");
418 if (I != Features.end() && I->getValue() &&
419 std::find(FeaturesVec.begin(), FeaturesVec.end(),
"-popcnt") ==
421 Features[
"popcnt"] =
true;
424 I = Features.find(
"3dnow");
425 if (I != Features.end() && I->getValue() &&
426 std::find(FeaturesVec.begin(), FeaturesVec.end(),
"-prfchw") ==
428 Features[
"prfchw"] =
true;
432 I = Features.find(
"sse");
433 if (I != Features.end() && I->getValue() &&
434 std::find(FeaturesVec.begin(), FeaturesVec.end(),
"-mmx") ==
436 Features[
"mmx"] =
true;
442 X86SSEEnum
Level,
bool Enabled) {
446 Features[
"avx512f"] = Features[
"fma"] = Features[
"f16c"] =
true;
449 Features[
"avx2"] =
true;
452 Features[
"avx"] =
true;
453 Features[
"xsave"] =
true;
456 Features[
"sse4.2"] =
true;
459 Features[
"sse4.1"] =
true;
462 Features[
"ssse3"] =
true;
465 Features[
"sse3"] =
true;
468 Features[
"sse2"] =
true;
471 Features[
"sse"] =
true;
482 Features[
"sse"] =
false;
485 Features[
"sse2"] = Features[
"pclmul"] = Features[
"aes"] = Features[
"sha"] =
486 Features[
"gfni"] =
false;
489 Features[
"sse3"] =
false;
490 setXOPLevel(Features, NoXOP,
false);
493 Features[
"ssse3"] =
false;
496 Features[
"sse4.1"] =
false;
499 Features[
"sse4.2"] =
false;
502 Features[
"fma"] = Features[
"avx"] = Features[
"f16c"] = Features[
"xsave"] =
503 Features[
"xsaveopt"] = Features[
"vaes"] = Features[
"vpclmulqdq"] =
false;
504 setXOPLevel(Features, FMA4,
false);
507 Features[
"avx2"] =
false;
510 Features[
"avx512f"] = Features[
"avx512cd"] = Features[
"avx512er"] =
511 Features[
"avx512pf"] = Features[
"avx512dq"] = Features[
"avx512bw"] =
512 Features[
"avx512vl"] = Features[
"avx512vbmi"] =
513 Features[
"avx512ifma"] = Features[
"avx512vpopcntdq"] =
514 Features[
"avx512bitalg"] = Features[
"avx512vnni"] =
515 Features[
"avx512vbmi2"] =
false;
521 MMX3DNowEnum
Level,
bool Enabled) {
525 Features[
"3dnowa"] =
true;
528 Features[
"3dnow"] =
true;
531 Features[
"mmx"] =
true;
542 Features[
"mmx"] =
false;
545 Features[
"3dnow"] =
false;
548 Features[
"3dnowa"] =
false;
558 Features[
"xop"] =
true;
561 Features[
"fma4"] =
true;
562 setSSELevel(Features, AVX,
true);
565 Features[
"sse4a"] =
true;
566 setSSELevel(Features, SSE3,
true);
577 Features[
"sse4a"] =
false;
580 Features[
"fma4"] =
false;
583 Features[
"xop"] =
false;
589 StringRef Name,
bool Enabled) {
594 Features[Name] = Enabled;
597 setMMXLevel(Features, MMX, Enabled);
598 }
else if (Name ==
"sse") {
599 setSSELevel(Features, SSE1, Enabled);
600 }
else if (Name ==
"sse2") {
601 setSSELevel(Features, SSE2, Enabled);
602 }
else if (Name ==
"sse3") {
603 setSSELevel(Features, SSE3, Enabled);
604 }
else if (Name ==
"ssse3") {
605 setSSELevel(Features, SSSE3, Enabled);
606 }
else if (Name ==
"sse4.2") {
607 setSSELevel(Features, SSE42, Enabled);
608 }
else if (Name ==
"sse4.1") {
609 setSSELevel(Features, SSE41, Enabled);
610 }
else if (Name ==
"3dnow") {
611 setMMXLevel(Features, AMD3DNow, Enabled);
612 }
else if (Name ==
"3dnowa") {
613 setMMXLevel(Features, AMD3DNowAthlon, Enabled);
614 }
else if (Name ==
"aes") {
616 setSSELevel(Features, SSE2, Enabled);
618 Features[
"vaes"] =
false;
619 }
else if (Name ==
"vaes") {
621 setSSELevel(Features, AVX, Enabled);
622 Features[
"aes"] =
true;
624 }
else if (Name ==
"pclmul") {
626 setSSELevel(Features, SSE2, Enabled);
628 Features[
"vpclmulqdq"] =
false;
629 }
else if (Name ==
"vpclmulqdq") {
631 setSSELevel(Features, AVX, Enabled);
632 Features[
"pclmul"] =
true;
634 }
else if (Name ==
"gfni") {
636 setSSELevel(Features, SSE2, Enabled);
637 }
else if (Name ==
"avx") {
638 setSSELevel(Features, AVX, Enabled);
639 }
else if (Name ==
"avx2") {
640 setSSELevel(Features, AVX2, Enabled);
641 }
else if (Name ==
"avx512f") {
642 setSSELevel(Features, AVX512F, Enabled);
643 }
else if (Name ==
"avx512cd" || Name ==
"avx512er" || Name ==
"avx512pf" ||
644 Name ==
"avx512dq" || Name ==
"avx512bw" || Name ==
"avx512vl" ||
645 Name ==
"avx512vbmi" || Name ==
"avx512ifma" ||
646 Name ==
"avx512vpopcntdq" || Name ==
"avx512bitalg" ||
647 Name ==
"avx512vnni" || Name ==
"avx512vbmi2") {
649 setSSELevel(Features, AVX512F, Enabled);
651 if ((Name.startswith(
"avx512vbmi") || Name ==
"avx512bitalg") && Enabled)
652 Features[
"avx512bw"] =
true;
654 if (Name ==
"avx512bw" && !Enabled)
655 Features[
"avx512vbmi"] = Features[
"avx512vbmi2"] =
656 Features[
"avx512bitalg"] =
false;
657 }
else if (Name ==
"fma") {
659 setSSELevel(Features, AVX, Enabled);
661 setSSELevel(Features, AVX512F, Enabled);
662 }
else if (Name ==
"fma4") {
663 setXOPLevel(Features, FMA4, Enabled);
664 }
else if (Name ==
"xop") {
665 setXOPLevel(Features, XOP, Enabled);
666 }
else if (Name ==
"sse4a") {
667 setXOPLevel(Features, SSE4A, Enabled);
668 }
else if (Name ==
"f16c") {
670 setSSELevel(Features, AVX, Enabled);
672 setSSELevel(Features, AVX512F, Enabled);
673 }
else if (Name ==
"sha") {
675 setSSELevel(Features, SSE2, Enabled);
676 }
else if (Name ==
"sse4") {
682 setSSELevel(Features, SSE42, Enabled);
684 setSSELevel(Features, SSE41, Enabled);
685 }
else if (Name ==
"xsave") {
687 Features[
"xsaveopt"] =
false;
688 }
else if (Name ==
"xsaveopt" || Name ==
"xsavec" || Name ==
"xsaves") {
690 Features[
"xsave"] =
true;
698 for (
const auto &Feature : Features) {
699 if (Feature[0] !=
'+')
702 if (Feature ==
"+aes") {
704 }
else if (Feature ==
"+vaes") {
706 }
else if (Feature ==
"+pclmul") {
708 }
else if (Feature ==
"+vpclmulqdq") {
709 HasVPCLMULQDQ =
true;
710 }
else if (Feature ==
"+lzcnt") {
712 }
else if (Feature ==
"+rdrnd") {
714 }
else if (Feature ==
"+fsgsbase") {
716 }
else if (Feature ==
"+bmi") {
718 }
else if (Feature ==
"+bmi2") {
720 }
else if (Feature ==
"+popcnt") {
722 }
else if (Feature ==
"+rtm") {
724 }
else if (Feature ==
"+prfchw") {
726 }
else if (Feature ==
"+rdseed") {
728 }
else if (Feature ==
"+adx") {
730 }
else if (Feature ==
"+tbm") {
732 }
else if (Feature ==
"+lwp") {
734 }
else if (Feature ==
"+fma") {
736 }
else if (Feature ==
"+f16c") {
738 }
else if (Feature ==
"+gfni") {
740 }
else if (Feature ==
"+avx512cd") {
742 }
else if (Feature ==
"+avx512vpopcntdq") {
743 HasAVX512VPOPCNTDQ =
true;
744 }
else if (Feature ==
"+avx512vnni") {
745 HasAVX512VNNI =
true;
746 }
else if (Feature ==
"+avx512er") {
748 }
else if (Feature ==
"+avx512pf") {
750 }
else if (Feature ==
"+avx512dq") {
752 }
else if (Feature ==
"+avx512bitalg") {
753 HasAVX512BITALG =
true;
754 }
else if (Feature ==
"+avx512bw") {
756 }
else if (Feature ==
"+avx512vl") {
758 }
else if (Feature ==
"+avx512vbmi") {
759 HasAVX512VBMI =
true;
760 }
else if (Feature ==
"+avx512vbmi2") {
761 HasAVX512VBMI2 =
true;
762 }
else if (Feature ==
"+avx512ifma") {
763 HasAVX512IFMA =
true;
764 }
else if (Feature ==
"+sha") {
766 }
else if (Feature ==
"+mpx") {
768 }
else if (Feature ==
"+shstk") {
770 }
else if (Feature ==
"+movbe") {
772 }
else if (Feature ==
"+sgx") {
774 }
else if (Feature ==
"+cx16") {
776 }
else if (Feature ==
"+fxsr") {
778 }
else if (Feature ==
"+xsave") {
780 }
else if (Feature ==
"+xsaveopt") {
782 }
else if (Feature ==
"+xsavec") {
784 }
else if (Feature ==
"+xsaves") {
786 }
else if (Feature ==
"+mwaitx") {
788 }
else if (Feature ==
"+pku") {
790 }
else if (Feature ==
"+clflushopt") {
791 HasCLFLUSHOPT =
true;
792 }
else if (Feature ==
"+clwb") {
794 }
else if (Feature ==
"+wbnoinvd") {
796 }
else if (Feature ==
"+prefetchwt1") {
797 HasPREFETCHWT1 =
true;
798 }
else if (Feature ==
"+clzero") {
800 }
else if (Feature ==
"+cldemote") {
802 }
else if (Feature ==
"+rdpid") {
804 }
else if (Feature ==
"+retpoline-external-thunk") {
805 HasRetpolineExternalThunk =
true;
806 }
else if (Feature ==
"+sahf") {
808 }
else if (Feature ==
"+waitpkg") {
810 }
else if (Feature ==
"+movdiri") {
812 }
else if (Feature ==
"+movdir64b") {
814 }
else if (Feature ==
"+pconfig") {
816 }
else if (Feature ==
"+ptwrite") {
818 }
else if (Feature ==
"+invpcid") {
822 X86SSEEnum
Level = llvm::StringSwitch<X86SSEEnum>(Feature)
823 .Case(
"+avx512f", AVX512F)
826 .Case(
"+sse4.2", SSE42)
827 .Case(
"+sse4.1", SSE41)
828 .Case(
"+ssse3", SSSE3)
833 SSELevel =
std::max(SSELevel, Level);
835 MMX3DNowEnum ThreeDNowLevel = llvm::StringSwitch<MMX3DNowEnum>(Feature)
836 .Case(
"+3dnowa", AMD3DNowAthlon)
837 .Case(
"+3dnow", AMD3DNow)
839 .Default(NoMMX3DNow);
840 MMX3DNowLevel =
std::max(MMX3DNowLevel, ThreeDNowLevel);
842 XOPEnum XLevel = llvm::StringSwitch<XOPEnum>(Feature)
845 .Case(
"+sse4a", SSE4A)
847 XOPLevel =
std::max(XOPLevel, XLevel);
852 if ((FPMath == FP_SSE && SSELevel < SSE1) ||
853 (FPMath == FP_387 && SSELevel >= SSE1)) {
854 Diags.
Report(diag::err_target_unsupported_fpmath)
855 << (FPMath == FP_SSE ?
"sse" :
"387");
868 std::string CodeModel = getTargetOpts().CodeModel;
869 if (CodeModel ==
"default")
871 Builder.
defineMacro(
"__code_model_" + CodeModel +
"_");
874 if (getTriple().getArch() == llvm::Triple::x86_64) {
879 if (getTriple().getArchName() ==
"x86_64h") {
945 case CK_GoldmontPlus:
957 case CK_SkylakeClient:
958 case CK_SkylakeServer:
961 case CK_IcelakeClient:
962 case CK_IcelakeServer:
983 if (CPU != CK_K6_2) {
997 if (SSELevel != NoSSE) {
1123 if (HasAVX512VPOPCNTDQ)
1133 if (HasAVX512BITALG)
1229 if (Opts.MicrosoftExt && getTriple().getArch() == llvm::Triple::x86) {
1251 switch (MMX3DNowLevel) {
1252 case AMD3DNowAthlon:
1265 if (CPU >= CK_i486) {
1266 Builder.
defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
1267 Builder.
defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
1268 Builder.
defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
1271 Builder.
defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
1273 Builder.
defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16");
1280 return llvm::StringSwitch<bool>(Name)
1281 .Case(
"3dnow",
true)
1282 .Case(
"3dnowa",
true)
1287 .Case(
"avx512f",
true)
1288 .Case(
"avx512cd",
true)
1289 .Case(
"avx512vpopcntdq",
true)
1290 .Case(
"avx512vnni",
true)
1291 .Case(
"avx512er",
true)
1292 .Case(
"avx512pf",
true)
1293 .Case(
"avx512dq",
true)
1294 .Case(
"avx512bitalg",
true)
1295 .Case(
"avx512bw",
true)
1296 .Case(
"avx512vl",
true)
1297 .Case(
"avx512vbmi",
true)
1298 .Case(
"avx512vbmi2",
true)
1299 .Case(
"avx512ifma",
true)
1302 .Case(
"cldemote",
true)
1303 .Case(
"clflushopt",
true)
1305 .Case(
"clzero",
true)
1310 .Case(
"fsgsbase",
true)
1313 .Case(
"invpcid",
true)
1315 .Case(
"lzcnt",
true)
1317 .Case(
"movbe",
true)
1318 .Case(
"movdiri",
true)
1319 .Case(
"movdir64b",
true)
1321 .Case(
"mwaitx",
true)
1322 .Case(
"pclmul",
true)
1323 .Case(
"pconfig",
true)
1325 .Case(
"popcnt",
true)
1326 .Case(
"prefetchwt1",
true)
1327 .Case(
"prfchw",
true)
1328 .Case(
"ptwrite",
true)
1329 .Case(
"rdpid",
true)
1330 .Case(
"rdrnd",
true)
1331 .Case(
"rdseed",
true)
1336 .Case(
"shstk",
true)
1340 .Case(
"ssse3",
true)
1342 .Case(
"sse4.1",
true)
1343 .Case(
"sse4.2",
true)
1344 .Case(
"sse4a",
true)
1347 .Case(
"vpclmulqdq",
true)
1348 .Case(
"wbnoinvd",
true)
1349 .Case(
"waitpkg",
true)
1352 .Case(
"xsave",
true)
1353 .Case(
"xsavec",
true)
1354 .Case(
"xsaves",
true)
1355 .Case(
"xsaveopt",
true)
1360 return llvm::StringSwitch<bool>(Feature)
1361 .Case(
"adx", HasADX)
1362 .Case(
"aes", HasAES)
1363 .Case(
"avx", SSELevel >= AVX)
1364 .Case(
"avx2", SSELevel >= AVX2)
1365 .Case(
"avx512f", SSELevel >= AVX512F)
1366 .Case(
"avx512cd", HasAVX512CD)
1367 .Case(
"avx512vpopcntdq", HasAVX512VPOPCNTDQ)
1368 .Case(
"avx512vnni", HasAVX512VNNI)
1369 .Case(
"avx512er", HasAVX512ER)
1370 .Case(
"avx512pf", HasAVX512PF)
1371 .Case(
"avx512dq", HasAVX512DQ)
1372 .Case(
"avx512bitalg", HasAVX512BITALG)
1373 .Case(
"avx512bw", HasAVX512BW)
1374 .Case(
"avx512vl", HasAVX512VL)
1375 .Case(
"avx512vbmi", HasAVX512VBMI)
1376 .Case(
"avx512vbmi2", HasAVX512VBMI2)
1377 .Case(
"avx512ifma", HasAVX512IFMA)
1378 .Case(
"bmi", HasBMI)
1379 .Case(
"bmi2", HasBMI2)
1380 .Case(
"cldemote", HasCLDEMOTE)
1381 .Case(
"clflushopt", HasCLFLUSHOPT)
1382 .Case(
"clwb", HasCLWB)
1383 .Case(
"clzero", HasCLZERO)
1384 .Case(
"cx16", HasCX16)
1385 .Case(
"f16c", HasF16C)
1386 .Case(
"fma", HasFMA)
1387 .Case(
"fma4", XOPLevel >= FMA4)
1388 .Case(
"fsgsbase", HasFSGSBASE)
1389 .Case(
"fxsr", HasFXSR)
1390 .Case(
"gfni", HasGFNI)
1391 .Case(
"invpcid", HasINVPCID)
1392 .Case(
"lwp", HasLWP)
1393 .Case(
"lzcnt", HasLZCNT)
1394 .Case(
"mm3dnow", MMX3DNowLevel >= AMD3DNow)
1395 .Case(
"mm3dnowa", MMX3DNowLevel >= AMD3DNowAthlon)
1396 .Case(
"mmx", MMX3DNowLevel >= MMX)
1397 .Case(
"movbe", HasMOVBE)
1398 .Case(
"movdiri", HasMOVDIRI)
1399 .Case(
"movdir64b", HasMOVDIR64B)
1400 .Case(
"mpx", HasMPX)
1401 .Case(
"mwaitx", HasMWAITX)
1402 .Case(
"pclmul", HasPCLMUL)
1403 .Case(
"pconfig", HasPCONFIG)
1404 .Case(
"pku", HasPKU)
1405 .Case(
"popcnt", HasPOPCNT)
1406 .Case(
"prefetchwt1", HasPREFETCHWT1)
1407 .Case(
"prfchw", HasPRFCHW)
1408 .Case(
"ptwrite", HasPTWRITE)
1409 .Case(
"rdpid", HasRDPID)
1410 .Case(
"rdrnd", HasRDRND)
1411 .Case(
"rdseed", HasRDSEED)
1412 .Case(
"retpoline-external-thunk", HasRetpolineExternalThunk)
1413 .Case(
"rtm", HasRTM)
1414 .Case(
"sahf", HasLAHFSAHF)
1415 .Case(
"sgx", HasSGX)
1416 .Case(
"sha", HasSHA)
1417 .Case(
"shstk", HasSHSTK)
1418 .Case(
"sse", SSELevel >= SSE1)
1419 .Case(
"sse2", SSELevel >= SSE2)
1420 .Case(
"sse3", SSELevel >= SSE3)
1421 .Case(
"ssse3", SSELevel >= SSSE3)
1422 .Case(
"sse4.1", SSELevel >= SSE41)
1423 .Case(
"sse4.2", SSELevel >= SSE42)
1424 .Case(
"sse4a", XOPLevel >= SSE4A)
1425 .Case(
"tbm", HasTBM)
1426 .Case(
"vaes", HasVAES)
1427 .Case(
"vpclmulqdq", HasVPCLMULQDQ)
1428 .Case(
"wbnoinvd", HasWBNOINVD)
1429 .Case(
"waitpkg", HasWAITPKG)
1431 .Case(
"x86_32", getTriple().getArch() == llvm::Triple::x86)
1432 .Case(
"x86_64", getTriple().getArch() == llvm::Triple::x86_64)
1433 .Case(
"xop", XOPLevel >= XOP)
1434 .Case(
"xsave", HasXSAVE)
1435 .Case(
"xsavec", HasXSAVEC)
1436 .Case(
"xsaves", HasXSAVES)
1437 .Case(
"xsaveopt", HasXSAVEOPT)
1447 return llvm::StringSwitch<bool>(FeatureStr)
1449 #include "llvm/Support/X86TargetParser.def" 1454 return llvm::StringSwitch<llvm::X86::ProcessorFeatures>(Name)
1456 #include "llvm/Support/X86TargetParser.def" 1463 enum class FeatPriority {
1464 #define FEATURE(FEAT) FEAT, 1465 #include "clang/Basic/X86Target.def" 1468 #define FEATURE(FEAT) \ 1469 case llvm::X86::FEAT: \ 1470 return static_cast<unsigned>(FeatPriority::FEAT); 1471 #include "clang/Basic/X86Target.def" 1473 llvm_unreachable(
"No Feature Priority for non-CPUSupports Features");
1481 if (Kind != CK_Generic) {
1485 "CPU Type without a key feature used in 'target' attribute");
1486 #define PROC_WITH_FEAT(ENUM, STR, IS64, KEY_FEAT) \ 1488 return (getFeaturePriority(llvm::X86::KEY_FEAT) << 1) + 1; 1489 #include "clang/Basic/X86Target.def" 1499 return llvm::StringSwitch<bool>(Name)
1500 #define
CPU_SPECIFIC(NAME, MANGLING, FEATURES) .Case(NAME,
true)
1501 #define CPU_SPECIFIC_ALIAS(NEW_NAME, NAME) .Case(NEW_NAME, true) 1502 #include "clang/Basic/X86Target.def" 1507 return llvm::StringSwitch<StringRef>(Name)
1509 #include "clang/Basic/X86Target.def" 1515 #define
CPU_SPECIFIC(NAME, MANGLING, FEATURES) .Case(NAME, MANGLING)
1516 #include "clang/Basic/X86Target.def" 1522 StringRef WholeList =
1524 #define
CPU_SPECIFIC(NAME, MANGLING, FEATURES) .Case(NAME, FEATURES)
1525 #include "clang/Basic/X86Target.def" 1527 WholeList.split(Features,
',', -1,
false);
1534 #define PROC(ENUM, STRING, IS64BIT) \ 1537 #include "clang/Basic/X86Target.def" 1539 llvm_unreachable(
"Invalid CPUKind");
1547 return llvm::StringSwitch<bool>(FeatureStr)
1548 #define
X86_VENDOR(ENUM, STRING) .Case(STRING,
true)
1549 #define X86_CPU_TYPE_COMPAT_WITH_ALIAS(ARCHNAME, ENUM, STR, ALIAS) \ 1550 .Cases(STR, ALIAS, true) 1551 #define X86_CPU_TYPE_COMPAT(ARCHNAME, ENUM, STR) .Case(STR, true) 1552 #define X86_CPU_SUBTYPE_COMPAT(ARCHNAME, ENUM, STR) .Case(STR, true) 1553 #include "llvm/Support/X86TargetParser.def" 1643 unsigned Size)
const {
1645 while (Constraint[0] ==
'=' || Constraint[0] ==
'+' || Constraint[0] ==
'&')
1646 Constraint = Constraint.substr(1);
1648 return validateOperandSize(Constraint, Size);
1652 unsigned Size)
const {
1653 return validateOperandSize(Constraint, Size);
1657 unsigned Size)
const {
1658 switch (Constraint[0]) {
1671 switch (Constraint[1]) {
1681 if (SSELevel >= SSE1)
1682 return Size <= 128U;
1688 if (SSELevel < SSE2)
1695 if (SSELevel >= AVX512F)
1697 return Size <= 512U;
1698 else if (SSELevel >= AVX)
1700 return Size <= 256U;
1701 return Size <= 128U;
1709 switch (*Constraint) {
1711 return std::string(
"{ax}");
1713 return std::string(
"{bx}");
1715 return std::string(
"{cx}");
1717 return std::string(
"{dx}");
1719 return std::string(
"{si}");
1721 return std::string(
"{di}");
1723 return std::string(
"im");
1725 return std::string(
"{st}");
1727 return std::string(
"{st(1)}");
1729 switch (Constraint[1]) {
1745 return std::string(
"^") + std::string(Constraint++, 2);
1749 return std::string(1, *Constraint);
1760 #define PROC(ENUM, STRING, IS64BIT) \ 1762 return IS64BIT || getTriple().getArch() == llvm::Triple::x86; 1763 #include "clang/Basic/X86Target.def" 1765 llvm_unreachable(
"Unhandled CPU kind");
1769 #define PROC(ENUM, STRING, IS64BIT) \ 1770 if (IS64BIT || getTriple().getArch() == llvm::Triple::x86) \ 1771 Values.emplace_back(STRING); 1774 #define PROC_ALIAS(ENUM, ALIAS) \ 1775 if (checkCPUKind(getCPUKind(ALIAS))) \ 1776 Values.emplace_back(ALIAS); 1777 #include "clang/Basic/X86Target.def" 1781 return llvm::StringSwitch<CPUKind>(CPU)
1782 #define
PROC(ENUM, STRING, IS64BIT) .Case(STRING, CK_##ENUM)
1783 #define PROC_ALIAS(ENUM, ALIAS) .Case(ALIAS, CK_##ENUM) 1784 #include "clang/Basic/X86Target.def" 1785 .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 ...