[RISCV] Use a lambda to avoid having the Support library depend on Option library.

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.

Differential Revision: https://reviews.llvm.org/D112032
This commit is contained in:
Craig Topper 2021-10-18 13:26:35 -07:00
parent 431a5d8411
commit 1053e0b27c
3 changed files with 9 additions and 11 deletions

View File

@ -41,7 +41,8 @@ static bool getArchFeatures(const Driver &D, StringRef Arch,
return false;
}
(*ISAInfo)->toFeatures(Args, Features);
(*ISAInfo)->toFeatures(
Features, [&Args](const Twine &Str) { return Args.MakeArgString(Str); });
return true;
}

View File

@ -19,9 +19,6 @@
#include <vector>
namespace llvm {
namespace opt {
class ArgList;
}
struct RISCVExtensionInfo {
std::string ExtName;
unsigned MajorVersion;
@ -57,8 +54,8 @@ public:
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; };

View File

@ -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 @@ bool RISCVISAInfo::compareExtension(const std::string &LHS,
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 @@ void RISCVISAInfo::toFeatures(const llvm::opt::ArgList &Args,
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));
}
}
}