[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
Sun Feb 13 21:05:19 PST 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG7f51a9e2730e: [RISCV] Fix RISCVTargetInfo::initFeatureMap, add non-ISA features back after… (authored by eopXD).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119541/new/

https://reviews.llvm.org/D119541

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/test/Driver/riscv-default-features.c


Index: clang/test/Driver/riscv-default-features.c
===================================================================
--- /dev/null
+++ clang/test/Driver/riscv-default-features.c
@@ -0,0 +1,9 @@
+// RUN: %clang -target riscv32-unknown-elf -S -emit-llvm %s -o - | FileCheck %s -check-prefix=RV32
+
+// RV32: "target-features"="+a,+c,+m,+relax,-save-restore"
+// RV64: "target-features"="+64bit,+a,+c,+m,+relax,-save-restore"
+
+// Dummy function
+int foo(){
+  return  3;
+}
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.408325.patch
Type: text/x-patch
Size: 1401 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220214/664578cb/attachment.bin>


More information about the cfe-commits mailing list