[PATCH] D146113: [RISCV] Make RISCVISAInfo::toFeatureVector ignore unsupported extensions

Alex Bradbury via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 14 23:00:35 PDT 2023


asb created this revision.
asb added reviewers: craig.topper, kito-cheng, reames, MaskRay.
Herald added subscribers: jobnoorman, luke, wingo, pmatos, VincentWu, vkmr, frasercrmck, evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya, arichardson.
Herald added a project: All.
asb requested review of this revision.
Herald added subscribers: pcwang-thead, eopXD.
Herald added a project: LLVM.

parseNormalizedArchString adds a code path that creates a RISCVISAInfo including extensions that may not be supported by LLVM (rather than erroring or just ignoring them). Therefore, toFeatureVector needs to check the extension is supported in order to avoid creating unrecognised feature strings.

This change shouldn't impact any code paths used outside of test code, but this will be relied upon by the next patch which moves llvm-objdump and related tools over to using parseNormalizedArchString.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146113

Files:
  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
@@ -457,3 +457,9 @@
   EXPECT_THAT((*MaybeISAInfo2)->toFeatureVector(),
               ElementsAre("+e", "+experimental-zihintntl", "+xventanacondops"));
 }
+
+TEST(ToFeatureVector, UnsupportedExtensionsAreDropped) {
+  auto MaybeISAInfo = RISCVISAInfo::parseNormalizedArchString("rv64i2p0_m2p0_xmadeup1p0");
+  ASSERT_THAT_EXPECTED(MaybeISAInfo, Succeeded());
+  EXPECT_THAT((*MaybeISAInfo1)->toFeatureVector(), ElementsAre("+m"));
+}
Index: llvm/lib/Support/RISCVISAInfo.cpp
===================================================================
--- llvm/lib/Support/RISCVISAInfo.cpp
+++ llvm/lib/Support/RISCVISAInfo.cpp
@@ -1101,6 +1101,8 @@
     std::string ExtName = Ext.first;
     if (ExtName == "i") // i is not recognized in clang -cc1
       continue;
+    if (!isSupportedExtension(ExtName))
+      continue;
     std::string Feature = isExperimentalExtension(ExtName)
                               ? "+experimental-" + ExtName
                               : "+" + ExtName;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146113.505371.patch
Type: text/x-patch
Size: 1201 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230315/c759e62c/attachment.bin>


More information about the llvm-commits mailing list