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 @@ -695,11 +695,22 @@ return Error::success(); } +static const char *ImpliedExts_v[] = {"zvlsseg"}; +static const char *ImpliedExts_zfh[] = {"zfhmin"}; + +struct ImpliedExtsEntry { + StringLiteral Name; + ArrayRef Exts; +}; + +static constexpr ImpliedExtsEntry ImpliedExts[] = { + {"v", ImpliedExts_v}, + {"zfh", ImpliedExts_zfh}, +}; + void RISCVISAInfo::updateImplication() { bool HasE = Exts.count("e") == 1; bool HasI = Exts.count("i") == 1; - bool HasV = Exts.count("v") == 1; - bool HasZfh = Exts.count("zfh") == 1; // If not in e extension and i extension does not exist, i extension is // implied @@ -708,14 +719,16 @@ addExtension("i", Version->Major, Version->Minor); } - if (HasV) { - auto Version = findDefaultVersion("zvlsseg"); - addExtension("zvlsseg", Version->Major, Version->Minor); - } - - if (HasZfh) { - auto Version = findDefaultVersion("zfhmin"); - addExtension("zfhmin", Version->Major, Version->Minor); + for (auto &Ext : Exts) { + auto I = llvm::lower_bound(ImpliedExts, Ext.first, + [](const ImpliedExtsEntry &Entry, + StringRef Ext) { return Entry.Name < Ext; }); + if (I != std::end(ImpliedExts) && I->Name == Ext.first) { + for (auto &ImpliedExt : I->Exts) { + auto Version = findDefaultVersion(ImpliedExt); + addExtension(ImpliedExt, Version->Major, Version->Minor); + } + } } }