Skip to content

Commit

Permalink
[NFC][AArch64] Get default features directly from ArchInfo and CpuInf…
Browse files Browse the repository at this point in the history
…o objects

This updates the AArch64's Target Parser and its uses to capture
information about default features directly from ArchInfo and CpuInfo
objects, instead of relying on an API function to access them
indirectly.

Reviewed By: tmatheson

Differential Revision: https://reviews.llvm.org/D142540
  • Loading branch information
pratlucas committed Jan 27, 2023
1 parent 9ea00fc commit 0753cf2
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 25 deletions.
6 changes: 2 additions & 4 deletions clang/lib/Basic/Targets/AArch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,10 +692,8 @@ void AArch64TargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
Features[OtherArch->getSubArch()] = Enabled;

// Set any features implied by the architecture
uint64_t Extensions =
llvm::AArch64::getDefaultExtensions("generic", *ArchInfo);
std::vector<StringRef> CPUFeats;
if (llvm::AArch64::getExtensionFeatures(Extensions, CPUFeats)) {
if (llvm::AArch64::getExtensionFeatures(ArchInfo->DefaultExts, CPUFeats)) {
for (auto F : CPUFeats) {
assert(F[0] == '+' && "Expected + in target feature!");
Features[F.drop_front(1)] = true;
Expand Down Expand Up @@ -951,7 +949,7 @@ bool AArch64TargetInfo::initFeatureMap(
// Parse the CPU and add any implied features.
std::optional<llvm::AArch64::CpuInfo> CpuInfo = llvm::AArch64::parseCpu(CPU);
if (CpuInfo) {
uint64_t Exts = llvm::AArch64::getDefaultExtensions(CPU, CpuInfo->Arch);
uint64_t Exts = CpuInfo->getImpliedExtensions();
std::vector<StringRef> CPUFeats;
llvm::AArch64::getExtensionFeatures(Exts, CPUFeats);
for (auto F : CPUFeats) {
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/Arch/AArch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ static bool DecodeAArch64Mcpu(const Driver &D, StringRef Mcpu, StringRef &CPU,

Features.push_back(ArchInfo->ArchFeature);

uint64_t Extension = llvm::AArch64::getDefaultExtensions(CPU, *ArchInfo);
uint64_t Extension = CpuInfo->getImpliedExtensions();
if (!llvm::AArch64::getExtensionFeatures(Extension, Features))
return false;
}
Expand Down
5 changes: 4 additions & 1 deletion llvm/include/llvm/TargetParser/AArch64TargetParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@ struct CpuInfo {
const ArchInfo &Arch;
uint64_t DefaultExtensions; // Default extensions for this CPU. These will be
// ORd with the architecture defaults.

uint64_t getImpliedExtensions() const {
return DefaultExtensions | Arch.DefaultExts;
}
};

inline constexpr CpuInfo CpuInfos[] = {
Expand Down Expand Up @@ -509,7 +513,6 @@ StringRef getArchExtFeature(StringRef ArchExt);
StringRef resolveCPUAlias(StringRef CPU);

// Information by Name
uint64_t getDefaultExtensions(StringRef CPU, const ArchInfo &AI);
void getFeatureOption(StringRef Name, std::string &Feature);
std::optional<ArchInfo> getArchForCpu(StringRef CPU);

Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6891,8 +6891,7 @@ bool AArch64AsmParser::parseDirectiveArch(SMLoc L) {
// Get the architecture and extension features.
std::vector<StringRef> AArch64Features;
AArch64Features.push_back(ArchInfo->ArchFeature);
AArch64::getExtensionFeatures(
AArch64::getDefaultExtensions("generic", *ArchInfo), AArch64Features);
AArch64::getExtensionFeatures(ArchInfo->DefaultExts, AArch64Features);

MCSubtargetInfo &STI = copySTI();
std::vector<std::string> ArchFeatures(AArch64Features.begin(), AArch64Features.end());
Expand Down
13 changes: 0 additions & 13 deletions llvm/lib/TargetParser/AArch64TargetParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,6 @@ static unsigned checkArchVersion(llvm::StringRef Arch) {
return 0;
}

uint64_t AArch64::getDefaultExtensions(StringRef CPU,
const AArch64::ArchInfo &AI) {
if (CPU == "generic")
return AI.DefaultExts;

// Note: this now takes cpu aliases into account
std::optional<CpuInfo> Cpu = parseCpu(CPU);
if (!Cpu)
return AI.DefaultExts;

return Cpu->Arch.DefaultExts | Cpu->DefaultExtensions;
}

void AArch64::getFeatureOption(StringRef Name, std::string &Feature) {
for (const auto &E : llvm::AArch64::Extensions) {
if (Name == E.Name) {
Expand Down
6 changes: 2 additions & 4 deletions llvm/unittests/TargetParser/TargetParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -966,11 +966,9 @@ TEST_P(AArch64CPUTestFixture, testAArch64CPU) {
EXPECT_TRUE(Cpu);
EXPECT_EQ(params.ExpectedArch, Cpu->Arch.Name);

uint64_t default_extensions =
AArch64::getDefaultExtensions(params.CPUName, Cpu->Arch);
EXPECT_PRED_FORMAT2(
AssertSameExtensionFlags<ARM::ISAKind::AARCH64>(params.CPUName),
params.ExpectedFlags, default_extensions);
params.ExpectedFlags, Cpu->getImpliedExtensions());
}

INSTANTIATE_TEST_SUITE_P(
Expand Down Expand Up @@ -1472,7 +1470,7 @@ bool testAArch64Extension(StringRef CPUName, StringRef ArchExt) {
if (!Extension)
return false;
std::optional<AArch64::CpuInfo> CpuInfo = AArch64::parseCpu(CPUName);
return (CpuInfo->Arch.DefaultExts | CpuInfo->DefaultExtensions) & Extension->ID;
return CpuInfo->getImpliedExtensions() & Extension->ID;
}

bool testAArch64Extension(const AArch64::ArchInfo &AI, StringRef ArchExt) {
Expand Down

0 comments on commit 0753cf2

Please sign in to comment.