[llvm] r288644 - TableGen: Use StringInit instead of std::string for DagInit arg names
Matthias Braun via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 4 22:00:46 PST 2016
Author: matze
Date: Mon Dec 5 00:00:46 2016
New Revision: 288644
URL: http://llvm.org/viewvc/llvm-project?rev=288644&view=rev
Log:
TableGen: Use StringInit instead of std::string for DagInit arg names
Modified:
llvm/trunk/include/llvm/TableGen/Record.h
llvm/trunk/lib/TableGen/Record.cpp
llvm/trunk/lib/TableGen/TGParser.cpp
llvm/trunk/lib/TableGen/TGParser.h
llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp
llvm/trunk/utils/TableGen/CodeGenInstruction.cpp
llvm/trunk/utils/TableGen/FixedLenDecoderEmitter.cpp
llvm/trunk/utils/TableGen/PseudoLoweringEmitter.cpp
Modified: llvm/trunk/include/llvm/TableGen/Record.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/TableGen/Record.h?rev=288644&r1=288643&r2=288644&view=diff
==============================================================================
--- llvm/trunk/include/llvm/TableGen/Record.h (original)
+++ llvm/trunk/include/llvm/TableGen/Record.h Mon Dec 5 00:00:46 2016
@@ -1148,10 +1148,10 @@ class DagInit : public TypedInit, public
Init *Val;
StringInit *ValName;
std::vector<Init*> Args;
- std::vector<std::string> ArgNames;
+ std::vector<StringInit*> ArgNames;
DagInit(Init *V, StringInit *VN, ArrayRef<Init *> ArgRange,
- ArrayRef<std::string> NameRange)
+ ArrayRef<StringInit *> NameRange)
: TypedInit(IK_DagInit, DagRecTy::get()), Val(V), ValName(VN),
Args(ArgRange.begin(), ArgRange.end()),
ArgNames(NameRange.begin(), NameRange.end()) {}
@@ -1165,9 +1165,9 @@ public:
}
static DagInit *get(Init *V, StringInit *VN, ArrayRef<Init *> ArgRange,
- ArrayRef<std::string> NameRange);
+ ArrayRef<StringInit *> NameRange);
static DagInit *get(Init *V, StringInit *VN,
- const std::vector<std::pair<Init*, std::string>> &args);
+ const std::vector<std::pair<Init*, StringInit*>> &args);
void Profile(FoldingSetNodeID &ID) const;
@@ -1185,17 +1185,21 @@ public:
assert(Num < Args.size() && "Arg number out of range!");
return Args[Num];
}
- StringRef getArgName(unsigned Num) const {
+ StringInit *getArgName(unsigned Num) const {
assert(Num < ArgNames.size() && "Arg number out of range!");
return ArgNames[Num];
}
+ StringRef getArgNameStr(unsigned Num) const {
+ StringInit *Init = getArgName(Num);
+ return Init ? Init->getValue() : StringRef();
+ }
Init *resolveReferences(Record &R, const RecordVal *RV) const override;
std::string getAsString() const override;
typedef std::vector<Init*>::const_iterator const_arg_iterator;
- typedef std::vector<std::string>::const_iterator const_name_iterator;
+ typedef std::vector<StringInit*>::const_iterator const_name_iterator;
inline const_arg_iterator arg_begin() const { return Args.begin(); }
inline const_arg_iterator arg_end () const { return Args.end(); }
Modified: llvm/trunk/lib/TableGen/Record.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/Record.cpp?rev=288644&r1=288643&r2=288644&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/Record.cpp (original)
+++ llvm/trunk/lib/TableGen/Record.cpp Mon Dec 5 00:00:46 2016
@@ -829,7 +829,7 @@ Init *BinOpInit::Fold(Record *CurRec, Mu
if (!LOp || !ROp || LOp->getDef() != ROp->getDef())
PrintFatalError("Concated Dag operators do not match!");
std::vector<Init*> Args;
- std::vector<std::string> ArgNames;
+ std::vector<StringInit*> ArgNames;
for (unsigned i = 0, e = LHSs->getNumArgs(); i != e; ++i) {
Args.push_back(LHSs->getArg(i));
ArgNames.push_back(LHSs->getArgName(i));
@@ -1021,10 +1021,10 @@ static Init *ForeachHelper(Init *LHS, In
Type, CurRec, CurMultiClass))
Val = Result;
- std::vector<std::pair<Init *, std::string> > args;
+ std::vector<std::pair<Init *, StringInit*> > args;
for (unsigned int i = 0; i < MHSd->getNumArgs(); ++i) {
Init *Arg = MHSd->getArg(i);
- std::string ArgName = MHSd->getArgName(i);
+ StringInit *ArgName = MHSd->getArgName(i);
// Process args
if (Init *Result = EvaluateOperation(RHSo, LHS, Arg, Type,
@@ -1525,23 +1525,23 @@ Init *FieldInit::resolveReferences(Recor
static void ProfileDagInit(FoldingSetNodeID &ID, Init *V, StringInit *VN,
ArrayRef<Init *> ArgRange,
- ArrayRef<std::string> NameRange) {
+ ArrayRef<StringInit *> NameRange) {
ID.AddPointer(V);
ID.AddPointer(VN);
- ArrayRef<Init *>::iterator Arg = ArgRange.begin();
- ArrayRef<std::string>::iterator Name = NameRange.begin();
+ ArrayRef<Init *>::iterator Arg = ArgRange.begin();
+ ArrayRef<StringInit *>::iterator Name = NameRange.begin();
while (Arg != ArgRange.end()) {
assert(Name != NameRange.end() && "Arg name underflow!");
ID.AddPointer(*Arg++);
- ID.AddString(*Name++);
+ ID.AddPointer(*Name++);
}
assert(Name == NameRange.end() && "Arg name overflow!");
}
DagInit *
DagInit::get(Init *V, StringInit *VN, ArrayRef<Init *> ArgRange,
- ArrayRef<std::string> NameRange) {
+ ArrayRef<StringInit *> NameRange) {
static FoldingSet<DagInit> ThePool;
static std::vector<DagInit*> TheActualPool;
@@ -1560,9 +1560,9 @@ DagInit::get(Init *V, StringInit *VN, Ar
DagInit *
DagInit::get(Init *V, StringInit *VN,
- const std::vector<std::pair<Init*, std::string> > &args) {
+ const std::vector<std::pair<Init*, StringInit*> > &args) {
std::vector<Init *> Args;
- std::vector<std::string> Names;
+ std::vector<StringInit *> Names;
for (const auto &Arg : args) {
Args.push_back(Arg.first);
@@ -1602,10 +1602,10 @@ std::string DagInit::getAsString() const
Result += ":" + ValName->getAsUnquotedString();
if (!Args.empty()) {
Result += " " + Args[0]->getAsString();
- if (!ArgNames[0].empty()) Result += ":$" + ArgNames[0];
+ if (ArgNames[0]) Result += ":$" + ArgNames[0]->getAsUnquotedString();
for (unsigned i = 1, e = Args.size(); i != e; ++i) {
Result += ", " + Args[i]->getAsString();
- if (!ArgNames[i].empty()) Result += ":$" + ArgNames[i];
+ if (ArgNames[i]) Result += ":$" + ArgNames[i]->getAsUnquotedString();
}
}
return Result + ")";
Modified: llvm/trunk/lib/TableGen/TGParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/TGParser.cpp?rev=288644&r1=288643&r2=288644&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/TGParser.cpp (original)
+++ llvm/trunk/lib/TableGen/TGParser.cpp Mon Dec 5 00:00:46 2016
@@ -1428,7 +1428,7 @@ Init *TGParser::ParseSimpleValue(Record
Lex.Lex(); // eat the VarName.
}
- std::vector<std::pair<llvm::Init*, std::string> > DagArgs;
+ std::vector<std::pair<llvm::Init*, StringInit*> > DagArgs;
if (Lex.getCode() != tgtok::r_paren) {
DagArgs = ParseDagArgList(CurRec);
if (DagArgs.empty()) return nullptr;
@@ -1603,30 +1603,31 @@ Init *TGParser::ParseValue(Record *CurRe
/// DagArg ::= VARNAME
/// DagArgList ::= DagArg
/// DagArgList ::= DagArgList ',' DagArg
-std::vector<std::pair<llvm::Init*, std::string> >
+std::vector<std::pair<llvm::Init*, StringInit*> >
TGParser::ParseDagArgList(Record *CurRec) {
- std::vector<std::pair<llvm::Init*, std::string> > Result;
+ std::vector<std::pair<llvm::Init*, StringInit*> > Result;
while (true) {
// DagArg ::= VARNAME
if (Lex.getCode() == tgtok::VarName) {
// A missing value is treated like '?'.
- Result.emplace_back(UnsetInit::get(), Lex.getCurStrVal());
+ StringInit *VarName = StringInit::get(Lex.getCurStrVal());
+ Result.emplace_back(UnsetInit::get(), VarName);
Lex.Lex();
} else {
// DagArg ::= Value (':' VARNAME)?
Init *Val = ParseValue(CurRec);
if (!Val)
- return std::vector<std::pair<llvm::Init*, std::string> >();
+ return std::vector<std::pair<llvm::Init*, StringInit*> >();
// If the variable name is present, add it.
- std::string VarName;
+ StringInit *VarName = nullptr;
if (Lex.getCode() == tgtok::colon) {
if (Lex.Lex() != tgtok::VarName) { // eat the ':'
TokError("expected variable name in dag literal");
- return std::vector<std::pair<llvm::Init*, std::string> >();
+ return std::vector<std::pair<llvm::Init*, StringInit*> >();
}
- VarName = Lex.getCurStrVal();
+ VarName = StringInit::get(Lex.getCurStrVal());
Lex.Lex(); // eat the VarName.
}
Modified: llvm/trunk/lib/TableGen/TGParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/TGParser.h?rev=288644&r1=288643&r2=288644&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/TGParser.h (original)
+++ llvm/trunk/lib/TableGen/TGParser.h Mon Dec 5 00:00:46 2016
@@ -175,7 +175,7 @@ private: // Parser methods.
IDParseMode Mode = ParseValueMode);
std::vector<Init*> ParseValueList(Record *CurRec, Record *ArgsRec = nullptr,
RecTy *EltTy = nullptr);
- std::vector<std::pair<llvm::Init*, std::string> > ParseDagArgList(Record *);
+ std::vector<std::pair<llvm::Init*, StringInit*> > ParseDagArgList(Record *);
bool ParseOptionalRangeList(std::vector<unsigned> &Ranges);
bool ParseOptionalBitList(std::vector<unsigned> &Ranges);
std::vector<unsigned> ParseRangeList();
Modified: llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp?rev=288644&r1=288643&r2=288644&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp (original)
+++ llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp Mon Dec 5 00:00:46 2016
@@ -2073,7 +2073,7 @@ TreePatternNode *TreePattern::ParseTreeP
if (R->isSubClassOf("SDNode") || R->isSubClassOf("PatFrag"))
return ParseTreePattern(
DagInit::get(DI, nullptr,
- std::vector<std::pair<Init*, std::string> >()),
+ std::vector<std::pair<Init*, StringInit*> >()),
OpName);
// Input argument?
@@ -2127,7 +2127,8 @@ TreePatternNode *TreePattern::ParseTreeP
if (Dag->getNumArgs() != 1)
error("Type cast only takes one operand!");
- TreePatternNode *New = ParseTreePattern(Dag->getArg(0), Dag->getArgName(0));
+ TreePatternNode *New = ParseTreePattern(Dag->getArg(0),
+ Dag->getArgNameStr(0));
// Apply the type cast.
assert(New->getNumTypes() == 1 && "FIXME: Unhandled");
@@ -2178,7 +2179,7 @@ TreePatternNode *TreePattern::ParseTreeP
// Parse all the operands.
for (unsigned i = 0, e = Dag->getNumArgs(); i != e; ++i)
- Children.push_back(ParseTreePattern(Dag->getArg(i), Dag->getArgName(i)));
+ Children.push_back(ParseTreePattern(Dag->getArg(i), Dag->getArgNameStr(i)));
// If the operator is an intrinsic, then this is just syntactic sugar for for
// (intrinsic_* <number>, ..children..). Pick the right intrinsic node, and
@@ -2484,13 +2485,14 @@ void CodeGenDAGPatterns::ParsePatternFra
if (!isa<DefInit>(OpsList->getArg(j)) ||
cast<DefInit>(OpsList->getArg(j))->getDef()->getName() != "node")
P->error("Operands list should all be 'node' values.");
- if (OpsList->getArgName(j).empty())
+ if (!OpsList->getArgName(j))
P->error("Operands list should have names for each operand!");
- if (!OperandsSet.count(OpsList->getArgName(j)))
- P->error("'" + OpsList->getArgName(j) +
+ StringRef ArgNameStr = OpsList->getArgNameStr(j);
+ if (!OperandsSet.count(ArgNameStr))
+ P->error("'" + ArgNameStr +
"' does not occur in pattern or was multiply specified!");
- OperandsSet.erase(OpsList->getArgName(j));
- Args.push_back(OpsList->getArgName(j));
+ OperandsSet.erase(ArgNameStr);
+ Args.push_back(ArgNameStr);
}
if (!OperandsSet.empty())
@@ -2542,7 +2544,7 @@ void CodeGenDAGPatterns::ParseDefaultOpe
// Clone the DefaultInfo dag node, changing the operator from 'ops' to
// SomeSDnode so that we can parse this.
- std::vector<std::pair<Init*, std::string> > Ops;
+ std::vector<std::pair<Init*, StringInit*> > Ops;
for (unsigned op = 0, e = DefaultInfo->getNumArgs(); op != e; ++op)
Ops.push_back(std::make_pair(DefaultInfo->getArg(op),
DefaultInfo->getArgName(op)));
Modified: llvm/trunk/utils/TableGen/CodeGenInstruction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenInstruction.cpp?rev=288644&r1=288643&r2=288644&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenInstruction.cpp (original)
+++ llvm/trunk/utils/TableGen/CodeGenInstruction.cpp Mon Dec 5 00:00:46 2016
@@ -53,13 +53,13 @@ CGIOperandList::CGIOperandList(Record *R
OperandList.reserve(e);
for (unsigned i = 0; i != e; ++i){
Init *ArgInit;
- std::string ArgName;
+ StringRef ArgName;
if (i < NumDefs) {
ArgInit = OutDI->getArg(i);
- ArgName = OutDI->getArgName(i);
+ ArgName = OutDI->getArgNameStr(i);
} else {
ArgInit = InDI->getArg(i-NumDefs);
- ArgName = InDI->getArgName(i-NumDefs);
+ ArgName = InDI->getArgNameStr(i-NumDefs);
}
DefInit *Arg = dyn_cast<DefInit>(ArgInit);
@@ -193,7 +193,7 @@ CGIOperandList::ParseOperandName(const s
// Find the operand with the right name.
for (unsigned i = 0, e = MIOpInfo->getNumArgs(); i != e; ++i)
- if (MIOpInfo->getArgName(i) == SubOpName)
+ if (MIOpInfo->getArgNameStr(i) == SubOpName)
return std::make_pair(OpIdx, i);
// Otherwise, didn't find it!
@@ -449,10 +449,10 @@ bool CodeGenInstAlias::tryAliasOpMatch(D
if (ADI && ADI->getDef() == InstOpRec) {
// If the operand is a record, it must have a name, and the record type
// must match up with the instruction's argument type.
- if (Result->getArgName(AliasOpNo).empty())
+ if (!Result->getArgName(AliasOpNo))
PrintFatalError(Loc, "result argument #" + Twine(AliasOpNo) +
" must have a name!");
- ResOp = ResultOperand(Result->getArgName(AliasOpNo), ResultRecord);
+ ResOp = ResultOperand(Result->getArgNameStr(AliasOpNo), ResultRecord);
return true;
}
@@ -470,7 +470,7 @@ bool CodeGenInstAlias::tryAliasOpMatch(D
if (!T.getRegisterClass(InstOpRec)
.hasSubClass(&T.getRegisterClass(ADI->getDef())))
return false;
- ResOp = ResultOperand(Result->getArgName(AliasOpNo), ResultRecord);
+ ResOp = ResultOperand(Result->getArgNameStr(AliasOpNo), ResultRecord);
return true;
}
@@ -492,7 +492,7 @@ bool CodeGenInstAlias::tryAliasOpMatch(D
" is not a member of the " + InstOpRec->getName() +
" register class!");
- if (!Result->getArgName(AliasOpNo).empty())
+ if (Result->getArgName(AliasOpNo))
PrintFatalError(Loc, "result fixed register argument must "
"not have a name!");
@@ -521,7 +521,7 @@ bool CodeGenInstAlias::tryAliasOpMatch(D
if (hasSubOps || !InstOpRec->isSubClassOf("Operand"))
return false;
// Integer arguments can't have names.
- if (!Result->getArgName(AliasOpNo).empty())
+ if (Result->getArgName(AliasOpNo))
PrintFatalError(Loc, "result argument #" + Twine(AliasOpNo) +
" must not have a name!");
ResOp = ResultOperand(II->getValue());
@@ -552,7 +552,7 @@ bool CodeGenInstAlias::tryAliasOpMatch(D
// MIOperandInfo perhaps?
if (InstOpRec->getValueInit("Type") != ADI->getDef()->getValueInit("Type"))
return false;
- ResOp = ResultOperand(Result->getArgName(AliasOpNo), ADI->getDef());
+ ResOp = ResultOperand(Result->getArgNameStr(AliasOpNo), ADI->getDef());
return true;
}
@@ -597,14 +597,14 @@ CodeGenInstAlias::CodeGenInstAlias(Recor
StringMap<Record*> NameClass;
for (unsigned i = 0, e = Result->getNumArgs(); i != e; ++i) {
DefInit *ADI = dyn_cast<DefInit>(Result->getArg(i));
- if (!ADI || Result->getArgName(i).empty())
+ if (!ADI || !Result->getArgName(i))
continue;
// Verify we don't have something like: (someinst GR16:$foo, GR32:$foo)
// $foo can exist multiple times in the result list, but it must have the
// same type.
- Record *&Entry = NameClass[Result->getArgName(i)];
+ Record *&Entry = NameClass[Result->getArgNameStr(i)];
if (Entry && Entry != ADI->getDef())
- PrintFatalError(R->getLoc(), "result value $" + Result->getArgName(i) +
+ PrintFatalError(R->getLoc(), "result value $" + Result->getArgNameStr(i) +
" is both " + Entry->getName() + " and " +
ADI->getDef()->getName() + "!");
Entry = ADI->getDef();
@@ -647,9 +647,9 @@ CodeGenInstAlias::CodeGenInstAlias(Recor
// Take care to instantiate each of the suboperands with the correct
// nomenclature: $foo.bar
- ResultOperands.emplace_back(Result->getArgName(AliasOpNo).str()
- + "." + MIOI->getArgName(SubOp).str(),
- SubRec);
+ ResultOperands.emplace_back(
+ Result->getArgName(AliasOpNo)->getAsUnquotedString() + "." +
+ MIOI->getArgName(SubOp)->getAsUnquotedString(), SubRec);
ResultInstOperandIndex.push_back(std::make_pair(i, SubOp));
}
++AliasOpNo;
Modified: llvm/trunk/utils/TableGen/FixedLenDecoderEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/FixedLenDecoderEmitter.cpp?rev=288644&r1=288643&r2=288644&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/FixedLenDecoderEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/FixedLenDecoderEmitter.cpp Mon Dec 5 00:00:46 2016
@@ -1759,13 +1759,15 @@ static bool populateInstruction(CodeGenT
// Gather the outputs/inputs of the instruction, so we can find their
// positions in the encoding. This assumes for now that they appear in the
// MCInst in the order that they're listed.
- std::vector<std::pair<Init*, std::string>> InOutOperands;
+ std::vector<std::pair<Init*, StringRef>> InOutOperands;
DagInit *Out = Def.getValueAsDag("OutOperandList");
DagInit *In = Def.getValueAsDag("InOperandList");
for (unsigned i = 0; i < Out->getNumArgs(); ++i)
- InOutOperands.push_back(std::make_pair(Out->getArg(i), Out->getArgName(i)));
+ InOutOperands.push_back(std::make_pair(Out->getArg(i),
+ Out->getArgNameStr(i)));
for (unsigned i = 0; i < In->getNumArgs(); ++i)
- InOutOperands.push_back(std::make_pair(In->getArg(i), In->getArgName(i)));
+ InOutOperands.push_back(std::make_pair(In->getArg(i),
+ In->getArgNameStr(i)));
// Search for tied operands, so that we can correctly instantiate
// operands that are not explicitly represented in the encoding.
Modified: llvm/trunk/utils/TableGen/PseudoLoweringEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/PseudoLoweringEmitter.cpp?rev=288644&r1=288643&r2=288644&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/PseudoLoweringEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/PseudoLoweringEmitter.cpp Mon Dec 5 00:00:46 2016
@@ -177,10 +177,10 @@ void PseudoLoweringEmitter::evaluateExpa
if (OperandMap[Insn.Operands[i].MIOperandNo].Kind != OpData::Operand)
continue;
StringMap<unsigned>::iterator SourceOp =
- SourceOperands.find(Dag->getArgName(i));
+ SourceOperands.find(Dag->getArgNameStr(i));
if (SourceOp == SourceOperands.end())
PrintFatalError(Rec->getLoc(),
- "Pseudo output operand '" + Dag->getArgName(i) +
+ "Pseudo output operand '" + Dag->getArgNameStr(i) +
"' has no matching source operand.");
// Map the source operand to the destination operand index for each
// MachineInstr operand.
More information about the llvm-commits
mailing list