Implement Regression/TableGen/DagDefSubst.ll

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27263 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2006-03-30 22:50:40 +00:00
parent 824b46f26f
commit 8c06318821
4 changed files with 45 additions and 41 deletions

View File

@ -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<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 @@ TreePatternNode *TreePattern::ParseTreePattern(DagInit *Dag) {
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 @@ 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<std::pair<Init*, std::string> >()));
--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<DefInit*>(OpsList->getOperator());
if (!OpsOp || OpsOp->getDef()->getName() != "ops")
P->error("Operands list should start with '(ops ... '!");
// Copy over the arguments.

View File

@ -210,7 +210,7 @@ using namespace llvm;
%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 @@ 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);

View File

@ -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];

View File

@ -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<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 @@ public:
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 {