[llvm] Detect apple m2 processors (PR #67591)

Tom Forbes via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 27 12:00:50 PDT 2023


https://github.com/orf created https://github.com/llvm/llvm-project/pull/67591

Currently on MacOS getHostCPUName only detects M1 processors and not M2 processors. The M2 CPU family is the following:

```
❯ sysctl hw.cpufamily
hw.cpufamily: -634136515
```

This PR sets the target CPU to apple-m2.

>From 0064c958009ed2a43fcfe39a7e67dc1a8c302ec9 Mon Sep 17 00:00:00 2001
From: Tom Forbes <tom at tomforb.es>
Date: Fri, 25 Aug 2023 13:41:55 +0100
Subject: [PATCH] Detect apple m2 processors

---
 llvm/lib/TargetParser/Host.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
index cdb1f72ae39b9fc..b297e75ddd48148 100644
--- a/llvm/lib/TargetParser/Host.cpp
+++ b/llvm/lib/TargetParser/Host.cpp
@@ -1418,6 +1418,7 @@ StringRef sys::getHostCPUName() {
 #define CPUFAMILY_ARM_VORTEX_TEMPEST 0x07d34b9f
 #define CPUFAMILY_ARM_LIGHTNING_THUNDER 0x462504d2
 #define CPUFAMILY_ARM_FIRESTORM_ICESTORM 0x1b588bb3
+#define CPUFAMILY_ARM_BLIZZARD_AVALANCHE 0xda33d83d
 
 StringRef sys::getHostCPUName() {
   uint32_t Family;
@@ -1443,9 +1444,11 @@ StringRef sys::getHostCPUName() {
     return "apple-a13";
   case CPUFAMILY_ARM_FIRESTORM_ICESTORM:
     return "apple-m1";
+  case CPUFAMILY_ARM_BLIZZARD_AVALANCHE:
+    return "apple-m2";
   default:
     // Default to the newest CPU we know about.
-    return "apple-m1";
+    return "apple-m2";
   }
 }
 #elif defined(_AIX)



More information about the llvm-commits mailing list