diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp index 07a1b63be80510..faacc8f834be72 100644 --- a/lld/ELF/Arch/RISCV.cpp +++ b/lld/ELF/Arch/RISCV.cpp @@ -1251,9 +1251,8 @@ mergeAttributesSection(const SmallVector §ions) { } } - if (hasArch) { - if (auto result = RISCVISAInfo::postProcessAndChecking( - std::make_unique(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 ba2965600decd7..5d3f3e113e96d3 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> parseFeatures(unsigned XLen, const std::vector &Features); + static llvm::Expected> + createFromExtMap(unsigned XLen, + const RISCVISAUtils::OrderedExtensionMap &Exts); + /// Convert RISC-V ISA info to a feature vector. std::vector 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> - postProcessAndChecking(std::unique_ptr &&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> + postProcessAndChecking(std::unique_ptr &&ISAInfo); }; } // namespace llvm diff --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp b/llvm/lib/TargetParser/RISCVISAInfo.cpp index 1d077326e4cf23..0229b5a140f91b 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> +RISCVISAInfo::createFromExtMap(unsigned XLen, + const RISCVISAUtils::OrderedExtensionMap &Exts) { + assert(XLen == 32 || XLen == 64); + std::unique_ptr ISAInfo(new RISCVISAInfo(XLen)); + + ISAInfo->Exts = Exts; + + return RISCVISAInfo::postProcessAndChecking(std::move(ISAInfo)); +} + llvm::Expected> RISCVISAInfo::parseFeatures(unsigned XLen, const std::vector &Features) {