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 if (Features.lookup(
"egpr") &&
getTriple().isOSWindows()) {
172 std::vector<std::string> UpdatedFeaturesVec;
173 for (
const auto &
Feature : FeaturesVec) {
175 if (
Feature ==
"+general-regs-only") {
176 UpdatedFeaturesVec.push_back(
"-x87");
177 UpdatedFeaturesVec.push_back(
"-mmx");
178 UpdatedFeaturesVec.push_back(
"-sse");
182 UpdatedFeaturesVec.push_back(
Feature);
192 auto I = Features.find(
"sse4.2");
193 if (I != Features.end() && I->getValue() &&
194 !llvm::is_contained(UpdatedFeaturesVec,
"-popcnt"))
195 Features[
"popcnt"] =
true;
199 I = Features.find(
"sse");
200 if (I != Features.end() && I->getValue() &&
201 !llvm::is_contained(UpdatedFeaturesVec,
"-mmx"))
202 Features[
"mmx"] =
true;
205 I = Features.find(
"avx");
206 if (I != Features.end() && I->getValue() &&
207 !llvm::is_contained(UpdatedFeaturesVec,
"-xsave"))
208 Features[
"xsave"] =
true;
211 I = Features.find(
"sse4.2");
212 if (I != Features.end() && I->getValue() &&
213 !llvm::is_contained(UpdatedFeaturesVec,
"-crc32"))
214 Features[
"crc32"] =
true;
220 StringRef Name,
bool Enabled)
const {
221 if (Name ==
"sse4") {
232 Features[Name] = Enabled;
233 llvm::X86::updateImpliedFeatures(Name, Enabled, Features);
240 for (
const auto &
Feature : Features) {
246 }
else if (
Feature ==
"+aes") {
248 }
else if (
Feature ==
"+vaes") {
250 }
else if (
Feature ==
"+pclmul") {
252 }
else if (
Feature ==
"+vpclmulqdq") {
253 HasVPCLMULQDQ =
true;
254 }
else if (
Feature ==
"+lzcnt") {
256 }
else if (
Feature ==
"+rdrnd") {
258 }
else if (
Feature ==
"+fsgsbase") {
260 }
else if (
Feature ==
"+bmi") {
262 }
else if (
Feature ==
"+bmi2") {
264 }
else if (
Feature ==
"+popcnt") {
266 }
else if (
Feature ==
"+rtm") {
268 }
else if (
Feature ==
"+prfchw") {
270 }
else if (
Feature ==
"+rdseed") {
272 }
else if (
Feature ==
"+adx") {
274 }
else if (
Feature ==
"+tbm") {
276 }
else if (
Feature ==
"+lwp") {
278 }
else if (
Feature ==
"+fma") {
280 }
else if (
Feature ==
"+f16c") {
282 }
else if (
Feature ==
"+gfni") {
284 }
else if (
Feature ==
"+avx10.1") {
286 }
else if (
Feature ==
"+avx10.2") {
289 }
else if (
Feature ==
"+avx512cd") {
291 }
else if (
Feature ==
"+avx512vpopcntdq") {
292 HasAVX512VPOPCNTDQ =
true;
293 }
else if (
Feature ==
"+avx512vnni") {
294 HasAVX512VNNI =
true;
295 }
else if (
Feature ==
"+avx512bf16") {
296 HasAVX512BF16 =
true;
297 }
else if (
Feature ==
"+avx512fp16") {
298 HasAVX512FP16 =
true;
300 }
else if (
Feature ==
"+avx512dq") {
302 }
else if (
Feature ==
"+avx512bitalg") {
303 HasAVX512BITALG =
true;
304 }
else if (
Feature ==
"+avx512bw") {
306 }
else if (
Feature ==
"+avx512vl") {
308 }
else if (
Feature ==
"+avx512vbmi") {
309 HasAVX512VBMI =
true;
310 }
else if (
Feature ==
"+avx512vbmi2") {
311 HasAVX512VBMI2 =
true;
312 }
else if (
Feature ==
"+avx512ifma") {
313 HasAVX512IFMA =
true;
314 }
else if (
Feature ==
"+avx512vp2intersect") {
315 HasAVX512VP2INTERSECT =
true;
316 }
else if (
Feature ==
"+sha") {
318 }
else if (
Feature ==
"+sha512") {
320 }
else if (
Feature ==
"+shstk") {
322 }
else if (
Feature ==
"+sm3") {
324 }
else if (
Feature ==
"+sm4") {
326 }
else if (
Feature ==
"+movbe") {
328 }
else if (
Feature ==
"+movrs") {
330 }
else if (
Feature ==
"+sgx") {
332 }
else if (
Feature ==
"+cx8") {
334 }
else if (
Feature ==
"+cx16") {
336 }
else if (
Feature ==
"+fxsr") {
338 }
else if (
Feature ==
"+xsave") {
340 }
else if (
Feature ==
"+xsaveopt") {
342 }
else if (
Feature ==
"+xsavec") {
344 }
else if (
Feature ==
"+xsaves") {
346 }
else if (
Feature ==
"+mwaitx") {
348 }
else if (
Feature ==
"+pku") {
350 }
else if (
Feature ==
"+clflushopt") {
351 HasCLFLUSHOPT =
true;
352 }
else if (
Feature ==
"+clwb") {
354 }
else if (
Feature ==
"+wbnoinvd") {
356 }
else if (
Feature ==
"+prefetchi") {
358 }
else if (
Feature ==
"+clzero") {
360 }
else if (
Feature ==
"+cldemote") {
362 }
else if (
Feature ==
"+rdpid") {
364 }
else if (
Feature ==
"+rdpru") {
368 }
else if (
Feature ==
"+widekl") {
370 }
else if (
Feature ==
"+retpoline-external-thunk") {
371 HasRetpolineExternalThunk =
true;
372 }
else if (
Feature ==
"+sahf") {
374 }
else if (
Feature ==
"+waitpkg") {
376 }
else if (
Feature ==
"+movdiri") {
378 }
else if (
Feature ==
"+movdir64b") {
380 }
else if (
Feature ==
"+pconfig") {
382 }
else if (
Feature ==
"+ptwrite") {
384 }
else if (
Feature ==
"+invpcid") {
386 }
else if (
Feature ==
"+enqcmd") {
388 }
else if (
Feature ==
"+hreset") {
390 }
else if (
Feature ==
"+amx-bf16") {
392 }
else if (
Feature ==
"+amx-fp16") {
394 }
else if (
Feature ==
"+amx-int8") {
396 }
else if (
Feature ==
"+amx-tile") {
398 }
else if (
Feature ==
"+amx-complex") {
399 HasAMXCOMPLEX =
true;
400 }
else if (
Feature ==
"+amx-fp8") {
402 }
else if (
Feature ==
"+amx-movrs") {
404 }
else if (
Feature ==
"+amx-avx512") {
406 }
else if (
Feature ==
"+amx-tf32") {
408 }
else if (
Feature ==
"+cmpccxadd") {
410 }
else if (
Feature ==
"+raoint") {
412 }
else if (
Feature ==
"+avxifma") {
414 }
else if (
Feature ==
"+avxneconvert") {
415 HasAVXNECONVERT=
true;
416 }
else if (
Feature ==
"+avxvnni") {
418 }
else if (
Feature ==
"+avxvnniint16") {
419 HasAVXVNNIINT16 =
true;
420 }
else if (
Feature ==
"+avxvnniint8") {
421 HasAVXVNNIINT8 =
true;
422 }
else if (
Feature ==
"+serialize") {
424 }
else if (
Feature ==
"+tsxldtrk") {
426 }
else if (
Feature ==
"+uintr") {
428 }
else if (
Feature ==
"+usermsr") {
430 }
else if (
Feature ==
"+crc32") {
432 }
else if (
Feature ==
"+x87") {
434 }
else if (
Feature ==
"+fullbf16") {
436 }
else if (
Feature ==
"+egpr") {
438 }
else if (
Feature ==
"+inline-asm-use-gpr32") {
439 HasInlineAsmUseGPR32 =
true;
440 }
else if (
Feature ==
"+push2pop2") {
442 }
else if (
Feature ==
"+ppx") {
444 }
else if (
Feature ==
"+ndd") {
446 }
else if (
Feature ==
"+ccmp") {
454 }
else if (
Feature ==
"+branch-hint") {
455 HasBranchHint =
true;
458 X86SSEEnum Level = llvm::StringSwitch<X86SSEEnum>(
Feature)
459 .Case(
"+avx512f", AVX512F)
462 .Case(
"+sse4.2", SSE42)
463 .Case(
"+sse4.1", SSE41)
464 .Case(
"+ssse3", SSSE3)
469 SSELevel = std::max(SSELevel, Level);
484 XOPEnum XLevel = llvm::StringSwitch<XOPEnum>(
Feature)
487 .Case(
"+sse4a", SSE4A)
489 XOPLevel = std::max(XOPLevel, XLevel);
496 Diags.
Report(diag::err_target_unsupported_fpmath)
514 Builder.defineMacro(
"__GCC_ASM_FLAG_OUTPUTS__");
517 if (CodeModel ==
"default")
519 Builder.defineMacro(
"__code_model_" + CodeModel +
"__");
522 if (
getTriple().getArch() == llvm::Triple::x86_64) {
523 Builder.defineMacro(
"__amd64__");
524 Builder.defineMacro(
"__amd64");
525 Builder.defineMacro(
"__x86_64");
526 Builder.defineMacro(
"__x86_64__");
527 if (
getTriple().getArchName() ==
"x86_64h") {
528 Builder.defineMacro(
"__x86_64h");
529 Builder.defineMacro(
"__x86_64h__");
535 Builder.defineMacro(
"__SEG_GS");
536 Builder.defineMacro(
"__SEG_FS");
537 Builder.defineMacro(
"__seg_gs",
"__attribute__((address_space(256)))");
538 Builder.defineMacro(
"__seg_fs",
"__attribute__((address_space(257)))");
543 using namespace llvm::X86;
549 Builder.defineMacro(
"__tune_i386__");
558 Builder.defineMacro(
"__pentium_mmx__");
559 Builder.defineMacro(
"__tune_pentium_mmx__");
568 Builder.defineMacro(
"__tune_pentium3__");
572 Builder.defineMacro(
"__tune_pentium2__");
600 case CK_GoldmontPlus:
614 case CK_SkylakeClient:
615 case CK_SkylakeServer:
619 case CK_IcelakeClient:
621 case CK_IcelakeServer:
623 case CK_SapphireRapids:
633 case CK_Sierraforest:
635 case CK_Graniterapids:
636 case CK_GraniterapidsD:
637 case CK_Emeraldrapids:
638 case CK_Clearwaterforest:
639 case CK_Diamondrapids:
653 Builder.defineMacro(
"__tune_lakemont__");
656 Builder.defineMacro(
"__k6_2__");
657 Builder.defineMacro(
"__tune_k6_2__");
660 if (
CPU != CK_K6_2) {
664 Builder.defineMacro(
"__k6_3__");
665 Builder.defineMacro(
"__tune_k6_3__");
674 if (SSELevel != NoSSE) {
675 Builder.defineMacro(
"__athlon_sse__");
676 Builder.defineMacro(
"__tune_athlon_sse__");
733 Builder.defineMacro(
"__REGISTER_PREFIX__",
"");
738 Builder.defineMacro(
"__NO_MATH_INLINES");
741 Builder.defineMacro(
"__AES__");
744 Builder.defineMacro(
"__VAES__");
747 Builder.defineMacro(
"__PCLMUL__");
750 Builder.defineMacro(
"__VPCLMULQDQ__");
754 if (HasLAHFSAHF ||
getTriple().getArch() == llvm::Triple::x86)
755 Builder.defineMacro(
"__LAHF_SAHF__");
758 Builder.defineMacro(
"__LZCNT__");
761 Builder.defineMacro(
"__RDRND__");
764 Builder.defineMacro(
"__FSGSBASE__");
767 Builder.defineMacro(
"__BMI__");
770 Builder.defineMacro(
"__BMI2__");
773 Builder.defineMacro(
"__POPCNT__");
776 Builder.defineMacro(
"__RTM__");
779 Builder.defineMacro(
"__PRFCHW__");
782 Builder.defineMacro(
"__RDSEED__");
785 Builder.defineMacro(
"__ADX__");
788 Builder.defineMacro(
"__TBM__");
791 Builder.defineMacro(
"__LWP__");
794 Builder.defineMacro(
"__MWAITX__");
797 Builder.defineMacro(
"__MOVBE__");
801 Builder.defineMacro(
"__XOP__");
804 Builder.defineMacro(
"__FMA4__");
807 Builder.defineMacro(
"__SSE4A__");
814 Builder.defineMacro(
"__FMA__");
817 Builder.defineMacro(
"__F16C__");
820 Builder.defineMacro(
"__GFNI__");
823 Builder.defineMacro(
"__AVX10_1__");
824 Builder.defineMacro(
"__AVX10_1_512__");
827 Builder.defineMacro(
"__AVX10_2__");
828 Builder.defineMacro(
"__AVX10_2_512__");
831 Builder.defineMacro(
"__AVX512CD__");
832 if (HasAVX512VPOPCNTDQ)
833 Builder.defineMacro(
"__AVX512VPOPCNTDQ__");
835 Builder.defineMacro(
"__AVX512VNNI__");
837 Builder.defineMacro(
"__AVX512BF16__");
839 Builder.defineMacro(
"__AVX512FP16__");
841 Builder.defineMacro(
"__AVX512DQ__");
843 Builder.defineMacro(
"__AVX512BITALG__");
845 Builder.defineMacro(
"__AVX512BW__");
847 Builder.defineMacro(
"__AVX512VL__");
850 Builder.defineMacro(
"__AVX512VBMI__");
852 Builder.defineMacro(
"__AVX512VBMI2__");
854 Builder.defineMacro(
"__AVX512IFMA__");
855 if (HasAVX512VP2INTERSECT)
856 Builder.defineMacro(
"__AVX512VP2INTERSECT__");
858 Builder.defineMacro(
"__SHA__");
860 Builder.defineMacro(
"__SHA512__");
863 Builder.defineMacro(
"__FXSR__");
865 Builder.defineMacro(
"__XSAVE__");
867 Builder.defineMacro(
"__XSAVEOPT__");
869 Builder.defineMacro(
"__XSAVEC__");
871 Builder.defineMacro(
"__XSAVES__");
873 Builder.defineMacro(
"__PKU__");
875 Builder.defineMacro(
"__CLFLUSHOPT__");
877 Builder.defineMacro(
"__CLWB__");
879 Builder.defineMacro(
"__WBNOINVD__");
881 Builder.defineMacro(
"__SHSTK__");
883 Builder.defineMacro(
"__SGX__");
885 Builder.defineMacro(
"__SM3__");
887 Builder.defineMacro(
"__SM4__");
889 Builder.defineMacro(
"__PREFETCHI__");
891 Builder.defineMacro(
"__CLZERO__");
893 Builder.defineMacro(
"__KL__");
895 Builder.defineMacro(
"__WIDEKL__");
897 Builder.defineMacro(
"__RDPID__");
899 Builder.defineMacro(
"__RDPRU__");
901 Builder.defineMacro(
"__CLDEMOTE__");
903 Builder.defineMacro(
"__WAITPKG__");
905 Builder.defineMacro(
"__MOVDIRI__");
907 Builder.defineMacro(
"__MOVDIR64B__");
909 Builder.defineMacro(
"__MOVRS__");
911 Builder.defineMacro(
"__PCONFIG__");
913 Builder.defineMacro(
"__PTWRITE__");
915 Builder.defineMacro(
"__INVPCID__");
917 Builder.defineMacro(
"__ENQCMD__");
919 Builder.defineMacro(
"__HRESET__");
921 Builder.defineMacro(
"__AMX_TILE__");
923 Builder.defineMacro(
"__AMX_INT8__");
925 Builder.defineMacro(
"__AMX_BF16__");
927 Builder.defineMacro(
"__AMX_FP16__");
929 Builder.defineMacro(
"__AMX_COMPLEX__");
931 Builder.defineMacro(
"__AMX_FP8__");
933 Builder.defineMacro(
"__AMX_MOVRS__");
935 Builder.defineMacro(
"__AMX_AVX512__");
937 Builder.defineMacro(
"__AMX_TF32__");
939 Builder.defineMacro(
"__CMPCCXADD__");
941 Builder.defineMacro(
"__RAOINT__");
943 Builder.defineMacro(
"__AVXIFMA__");
945 Builder.defineMacro(
"__AVXNECONVERT__");
947 Builder.defineMacro(
"__AVXVNNI__");
949 Builder.defineMacro(
"__AVXVNNIINT16__");
951 Builder.defineMacro(
"__AVXVNNIINT8__");
953 Builder.defineMacro(
"__SERIALIZE__");
955 Builder.defineMacro(
"__TSXLDTRK__");
957 Builder.defineMacro(
"__UINTR__");
959 Builder.defineMacro(
"__USERMSR__");
961 Builder.defineMacro(
"__CRC32__");
963 Builder.defineMacro(
"__EGPR__");
965 Builder.defineMacro(
"__PUSH2POP2__");
967 Builder.defineMacro(
"__PPX__");
969 Builder.defineMacro(
"__NDD__");
971 Builder.defineMacro(
"__CCMP__");
973 Builder.defineMacro(
"__NF__");
975 Builder.defineMacro(
"__CF__");
977 Builder.defineMacro(
"__ZU__");
978 if (HasEGPR && HasNDD && HasCCMP && HasNF && HasZU)
979 if (
getTriple().isOSWindows() || (HasPush2Pop2 && HasPPX))
980 Builder.defineMacro(
"__APX_F__");
981 if (HasEGPR && HasInlineAsmUseGPR32)
982 Builder.defineMacro(
"__APX_INLINE_ASM_USE_GPR32__");
987 Builder.defineMacro(
"__AVX512F__");
990 Builder.defineMacro(
"__AVX2__");
993 Builder.defineMacro(
"__AVX__");
996 Builder.defineMacro(
"__SSE4_2__");
999 Builder.defineMacro(
"__SSE4_1__");
1002 Builder.defineMacro(
"__SSSE3__");
1005 Builder.defineMacro(
"__SSE3__");
1008 Builder.defineMacro(
"__SSE2__");
1009 Builder.defineMacro(
"__SSE2_MATH__");
1012 Builder.defineMacro(
"__SSE__");
1013 Builder.defineMacro(
"__SSE_MATH__");
1019 if (Opts.MicrosoftExt &&
getTriple().getArch() == llvm::Triple::x86) {
1029 Builder.defineMacro(
"_M_IX86_FP", Twine(2));
1032 Builder.defineMacro(
"_M_IX86_FP", Twine(1));
1035 Builder.defineMacro(
"_M_IX86_FP", Twine(0));
1042 Builder.defineMacro(
"__MMX__");
1045 if (
CPU >= CK_i486 ||
CPU == CK_None) {
1046 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
1047 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
1048 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
1051 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
1052 if (HasCX16 &&
getTriple().getArch() == llvm::Triple::x86_64)
1053 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16");
1056 Builder.defineMacro(
"__SIZEOF_FLOAT128__",
"16");
1058 if (Opts.CFProtectionReturn || Opts.CFProtectionBranch)
1059 Builder.defineMacro(
"__CET__", Twine{(Opts.CFProtectionReturn << 1) |
1060 Opts.CFProtectionBranch});
1064 return llvm::StringSwitch<bool>(Name)
1067 .Case(
"amx-avx512",
true)
1068 .Case(
"amx-bf16",
true)
1069 .Case(
"amx-complex",
true)
1070 .Case(
"amx-fp16",
true)
1071 .Case(
"amx-fp8",
true)
1072 .Case(
"amx-int8",
true)
1073 .Case(
"amx-movrs",
true)
1074 .Case(
"amx-tf32",
true)
1075 .Case(
"amx-tile",
true)
1077 .Case(
"avx10.1",
true)
1078 .Case(
"avx10.2",
true)
1080 .Case(
"avx512f",
true)
1081 .Case(
"avx512cd",
true)
1082 .Case(
"avx512vpopcntdq",
true)
1083 .Case(
"avx512vnni",
true)
1084 .Case(
"avx512bf16",
true)
1085 .Case(
"avx512fp16",
true)
1086 .Case(
"avx512dq",
true)
1087 .Case(
"avx512bitalg",
true)
1088 .Case(
"avx512bw",
true)
1089 .Case(
"avx512vl",
true)
1090 .Case(
"avx512vbmi",
true)
1091 .Case(
"avx512vbmi2",
true)
1092 .Case(
"avx512ifma",
true)
1093 .Case(
"avx512vp2intersect",
true)
1094 .Case(
"avxifma",
true)
1095 .Case(
"avxneconvert",
true)
1096 .Case(
"avxvnni",
true)
1097 .Case(
"avxvnniint16",
true)
1098 .Case(
"avxvnniint8",
true)
1101 .Case(
"cldemote",
true)
1102 .Case(
"clflushopt",
true)
1104 .Case(
"clzero",
true)
1105 .Case(
"cmpccxadd",
true)
1106 .Case(
"crc32",
true)
1108 .Case(
"enqcmd",
true)
1112 .Case(
"fsgsbase",
true)
1114 .Case(
"general-regs-only",
true)
1116 .Case(
"hreset",
true)
1117 .Case(
"invpcid",
true)
1119 .Case(
"widekl",
true)
1121 .Case(
"lzcnt",
true)
1123 .Case(
"movbe",
true)
1124 .Case(
"movrs",
true)
1125 .Case(
"movdiri",
true)
1126 .Case(
"movdir64b",
true)
1127 .Case(
"mwaitx",
true)
1128 .Case(
"pclmul",
true)
1129 .Case(
"pconfig",
true)
1131 .Case(
"popcnt",
true)
1132 .Case(
"prefer-256-bit",
true)
1133 .Case(
"prefetchi",
true)
1134 .Case(
"prfchw",
true)
1135 .Case(
"ptwrite",
true)
1136 .Case(
"raoint",
true)
1137 .Case(
"rdpid",
true)
1138 .Case(
"rdpru",
true)
1139 .Case(
"rdrnd",
true)
1140 .Case(
"rdseed",
true)
1143 .Case(
"serialize",
true)
1146 .Case(
"sha512",
true)
1147 .Case(
"shstk",
true)
1153 .Case(
"ssse3",
true)
1155 .Case(
"sse4.1",
true)
1156 .Case(
"sse4.2",
true)
1157 .Case(
"sse4a",
true)
1159 .Case(
"tsxldtrk",
true)
1160 .Case(
"uintr",
true)
1161 .Case(
"usermsr",
true)
1163 .Case(
"vpclmulqdq",
true)
1164 .Case(
"wbnoinvd",
true)
1165 .Case(
"waitpkg",
true)
1168 .Case(
"xsave",
true)
1169 .Case(
"xsavec",
true)
1170 .Case(
"xsaves",
true)
1171 .Case(
"xsaveopt",
true)
1173 .Case(
"push2pop2",
true)
1184 return llvm::StringSwitch<bool>(
Feature)
1185 .Case(
"adx", HasADX)
1186 .Case(
"aes", HasAES)
1187 .Case(
"amx-avx512", HasAMXAVX512)
1188 .Case(
"amx-bf16", HasAMXBF16)
1189 .Case(
"amx-complex", HasAMXCOMPLEX)
1190 .Case(
"amx-fp16", HasAMXFP16)
1191 .Case(
"amx-fp8", HasAMXFP8)
1192 .Case(
"amx-int8", HasAMXINT8)
1193 .Case(
"amx-movrs", HasAMXMOVRS)
1194 .Case(
"amx-tf32", HasAMXTF32)
1195 .Case(
"amx-tile", HasAMXTILE)
1196 .Case(
"avx", SSELevel >= AVX)
1197 .Case(
"avx10.1", HasAVX10_1)
1198 .Case(
"avx10.2", HasAVX10_2)
1199 .Case(
"avx2", SSELevel >= AVX2)
1200 .Case(
"avx512f", SSELevel >= AVX512F)
1201 .Case(
"avx512cd", HasAVX512CD)
1202 .Case(
"avx512vpopcntdq", HasAVX512VPOPCNTDQ)
1203 .Case(
"avx512vnni", HasAVX512VNNI)
1204 .Case(
"avx512bf16", HasAVX512BF16)
1205 .Case(
"avx512fp16", HasAVX512FP16)
1206 .Case(
"avx512dq", HasAVX512DQ)
1207 .Case(
"avx512bitalg", HasAVX512BITALG)
1208 .Case(
"avx512bw", HasAVX512BW)
1209 .Case(
"avx512vl", HasAVX512VL)
1210 .Case(
"avx512vbmi", HasAVX512VBMI)
1211 .Case(
"avx512vbmi2", HasAVX512VBMI2)
1212 .Case(
"avx512ifma", HasAVX512IFMA)
1213 .Case(
"avx512vp2intersect", HasAVX512VP2INTERSECT)
1214 .Case(
"avxifma", HasAVXIFMA)
1215 .Case(
"avxneconvert", HasAVXNECONVERT)
1216 .Case(
"avxvnni", HasAVXVNNI)
1217 .Case(
"avxvnniint16", HasAVXVNNIINT16)
1218 .Case(
"avxvnniint8", HasAVXVNNIINT8)
1219 .Case(
"bmi", HasBMI)
1220 .Case(
"bmi2", HasBMI2)
1221 .Case(
"cldemote", HasCLDEMOTE)
1222 .Case(
"clflushopt", HasCLFLUSHOPT)
1223 .Case(
"clwb", HasCLWB)
1224 .Case(
"clzero", HasCLZERO)
1225 .Case(
"cmpccxadd", HasCMPCCXADD)
1226 .Case(
"crc32", HasCRC32)
1227 .Case(
"cx8", HasCX8)
1228 .Case(
"cx16", HasCX16)
1229 .Case(
"enqcmd", HasENQCMD)
1230 .Case(
"f16c", HasF16C)
1231 .Case(
"fma", HasFMA)
1232 .Case(
"fma4", XOPLevel >= FMA4)
1233 .Case(
"fsgsbase", HasFSGSBASE)
1234 .Case(
"fxsr", HasFXSR)
1235 .Case(
"gfni", HasGFNI)
1236 .Case(
"hreset", HasHRESET)
1237 .Case(
"invpcid", HasINVPCID)
1239 .Case(
"widekl", HasWIDEKL)
1240 .Case(
"lwp", HasLWP)
1241 .Case(
"lzcnt", HasLZCNT)
1242 .Case(
"mmx", HasMMX)
1243 .Case(
"movbe", HasMOVBE)
1244 .Case(
"movrs", HasMOVRS)
1245 .Case(
"movdiri", HasMOVDIRI)
1246 .Case(
"movdir64b", HasMOVDIR64B)
1247 .Case(
"mwaitx", HasMWAITX)
1248 .Case(
"pclmul", HasPCLMUL)
1249 .Case(
"pconfig", HasPCONFIG)
1250 .Case(
"pku", HasPKU)
1251 .Case(
"popcnt", HasPOPCNT)
1252 .Case(
"prefetchi", HasPREFETCHI)
1253 .Case(
"prfchw", HasPRFCHW)
1254 .Case(
"ptwrite", HasPTWRITE)
1255 .Case(
"raoint", HasRAOINT)
1256 .Case(
"rdpid", HasRDPID)
1257 .Case(
"rdpru", HasRDPRU)
1258 .Case(
"rdrnd", HasRDRND)
1259 .Case(
"rdseed", HasRDSEED)
1260 .Case(
"retpoline-external-thunk", HasRetpolineExternalThunk)
1261 .Case(
"rtm", HasRTM)
1262 .Case(
"sahf", HasLAHFSAHF)
1263 .Case(
"serialize", HasSERIALIZE)
1264 .Case(
"sgx", HasSGX)
1265 .Case(
"sha", HasSHA)
1266 .Case(
"sha512", HasSHA512)
1267 .Case(
"shstk", HasSHSTK)
1268 .Case(
"sm3", HasSM3)
1269 .Case(
"sm4", HasSM4)
1270 .Case(
"sse", SSELevel >= SSE1)
1271 .Case(
"sse2", SSELevel >= SSE2)
1272 .Case(
"sse3", SSELevel >= SSE3)
1273 .Case(
"ssse3", SSELevel >= SSSE3)
1274 .Case(
"sse4.1", SSELevel >= SSE41)
1275 .Case(
"sse4.2", SSELevel >= SSE42)
1276 .Case(
"sse4a", XOPLevel >= SSE4A)
1277 .Case(
"tbm", HasTBM)
1278 .Case(
"tsxldtrk", HasTSXLDTRK)
1279 .Case(
"uintr", HasUINTR)
1280 .Case(
"usermsr", HasUSERMSR)
1281 .Case(
"vaes", HasVAES)
1282 .Case(
"vpclmulqdq", HasVPCLMULQDQ)
1283 .Case(
"wbnoinvd", HasWBNOINVD)
1284 .Case(
"waitpkg", HasWAITPKG)
1286 .Case(
"x86_32",
getTriple().getArch() == llvm::Triple::x86)
1287 .Case(
"x86_64",
getTriple().getArch() == llvm::Triple::x86_64)
1288 .Case(
"x87", HasX87)
1289 .Case(
"xop", XOPLevel >= XOP)
1290 .Case(
"xsave", HasXSAVE)
1291 .Case(
"xsavec", HasXSAVEC)
1292 .Case(
"xsaves", HasXSAVES)
1293 .Case(
"xsaveopt", HasXSAVEOPT)
1295 .Case(
"egpr", HasEGPR)
1296 .Case(
"push2pop2", HasPush2Pop2)
1297 .Case(
"ppx", HasPPX)
1298 .Case(
"ndd", HasNDD)
1299 .Case(
"ccmp", HasCCMP)
1303 .Case(
"branch-hint", HasBranchHint)
1313 return llvm::StringSwitch<bool>(FeatureStr)
1314#define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY, ABI_VALUE) .Case(STR, true)
1315#define X86_MICROARCH_LEVEL(ENUM, STR, PRIORITY, ABI_VALUE) .Case(STR, true)
1316#include "llvm/TargetParser/X86TargetParser.def"
1321 return llvm::StringSwitch<llvm::X86::ProcessorFeatures>(Name)
1322#define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY, ABI_VALUE) \
1323 .Case(STR, llvm::X86::FEATURE_##ENUM)
1325#include "llvm/TargetParser/X86TargetParser.def"
1332 auto getPriority = [](StringRef
Feature) ->
unsigned {
1335 using namespace llvm::X86;
1336 CPUKind Kind = parseArchX86(
Feature);
1337 if (Kind != CK_None) {
1338 ProcessorFeatures KeyFeature = getKeyFeature(Kind);
1339 return (getFeaturePriority(KeyFeature) << 1) + 1;
1346 unsigned Priority = 0;
1347 for (StringRef
Feature : Features)
1349 Priority = std::max(Priority, getPriority(
Feature));
1350 return llvm::APInt(32, Priority);
1354 return llvm::X86::validateCPUSpecificCPUDispatch(Name);
1358 return llvm::X86::getCPUDispatchMangling(Name);
1364 llvm::X86::getFeaturesForCPU(Name, TargetCPUFeatures,
true);
1365 for (
auto &F : TargetCPUFeatures)
1366 Features.push_back(F);
1374 return llvm::StringSwitch<bool>(FeatureStr)
1375#define X86_VENDOR(ENUM, STRING) .Case(STRING, true)
1376#define X86_CPU_TYPE_ALIAS(ENUM, ALIAS) .Case(ALIAS, true)
1377#define X86_CPU_TYPE(ENUM, STR) .Case(STR, true)
1378#define X86_CPU_SUBTYPE_ALIAS(ENUM, ALIAS) .Case(ALIAS, true)
1379#define X86_CPU_SUBTYPE(ENUM, STR) .Case(STR, true)
1380#include "llvm/TargetParser/X86TargetParser.def"
1385 auto RV = llvm::StringSwitch<unsigned>(Name)
1554 using namespace llvm::X86;
1594 case CK_GoldmontPlus:
1599 case CK_SandyBridge:
1603 case CK_SkylakeClient:
1604 case CK_SkylakeServer:
1605 case CK_Cascadelake:
1610 case CK_SapphireRapids:
1611 case CK_IcelakeClient:
1613 case CK_IcelakeServer:
1620 case CK_Pantherlake:
1621 case CK_Wildcatlake:
1623 case CK_Sierraforest:
1625 case CK_Graniterapids:
1626 case CK_GraniterapidsD:
1627 case CK_Emeraldrapids:
1628 case CK_Clearwaterforest:
1629 case CK_Diamondrapids:
1667 return std::nullopt;
1669 llvm_unreachable(
"Unknown CPU kind");
1673 StringRef Constraint,
1674 unsigned Size)
const {
1676 Constraint = Constraint.ltrim(
"=+&");
1682 StringRef Constraint,
1683 unsigned Size)
const {
1688 StringRef Constraint,
1689 unsigned Size)
const {
1690 switch (Constraint[0]) {
1703 switch (Constraint[1]) {
1714 return Size <= 512U;
1717 return Size <= 256U;
1719 return Size <= 128U;
1725 if (SSELevel < SSE2)
1734 return Size <= 512U;
1737 return Size <= 256U;
1738 return Size <= 128U;
1746 switch (*Constraint) {
1749 std::string Converted =
"{" + std::string(Constraint, Len) +
"}";
1750 Constraint += Len - 1;
1753 return std::string(1, *Constraint);
1755 return std::string(
"{ax}");
1757 return std::string(
"{bx}");
1759 return std::string(
"{cx}");
1761 return std::string(
"{dx}");
1763 return std::string(
"{si}");
1765 return std::string(
"{di}");
1767 return std::string(
"p");
1769 return std::string(
"{st}");
1771 return std::string(
"{st(1)}");
1773 assert(Constraint[1] ==
's');
1774 return '^' + std::string(Constraint++, 2);
1776 switch (Constraint[1]) {
1791 return std::string(
"^") + std::string(Constraint++, 2);
1795 switch (Constraint[1]) {
1806 return std::string(
"^") + std::string(Constraint++, 2);
1810 return std::string(1, *Constraint);
1815 bool Only64Bit =
getTriple().getArch() != llvm::Triple::x86;
1816 llvm::X86::fillValidCPUArchList(Values, Only64Bit);
1820 llvm::X86::fillValidTuneCPUList(Values);
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...
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 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 ...
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.
The JSON file list parser is used to communicate input to InstallAPI.
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