From 8c06318821e4febb3a7f1afbab72dae362f1bf5f Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 30 Mar 2006 22:50:40 +0000 Subject: [PATCH] Implement Regression/TableGen/DagDefSubst.ll git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27263 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/TableGen/DAGISelEmitter.cpp | 11 ++++--- utils/TableGen/FileParser.y | 49 +++++++++++++++---------------- utils/TableGen/Record.cpp | 8 +++-- utils/TableGen/Record.h | 18 ++++++------ 4 files changed, 45 insertions(+), 41 deletions(-) diff --git a/utils/TableGen/DAGISelEmitter.cpp b/utils/TableGen/DAGISelEmitter.cpp index 38bc05c965f..06e0d5b7135 100644 --- a/utils/TableGen/DAGISelEmitter.cpp +++ b/utils/TableGen/DAGISelEmitter.cpp @@ -804,7 +804,9 @@ void TreePattern::error(const std::string &Msg) const { } TreePatternNode *TreePattern::ParseTreePattern(DagInit *Dag) { - Record *Operator = Dag->getNodeType(); + DefInit *OpDef = dynamic_cast(Dag->getOperator()); + if (!OpDef) error("Pattern has unexpected operator type!"); + Record *Operator = OpDef->getDef(); if (Operator->isSubClassOf("ValueType")) { // If the operator is a ValueType, then this must be "type cast" of a leaf @@ -817,7 +819,7 @@ TreePatternNode *TreePattern::ParseTreePattern(DagInit *Dag) { if (DefInit *DI = dynamic_cast(Arg)) { Record *R = DI->getDef(); if (R->isSubClassOf("SDNode") || R->isSubClassOf("PatFrag")) { - Dag->setArg(0, new DagInit(R, + Dag->setArg(0, new DagInit(DI, std::vector >())); return ParseTreePattern(Dag); } @@ -866,7 +868,7 @@ TreePatternNode *TreePattern::ParseTreePattern(DagInit *Dag) { // Direct reference to a leaf DagNode or PatFrag? Turn it into a // TreePatternNode if its own. if (R->isSubClassOf("SDNode") || R->isSubClassOf("PatFrag")) { - Dag->setArg(i, new DagInit(R, + Dag->setArg(i, new DagInit(DefI, std::vector >())); --i; // Revisit this node... } else { @@ -1043,7 +1045,8 @@ void DAGISelEmitter::ParsePatternFragments(std::ostream &OS) { // Parse the operands list. DagInit *OpsList = Fragments[i]->getValueAsDag("Operands"); - if (OpsList->getNodeType()->getName() != "ops") + DefInit *OpsOp = dynamic_cast(OpsList->getOperator()); + if (!OpsOp || OpsOp->getDef()->getName() != "ops") P->error("Operands list should start with '(ops ... '!"); // Copy over the arguments. diff --git a/utils/TableGen/FileParser.y b/utils/TableGen/FileParser.y index 28bb7b3f01f..11fda1ded09 100644 --- a/utils/TableGen/FileParser.y +++ b/utils/TableGen/FileParser.y @@ -210,7 +210,7 @@ using namespace llvm; %type SubClassRef %type ClassList ClassListNE %type OptPrefix -%type Value OptValue +%type Value OptValue IDValue %type DagArgList DagArgListNE %type ValueList ValueListNE %type BitList OptBitList RBitList @@ -253,7 +253,26 @@ OptPrefix : /*empty*/ { $$ = 0; } | FIELD { $$ = 1; }; OptValue : /*empty*/ { $$ = 0; } | '=' Value { $$ = $2; }; -Value : INTVAL { +IDValue : ID { + if (const RecordVal *RV = (CurRec ? CurRec->getValue(*$1) : 0)) { + $$ = new VarInit(*$1, RV->getType()); + } else if (CurRec && CurRec->isTemplateArg(CurRec->getName()+":"+*$1)) { + const RecordVal *RV = CurRec->getValue(CurRec->getName()+":"+*$1); + assert(RV && "Template arg doesn't exist??"); + $$ = new VarInit(CurRec->getName()+":"+*$1, RV->getType()); + } else if (Record *D = Records.getDef(*$1)) { + $$ = new DefInit(D); + } else { + err() << "Variable not defined: '" << *$1 << "'!\n"; + exit(1); + } + + delete $1; +}; + +Value : IDValue { + $$ = $1; + } | INTVAL { $$ = new IntInit($1); } | STRVAL { $$ = new StringInit(*$1); @@ -304,21 +323,6 @@ Value : INTVAL { // Restore the old CurRec CurRec = OldRec; - } | ID { - if (const RecordVal *RV = (CurRec ? CurRec->getValue(*$1) : 0)) { - $$ = new VarInit(*$1, RV->getType()); - } else if (CurRec && CurRec->isTemplateArg(CurRec->getName()+":"+*$1)) { - const RecordVal *RV = CurRec->getValue(CurRec->getName()+":"+*$1); - assert(RV && "Template arg doesn't exist??"); - $$ = new VarInit(CurRec->getName()+":"+*$1, RV->getType()); - } else if (Record *D = Records.getDef(*$1)) { - $$ = new DefInit(D); - } else { - err() << "Variable not defined: '" << *$1 << "'!\n"; - exit(1); - } - - delete $1; } | Value '{' BitList '}' { $$ = $1->convertInitializerBitRange(*$3); if ($$ == 0) { @@ -336,14 +340,9 @@ Value : INTVAL { } $$ = new FieldInit($1, *$3); delete $3; - } | '(' ID DagArgList ')' { - Record *D = Records.getDef(*$2); - if (D == 0) { - err() << "Invalid def '" << *$2 << "'!\n"; - exit(1); - } - $$ = new DagInit(D, *$3); - delete $2; delete $3; + } | '(' IDValue DagArgList ')' { + $$ = new DagInit($2, *$3); + delete $3; } | Value '[' BitList ']' { std::reverse($3->begin(), $3->end()); $$ = $1->convertInitListSlice(*$3); diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp index 2798afba6cc..251b7a9d921 100644 --- a/utils/TableGen/Record.cpp +++ b/utils/TableGen/Record.cpp @@ -559,15 +559,17 @@ Init *DagInit::resolveReferences(Record &R, const RecordVal *RV) { for (unsigned i = 0, e = Args.size(); i != e; ++i) NewArgs.push_back(Args[i]->resolveReferences(R, RV)); - if (Args != NewArgs) - return new DagInit(NodeTypeDef, NewArgs, ArgNames); + Init *Op = Val->resolveReferences(R, RV); + + if (Args != NewArgs || Op != Val) + return new DagInit(Op, NewArgs, ArgNames); return this; } void DagInit::print(std::ostream &OS) const { - OS << "(" << NodeTypeDef->getName(); + OS << "(" << *Val; if (Args.size()) { OS << " " << *Args[0]; if (!ArgNames[0].empty()) OS << ":$" << ArgNames[0]; diff --git a/utils/TableGen/Record.h b/utils/TableGen/Record.h index a4175e5845a..26a97013d72 100644 --- a/utils/TableGen/Record.h +++ b/utils/TableGen/Record.h @@ -808,17 +808,17 @@ public: } }; -/// DagInit - (def a, b) - Represent a DAG tree value. DAG inits are required -/// to have Records for their first value, after that, any legal Init is -/// possible. +/// DagInit - (v a, b) - Represent a DAG tree value. DAG inits are required +/// to have at least one value then a (possibly empty) list of arguments. Each +/// argument can have a name associated with it. /// class DagInit : public Init { - Record *NodeTypeDef; + Init *Val; std::vector Args; std::vector ArgNames; public: - DagInit(Record *D, const std::vector > &args) - : NodeTypeDef(D) { + DagInit(Init *V, const std::vector > &args) + : Val(V) { Args.reserve(args.size()); ArgNames.reserve(args.size()); for (unsigned i = 0, e = args.size(); i != e; ++i) { @@ -826,16 +826,16 @@ public: ArgNames.push_back(args[i].second); } } - DagInit(Record *D, const std::vector &args, + DagInit(Init *V, const std::vector &args, const std::vector &argNames) - : NodeTypeDef(D), Args(args), ArgNames(argNames) { + : Val(V), Args(args), ArgNames(argNames) { } virtual Init *convertInitializerTo(RecTy *Ty) { return Ty->convertValue(this); } - Record *getNodeType() const { return NodeTypeDef; } + Init *getOperator() const { return Val; } unsigned getNumArgs() const { return Args.size(); } Init *getArg(unsigned Num) const { -- 2.34.1