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

Madhur Amilkanthwar via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 4 23:18:14 PDT 2024


================
@@ -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()));
+        }
+      }
+    }
----------------
madhur13490 wrote:

You can use early return here.

```
if (!CPUArg) 
return;

if (CPUName != "native")
return

if (!llvm::sys::getHostCPUFeatures(HostFeatures)) 
return

```
and then iterate over `HostFeatures`. I think it will be cleaner.

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


More information about the cfe-commits mailing list