Skip to content

Commit 6647011

Browse files
authored
[RISCV] Don't expose any constructors of RISCVISAInfo publicly. (#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.
1 parent 7b96d13 commit 6647011

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

lld/ELF/Arch/RISCV.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,9 +1251,8 @@ mergeAttributesSection(const SmallVector<InputSectionBase *, 0> &sections) {
12511251
}
12521252
}
12531253

1254-
if (hasArch) {
1255-
if (auto result = RISCVISAInfo::postProcessAndChecking(
1256-
std::make_unique<RISCVISAInfo>(xlen, exts))) {
1254+
if (hasArch && xlen != 0) {
1255+
if (auto result = RISCVISAInfo::createFromExtMap(xlen, exts)) {
12571256
merged.strAttr.try_emplace(RISCVAttrs::ARCH,
12581257
saver().save((*result)->toString()));
12591258
} else {

llvm/include/llvm/TargetParser/RISCVISAInfo.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ class RISCVISAInfo {
2626
RISCVISAInfo(const RISCVISAInfo &) = delete;
2727
RISCVISAInfo &operator=(const RISCVISAInfo &) = delete;
2828

29-
RISCVISAInfo(unsigned XLen, RISCVISAUtils::OrderedExtensionMap &Exts)
30-
: XLen(XLen), FLen(0), MinVLen(0), MaxELen(0), MaxELenFp(0), Exts(Exts) {}
31-
3229
/// Parse RISC-V ISA info from arch string.
3330
/// If IgnoreUnknown is set, any unrecognised extension names or
3431
/// extensions with unrecognised versions will be silently dropped, except
@@ -48,6 +45,10 @@ class RISCVISAInfo {
4845
static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
4946
parseFeatures(unsigned XLen, const std::vector<std::string> &Features);
5047

48+
static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
49+
createFromExtMap(unsigned XLen,
50+
const RISCVISAUtils::OrderedExtensionMap &Exts);
51+
5152
/// Convert RISC-V ISA info to a feature vector.
5253
std::vector<std::string> toFeatures(bool AddAllExtensions = false,
5354
bool IgnoreUnknown = true) const;
@@ -72,8 +73,6 @@ class RISCVISAInfo {
7273
static bool isSupportedExtensionWithVersion(StringRef Ext);
7374
static bool isSupportedExtension(StringRef Ext, unsigned MajorVersion,
7475
unsigned MinorVersion);
75-
static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
76-
postProcessAndChecking(std::unique_ptr<RISCVISAInfo> &&ISAInfo);
7776
static std::string getTargetFeatureForExtension(StringRef Ext);
7877

7978
private:
@@ -93,6 +92,9 @@ class RISCVISAInfo {
9392

9493
/// Update FLen, MinVLen, MaxELen, and MaxELenFp.
9594
void updateImpliedLengths();
95+
96+
static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
97+
postProcessAndChecking(std::unique_ptr<RISCVISAInfo> &&ISAInfo);
9698
};
9799

98100
} // namespace llvm

llvm/lib/TargetParser/RISCVISAInfo.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,17 @@ static Error getExtensionVersion(StringRef Ext, StringRef In, unsigned &Major,
395395
return getError(Error);
396396
}
397397

398+
llvm::Expected<std::unique_ptr<RISCVISAInfo>>
399+
RISCVISAInfo::createFromExtMap(unsigned XLen,
400+
const RISCVISAUtils::OrderedExtensionMap &Exts) {
401+
assert(XLen == 32 || XLen == 64);
402+
std::unique_ptr<RISCVISAInfo> ISAInfo(new RISCVISAInfo(XLen));
403+
404+
ISAInfo->Exts = Exts;
405+
406+
return RISCVISAInfo::postProcessAndChecking(std::move(ISAInfo));
407+
}
408+
398409
llvm::Expected<std::unique_ptr<RISCVISAInfo>>
399410
RISCVISAInfo::parseFeatures(unsigned XLen,
400411
const std::vector<std::string> &Features) {

0 commit comments

Comments
 (0)