diff --git a/llvm/include/llvm/Support/RISCVISAInfo.h b/llvm/include/llvm/Support/RISCVISAInfo.h --- a/llvm/include/llvm/Support/RISCVISAInfo.h +++ b/llvm/include/llvm/Support/RISCVISAInfo.h @@ -85,10 +85,12 @@ static bool isSupportedExtensionFeature(StringRef Ext); static bool isSupportedExtension(StringRef Ext); + 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 getTargetFeatureFromOneExt(StringRef Ext); private: RISCVISAInfo(unsigned XLen) diff --git a/llvm/lib/Support/RISCVISAInfo.cpp b/llvm/lib/Support/RISCVISAInfo.cpp --- a/llvm/lib/Support/RISCVISAInfo.cpp +++ b/llvm/lib/Support/RISCVISAInfo.cpp @@ -1192,3 +1192,34 @@ } llvm_unreachable("Invalid XLEN"); } + +bool RISCVISAInfo::isSupportedExtensionWithVersion(StringRef Ext) { + if (Ext.empty()) + return false; + + auto Pos = findFirstNonVersionCharacter(Ext) + 1; + StringRef Name(Ext.substr(0, Pos)); + StringRef Vers(Ext.substr(Pos)); + if (Vers.empty()) + return false; + + unsigned Major, Minor, ConsumeLength; + if (auto E = getExtensionVersion(Name, Vers, Major, Minor, ConsumeLength, + true, true)) { + consumeError(std::move(E)); + return false; + } + + return true; +} + +std::string RISCVISAInfo::getTargetFeatureFromOneExt(StringRef Ext) { + auto Pos = findFirstNonVersionCharacter(Ext) + 1; + StringRef Name(Ext.substr(0, Pos)); + + if (!isSupportedExtension(Name)) + return std::string(); + + return isExperimentalExtension(Name) ? "experimental-" + Name.str() + : Name.str(); +}