[clang] 7f51a9e - [RISCV] Fix RISCVTargetInfo::initFeatureMap, add non-ISA features back after implication
via cfe-commits
cfe-commits at lists.llvm.org
Sun Feb 13 21:05:17 PST 2022
Author: eopXD
Date: 2022-02-13T21:05:06-08:00
New Revision: 7f51a9e2730e32eec45ff2e91b3d7bae897893e4
URL: https://github.com/llvm/llvm-project/commit/7f51a9e2730e32eec45ff2e91b3d7bae897893e4
DIFF: https://github.com/llvm/llvm-project/commit/7f51a9e2730e32eec45ff2e91b3d7bae897893e4.diff
LOG: [RISCV] Fix RISCVTargetInfo::initFeatureMap, add non-ISA features back after implication
Previously 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.
Reviewed By: junparser
Differential Revision: https://reviews.llvm.org/D119541
Added:
clang/test/Driver/riscv-default-features.c
Modified:
clang/lib/Basic/Targets/RISCV.cpp
Removed:
################################################################################
diff --git a/clang/lib/Basic/Targets/RISCV.cpp b/clang/lib/Basic/Targets/RISCV.cpp
index ca72cf200d466..fd30551eb4e0d 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -232,8 +232,16 @@ bool RISCVTargetInfo::initFeatureMap(
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.
diff --git a/clang/test/Driver/riscv-default-features.c b/clang/test/Driver/riscv-default-features.c
new file mode 100644
index 0000000000000..07b0778cd9938
--- /dev/null
+++ b/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;
+}
More information about the cfe-commits
mailing list