[llvm] bebea42 - Revert "[X86] Calculate the needed size of the feature arrays in _cpu_indicator_init and getHostCPUName using the size of the feature enum."

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 22 12:21:37 PDT 2020


Author: Craig Topper
Date: 2020-06-22T12:20:40-07:00
New Revision: bebea4221d3d1db9adaf7c921c109b6c2af26b74

URL: https://github.com/llvm/llvm-project/commit/bebea4221d3d1db9adaf7c921c109b6c2af26b74
DIFF: https://github.com/llvm/llvm-project/commit/bebea4221d3d1db9adaf7c921c109b6c2af26b74.diff

LOG: Revert "[X86] Calculate the needed size of the feature arrays in _cpu_indicator_init and getHostCPUName using the size of the feature enum."

Seems to breaking build.

This reverts commit 5ac144fe64c6911b5b6011cac1d61e0f82562e7f.

Added: 
    

Modified: 
    compiler-rt/lib/builtins/cpu_model.c
    llvm/include/llvm/Support/X86TargetParser.h
    llvm/lib/Support/Host.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/builtins/cpu_model.c b/compiler-rt/lib/builtins/cpu_model.c
index 3207f1449e00..59c6974207c7 100644
--- a/compiler-rt/lib/builtins/cpu_model.c
+++ b/compiler-rt/lib/builtins/cpu_model.c
@@ -125,8 +125,7 @@ enum ProcessorFeatures {
   FEATURE_AVX512VNNI,
   FEATURE_AVX512BITALG,
   FEATURE_AVX512BF16,
-  FEATURE_AVX512VP2INTERSECT,
-  CPU_FEATURE_MAX
+  FEATURE_AVX512VP2INTERSECT
 };
 
 // The check below for i386 was copied from clang's cpuid.h (__get_cpuid_max).
@@ -494,6 +493,8 @@ static void getAMDProcessorTypeAndSubtype(unsigned Family, unsigned Model,
 
 static void getAvailableFeatures(unsigned ECX, unsigned EDX, unsigned MaxLeaf,
                                  unsigned *Features) {
+  Features[0] = 0;
+  Features[1] = 0;
   unsigned EAX, EBX;
 
 #define setFeature(F)                                                          \
@@ -652,8 +653,7 @@ int CONSTRUCTOR_ATTRIBUTE __cpu_indicator_init(void) {
   unsigned MaxLeaf = 5;
   unsigned Vendor;
   unsigned Model, Family;
-  const unsigned SIZE_OF_FEATURES = (CPU_FEATURE_MAX + 31) / 32;
-  unsigned Features[SIZE_OF_FEATURES] = {0};
+  unsigned Features[2];
 
   // This function needs to run just once.
   if (__cpu_model.__cpu_vendor)
@@ -670,8 +670,6 @@ int CONSTRUCTOR_ATTRIBUTE __cpu_indicator_init(void) {
 
   // Find available features.
   getAvailableFeatures(ECX, EDX, MaxLeaf, &Features[0]);
-
-  assert(SIZE_OF_FEATURES == 2);
   __cpu_model.__cpu_features[0] = Features[0];
   __cpu_features2 = Features[1];
 

diff  --git a/llvm/include/llvm/Support/X86TargetParser.h b/llvm/include/llvm/Support/X86TargetParser.h
index 79cb0af4ed06..7b4ade866a9d 100644
--- a/llvm/include/llvm/Support/X86TargetParser.h
+++ b/llvm/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/llvm/lib/Support/Host.cpp b/llvm/lib/Support/Host.cpp
index e4c6b879884a..c6b12e6516a4 100644
--- a/llvm/lib/Support/Host.cpp
+++ b/llvm/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,
+                                const unsigned (&Features)[3],
                                 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,
+                                          const unsigned (&Features)[3],
                                           unsigned *Type, unsigned *Subtype) {
   auto testFeature = [&](unsigned F) {
     return (Features[F / 32] & (1U << (F % 32))) != 0;
@@ -1012,7 +1012,10 @@ static void getAMDProcessorTypeAndSubtype(unsigned Family, unsigned Model,
 }
 
 static void getAvailableFeatures(unsigned ECX, unsigned EDX, unsigned MaxLeaf,
-                                 unsigned *Features) {
+                                 unsigned (&Features)[3]) {
+  Features[0] = 0;
+  Features[1] = 0;
+  Features[2] = 0;
   unsigned EAX, EBX;
 
   auto setFeature = [&](unsigned F) {
@@ -1154,7 +1157,7 @@ StringRef sys::getHostCPUName() {
   getX86CpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX);
 
   unsigned Family = 0, Model = 0;
-  unsigned Features[(X86::CPU_FEATURE_MAX + 31) / 32] = {0};
+  unsigned Features[3] = {0, 0, 0};
   detectX86FamilyModel(EAX, &Family, &Model);
   getAvailableFeatures(ECX, EDX, MaxLeaf, Features);
 


        


More information about the llvm-commits mailing list