aboutsummaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorNate Begeman <natebegeman@mac.com>2009-03-19 05:21:56 +0000
committerNate Begeman <natebegeman@mac.com>2009-03-19 05:21:56 +0000
commit7cee81703de8333d457ec9e560b0537b71df5a48 (patch)
tree510812a4ee134e4dbda6b3f38cdaeab84a82a86f /utils
parentb53db4fb321823a8a1f6abc372bdc7c36ef1447f (diff)
downloadexternal_llvm-7cee81703de8333d457ec9e560b0537b71df5a48.zip
external_llvm-7cee81703de8333d457ec9e560b0537b71df5a48.tar.gz
external_llvm-7cee81703de8333d457ec9e560b0537b71df5a48.tar.bz2
Add support to tablegen for naming the nodes themselves, not just the operands,
in selectiondag patterns. This is required for the upcoming shuffle_vector rewrite, and as it turns out, cleans up a hack in the Alpha instruction info. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@67286 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils')
-rw-r--r--utils/TableGen/CodeGenDAGPatterns.cpp22
-rw-r--r--utils/TableGen/Record.cpp6
-rw-r--r--utils/TableGen/Record.h12
-rw-r--r--utils/TableGen/TGParser.cpp14
4 files changed, 36 insertions, 18 deletions
diff --git a/utils/TableGen/CodeGenDAGPatterns.cpp b/utils/TableGen/CodeGenDAGPatterns.cpp
index 6af0515..c5e6bdf 100644
--- a/utils/TableGen/CodeGenDAGPatterns.cpp
+++ b/utils/TableGen/CodeGenDAGPatterns.cpp
@@ -1132,7 +1132,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(DI,
+ Dag->setArg(0, new DagInit(DI, "",
std::vector<std::pair<Init*, std::string> >()));
return ParseTreePattern(Dag);
}
@@ -1160,12 +1160,14 @@ TreePatternNode *TreePattern::ParseTreePattern(DagInit *Dag) {
// Apply the type cast.
New->UpdateNodeType(getValueType(Operator), *this);
- New->setName(Dag->getArgName(0));
+ if (New->getNumChildren() == 0)
+ New->setName(Dag->getArgName(0));
return New;
}
// Verify that this is something that makes sense for an operator.
- if (!Operator->isSubClassOf("PatFrag") && !Operator->isSubClassOf("SDNode") &&
+ if (!Operator->isSubClassOf("PatFrag") &&
+ !Operator->isSubClassOf("SDNode") &&
!Operator->isSubClassOf("Instruction") &&
!Operator->isSubClassOf("SDNodeXForm") &&
!Operator->isSubClassOf("Intrinsic") &&
@@ -1192,7 +1194,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(DefI,
+ Dag->setArg(i, new DagInit(DefI, "",
std::vector<std::pair<Init*, std::string> >()));
--i; // Revisit this node...
} else {
@@ -1253,7 +1255,9 @@ TreePatternNode *TreePattern::ParseTreePattern(DagInit *Dag) {
Children.insert(Children.begin(), IIDNode);
}
- return new TreePatternNode(Operator, Children);
+ TreePatternNode *Result = new TreePatternNode(Operator, Children);
+ Result->setName(Dag->getName());
+ return Result;
}
/// InferAllTypes - Infer/propagate as many types throughout the expression
@@ -1482,7 +1486,7 @@ void CodeGenDAGPatterns::ParseDefaultOperands() {
for (unsigned op = 0, e = DefaultInfo->getNumArgs(); op != e; ++op)
Ops.push_back(std::make_pair(DefaultInfo->getArg(op),
DefaultInfo->getArgName(op)));
- DagInit *DI = new DagInit(SomeSDNode, Ops);
+ DagInit *DI = new DagInit(SomeSDNode, "", Ops);
// Create a TreePattern to parse this.
TreePattern P(DefaultOps[iter][i], DI, false, *this);
@@ -1527,7 +1531,6 @@ static bool HandleUse(TreePattern *I, TreePatternNode *Pat,
I->error("Input " + DI->getDef()->getName() + " must be named!");
else if (DI && DI->getDef()->isSubClassOf("Register"))
InstImpInputs.push_back(DI->getDef());
- ;
}
return false;
}
@@ -1538,7 +1541,6 @@ static bool HandleUse(TreePattern *I, TreePatternNode *Pat,
if (!DI) I->error("Input $" + Pat->getName() + " must be an identifier!");
Rec = DI->getDef();
} else {
- assert(Pat->getNumChildren() == 0 && "can't be a use with children!");
Rec = Pat->getOperator();
}
@@ -1605,9 +1607,7 @@ FindPatternInputsAndOutputs(TreePattern *I, TreePatternNode *Pat,
// If this is a non-leaf node with no children, treat it basically as if
// it were a leaf. This handles nodes like (imm).
- bool isUse = false;
- if (Pat->getNumChildren() == 0)
- isUse = HandleUse(I, Pat, InstInputs, InstImpInputs);
+ bool isUse = HandleUse(I, Pat, InstInputs, InstImpInputs);
if (!isUse && Pat->getTransformFn())
I->error("Cannot specify a transform function for a non-input value!");
diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp
index e173cae..e2d9657 100644
--- a/utils/TableGen/Record.cpp
+++ b/utils/TableGen/Record.cpp
@@ -426,7 +426,7 @@ Init *BinOpInit::Fold() {
Args.push_back(RHSs->getArg(i));
ArgNames.push_back(RHSs->getArgName(i));
}
- return new DagInit(LHSs->getOperator(), Args, ArgNames);
+ return new DagInit(LHSs->getOperator(), "", Args, ArgNames);
}
break;
}
@@ -679,7 +679,7 @@ Init *DagInit::resolveReferences(Record &R, const RecordVal *RV) {
Init *Op = Val->resolveReferences(R, RV);
if (Args != NewArgs || Op != Val)
- return new DagInit(Op, NewArgs, ArgNames);
+ return new DagInit(Op, "", NewArgs, ArgNames);
return this;
}
@@ -687,6 +687,8 @@ Init *DagInit::resolveReferences(Record &R, const RecordVal *RV) {
std::string DagInit::getAsString() const {
std::string Result = "(" + Val->getAsString();
+ if (!ValName.empty())
+ Result += ":" + ValName;
if (Args.size()) {
Result += " " + Args[0]->getAsString();
if (!ArgNames[0].empty()) Result += ":$" + ArgNames[0];
diff --git a/utils/TableGen/Record.h b/utils/TableGen/Record.h
index 3b2141c..32172ef 100644
--- a/utils/TableGen/Record.h
+++ b/utils/TableGen/Record.h
@@ -857,11 +857,13 @@ public:
///
class DagInit : public Init {
Init *Val;
+ std::string ValName;
std::vector<Init*> Args;
std::vector<std::string> ArgNames;
public:
- DagInit(Init *V, const std::vector<std::pair<Init*, std::string> > &args)
- : Val(V) {
+ DagInit(Init *V, std::string VN,
+ const std::vector<std::pair<Init*, std::string> > &args)
+ : Val(V), ValName(VN) {
Args.reserve(args.size());
ArgNames.reserve(args.size());
for (unsigned i = 0, e = args.size(); i != e; ++i) {
@@ -869,9 +871,9 @@ public:
ArgNames.push_back(args[i].second);
}
}
- DagInit(Init *V, const std::vector<Init*> &args,
+ DagInit(Init *V, std::string VN, const std::vector<Init*> &args,
const std::vector<std::string> &argNames)
- : Val(V), Args(args), ArgNames(argNames) {
+ : Val(V), ValName(VN), Args(args), ArgNames(argNames) {
}
virtual Init *convertInitializerTo(RecTy *Ty) {
@@ -880,6 +882,8 @@ public:
Init *getOperator() const { return Val; }
+ const std::string &getName() const { return ValName; }
+
unsigned getNumArgs() const { return Args.size(); }
Init *getArg(unsigned Num) const {
assert(Num < Args.size() && "Arg number out of range!");
diff --git a/utils/TableGen/TGParser.cpp b/utils/TableGen/TGParser.cpp
index 1fa8272..9d579c2 100644
--- a/utils/TableGen/TGParser.cpp
+++ b/utils/TableGen/TGParser.cpp
@@ -636,6 +636,18 @@ Init *TGParser::ParseSimpleValue(Record *CurRec) {
Init *Operator = ParseIDValue(CurRec);
if (Operator == 0) return 0;
+ // If the operator name is present, parse it.
+ std::string OperatorName;
+ if (Lex.getCode() == tgtok::colon) {
+ if (Lex.Lex() != tgtok::VarName) { // eat the ':'
+ TokError("expected variable name in dag operator");
+ return 0;
+ }
+ OperatorName = Lex.getCurStrVal();
+ Lex.Lex(); // eat the VarName.
+ }
+
+
std::vector<std::pair<llvm::Init*, std::string> > DagArgs;
if (Lex.getCode() != tgtok::r_paren) {
DagArgs = ParseDagArgList(CurRec);
@@ -648,7 +660,7 @@ Init *TGParser::ParseSimpleValue(Record *CurRec) {
}
Lex.Lex(); // eat the ')'
- return new DagInit(Operator, DagArgs);
+ return new DagInit(Operator, OperatorName, DagArgs);
}
case tgtok::XConcat:
case tgtok::XSRA: