Skip to content

Commit

Permalink
[AArch64] Use parseArchExtension function. NFC (#78158)
Browse files Browse the repository at this point in the history
  • Loading branch information
atrosinenko authored Jan 17, 2024
1 parent 92289db commit 7f7bbb9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 29 deletions.
24 changes: 9 additions & 15 deletions clang/lib/Basic/Targets/AArch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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 {
Expand Down
22 changes: 8 additions & 14 deletions llvm/lib/TargetParser/AArch64TargetParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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();
}

Expand Down

0 comments on commit 7f7bbb9

Please sign in to comment.