[llvm-commits] CVS: llvm/utils/TableGen/DAGISelEmitter.cpp FileParser.y Record.h Record.cpp
Chris Lattner
lattner at cs.uiuc.edu
Thu Mar 30 14:50:52 PST 2006
Changes in directory llvm/utils/TableGen:
DAGISelEmitter.cpp updated: 1.190 -> 1.191
FileParser.y updated: 1.40 -> 1.41
Record.h updated: 1.55 -> 1.56
Record.cpp updated: 1.51 -> 1.52
---
Log message:
Implement Regression/TableGen/DagDefSubst.ll
---
Diffs of the changes: (+45 -41)
DAGISelEmitter.cpp | 11 +++++++----
FileParser.y | 49 ++++++++++++++++++++++++-------------------------
Record.cpp | 8 +++++---
Record.h | 18 +++++++++---------
4 files changed, 45 insertions(+), 41 deletions(-)
Index: llvm/utils/TableGen/DAGISelEmitter.cpp
diff -u llvm/utils/TableGen/DAGISelEmitter.cpp:1.190 llvm/utils/TableGen/DAGISelEmitter.cpp:1.191
--- llvm/utils/TableGen/DAGISelEmitter.cpp:1.190 Mon Mar 27 18:41:33 2006
+++ llvm/utils/TableGen/DAGISelEmitter.cpp Thu Mar 30 16:50:40 2006
@@ -804,7 +804,9 @@
}
TreePatternNode *TreePattern::ParseTreePattern(DagInit *Dag) {
- Record *Operator = Dag->getNodeType();
+ DefInit *OpDef = dynamic_cast<DefInit*>(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 @@
if (DefInit *DI = dynamic_cast<DefInit*>(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<std::pair<Init*, std::string> >()));
return ParseTreePattern(Dag);
}
@@ -866,7 +868,7 @@
// 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<std::pair<Init*, std::string> >()));
--i; // Revisit this node...
} else {
@@ -1043,7 +1045,8 @@
// Parse the operands list.
DagInit *OpsList = Fragments[i]->getValueAsDag("Operands");
- if (OpsList->getNodeType()->getName() != "ops")
+ DefInit *OpsOp = dynamic_cast<DefInit*>(OpsList->getOperator());
+ if (!OpsOp || OpsOp->getDef()->getName() != "ops")
P->error("Operands list should start with '(ops ... '!");
// Copy over the arguments.
Index: llvm/utils/TableGen/FileParser.y
diff -u llvm/utils/TableGen/FileParser.y:1.40 llvm/utils/TableGen/FileParser.y:1.41
--- llvm/utils/TableGen/FileParser.y:1.40 Tue Jan 31 00:02:35 2006
+++ llvm/utils/TableGen/FileParser.y Thu Mar 30 16:50:40 2006
@@ -210,7 +210,7 @@
%type <SubClassRef> SubClassRef
%type <SubClassList> ClassList ClassListNE
%type <IntVal> OptPrefix
-%type <Initializer> Value OptValue
+%type <Initializer> Value OptValue IDValue
%type <DagValueList> DagArgList DagArgListNE
%type <FieldList> ValueList ValueListNE
%type <BitList> BitList OptBitList RBitList
@@ -253,7 +253,26 @@
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 @@
// 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 @@
}
$$ = 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);
Index: llvm/utils/TableGen/Record.h
diff -u llvm/utils/TableGen/Record.h:1.55 llvm/utils/TableGen/Record.h:1.56
--- llvm/utils/TableGen/Record.h:1.55 Tue Jan 31 00:02:35 2006
+++ llvm/utils/TableGen/Record.h Thu Mar 30 16:50:40 2006
@@ -808,17 +808,17 @@
}
};
-/// 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<Init*> Args;
std::vector<std::string> ArgNames;
public:
- DagInit(Record *D, const std::vector<std::pair<Init*, std::string> > &args)
- : NodeTypeDef(D) {
+ DagInit(Init *V, const std::vector<std::pair<Init*, std::string> > &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 @@
ArgNames.push_back(args[i].second);
}
}
- DagInit(Record *D, const std::vector<Init*> &args,
+ DagInit(Init *V, const std::vector<Init*> &args,
const std::vector<std::string> &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 {
Index: llvm/utils/TableGen/Record.cpp
diff -u llvm/utils/TableGen/Record.cpp:1.51 llvm/utils/TableGen/Record.cpp:1.52
--- llvm/utils/TableGen/Record.cpp:1.51 Fri Feb 17 21:20:33 2006
+++ llvm/utils/TableGen/Record.cpp Thu Mar 30 16:50:40 2006
@@ -559,15 +559,17 @@
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];
More information about the llvm-commits
mailing list