17#include "llvm/ADT/StringExtras.h"
18#include "llvm/ADT/StringRef.h"
19#include "llvm/ADT/StringSwitch.h"
20#include "llvm/TargetParser/X86TargetParser.h"
27#define BUILTIN(ID, TYPE, ATTRS) \
28 {#ID, TYPE, ATTRS, nullptr, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
29#define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) \
30 {#ID, TYPE, ATTRS, FEATURE, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
31#define TARGET_HEADER_BUILTIN(ID, TYPE, ATTRS, HEADER, LANGS, FEATURE) \
32 {#ID, TYPE, ATTRS, FEATURE, HeaderDesc::HEADER, LANGS},
33#include "clang/Basic/BuiltinsX86.def"
35#define BUILTIN(ID, TYPE, ATTRS) \
36 {#ID, TYPE, ATTRS, nullptr, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
37#define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) \
38 {#ID, TYPE, ATTRS, FEATURE, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
39#define TARGET_HEADER_BUILTIN(ID, TYPE, ATTRS, HEADER, LANGS, FEATURE) \
40 {#ID, TYPE, ATTRS, FEATURE, HeaderDesc::HEADER, LANGS},
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",
66 "tmm0",
"tmm1",
"tmm2",
"tmm3",
"tmm4",
"tmm5",
"tmm6",
"tmm7",
67 "r16",
"r17",
"r18",
"r19",
"r20",
"r21",
"r22",
"r23",
68 "r24",
"r25",
"r26",
"r27",
"r28",
"r29",
"r30",
"r31",
72 {{
"al",
"ah",
"eax",
"rax"}, 0},
73 {{
"bl",
"bh",
"ebx",
"rbx"}, 3},
74 {{
"cl",
"ch",
"ecx",
"rcx"}, 2},
75 {{
"dl",
"dh",
"edx",
"rdx"}, 1},
80 {{
"r8d",
"r8w",
"r8b"}, 38},
81 {{
"r9d",
"r9w",
"r9b"}, 39},
82 {{
"r10d",
"r10w",
"r10b"}, 40},
83 {{
"r11d",
"r11w",
"r11b"}, 41},
84 {{
"r12d",
"r12w",
"r12b"}, 42},
85 {{
"r13d",
"r13w",
"r13b"}, 43},
86 {{
"r14d",
"r14w",
"r14b"}, 44},
87 {{
"r15d",
"r15w",
"r15b"}, 45},
88 {{
"r16d",
"r16w",
"r16b"}, 165},
89 {{
"r17d",
"r17w",
"r17b"}, 166},
90 {{
"r18d",
"r18w",
"r18b"}, 167},
91 {{
"r19d",
"r19w",
"r19b"}, 168},
92 {{
"r20d",
"r20w",
"r20b"}, 169},
93 {{
"r21d",
"r21w",
"r21b"}, 170},
94 {{
"r22d",
"r22w",
"r22b"}, 171},
95 {{
"r23d",
"r23w",
"r23b"}, 172},
96 {{
"r24d",
"r24w",
"r24b"}, 173},
97 {{
"r25d",
"r25w",
"r25b"}, 174},
98 {{
"r26d",
"r26w",
"r26b"}, 175},
99 {{
"r27d",
"r27w",
"r27b"}, 176},
100 {{
"r28d",
"r28w",
"r28b"}, 177},
101 {{
"r29d",
"r29w",
"r29b"}, 178},
102 {{
"r30d",
"r30w",
"r30b"}, 179},
103 {{
"r31d",
"r31w",
"r31b"}, 180},
108using namespace clang;
125 const std::vector<std::string> &FeaturesVec)
const {
128 if (
getTriple().getArch() == llvm::Triple::x86_64)
131 using namespace llvm::X86;
134 getFeaturesForCPU(
CPU, CPUFeatures);
135 for (
auto &F : CPUFeatures)
138 std::vector<std::string> UpdatedFeaturesVec;
139 std::vector<std::string> UpdatedAVX10FeaturesVec;
140 enum { FE_NOSET = -1, FE_FALSE, FE_TRUE };
141 int HasEVEX512 = FE_NOSET;
142 bool HasAVX512F = Features.lookup(
"avx512f");
143 bool HasAVX10 = Features.lookup(
"avx10.1-256");
144 bool HasAVX10_512 = Features.lookup(
"avx10.1-512");
145 std::string LastAVX10;
146 std::string LastAVX512;
147 for (
const auto &Feature : FeaturesVec) {
149 if (Feature ==
"+general-regs-only") {
150 UpdatedFeaturesVec.push_back(
"-x87");
151 UpdatedFeaturesVec.push_back(
"-mmx");
152 UpdatedFeaturesVec.push_back(
"-sse");
156 if (Feature.substr(1, 6) ==
"avx10.") {
157 if (Feature[0] ==
'+') {
159 if (StringRef(Feature).ends_with(
"512"))
162 }
else if (HasAVX10 && Feature ==
"-avx10.1-256") {
164 HasAVX10_512 =
false;
165 }
else if (HasAVX10_512 && Feature ==
"-avx10.1-512") {
166 HasAVX10_512 =
false;
169 UpdatedAVX10FeaturesVec.push_back(Feature);
171 }
else if (!HasAVX512F && StringRef(Feature).starts_with(
"+avx512")) {
173 LastAVX512 = Feature;
174 }
else if (HasAVX512F && Feature ==
"-avx512f") {
176 }
else if (HasEVEX512 != FE_TRUE && Feature ==
"+evex512") {
177 HasEVEX512 = FE_TRUE;
179 }
else if (HasEVEX512 != FE_FALSE && Feature ==
"-evex512") {
180 HasEVEX512 = FE_FALSE;
184 UpdatedFeaturesVec.push_back(Feature);
186 llvm::append_range(UpdatedFeaturesVec, UpdatedAVX10FeaturesVec);
189 if (!HasAVX10_512 && HasAVX512F) {
190 UpdatedFeaturesVec.push_back(HasEVEX512 == FE_FALSE ?
"-evex512"
192 if (HasAVX10 && HasEVEX512 != FE_FALSE)
193 Diags.
Report(diag::warn_invalid_feature_combination)
194 << LastAVX512 +
" " + LastAVX10 +
"; will be promoted to avx10.1-512";
195 }
else if (HasAVX10) {
196 if (!HasAVX512F && HasEVEX512 != FE_NOSET)
197 Diags.
Report(diag::warn_invalid_feature_combination)
198 << LastAVX10 + (HasEVEX512 == FE_TRUE ?
" +evex512" :
" -evex512");
199 UpdatedFeaturesVec.push_back(HasAVX10_512 ?
"+evex512" :
"-evex512");
209 auto I = Features.find(
"sse4.2");
210 if (I != Features.end() && I->getValue() &&
211 !llvm::is_contained(UpdatedFeaturesVec,
"-popcnt"))
212 Features[
"popcnt"] =
true;
216 I = Features.find(
"sse");
217 if (I != Features.end() && I->getValue() &&
218 !llvm::is_contained(UpdatedFeaturesVec,
"-mmx"))
219 Features[
"mmx"] =
true;
222 I = Features.find(
"avx");
223 if (I != Features.end() && I->getValue() &&
224 !llvm::is_contained(UpdatedFeaturesVec,
"-xsave"))
225 Features[
"xsave"] =
true;
228 I = Features.find(
"sse4.2");
229 if (I != Features.end() && I->getValue() &&
230 !llvm::is_contained(UpdatedFeaturesVec,
"-crc32"))
231 Features[
"crc32"] =
true;
237 StringRef Name,
bool Enabled)
const {
238 if (Name ==
"sse4") {
249 Features[Name] = Enabled;
250 llvm::X86::updateImpliedFeatures(Name, Enabled, Features);
257 for (
const auto &Feature : Features) {
258 if (Feature[0] !=
'+')
261 if (Feature ==
"+mmx") {
263 }
else if (Feature ==
"+aes") {
265 }
else if (Feature ==
"+vaes") {
267 }
else if (Feature ==
"+pclmul") {
269 }
else if (Feature ==
"+vpclmulqdq") {
270 HasVPCLMULQDQ =
true;
271 }
else if (Feature ==
"+lzcnt") {
273 }
else if (Feature ==
"+rdrnd") {
275 }
else if (Feature ==
"+fsgsbase") {
277 }
else if (Feature ==
"+bmi") {
279 }
else if (Feature ==
"+bmi2") {
281 }
else if (Feature ==
"+popcnt") {
283 }
else if (Feature ==
"+rtm") {
285 }
else if (Feature ==
"+prfchw") {
287 }
else if (Feature ==
"+rdseed") {
289 }
else if (Feature ==
"+adx") {
291 }
else if (Feature ==
"+tbm") {
293 }
else if (Feature ==
"+lwp") {
295 }
else if (Feature ==
"+fma") {
297 }
else if (Feature ==
"+f16c") {
299 }
else if (Feature ==
"+gfni") {
301 }
else if (Feature ==
"+evex512") {
303 }
else if (Feature ==
"+avx10.1-256") {
305 }
else if (Feature ==
"+avx10.1-512") {
306 HasAVX10_1_512 =
true;
307 }
else if (Feature ==
"+avx10.2-256") {
309 }
else if (Feature ==
"+avx10.2-512") {
310 HasAVX10_2_512 =
true;
311 }
else if (Feature ==
"+avx512cd") {
313 }
else if (Feature ==
"+avx512vpopcntdq") {
314 HasAVX512VPOPCNTDQ =
true;
315 }
else if (Feature ==
"+avx512vnni") {
316 HasAVX512VNNI =
true;
317 }
else if (Feature ==
"+avx512bf16") {
318 HasAVX512BF16 =
true;
319 }
else if (Feature ==
"+avx512fp16") {
320 HasAVX512FP16 =
true;
322 }
else if (Feature ==
"+avx512dq") {
324 }
else if (Feature ==
"+avx512bitalg") {
325 HasAVX512BITALG =
true;
326 }
else if (Feature ==
"+avx512bw") {
328 }
else if (Feature ==
"+avx512vl") {
330 }
else if (Feature ==
"+avx512vbmi") {
331 HasAVX512VBMI =
true;
332 }
else if (Feature ==
"+avx512vbmi2") {
333 HasAVX512VBMI2 =
true;
334 }
else if (Feature ==
"+avx512ifma") {
335 HasAVX512IFMA =
true;
336 }
else if (Feature ==
"+avx512vp2intersect") {
337 HasAVX512VP2INTERSECT =
true;
338 }
else if (Feature ==
"+sha") {
340 }
else if (Feature ==
"+sha512") {
342 }
else if (Feature ==
"+shstk") {
344 }
else if (Feature ==
"+sm3") {
346 }
else if (Feature ==
"+sm4") {
348 }
else if (Feature ==
"+movbe") {
350 }
else if (Feature ==
"+sgx") {
352 }
else if (Feature ==
"+cx8") {
354 }
else if (Feature ==
"+cx16") {
356 }
else if (Feature ==
"+fxsr") {
358 }
else if (Feature ==
"+xsave") {
360 }
else if (Feature ==
"+xsaveopt") {
362 }
else if (Feature ==
"+xsavec") {
364 }
else if (Feature ==
"+xsaves") {
366 }
else if (Feature ==
"+mwaitx") {
368 }
else if (Feature ==
"+pku") {
370 }
else if (Feature ==
"+clflushopt") {
371 HasCLFLUSHOPT =
true;
372 }
else if (Feature ==
"+clwb") {
374 }
else if (Feature ==
"+wbnoinvd") {
376 }
else if (Feature ==
"+prefetchi") {
378 }
else if (Feature ==
"+clzero") {
380 }
else if (Feature ==
"+cldemote") {
382 }
else if (Feature ==
"+rdpid") {
384 }
else if (Feature ==
"+rdpru") {
386 }
else if (Feature ==
"+kl") {
388 }
else if (Feature ==
"+widekl") {
390 }
else if (Feature ==
"+retpoline-external-thunk") {
391 HasRetpolineExternalThunk =
true;
392 }
else if (Feature ==
"+sahf") {
394 }
else if (Feature ==
"+waitpkg") {
396 }
else if (Feature ==
"+movdiri") {
398 }
else if (Feature ==
"+movdir64b") {
400 }
else if (Feature ==
"+pconfig") {
402 }
else if (Feature ==
"+ptwrite") {
404 }
else if (Feature ==
"+invpcid") {
406 }
else if (Feature ==
"+enqcmd") {
408 }
else if (Feature ==
"+hreset") {
410 }
else if (Feature ==
"+amx-bf16") {
412 }
else if (Feature ==
"+amx-fp16") {
414 }
else if (Feature ==
"+amx-int8") {
416 }
else if (Feature ==
"+amx-tile") {
418 }
else if (Feature ==
"+amx-complex") {
419 HasAMXCOMPLEX =
true;
420 }
else if (Feature ==
"+cmpccxadd") {
422 }
else if (Feature ==
"+raoint") {
424 }
else if (Feature ==
"+avxifma") {
426 }
else if (Feature ==
"+avxneconvert") {
427 HasAVXNECONVERT=
true;
428 }
else if (Feature ==
"+avxvnni") {
430 }
else if (Feature ==
"+avxvnniint16") {
431 HasAVXVNNIINT16 =
true;
432 }
else if (Feature ==
"+avxvnniint8") {
433 HasAVXVNNIINT8 =
true;
434 }
else if (Feature ==
"+serialize") {
436 }
else if (Feature ==
"+tsxldtrk") {
438 }
else if (Feature ==
"+uintr") {
440 }
else if (Feature ==
"+usermsr") {
442 }
else if (Feature ==
"+crc32") {
444 }
else if (Feature ==
"+x87") {
446 }
else if (Feature ==
"+fullbf16") {
448 }
else if (Feature ==
"+egpr") {
450 }
else if (Feature ==
"+inline-asm-use-gpr32") {
451 HasInlineAsmUseGPR32 =
true;
452 }
else if (Feature ==
"+push2pop2") {
454 }
else if (Feature ==
"+ppx") {
456 }
else if (Feature ==
"+ndd") {
458 }
else if (Feature ==
"+ccmp") {
460 }
else if (Feature ==
"+nf") {
462 }
else if (Feature ==
"+cf") {
464 }
else if (Feature ==
"+zu") {
466 }
else if (Feature ==
"+branch-hint") {
467 HasBranchHint =
true;
470 X86SSEEnum Level = llvm::StringSwitch<X86SSEEnum>(Feature)
471 .Case(
"+avx512f", AVX512F)
474 .Case(
"+sse4.2", SSE42)
475 .Case(
"+sse4.1", SSE41)
476 .Case(
"+ssse3", SSSE3)
481 SSELevel = std::max(SSELevel, Level);
496 XOPEnum XLevel = llvm::StringSwitch<XOPEnum>(Feature)
499 .Case(
"+sse4a", SSE4A)
501 XOPLevel = std::max(XOPLevel, XLevel);
508 Diags.
Report(diag::err_target_unsupported_fpmath)
526 Builder.defineMacro(
"__GCC_ASM_FLAG_OUTPUTS__");
529 if (CodeModel ==
"default")
531 Builder.defineMacro(
"__code_model_" + CodeModel +
"__");
534 if (
getTriple().getArch() == llvm::Triple::x86_64) {
535 Builder.defineMacro(
"__amd64__");
536 Builder.defineMacro(
"__amd64");
537 Builder.defineMacro(
"__x86_64");
538 Builder.defineMacro(
"__x86_64__");
539 if (
getTriple().getArchName() ==
"x86_64h") {
540 Builder.defineMacro(
"__x86_64h");
541 Builder.defineMacro(
"__x86_64h__");
547 Builder.defineMacro(
"__SEG_GS");
548 Builder.defineMacro(
"__SEG_FS");
549 Builder.defineMacro(
"__seg_gs",
"__attribute__((address_space(256)))");
550 Builder.defineMacro(
"__seg_fs",
"__attribute__((address_space(257)))");
555 using namespace llvm::X86;
561 Builder.defineMacro(
"__tune_i386__");
570 Builder.defineMacro(
"__pentium_mmx__");
571 Builder.defineMacro(
"__tune_pentium_mmx__");
580 Builder.defineMacro(
"__tune_pentium3__");
584 Builder.defineMacro(
"__tune_pentium2__");
612 case CK_GoldmontPlus:
626 case CK_SkylakeClient:
627 case CK_SkylakeServer:
631 case CK_IcelakeClient:
633 case CK_IcelakeServer:
635 case CK_SapphireRapids:
643 case CK_Sierraforest:
645 case CK_Graniterapids:
646 case CK_GraniterapidsD:
647 case CK_Emeraldrapids:
648 case CK_Clearwaterforest:
662 Builder.defineMacro(
"__tune_lakemont__");
665 Builder.defineMacro(
"__k6_2__");
666 Builder.defineMacro(
"__tune_k6_2__");
669 if (
CPU != CK_K6_2) {
673 Builder.defineMacro(
"__k6_3__");
674 Builder.defineMacro(
"__tune_k6_3__");
683 if (SSELevel != NoSSE) {
684 Builder.defineMacro(
"__athlon_sse__");
685 Builder.defineMacro(
"__tune_athlon_sse__");
736 Builder.defineMacro(
"__REGISTER_PREFIX__",
"");
741 Builder.defineMacro(
"__NO_MATH_INLINES");
744 Builder.defineMacro(
"__AES__");
747 Builder.defineMacro(
"__VAES__");
750 Builder.defineMacro(
"__PCLMUL__");
753 Builder.defineMacro(
"__VPCLMULQDQ__");
757 if (HasLAHFSAHF ||
getTriple().getArch() == llvm::Triple::x86)
758 Builder.defineMacro(
"__LAHF_SAHF__");
761 Builder.defineMacro(
"__LZCNT__");
764 Builder.defineMacro(
"__RDRND__");
767 Builder.defineMacro(
"__FSGSBASE__");
770 Builder.defineMacro(
"__BMI__");
773 Builder.defineMacro(
"__BMI2__");
776 Builder.defineMacro(
"__POPCNT__");
779 Builder.defineMacro(
"__RTM__");
782 Builder.defineMacro(
"__PRFCHW__");
785 Builder.defineMacro(
"__RDSEED__");
788 Builder.defineMacro(
"__ADX__");
791 Builder.defineMacro(
"__TBM__");
794 Builder.defineMacro(
"__LWP__");
797 Builder.defineMacro(
"__MWAITX__");
800 Builder.defineMacro(
"__MOVBE__");
804 Builder.defineMacro(
"__XOP__");
807 Builder.defineMacro(
"__FMA4__");
810 Builder.defineMacro(
"__SSE4A__");
817 Builder.defineMacro(
"__FMA__");
820 Builder.defineMacro(
"__F16C__");
823 Builder.defineMacro(
"__GFNI__");
826 Builder.defineMacro(
"__EVEX512__");
828 Builder.defineMacro(
"__AVX10_1__");
830 Builder.defineMacro(
"__AVX10_1_512__");
832 Builder.defineMacro(
"__AVX10_2__");
834 Builder.defineMacro(
"__AVX10_2_512__");
836 Builder.defineMacro(
"__AVX512CD__");
837 if (HasAVX512VPOPCNTDQ)
838 Builder.defineMacro(
"__AVX512VPOPCNTDQ__");
840 Builder.defineMacro(
"__AVX512VNNI__");
842 Builder.defineMacro(
"__AVX512BF16__");
844 Builder.defineMacro(
"__AVX512FP16__");
846 Builder.defineMacro(
"__AVX512DQ__");
848 Builder.defineMacro(
"__AVX512BITALG__");
850 Builder.defineMacro(
"__AVX512BW__");
852 Builder.defineMacro(
"__AVX512VL__");
853 Builder.defineMacro(
"__EVEX256__");
856 Builder.defineMacro(
"__AVX512VBMI__");
858 Builder.defineMacro(
"__AVX512VBMI2__");
860 Builder.defineMacro(
"__AVX512IFMA__");
861 if (HasAVX512VP2INTERSECT)
862 Builder.defineMacro(
"__AVX512VP2INTERSECT__");
864 Builder.defineMacro(
"__SHA__");
866 Builder.defineMacro(
"__SHA512__");
869 Builder.defineMacro(
"__FXSR__");
871 Builder.defineMacro(
"__XSAVE__");
873 Builder.defineMacro(
"__XSAVEOPT__");
875 Builder.defineMacro(
"__XSAVEC__");
877 Builder.defineMacro(
"__XSAVES__");
879 Builder.defineMacro(
"__PKU__");
881 Builder.defineMacro(
"__CLFLUSHOPT__");
883 Builder.defineMacro(
"__CLWB__");
885 Builder.defineMacro(
"__WBNOINVD__");
887 Builder.defineMacro(
"__SHSTK__");
889 Builder.defineMacro(
"__SGX__");
891 Builder.defineMacro(
"__SM3__");
893 Builder.defineMacro(
"__SM4__");
895 Builder.defineMacro(
"__PREFETCHI__");
897 Builder.defineMacro(
"__CLZERO__");
899 Builder.defineMacro(
"__KL__");
901 Builder.defineMacro(
"__WIDEKL__");
903 Builder.defineMacro(
"__RDPID__");
905 Builder.defineMacro(
"__RDPRU__");
907 Builder.defineMacro(
"__CLDEMOTE__");
909 Builder.defineMacro(
"__WAITPKG__");
911 Builder.defineMacro(
"__MOVDIRI__");
913 Builder.defineMacro(
"__MOVDIR64B__");
915 Builder.defineMacro(
"__PCONFIG__");
917 Builder.defineMacro(
"__PTWRITE__");
919 Builder.defineMacro(
"__INVPCID__");
921 Builder.defineMacro(
"__ENQCMD__");
923 Builder.defineMacro(
"__HRESET__");
925 Builder.defineMacro(
"__AMX_TILE__");
927 Builder.defineMacro(
"__AMX_INT8__");
929 Builder.defineMacro(
"__AMX_BF16__");
931 Builder.defineMacro(
"__AMX_FP16__");
933 Builder.defineMacro(
"__AMX_COMPLEX__");
935 Builder.defineMacro(
"__CMPCCXADD__");
937 Builder.defineMacro(
"__RAOINT__");
939 Builder.defineMacro(
"__AVXIFMA__");
941 Builder.defineMacro(
"__AVXNECONVERT__");
943 Builder.defineMacro(
"__AVXVNNI__");
945 Builder.defineMacro(
"__AVXVNNIINT16__");
947 Builder.defineMacro(
"__AVXVNNIINT8__");
949 Builder.defineMacro(
"__SERIALIZE__");
951 Builder.defineMacro(
"__TSXLDTRK__");
953 Builder.defineMacro(
"__UINTR__");
955 Builder.defineMacro(
"__USERMSR__");
957 Builder.defineMacro(
"__CRC32__");
959 Builder.defineMacro(
"__EGPR__");
961 Builder.defineMacro(
"__PUSH2POP2__");
963 Builder.defineMacro(
"__PPX__");
965 Builder.defineMacro(
"__NDD__");
967 Builder.defineMacro(
"__CCMP__");
969 Builder.defineMacro(
"__NF__");
971 Builder.defineMacro(
"__CF__");
973 Builder.defineMacro(
"__ZU__");
974 if (HasEGPR && HasPush2Pop2 && HasPPX && HasNDD && HasCCMP && HasNF &&
976 Builder.defineMacro(
"__APX_F__");
977 if (HasEGPR && HasInlineAsmUseGPR32)
978 Builder.defineMacro(
"__APX_INLINE_ASM_USE_GPR32__");
983 Builder.defineMacro(
"__AVX512F__");
986 Builder.defineMacro(
"__AVX2__");
989 Builder.defineMacro(
"__AVX__");
992 Builder.defineMacro(
"__SSE4_2__");
995 Builder.defineMacro(
"__SSE4_1__");
998 Builder.defineMacro(
"__SSSE3__");
1001 Builder.defineMacro(
"__SSE3__");
1004 Builder.defineMacro(
"__SSE2__");
1005 Builder.defineMacro(
"__SSE2_MATH__");
1008 Builder.defineMacro(
"__SSE__");
1009 Builder.defineMacro(
"__SSE_MATH__");
1015 if (Opts.MicrosoftExt &&
getTriple().getArch() == llvm::Triple::x86) {
1025 Builder.defineMacro(
"_M_IX86_FP", Twine(2));
1028 Builder.defineMacro(
"_M_IX86_FP", Twine(1));
1031 Builder.defineMacro(
"_M_IX86_FP", Twine(0));
1038 Builder.defineMacro(
"__MMX__");
1041 if (
CPU >= CK_i486 ||
CPU == CK_None) {
1042 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
1043 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
1044 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
1047 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
1048 if (HasCX16 &&
getTriple().getArch() == llvm::Triple::x86_64)
1049 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16");
1052 Builder.defineMacro(
"__SIZEOF_FLOAT128__",
"16");
1056 return llvm::StringSwitch<bool>(Name)
1059 .Case(
"amx-bf16",
true)
1060 .Case(
"amx-complex",
true)
1061 .Case(
"amx-fp16",
true)
1062 .Case(
"amx-int8",
true)
1063 .Case(
"amx-tile",
true)
1065 .Case(
"avx10.1-256",
true)
1066 .Case(
"avx10.1-512",
true)
1067 .Case(
"avx10.2-256",
true)
1068 .Case(
"avx10.2-512",
true)
1070 .Case(
"avx512f",
true)
1071 .Case(
"avx512cd",
true)
1072 .Case(
"avx512vpopcntdq",
true)
1073 .Case(
"avx512vnni",
true)
1074 .Case(
"avx512bf16",
true)
1075 .Case(
"avx512fp16",
true)
1076 .Case(
"avx512dq",
true)
1077 .Case(
"avx512bitalg",
true)
1078 .Case(
"avx512bw",
true)
1079 .Case(
"avx512vl",
true)
1080 .Case(
"avx512vbmi",
true)
1081 .Case(
"avx512vbmi2",
true)
1082 .Case(
"avx512ifma",
true)
1083 .Case(
"avx512vp2intersect",
true)
1084 .Case(
"avxifma",
true)
1085 .Case(
"avxneconvert",
true)
1086 .Case(
"avxvnni",
true)
1087 .Case(
"avxvnniint16",
true)
1088 .Case(
"avxvnniint8",
true)
1091 .Case(
"cldemote",
true)
1092 .Case(
"clflushopt",
true)
1094 .Case(
"clzero",
true)
1095 .Case(
"cmpccxadd",
true)
1096 .Case(
"crc32",
true)
1098 .Case(
"enqcmd",
true)
1099 .Case(
"evex512",
true)
1103 .Case(
"fsgsbase",
true)
1105 .Case(
"general-regs-only",
true)
1107 .Case(
"hreset",
true)
1108 .Case(
"invpcid",
true)
1110 .Case(
"widekl",
true)
1112 .Case(
"lzcnt",
true)
1114 .Case(
"movbe",
true)
1115 .Case(
"movdiri",
true)
1116 .Case(
"movdir64b",
true)
1117 .Case(
"mwaitx",
true)
1118 .Case(
"pclmul",
true)
1119 .Case(
"pconfig",
true)
1121 .Case(
"popcnt",
true)
1122 .Case(
"prefetchi",
true)
1123 .Case(
"prfchw",
true)
1124 .Case(
"ptwrite",
true)
1125 .Case(
"raoint",
true)
1126 .Case(
"rdpid",
true)
1127 .Case(
"rdpru",
true)
1128 .Case(
"rdrnd",
true)
1129 .Case(
"rdseed",
true)
1132 .Case(
"serialize",
true)
1135 .Case(
"sha512",
true)
1136 .Case(
"shstk",
true)
1142 .Case(
"ssse3",
true)
1144 .Case(
"sse4.1",
true)
1145 .Case(
"sse4.2",
true)
1146 .Case(
"sse4a",
true)
1148 .Case(
"tsxldtrk",
true)
1149 .Case(
"uintr",
true)
1150 .Case(
"usermsr",
true)
1152 .Case(
"vpclmulqdq",
true)
1153 .Case(
"wbnoinvd",
true)
1154 .Case(
"waitpkg",
true)
1157 .Case(
"xsave",
true)
1158 .Case(
"xsavec",
true)
1159 .Case(
"xsaves",
true)
1160 .Case(
"xsaveopt",
true)
1162 .Case(
"push2pop2",
true)
1173 return llvm::StringSwitch<bool>(Feature)
1174 .Case(
"adx", HasADX)
1175 .Case(
"aes", HasAES)
1176 .Case(
"amx-bf16", HasAMXBF16)
1177 .Case(
"amx-complex", HasAMXCOMPLEX)
1178 .Case(
"amx-fp16", HasAMXFP16)
1179 .Case(
"amx-int8", HasAMXINT8)
1180 .Case(
"amx-tile", HasAMXTILE)
1181 .Case(
"avx", SSELevel >= AVX)
1182 .Case(
"avx10.1-256", HasAVX10_1)
1183 .Case(
"avx10.1-512", HasAVX10_1_512)
1184 .Case(
"avx10.2-256", HasAVX10_2)
1185 .Case(
"avx10.2-512", HasAVX10_2_512)
1186 .Case(
"avx2", SSELevel >= AVX2)
1187 .Case(
"avx512f", SSELevel >= AVX512F)
1188 .Case(
"avx512cd", HasAVX512CD)
1189 .Case(
"avx512vpopcntdq", HasAVX512VPOPCNTDQ)
1190 .Case(
"avx512vnni", HasAVX512VNNI)
1191 .Case(
"avx512bf16", HasAVX512BF16)
1192 .Case(
"avx512fp16", HasAVX512FP16)
1193 .Case(
"avx512dq", HasAVX512DQ)
1194 .Case(
"avx512bitalg", HasAVX512BITALG)
1195 .Case(
"avx512bw", HasAVX512BW)
1196 .Case(
"avx512vl", HasAVX512VL)
1197 .Case(
"avx512vbmi", HasAVX512VBMI)
1198 .Case(
"avx512vbmi2", HasAVX512VBMI2)
1199 .Case(
"avx512ifma", HasAVX512IFMA)
1200 .Case(
"avx512vp2intersect", HasAVX512VP2INTERSECT)
1201 .Case(
"avxifma", HasAVXIFMA)
1202 .Case(
"avxneconvert", HasAVXNECONVERT)
1203 .Case(
"avxvnni", HasAVXVNNI)
1204 .Case(
"avxvnniint16", HasAVXVNNIINT16)
1205 .Case(
"avxvnniint8", HasAVXVNNIINT8)
1206 .Case(
"bmi", HasBMI)
1207 .Case(
"bmi2", HasBMI2)
1208 .Case(
"cldemote", HasCLDEMOTE)
1209 .Case(
"clflushopt", HasCLFLUSHOPT)
1210 .Case(
"clwb", HasCLWB)
1211 .Case(
"clzero", HasCLZERO)
1212 .Case(
"cmpccxadd", HasCMPCCXADD)
1213 .Case(
"crc32", HasCRC32)
1214 .Case(
"cx8", HasCX8)
1215 .Case(
"cx16", HasCX16)
1216 .Case(
"enqcmd", HasENQCMD)
1217 .Case(
"evex512", HasEVEX512)
1218 .Case(
"f16c", HasF16C)
1219 .Case(
"fma", HasFMA)
1220 .Case(
"fma4", XOPLevel >= FMA4)
1221 .Case(
"fsgsbase", HasFSGSBASE)
1222 .Case(
"fxsr", HasFXSR)
1223 .Case(
"gfni", HasGFNI)
1224 .Case(
"hreset", HasHRESET)
1225 .Case(
"invpcid", HasINVPCID)
1227 .Case(
"widekl", HasWIDEKL)
1228 .Case(
"lwp", HasLWP)
1229 .Case(
"lzcnt", HasLZCNT)
1230 .Case(
"mmx", HasMMX)
1231 .Case(
"movbe", HasMOVBE)
1232 .Case(
"movdiri", HasMOVDIRI)
1233 .Case(
"movdir64b", HasMOVDIR64B)
1234 .Case(
"mwaitx", HasMWAITX)
1235 .Case(
"pclmul", HasPCLMUL)
1236 .Case(
"pconfig", HasPCONFIG)
1237 .Case(
"pku", HasPKU)
1238 .Case(
"popcnt", HasPOPCNT)
1239 .Case(
"prefetchi", HasPREFETCHI)
1240 .Case(
"prfchw", HasPRFCHW)
1241 .Case(
"ptwrite", HasPTWRITE)
1242 .Case(
"raoint", HasRAOINT)
1243 .Case(
"rdpid", HasRDPID)
1244 .Case(
"rdpru", HasRDPRU)
1245 .Case(
"rdrnd", HasRDRND)
1246 .Case(
"rdseed", HasRDSEED)
1247 .Case(
"retpoline-external-thunk", HasRetpolineExternalThunk)
1248 .Case(
"rtm", HasRTM)
1249 .Case(
"sahf", HasLAHFSAHF)
1250 .Case(
"serialize", HasSERIALIZE)
1251 .Case(
"sgx", HasSGX)
1252 .Case(
"sha", HasSHA)
1253 .Case(
"sha512", HasSHA512)
1254 .Case(
"shstk", HasSHSTK)
1255 .Case(
"sm3", HasSM3)
1256 .Case(
"sm4", HasSM4)
1257 .Case(
"sse", SSELevel >= SSE1)
1258 .Case(
"sse2", SSELevel >= SSE2)
1259 .Case(
"sse3", SSELevel >= SSE3)
1260 .Case(
"ssse3", SSELevel >= SSSE3)
1261 .Case(
"sse4.1", SSELevel >= SSE41)
1262 .Case(
"sse4.2", SSELevel >= SSE42)
1263 .Case(
"sse4a", XOPLevel >= SSE4A)
1264 .Case(
"tbm", HasTBM)
1265 .Case(
"tsxldtrk", HasTSXLDTRK)
1266 .Case(
"uintr", HasUINTR)
1267 .Case(
"usermsr", HasUSERMSR)
1268 .Case(
"vaes", HasVAES)
1269 .Case(
"vpclmulqdq", HasVPCLMULQDQ)
1270 .Case(
"wbnoinvd", HasWBNOINVD)
1271 .Case(
"waitpkg", HasWAITPKG)
1273 .Case(
"x86_32",
getTriple().getArch() == llvm::Triple::x86)
1274 .Case(
"x86_64",
getTriple().getArch() == llvm::Triple::x86_64)
1275 .Case(
"x87", HasX87)
1276 .Case(
"xop", XOPLevel >= XOP)
1277 .Case(
"xsave", HasXSAVE)
1278 .Case(
"xsavec", HasXSAVEC)
1279 .Case(
"xsaves", HasXSAVES)
1280 .Case(
"xsaveopt", HasXSAVEOPT)
1282 .Case(
"egpr", HasEGPR)
1283 .Case(
"push2pop2", HasPush2Pop2)
1284 .Case(
"ppx", HasPPX)
1285 .Case(
"ndd", HasNDD)
1286 .Case(
"ccmp", HasCCMP)
1290 .Case(
"branch-hint", HasBranchHint)
1300 return llvm::StringSwitch<bool>(FeatureStr)
1301#define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY) .Case(STR, true)
1302#define X86_MICROARCH_LEVEL(ENUM, STR, PRIORITY) .Case(STR, true)
1303#include "llvm/TargetParser/X86TargetParser.def"
1308 return llvm::StringSwitch<llvm::X86::ProcessorFeatures>(Name)
1309#define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY) \
1310 .Case(STR, llvm::X86::FEATURE_##ENUM)
1312#include "llvm/TargetParser/X86TargetParser.def"
1321 using namespace llvm::X86;
1322 CPUKind Kind = parseArchX86(Name);
1323 if (Kind != CK_None) {
1324 ProcessorFeatures KeyFeature = getKeyFeature(Kind);
1325 return (getFeaturePriority(KeyFeature) << 1) + 1;
1330 return getFeaturePriority(
getFeature(Name)) << 1;
1334 return llvm::X86::validateCPUSpecificCPUDispatch(Name);
1338 return llvm::X86::getCPUDispatchMangling(Name);
1344 llvm::X86::getFeaturesForCPU(Name, TargetCPUFeatures,
true);
1345 for (
auto &F : TargetCPUFeatures)
1346 Features.push_back(F);
1354 return llvm::StringSwitch<bool>(FeatureStr)
1355#define X86_VENDOR(ENUM, STRING) .Case(STRING, true)
1356#define X86_CPU_TYPE_ALIAS(ENUM, ALIAS) .Case(ALIAS, true)
1357#define X86_CPU_TYPE(ENUM, STR) .Case(STR, true)
1358#define X86_CPU_SUBTYPE_ALIAS(ENUM, ALIAS) .Case(ALIAS, true)
1359#define X86_CPU_SUBTYPE(ENUM, STR) .Case(STR, true)
1360#include "llvm/TargetParser/X86TargetParser.def"
1365 auto RV = llvm::StringSwitch<unsigned>(Name)
1533 using namespace llvm::X86;
1573 case CK_GoldmontPlus:
1578 case CK_SandyBridge:
1582 case CK_SkylakeClient:
1583 case CK_SkylakeServer:
1584 case CK_Cascadelake:
1589 case CK_SapphireRapids:
1590 case CK_IcelakeClient:
1592 case CK_IcelakeServer:
1599 case CK_Pantherlake:
1600 case CK_Sierraforest:
1602 case CK_Graniterapids:
1603 case CK_GraniterapidsD:
1604 case CK_Emeraldrapids:
1605 case CK_Clearwaterforest:
1641 return std::nullopt;
1643 llvm_unreachable(
"Unknown CPU kind");
1647 StringRef Constraint,
1648 unsigned Size)
const {
1650 Constraint = Constraint.ltrim(
"=+&");
1656 StringRef Constraint,
1657 unsigned Size)
const {
1662 StringRef Constraint,
1663 unsigned Size)
const {
1664 switch (Constraint[0]) {
1677 switch (Constraint[1]) {
1689 return Size <= 512U;
1692 return Size <= 256U;
1694 return Size <= 128U;
1700 if (SSELevel < SSE2)
1711 return Size <= 512U;
1714 return Size <= 256U;
1715 return Size <= 128U;
1723 switch (*Constraint) {
1726 std::string Converted =
"{" + std::string(Constraint, Len) +
"}";
1727 Constraint += Len - 1;
1730 return std::string(1, *Constraint);
1732 return std::string(
"{ax}");
1734 return std::string(
"{bx}");
1736 return std::string(
"{cx}");
1738 return std::string(
"{dx}");
1740 return std::string(
"{si}");
1742 return std::string(
"{di}");
1744 return std::string(
"p");
1746 return std::string(
"{st}");
1748 return std::string(
"{st(1)}");
1750 assert(Constraint[1] ==
's');
1751 return '^' + std::string(Constraint++, 2);
1753 switch (Constraint[1]) {
1768 return std::string(
"^") + std::string(Constraint++, 2);
1772 switch (Constraint[1]) {
1783 return std::string(
"^") + std::string(Constraint++, 2);
1787 return std::string(1, *Constraint);
1792 bool Only64Bit =
getTriple().getArch() != llvm::Triple::x86;
1793 llvm::X86::fillValidCPUArchList(Values, Only64Bit);
1797 llvm::X86::fillValidTuneCPUList(Values);
Defines the Diagnostic-related interfaces.
static unsigned matchAsmCCConstraint(const char *Name)
static llvm::X86::ProcessorFeatures getFeature(StringRef Name)
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
unsigned multiVersionSortPriority(StringRef Name) 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
ArrayRef< Builtin::Info > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
ArrayRef< Builtin::Info > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
void defineCPUMacros(MacroBuilder &Builder, StringRef CPUName, bool Tuning)
static constexpr Builtin::Info BuiltinInfoX86[]
const TargetInfo::AddlRegName AddlRegNames[]
static const char *const GCCRegNames[]
void DefineStd(MacroBuilder &Builder, StringRef MacroName, const LangOptions &Opts)
DefineStd - Define a macro name and standard variants.
The JSON file list parser is used to communicate input to InstallAPI.
std::string ConstraintStr
void setRequiresImmediate(int Min, int Max)
const llvm::fltSemantics * LongDoubleFormat