diff --git a/llvm/support/tools/TableGen/FileParser.y b/llvm/support/tools/TableGen/FileParser.y index 5b983eb06c7a..9650c53e2f26 100644 --- a/llvm/support/tools/TableGen/FileParser.y +++ b/llvm/support/tools/TableGen/FileParser.y @@ -161,12 +161,12 @@ static void addSubClass(Record *SC, const std::vector &TemplateArgs) { int IntVal; RecTy *Ty; Init *Initializer; - std::vector *DagValueList; std::vector *FieldList; std::vector*BitList; Record *Rec; SubClassRefTy *SubClassRef; std::vector *SubClassList; + std::vector > *DagValueList; }; %token INT BIT STRING BITS LIST CODE DAG CLASS DEF FIELD LET IN @@ -183,7 +183,7 @@ static void addSubClass(Record *SC, const std::vector &TemplateArgs) { %type DagArgList DagArgListNE %type ValueList ValueListNE %type BitList OptBitList RBitList -%type Declaration OptID +%type Declaration OptID OptVarName %start File %% @@ -282,16 +282,26 @@ Value : INTVAL { delete $2; delete $3; }; -DagArgListNE : Value { - $$ = new std::vector(); - $$->push_back($1); +OptVarName : /* empty */ { + $$ = new std::string(); } - | DagArgListNE ',' Value { - $1->push_back($3); + | ':' VARNAME { + $$ = $2; + }; + +DagArgListNE : Value OptVarName { + $$ = new std::vector >(); + $$->push_back(std::make_pair($1, *$2)); + delete $2; + } + | DagArgListNE ',' Value OptVarName { + $1->push_back(std::make_pair($3, *$4)); + delete $4; + $$ = $1; }; DagArgList : /*empty*/ { - $$ = new std::vector(); + $$ = new std::vector >(); } | DagArgListNE { $$ = $1; }; diff --git a/llvm/support/tools/TableGen/InstrSelectorEmitter.cpp b/llvm/support/tools/TableGen/InstrSelectorEmitter.cpp index f0b3ca1c4f79..9eb3be7f3fb0 100644 --- a/llvm/support/tools/TableGen/InstrSelectorEmitter.cpp +++ b/llvm/support/tools/TableGen/InstrSelectorEmitter.cpp @@ -172,15 +172,14 @@ MVT::ValueType Pattern::getIntrinsicType(Record *R) const { TreePatternNode *Pattern::ParseTreePattern(DagInit *DI) { Record *Operator = DI->getNodeType(); - const std::vector &Args = DI->getArgs(); if (Operator->isSubClassOf("ValueType")) { // If the operator is a ValueType, then this must be "type cast" of a leaf // node. - if (Args.size() != 1) + if (DI->getNumArgs() != 1) error("Type cast only valid for a leaf node!"); - Init *Arg = Args[0]; + Init *Arg = DI->getArg(0); TreePatternNode *New; if (DefInit *DI = dynamic_cast(Arg)) { New = new TreePatternNode(DI); @@ -201,8 +200,8 @@ TreePatternNode *Pattern::ParseTreePattern(DagInit *DI) { std::vector Children; - for (unsigned i = 0, e = Args.size(); i != e; ++i) { - Init *Arg = Args[i]; + for (unsigned i = 0, e = DI->getNumArgs(); i != e; ++i) { + Init *Arg = DI->getArg(i); if (DagInit *DI = dynamic_cast(Arg)) { Children.push_back(ParseTreePattern(DI)); } else if (DefInit *DI = dynamic_cast(Arg)) { diff --git a/llvm/support/tools/TableGen/Record.cpp b/llvm/support/tools/TableGen/Record.cpp index a76c55cfb678..384005081e70 100644 --- a/llvm/support/tools/TableGen/Record.cpp +++ b/llvm/support/tools/TableGen/Record.cpp @@ -438,8 +438,11 @@ void DagInit::print(std::ostream &OS) const { OS << "(" << NodeTypeDef->getName(); if (Args.size()) { OS << " " << *Args[0]; - for (unsigned i = 1, e = Args.size(); i != e; ++i) + if (!ArgNames[0].empty()) OS << ":$" << ArgNames[0]; + for (unsigned i = 1, e = Args.size(); i != e; ++i) { OS << ", " << *Args[i]; + if (!ArgNames[i].empty()) OS << ":$" << ArgNames[i]; + } } OS << ")"; } diff --git a/llvm/support/tools/TableGen/Record.h b/llvm/support/tools/TableGen/Record.h index 5c50a07651dd..88312509ef3f 100644 --- a/llvm/support/tools/TableGen/Record.h +++ b/llvm/support/tools/TableGen/Record.h @@ -591,9 +591,16 @@ public: class DagInit : public Init { Record *NodeTypeDef; std::vector Args; + std::vector ArgNames; public: - DagInit(Record *D, std::vector &a) : NodeTypeDef(D) { - Args.swap(a); // DESTRUCTIVELY take the arguments + DagInit(Record *D, const std::vector > &args) + : NodeTypeDef(D) { + Args.reserve(args.size()); + ArgNames.reserve(args.size()); + for (unsigned i = 0, e = args.size(); i != e; ++i) { + Args.push_back(args[i].first); + ArgNames.push_back(args[i].second); + } } virtual Init *convertInitializerTo(RecTy *Ty) { @@ -601,7 +608,16 @@ public: } Record *getNodeType() const { return NodeTypeDef; } - const std::vector &getArgs() const { return Args; } + + unsigned getNumArgs() const { return Args.size(); } + Init *getArg(unsigned Num) const { + assert(Num < Args.size() && "Arg number out of range!"); + return Args[Num]; + } + const std::string &getArgName(unsigned Num) const { + assert(Num < ArgNames.size() && "Arg number out of range!"); + return ArgNames[Num]; + } virtual void print(std::ostream &OS) const; };