[llvm] 84d75c8 - [AArch64] Make compiling arm_neon.h faster (#226378)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 25 06:47:11 PDT 2026
Author: Nico Weber
Date: 2026-09-25T13:47:02Z
New Revision: 84d75c8ab6eb610cde0048458f96085f923fc392
URL: https://github.com/llvm/llvm-project/commit/84d75c8ab6eb610cde0048458f96085f923fc392
DIFF: https://github.com/llvm/llvm-project/commit/84d75c8ab6eb610cde0048458f96085f923fc392.diff
LOG: [AArch64] Make compiling arm_neon.h faster (#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.
Added:
Modified:
llvm/lib/TargetParser/AArch64TargetParser.cpp
Removed:
################################################################################
diff --git a/llvm/lib/TargetParser/AArch64TargetParser.cpp b/llvm/lib/TargetParser/AArch64TargetParser.cpp
index b7ceb0bb403c3..3624b04ffb81e 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/DenseMap.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 DenseMap<StringRef, const ExtensionInfo *> NameToExt = [] {
+ DenseMap<StringRef, 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 = NameToExt.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 DenseMap<StringRef, const ExtensionInfo *> FeatureToExt = [] {
+ DenseMap<StringRef, 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 = FeatureToExt.lookup(TargetFeature))
+ return *E;
return {};
}
More information about the llvm-commits
mailing list