mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-11 13:44:28 +00:00
[TableGen] Make Record::getValueAsString and getValueAsListOfStrings return StringRefs instead of std::string
Internally both these methods just return the result of getValue on either a StringInit or a CodeInit object. In both cases this returns a StringRef pointing to a string allocated in the BumpPtrAllocator so its not going anywhere. So we can just pass that StringRef along. This is a fairly naive patch that targets just the build failures caused by this change. There's additional work that can be done to avoid creating std::string at call sites that still think getValueAsString returns a std::string. I'll try to clean those up in future patches. Differential Revision: https://reviews.llvm.org/D33710 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304325 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
923e8566d0
commit
c469be384c
@ -1491,7 +1491,7 @@ public:
|
||||
/// its value as a string, throwing an exception if the field does not exist
|
||||
/// or if the value is not a string.
|
||||
///
|
||||
std::string getValueAsString(StringRef FieldName) const;
|
||||
StringRef getValueAsString(StringRef FieldName) const;
|
||||
|
||||
/// This method looks up the specified field and returns
|
||||
/// its value as a BitsInit, throwing an exception if the field does not exist
|
||||
@ -1521,7 +1521,7 @@ public:
|
||||
/// returns its value as a vector of strings, throwing an exception if the
|
||||
/// field does not exist or if the value is not the right type.
|
||||
///
|
||||
std::vector<std::string> getValueAsListOfStrings(StringRef FieldName) const;
|
||||
std::vector<StringRef> getValueAsListOfStrings(StringRef FieldName) const;
|
||||
|
||||
/// This method looks up the specified field and returns its
|
||||
/// value as a Record, throwing an exception if the field does not exist or if
|
||||
|
@ -1708,7 +1708,7 @@ Init *Record::getValueInit(StringRef FieldName) const {
|
||||
return R->getValue();
|
||||
}
|
||||
|
||||
std::string Record::getValueAsString(StringRef FieldName) const {
|
||||
StringRef Record::getValueAsString(StringRef FieldName) const {
|
||||
const RecordVal *R = getValue(FieldName);
|
||||
if (!R || !R->getValue())
|
||||
PrintFatalError(getLoc(), "Record `" + getName() +
|
||||
@ -1787,10 +1787,10 @@ Record::getValueAsListOfInts(StringRef FieldName) const {
|
||||
return Ints;
|
||||
}
|
||||
|
||||
std::vector<std::string>
|
||||
std::vector<StringRef>
|
||||
Record::getValueAsListOfStrings(StringRef FieldName) const {
|
||||
ListInit *List = getValueAsListInit(FieldName);
|
||||
std::vector<std::string> Strings;
|
||||
std::vector<StringRef> Strings;
|
||||
for (Init *I : List->getValues()) {
|
||||
if (StringInit *SI = dyn_cast<StringInit>(I))
|
||||
Strings.push_back(SI->getValue());
|
||||
|
@ -2486,14 +2486,18 @@ static void emitMnemonicAliasVariant(raw_ostream &OS,const AsmMatcherInfo &Info,
|
||||
if (!MatchCode.empty())
|
||||
MatchCode += "else ";
|
||||
MatchCode += "if ((Features & " + FeatureMask + ") == "+FeatureMask+")\n";
|
||||
MatchCode += " Mnemonic = \"" +R->getValueAsString("ToMnemonic")+"\";\n";
|
||||
MatchCode += " Mnemonic = \"";
|
||||
MatchCode += R->getValueAsString("ToMnemonic");
|
||||
MatchCode += "\";\n";
|
||||
}
|
||||
|
||||
if (AliasWithNoPredicate != -1) {
|
||||
Record *R = ToVec[AliasWithNoPredicate];
|
||||
if (!MatchCode.empty())
|
||||
MatchCode += "else\n ";
|
||||
MatchCode += "Mnemonic = \"" + R->getValueAsString("ToMnemonic")+"\";\n";
|
||||
MatchCode += "Mnemonic = \"";
|
||||
MatchCode += R->getValueAsString("ToMnemonic");
|
||||
MatchCode += "\";\n";
|
||||
}
|
||||
|
||||
MatchCode += "return;";
|
||||
|
@ -523,7 +523,7 @@ emitRegisterNameString(raw_ostream &O, StringRef AltName,
|
||||
// If the register has an alternate name for this index, use it.
|
||||
// Otherwise, leave it empty as an error flag.
|
||||
if (Idx < e) {
|
||||
std::vector<std::string> AltNames =
|
||||
std::vector<StringRef> AltNames =
|
||||
Reg.TheDef->getValueAsListOfStrings("AltNames");
|
||||
if (AltNames.size() <= Idx)
|
||||
PrintFatalError(Reg.TheDef->getLoc(),
|
||||
|
@ -278,11 +278,11 @@ void CodeEmitterGen::run(raw_ostream &o) {
|
||||
if (R->getValueAsString("Namespace") == "TargetOpcode" ||
|
||||
R->getValueAsBit("isPseudo"))
|
||||
continue;
|
||||
const std::string &InstName = R->getValueAsString("Namespace") + "::"
|
||||
+ R->getName().str();
|
||||
std::string InstName =
|
||||
(R->getValueAsString("Namespace") + "::" + R->getName()).str();
|
||||
std::string Case = getInstructionCase(R, Target);
|
||||
|
||||
CaseMap[Case].push_back(InstName);
|
||||
CaseMap[Case].push_back(std::move(InstName));
|
||||
}
|
||||
|
||||
// Emit initial function code
|
||||
|
@ -893,7 +893,9 @@ std::string PatternToMatch::getPredicateCheck() const {
|
||||
for (Record *Pred : PredicateRecs) {
|
||||
if (!PredicateCheck.empty())
|
||||
PredicateCheck += " && ";
|
||||
PredicateCheck += "(" + Pred->getValueAsString("CondString") + ")";
|
||||
PredicateCheck += "(";
|
||||
PredicateCheck += Pred->getValueAsString("CondString");
|
||||
PredicateCheck += ")";
|
||||
}
|
||||
|
||||
return PredicateCheck.str();
|
||||
|
@ -118,7 +118,7 @@ static std::string explainPredicates(const TreePatternNode *N) {
|
||||
|
||||
std::string explainOperator(Record *Operator) {
|
||||
if (Operator->isSubClassOf("SDNode"))
|
||||
return " (" + Operator->getValueAsString("Opcode") + ")";
|
||||
return (" (" + Operator->getValueAsString("Opcode") + ")").str();
|
||||
|
||||
if (Operator->isSubClassOf("Intrinsic"))
|
||||
return (" (Operator is an Intrinsic, " + Operator->getName() + ")").str();
|
||||
|
@ -21,6 +21,8 @@ using namespace llvm;
|
||||
|
||||
// Ordering on Info. The logic should match with the consumer-side function in
|
||||
// llvm/Option/OptTable.h.
|
||||
// FIXME: Mmake this take StringRefs instead of null terminated strings to
|
||||
// simplify callers.
|
||||
static int StrCmpOptionName(const char *A, const char *B) {
|
||||
const char *X = A, *Y = B;
|
||||
char a = tolower(*A), b = tolower(*B);
|
||||
@ -53,22 +55,22 @@ static int CompareOptionRecords(Record *const *Av, Record *const *Bv) {
|
||||
|
||||
// Compare options by name, unless they are sentinels.
|
||||
if (!ASent)
|
||||
if (int Cmp = StrCmpOptionName(A->getValueAsString("Name").c_str(),
|
||||
B->getValueAsString("Name").c_str()))
|
||||
if (int Cmp = StrCmpOptionName(A->getValueAsString("Name").str().c_str(),
|
||||
B->getValueAsString("Name").str().c_str()))
|
||||
return Cmp;
|
||||
|
||||
if (!ASent) {
|
||||
std::vector<std::string> APrefixes = A->getValueAsListOfStrings("Prefixes");
|
||||
std::vector<std::string> BPrefixes = B->getValueAsListOfStrings("Prefixes");
|
||||
std::vector<StringRef> APrefixes = A->getValueAsListOfStrings("Prefixes");
|
||||
std::vector<StringRef> BPrefixes = B->getValueAsListOfStrings("Prefixes");
|
||||
|
||||
for (std::vector<std::string>::const_iterator APre = APrefixes.begin(),
|
||||
AEPre = APrefixes.end(),
|
||||
BPre = BPrefixes.begin(),
|
||||
BEPre = BPrefixes.end();
|
||||
APre != AEPre &&
|
||||
BPre != BEPre;
|
||||
++APre, ++BPre) {
|
||||
if (int Cmp = StrCmpOptionName(APre->c_str(), BPre->c_str()))
|
||||
for (std::vector<StringRef>::const_iterator APre = APrefixes.begin(),
|
||||
AEPre = APrefixes.end(),
|
||||
BPre = BPrefixes.begin(),
|
||||
BEPre = BPrefixes.end();
|
||||
APre != AEPre &&
|
||||
BPre != BEPre;
|
||||
++APre, ++BPre) {
|
||||
if (int Cmp = StrCmpOptionName(APre->str().c_str(), BPre->str().c_str()))
|
||||
return Cmp;
|
||||
}
|
||||
}
|
||||
@ -122,7 +124,7 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) {
|
||||
unsigned CurPrefix = 0;
|
||||
for (unsigned i = 0, e = Opts.size(); i != e; ++i) {
|
||||
const Record &R = *Opts[i];
|
||||
std::vector<std::string> prf = R.getValueAsListOfStrings("Prefixes");
|
||||
std::vector<StringRef> prf = R.getValueAsListOfStrings("Prefixes");
|
||||
PrefixKeyT prfkey(prf.begin(), prf.end());
|
||||
unsigned NewPrefix = CurPrefix + 1;
|
||||
if (Prefixes.insert(std::make_pair(prfkey, (Twine("prefix_") +
|
||||
@ -207,7 +209,7 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) {
|
||||
OS << "OPTION(";
|
||||
|
||||
// The option prefix;
|
||||
std::vector<std::string> prf = R.getValueAsListOfStrings("Prefixes");
|
||||
std::vector<StringRef> prf = R.getValueAsListOfStrings("Prefixes");
|
||||
OS << Prefixes[PrefixKeyT(prf.begin(), prf.end())] << ", ";
|
||||
|
||||
// The option string.
|
||||
@ -240,7 +242,7 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) {
|
||||
// would become "foo\0bar\0". Note that the compiler adds an implicit
|
||||
// terminating \0 at the end.
|
||||
OS << ", ";
|
||||
std::vector<std::string> AliasArgs = R.getValueAsListOfStrings("AliasArgs");
|
||||
std::vector<StringRef> AliasArgs = R.getValueAsListOfStrings("AliasArgs");
|
||||
if (AliasArgs.size() == 0) {
|
||||
OS << "nullptr";
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user