20 #include "llvm/Config/config.h"
38 #if defined(__APPLE__) && (defined(__ppc__) || defined(__powerpc__))
39 #include <mach/host_info.h>
40 #include <mach/mach.h>
41 #include <mach/mach_host.h>
42 #include <mach/machine.h>
45 #define DEBUG_TYPE "host-detection"
55 static std::unique_ptr<llvm::MemoryBuffer>
59 if (std::error_code EC = Text.
getError()) {
61 <<
"/proc/cpuinfo: " << EC.message() <<
"\n";
64 return std::move(*Text);
72 const char *
generic =
"generic";
86 while (CIP < CPUInfoEnd && CPUStart == 0) {
87 if (CIP < CPUInfoEnd && *CIP ==
'\n')
90 if (CIP < CPUInfoEnd && *CIP ==
'c') {
92 if (CIP < CPUInfoEnd && *CIP ==
'p') {
94 if (CIP < CPUInfoEnd && *CIP ==
'u') {
96 while (CIP < CPUInfoEnd && (*CIP ==
' ' || *CIP ==
'\t'))
99 if (CIP < CPUInfoEnd && *CIP ==
':') {
101 while (CIP < CPUInfoEnd && (*CIP ==
' ' || *CIP ==
'\t'))
104 if (CIP < CPUInfoEnd) {
106 while (CIP < CPUInfoEnd && (*CIP !=
' ' && *CIP !=
'\t' &&
107 *CIP !=
',' && *CIP !=
'\n'))
109 CPULen = CIP - CPUStart;
117 while (CIP < CPUInfoEnd && *CIP !=
'\n')
125 .Case(
"604e",
"604e")
127 .
Case(
"7400",
"7400")
128 .
Case(
"7410",
"7400")
129 .
Case(
"7447",
"7400")
130 .
Case(
"7455",
"7450")
132 .
Case(
"POWER4",
"970")
133 .
Case(
"PPC970FX",
"970")
134 .
Case(
"PPC970MP",
"970")
136 .
Case(
"POWER5",
"g5")
138 .
Case(
"POWER6",
"pwr6")
139 .
Case(
"POWER7",
"pwr7")
140 .
Case(
"POWER8",
"pwr8")
141 .
Case(
"POWER8E",
"pwr8")
142 .
Case(
"POWER8NVL",
"pwr8")
143 .
Case(
"POWER9",
"pwr9")
155 ProcCpuinfoContent.
split(Lines,
"\n");
160 for (
unsigned I = 0,
E = Lines.
size();
I !=
E; ++
I) {
162 Implementer = Lines[
I].substr(15).ltrim(
"\t :");
164 Hardware = Lines[
I].substr(8).ltrim(
"\t :");
167 if (Implementer ==
"0x41") {
175 for (
unsigned I = 0,
E = Lines.
size();
I !=
E; ++
I)
181 .Case(
"0x926",
"arm926ej-s")
182 .
Case(
"0xb02",
"mpcore")
183 .
Case(
"0xb36",
"arm1136j-s")
184 .
Case(
"0xb56",
"arm1156t2-s")
185 .
Case(
"0xb76",
"arm1176jz-s")
186 .
Case(
"0xc08",
"cortex-a8")
187 .
Case(
"0xc09",
"cortex-a9")
188 .
Case(
"0xc0f",
"cortex-a15")
189 .
Case(
"0xc20",
"cortex-m0")
190 .
Case(
"0xc23",
"cortex-m3")
191 .
Case(
"0xc24",
"cortex-m4")
192 .
Case(
"0xd04",
"cortex-a35")
193 .
Case(
"0xd03",
"cortex-a53")
194 .
Case(
"0xd07",
"cortex-a57")
195 .
Case(
"0xd08",
"cortex-a72")
196 .
Case(
"0xd09",
"cortex-a73")
200 if (Implementer ==
"0x51")
202 for (
unsigned I = 0,
E = Lines.
size();
I !=
E; ++
I)
208 .Case(
"0x06f",
"krait")
209 .
Case(
"0x201",
"kryo")
210 .
Case(
"0x205",
"kryo")
223 ProcCpuinfoContent.
split(Lines,
"\n");
227 for (
unsigned I = 0,
E = Lines.
size();
I !=
E; ++
I)
229 size_t Pos = Lines[
I].find(
":");
231 Lines[
I].drop_front(Pos + 1).split(CPUFeatures,
' ');
239 bool HaveVectorSupport =
false;
240 for (
unsigned I = 0,
E = CPUFeatures.
size();
I !=
E; ++
I) {
241 if (CPUFeatures[
I] ==
"vx")
242 HaveVectorSupport =
true;
246 for (
unsigned I = 0,
E = Lines.
size();
I !=
E; ++
I) {
248 size_t Pos = Lines[
I].find(
"machine = ");
250 Pos +=
sizeof(
"machine = ") - 1;
252 if (!Lines[
I].drop_front(Pos).getAsInteger(10, Id)) {
253 if (Id >= 3906 && HaveVectorSupport)
255 if (Id >= 2964 && HaveVectorSupport)
270 #if defined(__i386__) || defined(_M_IX86) || \
271 defined(__x86_64__) || defined(_M_X64)
273 enum VendorSignatures {
274 SIG_INTEL = 0x756e6547 ,
278 enum ProcessorVendors {
285 enum ProcessorTypes {
316 enum ProcessorSubtypes {
317 INTEL_COREI7_NEHALEM = 1,
318 INTEL_COREI7_WESTMERE,
319 INTEL_COREI7_SANDYBRIDGE,
328 INTEL_COREI7_IVYBRIDGE,
329 INTEL_COREI7_HASWELL,
330 INTEL_COREI7_BROADWELL,
331 INTEL_COREI7_SKYLAKE,
332 INTEL_COREI7_SKYLAKE_AVX512,
348 enum ProcessorFeatures {
377 FEATURE_AVX5124VNNIW,
378 FEATURE_AVX5124FMAPS,
379 FEATURE_AVX512VPOPCNTDQ,
393 static bool isCpuIdSupported() {
394 #if defined(__GNUC__) || defined(__clang__)
395 #if defined(__i386__)
396 int __cpuid_supported;
399 " movl %%eax,%%ecx\n"
400 " xorl $0x00200000,%%eax\n"
406 " cmpl %%eax,%%ecx\n"
410 :
"=r"(__cpuid_supported)
413 if (!__cpuid_supported)
423 static bool getX86CpuIDAndInfo(
unsigned value,
unsigned *rEAX,
unsigned *rEBX,
424 unsigned *rECX,
unsigned *rEDX) {
425 #if defined(__GNUC__) || defined(__clang__)
426 #if defined(__x86_64__)
429 __asm__(
"movq\t%%rbx, %%rsi\n\t"
431 "xchgq\t%%rbx, %%rsi\n\t"
432 :
"=a"(*rEAX),
"=S"(*rEBX),
"=c"(*rECX),
"=d"(*rEDX)
435 #elif defined(__i386__)
436 __asm__(
"movl\t%%ebx, %%esi\n\t"
438 "xchgl\t%%ebx, %%esi\n\t"
439 :
"=a"(*rEAX),
"=S"(*rEBX),
"=c"(*rECX),
"=d"(*rEDX)
445 #elif defined(_MSC_VER)
448 __cpuid(registers, value);
449 *rEAX = registers[0];
450 *rEBX = registers[1];
451 *rECX = registers[2];
452 *rEDX = registers[3];
462 static bool getX86CpuIDAndInfoEx(
unsigned value,
unsigned subleaf,
463 unsigned *rEAX,
unsigned *rEBX,
unsigned *rECX,
465 #if defined(__GNUC__) || defined(__clang__)
466 #if defined(__x86_64__)
469 __asm__(
"movq\t%%rbx, %%rsi\n\t"
471 "xchgq\t%%rbx, %%rsi\n\t"
472 :
"=a"(*rEAX),
"=S"(*rEBX),
"=c"(*rECX),
"=d"(*rEDX)
473 :
"a"(value),
"c"(subleaf));
475 #elif defined(__i386__)
476 __asm__(
"movl\t%%ebx, %%esi\n\t"
478 "xchgl\t%%ebx, %%esi\n\t"
479 :
"=a"(*rEAX),
"=S"(*rEBX),
"=c"(*rECX),
"=d"(*rEDX)
480 :
"a"(value),
"c"(subleaf));
485 #elif defined(_MSC_VER)
487 __cpuidex(registers, value, subleaf);
488 *rEAX = registers[0];
489 *rEBX = registers[1];
490 *rECX = registers[2];
491 *rEDX = registers[3];
499 static bool getX86XCR0(
unsigned *rEAX,
unsigned *rEDX) {
500 #if defined(__GNUC__) || defined(__clang__)
504 __asm__(
".byte 0x0f, 0x01, 0xd0" :
"=a"(*rEAX),
"=d"(*rEDX) :
"c"(0));
506 #elif defined(_MSC_FULL_VER) && defined(_XCR_XFEATURE_ENABLED_MASK)
507 unsigned long long Result = _xgetbv(_XCR_XFEATURE_ENABLED_MASK);
509 *rEDX = Result >> 32;
516 static void detectX86FamilyModel(
unsigned EAX,
unsigned *Family,
518 *Family = (EAX >> 8) & 0xf;
519 *Model = (EAX >> 4) & 0xf;
520 if (*Family == 6 || *Family == 0xf) {
523 *Family += (EAX >> 20) & 0xff;
525 *Model += ((EAX >> 16) & 0xf) << 4;
530 getIntelProcessorTypeAndSubtype(
unsigned Family,
unsigned Model,
531 unsigned Brand_id,
unsigned Features,
532 unsigned Features2,
unsigned *
Type,
565 *Type = INTEL_PENTIUM;
570 *Type = INTEL_PENTIUM;
571 *Subtype = INTEL_PENTIUM_MMX;
574 *Type = INTEL_PENTIUM;
581 *Type = INTEL_PENTIUM_PRO;
588 *Type = INTEL_PENTIUM_II;
596 *Type = INTEL_PENTIUM_III;
603 *Type = INTEL_PENTIUM_M;
607 *Type = INTEL_CORE_DUO;
617 *Subtype = INTEL_CORE2_65;
626 *Subtype = INTEL_CORE2_45;
634 *Type = INTEL_COREI7;
635 *Subtype = INTEL_COREI7_NEHALEM;
641 *Type = INTEL_COREI7;
642 *Subtype = INTEL_COREI7_WESTMERE;
647 *Type = INTEL_COREI7;
648 *Subtype = INTEL_COREI7_SANDYBRIDGE;
652 *Type = INTEL_COREI7;
653 *Subtype = INTEL_COREI7_IVYBRIDGE;
661 *Type = INTEL_COREI7;
662 *Subtype = INTEL_COREI7_HASWELL;
670 *Type = INTEL_COREI7;
671 *Subtype = INTEL_COREI7_BROADWELL;
679 *Type = INTEL_COREI7;
680 *Subtype = INTEL_COREI7_SKYLAKE;
685 *Type = INTEL_COREI7;
686 *Subtype = INTEL_COREI7_SKYLAKE_AVX512;
694 *Type = INTEL_BONNELL;
704 *Type = INTEL_SILVERMONT;
709 *Type = INTEL_GOLDMONT;
716 if (Features & (1 << FEATURE_AVX512F)) {
720 if (Features2 & (1 << (FEATURE_ADX - 32))) {
721 *Type = INTEL_COREI7;
722 *Subtype = INTEL_COREI7_BROADWELL;
725 if (Features & (1 << FEATURE_AVX2)) {
726 *Type = INTEL_COREI7;
727 *Subtype = INTEL_COREI7_HASWELL;
730 if (Features & (1 << FEATURE_AVX)) {
731 *Type = INTEL_COREI7;
732 *Subtype = INTEL_COREI7_SANDYBRIDGE;
735 if (Features & (1 << FEATURE_SSE4_2)) {
736 if (Features2 & (1 << (FEATURE_MOVBE - 32))) {
737 *Type = INTEL_SILVERMONT;
739 *Type = INTEL_COREI7;
740 *Subtype = INTEL_COREI7_NEHALEM;
744 if (Features & (1 << FEATURE_SSE4_1)) {
746 *Subtype = INTEL_CORE2_45;
749 if (Features & (1 << FEATURE_SSSE3)) {
750 if (Features2 & (1 << (FEATURE_MOVBE - 32))) {
751 *Type = INTEL_BONNELL;
754 *Subtype = INTEL_CORE2_65;
758 if (Features2 & (1 << (FEATURE_EM64T - 32))) {
759 *Type = INTEL_X86_64;
762 if (Features & (1 << FEATURE_SSE2)) {
763 *Type = INTEL_PENTIUM_M;
766 if (Features & (1 << FEATURE_SSE)) {
767 *Type = INTEL_PENTIUM_III;
770 if (Features & (1 << FEATURE_MMX)) {
771 *Type = INTEL_PENTIUM_II;
774 *Type = INTEL_PENTIUM_PRO;
789 *Type = ((Features2 & (1 << (FEATURE_EM64T - 32))) ? INTEL_X86_64
804 *Type = ((Features2 & (1 << (FEATURE_EM64T - 32))) ? INTEL_NOCONA
809 *Type = ((Features2 & (1 << (FEATURE_EM64T - 32))) ? INTEL_X86_64
820 static void getAMDProcessorTypeAndSubtype(
unsigned Family,
unsigned Model,
821 unsigned Features,
unsigned *Type,
835 *Subtype = AMDPENTIUM_K6;
838 *Subtype = AMDPENTIUM_K62;
842 *Subtype = AMDPENTIUM_K63;
845 *Subtype = AMDPENTIUM_GEODE;
851 if (Features & (1 << FEATURE_SSE)) {
852 *Subtype = AMDATHLON_XP;
855 *Subtype = AMDATHLON_CLASSIC;
859 if (Features & (1 << FEATURE_SSE3)) {
860 *Subtype = AMDATHLON_K8SSE3;
863 *Subtype = AMDATHLON_K8;
869 *Subtype = AMDFAM10H_BARCELONA;
872 *Subtype = AMDFAM10H_SHANGHAI;
875 *Subtype = AMDFAM10H_ISTANBUL;
884 if (Model >= 0x60 && Model <= 0x7f) {
885 *Subtype = AMDFAM15H_BDVER4;
888 if (Model >= 0x30 && Model <= 0x3f) {
889 *Subtype = AMDFAM15H_BDVER3;
892 if (Model >= 0x10 && Model <= 0x1f) {
893 *Subtype = AMDFAM15H_BDVER2;
897 *Subtype = AMDFAM15H_BDVER1;
906 *Subtype = AMDFAM17H_ZNVER1;
913 static void getAvailableFeatures(
unsigned ECX,
unsigned EDX,
unsigned MaxLeaf,
914 unsigned *FeaturesOut,
915 unsigned *Features2Out) {
916 unsigned Features = 0;
917 unsigned Features2 = 0;
921 Features |= 1 << FEATURE_CMOV;
923 Features |= 1 << FEATURE_MMX;
925 Features |= 1 << FEATURE_SSE;
927 Features |= 1 << FEATURE_SSE2;
930 Features |= 1 << FEATURE_SSE3;
932 Features |= 1 << FEATURE_PCLMUL;
934 Features |= 1 << FEATURE_SSSE3;
936 Features |= 1 << FEATURE_FMA;
938 Features |= 1 << FEATURE_SSE4_1;
940 Features |= 1 << FEATURE_SSE4_2;
942 Features |= 1 << FEATURE_POPCNT;
944 Features |= 1 << FEATURE_AES;
947 Features2 |= 1 << (FEATURE_MOVBE - 32);
952 const unsigned AVXBits = (1 << 27) | (1 << 28);
953 bool HasAVX = ((ECX & AVXBits) == AVXBits) && !getX86XCR0(&EAX, &EDX) &&
954 ((EAX & 0x6) == 0x6);
955 bool HasAVX512Save = HasAVX && ((EAX & 0xe0) == 0xe0);
958 Features |= 1 << FEATURE_AVX;
961 MaxLeaf >= 0x7 && !getX86CpuIDAndInfoEx(0x7, 0x0, &EAX, &EBX, &ECX, &EDX);
963 if (HasLeaf7 && ((EBX >> 3) & 1))
964 Features |= 1 << FEATURE_BMI;
965 if (HasLeaf7 && ((EBX >> 5) & 1) && HasAVX)
966 Features |= 1 << FEATURE_AVX2;
967 if (HasLeaf7 && ((EBX >> 9) & 1))
968 Features |= 1 << FEATURE_BMI2;
969 if (HasLeaf7 && ((EBX >> 16) & 1) && HasAVX512Save)
970 Features |= 1 << FEATURE_AVX512F;
971 if (HasLeaf7 && ((EBX >> 17) & 1) && HasAVX512Save)
972 Features |= 1 << FEATURE_AVX512DQ;
973 if (HasLeaf7 && ((EBX >> 19) & 1))
974 Features2 |= 1 << (FEATURE_ADX - 32);
975 if (HasLeaf7 && ((EBX >> 21) & 1) && HasAVX512Save)
976 Features |= 1 << FEATURE_AVX512IFMA;
977 if (HasLeaf7 && ((EBX >> 26) & 1) && HasAVX512Save)
978 Features |= 1 << FEATURE_AVX512PF;
979 if (HasLeaf7 && ((EBX >> 27) & 1) && HasAVX512Save)
980 Features |= 1 << FEATURE_AVX512ER;
981 if (HasLeaf7 && ((EBX >> 28) & 1) && HasAVX512Save)
982 Features |= 1 << FEATURE_AVX512CD;
983 if (HasLeaf7 && ((EBX >> 30) & 1) && HasAVX512Save)
984 Features |= 1 << FEATURE_AVX512BW;
985 if (HasLeaf7 && ((EBX >> 31) & 1) && HasAVX512Save)
986 Features |= 1 << FEATURE_AVX512VL;
988 if (HasLeaf7 && ((ECX >> 1) & 1) && HasAVX512Save)
989 Features |= 1 << FEATURE_AVX512VBMI;
990 if (HasLeaf7 && ((ECX >> 14) & 1) && HasAVX512Save)
991 Features |= 1 << FEATURE_AVX512VPOPCNTDQ;
993 if (HasLeaf7 && ((EDX >> 2) & 1) && HasAVX512Save)
994 Features |= 1 << FEATURE_AVX5124VNNIW;
995 if (HasLeaf7 && ((EDX >> 3) & 1) && HasAVX512Save)
996 Features |= 1 << FEATURE_AVX5124FMAPS;
998 unsigned MaxExtLevel;
999 getX86CpuIDAndInfo(0x80000000, &MaxExtLevel, &EBX, &ECX, &EDX);
1001 bool HasExtLeaf1 = MaxExtLevel >= 0x80000001 &&
1002 !getX86CpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
1003 if (HasExtLeaf1 && ((ECX >> 6) & 1))
1004 Features |= 1 << FEATURE_SSE4_A;
1005 if (HasExtLeaf1 && ((ECX >> 11) & 1))
1006 Features |= 1 << FEATURE_XOP;
1007 if (HasExtLeaf1 && ((ECX >> 16) & 1))
1008 Features |= 1 << FEATURE_FMA4;
1010 if (HasExtLeaf1 && ((EDX >> 29) & 1))
1011 Features2 |= 1 << (FEATURE_EM64T - 32);
1014 *Features2Out = Features2;
1018 unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0;
1019 unsigned MaxLeaf, Vendor;
1021 #if defined(__GNUC__) || defined(__clang__)
1026 if(!isCpuIdSupported())
1029 if (getX86CpuIDAndInfo(0, &MaxLeaf, &Vendor, &ECX, &EDX) || MaxLeaf < 1)
1031 getX86CpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX);
1033 unsigned Brand_id = EBX & 0xff;
1034 unsigned Family = 0, Model = 0;
1035 unsigned Features = 0, Features2 = 0;
1036 detectX86FamilyModel(EAX, &Family, &Model);
1037 getAvailableFeatures(ECX, EDX, MaxLeaf, &Features, &Features2);
1042 if (Vendor == SIG_INTEL) {
1043 getIntelProcessorTypeAndSubtype(Family, Model, Brand_id, Features,
1044 Features2, &Type, &Subtype);
1051 if (Subtype == INTEL_PENTIUM_MMX)
1052 return "pentium-mmx";
1054 case INTEL_PENTIUM_PRO:
1055 return "pentiumpro";
1056 case INTEL_PENTIUM_II:
1058 case INTEL_PENTIUM_III:
1060 case INTEL_PENTIUM_IV:
1062 case INTEL_PENTIUM_M:
1064 case INTEL_CORE_DUO:
1068 case INTEL_CORE2_65:
1070 case INTEL_CORE2_45:
1077 case INTEL_COREI7_NEHALEM:
1079 case INTEL_COREI7_WESTMERE:
1081 case INTEL_COREI7_SANDYBRIDGE:
1082 return "sandybridge";
1083 case INTEL_COREI7_IVYBRIDGE:
1085 case INTEL_COREI7_HASWELL:
1087 case INTEL_COREI7_BROADWELL:
1089 case INTEL_COREI7_SKYLAKE:
1091 case INTEL_COREI7_SKYLAKE_AVX512:
1092 return "skylake-avx512";
1098 case INTEL_SILVERMONT:
1099 return "silvermont";
1100 case INTEL_GOLDMONT:
1108 case INTEL_PRESCOTT:
1113 }
else if (Vendor == SIG_AMD) {
1114 getAMDProcessorTypeAndSubtype(Family, Model, Features, &Type, &Subtype);
1122 case AMDPENTIUM_K62:
1124 case AMDPENTIUM_K63:
1126 case AMDPENTIUM_GEODE:
1133 case AMDATHLON_CLASSIC:
1139 case AMDATHLON_K8SSE3:
1151 case AMDFAM15H_BDVER1:
1153 case AMDFAM15H_BDVER2:
1155 case AMDFAM15H_BDVER3:
1157 case AMDFAM15H_BDVER4:
1171 #elif defined(__APPLE__) && (defined(__ppc__) || defined(__powerpc__))
1173 host_basic_info_data_t hostInfo;
1174 mach_msg_type_number_t infoCount;
1176 infoCount = HOST_BASIC_INFO_COUNT;
1177 host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo,
1183 switch (hostInfo.cpu_subtype) {
1213 #elif defined(__linux__) && (defined(__ppc__) || defined(__powerpc__))
1216 const StringRef& Content = P ? P->getBuffer() :
"";
1219 #elif defined(__linux__) && (defined(__arm__) || defined(__aarch64__))
1222 const StringRef& Content = P ? P->getBuffer() :
"";
1225 #elif defined(__linux__) && defined(__s390x__)
1228 const StringRef& Content = P ? P->getBuffer() :
"";
1235 #if defined(__linux__) && defined(__x86_64__)
1244 if (std::error_code EC = Text.
getError()) {
1246 <<
"/proc/cpuinfo: " << EC.message() <<
"\n";
1250 (*Text)->getBuffer().split(strs,
"\n", -1,
1252 int CurPhysicalId = -1;
1255 for (
auto &Line : strs) {
1257 if (!Line.startswith(
"physical id") && !Line.startswith(
"core id"))
1259 std::pair<StringRef, StringRef>
Data = Line.split(
':');
1260 auto Name = Data.first.trim();
1261 auto Val = Data.second.trim();
1262 if (
Name ==
"physical id") {
1263 assert(CurPhysicalId == -1 &&
1264 "Expected a core id before seeing another physical id");
1265 Val.getAsInteger(10, CurPhysicalId);
1267 if (
Name ==
"core id") {
1268 assert(CurCoreId == -1 &&
1269 "Expected a physical id before seeing another core id");
1270 Val.getAsInteger(10, CurCoreId);
1272 if (CurPhysicalId != -1 && CurCoreId != -1) {
1273 UniqueItems.
insert(std::make_pair(CurPhysicalId, CurCoreId));
1278 return UniqueItems.
size();
1280 #elif defined(__APPLE__) && defined(__x86_64__)
1281 #include <sys/param.h>
1282 #include <sys/sysctl.h>
1287 size_t len =
sizeof(
count);
1288 sysctlbyname(
"hw.physicalcpu", &count, &len, NULL, 0);
1292 nm[1] = HW_AVAILCPU;
1293 sysctl(nm, 2, &count, &len, NULL, 0);
1309 #if defined(__i386__) || defined(_M_IX86) || \
1310 defined(__x86_64__) || defined(_M_X64)
1312 unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0;
1319 if (getX86CpuIDAndInfo(0, &MaxLevel, text.u + 0, text.u + 2, text.u + 1) ||
1323 getX86CpuIDAndInfo(1, &EAX, &EBX, &ECX, &EDX);
1325 Features[
"cmov"] = (EDX >> 15) & 1;
1326 Features[
"mmx"] = (EDX >> 23) & 1;
1327 Features[
"sse"] = (EDX >> 25) & 1;
1328 Features[
"sse2"] = (EDX >> 26) & 1;
1329 Features[
"sse3"] = (ECX >> 0) & 1;
1330 Features[
"ssse3"] = (ECX >> 9) & 1;
1331 Features[
"sse4.1"] = (ECX >> 19) & 1;
1332 Features[
"sse4.2"] = (ECX >> 20) & 1;
1334 Features[
"pclmul"] = (ECX >> 1) & 1;
1335 Features[
"cx16"] = (ECX >> 13) & 1;
1336 Features[
"movbe"] = (ECX >> 22) & 1;
1337 Features[
"popcnt"] = (ECX >> 23) & 1;
1338 Features[
"aes"] = (ECX >> 25) & 1;
1339 Features[
"rdrnd"] = (ECX >> 30) & 1;
1344 bool HasAVXSave = ((ECX >> 27) & 1) && ((ECX >> 28) & 1) &&
1345 !getX86XCR0(&EAX, &EDX) && ((EAX & 0x6) == 0x6);
1346 Features[
"avx"] = HasAVXSave;
1347 Features[
"fma"] = HasAVXSave && (ECX >> 12) & 1;
1348 Features[
"f16c"] = HasAVXSave && (ECX >> 29) & 1;
1351 Features[
"xsave"] = HasAVXSave && (ECX >> 26) & 1;
1354 bool HasAVX512Save = HasAVXSave && ((EAX & 0xe0) == 0xe0);
1356 unsigned MaxExtLevel;
1357 getX86CpuIDAndInfo(0x80000000, &MaxExtLevel, &EBX, &ECX, &EDX);
1359 bool HasExtLeaf1 = MaxExtLevel >= 0x80000001 &&
1360 !getX86CpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
1361 Features[
"lzcnt"] = HasExtLeaf1 && ((ECX >> 5) & 1);
1362 Features[
"sse4a"] = HasExtLeaf1 && ((ECX >> 6) & 1);
1363 Features[
"prfchw"] = HasExtLeaf1 && ((ECX >> 8) & 1);
1364 Features[
"xop"] = HasExtLeaf1 && ((ECX >> 11) & 1) && HasAVXSave;
1365 Features[
"lwp"] = HasExtLeaf1 && ((ECX >> 15) & 1);
1366 Features[
"fma4"] = HasExtLeaf1 && ((ECX >> 16) & 1) && HasAVXSave;
1367 Features[
"tbm"] = HasExtLeaf1 && ((ECX >> 21) & 1);
1368 Features[
"mwaitx"] = HasExtLeaf1 && ((ECX >> 29) & 1);
1370 bool HasExtLeaf8 = MaxExtLevel >= 0x80000008 &&
1371 !getX86CpuIDAndInfoEx(0x80000008,0x0, &EAX, &EBX, &ECX, &EDX);
1372 Features[
"clzero"] = HasExtLeaf8 && ((EBX >> 0) & 1);
1375 MaxLevel >= 7 && !getX86CpuIDAndInfoEx(0x7, 0x0, &EAX, &EBX, &ECX, &EDX);
1378 Features[
"avx2"] = HasAVXSave && HasLeaf7 && ((EBX >> 5) & 1);
1380 Features[
"fsgsbase"] = HasLeaf7 && ((EBX >> 0) & 1);
1381 Features[
"sgx"] = HasLeaf7 && ((EBX >> 2) & 1);
1382 Features[
"bmi"] = HasLeaf7 && ((EBX >> 3) & 1);
1383 Features[
"bmi2"] = HasLeaf7 && ((EBX >> 8) & 1);
1384 Features[
"rtm"] = HasLeaf7 && ((EBX >> 11) & 1);
1385 Features[
"rdseed"] = HasLeaf7 && ((EBX >> 18) & 1);
1386 Features[
"adx"] = HasLeaf7 && ((EBX >> 19) & 1);
1387 Features[
"clflushopt"] = HasLeaf7 && ((EBX >> 23) & 1);
1388 Features[
"clwb"] = HasLeaf7 && ((EBX >> 24) & 1);
1389 Features[
"sha"] = HasLeaf7 && ((EBX >> 29) & 1);
1392 Features[
"avx512f"] = HasLeaf7 && ((EBX >> 16) & 1) && HasAVX512Save;
1393 Features[
"avx512dq"] = HasLeaf7 && ((EBX >> 17) & 1) && HasAVX512Save;
1394 Features[
"avx512ifma"] = HasLeaf7 && ((EBX >> 21) & 1) && HasAVX512Save;
1395 Features[
"avx512pf"] = HasLeaf7 && ((EBX >> 26) & 1) && HasAVX512Save;
1396 Features[
"avx512er"] = HasLeaf7 && ((EBX >> 27) & 1) && HasAVX512Save;
1397 Features[
"avx512cd"] = HasLeaf7 && ((EBX >> 28) & 1) && HasAVX512Save;
1398 Features[
"avx512bw"] = HasLeaf7 && ((EBX >> 30) & 1) && HasAVX512Save;
1399 Features[
"avx512vl"] = HasLeaf7 && ((EBX >> 31) & 1) && HasAVX512Save;
1401 Features[
"prefetchwt1"] = HasLeaf7 && (ECX & 1);
1402 Features[
"avx512vbmi"] = HasLeaf7 && ((ECX >> 1) & 1) && HasAVX512Save;
1403 Features[
"avx512vpopcntdq"] = HasLeaf7 && ((ECX >> 14) & 1) && HasAVX512Save;
1405 Features[
"pku"] = HasLeaf7 && ((ECX >> 4) & 1);
1407 bool HasLeafD = MaxLevel >= 0xd &&
1408 !getX86CpuIDAndInfoEx(0xd, 0x1, &EAX, &EBX, &ECX, &EDX);
1411 Features[
"xsaveopt"] = HasAVXSave && HasLeafD && ((EAX >> 0) & 1);
1412 Features[
"xsavec"] = HasAVXSave && HasLeafD && ((EAX >> 1) & 1);
1413 Features[
"xsaves"] = HasAVXSave && HasLeafD && ((EAX >> 3) & 1);
1417 #elif defined(__linux__) && (defined(__arm__) || defined(__aarch64__))
1424 P->getBuffer().split(Lines,
"\n");
1429 for (
unsigned I = 0,
E = Lines.
size();
I !=
E; ++
I)
1431 Lines[
I].split(CPUFeatures,
' ');
1435 #if defined(__aarch64__)
1437 enum { CAP_AES = 0x1, CAP_PMULL = 0x2, CAP_SHA1 = 0x4, CAP_SHA2 = 0x8 };
1441 for (
unsigned I = 0,
E = CPUFeatures.
size();
I !=
E; ++
I) {
1443 #
if defined(__aarch64__)
1444 .
Case(
"asimd",
"neon")
1445 .
Case(
"fp",
"fp-armv8")
1446 .
Case(
"crc32",
"crc")
1448 .
Case(
"half",
"fp16")
1449 .
Case(
"neon",
"neon")
1450 .
Case(
"vfpv3",
"vfp3")
1451 .
Case(
"vfpv3d16",
"d16")
1452 .
Case(
"vfpv4",
"vfp4")
1453 .
Case(
"idiva",
"hwdiv-arm")
1454 .
Case(
"idivt",
"hwdiv")
1458 #if defined(__aarch64__)
1461 if (CPUFeatures[
I] ==
"aes")
1463 else if (CPUFeatures[
I] ==
"pmull")
1464 crypto |= CAP_PMULL;
1465 else if (CPUFeatures[
I] ==
"sha1")
1467 else if (CPUFeatures[
I] ==
"sha2")
1471 if (LLVMFeatureStr !=
"")
1472 Features[LLVMFeatureStr] =
true;
1475 #if defined(__aarch64__)
1477 if (crypto == (CAP_AES | CAP_PMULL | CAP_SHA1 | CAP_SHA2))
1478 Features[
"crypto"] =
true;
1488 std::string TargetTripleString = updateTripleOSVersion(LLVM_HOST_TRIPLE);
std::error_code getError() const
Represents either an error or a value T.
static std::unique_ptr< llvm::MemoryBuffer > LLVM_ATTRIBUTE_UNUSED getProcCpuinfoContent()
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool endswith(StringRef Suffix) const
Check if this string ends with the given Suffix.
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
StringRef getHostCPUNameForARM(const StringRef &ProcCpuinfoContent)
const std::string & str() const
int getHostNumPhysicalCores()
Get the number of physical cores (as opposed to logical cores returned from thread::hardware_concurre...
StringRef getHostCPUNameForS390x(const StringRef &ProcCpuinfoContent)
LLVM_ATTRIBUTE_ALWAYS_INLINE R Default(const T &Value) const
static bool startswith(StringRef Magic, const char(&S)[N])
bool isArch64Bit() const
Test whether the architecture is 64-bit.
LLVM_ATTRIBUTE_ALWAYS_INLINE StringSwitch & Case(const char(&S)[N], const T &Value)
auto count(R &&Range, const E &Element) -> typename std::iterator_traits< decltype(std::begin(Range))>::difference_type
Wrapper function around std::count to count the number of times an element Element occurs in the give...
llvm::Triple get32BitArchVariant() const
Form a triple with a 32-bit variant of the current architecture.
A switch()-like statement whose cases are string literals.
StringRef getHostCPUNameForPowerPC(const StringRef &ProcCpuinfoContent)
Helper functions to extract HostCPUName from /proc/cpuinfo on linux.
The instances of the Type class are immutable: once they are created, they are never changed...
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
#define LLVM_ATTRIBUTE_UNUSED
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
std::string normalize() const
Return the normalized form of this triple's string.
std::string getProcessTriple()
getProcessTriple() - Return an appropriate target triple for generating code to be loaded into the cu...
Triple - Helper class for working with autoconf configuration names.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
llvm_unreachable("Unknown RegBank!")
llvm::Triple get64BitArchVariant() const
Form a triple with a 64-bit variant of the current architecture.
StringRef getHostCPUName()
getHostCPUName - Get the LLVM name for the host CPU.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileAsStream(const Twine &Filename)
Read all of the specified file into a MemoryBuffer as a stream (i.e.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const FeatureBitset Features
StringRef - Represent a constant reference to a string, i.e.
bool getHostCPUFeatures(StringMap< bool > &Features)
getHostCPUFeatures - Get the LLVM names for the host CPU features.
bool isArch32Bit() const
Test whether the architecture is 32-bit.
static int computeHostNumPhysicalCores()