[PATCH] D119541: [RISCV] Fix RISCVTargetInfo::initFeatureMap, add non-isa features back after implication

Yueh-Ting Chen via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 11 04:42:03 PST 2022

eopXD created this revision.
eopXD added reviewers: junparser, craig.topper, asb, frasercrmck.
Herald added subscribers: VincentWu, luke957, achieveartificialintelligence, vkmr, evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar.
eopXD requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, MaskRay.
Herald added a project: clang.

Previously D113336 <https://reviews.llvm.org/D113336> makes RISCVTargetInfo::initFeatureMap return the results
processed by RISCVISAInfo, which only consists of ISA features and misses
non-ISA features like `relax` and `save-restore`.

This patch fixes the problem.

  rG LLVM Github Monorepo



Index: clang/lib/Basic/Targets/RISCV.cpp
--- clang/lib/Basic/Targets/RISCV.cpp
+++ clang/lib/Basic/Targets/RISCV.cpp
@@ -232,8 +232,16 @@
     return false;
-  return TargetInfo::initFeatureMap(Features, Diags, CPU,
-                                    (*ParseResult)->toFeatureVector());
+  // RISCVISAInfo makes implications for ISA features
+  std::vector<std::string> ImpliedFeatures = (*ParseResult)->toFeatureVector();
+  // Add non-ISA features like `relax` and `save-restore` back
+  for (std::string Feature : FeaturesVec) {
+    if (std::find(begin(ImpliedFeatures), end(ImpliedFeatures), Feature) ==
+        end(ImpliedFeatures))
+      ImpliedFeatures.push_back(Feature);
+  }
+  return TargetInfo::initFeatureMap(Features, Diags, CPU, ImpliedFeatures);
 /// Return true if has this feature, need to sync with handleTargetFeatures.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119541.407841.patch
Type: text/x-patch
Size: 927 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220211/591edbca/attachment.bin>

More information about the cfe-commits mailing list