[clang] [llvm] [AArch64] Use parseArchExtension function. NFC (PR #78158)
Anatoly Trosinenko via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 15 05:31:00 PST 2024
https://github.com/atrosinenko created https://github.com/llvm/llvm-project/pull/78158
None
>From 2c4ebf05d3d85cb9541cefc446f3a85abc64ec22 Mon Sep 17 00:00:00 2001
From: Anatoly Trosinenko <atrosinenko at accesssoftek.com>
Date: Sat, 13 Jan 2024 12:14:46 +0300
Subject: [PATCH] [AArch64] Use parseArchExtension function. NFC
---
clang/lib/Basic/Targets/AArch64.cpp | 24 +++++++------------
llvm/lib/TargetParser/AArch64TargetParser.cpp | 22 +++++++----------
2 files changed, 17 insertions(+), 29 deletions(-)
diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp
index 9ebaf4d40cd7e5..da6846cdbffb9a 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -622,9 +622,8 @@ AArch64TargetInfo::getVScaleRange(const LangOptions &LangOpts) const {
unsigned AArch64TargetInfo::multiVersionSortPriority(StringRef Name) const {
if (Name == "default")
return 0;
- for (const auto &E : llvm::AArch64::Extensions)
- if (Name == E.Name)
- return E.FmvPriority;
+ if (auto Ext = llvm::AArch64::parseArchExtension(Name))
+ return Ext->FmvPriority;
return 0;
}
@@ -634,24 +633,19 @@ unsigned AArch64TargetInfo::multiVersionFeatureCost() const {
}
bool AArch64TargetInfo::doesFeatureAffectCodeGen(StringRef Name) const {
- auto F = llvm::find_if(llvm::AArch64::Extensions, [&](const auto &E) {
- return Name == E.Name && !E.DependentFeatures.empty();
- });
- return F != std::end(llvm::AArch64::Extensions);
+ if (auto Ext = llvm::AArch64::parseArchExtension(Name))
+ return !Ext->DependentFeatures.empty();
+ return false;
}
StringRef AArch64TargetInfo::getFeatureDependencies(StringRef Name) const {
- auto F = llvm::find_if(llvm::AArch64::Extensions,
- [&](const auto &E) { return Name == E.Name; });
- return F != std::end(llvm::AArch64::Extensions) ? F->DependentFeatures
- : StringRef();
+ if (auto Ext = llvm::AArch64::parseArchExtension(Name))
+ return Ext->DependentFeatures;
+ return StringRef();
}
bool AArch64TargetInfo::validateCpuSupports(StringRef FeatureStr) const {
- for (const auto &E : llvm::AArch64::Extensions)
- if (FeatureStr == E.Name)
- return true;
- return false;
+ return llvm::AArch64::parseArchExtension(FeatureStr).has_value();
}
bool AArch64TargetInfo::hasFeature(StringRef Feature) const {
diff --git a/llvm/lib/TargetParser/AArch64TargetParser.cpp b/llvm/lib/TargetParser/AArch64TargetParser.cpp
index d3c72497c41cbe..fe051922061a91 100644
--- a/llvm/lib/TargetParser/AArch64TargetParser.cpp
+++ b/llvm/lib/TargetParser/AArch64TargetParser.cpp
@@ -47,11 +47,8 @@ std::optional<AArch64::ArchInfo> AArch64::ArchInfo::findBySubArch(StringRef SubA
uint64_t AArch64::getCpuSupportsMask(ArrayRef<StringRef> FeatureStrs) {
uint64_t FeaturesMask = 0;
for (const StringRef &FeatureStr : FeatureStrs) {
- for (const auto &E : llvm::AArch64::Extensions)
- if (FeatureStr == E.Name) {
- FeaturesMask |= (1ULL << E.CPUFeature);
- break;
- }
+ if (auto Ext = parseArchExtension(FeatureStr))
+ FeaturesMask |= (1ULL << Ext->CPUFeature);
}
return FeaturesMask;
}
@@ -75,17 +72,14 @@ StringRef AArch64::resolveCPUAlias(StringRef Name) {
}
StringRef AArch64::getArchExtFeature(StringRef ArchExt) {
- if (ArchExt.starts_with("no")) {
- StringRef ArchExtBase(ArchExt.substr(2));
- for (const auto &AE : Extensions) {
- if (!AE.NegFeature.empty() && ArchExtBase == AE.Name)
- return AE.NegFeature;
- }
+ bool IsNegated = ArchExt.starts_with("no");
+ StringRef ArchExtBase = IsNegated ? ArchExt.drop_front(2) : ArchExt;
+
+ if (auto AE = parseArchExtension(ArchExtBase)) {
+ // Note: the returned string can be empty.
+ return IsNegated ? AE->NegFeature : AE->Feature;
}
- for (const auto &AE : Extensions)
- if (!AE.Feature.empty() && ArchExt == AE.Name)
- return AE.Feature;
return StringRef();
}
More information about the llvm-commits
mailing list