diff --git a/compiler-rt/lib/builtins/cpu_model/x86.c b/compiler-rt/lib/builtins/cpu_model/x86.c index 606571d527501..0137c9d570e08 100644 --- a/compiler-rt/lib/builtins/cpu_model/x86.c +++ b/compiler-rt/lib/builtins/cpu_model/x86.c @@ -151,8 +151,8 @@ enum ProcessorFeatures { // FEATURE_3DNOW, // FEATURE_3DNOWP, FEATURE_ADX = 40, - // FEATURE_ABM, - FEATURE_CLDEMOTE = 42, + FEATURE_64BIT, + FEATURE_CLDEMOTE, FEATURE_CLFLUSHOPT, FEATURE_CLWB, FEATURE_CLZERO, @@ -323,11 +323,22 @@ static const char *getIntelProcessorTypeAndSubtype(unsigned Family, const unsigned *Features, unsigned *Type, unsigned *Subtype) { - // We select CPU strings to match the code in Host.cpp, but we don't use them - // in compiler-rt. const char *CPU = 0; switch (Family) { + case 3: + CPU = "i386"; + break; + case 4: + CPU = "i486"; + break; + case 5: + if (testFeature(FEATURE_MMX)) { + CPU = "pentium-mmx"; + break; + } + CPU = "pentium"; + break; case 6: switch (Model) { case 0x0f: // Intel Core 2 Duo processor, Intel Core 2 Duo mobile @@ -542,7 +553,7 @@ static const char *getIntelProcessorTypeAndSubtype(unsigned Family, *Subtype = INTEL_COREI7_SAPPHIRERAPIDS; break; - // Granite Rapids: + // Granite rapids: case 0xad: CPU = "graniterapids"; *Type = INTEL_COREI7; @@ -580,7 +591,7 @@ static const char *getIntelProcessorTypeAndSubtype(unsigned Family, case 0x5f: // Denverton CPU = "goldmont"; *Type = INTEL_GOLDMONT; - break; // "goldmont" + break; case 0x7a: CPU = "goldmont-plus"; *Type = INTEL_GOLDMONT_PLUS; @@ -608,10 +619,10 @@ static const char *getIntelProcessorTypeAndSubtype(unsigned Family, // Clearwaterforest: case 0xdd: CPU = "clearwaterforest"; - *Type = INTEL_COREI7; - *Subtype = INTEL_CLEARWATERFOREST; + *Type = INTEL_CLEARWATERFOREST; break; + // Xeon Phi (Knights Landing + Knights Mill): case 0x57: CPU = "knl"; *Type = INTEL_KNL; @@ -622,10 +633,102 @@ static const char *getIntelProcessorTypeAndSubtype(unsigned Family, *Type = INTEL_KNM; break; - default: // Unknown family 6 CPU. + default: // Unknown family 6 CPU, try to guess. + // TODO detect tigerlake host from model + if (testFeature(FEATURE_AVX512VP2INTERSECT)) { + CPU = "tigerlake"; + *Type = INTEL_COREI7; + *Subtype = INTEL_COREI7_TIGERLAKE; + } else if (testFeature(FEATURE_AVX512VBMI2)) { + CPU = "icelake-client"; + *Type = INTEL_COREI7; + *Subtype = INTEL_COREI7_ICELAKE_CLIENT; + } else if (testFeature(FEATURE_AVX512VBMI)) { + CPU = "cannonlake"; + *Type = INTEL_COREI7; + *Subtype = INTEL_COREI7_CANNONLAKE; + } else if (testFeature(FEATURE_AVX512BF16)) { + CPU = "cooperlake"; + *Type = INTEL_COREI7; + *Subtype = INTEL_COREI7_COOPERLAKE; + } else if (testFeature(FEATURE_AVX512VNNI)) { + CPU = "cascadelake"; + *Type = INTEL_COREI7; + *Subtype = INTEL_COREI7_CASCADELAKE; + } else if (testFeature(FEATURE_AVX512VL)) { + CPU = "skylake-avx512"; + *Type = INTEL_COREI7; + *Subtype = INTEL_COREI7_SKYLAKE_AVX512; + } else if (testFeature(FEATURE_CLFLUSHOPT)) { + if (testFeature(FEATURE_SHA)) { + CPU = "goldmont"; + *Type = INTEL_GOLDMONT; + } else { + CPU = "skylake"; + *Type = INTEL_COREI7; + *Subtype = INTEL_COREI7_SKYLAKE; + } + } else if (testFeature(FEATURE_ADX)) { + CPU = "broadwell"; + *Type = INTEL_COREI7; + *Subtype = INTEL_COREI7_BROADWELL; + } else if (testFeature(FEATURE_AVX2)) { + CPU = "haswell"; + *Type = INTEL_COREI7; + *Subtype = INTEL_COREI7_HASWELL; + } else if (testFeature(FEATURE_AVX)) { + CPU = "sandybridge"; + *Type = INTEL_COREI7; + *Subtype = INTEL_COREI7_SANDYBRIDGE; + } else if (testFeature(FEATURE_SSE4_2)) { + if (testFeature(FEATURE_MOVBE)) { + CPU = "silvermont"; + *Type = INTEL_SILVERMONT; + } else { + CPU = "nehalem"; + *Type = INTEL_COREI7; + *Subtype = INTEL_COREI7_NEHALEM; + } + } else if (testFeature(FEATURE_SSE4_1)) { + CPU = "penryn"; + *Type = INTEL_CORE2; + } else if (testFeature(FEATURE_SSSE3)) { + if (testFeature(FEATURE_MOVBE)) { + CPU = "bonnell"; + *Type = INTEL_BONNELL; + } else { + CPU = "core2"; + *Type = INTEL_CORE2; + } + } else if (testFeature(FEATURE_64BIT)) { + CPU = "core2"; + *Type = INTEL_CORE2; + } else if (testFeature(FEATURE_SSE3)) { + CPU = "yonah"; + } else if (testFeature(FEATURE_SSE2)) { + CPU = "pentium-m"; + } else if (testFeature(FEATURE_SSE)) { + CPU = "pentium3"; + } else if (testFeature(FEATURE_MMX)) { + CPU = "pentium2"; + } else { + CPU = "pentiumpro"; + } break; } break; + case 15: { + if (testFeature(FEATURE_64BIT)) { + CPU = "nocona"; + break; + } + if (testFeature(FEATURE_SSE3)) { + CPU = "prescott"; + break; + } + CPU = "pentium4"; + break; + } case 19: switch (Model) { // Diamond Rapids: diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp index b5119c8e2ac50..3aa01f6dbef1d 100644 --- a/llvm/lib/TargetParser/Host.cpp +++ b/llvm/lib/TargetParser/Host.cpp @@ -660,7 +660,7 @@ static StringRef getIntelProcessorTypeAndSubtype(unsigned Family, const unsigned *Features, unsigned *Type, unsigned *Subtype) { - StringRef CPU; + const char *CPU = 0; switch (Family) { case 3: @@ -702,7 +702,7 @@ static StringRef getIntelProcessorTypeAndSubtype(unsigned Family, case 0x1e: // Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz. // As found in a Summer 2010 model iMac. case 0x1f: - case 0x2e: // Nehalem EX + case 0x2e: // Nehalem EX CPU = "nehalem"; *Type = X86::INTEL_COREI7; *Subtype = X86::INTEL_COREI7_NEHALEM; @@ -723,7 +723,7 @@ static StringRef getIntelProcessorTypeAndSubtype(unsigned Family, *Subtype = X86::INTEL_COREI7_SANDYBRIDGE; break; case 0x3a: - case 0x3e: // Ivy Bridge EP + case 0x3e: // Ivy Bridge EP CPU = "ivybridge"; *Type = X86::INTEL_COREI7; *Subtype = X86::INTEL_COREI7_IVYBRIDGE; @@ -750,12 +750,12 @@ static StringRef getIntelProcessorTypeAndSubtype(unsigned Family, break; // Skylake: - case 0x4e: // Skylake mobile - case 0x5e: // Skylake desktop - case 0x8e: // Kaby Lake mobile - case 0x9e: // Kaby Lake desktop - case 0xa5: // Comet Lake-H/S - case 0xa6: // Comet Lake-U + case 0x4e: // Skylake mobile + case 0x5e: // Skylake desktop + case 0x8e: // Kaby Lake mobile + case 0x9e: // Kaby Lake desktop + case 0xa5: // Comet Lake-H/S + case 0xa6: // Comet Lake-U CPU = "skylake"; *Type = X86::INTEL_COREI7; *Subtype = X86::INTEL_COREI7_SKYLAKE; @@ -868,20 +868,6 @@ static StringRef getIntelProcessorTypeAndSubtype(unsigned Family, *Subtype = X86::INTEL_COREI7_PANTHERLAKE; break; - // Graniterapids: - case 0xad: - CPU = "graniterapids"; - *Type = X86::INTEL_COREI7; - *Subtype = X86::INTEL_COREI7_GRANITERAPIDS; - break; - - // Granite Rapids D: - case 0xae: - CPU = "graniterapids-d"; - *Type = X86::INTEL_COREI7; - *Subtype = X86::INTEL_COREI7_GRANITERAPIDS_D; - break; - // Icelake Xeon: case 0x6a: case 0x6c: @@ -904,6 +890,20 @@ static StringRef getIntelProcessorTypeAndSubtype(unsigned Family, *Subtype = X86::INTEL_COREI7_SAPPHIRERAPIDS; break; + // Granite rapids: + case 0xad: + CPU = "graniterapids"; + *Type = X86::INTEL_COREI7; + *Subtype = X86::INTEL_COREI7_GRANITERAPIDS; + break; + + // Granite Rapids D: + case 0xae: + CPU = "graniterapids-d"; + *Type = X86::INTEL_COREI7; + *Subtype = X86::INTEL_COREI7_GRANITERAPIDS_D; + break; + case 0x1c: // Most 45 nm Intel Atom processors case 0x26: // 45 nm Atom Lincroft case 0x27: // 32 nm Atom Medfield @@ -964,52 +964,82 @@ static StringRef getIntelProcessorTypeAndSubtype(unsigned Family, CPU = "knl"; *Type = X86::INTEL_KNL; break; + case 0x85: CPU = "knm"; *Type = X86::INTEL_KNM; break; default: // Unknown family 6 CPU, try to guess. - // Don't both with Type/Subtype here, they aren't used by the caller. - // They're used above to keep the code in sync with compiler-rt. // TODO detect tigerlake host from model if (testFeature(X86::FEATURE_AVX512VP2INTERSECT)) { CPU = "tigerlake"; + *Type = X86::INTEL_COREI7; + *Subtype = X86::INTEL_COREI7_TIGERLAKE; } else if (testFeature(X86::FEATURE_AVX512VBMI2)) { CPU = "icelake-client"; + *Type = X86::INTEL_COREI7; + *Subtype = X86::INTEL_COREI7_ICELAKE_CLIENT; } else if (testFeature(X86::FEATURE_AVX512VBMI)) { CPU = "cannonlake"; + *Type = X86::INTEL_COREI7; + *Subtype = X86::INTEL_COREI7_CANNONLAKE; } else if (testFeature(X86::FEATURE_AVX512BF16)) { CPU = "cooperlake"; + *Type = X86::INTEL_COREI7; + *Subtype = X86::INTEL_COREI7_COOPERLAKE; } else if (testFeature(X86::FEATURE_AVX512VNNI)) { CPU = "cascadelake"; + *Type = X86::INTEL_COREI7; + *Subtype = X86::INTEL_COREI7_CASCADELAKE; } else if (testFeature(X86::FEATURE_AVX512VL)) { CPU = "skylake-avx512"; + *Type = X86::INTEL_COREI7; + *Subtype = X86::INTEL_COREI7_SKYLAKE_AVX512; } else if (testFeature(X86::FEATURE_CLFLUSHOPT)) { - if (testFeature(X86::FEATURE_SHA)) + if (testFeature(X86::FEATURE_SHA)) { CPU = "goldmont"; - else + *Type = X86::INTEL_GOLDMONT; + } else { CPU = "skylake"; + *Type = X86::INTEL_COREI7; + *Subtype = X86::INTEL_COREI7_SKYLAKE; + } } else if (testFeature(X86::FEATURE_ADX)) { CPU = "broadwell"; + *Type = X86::INTEL_COREI7; + *Subtype = X86::INTEL_COREI7_BROADWELL; } else if (testFeature(X86::FEATURE_AVX2)) { CPU = "haswell"; + *Type = X86::INTEL_COREI7; + *Subtype = X86::INTEL_COREI7_HASWELL; } else if (testFeature(X86::FEATURE_AVX)) { CPU = "sandybridge"; + *Type = X86::INTEL_COREI7; + *Subtype = X86::INTEL_COREI7_SANDYBRIDGE; } else if (testFeature(X86::FEATURE_SSE4_2)) { - if (testFeature(X86::FEATURE_MOVBE)) + if (testFeature(X86::FEATURE_MOVBE)) { CPU = "silvermont"; - else + *Type = X86::INTEL_SILVERMONT; + } else { CPU = "nehalem"; + *Type = X86::INTEL_COREI7; + *Subtype = X86::INTEL_COREI7_NEHALEM; + } } else if (testFeature(X86::FEATURE_SSE4_1)) { CPU = "penryn"; + *Type = X86::INTEL_CORE2; } else if (testFeature(X86::FEATURE_SSSE3)) { - if (testFeature(X86::FEATURE_MOVBE)) + if (testFeature(X86::FEATURE_MOVBE)) { CPU = "bonnell"; - else + *Type = X86::INTEL_BONNELL; + } else { CPU = "core2"; + *Type = X86::INTEL_CORE2; + } } else if (testFeature(X86::FEATURE_64BIT)) { CPU = "core2"; + *Type = X86::INTEL_CORE2; } else if (testFeature(X86::FEATURE_SSE3)) { CPU = "yonah"; } else if (testFeature(X86::FEATURE_SSE2)) {