[clang] [llvm] [AArch64] Use parseArchExtension function. NFC (PR #78158)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 15 05:31:26 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-aarch64

Author: Anatoly Trosinenko (atrosinenko)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/78158.diff


2 Files Affected:

- (modified) clang/lib/Basic/Targets/AArch64.cpp (+9-15) 
- (modified) llvm/lib/TargetParser/AArch64TargetParser.cpp (+8-14) 


``````````diff
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();
 }
 

``````````

</details>


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


More information about the cfe-commits mailing list