[clang] 60b6e73 - [RISCV] Imply extensions in RISCVTargetInfo::initFeatureMap
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 20 01:47:18 PST 2022
Author: eopXD
Date: 2022-01-20T01:47:10-08:00
New Revision: 60b6e73769f84110f2cc0a2dbbf610c8671aa696
URL: https://github.com/llvm/llvm-project/commit/60b6e73769f84110f2cc0a2dbbf610c8671aa696
DIFF: https://github.com/llvm/llvm-project/commit/60b6e73769f84110f2cc0a2dbbf610c8671aa696.diff
LOG: [RISCV] Imply extensions in RISCVTargetInfo::initFeatureMap
Under ASTContext, clang only copies the features from the options with
Target->initFeatureMap, and no implications is done there. This makes
clang_cc1 fail to imply into `zve32x` for the vector extension, and test
cases will have to add ` -target-feature +experimental-zve32x` in order
to work.
This patch fixes it.
Reviewed By: kito-cheng
Differential Revision: https://reviews.llvm.org/D113336
Added:
Modified:
clang/lib/Basic/Targets/RISCV.cpp
llvm/include/llvm/Support/RISCVISAInfo.h
llvm/lib/Support/RISCVISAInfo.cpp
Removed:
################################################################################
diff --git a/clang/lib/Basic/Targets/RISCV.cpp b/clang/lib/Basic/Targets/RISCV.cpp
index 43b031dbdad7a..dc4a451726bbe 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -214,10 +214,26 @@ bool RISCVTargetInfo::initFeatureMap(
llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
const std::vector<std::string> &FeaturesVec) const {
- if (getTriple().getArch() == llvm::Triple::riscv64)
+ unsigned XLen = 32;
+
+ if (getTriple().getArch() == llvm::Triple::riscv64) {
Features["64bit"] = true;
+ XLen = 64;
+ }
+
+ auto ParseResult = llvm::RISCVISAInfo::parseFeatures(XLen, FeaturesVec);
+ if (!ParseResult) {
+ std::string Buffer;
+ llvm::raw_string_ostream OutputErrMsg(Buffer);
+ handleAllErrors(ParseResult.takeError(), [&](llvm::StringError &ErrMsg) {
+ OutputErrMsg << ErrMsg.getMessage();
+ });
+ Diags.Report(diag::err_invalid_feature_combination) << OutputErrMsg.str();
+ return false;
+ }
- return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
+ return TargetInfo::initFeatureMap(Features, Diags, CPU,
+ (*ParseResult)->toFeatureVector());
}
/// Return true if has this feature, need to sync with handleTargetFeatures.
diff --git a/llvm/include/llvm/Support/RISCVISAInfo.h b/llvm/include/llvm/Support/RISCVISAInfo.h
index 2dca0fe65d563..93aaa82f4c0b1 100644
--- a/llvm/include/llvm/Support/RISCVISAInfo.h
+++ b/llvm/include/llvm/Support/RISCVISAInfo.h
@@ -67,6 +67,7 @@ class RISCVISAInfo {
bool hasExtension(StringRef Ext) const;
std::string toString() const;
+ std::vector<std::string> toFeatureVector() const;
static bool isSupportedExtensionFeature(StringRef Ext);
static bool isSupportedExtension(StringRef Ext);
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp b/llvm/lib/Support/RISCVISAInfo.cpp
index 7aee909a0bdc6..d1d222d3c0eb0 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -881,3 +881,17 @@ std::string RISCVISAInfo::toString() const {
return Arch.str();
}
+
+std::vector<std::string> RISCVISAInfo::toFeatureVector() const {
+ std::vector<std::string> FeatureVector;
+ for (auto Ext : Exts) {
+ std::string ExtName = Ext.first;
+ if (ExtName == "i") // i is not recognized in clang -cc1
+ continue;
+ std::string Feature = isExperimentalExtension(ExtName)
+ ? "+experimental-" + ExtName
+ : "+" + ExtName;
+ FeatureVector.push_back(Feature);
+ }
+ return FeatureVector;
+}
More information about the cfe-commits
mailing list