[clang] [AArch64] Add getHostCPUFeatures to query for enabled features in cpu… (PR #97749)

via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 4 08:46:05 PDT 2024


https://github.com/neildhickey created https://github.com/llvm/llvm-project/pull/97749

…info

This pull request adds code to call getHostCPUInfo into the AArch64 Target Parser to query the cpuinfo for the device in the case where we are compiling with -mcpu=native

>From c942cb269560c6472a814e2d31f1545c6b80a890 Mon Sep 17 00:00:00 2001
From: Neil Hickey <nhickey at nvidia.com>
Date: Wed, 3 Jul 2024 07:22:46 -0700
Subject: [PATCH] [AArch64] Add getHostCPUFeatures to query for enabled
 features in cpuinfo

---
 clang/lib/Driver/ToolChains/Arch/AArch64.cpp | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
index ec248b80251ea..2862c297622fa 100644
--- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -445,4 +445,21 @@ void aarch64::getAArch64TargetFeatures(const Driver &D,
 
   if (Args.getLastArg(options::OPT_mno_bti_at_return_twice))
     Features.push_back("+no-bti-at-return-twice");
+
+  // Parse AArch64 CPU Features
+  const Arg *CPUArg = Args.getLastArg(options::OPT_mcpu_EQ);
+  StringRef CPUName;
+
+  if (CPUArg) {
+    CPUName = CPUArg->getValue();
+    if (CPUName == "native") {
+      llvm::StringMap<bool> HostFeatures;
+      if (llvm::sys::getHostCPUFeatures(HostFeatures)) {
+        for (auto &F : HostFeatures) {
+          Features.push_back(
+            Args.MakeArgString((F.second ? "+" : "-") + F.first()));
+        }
+      }
+    }
+  }
 }



More information about the cfe-commits mailing list