diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -810,12 +810,9 @@ // Parse the architecture version, adding the required features to // Ret.Features. - std::vector FeatureStrs; - if (ArchKind == llvm::AArch64::ArchKind::INVALID || - !llvm::AArch64::getArchFeatures(ArchKind, FeatureStrs)) + if (ArchKind == llvm::AArch64::ArchKind::INVALID) continue; - for (auto R : FeatureStrs) - Ret.Features.push_back(R.str()); + Ret.Features.push_back(llvm::AArch64::getArchFeature(ArchKind).str()); // Add any extra features, after the + SplitAndAddFeatures(Split.second, Ret.Features); } else if (Feature.startswith("cpu=")) { diff --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp --- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp +++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp @@ -135,8 +135,9 @@ Features.push_back("+neon"); } else { ArchKind = llvm::AArch64::parseCPUArch(CPU); - if (!llvm::AArch64::getArchFeatures(ArchKind, Features)) + if (ArchKind == llvm::AArch64::ArchKind::INVALID) return false; + Features.push_back(llvm::AArch64::getArchFeature(ArchKind)); uint64_t Extension = llvm::AArch64::getDefaultExtensions(CPU, ArchKind); if (!llvm::AArch64::getExtensionFeatures(Extension, Features)) @@ -160,9 +161,9 @@ llvm::AArch64::ArchKind ArchKind = llvm::AArch64::parseArch(Split.first); if (Split.first == "native") ArchKind = llvm::AArch64::getCPUArchKind(llvm::sys::getHostCPUName().str()); - if (ArchKind == llvm::AArch64::ArchKind::INVALID || - !llvm::AArch64::getArchFeatures(ArchKind, Features)) + if (ArchKind == llvm::AArch64::ArchKind::INVALID) return false; + Features.push_back(llvm::AArch64::getArchFeature(ArchKind)); // Enable SVE2 by default on Armv9-A. // It can still be disabled if +nosve2 is present. diff --git a/llvm/include/llvm/Support/AArch64TargetParser.h b/llvm/include/llvm/Support/AArch64TargetParser.h --- a/llvm/include/llvm/Support/AArch64TargetParser.h +++ b/llvm/include/llvm/Support/AArch64TargetParser.h @@ -160,7 +160,7 @@ bool getExtensionFeatures(uint64_t Extensions, std::vector &Features); -bool getArchFeatures(ArchKind AK, std::vector &Features); +StringRef getArchFeature(ArchKind AK); StringRef getArchName(ArchKind AK); StringRef getSubArch(ArchKind AK); diff --git a/llvm/lib/Support/AArch64TargetParser.cpp b/llvm/lib/Support/AArch64TargetParser.cpp --- a/llvm/lib/Support/AArch64TargetParser.cpp +++ b/llvm/lib/Support/AArch64TargetParser.cpp @@ -80,12 +80,8 @@ .Default(CPU); } -bool AArch64::getArchFeatures(AArch64::ArchKind AK, - std::vector &Features) { - if (AK == ArchKind::INVALID) - return false; - Features.push_back(AArch64ARCHNames[static_cast(AK)].ArchFeature); - return true; +StringRef AArch64::getArchFeature(AArch64::ArchKind AK) { + return AArch64ARCHNames[static_cast(AK)].ArchFeature; } StringRef AArch64::getArchName(AArch64::ArchKind AK) { diff --git a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp --- a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp +++ b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp @@ -6889,7 +6889,7 @@ // Get the architecture and extension features. std::vector AArch64Features; - AArch64::getArchFeatures(ID, AArch64Features); + AArch64Features.push_back(AArch64::getArchFeature(ID)); AArch64::getExtensionFeatures(AArch64::getDefaultExtensions("generic", ID), AArch64Features); diff --git a/llvm/unittests/Support/TargetParserTest.cpp b/llvm/unittests/Support/TargetParserTest.cpp --- a/llvm/unittests/Support/TargetParserTest.cpp +++ b/llvm/unittests/Support/TargetParserTest.cpp @@ -1689,14 +1689,23 @@ } TEST(TargetParserTest, AArch64ArchFeatures) { - std::vector Features; - - for (auto AK : AArch64::ArchKinds) { - if (AK == AArch64::ArchKind::INVALID) - EXPECT_FALSE(AArch64::getArchFeatures(AK, Features)); - else - EXPECT_TRUE(AArch64::getArchFeatures(AK, Features)); - } + EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::INVALID), "+"); + EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8A), "+v8a"); + EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8_1A), "+v8.1a"); + EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8_2A), "+v8.2a"); + EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8_3A), "+v8.3a"); + EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8_4A), "+v8.4a"); + EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8_5A), "+v8.5a"); + EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8_6A), "+v8.6a"); + EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8_7A), "+v8.7a"); + EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8_8A), "+v8.8a"); + EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8_9A), "+v8.9a"); + EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV9A), "+v9a"); + EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV9_1A), "+v9.1a"); + EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV9_2A), "+v9.2a"); + EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV9_3A), "+v9.3a"); + EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV9_4A), "+v9.4a"); + EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8R), "+v8r"); } TEST(TargetParserTest, AArch64ArchV9toV8Conversion) {