From 23cda02b12ccd967b4987f146ec91458ba16440d Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Mon, 22 Jun 2020 13:29:43 -0700 Subject: [PATCH] Recommit "[X86] Calculate the needed size of the feature arrays in _cpu_indicator_init and getHostCPUName using the size of the feature enum." Hopefully this version will fix the previously buildbot failure --- include/llvm/Support/X86TargetParser.h | 2 +- lib/Support/Host.cpp | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/include/llvm/Support/X86TargetParser.h b/include/llvm/Support/X86TargetParser.h index 7b4ade866a9..79cb0af4ed0 100644 --- a/include/llvm/Support/X86TargetParser.h +++ b/include/llvm/Support/X86TargetParser.h @@ -56,7 +56,7 @@ enum ProcessorFeatures { #define X86_FEATURE(ENUM) \ ENUM, #include "llvm/Support/X86TargetParser.def" - + CPU_FEATURE_MAX }; enum CPUKind { diff --git a/lib/Support/Host.cpp b/lib/Support/Host.cpp index c6b12e6516a..e4c6b879884 100644 --- a/lib/Support/Host.cpp +++ b/lib/Support/Host.cpp @@ -582,7 +582,7 @@ static void detectX86FamilyModel(unsigned EAX, unsigned *Family, static void getIntelProcessorTypeAndSubtype(unsigned Family, unsigned Model, - const unsigned (&Features)[3], + const unsigned *Features, unsigned *Type, unsigned *Subtype) { auto testFeature = [&](unsigned F) { return (Features[F / 32] & (1U << (F % 32))) != 0; @@ -910,7 +910,7 @@ getIntelProcessorTypeAndSubtype(unsigned Family, unsigned Model, } static void getAMDProcessorTypeAndSubtype(unsigned Family, unsigned Model, - const unsigned (&Features)[3], + const unsigned *Features, unsigned *Type, unsigned *Subtype) { auto testFeature = [&](unsigned F) { return (Features[F / 32] & (1U << (F % 32))) != 0; @@ -1012,10 +1012,7 @@ static void getAMDProcessorTypeAndSubtype(unsigned Family, unsigned Model, } static void getAvailableFeatures(unsigned ECX, unsigned EDX, unsigned MaxLeaf, - unsigned (&Features)[3]) { - Features[0] = 0; - Features[1] = 0; - Features[2] = 0; + unsigned *Features) { unsigned EAX, EBX; auto setFeature = [&](unsigned F) { @@ -1157,7 +1154,7 @@ StringRef sys::getHostCPUName() { getX86CpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX); unsigned Family = 0, Model = 0; - unsigned Features[3] = {0, 0, 0}; + unsigned Features[(X86::CPU_FEATURE_MAX + 31) / 32] = {0}; detectX86FamilyModel(EAX, &Family, &Model); getAvailableFeatures(ECX, EDX, MaxLeaf, Features);