[PATCH] D158621: [RISCV] Add getExtensionSerialProvide a unique number for extension.
Piyou Chen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 23 07:44:18 PDT 2023
BeMg created this revision.
Herald added subscribers: jobnoorman, luke, sunshaoce, VincentWu, vkmr, frasercrmck, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, hiraditya, arichardson.
Herald added a project: All.
BeMg requested review of this revision.
Herald added subscribers: llvm-commits, wangpc, eopXD, MaskRay.
Herald added a project: LLVM.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D158621
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
@@ -626,3 +626,10 @@
EXPECT_EQ(RISCVISAInfo::getTargetFeatureForExtension(""), "");
EXPECT_EQ(RISCVISAInfo::getTargetFeatureForExtension("zbbzihintntl"), "");
}
+
+TEST(getExtensionSerial, RetrieveAUniqueNumberForExt) {
+ EXPECT_EQ(RISCVISAInfo::getExtensionSerial("f"), 5U);
+ EXPECT_EQ(RISCVISAInfo::getExtensionSerial("a"), 1U);
+ EXPECT_EQ(RISCVISAInfo::getExtensionSerial("foo"), 0U);
+ EXPECT_EQ(RISCVISAInfo::getExtensionSerial("experimental-zicond"), 97U);
+}
Index: llvm/lib/Support/RISCVISAInfo.cpp
===================================================================
--- llvm/lib/Support/RISCVISAInfo.cpp
+++ llvm/lib/Support/RISCVISAInfo.cpp
@@ -1290,3 +1290,22 @@
return isExperimentalExtension(Name) ? "experimental-" + Name.str()
: Name.str();
}
+
+
+
+unsigned RISCVISAInfo::getExtensionSerial(StringRef ExtName) {
+ verifyTables();
+
+ unsigned Offset = 1;
+ if (stripExperimentalPrefix(ExtName))
+ Offset += sizeof(SupportedExtensions) / sizeof(SupportedExtensions[0]);
+
+ for (auto ExtInfo : {ArrayRef(SupportedExtensions),
+ ArrayRef(SupportedExperimentalExtensions)}) {
+ auto I = llvm::lower_bound(ExtInfo, ExtName, LessExtName());
+ if (I != ExtInfo.end() && I->Name == ExtName)
+ return (I - ExtInfo.begin()) + Offset;
+ }
+
+ return 0;
+}
Index: llvm/include/llvm/Support/RISCVISAInfo.h
===================================================================
--- llvm/include/llvm/Support/RISCVISAInfo.h
+++ llvm/include/llvm/Support/RISCVISAInfo.h
@@ -91,6 +91,7 @@
static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
postProcessAndChecking(std::unique_ptr<RISCVISAInfo> &&ISAInfo);
static std::string getTargetFeatureForExtension(StringRef Ext);
+ static unsigned getExtensionSerial(StringRef ExtName);
private:
RISCVISAInfo(unsigned XLen)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158621.552711.patch
Type: text/x-patch
Size: 2092 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230823/318fc52c/attachment.bin>
More information about the llvm-commits
mailing list