[compiler-rt] [llvm] [compiler-rt][X86] Unify getAMDProcessorTypeAndSubType (PR #97863)
Aiden Grossman via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 8 10:59:07 PDT 2024
https://github.com/boomanaiden154 updated https://github.com/llvm/llvm-project/pull/97863
>From 2be7a7864cedafd42f9ca0aee35d6a7695899243 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Fri, 5 Jul 2024 22:02:44 +0000
Subject: [PATCH 1/4] [compiler-rt][X86] Unify getAMDProcessorTypeAndSubType
This patch unifies the implementation of getAMDProcessorTypeAndSubtype
between compiler-rt and LLVM.
This patch is intended to be a step towards pulling these functions out
into identical .inc files to better facilitate code sharing between LLVM
and compiler-rt.
---
compiler-rt/lib/builtins/cpu_model/x86.c | 42 +++++++++++++++++++++---
llvm/lib/TargetParser/Host.cpp | 21 +++++-------
2 files changed, 46 insertions(+), 17 deletions(-)
diff --git a/compiler-rt/lib/builtins/cpu_model/x86.c b/compiler-rt/lib/builtins/cpu_model/x86.c
index 7e8acb3e73eda..546976d83c3a7 100644
--- a/compiler-rt/lib/builtins/cpu_model/x86.c
+++ b/compiler-rt/lib/builtins/cpu_model/x86.c
@@ -662,14 +662,48 @@ static const char *getAMDProcessorTypeAndSubtype(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 4:
+ CPU = "i486";
+ break;
+ case 5:
+ CPU = "pentium";
+ switch (Model) {
+ case 6:
+ case 7:
+ CPU = "k6";
+ break;
+ case 8:
+ CPU = "k6-2";
+ break;
+ case 9:
+ case 13:
+ CPU = "k6-3";
+ break;
+ case 10:
+ CPU = "geode";
+ break;
+ }
+ break;
+ case 6:
+ if (testFeature(FEATURE_SSE)) {
+ CPU = "athlon-xp";
+ break;
+ }
+ CPU = "athlon";
+ break;
+ case 15:
+ if (testFeature(FEATURE_SSE3)) {
+ CPU = "k8-sse3";
+ break;
+ }
+ CPU = "k8";
+ break;
case 16:
CPU = "amdfam10";
- *Type = AMDFAM10H;
+ *Type = AMDFAM10H; // "amdfam10"
switch (Model) {
case 2:
*Subtype = AMDFAM10H_BARCELONA;
@@ -745,7 +779,7 @@ static const char *getAMDProcessorTypeAndSubtype(unsigned Family,
case 25:
CPU = "znver3";
*Type = AMDFAM19H;
- if ((Model <= 0x0f) || (Model >= 0x20 && Model <= 0x2f) ||
+ if (Model <= 0x0f || (Model >= 0x20 && Model <= 0x2f) ||
(Model >= 0x30 && Model <= 0x3f) || (Model >= 0x40 && Model <= 0x4f) ||
(Model >= 0x50 && Model <= 0x5f)) {
// Family 19h Models 00h-0Fh (Genesis, Chagall) Zen 3
diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
index 2ea56746aff24..90b7d7672e931 100644
--- a/llvm/lib/TargetParser/Host.cpp
+++ b/llvm/lib/TargetParser/Host.cpp
@@ -707,9 +707,7 @@ static StringRef
getIntelProcessorTypeAndSubtype(unsigned Family, unsigned Model,
const unsigned *Features,
unsigned *Type, unsigned *Subtype) {
- auto testFeature = [&](unsigned F) {
- return (Features[F / 32] & (1U << (F % 32))) != 0;
- };
+#define testFeature(F) (Features[F / 32] & (1 << (F % 32))) != 0
StringRef CPU;
@@ -1067,15 +1065,12 @@ getIntelProcessorTypeAndSubtype(unsigned Family, unsigned Model,
return CPU;
}
-static StringRef
-getAMDProcessorTypeAndSubtype(unsigned Family, unsigned Model,
- const unsigned *Features,
- unsigned *Type, unsigned *Subtype) {
- auto testFeature = [&](unsigned F) {
- return (Features[F / 32] & (1U << (F % 32))) != 0;
- };
-
- StringRef CPU;
+static const char *getAMDProcessorTypeAndSubtype(unsigned Family,
+ unsigned Model,
+ const unsigned *Features,
+ unsigned *Type,
+ unsigned *Subtype) {
+ const char *CPU = 0;
switch (Family) {
case 4:
@@ -1215,7 +1210,7 @@ getAMDProcessorTypeAndSubtype(unsigned Family, unsigned Model,
*Subtype = X86::AMDFAM19H_ZNVER4;
break; // "znver4"
}
- break;
+ break; // family 19h
default:
break; // Unknown AMD CPU.
}
>From e9443461b1a60769838ef5a95303886eafd0ebee Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Sun, 7 Jul 2024 19:09:25 +0000
Subject: [PATCH 2/4] Address feedback
---
compiler-rt/lib/builtins/cpu_model/x86.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/compiler-rt/lib/builtins/cpu_model/x86.c b/compiler-rt/lib/builtins/cpu_model/x86.c
index 546976d83c3a7..ab2b685e67ef8 100644
--- a/compiler-rt/lib/builtins/cpu_model/x86.c
+++ b/compiler-rt/lib/builtins/cpu_model/x86.c
@@ -367,13 +367,13 @@ static void detectX86FamilyModel(unsigned EAX, unsigned *Family,
}
}
+#define testFeature(F) (Features[F / 32] & (1 << (F % 32))) != 0
+
static const char *getIntelProcessorTypeAndSubtype(unsigned Family,
unsigned Model,
const unsigned *Features,
unsigned *Type,
unsigned *Subtype) {
-#define testFeature(F) (Features[F / 32] & (1 << (F % 32))) != 0
-
// We select CPU strings to match the code in Host.cpp, but we don't use them
// in compiler-rt.
const char *CPU = 0;
@@ -810,6 +810,8 @@ static const char *getAMDProcessorTypeAndSubtype(unsigned Family,
return CPU;
}
+#undef testFeature
+
static void getAvailableFeatures(unsigned ECX, unsigned EDX, unsigned MaxLeaf,
unsigned *Features) {
unsigned EAX = 0, EBX = 0;
>From 880f65987fe8d05084cd01b79641f58f82695614 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Mon, 8 Jul 2024 17:52:52 +0000
Subject: [PATCH 3/4] Address feedback
---
llvm/lib/TargetParser/Host.cpp | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
index 90b7d7672e931..66c1600a5dd97 100644
--- a/llvm/lib/TargetParser/Host.cpp
+++ b/llvm/lib/TargetParser/Host.cpp
@@ -703,12 +703,12 @@ static void detectX86FamilyModel(unsigned EAX, unsigned *Family,
}
}
+#define testFeature(F) (Features[F / 32] & (1 << (F % 32))) != 0
+
static StringRef
getIntelProcessorTypeAndSubtype(unsigned Family, unsigned Model,
const unsigned *Features,
unsigned *Type, unsigned *Subtype) {
-#define testFeature(F) (Features[F / 32] & (1 << (F % 32))) != 0
-
StringRef CPU;
switch (Family) {
@@ -1218,6 +1218,8 @@ static const char *getAMDProcessorTypeAndSubtype(unsigned Family,
return CPU;
}
+#undef testFeature;
+
static void getAvailableFeatures(unsigned ECX, unsigned EDX, unsigned MaxLeaf,
unsigned *Features) {
unsigned EAX, EBX;
>From 3174ba6926bc002cb6019ea46e5f2678c0ab630b Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Mon, 8 Jul 2024 17:58:54 +0000
Subject: [PATCH 4/4] Fix formatting
---
llvm/lib/TargetParser/Host.cpp | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
index 66c1600a5dd97..87ab23253722e 100644
--- a/llvm/lib/TargetParser/Host.cpp
+++ b/llvm/lib/TargetParser/Host.cpp
@@ -705,10 +705,11 @@ static void detectX86FamilyModel(unsigned EAX, unsigned *Family,
#define testFeature(F) (Features[F / 32] & (1 << (F % 32))) != 0
-static StringRef
-getIntelProcessorTypeAndSubtype(unsigned Family, unsigned Model,
- const unsigned *Features,
- unsigned *Type, unsigned *Subtype) {
+static StringRef getIntelProcessorTypeAndSubtype(unsigned Family,
+ unsigned Model,
+ const unsigned *Features,
+ unsigned *Type,
+ unsigned *Subtype) {
StringRef CPU;
switch (Family) {
More information about the llvm-commits
mailing list