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",
70 {{
"al",
"ah",
"eax",
"rax"}, 0},
71 {{
"bl",
"bh",
"ebx",
"rbx"}, 3},
72 {{
"cl",
"ch",
"ecx",
"rcx"}, 2},
73 {{
"dl",
"dh",
"edx",
"rdx"}, 1},
78 {{
"r8d",
"r8w",
"r8b"}, 38},
79 {{
"r9d",
"r9w",
"r9b"}, 39},
80 {{
"r10d",
"r10w",
"r10b"}, 40},
81 {{
"r11d",
"r11w",
"r11b"}, 41},
82 {{
"r12d",
"r12w",
"r12b"}, 42},
83 {{
"r13d",
"r13w",
"r13b"}, 43},
84 {{
"r14d",
"r14w",
"r14b"}, 44},
85 {{
"r15d",
"r15w",
"r15b"}, 45},
108 const std::vector<std::string> &FeaturesVec)
const {
111 if (
getTriple().getArch() == llvm::Triple::x86_64)
114 using namespace llvm::X86;
117 getFeaturesForCPU(
CPU, CPUFeatures);
118 for (
auto &F : CPUFeatures)
121 std::vector<std::string> UpdatedFeaturesVec;
122 std::vector<std::string> UpdatedAVX10FeaturesVec;
123 enum { FE_NOSET = -1, FE_FALSE, FE_TRUE };
124 int HasEVEX512 = FE_NOSET;
125 bool HasAVX512F = Features.lookup(
"avx512f");
126 bool HasAVX10 = Features.lookup(
"avx10.1-256");
127 bool HasAVX10_512 = Features.lookup(
"avx10.1-512");
128 std::string LastAVX10;
129 std::string LastAVX512;
130 for (
const auto &Feature : FeaturesVec) {
132 if (Feature ==
"+general-regs-only") {
133 UpdatedFeaturesVec.push_back(
"-x87");
134 UpdatedFeaturesVec.push_back(
"-mmx");
135 UpdatedFeaturesVec.push_back(
"-sse");
139 if (Feature.substr(1, 6) ==
"avx10.") {
140 if (Feature[0] ==
'+') {
142 if (StringRef(Feature).ends_with(
"512"))
145 }
else if (HasAVX10 && Feature ==
"-avx10.1-256") {
147 HasAVX10_512 =
false;
148 }
else if (HasAVX10_512 && Feature ==
"-avx10.1-512") {
149 HasAVX10_512 =
false;
152 UpdatedAVX10FeaturesVec.push_back(Feature);
154 }
else if (!HasAVX512F && StringRef(Feature).starts_with(
"+avx512")) {
156 LastAVX512 = Feature;
157 }
else if (HasAVX512F && Feature ==
"-avx512f") {
159 }
else if (HasEVEX512 != FE_TRUE && Feature ==
"+evex512") {
160 HasEVEX512 = FE_TRUE;
162 }
else if (HasEVEX512 != FE_FALSE && Feature ==
"-evex512") {
163 HasEVEX512 = FE_FALSE;
167 UpdatedFeaturesVec.push_back(Feature);
169 llvm::append_range(UpdatedFeaturesVec, UpdatedAVX10FeaturesVec);
173 UpdatedFeaturesVec.push_back(HasEVEX512 == FE_FALSE ?
"-evex512"
175 if (HasAVX10 && !HasAVX10_512 && HasEVEX512 != FE_FALSE)
176 Diags.
Report(diag::warn_invalid_feature_combination)
177 << LastAVX512 +
" " + LastAVX10 +
"; will be promoted to avx10.1-512";
178 }
else if (HasAVX10) {
179 if (HasEVEX512 != FE_NOSET)
180 Diags.
Report(diag::warn_invalid_feature_combination)
181 << LastAVX10 + (HasEVEX512 == FE_TRUE ?
" +evex512" :
" -evex512");
182 UpdatedFeaturesVec.push_back(HasAVX10_512 ?
"+evex512" :
"-evex512");
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) {
241 if (Feature[0] !=
'+')
244 if (Feature ==
"+aes") {
246 }
else if (Feature ==
"+vaes") {
248 }
else if (Feature ==
"+pclmul") {
250 }
else if (Feature ==
"+vpclmulqdq") {
251 HasVPCLMULQDQ =
true;
252 }
else if (Feature ==
"+lzcnt") {
254 }
else if (Feature ==
"+rdrnd") {
256 }
else if (Feature ==
"+fsgsbase") {
258 }
else if (Feature ==
"+bmi") {
260 }
else if (Feature ==
"+bmi2") {
262 }
else if (Feature ==
"+popcnt") {
264 }
else if (Feature ==
"+rtm") {
266 }
else if (Feature ==
"+prfchw") {
268 }
else if (Feature ==
"+rdseed") {
270 }
else if (Feature ==
"+adx") {
272 }
else if (Feature ==
"+tbm") {
274 }
else if (Feature ==
"+lwp") {
276 }
else if (Feature ==
"+fma") {
278 }
else if (Feature ==
"+f16c") {
280 }
else if (Feature ==
"+gfni") {
282 }
else if (Feature ==
"+evex512") {
284 }
else if (Feature ==
"+avx10.1-256") {
286 }
else if (Feature ==
"+avx10.1-512") {
287 HasAVX10_1_512 =
true;
288 }
else if (Feature ==
"+avx512cd") {
290 }
else if (Feature ==
"+avx512vpopcntdq") {
291 HasAVX512VPOPCNTDQ =
true;
292 }
else if (Feature ==
"+avx512vnni") {
293 HasAVX512VNNI =
true;
294 }
else if (Feature ==
"+avx512bf16") {
295 HasAVX512BF16 =
true;
296 }
else if (Feature ==
"+avx512er") {
298 Diags.
Report(diag::warn_knl_knm_isa_support_removed);
299 }
else if (Feature ==
"+avx512fp16") {
300 HasAVX512FP16 =
true;
302 }
else if (Feature ==
"+avx512pf") {
304 Diags.
Report(diag::warn_knl_knm_isa_support_removed);
305 }
else if (Feature ==
"+avx512dq") {
307 }
else if (Feature ==
"+avx512bitalg") {
308 HasAVX512BITALG =
true;
309 }
else if (Feature ==
"+avx512bw") {
311 }
else if (Feature ==
"+avx512vl") {
313 }
else if (Feature ==
"+avx512vbmi") {
314 HasAVX512VBMI =
true;
315 }
else if (Feature ==
"+avx512vbmi2") {
316 HasAVX512VBMI2 =
true;
317 }
else if (Feature ==
"+avx512ifma") {
318 HasAVX512IFMA =
true;
319 }
else if (Feature ==
"+avx512vp2intersect") {
320 HasAVX512VP2INTERSECT =
true;
321 }
else if (Feature ==
"+sha") {
323 }
else if (Feature ==
"+sha512") {
325 }
else if (Feature ==
"+shstk") {
327 }
else if (Feature ==
"+sm3") {
329 }
else if (Feature ==
"+sm4") {
331 }
else if (Feature ==
"+movbe") {
333 }
else if (Feature ==
"+sgx") {
335 }
else if (Feature ==
"+cx8") {
337 }
else if (Feature ==
"+cx16") {
339 }
else if (Feature ==
"+fxsr") {
341 }
else if (Feature ==
"+xsave") {
343 }
else if (Feature ==
"+xsaveopt") {
345 }
else if (Feature ==
"+xsavec") {
347 }
else if (Feature ==
"+xsaves") {
349 }
else if (Feature ==
"+mwaitx") {
351 }
else if (Feature ==
"+pku") {
353 }
else if (Feature ==
"+clflushopt") {
354 HasCLFLUSHOPT =
true;
355 }
else if (Feature ==
"+clwb") {
357 }
else if (Feature ==
"+wbnoinvd") {
359 }
else if (Feature ==
"+prefetchi") {
361 }
else if (Feature ==
"+prefetchwt1") {
362 HasPREFETCHWT1 =
true;
363 Diags.
Report(diag::warn_knl_knm_isa_support_removed);
364 }
else if (Feature ==
"+clzero") {
366 }
else if (Feature ==
"+cldemote") {
368 }
else if (Feature ==
"+rdpid") {
370 }
else if (Feature ==
"+rdpru") {
372 }
else if (Feature ==
"+kl") {
374 }
else if (Feature ==
"+widekl") {
376 }
else if (Feature ==
"+retpoline-external-thunk") {
377 HasRetpolineExternalThunk =
true;
378 }
else if (Feature ==
"+sahf") {
380 }
else if (Feature ==
"+waitpkg") {
382 }
else if (Feature ==
"+movdiri") {
384 }
else if (Feature ==
"+movdir64b") {
386 }
else if (Feature ==
"+pconfig") {
388 }
else if (Feature ==
"+ptwrite") {
390 }
else if (Feature ==
"+invpcid") {
392 }
else if (Feature ==
"+enqcmd") {
394 }
else if (Feature ==
"+hreset") {
396 }
else if (Feature ==
"+amx-bf16") {
398 }
else if (Feature ==
"+amx-fp16") {
400 }
else if (Feature ==
"+amx-int8") {
402 }
else if (Feature ==
"+amx-tile") {
404 }
else if (Feature ==
"+amx-complex") {
405 HasAMXCOMPLEX =
true;
406 }
else if (Feature ==
"+cmpccxadd") {
408 }
else if (Feature ==
"+raoint") {
410 }
else if (Feature ==
"+avxifma") {
412 }
else if (Feature ==
"+avxneconvert") {
413 HasAVXNECONVERT=
true;
414 }
else if (Feature ==
"+avxvnni") {
416 }
else if (Feature ==
"+avxvnniint16") {
417 HasAVXVNNIINT16 =
true;
418 }
else if (Feature ==
"+avxvnniint8") {
419 HasAVXVNNIINT8 =
true;
420 }
else if (Feature ==
"+serialize") {
422 }
else if (Feature ==
"+tsxldtrk") {
424 }
else if (Feature ==
"+uintr") {
426 }
else if (Feature ==
"+usermsr") {
428 }
else if (Feature ==
"+crc32") {
430 }
else if (Feature ==
"+x87") {
432 }
else if (Feature ==
"+fullbf16") {
434 }
else if (Feature ==
"+egpr") {
436 }
else if (Feature ==
"+push2pop2") {
438 }
else if (Feature ==
"+ppx") {
440 }
else if (Feature ==
"+ndd") {
442 }
else if (Feature ==
"+ccmp") {
444 }
else if (Feature ==
"+cf") {
448 X86SSEEnum Level = llvm::StringSwitch<X86SSEEnum>(Feature)
449 .Case(
"+avx512f", AVX512F)
452 .Case(
"+sse4.2", SSE42)
453 .Case(
"+sse4.1", SSE41)
454 .Case(
"+ssse3", SSSE3)
459 SSELevel = std::max(SSELevel, Level);
474 MMX3DNowEnum ThreeDNowLevel = llvm::StringSwitch<MMX3DNowEnum>(Feature)
475 .Case(
"+3dnowa", AMD3DNowAthlon)
476 .Case(
"+3dnow", AMD3DNow)
478 .Default(NoMMX3DNow);
479 MMX3DNowLevel = std::max(MMX3DNowLevel, ThreeDNowLevel);
481 XOPEnum XLevel = llvm::StringSwitch<XOPEnum>(Feature)
484 .Case(
"+sse4a", SSE4A)
486 XOPLevel = std::max(XOPLevel, XLevel);
493 Diags.
Report(diag::err_target_unsupported_fpmath)
511 Builder.defineMacro(
"__GCC_ASM_FLAG_OUTPUTS__");
514 if (CodeModel ==
"default")
516 Builder.defineMacro(
"__code_model_" + CodeModel +
"__");
519 if (
getTriple().getArch() == llvm::Triple::x86_64) {
520 Builder.defineMacro(
"__amd64__");
521 Builder.defineMacro(
"__amd64");
522 Builder.defineMacro(
"__x86_64");
523 Builder.defineMacro(
"__x86_64__");
524 if (
getTriple().getArchName() ==
"x86_64h") {
525 Builder.defineMacro(
"__x86_64h");
526 Builder.defineMacro(
"__x86_64h__");
532 Builder.defineMacro(
"__SEG_GS");
533 Builder.defineMacro(
"__SEG_FS");
534 Builder.defineMacro(
"__seg_gs",
"__attribute__((address_space(256)))");
535 Builder.defineMacro(
"__seg_fs",
"__attribute__((address_space(257)))");
540 using namespace llvm::X86;
546 Builder.defineMacro(
"__tune_i386__");
555 Builder.defineMacro(
"__pentium_mmx__");
556 Builder.defineMacro(
"__tune_pentium_mmx__");
565 Builder.defineMacro(
"__tune_pentium3__");
569 Builder.defineMacro(
"__tune_pentium2__");
597 case CK_GoldmontPlus:
611 case CK_SkylakeClient:
612 case CK_SkylakeServer:
616 case CK_IcelakeClient:
618 case CK_IcelakeServer:
620 case CK_SapphireRapids:
628 case CK_Sierraforest:
630 case CK_Graniterapids:
631 case CK_GraniterapidsD:
632 case CK_Emeraldrapids:
633 case CK_Clearwaterforest:
647 Builder.defineMacro(
"__tune_lakemont__");
650 Builder.defineMacro(
"__k6_2__");
651 Builder.defineMacro(
"__tune_k6_2__");
654 if (
CPU != CK_K6_2) {
658 Builder.defineMacro(
"__k6_3__");
659 Builder.defineMacro(
"__tune_k6_3__");
668 if (SSELevel != NoSSE) {
669 Builder.defineMacro(
"__athlon_sse__");
670 Builder.defineMacro(
"__tune_athlon_sse__");
721 Builder.defineMacro(
"__REGISTER_PREFIX__",
"");
726 Builder.defineMacro(
"__NO_MATH_INLINES");
729 Builder.defineMacro(
"__AES__");
732 Builder.defineMacro(
"__VAES__");
735 Builder.defineMacro(
"__PCLMUL__");
738 Builder.defineMacro(
"__VPCLMULQDQ__");
742 if (HasLAHFSAHF ||
getTriple().getArch() == llvm::Triple::x86)
743 Builder.defineMacro(
"__LAHF_SAHF__");
746 Builder.defineMacro(
"__LZCNT__");
749 Builder.defineMacro(
"__RDRND__");
752 Builder.defineMacro(
"__FSGSBASE__");
755 Builder.defineMacro(
"__BMI__");
758 Builder.defineMacro(
"__BMI2__");
761 Builder.defineMacro(
"__POPCNT__");
764 Builder.defineMacro(
"__RTM__");
767 Builder.defineMacro(
"__PRFCHW__");
770 Builder.defineMacro(
"__RDSEED__");
773 Builder.defineMacro(
"__ADX__");
776 Builder.defineMacro(
"__TBM__");
779 Builder.defineMacro(
"__LWP__");
782 Builder.defineMacro(
"__MWAITX__");
785 Builder.defineMacro(
"__MOVBE__");
789 Builder.defineMacro(
"__XOP__");
792 Builder.defineMacro(
"__FMA4__");
795 Builder.defineMacro(
"__SSE4A__");
802 Builder.defineMacro(
"__FMA__");
805 Builder.defineMacro(
"__F16C__");
808 Builder.defineMacro(
"__GFNI__");
811 Builder.defineMacro(
"__EVEX512__");
813 Builder.defineMacro(
"__AVX10_1__");
815 Builder.defineMacro(
"__AVX10_1_512__");
817 Builder.defineMacro(
"__AVX512CD__");
818 if (HasAVX512VPOPCNTDQ)
819 Builder.defineMacro(
"__AVX512VPOPCNTDQ__");
821 Builder.defineMacro(
"__AVX512VNNI__");
823 Builder.defineMacro(
"__AVX512BF16__");
825 Builder.defineMacro(
"__AVX512ER__");
827 Builder.defineMacro(
"__AVX512FP16__");
829 Builder.defineMacro(
"__AVX512PF__");
831 Builder.defineMacro(
"__AVX512DQ__");
833 Builder.defineMacro(
"__AVX512BITALG__");
835 Builder.defineMacro(
"__AVX512BW__");
837 Builder.defineMacro(
"__AVX512VL__");
838 Builder.defineMacro(
"__EVEX256__");
841 Builder.defineMacro(
"__AVX512VBMI__");
843 Builder.defineMacro(
"__AVX512VBMI2__");
845 Builder.defineMacro(
"__AVX512IFMA__");
846 if (HasAVX512VP2INTERSECT)
847 Builder.defineMacro(
"__AVX512VP2INTERSECT__");
849 Builder.defineMacro(
"__SHA__");
851 Builder.defineMacro(
"__SHA512__");
854 Builder.defineMacro(
"__FXSR__");
856 Builder.defineMacro(
"__XSAVE__");
858 Builder.defineMacro(
"__XSAVEOPT__");
860 Builder.defineMacro(
"__XSAVEC__");
862 Builder.defineMacro(
"__XSAVES__");
864 Builder.defineMacro(
"__PKU__");
866 Builder.defineMacro(
"__CLFLUSHOPT__");
868 Builder.defineMacro(
"__CLWB__");
870 Builder.defineMacro(
"__WBNOINVD__");
872 Builder.defineMacro(
"__SHSTK__");
874 Builder.defineMacro(
"__SGX__");
876 Builder.defineMacro(
"__SM3__");
878 Builder.defineMacro(
"__SM4__");
880 Builder.defineMacro(
"__PREFETCHI__");
882 Builder.defineMacro(
"__PREFETCHWT1__");
884 Builder.defineMacro(
"__CLZERO__");
886 Builder.defineMacro(
"__KL__");
888 Builder.defineMacro(
"__WIDEKL__");
890 Builder.defineMacro(
"__RDPID__");
892 Builder.defineMacro(
"__RDPRU__");
894 Builder.defineMacro(
"__CLDEMOTE__");
896 Builder.defineMacro(
"__WAITPKG__");
898 Builder.defineMacro(
"__MOVDIRI__");
900 Builder.defineMacro(
"__MOVDIR64B__");
902 Builder.defineMacro(
"__PCONFIG__");
904 Builder.defineMacro(
"__PTWRITE__");
906 Builder.defineMacro(
"__INVPCID__");
908 Builder.defineMacro(
"__ENQCMD__");
910 Builder.defineMacro(
"__HRESET__");
912 Builder.defineMacro(
"__AMX_TILE__");
914 Builder.defineMacro(
"__AMX_INT8__");
916 Builder.defineMacro(
"__AMX_BF16__");
918 Builder.defineMacro(
"__AMX_FP16__");
920 Builder.defineMacro(
"__AMX_COMPLEX__");
922 Builder.defineMacro(
"__CMPCCXADD__");
924 Builder.defineMacro(
"__RAOINT__");
926 Builder.defineMacro(
"__AVXIFMA__");
928 Builder.defineMacro(
"__AVXNECONVERT__");
930 Builder.defineMacro(
"__AVXVNNI__");
932 Builder.defineMacro(
"__AVXVNNIINT16__");
934 Builder.defineMacro(
"__AVXVNNIINT8__");
936 Builder.defineMacro(
"__SERIALIZE__");
938 Builder.defineMacro(
"__TSXLDTRK__");
940 Builder.defineMacro(
"__UINTR__");
942 Builder.defineMacro(
"__USERMSR__");
944 Builder.defineMacro(
"__CRC32__");
946 Builder.defineMacro(
"__EGPR__");
948 Builder.defineMacro(
"__PUSH2POP2__");
950 Builder.defineMacro(
"__PPX__");
952 Builder.defineMacro(
"__NDD__");
954 Builder.defineMacro(
"__CCMP__");
956 Builder.defineMacro(
"__CF__");
961 Builder.defineMacro(
"__AVX512F__");
964 Builder.defineMacro(
"__AVX2__");
967 Builder.defineMacro(
"__AVX__");
970 Builder.defineMacro(
"__SSE4_2__");
973 Builder.defineMacro(
"__SSE4_1__");
976 Builder.defineMacro(
"__SSSE3__");
979 Builder.defineMacro(
"__SSE3__");
982 Builder.defineMacro(
"__SSE2__");
983 Builder.defineMacro(
"__SSE2_MATH__");
986 Builder.defineMacro(
"__SSE__");
987 Builder.defineMacro(
"__SSE_MATH__");
993 if (Opts.MicrosoftExt &&
getTriple().getArch() == llvm::Triple::x86) {
1003 Builder.defineMacro(
"_M_IX86_FP", Twine(2));
1006 Builder.defineMacro(
"_M_IX86_FP", Twine(1));
1009 Builder.defineMacro(
"_M_IX86_FP", Twine(0));
1015 switch (MMX3DNowLevel) {
1016 case AMD3DNowAthlon:
1017 Builder.defineMacro(
"__3dNOW_A__");
1020 Builder.defineMacro(
"__3dNOW__");
1023 Builder.defineMacro(
"__MMX__");
1029 if (
CPU >= CK_i486 ||
CPU == CK_None) {
1030 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
1031 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
1032 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
1035 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
1036 if (HasCX16 &&
getTriple().getArch() == llvm::Triple::x86_64)
1037 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16");
1040 Builder.defineMacro(
"__SIZEOF_FLOAT128__",
"16");
1044 return llvm::StringSwitch<bool>(Name)
1045 .Case(
"3dnow",
true)
1046 .Case(
"3dnowa",
true)
1049 .Case(
"amx-bf16",
true)
1050 .Case(
"amx-complex",
true)
1051 .Case(
"amx-fp16",
true)
1052 .Case(
"amx-int8",
true)
1053 .Case(
"amx-tile",
true)
1055 .Case(
"avx10.1-256",
true)
1056 .Case(
"avx10.1-512",
true)
1058 .Case(
"avx512f",
true)
1059 .Case(
"avx512cd",
true)
1060 .Case(
"avx512vpopcntdq",
true)
1061 .Case(
"avx512vnni",
true)
1062 .Case(
"avx512bf16",
true)
1063 .Case(
"avx512er",
true)
1064 .Case(
"avx512fp16",
true)
1065 .Case(
"avx512pf",
true)
1066 .Case(
"avx512dq",
true)
1067 .Case(
"avx512bitalg",
true)
1068 .Case(
"avx512bw",
true)
1069 .Case(
"avx512vl",
true)
1070 .Case(
"avx512vbmi",
true)
1071 .Case(
"avx512vbmi2",
true)
1072 .Case(
"avx512ifma",
true)
1073 .Case(
"avx512vp2intersect",
true)
1074 .Case(
"avxifma",
true)
1075 .Case(
"avxneconvert",
true)
1076 .Case(
"avxvnni",
true)
1077 .Case(
"avxvnniint16",
true)
1078 .Case(
"avxvnniint8",
true)
1081 .Case(
"cldemote",
true)
1082 .Case(
"clflushopt",
true)
1084 .Case(
"clzero",
true)
1085 .Case(
"cmpccxadd",
true)
1086 .Case(
"crc32",
true)
1088 .Case(
"enqcmd",
true)
1089 .Case(
"evex512",
true)
1093 .Case(
"fsgsbase",
true)
1095 .Case(
"general-regs-only",
true)
1097 .Case(
"hreset",
true)
1098 .Case(
"invpcid",
true)
1100 .Case(
"widekl",
true)
1102 .Case(
"lzcnt",
true)
1104 .Case(
"movbe",
true)
1105 .Case(
"movdiri",
true)
1106 .Case(
"movdir64b",
true)
1107 .Case(
"mwaitx",
true)
1108 .Case(
"pclmul",
true)
1109 .Case(
"pconfig",
true)
1111 .Case(
"popcnt",
true)
1112 .Case(
"prefetchi",
true)
1113 .Case(
"prefetchwt1",
true)
1114 .Case(
"prfchw",
true)
1115 .Case(
"ptwrite",
true)
1116 .Case(
"raoint",
true)
1117 .Case(
"rdpid",
true)
1118 .Case(
"rdpru",
true)
1119 .Case(
"rdrnd",
true)
1120 .Case(
"rdseed",
true)
1123 .Case(
"serialize",
true)
1126 .Case(
"sha512",
true)
1127 .Case(
"shstk",
true)
1133 .Case(
"ssse3",
true)
1135 .Case(
"sse4.1",
true)
1136 .Case(
"sse4.2",
true)
1137 .Case(
"sse4a",
true)
1139 .Case(
"tsxldtrk",
true)
1140 .Case(
"uintr",
true)
1141 .Case(
"usermsr",
true)
1143 .Case(
"vpclmulqdq",
true)
1144 .Case(
"wbnoinvd",
true)
1145 .Case(
"waitpkg",
true)
1148 .Case(
"xsave",
true)
1149 .Case(
"xsavec",
true)
1150 .Case(
"xsaves",
true)
1151 .Case(
"xsaveopt",
true)
1153 .Case(
"push2pop2",
true)
1162 return llvm::StringSwitch<bool>(Feature)
1163 .Case(
"adx", HasADX)
1164 .Case(
"aes", HasAES)
1165 .Case(
"amx-bf16", HasAMXBF16)
1166 .Case(
"amx-complex", HasAMXCOMPLEX)
1167 .Case(
"amx-fp16", HasAMXFP16)
1168 .Case(
"amx-int8", HasAMXINT8)
1169 .Case(
"amx-tile", HasAMXTILE)
1170 .Case(
"avx", SSELevel >= AVX)
1171 .Case(
"avx10.1-256", HasAVX10_1)
1172 .Case(
"avx10.1-512", HasAVX10_1_512)
1173 .Case(
"avx2", SSELevel >= AVX2)
1174 .Case(
"avx512f", SSELevel >= AVX512F)
1175 .Case(
"avx512cd", HasAVX512CD)
1176 .Case(
"avx512vpopcntdq", HasAVX512VPOPCNTDQ)
1177 .Case(
"avx512vnni", HasAVX512VNNI)
1178 .Case(
"avx512bf16", HasAVX512BF16)
1179 .Case(
"avx512er", HasAVX512ER)
1180 .Case(
"avx512fp16", HasAVX512FP16)
1181 .Case(
"avx512pf", HasAVX512PF)
1182 .Case(
"avx512dq", HasAVX512DQ)
1183 .Case(
"avx512bitalg", HasAVX512BITALG)
1184 .Case(
"avx512bw", HasAVX512BW)
1185 .Case(
"avx512vl", HasAVX512VL)
1186 .Case(
"avx512vbmi", HasAVX512VBMI)
1187 .Case(
"avx512vbmi2", HasAVX512VBMI2)
1188 .Case(
"avx512ifma", HasAVX512IFMA)
1189 .Case(
"avx512vp2intersect", HasAVX512VP2INTERSECT)
1190 .Case(
"avxifma", HasAVXIFMA)
1191 .Case(
"avxneconvert", HasAVXNECONVERT)
1192 .Case(
"avxvnni", HasAVXVNNI)
1193 .Case(
"avxvnniint16", HasAVXVNNIINT16)
1194 .Case(
"avxvnniint8", HasAVXVNNIINT8)
1195 .Case(
"bmi", HasBMI)
1196 .Case(
"bmi2", HasBMI2)
1197 .Case(
"cldemote", HasCLDEMOTE)
1198 .Case(
"clflushopt", HasCLFLUSHOPT)
1199 .Case(
"clwb", HasCLWB)
1200 .Case(
"clzero", HasCLZERO)
1201 .Case(
"cmpccxadd", HasCMPCCXADD)
1202 .Case(
"crc32", HasCRC32)
1203 .Case(
"cx8", HasCX8)
1204 .Case(
"cx16", HasCX16)
1205 .Case(
"enqcmd", HasENQCMD)
1206 .Case(
"evex512", HasEVEX512)
1207 .Case(
"f16c", HasF16C)
1208 .Case(
"fma", HasFMA)
1209 .Case(
"fma4", XOPLevel >= FMA4)
1210 .Case(
"fsgsbase", HasFSGSBASE)
1211 .Case(
"fxsr", HasFXSR)
1212 .Case(
"gfni", HasGFNI)
1213 .Case(
"hreset", HasHRESET)
1214 .Case(
"invpcid", HasINVPCID)
1216 .Case(
"widekl", HasWIDEKL)
1217 .Case(
"lwp", HasLWP)
1218 .Case(
"lzcnt", HasLZCNT)
1219 .Case(
"mm3dnow", MMX3DNowLevel >= AMD3DNow)
1220 .Case(
"mm3dnowa", MMX3DNowLevel >= AMD3DNowAthlon)
1221 .Case(
"mmx", MMX3DNowLevel >= MMX)
1222 .Case(
"movbe", HasMOVBE)
1223 .Case(
"movdiri", HasMOVDIRI)
1224 .Case(
"movdir64b", HasMOVDIR64B)
1225 .Case(
"mwaitx", HasMWAITX)
1226 .Case(
"pclmul", HasPCLMUL)
1227 .Case(
"pconfig", HasPCONFIG)
1228 .Case(
"pku", HasPKU)
1229 .Case(
"popcnt", HasPOPCNT)
1230 .Case(
"prefetchi", HasPREFETCHI)
1231 .Case(
"prefetchwt1", HasPREFETCHWT1)
1232 .Case(
"prfchw", HasPRFCHW)
1233 .Case(
"ptwrite", HasPTWRITE)
1234 .Case(
"raoint", HasRAOINT)
1235 .Case(
"rdpid", HasRDPID)
1236 .Case(
"rdpru", HasRDPRU)
1237 .Case(
"rdrnd", HasRDRND)
1238 .Case(
"rdseed", HasRDSEED)
1239 .Case(
"retpoline-external-thunk", HasRetpolineExternalThunk)
1240 .Case(
"rtm", HasRTM)
1241 .Case(
"sahf", HasLAHFSAHF)
1242 .Case(
"serialize", HasSERIALIZE)
1243 .Case(
"sgx", HasSGX)
1244 .Case(
"sha", HasSHA)
1245 .Case(
"sha512", HasSHA512)
1246 .Case(
"shstk", HasSHSTK)
1247 .Case(
"sm3", HasSM3)
1248 .Case(
"sm4", HasSM4)
1249 .Case(
"sse", SSELevel >= SSE1)
1250 .Case(
"sse2", SSELevel >= SSE2)
1251 .Case(
"sse3", SSELevel >= SSE3)
1252 .Case(
"ssse3", SSELevel >= SSSE3)
1253 .Case(
"sse4.1", SSELevel >= SSE41)
1254 .Case(
"sse4.2", SSELevel >= SSE42)
1255 .Case(
"sse4a", XOPLevel >= SSE4A)
1256 .Case(
"tbm", HasTBM)
1257 .Case(
"tsxldtrk", HasTSXLDTRK)
1258 .Case(
"uintr", HasUINTR)
1259 .Case(
"usermsr", HasUSERMSR)
1260 .Case(
"vaes", HasVAES)
1261 .Case(
"vpclmulqdq", HasVPCLMULQDQ)
1262 .Case(
"wbnoinvd", HasWBNOINVD)
1263 .Case(
"waitpkg", HasWAITPKG)
1265 .Case(
"x86_32",
getTriple().getArch() == llvm::Triple::x86)
1266 .Case(
"x86_64",
getTriple().getArch() == llvm::Triple::x86_64)
1267 .Case(
"x87", HasX87)
1268 .Case(
"xop", XOPLevel >= XOP)
1269 .Case(
"xsave", HasXSAVE)
1270 .Case(
"xsavec", HasXSAVEC)
1271 .Case(
"xsaves", HasXSAVES)
1272 .Case(
"xsaveopt", HasXSAVEOPT)
1274 .Case(
"egpr", HasEGPR)
1275 .Case(
"push2pop2", HasPush2Pop2)
1276 .Case(
"ppx", HasPPX)
1277 .Case(
"ndd", HasNDD)
1278 .Case(
"ccmp", HasCCMP)
1289 return llvm::StringSwitch<bool>(FeatureStr)
1290#define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY) .Case(STR, true)
1291#define X86_MICROARCH_LEVEL(ENUM, STR, PRIORITY) .Case(STR, true)
1292#include "llvm/TargetParser/X86TargetParser.def"
1297 return llvm::StringSwitch<llvm::X86::ProcessorFeatures>(Name)
1298#define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY) \
1299 .Case(STR, llvm::X86::FEATURE_##ENUM)
1301#include "llvm/TargetParser/X86TargetParser.def"
1310 using namespace llvm::X86;
1311 CPUKind Kind = parseArchX86(Name);
1312 if (Kind != CK_None) {
1313 ProcessorFeatures KeyFeature = getKeyFeature(Kind);
1314 return (getFeaturePriority(KeyFeature) << 1) + 1;
1319 return getFeaturePriority(
getFeature(Name)) << 1;
1323 return llvm::X86::validateCPUSpecificCPUDispatch(Name);
1327 return llvm::X86::getCPUDispatchMangling(Name);
1333 llvm::X86::getFeaturesForCPU(Name, TargetCPUFeatures,
true);
1334 for (
auto &F : TargetCPUFeatures)
1335 Features.push_back(F);
1343 return llvm::StringSwitch<bool>(FeatureStr)
1344#define X86_VENDOR(ENUM, STRING) .Case(STRING, true)
1345#define X86_CPU_TYPE_ALIAS(ENUM, ALIAS) .Case(ALIAS, true)
1346#define X86_CPU_TYPE(ENUM, STR) .Case(STR, true)
1347#define X86_CPU_SUBTYPE_ALIAS(ENUM, ALIAS) .Case(ALIAS, true)
1348#define X86_CPU_SUBTYPE(ENUM, STR) .Case(STR, true)
1349#include "llvm/TargetParser/X86TargetParser.def"
1354 auto RV = llvm::StringSwitch<unsigned>(Name)
1510 using namespace llvm::X86;
1550 case CK_GoldmontPlus:
1555 case CK_SandyBridge:
1559 case CK_SkylakeClient:
1560 case CK_SkylakeServer:
1561 case CK_Cascadelake:
1566 case CK_SapphireRapids:
1567 case CK_IcelakeClient:
1569 case CK_IcelakeServer:
1576 case CK_Pantherlake:
1577 case CK_Sierraforest:
1579 case CK_Graniterapids:
1580 case CK_GraniterapidsD:
1581 case CK_Emeraldrapids:
1582 case CK_Clearwaterforest:
1618 return std::nullopt;
1620 llvm_unreachable(
"Unknown CPU kind");
1624 StringRef Constraint,
1625 unsigned Size)
const {
1627 Constraint = Constraint.ltrim(
"=+&");
1633 StringRef Constraint,
1634 unsigned Size)
const {
1639 StringRef Constraint,
1640 unsigned Size)
const {
1641 switch (Constraint[0]) {
1654 switch (Constraint[1]) {
1666 return Size <= 512U;
1669 return Size <= 256U;
1671 return Size <= 128U;
1677 if (SSELevel < SSE2)
1688 return Size <= 512U;
1691 return Size <= 256U;
1692 return Size <= 128U;
1700 switch (*Constraint) {
1703 std::string Converted =
"{" + std::string(Constraint, Len) +
"}";
1704 Constraint += Len - 1;
1707 return std::string(1, *Constraint);
1709 return std::string(
"{ax}");
1711 return std::string(
"{bx}");
1713 return std::string(
"{cx}");
1715 return std::string(
"{dx}");
1717 return std::string(
"{si}");
1719 return std::string(
"{di}");
1721 return std::string(
"p");
1723 return std::string(
"{st}");
1725 return std::string(
"{st(1)}");
1727 assert(Constraint[1] ==
's');
1728 return '^' + std::string(Constraint++, 2);
1730 switch (Constraint[1]) {
1745 return std::string(
"^") + std::string(Constraint++, 2);
1749 return std::string(1, *Constraint);
1754 bool Only64Bit =
getTriple().getArch() != llvm::Triple::x86;
1755 llvm::X86::fillValidCPUArchList(Values, Only64Bit);
1759 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