Skip to content

Commit 7f51a9e

Browse files
author
eopXD
committed
[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
1 parent f4214e1 commit 7f51a9e

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

clang/lib/Basic/Targets/RISCV.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,16 @@ bool RISCVTargetInfo::initFeatureMap(
232232
return false;
233233
}
234234

235-
return TargetInfo::initFeatureMap(Features, Diags, CPU,
236-
(*ParseResult)->toFeatureVector());
235+
// RISCVISAInfo makes implications for ISA features
236+
std::vector<std::string> ImpliedFeatures = (*ParseResult)->toFeatureVector();
237+
// Add non-ISA features like `relax` and `save-restore` back
238+
for (std::string Feature : FeaturesVec) {
239+
if (std::find(begin(ImpliedFeatures), end(ImpliedFeatures), Feature) ==
240+
end(ImpliedFeatures))
241+
ImpliedFeatures.push_back(Feature);
242+
}
243+
244+
return TargetInfo::initFeatureMap(Features, Diags, CPU, ImpliedFeatures);
237245
}
238246

239247
/// Return true if has this feature, need to sync with handleTargetFeatures.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %clang -target riscv32-unknown-elf -S -emit-llvm %s -o - | FileCheck %s -check-prefix=RV32
2+
3+
// RV32: "target-features"="+a,+c,+m,+relax,-save-restore"
4+
// RV64: "target-features"="+64bit,+a,+c,+m,+relax,-save-restore"
5+
6+
// Dummy function
7+
int foo(){
8+
return 3;
9+
}

0 commit comments

Comments
 (0)