[PATCH] D119788: [AArch64] Add support for -march=native for Apple M1 CPU
Keith Smiley via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 17 19:57:47 PST 2022
keith updated this revision to Diff 409849.
keith added a comment.
Update to read CPU from sysctl
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D119788/new/
https://reviews.llvm.org/D119788
Files:
clang/lib/Driver/ToolChains/Arch/AArch64.cpp
llvm/lib/Support/Host.cpp
Index: llvm/lib/Support/Host.cpp
===================================================================
--- llvm/lib/Support/Host.cpp
+++ llvm/lib/Support/Host.cpp
@@ -1299,32 +1299,48 @@
bool HaveVectorSupport = CVT[244] & 0x80;
return getCPUNameFromS390Model(Id, HaveVectorSupport);
}
-#elif defined(__APPLE__) && defined(__aarch64__)
-StringRef sys::getHostCPUName() {
- return "cyclone";
-}
-#elif defined(__APPLE__) && defined(__arm__)
-StringRef sys::getHostCPUName() {
- host_basic_info_data_t hostInfo;
- mach_msg_type_number_t infoCount;
+#elif defined(__APPLE__) && (defined(__arm__) || defined(__aarch64__))
+#include <sys/param.h>
+#include <sys/sysctl.h>
- infoCount = HOST_BASIC_INFO_COUNT;
- mach_port_t hostPort = mach_host_self();
- host_info(hostPort, HOST_BASIC_INFO, (host_info_t)&hostInfo,
- &infoCount);
- mach_port_deallocate(mach_task_self(), hostPort);
+#define CPUFAMILY_ARM_SWIFT 0x1e2d6381
+#define CPUFAMILY_ARM_CYCLONE 0x37a09642
+#define CPUFAMILY_ARM_TYPHOON 0x2c91a47e
+#define CPUFAMILY_ARM_TWISTER 0x92fb37c8
+#define CPUFAMILY_ARM_HURRICANE 0x67ceee93
+#define CPUFAMILY_ARM_MONSOON_MISTRAL 0xe81e7ef6
+#define CPUFAMILY_ARM_VORTEX_TEMPEST 0x07d34b9f
+#define CPUFAMILY_ARM_LIGHTNING_THUNDER 0x462504d2
+#define CPUFAMILY_ARM_FIRESTORM_ICESTORM 0x1b588bb3
+
+StringRef sys::getHostCPUName() {
+ uint32_t Family;
+ size_t Length = sizeof(Family);
+ int Error = sysctlbyname("hw.cpufamily", &Family, &Length, NULL, 0);
+ assert(!Error && "Fetching hw.cpufamily failed");
- if (hostInfo.cpu_type != CPU_TYPE_ARM) {
- assert(false && "CPUType not equal to ARM should not be possible on ARM");
+ switch (Family) {
+ case CPUFAMILY_ARM_SWIFT:
+ return "swift";
+ case CPUFAMILY_ARM_CYCLONE:
+ return "apple-a7";
+ case CPUFAMILY_ARM_TYPHOON:
+ return "apple-a8";
+ case CPUFAMILY_ARM_TWISTER:
+ return "apple-a9";
+ case CPUFAMILY_ARM_HURRICANE:
+ return "apple-a10";
+ case CPUFAMILY_ARM_MONSOON_MISTRAL:
+ return "apple-a11";
+ case CPUFAMILY_ARM_VORTEX_TEMPEST:
+ return "apple-a12";
+ case CPUFAMILY_ARM_LIGHTNING_THUNDER:
+ return "apple-a13";
+ case CPUFAMILY_ARM_FIRESTORM_ICESTORM:
+ return "apple-m1";
+ default:
return "generic";
}
- switch (hostInfo.cpu_subtype) {
- case CPU_SUBTYPE_ARM_V7S:
- return "swift";
- default:;
- }
-
- return "generic";
}
#elif defined(_AIX)
StringRef sys::getHostCPUName() {
Index: clang/lib/Driver/ToolChains/Arch/AArch64.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -151,6 +151,8 @@
std::pair<StringRef, StringRef> Split = StringRef(MarchLowerCase).split("+");
llvm::AArch64::ArchKind ArchKind = llvm::AArch64::parseArch(Split.first);
+ if (Split.first == "native")
+ ArchKind = llvm::AArch64::getCPUArchKind(llvm::sys::getHostCPUName().str());
if (ArchKind == llvm::AArch64::ArchKind::INVALID ||
!llvm::AArch64::getArchFeatures(ArchKind, Features))
return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119788.409849.patch
Type: text/x-patch
Size: 3091 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220218/e6cc27f7/attachment.bin>
More information about the llvm-commits
mailing list