[llvm] d8f8ac8 - [RISCV] Don't pre-split before the loop in parseNormalizedArchString. (#91684)
via llvm-commits
llvm-commits at lists.llvm.org
Fri May 10 09:00:00 PDT 2024
Author: Craig Topper
Date: 2024-05-10T08:59:56-07:00
New Revision: d8f8ac8f5f9c787df94ba1ed99b04795afa40ba7
URL: https://github.com/llvm/llvm-project/commit/d8f8ac8f5f9c787df94ba1ed99b04795afa40ba7
DIFF: https://github.com/llvm/llvm-project/commit/d8f8ac8f5f9c787df94ba1ed99b04795afa40ba7.diff
LOG: [RISCV] Don't pre-split before the loop in parseNormalizedArchString. (#91684)
We can extract each extension as we process them without much
complexity.
I changed the error message for cases where there are double underscores
or a trailing underscore. I think this is an improvement over the
previous error.
Added:
Modified:
llvm/lib/TargetParser/RISCVISAInfo.cpp
llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp b/llvm/lib/TargetParser/RISCVISAInfo.cpp
index 975cb5897b760..8ae0c355479ce 100644
--- a/llvm/lib/TargetParser/RISCVISAInfo.cpp
+++ b/llvm/lib/TargetParser/RISCVISAInfo.cpp
@@ -451,9 +451,18 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
// Each extension is of the form ${name}${major_version}p${minor_version}
// and separated by _. Split by _ and then extract the name and version
// information for each extension.
- SmallVector<StringRef, 8> Split;
- Arch.split(Split, '_');
- for (StringRef Ext : Split) {
+ while (!Arch.empty()) {
+ if (Arch[0] == '_') {
+ if (Arch.size() == 1 || Arch[1] == '_')
+ return createStringError(errc::invalid_argument,
+ "extension name missing after separator '_'");
+ Arch = Arch.drop_front();
+ }
+
+ size_t Idx = Arch.find('_');
+ StringRef Ext = Arch.slice(0, Idx);
+ Arch = Arch.slice(Idx, StringRef::npos);
+
StringRef Prefix, MinorVersionStr;
std::tie(Prefix, MinorVersionStr) = Ext.rsplit('p');
if (MinorVersionStr.empty())
diff --git a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
index f9e386a85fea8..7f2d1eb8c0170 100644
--- a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
+++ b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
@@ -38,12 +38,17 @@ TEST(ParseNormalizedArchString, RejectsInvalidBaseISA) {
}
TEST(ParseNormalizedArchString, RejectsMalformedInputs) {
- for (StringRef Input :
- {"rv64i2p0_", "rv32i2p0__a2p0", "rv64e2p", "rv32i", "rv64ip1"}) {
+ for (StringRef Input : {"rv64e2p", "rv32i", "rv64ip1"}) {
EXPECT_EQ(
toString(RISCVISAInfo::parseNormalizedArchString(Input).takeError()),
"extension lacks version in expected format");
}
+
+ for (StringRef Input : {"rv64i2p0_", "rv32i2p0__a2p0"}) {
+ EXPECT_EQ(
+ toString(RISCVISAInfo::parseNormalizedArchString(Input).takeError()),
+ "extension name missing after separator '_'");
+ }
}
TEST(ParseNormalizedArchString, RejectsOnlyVersion) {
More information about the llvm-commits
mailing list