[llvm] [AArch64] Make compiling arm_neon.h faster (PR #226378)

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 24 23:43:42 PDT 2026


https://github.com/nico created https://github.com/llvm/llvm-project/pull/226378

Replace two linear scans with map lookups.

On my system, reduces time to compile a TU that does nothing but `#include <arm_neon.h>` from 92.0 ms ± 1.4 ms to 70.9 ms ± 1.3 ms.

No behavior change.

>From 01f3018d9d21412f44be5357e4b5fe7f793baf52 Mon Sep 17 00:00:00 2001
From: Nico Weber <thakis at chromium.org>
Date: Sun, 20 Sep 2026 12:40:26 -0400
Subject: [PATCH] [AArch64] Make compiling arm_neon.h faster
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Replace two linear scans with map lookups.

On my system, reduces time to compile a TU that does nothing but
`#include <arm_neon.h>` from 92.0 ms ± 1.4 ms to 70.9 ms ± 1.3 ms.

No behavior change.
---
 llvm/lib/TargetParser/AArch64TargetParser.cpp | 28 +++++++++++++------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/llvm/lib/TargetParser/AArch64TargetParser.cpp b/llvm/lib/TargetParser/AArch64TargetParser.cpp
index b7ceb0bb403c30..ee0a5204c1429c 100644
--- a/llvm/lib/TargetParser/AArch64TargetParser.cpp
+++ b/llvm/lib/TargetParser/AArch64TargetParser.cpp
@@ -12,6 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/TargetParser/AArch64TargetParser.h"
+#include "llvm/ADT/StringMap.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Format.h"
 #include "llvm/Support/raw_ostream.h"
@@ -165,10 +166,15 @@ std::optional<AArch64::ExtensionInfo>
 AArch64::parseArchExtension(StringRef ArchExt) {
   if (ArchExt.empty())
     return {};
-  for (const auto &A : Extensions) {
-    if (ArchExt == StrTab[A.UserVisibleName] || ArchExt == StrTab[A.Alias])
-      return A;
-  }
+  static const StringMap<const ExtensionInfo *> NameToExtension = [] {
+    StringMap<const ExtensionInfo *> Map;
+    for (const auto &A : Extensions)
+      for (StringRef Name : {StrTab[A.UserVisibleName], StrTab[A.Alias]})
+        Map.try_emplace(Name, &A);
+    return Map;
+  }();
+  if (const ExtensionInfo *A = NameToExtension.lookup(ArchExt))
+    return *A;
   return {};
 }
 
@@ -186,10 +192,16 @@ std::optional<AArch64::FMVInfo> AArch64::parseFMVExtension(StringRef FMVExt) {
 
 std::optional<AArch64::ExtensionInfo>
 AArch64::targetFeatureToExtension(StringRef TargetFeature) {
-  for (const auto &E : Extensions)
-    if (TargetFeature == StrTab[E.PosTargetFeature] ||
-        TargetFeature == StrTab[E.NegTargetFeature])
-      return E;
+  static const StringMap<const ExtensionInfo *> FeatureToExtension = [] {
+    StringMap<const ExtensionInfo *> Map;
+    for (const auto &E : Extensions)
+      for (StringRef Feature :
+           {StrTab[E.PosTargetFeature], StrTab[E.NegTargetFeature]})
+        Map.try_emplace(Feature, &E);
+    return Map;
+  }();
+  if (const ExtensionInfo *E = FeatureToExtension.lookup(TargetFeature))
+    return *E;
   return {};
 }
 



More information about the llvm-commits mailing list