https://github.com/MacDue created 
https://github.com/llvm/llvm-project/pull/180734

This resolves a recent AArch64 compile-time regression triggered by #176755, 
which inadvertently grew the feature lookup `StringSwitch` too large. This 
patch replaces the `StringSwitch` with a `DenseSet` of target features. This is 
built with a new `FeatureLookupBuilder` helper, which allows reusing all the 
existing cases (to avoid unintentionally changing any of them). 

Compiler-time impact: 
https://llvm-compile-time-tracker.com/compare.php?from=c9753859d19b07315c5a9a493efaa4df18db84ab&to=cb0684b602d5c741ca99b22bb3bc5f902b7a5a7e&stat=instructions:u

>From cd96fcf2398325425a6d0420306cdebaf61ac399 Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell <[email protected]>
Date: Tue, 10 Feb 2026 11:57:16 +0000
Subject: [PATCH] [AArch64][clang] Use DenseSet for target feature lookup (NFC)

---
 clang/lib/Basic/Targets/AArch64.cpp | 34 +++++++++++++++++++++++++----
 clang/lib/Basic/Targets/AArch64.h   |  7 ++++++
 2 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index d148705a36289..6bbda2b56562e 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -839,8 +839,30 @@ bool AArch64TargetInfo::validateCpuSupports(StringRef 
FeatureStr) const {
   return true;
 }
 
-bool AArch64TargetInfo::hasFeature(StringRef Feature) const {
-  return llvm::StringSwitch<bool>(Feature)
+/// A helper class for "hasFeature" lookups (mimicking a StringSwitch).
+struct FeatureLookupBuilder {
+  FeatureLookupBuilder(AArch64FeatureSet &Features) : Features(Features) {
+    Features.clear();
+  }
+
+  FeatureLookupBuilder &Case(StringRef Feat, bool HasFeature) {
+    if (HasFeature)
+      Features.insert(Feat);
+    return *this;
+  }
+
+  FeatureLookupBuilder &Cases(ArrayRef<StringRef> Feats, bool HasFeature) {
+    if (HasFeature)
+      Features.insert_range(Feats);
+    return *this;
+  }
+
+private:
+  AArch64FeatureSet &Features;
+};
+
+void AArch64TargetInfo::computeFeatureLookup() {
+  FeatureLookupBuilder(HasFeatureLookup)
       .Cases({"aarch64", "arm64", "arm"}, true)
       .Case("fmv", HasFMV)
       .Case("fp", FPU & FPUMode)
@@ -911,8 +933,11 @@ bool AArch64TargetInfo::hasFeature(StringRef Feature) 
const {
       .Case("sve-aes2", HasSVE_AES2)
       .Case("ssve-aes", HasSSVE_AES)
       .Case("sve2p2", FPU & SveMode && HasSVE2p2)
-      .Case("sme2p2", HasSME2p2)
-      .Default(false);
+      .Case("sme2p2", HasSME2p2);
+}
+
+bool AArch64TargetInfo::hasFeature(StringRef Feature) const {
+  return HasFeatureLookup.contains(Feature);
 }
 
 void AArch64TargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
@@ -1286,6 +1311,7 @@ bool 
AArch64TargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
   if (HasNoSVE)
     FPU &= ~SveMode;
 
+  computeFeatureLookup();
   return true;
 }
 
diff --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index 581b161de046a..f9dffed8769ef 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -15,6 +15,7 @@
 
 #include "OSTargets.h"
 #include "clang/Basic/TargetBuiltins.h"
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/TargetParser/AArch64TargetParser.h"
 #include <optional>
 
@@ -54,6 +55,8 @@ static const unsigned ARM64AddrSpaceMap[] = {
     20, // wasm_funcref
 };
 
+using AArch64FeatureSet = llvm::SmallDenseSet<StringRef, 32>;
+
 class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo {
   static const TargetInfo::GCCRegAlias GCCRegAliases[];
   static const char *const GCCRegNames[];
@@ -143,6 +146,10 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public 
TargetInfo {
 
   const llvm::AArch64::ArchInfo *ArchInfo = &llvm::AArch64::ARMV8A;
 
+  AArch64FeatureSet HasFeatureLookup;
+
+  void computeFeatureLookup();
+
 protected:
   std::string ABI;
 

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to