-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[RISCV] Don't expose any constructors of RISCVISAInfo publicly. #98249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
lld was using RISCVISAInfo(unsigned XLen, RISCVISAUtils::OrderedExtensionMap &Exts). This required a call to RISCVISAInfo::postProcessAndChecking to validate the RISCVISAInfo that was created. This exposes too much about RISCVISAInfo to lld. Replace with a new RISCVISAInfo::createFromExtMap that is responsible for creating the object and calling postProcessAndChecking.
@llvm/pr-subscribers-backend-risc-v @llvm/pr-subscribers-lld Author: Craig Topper (topperc) Changeslld was using RISCVISAInfo(unsigned XLen, RISCVISAUtils::OrderedExtensionMap &Exts). This required a call to RISCVISAInfo::postProcessAndChecking to validate the RISCVISAInfo that was created. This exposes too much about RISCVISAInfo to lld. Replace with a new RISCVISAInfo::createFromExtMap that is responsible for creating the object and calling postProcessAndChecking. Full diff: https://github.com/llvm/llvm-project/pull/98249.diff 3 Files Affected:
diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index 07a1b63be8051..faacc8f834be7 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -1251,9 +1251,8 @@ mergeAttributesSection(const SmallVector<InputSectionBase *, 0> §ions) {
}
}
- if (hasArch) {
- if (auto result = RISCVISAInfo::postProcessAndChecking(
- std::make_unique<RISCVISAInfo>(xlen, exts))) {
+ if (hasArch && xlen != 0) {
+ if (auto result = RISCVISAInfo::createFromExtMap(xlen, exts)) {
merged.strAttr.try_emplace(RISCVAttrs::ARCH,
saver().save((*result)->toString()));
} else {
diff --git a/llvm/include/llvm/TargetParser/RISCVISAInfo.h b/llvm/include/llvm/TargetParser/RISCVISAInfo.h
index ba2965600decd..5d3f3e113e96d 100644
--- a/llvm/include/llvm/TargetParser/RISCVISAInfo.h
+++ b/llvm/include/llvm/TargetParser/RISCVISAInfo.h
@@ -26,9 +26,6 @@ class RISCVISAInfo {
RISCVISAInfo(const RISCVISAInfo &) = delete;
RISCVISAInfo &operator=(const RISCVISAInfo &) = delete;
- RISCVISAInfo(unsigned XLen, RISCVISAUtils::OrderedExtensionMap &Exts)
- : XLen(XLen), FLen(0), MinVLen(0), MaxELen(0), MaxELenFp(0), Exts(Exts) {}
-
/// Parse RISC-V ISA info from arch string.
/// If IgnoreUnknown is set, any unrecognised extension names or
/// extensions with unrecognised versions will be silently dropped, except
@@ -48,6 +45,10 @@ class RISCVISAInfo {
static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
parseFeatures(unsigned XLen, const std::vector<std::string> &Features);
+ static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
+ createFromExtMap(unsigned XLen,
+ const RISCVISAUtils::OrderedExtensionMap &Exts);
+
/// Convert RISC-V ISA info to a feature vector.
std::vector<std::string> toFeatures(bool AddAllExtensions = false,
bool IgnoreUnknown = true) const;
@@ -72,8 +73,6 @@ class RISCVISAInfo {
static bool isSupportedExtensionWithVersion(StringRef Ext);
static bool isSupportedExtension(StringRef Ext, unsigned MajorVersion,
unsigned MinorVersion);
- static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
- postProcessAndChecking(std::unique_ptr<RISCVISAInfo> &&ISAInfo);
static std::string getTargetFeatureForExtension(StringRef Ext);
private:
@@ -93,6 +92,9 @@ class RISCVISAInfo {
/// Update FLen, MinVLen, MaxELen, and MaxELenFp.
void updateImpliedLengths();
+
+ static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
+ postProcessAndChecking(std::unique_ptr<RISCVISAInfo> &&ISAInfo);
};
} // namespace llvm
diff --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp b/llvm/lib/TargetParser/RISCVISAInfo.cpp
index 1d077326e4cf2..0229b5a140f91 100644
--- a/llvm/lib/TargetParser/RISCVISAInfo.cpp
+++ b/llvm/lib/TargetParser/RISCVISAInfo.cpp
@@ -395,6 +395,17 @@ static Error getExtensionVersion(StringRef Ext, StringRef In, unsigned &Major,
return getError(Error);
}
+llvm::Expected<std::unique_ptr<RISCVISAInfo>>
+RISCVISAInfo::createFromExtMap(unsigned XLen,
+ const RISCVISAUtils::OrderedExtensionMap &Exts) {
+ assert(XLen == 32 || XLen == 64);
+ std::unique_ptr<RISCVISAInfo> ISAInfo(new RISCVISAInfo(XLen));
+
+ ISAInfo->Exts = Exts;
+
+ return RISCVISAInfo::postProcessAndChecking(std::move(ISAInfo));
+}
+
llvm::Expected<std::unique_ptr<RISCVISAInfo>>
RISCVISAInfo::parseFeatures(unsigned XLen,
const std::vector<std::string> &Features) {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
if (hasArch) { | ||
if (auto result = RISCVISAInfo::postProcessAndChecking( | ||
std::make_unique<RISCVISAInfo>(xlen, exts))) { | ||
if (hasArch && xlen != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note, I had to add this xlen
check since the xlen
is 0 if we never successfully parsed an ISA string from any object. In that case we would have generated an error earlier so the linking would fail. Maybe it would be to have a flag that indicates we found an error earlier?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be useful to errorOrWarn
after mergeArch
call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The errorOrWarn is already inside mergeArch
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/30/builds/1615 Here is the relevant piece of the build log for the reference:
|
…#98249) lld was using RISCVISAInfo(unsigned XLen, RISCVISAUtils::OrderedExtensionMap &Exts). This required a call to RISCVISAInfo::postProcessAndChecking to validate the RISCVISAInfo that was created. This exposes too much about RISCVISAInfo to lld. Replace with a new RISCVISAInfo::createFromExtMap that is responsible for creating the object and calling postProcessAndChecking.
lld was using RISCVISAInfo(unsigned XLen, RISCVISAUtils::OrderedExtensionMap &Exts). This required a call to RISCVISAInfo::postProcessAndChecking to validate the RISCVISAInfo that was created. This exposes too much about RISCVISAInfo to lld.
Replace with a new RISCVISAInfo::createFromExtMap that is responsible for creating the object and calling postProcessAndChecking.