summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@sifive.com>2024-05-01 10:39:24 -0700
committerGitHub <noreply@github.com>2024-05-01 10:39:24 -0700
commit09f4b06dde65adcd077bd1d10f1165083c1fe410 (patch)
tree64bea8ec742e98ff236bab084dfdbb5385a02646
parent7396ab1210a2aeee6bab5b73ec6d02975ba51b93 (diff)
[RISCV] Refactor profile selection in RISCVISAInfo::parseArchString. (#90700)
Instead of hardcoding the 4 current profile prefixes, treat profile selection as a fallback if we don't find "rv32" or "rv64". Update the error message accordingly.
-rw-r--r--clang/test/Driver/riscv-arch.c2
-rw-r--r--clang/test/Driver/riscv-profiles.c2
-rw-r--r--llvm/lib/TargetParser/RISCVISAInfo.cpp45
-rw-r--r--llvm/test/MC/RISCV/invalid-attribute.s2
-rw-r--r--llvm/unittests/TargetParser/RISCVISAInfoTest.cpp6
5 files changed, 29 insertions, 28 deletions
diff --git a/clang/test/Driver/riscv-arch.c b/clang/test/Driver/riscv-arch.c
index abbe8612b378..8c701a736fc7 100644
--- a/clang/test/Driver/riscv-arch.c
+++ b/clang/test/Driver/riscv-arch.c
@@ -204,7 +204,7 @@
// RUN: not %clang --target=riscv32-unknown-elf -march=unknown -### %s \
// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-STR %s
// RV32-STR: error: invalid arch name 'unknown',
-// RV32-STR: string must begin with rv32{i,e,g} or rv64{i,e,g}
+// RV32-STR: string must begin with rv32{i,e,g}, rv64{i,e,g}, or a supported profile name
// RUN: not %clang --target=riscv32-unknown-elf -march=rv32q -### %s \
// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-LETTER %s
diff --git a/clang/test/Driver/riscv-profiles.c b/clang/test/Driver/riscv-profiles.c
index 647567d4c971..298f301de3fe 100644
--- a/clang/test/Driver/riscv-profiles.c
+++ b/clang/test/Driver/riscv-profiles.c
@@ -318,7 +318,7 @@
// PROFILE-WITH-ADDITIONAL: "-target-feature" "+zkt"
// RUN: not %clang --target=riscv64 -### -c %s 2>&1 -march=rva19u64_zfa | FileCheck -check-prefix=INVALID-PROFILE %s
-// INVALID-PROFILE: error: invalid arch name 'rva19u64_zfa', unsupported profile
+// INVALID-PROFILE: error: invalid arch name 'rva19u64_zfa', string must begin with rv32{i,e,g}, rv64{i,e,g}, or a supported profile name
// RUN: not %clang --target=riscv64 -### -c %s 2>&1 -march=rva22u64zfa | FileCheck -check-prefix=INVALID-ADDITIONAL %s
// INVALID-ADDITIONAL: error: invalid arch name 'rva22u64zfa', additional extensions must be after separator '_'
diff --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp b/llvm/lib/TargetParser/RISCVISAInfo.cpp
index 3b0cf8fab25f..d154c00a7859 100644
--- a/llvm/lib/TargetParser/RISCVISAInfo.cpp
+++ b/llvm/lib/TargetParser/RISCVISAInfo.cpp
@@ -592,40 +592,39 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
return createStringError(errc::invalid_argument,
"string must be lowercase");
- if (Arch.starts_with("rvi") || Arch.starts_with("rva") ||
- Arch.starts_with("rvb") || Arch.starts_with("rvm")) {
+ // ISA string must begin with rv32, rv64, or a profile.
+ unsigned XLen = 0;
+ if (Arch.consume_front("rv32")) {
+ XLen = 32;
+ } else if (Arch.consume_front("rv64")) {
+ XLen = 64;
+ } else {
+ // Try parsing as a profile.
const auto *FoundProfile =
llvm::find_if(SupportedProfiles, [Arch](const RISCVProfile &Profile) {
return Arch.starts_with(Profile.Name);
});
- if (FoundProfile == std::end(SupportedProfiles))
- return createStringError(errc::invalid_argument, "unsupported profile");
-
- std::string NewArch = FoundProfile->MArch.str();
- StringRef ArchWithoutProfile = Arch.substr(FoundProfile->Name.size());
- if (!ArchWithoutProfile.empty()) {
- if (!ArchWithoutProfile.starts_with("_"))
- return createStringError(
- errc::invalid_argument,
- "additional extensions must be after separator '_'");
- NewArch += ArchWithoutProfile.str();
+ if (FoundProfile != std::end(SupportedProfiles)) {
+ std::string NewArch = FoundProfile->MArch.str();
+ StringRef ArchWithoutProfile = Arch.drop_front(FoundProfile->Name.size());
+ if (!ArchWithoutProfile.empty()) {
+ if (ArchWithoutProfile.front() != '_')
+ return createStringError(
+ errc::invalid_argument,
+ "additional extensions must be after separator '_'");
+ NewArch += ArchWithoutProfile.str();
+ }
+ return parseArchString(NewArch, EnableExperimentalExtension,
+ ExperimentalExtensionVersionCheck, IgnoreUnknown);
}
- return parseArchString(NewArch, EnableExperimentalExtension,
- ExperimentalExtensionVersionCheck, IgnoreUnknown);
}
- // ISA string must begin with rv32 or rv64.
- unsigned XLen = 0;
- if (Arch.consume_front("rv32"))
- XLen = 32;
- else if (Arch.consume_front("rv64"))
- XLen = 64;
-
if (XLen == 0 || Arch.empty())
return createStringError(
errc::invalid_argument,
- "string must begin with rv32{i,e,g} or rv64{i,e,g}");
+ "string must begin with rv32{i,e,g}, rv64{i,e,g}, or a supported "
+ "profile name");
std::unique_ptr<RISCVISAInfo> ISAInfo(new RISCVISAInfo(XLen));
MapVector<std::string, RISCVISAUtils::ExtensionVersion,
diff --git a/llvm/test/MC/RISCV/invalid-attribute.s b/llvm/test/MC/RISCV/invalid-attribute.s
index 1d732af83cda..2989e80b269a 100644
--- a/llvm/test/MC/RISCV/invalid-attribute.s
+++ b/llvm/test/MC/RISCV/invalid-attribute.s
@@ -11,7 +11,7 @@
# CHECK: [[@LINE-1]]:12: error: attribute name not recognised: unknown
.attribute arch, "foo"
-# CHECK: [[@LINE-1]]:18: error: invalid arch name 'foo', string must begin with rv32{i,e,g} or rv64{i,e,g}
+# CHECK: [[@LINE-1]]:18: error: invalid arch name 'foo', string must begin with rv32{i,e,g}, rv64{i,e,g}, or a supported profile name{{$}}
.attribute arch, "rv32i2p1_y2p0"
# CHECK: [[@LINE-1]]:18: error: invalid arch name 'rv32i2p1_y2p0', invalid standard user-level extension 'y'
diff --git a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
index 9f23000d733d..3aa0178100ab 100644
--- a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
+++ b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
@@ -118,7 +118,8 @@ TEST(ParseArchString, RejectsUpperCase) {
TEST(ParseArchString, RejectsInvalidBaseISA) {
for (StringRef Input : {"rv32", "rv64", "rv65i"}) {
EXPECT_EQ(toString(RISCVISAInfo::parseArchString(Input, true).takeError()),
- "string must begin with rv32{i,e,g} or rv64{i,e,g}");
+ "string must begin with rv32{i,e,g}, rv64{i,e,g}, or a supported "
+ "profile name");
}
for (StringRef Input : {"rv32j", "rv32_i"}) {
@@ -133,7 +134,8 @@ TEST(ParseArchString, RejectsInvalidBaseISA) {
TEST(ParseArchString, RejectsUnsupportedBaseISA) {
for (StringRef Input : {"rv128i", "rv128g"}) {
EXPECT_EQ(toString(RISCVISAInfo::parseArchString(Input, true).takeError()),
- "string must begin with rv32{i,e,g} or rv64{i,e,g}");
+ "string must begin with rv32{i,e,g}, rv64{i,e,g}, or a supported "
+ "profile name");
}
}