17#include "llvm/ADT/StringRef.h"
18#include "llvm/ADT/StringSwitch.h"
19#include "llvm/TargetParser/X86TargetParser.h"
34#define GET_BUILTIN_STR_TABLE
35#include "clang/Basic/BuiltinsX86.inc"
36#undef GET_BUILTIN_STR_TABLE
39#define GET_BUILTIN_INFOS
40#include "clang/Basic/BuiltinsX86.inc"
41#undef GET_BUILTIN_INFOS
45#define GET_BUILTIN_PREFIXED_INFOS
46#include "clang/Basic/BuiltinsX86.inc"
47#undef GET_BUILTIN_PREFIXED_INFOS
54#define GET_BUILTIN_STR_TABLE
55#include "clang/Basic/BuiltinsX86_64.inc"
56#undef GET_BUILTIN_STR_TABLE
59#define GET_BUILTIN_INFOS
60#include "clang/Basic/BuiltinsX86_64.inc"
61#undef GET_BUILTIN_INFOS
65#define GET_BUILTIN_PREFIXED_INFOS
66#include "clang/Basic/BuiltinsX86_64.inc"
67#undef GET_BUILTIN_PREFIXED_INFOS
74 "ax",
"dx",
"cx",
"bx",
"si",
"di",
"bp",
"sp",
75 "st",
"st(1)",
"st(2)",
"st(3)",
"st(4)",
"st(5)",
"st(6)",
"st(7)",
76 "argp",
"flags",
"fpcr",
"fpsr",
"dirflag",
"frame",
"xmm0",
"xmm1",
77 "xmm2",
"xmm3",
"xmm4",
"xmm5",
"xmm6",
"xmm7",
"mm0",
"mm1",
78 "mm2",
"mm3",
"mm4",
"mm5",
"mm6",
"mm7",
"r8",
"r9",
79 "r10",
"r11",
"r12",
"r13",
"r14",
"r15",
"xmm8",
"xmm9",
80 "xmm10",
"xmm11",
"xmm12",
"xmm13",
"xmm14",
"xmm15",
"ymm0",
"ymm1",
81 "ymm2",
"ymm3",
"ymm4",
"ymm5",
"ymm6",
"ymm7",
"ymm8",
"ymm9",
82 "ymm10",
"ymm11",
"ymm12",
"ymm13",
"ymm14",
"ymm15",
"xmm16",
"xmm17",
83 "xmm18",
"xmm19",
"xmm20",
"xmm21",
"xmm22",
"xmm23",
"xmm24",
"xmm25",
84 "xmm26",
"xmm27",
"xmm28",
"xmm29",
"xmm30",
"xmm31",
"ymm16",
"ymm17",
85 "ymm18",
"ymm19",
"ymm20",
"ymm21",
"ymm22",
"ymm23",
"ymm24",
"ymm25",
86 "ymm26",
"ymm27",
"ymm28",
"ymm29",
"ymm30",
"ymm31",
"zmm0",
"zmm1",
87 "zmm2",
"zmm3",
"zmm4",
"zmm5",
"zmm6",
"zmm7",
"zmm8",
"zmm9",
88 "zmm10",
"zmm11",
"zmm12",
"zmm13",
"zmm14",
"zmm15",
"zmm16",
"zmm17",
89 "zmm18",
"zmm19",
"zmm20",
"zmm21",
"zmm22",
"zmm23",
"zmm24",
"zmm25",
90 "zmm26",
"zmm27",
"zmm28",
"zmm29",
"zmm30",
"zmm31",
"k0",
"k1",
91 "k2",
"k3",
"k4",
"k5",
"k6",
"k7",
92 "cr0",
"cr2",
"cr3",
"cr4",
"cr8",
93 "dr0",
"dr1",
"dr2",
"dr3",
"dr6",
"dr7",
94 "bnd0",
"bnd1",
"bnd2",
"bnd3",
95 "tmm0",
"tmm1",
"tmm2",
"tmm3",
"tmm4",
"tmm5",
"tmm6",
"tmm7",
96 "r16",
"r17",
"r18",
"r19",
"r20",
"r21",
"r22",
"r23",
97 "r24",
"r25",
"r26",
"r27",
"r28",
"r29",
"r30",
"r31",
101 {{
"al",
"ah",
"eax",
"rax"}, 0},
102 {{
"bl",
"bh",
"ebx",
"rbx"}, 3},
103 {{
"cl",
"ch",
"ecx",
"rcx"}, 2},
104 {{
"dl",
"dh",
"edx",
"rdx"}, 1},
109 {{
"r8d",
"r8w",
"r8b"}, 38},
110 {{
"r9d",
"r9w",
"r9b"}, 39},
111 {{
"r10d",
"r10w",
"r10b"}, 40},
112 {{
"r11d",
"r11w",
"r11b"}, 41},
113 {{
"r12d",
"r12w",
"r12b"}, 42},
114 {{
"r13d",
"r13w",
"r13b"}, 43},
115 {{
"r14d",
"r14w",
"r14b"}, 44},
116 {{
"r15d",
"r15w",
"r15b"}, 45},
117 {{
"r16d",
"r16w",
"r16b"}, 165},
118 {{
"r17d",
"r17w",
"r17b"}, 166},
119 {{
"r18d",
"r18w",
"r18b"}, 167},
120 {{
"r19d",
"r19w",
"r19b"}, 168},
121 {{
"r20d",
"r20w",
"r20b"}, 169},
122 {{
"r21d",
"r21w",
"r21b"}, 170},
123 {{
"r22d",
"r22w",
"r22b"}, 171},
124 {{
"r23d",
"r23w",
"r23b"}, 172},
125 {{
"r24d",
"r24w",
"r24b"}, 173},
126 {{
"r25d",
"r25w",
"r25b"}, 174},
127 {{
"r26d",
"r26w",
"r26b"}, 175},
128 {{
"r27d",
"r27w",
"r27b"}, 176},
129 {{
"r28d",
"r28w",
"r28b"}, 177},
130 {{
"r29d",
"r29w",
"r29b"}, 178},
131 {{
"r30d",
"r30w",
"r30b"}, 179},
132 {{
"r31d",
"r31w",
"r31b"}, 180},
137using namespace clang;
154 const std::vector<std::string> &FeaturesVec)
const {
157 if (
getTriple().getArch() == llvm::Triple::x86_64)
160 using namespace llvm::X86;
163 getFeaturesForCPU(
CPU, CPUFeatures);
164 for (
auto &F : CPUFeatures)
167 std::vector<std::string> UpdatedFeaturesVec;
168 for (
const auto &
Feature : FeaturesVec) {
170 if (
Feature ==
"+general-regs-only") {
171 UpdatedFeaturesVec.push_back(
"-x87");
172 UpdatedFeaturesVec.push_back(
"-mmx");
173 UpdatedFeaturesVec.push_back(
"-sse");
179 for (
const char *Sub :
180 {
"egpr",
"push2pop2",
"ppx",
"ndd",
"ccmp",
"nf",
"zu",
"jmpabs"})
181 UpdatedFeaturesVec.push_back(Sign + std::string(Sub));
185 UpdatedFeaturesVec.push_back(
Feature);
195 auto I = Features.find(
"sse4.2");
196 if (I != Features.end() && I->getValue() &&
197 !llvm::is_contained(UpdatedFeaturesVec,
"-popcnt"))
198 Features[
"popcnt"] =
true;
202 I = Features.find(
"sse");
203 if (I != Features.end() && I->getValue() &&
204 !llvm::is_contained(UpdatedFeaturesVec,
"-mmx"))
205 Features[
"mmx"] =
true;
208 I = Features.find(
"avx");
209 if (I != Features.end() && I->getValue() &&
210 !llvm::is_contained(UpdatedFeaturesVec,
"-xsave"))
211 Features[
"xsave"] =
true;
214 I = Features.find(
"sse4.2");
215 if (I != Features.end() && I->getValue() &&
216 !llvm::is_contained(UpdatedFeaturesVec,
"-crc32"))
217 Features[
"crc32"] =
true;
223 StringRef Name,
bool Enabled)
const {
224 if (Name ==
"sse4") {
235 Features[Name] = Enabled;
236 llvm::X86::updateImpliedFeatures(Name, Enabled, Features);
243 for (
const auto &
Feature : Features) {
249 }
else if (
Feature ==
"+aes") {
251 }
else if (
Feature ==
"+vaes") {
253 }
else if (
Feature ==
"+pclmul") {
255 }
else if (
Feature ==
"+vpclmulqdq") {
256 HasVPCLMULQDQ =
true;
257 }
else if (
Feature ==
"+lzcnt") {
259 }
else if (
Feature ==
"+rdrnd") {
261 }
else if (
Feature ==
"+fsgsbase") {
263 }
else if (
Feature ==
"+bmi") {
265 }
else if (
Feature ==
"+bmi2") {
267 }
else if (
Feature ==
"+popcnt") {
269 }
else if (
Feature ==
"+rtm") {
271 }
else if (
Feature ==
"+prfchw") {
273 }
else if (
Feature ==
"+rdseed") {
275 }
else if (
Feature ==
"+adx") {
277 }
else if (
Feature ==
"+tbm") {
279 }
else if (
Feature ==
"+lwp") {
281 }
else if (
Feature ==
"+fma") {
283 }
else if (
Feature ==
"+f16c") {
285 }
else if (
Feature ==
"+gfni") {
287 }
else if (
Feature ==
"+avx10.1") {
289 }
else if (
Feature ==
"+avx10.2") {
292 }
else if (
Feature ==
"+avx10v2aux") {
293 HasAVX10_V2_AUX =
true;
294 }
else if (
Feature ==
"+avx512cd") {
296 }
else if (
Feature ==
"+avx512vpopcntdq") {
297 HasAVX512VPOPCNTDQ =
true;
298 }
else if (
Feature ==
"+avx512vnni") {
299 HasAVX512VNNI =
true;
300 }
else if (
Feature ==
"+avx512bf16") {
301 HasAVX512BF16 =
true;
302 }
else if (
Feature ==
"+avx512fp16") {
303 HasAVX512FP16 =
true;
305 }
else if (
Feature ==
"+avx512dq") {
307 }
else if (
Feature ==
"+avx512bitalg") {
308 HasAVX512BITALG =
true;
309 }
else if (
Feature ==
"+avx512bmm") {
311 }
else if (
Feature ==
"+avx512bw") {
313 }
else if (
Feature ==
"+avx512vl") {
315 }
else if (
Feature ==
"+avx512vbmi") {
316 HasAVX512VBMI =
true;
317 }
else if (
Feature ==
"+avx512vbmi2") {
318 HasAVX512VBMI2 =
true;
319 }
else if (
Feature ==
"+avx512ifma") {
320 HasAVX512IFMA =
true;
321 }
else if (
Feature ==
"+avx512vp2intersect") {
322 HasAVX512VP2INTERSECT =
true;
323 }
else if (
Feature ==
"+sha") {
325 }
else if (
Feature ==
"+sha512") {
327 }
else if (
Feature ==
"+shstk") {
329 }
else if (
Feature ==
"+sm3") {
331 }
else if (
Feature ==
"+sm4") {
333 }
else if (
Feature ==
"+movbe") {
335 }
else if (
Feature ==
"+movrs") {
337 }
else if (
Feature ==
"+sgx") {
339 }
else if (
Feature ==
"+cx8") {
341 }
else if (
Feature ==
"+cx16") {
343 }
else if (
Feature ==
"+fxsr") {
345 }
else if (
Feature ==
"+xsave") {
347 }
else if (
Feature ==
"+xsaveopt") {
349 }
else if (
Feature ==
"+xsavec") {
351 }
else if (
Feature ==
"+xsaves") {
353 }
else if (
Feature ==
"+mwaitx") {
355 }
else if (
Feature ==
"+pku") {
357 }
else if (
Feature ==
"+clflushopt") {
358 HasCLFLUSHOPT =
true;
359 }
else if (
Feature ==
"+clwb") {
361 }
else if (
Feature ==
"+wbnoinvd") {
363 }
else if (
Feature ==
"+prefetchi") {
365 }
else if (
Feature ==
"+clzero") {
367 }
else if (
Feature ==
"+cldemote") {
369 }
else if (
Feature ==
"+rdpid") {
371 }
else if (
Feature ==
"+rdpru") {
375 }
else if (
Feature ==
"+widekl") {
377 }
else if (
Feature ==
"+retpoline-external-thunk") {
378 HasRetpolineExternalThunk =
true;
379 }
else if (
Feature ==
"+sahf") {
381 }
else if (
Feature ==
"+waitpkg") {
383 }
else if (
Feature ==
"+movdiri") {
385 }
else if (
Feature ==
"+movdir64b") {
387 }
else if (
Feature ==
"+pconfig") {
389 }
else if (
Feature ==
"+ptwrite") {
391 }
else if (
Feature ==
"+invpcid") {
393 }
else if (
Feature ==
"+enqcmd") {
395 }
else if (
Feature ==
"+hreset") {
397 }
else if (
Feature ==
"+amx-bf16") {
399 }
else if (
Feature ==
"+amx-fp16") {
401 }
else if (
Feature ==
"+amx-int8") {
403 }
else if (
Feature ==
"+amx-tile") {
405 }
else if (
Feature ==
"+amx-complex") {
406 HasAMXCOMPLEX =
true;
407 }
else if (
Feature ==
"+amx-fp8") {
409 }
else if (
Feature ==
"+amx-movrs") {
411 }
else if (
Feature ==
"+amx-avx512") {
413 }
else if (
Feature ==
"+cmpccxadd") {
415 }
else if (
Feature ==
"+raoint") {
417 }
else if (
Feature ==
"+avxifma") {
419 }
else if (
Feature ==
"+avxneconvert") {
420 HasAVXNECONVERT=
true;
421 }
else if (
Feature ==
"+avxvnni") {
423 }
else if (
Feature ==
"+avxvnniint16") {
424 HasAVXVNNIINT16 =
true;
425 }
else if (
Feature ==
"+avxvnniint8") {
426 HasAVXVNNIINT8 =
true;
427 }
else if (
Feature ==
"+serialize") {
429 }
else if (
Feature ==
"+tsxldtrk") {
431 }
else if (
Feature ==
"+uintr") {
433 }
else if (
Feature ==
"+usermsr") {
435 }
else if (
Feature ==
"+crc32") {
437 }
else if (
Feature ==
"+x87") {
439 }
else if (
Feature ==
"+fullbf16") {
441 }
else if (
Feature ==
"+egpr") {
443 }
else if (
Feature ==
"+inline-asm-use-gpr32") {
444 HasInlineAsmUseGPR32 =
true;
445 }
else if (
Feature ==
"+push2pop2") {
447 }
else if (
Feature ==
"+ppx") {
449 }
else if (
Feature ==
"+ndd") {
451 }
else if (
Feature ==
"+ccmp") {
459 }
else if (
Feature ==
"+jmpabs") {
461 }
else if (
Feature ==
"+branch-hint") {
462 HasBranchHint =
true;
465 X86SSEEnum Level = llvm::StringSwitch<X86SSEEnum>(
Feature)
466 .Case(
"+avx512f", AVX512F)
469 .Case(
"+sse4.2", SSE42)
470 .Case(
"+sse4.1", SSE41)
471 .Case(
"+ssse3", SSSE3)
476 SSELevel = std::max(SSELevel, Level);
491 XOPEnum XLevel = llvm::StringSwitch<XOPEnum>(
Feature)
494 .Case(
"+sse4a", SSE4A)
496 XOPLevel = std::max(XOPLevel, XLevel);
503 Diags.
Report(diag::err_target_unsupported_fpmath)
521 Builder.defineMacro(
"__GCC_ASM_FLAG_OUTPUTS__");
524 if (CodeModel ==
"default")
526 Builder.defineMacro(
"__code_model_" + CodeModel +
"__");
529 if (
getTriple().getArch() == llvm::Triple::x86_64) {
530 Builder.defineMacro(
"__amd64__");
531 Builder.defineMacro(
"__amd64");
532 Builder.defineMacro(
"__x86_64");
533 Builder.defineMacro(
"__x86_64__");
534 if (
getTriple().getArchName() ==
"x86_64h") {
535 Builder.defineMacro(
"__x86_64h");
536 Builder.defineMacro(
"__x86_64h__");
543 Builder.defineMacro(
"__LFI__");
546 Builder.defineMacro(
"__SEG_GS");
547 Builder.defineMacro(
"__SEG_FS");
548 Builder.defineMacro(
"__seg_gs",
"__attribute__((address_space(256)))");
549 Builder.defineMacro(
"__seg_fs",
"__attribute__((address_space(257)))");
554 using namespace llvm::X86;
560 Builder.defineMacro(
"__tune_i386__");
569 Builder.defineMacro(
"__pentium_mmx__");
570 Builder.defineMacro(
"__tune_pentium_mmx__");
579 Builder.defineMacro(
"__tune_pentium3__");
583 Builder.defineMacro(
"__tune_pentium2__");
611 case CK_GoldmontPlus:
625 case CK_SkylakeClient:
626 case CK_SkylakeServer:
630 case CK_IcelakeClient:
632 case CK_IcelakeServer:
634 case CK_SapphireRapids:
644 case CK_Sierraforest:
646 case CK_Graniterapids:
647 case CK_GraniterapidsD:
648 case CK_Emeraldrapids:
649 case CK_Clearwaterforest:
650 case CK_Diamondrapids:
664 Builder.defineMacro(
"__tune_lakemont__");
667 Builder.defineMacro(
"__k6_2__");
668 Builder.defineMacro(
"__tune_k6_2__");
671 if (
CPU != CK_K6_2) {
675 Builder.defineMacro(
"__k6_3__");
676 Builder.defineMacro(
"__tune_k6_3__");
685 if (SSELevel != NoSSE) {
686 Builder.defineMacro(
"__athlon_sse__");
687 Builder.defineMacro(
"__tune_athlon_sse__");
756 Builder.defineMacro(
"__REGISTER_PREFIX__",
"");
761 Builder.defineMacro(
"__NO_MATH_INLINES");
764 Builder.defineMacro(
"__AES__");
767 Builder.defineMacro(
"__VAES__");
770 Builder.defineMacro(
"__PCLMUL__");
773 Builder.defineMacro(
"__VPCLMULQDQ__");
777 if (HasLAHFSAHF ||
getTriple().getArch() == llvm::Triple::x86)
778 Builder.defineMacro(
"__LAHF_SAHF__");
781 Builder.defineMacro(
"__LZCNT__");
784 Builder.defineMacro(
"__RDRND__");
787 Builder.defineMacro(
"__FSGSBASE__");
790 Builder.defineMacro(
"__BMI__");
793 Builder.defineMacro(
"__BMI2__");
796 Builder.defineMacro(
"__POPCNT__");
799 Builder.defineMacro(
"__RTM__");
802 Builder.defineMacro(
"__PRFCHW__");
805 Builder.defineMacro(
"__RDSEED__");
808 Builder.defineMacro(
"__ADX__");
811 Builder.defineMacro(
"__TBM__");
814 Builder.defineMacro(
"__LWP__");
817 Builder.defineMacro(
"__MWAITX__");
820 Builder.defineMacro(
"__MOVBE__");
824 Builder.defineMacro(
"__XOP__");
827 Builder.defineMacro(
"__FMA4__");
830 Builder.defineMacro(
"__SSE4A__");
837 Builder.defineMacro(
"__FMA__");
840 Builder.defineMacro(
"__F16C__");
843 Builder.defineMacro(
"__GFNI__");
846 Builder.defineMacro(
"__AVX10_1__");
847 Builder.defineMacro(
"__AVX10_1_512__");
850 Builder.defineMacro(
"__AVX10_2__");
851 Builder.defineMacro(
"__AVX10_2_512__");
854 Builder.defineMacro(
"__AVX10_V2_AUX__");
856 Builder.defineMacro(
"__AVX512CD__");
857 if (HasAVX512VPOPCNTDQ)
858 Builder.defineMacro(
"__AVX512VPOPCNTDQ__");
860 Builder.defineMacro(
"__AVX512VNNI__");
862 Builder.defineMacro(
"__AVX512BF16__");
864 Builder.defineMacro(
"__AVX512FP16__");
866 Builder.defineMacro(
"__AVX512DQ__");
868 Builder.defineMacro(
"__AVX512BITALG__");
870 Builder.defineMacro(
"__AVX512BMM__");
872 Builder.defineMacro(
"__AVX512BW__");
874 Builder.defineMacro(
"__AVX512VL__");
877 Builder.defineMacro(
"__AVX512VBMI__");
879 Builder.defineMacro(
"__AVX512VBMI2__");
881 Builder.defineMacro(
"__AVX512IFMA__");
882 if (HasAVX512VP2INTERSECT)
883 Builder.defineMacro(
"__AVX512VP2INTERSECT__");
885 Builder.defineMacro(
"__SHA__");
887 Builder.defineMacro(
"__SHA512__");
890 Builder.defineMacro(
"__FXSR__");
892 Builder.defineMacro(
"__XSAVE__");
894 Builder.defineMacro(
"__XSAVEOPT__");
896 Builder.defineMacro(
"__XSAVEC__");
898 Builder.defineMacro(
"__XSAVES__");
900 Builder.defineMacro(
"__PKU__");
902 Builder.defineMacro(
"__CLFLUSHOPT__");
904 Builder.defineMacro(
"__CLWB__");
906 Builder.defineMacro(
"__WBNOINVD__");
908 Builder.defineMacro(
"__SHSTK__");
910 Builder.defineMacro(
"__SGX__");
912 Builder.defineMacro(
"__SM3__");
914 Builder.defineMacro(
"__SM4__");
916 Builder.defineMacro(
"__PREFETCHI__");
918 Builder.defineMacro(
"__CLZERO__");
920 Builder.defineMacro(
"__KL__");
922 Builder.defineMacro(
"__WIDEKL__");
924 Builder.defineMacro(
"__RDPID__");
926 Builder.defineMacro(
"__RDPRU__");
928 Builder.defineMacro(
"__CLDEMOTE__");
930 Builder.defineMacro(
"__WAITPKG__");
932 Builder.defineMacro(
"__MOVDIRI__");
934 Builder.defineMacro(
"__MOVDIR64B__");
936 Builder.defineMacro(
"__MOVRS__");
938 Builder.defineMacro(
"__PCONFIG__");
940 Builder.defineMacro(
"__PTWRITE__");
942 Builder.defineMacro(
"__INVPCID__");
944 Builder.defineMacro(
"__ENQCMD__");
946 Builder.defineMacro(
"__HRESET__");
948 Builder.defineMacro(
"__AMX_TILE__");
950 Builder.defineMacro(
"__AMX_INT8__");
952 Builder.defineMacro(
"__AMX_BF16__");
954 Builder.defineMacro(
"__AMX_FP16__");
956 Builder.defineMacro(
"__AMX_COMPLEX__");
958 Builder.defineMacro(
"__AMX_FP8__");
960 Builder.defineMacro(
"__AMX_MOVRS__");
962 Builder.defineMacro(
"__AMX_AVX512__");
964 Builder.defineMacro(
"__CMPCCXADD__");
966 Builder.defineMacro(
"__RAOINT__");
968 Builder.defineMacro(
"__AVXIFMA__");
970 Builder.defineMacro(
"__AVXNECONVERT__");
972 Builder.defineMacro(
"__AVXVNNI__");
974 Builder.defineMacro(
"__AVXVNNIINT16__");
976 Builder.defineMacro(
"__AVXVNNIINT8__");
978 Builder.defineMacro(
"__SERIALIZE__");
980 Builder.defineMacro(
"__TSXLDTRK__");
982 Builder.defineMacro(
"__UINTR__");
984 Builder.defineMacro(
"__USERMSR__");
986 Builder.defineMacro(
"__CRC32__");
988 Builder.defineMacro(
"__EGPR__");
990 Builder.defineMacro(
"__PUSH2POP2__");
992 Builder.defineMacro(
"__PPX__");
994 Builder.defineMacro(
"__NDD__");
996 Builder.defineMacro(
"__CCMP__");
998 Builder.defineMacro(
"__NF__");
1000 Builder.defineMacro(
"__CF__");
1002 Builder.defineMacro(
"__ZU__");
1004 Builder.defineMacro(
"__JMPABS__");
1005 if (HasEGPR && HasPush2Pop2 && HasPPX && HasNDD && HasCCMP && HasNF &&
1007 Builder.defineMacro(
"__APX_F__");
1008 if (HasEGPR && HasInlineAsmUseGPR32)
1009 Builder.defineMacro(
"__APX_INLINE_ASM_USE_GPR32__");
1014 Builder.defineMacro(
"__AVX512F__");
1017 Builder.defineMacro(
"__AVX2__");
1020 Builder.defineMacro(
"__AVX__");
1023 Builder.defineMacro(
"__SSE4_2__");
1026 Builder.defineMacro(
"__SSE4_1__");
1029 Builder.defineMacro(
"__SSSE3__");
1032 Builder.defineMacro(
"__SSE3__");
1035 Builder.defineMacro(
"__SSE2__");
1036 Builder.defineMacro(
"__SSE2_MATH__");
1039 Builder.defineMacro(
"__SSE__");
1040 Builder.defineMacro(
"__SSE_MATH__");
1046 if (Opts.MicrosoftExt &&
getTriple().getArch() == llvm::Triple::x86) {
1056 Builder.defineMacro(
"_M_IX86_FP", Twine(2));
1059 Builder.defineMacro(
"_M_IX86_FP", Twine(1));
1062 Builder.defineMacro(
"_M_IX86_FP", Twine(0));
1069 Builder.defineMacro(
"__MMX__");
1072 if (
CPU >= CK_i486 ||
CPU == CK_None) {
1073 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
1074 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
1075 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
1078 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
1079 if (HasCX16 &&
getTriple().getArch() == llvm::Triple::x86_64)
1080 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16");
1083 Builder.defineMacro(
"__SIZEOF_FLOAT128__",
"16");
1085 if (Opts.CFProtectionReturn || Opts.CFProtectionBranch)
1086 Builder.defineMacro(
"__CET__", Twine{(Opts.CFProtectionReturn << 1) |
1087 Opts.CFProtectionBranch});
1091 return llvm::StringSwitch<bool>(Name)
1094 .Case(
"amx-avx512",
true)
1095 .Case(
"amx-bf16",
true)
1096 .Case(
"amx-complex",
true)
1097 .Case(
"amx-fp16",
true)
1098 .Case(
"amx-fp8",
true)
1099 .Case(
"amx-int8",
true)
1100 .Case(
"amx-movrs",
true)
1101 .Case(
"amx-tile",
true)
1103 .Case(
"avx10.1",
true)
1104 .Case(
"avx10.2",
true)
1105 .Case(
"avx10v2aux",
true)
1107 .Case(
"avx512f",
true)
1108 .Case(
"avx512cd",
true)
1109 .Case(
"avx512vpopcntdq",
true)
1110 .Case(
"avx512vnni",
true)
1111 .Case(
"avx512bf16",
true)
1112 .Case(
"avx512fp16",
true)
1113 .Case(
"avx512dq",
true)
1114 .Case(
"avx512bitalg",
true)
1115 .Case(
"avx512bmm",
true)
1116 .Case(
"avx512bw",
true)
1117 .Case(
"avx512vl",
true)
1118 .Case(
"avx512vbmi",
true)
1119 .Case(
"avx512vbmi2",
true)
1120 .Case(
"avx512ifma",
true)
1121 .Case(
"avx512vp2intersect",
true)
1122 .Case(
"avxifma",
true)
1123 .Case(
"avxneconvert",
true)
1124 .Case(
"avxvnni",
true)
1125 .Case(
"avxvnniint16",
true)
1126 .Case(
"avxvnniint8",
true)
1129 .Case(
"cldemote",
true)
1130 .Case(
"clflushopt",
true)
1132 .Case(
"clzero",
true)
1133 .Case(
"cmpccxadd",
true)
1134 .Case(
"crc32",
true)
1136 .Case(
"enqcmd",
true)
1140 .Case(
"fsgsbase",
true)
1142 .Case(
"general-regs-only",
true)
1144 .Case(
"hreset",
true)
1145 .Case(
"invpcid",
true)
1147 .Case(
"widekl",
true)
1149 .Case(
"lzcnt",
true)
1151 .Case(
"movbe",
true)
1152 .Case(
"movrs",
true)
1153 .Case(
"movdiri",
true)
1154 .Case(
"movdir64b",
true)
1155 .Case(
"mwaitx",
true)
1156 .Case(
"pclmul",
true)
1157 .Case(
"pconfig",
true)
1159 .Case(
"popcnt",
true)
1160 .Case(
"prefer-256-bit",
true)
1161 .Case(
"prefetchi",
true)
1162 .Case(
"prfchw",
true)
1163 .Case(
"ptwrite",
true)
1164 .Case(
"raoint",
true)
1165 .Case(
"rdpid",
true)
1166 .Case(
"rdpru",
true)
1167 .Case(
"rdrnd",
true)
1168 .Case(
"rdseed",
true)
1171 .Case(
"serialize",
true)
1174 .Case(
"sha512",
true)
1175 .Case(
"shstk",
true)
1181 .Case(
"ssse3",
true)
1183 .Case(
"sse4.1",
true)
1184 .Case(
"sse4.2",
true)
1185 .Case(
"sse4a",
true)
1187 .Case(
"tsxldtrk",
true)
1188 .Case(
"uintr",
true)
1189 .Case(
"usermsr",
true)
1191 .Case(
"vpclmulqdq",
true)
1192 .Case(
"wbnoinvd",
true)
1193 .Case(
"waitpkg",
true)
1196 .Case(
"xsave",
true)
1197 .Case(
"xsavec",
true)
1198 .Case(
"xsaves",
true)
1199 .Case(
"xsaveopt",
true)
1202 .Case(
"push2pop2",
true)
1209 .Case(
"jmpabs",
true)
1214 return llvm::StringSwitch<bool>(
Feature)
1215 .Case(
"adx", HasADX)
1216 .Case(
"aes", HasAES)
1217 .Case(
"amx-avx512", HasAMXAVX512)
1218 .Case(
"amx-bf16", HasAMXBF16)
1219 .Case(
"amx-complex", HasAMXCOMPLEX)
1220 .Case(
"amx-fp16", HasAMXFP16)
1221 .Case(
"amx-fp8", HasAMXFP8)
1222 .Case(
"amx-int8", HasAMXINT8)
1223 .Case(
"amx-movrs", HasAMXMOVRS)
1224 .Case(
"amx-tile", HasAMXTILE)
1225 .Case(
"avx", SSELevel >= AVX)
1226 .Case(
"avx10.1", HasAVX10_1)
1227 .Case(
"avx10.2", HasAVX10_2)
1228 .Case(
"avx10v2aux", HasAVX10_V2_AUX)
1229 .Case(
"avx2", SSELevel >= AVX2)
1230 .Case(
"avx512f", SSELevel >= AVX512F)
1231 .Case(
"avx512cd", HasAVX512CD)
1232 .Case(
"avx512vpopcntdq", HasAVX512VPOPCNTDQ)
1233 .Case(
"avx512vnni", HasAVX512VNNI)
1234 .Case(
"avx512bf16", HasAVX512BF16)
1235 .Case(
"avx512fp16", HasAVX512FP16)
1236 .Case(
"avx512dq", HasAVX512DQ)
1237 .Case(
"avx512bitalg", HasAVX512BITALG)
1238 .Case(
"avx512bmm", HasAVX512BMM)
1239 .Case(
"avx512bw", HasAVX512BW)
1240 .Case(
"avx512vl", HasAVX512VL)
1241 .Case(
"avx512vbmi", HasAVX512VBMI)
1242 .Case(
"avx512vbmi2", HasAVX512VBMI2)
1243 .Case(
"avx512ifma", HasAVX512IFMA)
1244 .Case(
"avx512vp2intersect", HasAVX512VP2INTERSECT)
1245 .Case(
"avxifma", HasAVXIFMA)
1246 .Case(
"avxneconvert", HasAVXNECONVERT)
1247 .Case(
"avxvnni", HasAVXVNNI)
1248 .Case(
"avxvnniint16", HasAVXVNNIINT16)
1249 .Case(
"avxvnniint8", HasAVXVNNIINT8)
1250 .Case(
"bmi", HasBMI)
1251 .Case(
"bmi2", HasBMI2)
1252 .Case(
"cldemote", HasCLDEMOTE)
1253 .Case(
"clflushopt", HasCLFLUSHOPT)
1254 .Case(
"clwb", HasCLWB)
1255 .Case(
"clzero", HasCLZERO)
1256 .Case(
"cmpccxadd", HasCMPCCXADD)
1257 .Case(
"crc32", HasCRC32)
1258 .Case(
"cx8", HasCX8)
1259 .Case(
"cx16", HasCX16)
1260 .Case(
"enqcmd", HasENQCMD)
1261 .Case(
"f16c", HasF16C)
1262 .Case(
"fma", HasFMA)
1263 .Case(
"fma4", XOPLevel >= FMA4)
1264 .Case(
"fsgsbase", HasFSGSBASE)
1265 .Case(
"fxsr", HasFXSR)
1266 .Case(
"gfni", HasGFNI)
1267 .Case(
"hreset", HasHRESET)
1268 .Case(
"invpcid", HasINVPCID)
1270 .Case(
"widekl", HasWIDEKL)
1271 .Case(
"lwp", HasLWP)
1272 .Case(
"lzcnt", HasLZCNT)
1273 .Case(
"mmx", HasMMX)
1274 .Case(
"movbe", HasMOVBE)
1275 .Case(
"movrs", HasMOVRS)
1276 .Case(
"movdiri", HasMOVDIRI)
1277 .Case(
"movdir64b", HasMOVDIR64B)
1278 .Case(
"mwaitx", HasMWAITX)
1279 .Case(
"pclmul", HasPCLMUL)
1280 .Case(
"pconfig", HasPCONFIG)
1281 .Case(
"pku", HasPKU)
1282 .Case(
"popcnt", HasPOPCNT)
1283 .Case(
"prefetchi", HasPREFETCHI)
1284 .Case(
"prfchw", HasPRFCHW)
1285 .Case(
"ptwrite", HasPTWRITE)
1286 .Case(
"raoint", HasRAOINT)
1287 .Case(
"rdpid", HasRDPID)
1288 .Case(
"rdpru", HasRDPRU)
1289 .Case(
"rdrnd", HasRDRND)
1290 .Case(
"rdseed", HasRDSEED)
1291 .Case(
"retpoline-external-thunk", HasRetpolineExternalThunk)
1292 .Case(
"rtm", HasRTM)
1293 .Case(
"sahf", HasLAHFSAHF)
1294 .Case(
"serialize", HasSERIALIZE)
1295 .Case(
"sgx", HasSGX)
1296 .Case(
"sha", HasSHA)
1297 .Case(
"sha512", HasSHA512)
1298 .Case(
"shstk", HasSHSTK)
1299 .Case(
"sm3", HasSM3)
1300 .Case(
"sm4", HasSM4)
1301 .Case(
"sse", SSELevel >= SSE1)
1302 .Case(
"sse2", SSELevel >= SSE2)
1303 .Case(
"sse3", SSELevel >= SSE3)
1304 .Case(
"ssse3", SSELevel >= SSSE3)
1305 .Case(
"sse4.1", SSELevel >= SSE41)
1306 .Case(
"sse4.2", SSELevel >= SSE42)
1307 .Case(
"sse4a", XOPLevel >= SSE4A)
1308 .Case(
"tbm", HasTBM)
1309 .Case(
"tsxldtrk", HasTSXLDTRK)
1310 .Case(
"uintr", HasUINTR)
1311 .Case(
"usermsr", HasUSERMSR)
1312 .Case(
"vaes", HasVAES)
1313 .Case(
"vpclmulqdq", HasVPCLMULQDQ)
1314 .Case(
"wbnoinvd", HasWBNOINVD)
1315 .Case(
"waitpkg", HasWAITPKG)
1317 .Case(
"x86_32",
getTriple().getArch() == llvm::Triple::x86)
1318 .Case(
"x86_64",
getTriple().getArch() == llvm::Triple::x86_64)
1319 .Case(
"x87", HasX87)
1320 .Case(
"xop", XOPLevel >= XOP)
1321 .Case(
"xsave", HasXSAVE)
1322 .Case(
"xsavec", HasXSAVEC)
1323 .Case(
"xsaves", HasXSAVES)
1324 .Case(
"xsaveopt", HasXSAVEOPT)
1326 .Case(
"egpr", HasEGPR)
1327 .Case(
"push2pop2", HasPush2Pop2)
1328 .Case(
"ppx", HasPPX)
1329 .Case(
"ndd", HasNDD)
1330 .Case(
"ccmp", HasCCMP)
1334 .Case(
"jmpabs", HasJMPABS)
1335 .Case(
"branch-hint", HasBranchHint)
1345 return llvm::StringSwitch<bool>(FeatureStr)
1346#define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY, ABI_VALUE) .Case(STR, true)
1347#define X86_MICROARCH_LEVEL(ENUM, STR, PRIORITY, ABI_VALUE) .Case(STR, true)
1348#include "llvm/TargetParser/X86TargetParser.def"
1353 return llvm::StringSwitch<llvm::X86::ProcessorFeatures>(Name)
1354#define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY, ABI_VALUE) \
1355 .Case(STR, llvm::X86::FEATURE_##ENUM)
1357#include "llvm/TargetParser/X86TargetParser.def"
1364 auto getPriority = [](StringRef
Feature) ->
unsigned {
1367 using namespace llvm::X86;
1368 CPUKind Kind = parseArchX86(
Feature);
1369 if (Kind != CK_None) {
1370 ProcessorFeatures KeyFeature = getKeyFeature(Kind);
1371 return (getFeaturePriority(KeyFeature) << 1) + 1;
1378 unsigned Priority = 0;
1379 for (StringRef
Feature : Features)
1381 Priority = std::max(Priority, getPriority(
Feature));
1382 return llvm::APInt(32, Priority);
1386 return llvm::X86::validateCPUSpecificCPUDispatch(Name);
1390 return llvm::X86::getCPUDispatchMangling(Name);
1396 llvm::X86::getFeaturesForCPU(Name, TargetCPUFeatures,
true);
1397 for (
auto &F : TargetCPUFeatures)
1398 Features.push_back(F);
1406 return llvm::StringSwitch<bool>(FeatureStr)
1407#define X86_VENDOR(ENUM, STRING, ABI_VALUE) .Case(STRING, true)
1408#define X86_CPU_TYPE(ENUM, STR, ABI_VALUE) .Case(STR, true)
1409#define X86_CPU_SUBTYPE(ENUM, STR, ABI_VALUE) .Case(STR, true)
1410#include "llvm/TargetParser/X86TargetParser.def"
1415 auto RV = llvm::StringSwitch<unsigned>(Name)
1584 using namespace llvm::X86;
1624 case CK_GoldmontPlus:
1629 case CK_SandyBridge:
1633 case CK_SkylakeClient:
1634 case CK_SkylakeServer:
1635 case CK_Cascadelake:
1640 case CK_SapphireRapids:
1641 case CK_IcelakeClient:
1643 case CK_IcelakeServer:
1650 case CK_Pantherlake:
1651 case CK_Wildcatlake:
1653 case CK_Sierraforest:
1655 case CK_Graniterapids:
1656 case CK_GraniterapidsD:
1657 case CK_Emeraldrapids:
1658 case CK_Clearwaterforest:
1659 case CK_Diamondrapids:
1702 return std::nullopt;
1704 llvm_unreachable(
"Unknown CPU kind");
1708 StringRef Constraint,
1709 unsigned Size)
const {
1711 Constraint = Constraint.ltrim(
"=+&");
1717 StringRef Constraint,
1718 unsigned Size)
const {
1723 StringRef Constraint,
1724 unsigned Size)
const {
1725 switch (Constraint[0]) {
1738 switch (Constraint[1]) {
1749 return Size <= 512U;
1752 return Size <= 256U;
1754 return Size <= 128U;
1760 if (SSELevel < SSE2)
1769 return Size <= 512U;
1772 return Size <= 256U;
1773 return Size <= 128U;
1781 switch (*Constraint) {
1784 std::string Converted =
"{" + std::string(Constraint, Len) +
"}";
1785 Constraint += Len - 1;
1788 return std::string(1, *Constraint);
1790 return std::string(
"{ax}");
1792 return std::string(
"{bx}");
1794 return std::string(
"{cx}");
1796 return std::string(
"{dx}");
1798 return std::string(
"{si}");
1800 return std::string(
"{di}");
1802 return std::string(
"p");
1804 return std::string(
"{st}");
1806 return std::string(
"{st(1)}");
1808 assert(Constraint[1] ==
's');
1809 return '^' + std::string(Constraint++, 2);
1811 switch (Constraint[1]) {
1826 return std::string(
"^") + std::string(Constraint++, 2);
1830 switch (Constraint[1]) {
1841 return std::string(
"^") + std::string(Constraint++, 2);
1845 return std::string(1, *Constraint);
1850 bool Only64Bit =
getTriple().getArch() != llvm::Triple::x86;
1851 llvm::X86::fillValidCPUArchList(Values, Only64Bit);
1855 llvm::X86::fillValidTuneCPUList(Values);
1887 bool HasNonWeakDef)
const {
1893 if (!UseMSVCCompatGlobalAlign)
1907 UseMSVCCompatGlobalAlign =
false;
Defines the Diagnostic-related interfaces.
static unsigned matchAsmCCConstraint(const char *Name)
static constexpr Builtin::Info PrefixedBuiltinInfos[]
static llvm::X86::ProcessorFeatures getFeature(StringRef Name)
static constexpr Builtin::Info BuiltinInfos[]
Defines enum values for all the target-independent builtin functions.
Enumerates target-specific builtins in their own namespaces within namespace clang.
Concrete class used by the front-end to report problems and issues.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
bool isCompatibleWith(ClangABI Version) const
Exposes information about the current target.
TargetOptions & getTargetOpts() const
Retrieve the target options.
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
virtual bool hasFeatureEnabled(const llvm::StringMap< bool > &Features, StringRef Name) const
Check if target has a given feature enabled.
virtual void adjust(DiagnosticsEngine &Diags, LangOptions &Opts, const TargetInfo *Aux)
Set forced language options.
virtual unsigned getMinGlobalAlign(uint64_t Size, bool HasNonWeakDef) const
getMinGlobalAlign - Return the minimum alignment of a global variable, unless its alignment is explic...
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 ...
unsigned getMinGlobalAlign(uint64_t TypeSize, bool HasNonWeakDef) const override
getMinGlobalAlign - Return the minimum alignment of a global variable, unless its alignment is explic...
void adjust(DiagnosticsEngine &Diags, LangOptions &Opts, const TargetInfo *Aux) override
Set forced language options.
enum clang::targets::X86TargetInfo::FPMathKind FPMath
bool handleTargetFeatures(std::vector< std::string > &Features, DiagnosticsEngine &Diags) override
handleTargetFeatures - Perform initialization based on the user configured set of features.
std::optional< unsigned > getCPUCacheLineSize() const override
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &info) const override
llvm::APInt getFMVPriority(ArrayRef< StringRef > Features) const override
bool setFPMath(StringRef Name) override
Use the specified unit for FP math.
ArrayRef< const char * > getGCCRegNames() const override
char CPUSpecificManglingCharacter(StringRef Name) const override
std::string convertConstraint(const char *&Constraint) 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...
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 ...
void getCPUSpecificCPUDispatchFeatures(StringRef Name, llvm::SmallVectorImpl< StringRef > &Features) const override
bool validateCpuIs(StringRef FeatureStr) const override
bool validateOutputSize(const llvm::StringMap< bool > &FeatureMap, StringRef Constraint, unsigned Size) const override
virtual bool validateOperandSize(const llvm::StringMap< bool > &FeatureMap, StringRef Constraint, unsigned Size) const
void fillValidTuneCPUList(SmallVectorImpl< StringRef > &Values) const override
Fill a SmallVectorImpl with the valid values for tuning CPU.
bool validateCPUSpecificCPUDispatch(StringRef Name) const override
bool validateCpuSupports(StringRef FeatureStr) const override
bool isValidFeatureName(StringRef Name) const override
Determine whether this TargetInfo supports the given feature.
bool hasFeature(StringRef Feature) const final
Determine whether the given target has the given feature.
void setFeatureEnabled(llvm::StringMap< bool > &Features, StringRef Name, bool Enabled) const final
Enable or disable a specific target feature; the feature name must be valid.
void fillValidCPUList(SmallVectorImpl< StringRef > &Values) const override
Fill a SmallVectorImpl with the valid values to setCPU.
ArrayRef< TargetInfo::AddlRegName > getGCCAddlRegNames() const override
bool validateInputSize(const llvm::StringMap< bool > &FeatureMap, StringRef Constraint, unsigned Size) const override
llvm::SmallVector< Builtin::InfosShard > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
llvm::SmallVector< Builtin::InfosShard > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
static constexpr Builtin::Info BuiltinInfos[]
static constexpr Builtin::Info PrefixedBuiltinInfos[]
static constexpr Builtin::Info BuiltinInfos[]
static constexpr Builtin::Info PrefixedBuiltinInfos[]
static constexpr int NumX86Builtins
LLVM_LIBRARY_VISIBILITY void defineCPUMacros(clang::MacroBuilder &Builder, llvm::StringRef CPUName, bool Tuning=true)
static constexpr int NumBuiltins
const TargetInfo::AddlRegName AddlRegNames[]
static const char *const GCCRegNames[]
static constexpr int NumX86_64Builtins
LLVM_LIBRARY_VISIBILITY void DefineStd(clang::MacroBuilder &Builder, llvm::StringRef MacroName, const clang::LangOptions &Opts)
Define a macro name and standard variants.
Top level wrappers for InstallAPI frontend operations.
unsigned Microsoft64BitMinGlobalAlign(uint64_t TypeSize)
The info used to represent each builtin.
std::string ConstraintStr
void setOutputOperandBounds(unsigned Min, unsigned Max)
void setRequiresImmediate(int Min, int Max)
const llvm::fltSemantics * LongDoubleFormat
unsigned char LargeArrayAlign
unsigned char LargeArrayMinWidth