[llvm] [RISCV] Don't pre-split before the loop in parseNormalizedArchString. (PR #91684)
via llvm-commits
llvm-commits at lists.llvm.org
Thu May 9 17:07:49 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-risc-v
Author: Craig Topper (topperc)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/91684.diff
2 Files Affected:
- (modified) llvm/lib/TargetParser/RISCVISAInfo.cpp (+12-3)
- (modified) llvm/unittests/TargetParser/RISCVISAInfoTest.cpp (+7-2)
``````````diff
diff --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp b/llvm/lib/TargetParser/RISCVISAInfo.cpp
index c553e330a878b..033df27c68781 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) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/91684
More information about the llvm-commits
mailing list