craig.topper created this revision. craig.topper added reviewers: jrtc27, kito-cheng, HsiangKai, khchen, arcbbb. Herald added subscribers: achieveartificialintelligence, StephenFan, vkmr, frasercrmck, evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, hiraditya. craig.topper requested review of this revision. Herald added a subscriber: MaskRay. Herald added projects: clang, LLVM.
RISCVISAInfo::toFeatures needs to allocate strings using ArgList::MakeArgString, but toFeatures lives in Support and MakeArgString lives in Option. toFeature only has one caller, so the simple fix is to have that caller pass a lamdba that wraps MakeArgString to break the dependency. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D112032 Files: clang/lib/Driver/ToolChains/Arch/RISCV.cpp llvm/include/llvm/Support/RISCVISAInfo.h llvm/lib/Support/RISCVISAInfo.cpp Index: llvm/lib/Support/RISCVISAInfo.cpp =================================================================== --- llvm/lib/Support/RISCVISAInfo.cpp +++ llvm/lib/Support/RISCVISAInfo.cpp @@ -11,7 +11,6 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" -#include "llvm/Option/ArgList.h" #include "llvm/Support/Errc.h" #include "llvm/Support/Error.h" #include "llvm/Support/raw_ostream.h" @@ -252,8 +251,9 @@ return LHS < RHS; } -void RISCVISAInfo::toFeatures(const llvm::opt::ArgList &Args, - std::vector<StringRef> &Features) const { +void RISCVISAInfo::toFeatures( + std::vector<StringRef> &Features, + std::function<StringRef(const Twine &)> StrAlloc) const { for (auto &Ext : Exts) { StringRef ExtName = Ext.first; @@ -268,9 +268,9 @@ Features.push_back("+experimental-zvlsseg"); Features.push_back("+experimental-zvamo"); } else if (isExperimentalExtension(ExtName)) { - Features.push_back(Args.MakeArgString("+experimental-" + ExtName)); + Features.push_back(StrAlloc("+experimental-" + ExtName)); } else { - Features.push_back(Args.MakeArgString("+" + ExtName)); + Features.push_back(StrAlloc("+" + ExtName)); } } } Index: llvm/include/llvm/Support/RISCVISAInfo.h =================================================================== --- llvm/include/llvm/Support/RISCVISAInfo.h +++ llvm/include/llvm/Support/RISCVISAInfo.h @@ -19,9 +19,6 @@ #include <vector> namespace llvm { -namespace opt { -class ArgList; -} struct RISCVExtensionInfo { std::string ExtName; unsigned MajorVersion; @@ -57,8 +54,8 @@ parseFeatures(unsigned XLen, const std::vector<std::string> &Features); /// Convert RISCV ISA info to a feature vector. - void toFeatures(const llvm::opt::ArgList &Args, - std::vector<StringRef> &Features) const; + void toFeatures(std::vector<StringRef> &Features, + std::function<StringRef(const Twine &)> StrAlloc) const; const OrderedExtensionMap &getExtensions() const { return Exts; }; Index: clang/lib/Driver/ToolChains/Arch/RISCV.cpp =================================================================== --- clang/lib/Driver/ToolChains/Arch/RISCV.cpp +++ clang/lib/Driver/ToolChains/Arch/RISCV.cpp @@ -41,7 +41,8 @@ return false; } - (*ISAInfo)->toFeatures(Args, Features); + (*ISAInfo)->toFeatures( + Features, [&Args](const Twine &Str) { return Args.MakeArgString(Str); }); return true; }
Index: llvm/lib/Support/RISCVISAInfo.cpp =================================================================== --- llvm/lib/Support/RISCVISAInfo.cpp +++ llvm/lib/Support/RISCVISAInfo.cpp @@ -11,7 +11,6 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" -#include "llvm/Option/ArgList.h" #include "llvm/Support/Errc.h" #include "llvm/Support/Error.h" #include "llvm/Support/raw_ostream.h" @@ -252,8 +251,9 @@ return LHS < RHS; } -void RISCVISAInfo::toFeatures(const llvm::opt::ArgList &Args, - std::vector<StringRef> &Features) const { +void RISCVISAInfo::toFeatures( + std::vector<StringRef> &Features, + std::function<StringRef(const Twine &)> StrAlloc) const { for (auto &Ext : Exts) { StringRef ExtName = Ext.first; @@ -268,9 +268,9 @@ Features.push_back("+experimental-zvlsseg"); Features.push_back("+experimental-zvamo"); } else if (isExperimentalExtension(ExtName)) { - Features.push_back(Args.MakeArgString("+experimental-" + ExtName)); + Features.push_back(StrAlloc("+experimental-" + ExtName)); } else { - Features.push_back(Args.MakeArgString("+" + ExtName)); + Features.push_back(StrAlloc("+" + ExtName)); } } } Index: llvm/include/llvm/Support/RISCVISAInfo.h =================================================================== --- llvm/include/llvm/Support/RISCVISAInfo.h +++ llvm/include/llvm/Support/RISCVISAInfo.h @@ -19,9 +19,6 @@ #include <vector> namespace llvm { -namespace opt { -class ArgList; -} struct RISCVExtensionInfo { std::string ExtName; unsigned MajorVersion; @@ -57,8 +54,8 @@ parseFeatures(unsigned XLen, const std::vector<std::string> &Features); /// Convert RISCV ISA info to a feature vector. - void toFeatures(const llvm::opt::ArgList &Args, - std::vector<StringRef> &Features) const; + void toFeatures(std::vector<StringRef> &Features, + std::function<StringRef(const Twine &)> StrAlloc) const; const OrderedExtensionMap &getExtensions() const { return Exts; }; Index: clang/lib/Driver/ToolChains/Arch/RISCV.cpp =================================================================== --- clang/lib/Driver/ToolChains/Arch/RISCV.cpp +++ clang/lib/Driver/ToolChains/Arch/RISCV.cpp @@ -41,7 +41,8 @@ return false; } - (*ISAInfo)->toFeatures(Args, Features); + (*ISAInfo)->toFeatures( + Features, [&Args](const Twine &Str) { return Args.MakeArgString(Str); }); return true; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits