[PATCH] D152423: [RISCV] Add function that check extension name with version
Piyou Chen via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 20 21:07:07 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4b60e1e821b4: [RISCV] Add function that check extension name with version (authored by BeMg).
Herald added a subscriber: sunshaoce.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D152423/new/
https://reviews.llvm.org/D152423
Files:
llvm/include/llvm/Support/RISCVISAInfo.h
llvm/lib/Support/RISCVISAInfo.cpp
llvm/unittests/Support/RISCVISAInfoTest.cpp
Index: llvm/unittests/Support/RISCVISAInfoTest.cpp
===================================================================
--- llvm/unittests/Support/RISCVISAInfoTest.cpp
+++ llvm/unittests/Support/RISCVISAInfoTest.cpp
@@ -604,3 +604,25 @@
EXPECT_EQ(ExtsRV64IDZce.count("zcmp"), 1U);
EXPECT_EQ(ExtsRV64IDZce.count("zcmt"), 1U);
}
+
+TEST(isSupportedExtensionWithVersion, AcceptsSingleExtensionWithVersion) {
+ EXPECT_TRUE(RISCVISAInfo::isSupportedExtensionWithVersion("zbb1p0"));
+ EXPECT_FALSE(RISCVISAInfo::isSupportedExtensionWithVersion("zbb"));
+ EXPECT_FALSE(RISCVISAInfo::isSupportedExtensionWithVersion("zfoo1p0"));
+ EXPECT_FALSE(RISCVISAInfo::isSupportedExtensionWithVersion("zfoo"));
+ EXPECT_FALSE(RISCVISAInfo::isSupportedExtensionWithVersion(""));
+ EXPECT_FALSE(RISCVISAInfo::isSupportedExtensionWithVersion("c2p0zbb1p0"));
+}
+
+TEST(getTargetFeatureForExtension, RetrieveTargetFeatureFromOneExt) {
+ EXPECT_EQ(RISCVISAInfo::getTargetFeatureForExtension("zbb"), "zbb");
+ EXPECT_EQ(RISCVISAInfo::getTargetFeatureForExtension("zicond1p0"),
+ "experimental-zicond");
+ EXPECT_EQ(RISCVISAInfo::getTargetFeatureForExtension("zicond"),
+ "experimental-zicond");
+ EXPECT_EQ(RISCVISAInfo::getTargetFeatureForExtension("zihintntl1234p4321"),
+ "");
+ EXPECT_EQ(RISCVISAInfo::getTargetFeatureForExtension("zfoo"), "");
+ EXPECT_EQ(RISCVISAInfo::getTargetFeatureForExtension(""), "");
+ EXPECT_EQ(RISCVISAInfo::getTargetFeatureForExtension("zbbzihintntl"), "");
+}
Index: llvm/lib/Support/RISCVISAInfo.cpp
===================================================================
--- llvm/lib/Support/RISCVISAInfo.cpp
+++ llvm/lib/Support/RISCVISAInfo.cpp
@@ -1253,3 +1253,40 @@
}
llvm_unreachable("Invalid XLEN");
}
+
+bool RISCVISAInfo::isSupportedExtensionWithVersion(StringRef Ext) {
+ if (Ext.empty())
+ return false;
+
+ auto Pos = findLastNonVersionCharacter(Ext) + 1;
+ StringRef Name = Ext.substr(0, Pos);
+ StringRef Vers = Ext.substr(Pos);
+ if (Vers.empty())
+ return false;
+
+ unsigned Major, Minor, ConsumeLength;
+ if (auto E = getExtensionVersion(Name, Vers, Major, Minor, ConsumeLength,
+ true, true)) {
+ consumeError(std::move(E));
+ return false;
+ }
+
+ return true;
+}
+
+std::string RISCVISAInfo::getTargetFeatureForExtension(StringRef Ext) {
+ if (Ext.empty())
+ return std::string();
+
+ auto Pos = findLastNonVersionCharacter(Ext) + 1;
+ StringRef Name = Ext.substr(0, Pos);
+
+ if (Pos != Ext.size() && !isSupportedExtensionWithVersion(Ext))
+ return std::string();
+
+ if (!isSupportedExtension(Name))
+ return std::string();
+
+ return isExperimentalExtension(Name) ? "experimental-" + Name.str()
+ : Name.str();
+}
Index: llvm/include/llvm/Support/RISCVISAInfo.h
===================================================================
--- llvm/include/llvm/Support/RISCVISAInfo.h
+++ llvm/include/llvm/Support/RISCVISAInfo.h
@@ -85,10 +85,12 @@
static bool isSupportedExtensionFeature(StringRef Ext);
static bool isSupportedExtension(StringRef Ext);
+ static bool isSupportedExtensionWithVersion(StringRef Ext);
static bool isSupportedExtension(StringRef Ext, unsigned MajorVersion,
unsigned MinorVersion);
static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
postProcessAndChecking(std::unique_ptr<RISCVISAInfo> &&ISAInfo);
+ static std::string getTargetFeatureForExtension(StringRef Ext);
private:
RISCVISAInfo(unsigned XLen)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152423.551892.patch
Type: text/x-patch
Size: 3581 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230821/8e2f7922/attachment.bin>
More information about the cfe-commits
mailing list