summaryrefslogtreecommitdiff
path: root/utils/TableGen/DAGISelEmitter.cpp
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2007-07-06 01:05:26 +0000
committerEvan Cheng <evan.cheng@apple.com>2007-07-06 01:05:26 +0000
commita955939ca2e9c9d5934e884e8c676603e0a81705 (patch)
treea62d0e5cf536df28e8f206d5eb6e0be19ee750ff /utils/TableGen/DAGISelEmitter.cpp
parentdfb2ebac29f92a533218bd576734913a89d1299d (diff)
downloadllvm-a955939ca2e9c9d5934e884e8c676603e0a81705.tar.gz
llvm-a955939ca2e9c9d5934e884e8c676603e0a81705.tar.bz2
llvm-a955939ca2e9c9d5934e884e8c676603e0a81705.tar.xz
Refactor code to add initial support for OptionalDefOperand.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37933 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen/DAGISelEmitter.cpp')
-rw-r--r--utils/TableGen/DAGISelEmitter.cpp116
1 files changed, 63 insertions, 53 deletions
diff --git a/utils/TableGen/DAGISelEmitter.cpp b/utils/TableGen/DAGISelEmitter.cpp
index ca3d37a85a..fcad318587 100644
--- a/utils/TableGen/DAGISelEmitter.cpp
+++ b/utils/TableGen/DAGISelEmitter.cpp
@@ -775,11 +775,12 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
for (unsigned i = 0, e = Inst.getNumOperands(); i != e; ++i) {
Record *OperandNode = Inst.getOperand(i);
- // If the instruction expects a predicate operand, we codegen this by
- // setting the predicate to it's "execute always" value if it has a
- // non-empty ExecuteAlways field.
- if (OperandNode->isSubClassOf("PredicateOperand") &&
- !ISE.getPredicateOperand(OperandNode).AlwaysOps.empty())
+ // If the instruction expects a predicate or optional def operand, we
+ // codegen this by setting the operand to it's default value if it has a
+ // non-empty DefaultOps field.
+ if ((OperandNode->isSubClassOf("PredicateOperand") ||
+ OperandNode->isSubClassOf("OptionalDefOperand")) &&
+ !ISE.getDefaultOperand(OperandNode).DefaultOps.empty())
continue;
// Verify that we didn't run out of provided operands.
@@ -1246,47 +1247,54 @@ void DAGISelEmitter::ParsePatternFragments(std::ostream &OS) {
}
}
-void DAGISelEmitter::ParsePredicateOperands() {
- std::vector<Record*> PredOps =
- Records.getAllDerivedDefinitions("PredicateOperand");
+void DAGISelEmitter::ParseDefaultOperands() {
+ std::vector<Record*> DefaultOps[2];
+ DefaultOps[0] = Records.getAllDerivedDefinitions("PredicateOperand");
+ DefaultOps[1] = Records.getAllDerivedDefinitions("OptionalDefOperand");
// Find some SDNode.
assert(!SDNodes.empty() && "No SDNodes parsed?");
Init *SomeSDNode = new DefInit(SDNodes.begin()->first);
- for (unsigned i = 0, e = PredOps.size(); i != e; ++i) {
- DagInit *AlwaysInfo = PredOps[i]->getValueAsDag("ExecuteAlways");
-
- // Clone the AlwaysInfo dag node, changing the operator from 'ops' to
- // SomeSDnode so that we can parse this.
- std::vector<std::pair<Init*, std::string> > Ops;
- for (unsigned op = 0, e = AlwaysInfo->getNumArgs(); op != e; ++op)
- Ops.push_back(std::make_pair(AlwaysInfo->getArg(op),
- AlwaysInfo->getArgName(op)));
- DagInit *DI = new DagInit(SomeSDNode, Ops);
-
- // Create a TreePattern to parse this.
- TreePattern P(PredOps[i], DI, false, *this);
- assert(P.getNumTrees() == 1 && "This ctor can only produce one tree!");
-
- // Copy the operands over into a DAGPredicateOperand.
- DAGPredicateOperand PredOpInfo;
-
- TreePatternNode *T = P.getTree(0);
- for (unsigned op = 0, e = T->getNumChildren(); op != e; ++op) {
- TreePatternNode *TPN = T->getChild(op);
- while (TPN->ApplyTypeConstraints(P, false))
- /* Resolve all types */;
+ for (unsigned iter = 0; iter != 2; ++iter) {
+ for (unsigned i = 0, e = DefaultOps[iter].size(); i != e; ++i) {
+ DagInit *DefaultInfo = DefaultOps[iter][i]->getValueAsDag("DefaultOps");
+
+ // Clone the DefaultInfo dag node, changing the operator from 'ops' to
+ // SomeSDnode so that we can parse this.
+ std::vector<std::pair<Init*, std::string> > Ops;
+ 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);
+
+ // Create a TreePattern to parse this.
+ TreePattern P(DefaultOps[iter][i], DI, false, *this);
+ assert(P.getNumTrees() == 1 && "This ctor can only produce one tree!");
+
+ // Copy the operands over into a DAGDefaultOperand.
+ DAGDefaultOperand DefaultOpInfo;
+
+ TreePatternNode *T = P.getTree(0);
+ for (unsigned op = 0, e = T->getNumChildren(); op != e; ++op) {
+ TreePatternNode *TPN = T->getChild(op);
+ while (TPN->ApplyTypeConstraints(P, false))
+ /* Resolve all types */;
- if (TPN->ContainsUnresolvedType())
- throw "Value #" + utostr(i) + " of PredicateOperand '" +
- PredOps[i]->getName() + "' doesn't have a concrete type!";
+ if (TPN->ContainsUnresolvedType())
+ if (iter == 0)
+ throw "Value #" + utostr(i) + " of PredicateOperand '" +
+ DefaultOps[iter][i]->getName() + "' doesn't have a concrete type!";
+ else
+ throw "Value #" + utostr(i) + " of OptionalDefOperand '" +
+ DefaultOps[iter][i]->getName() + "' doesn't have a concrete type!";
- PredOpInfo.AlwaysOps.push_back(TPN);
- }
+ DefaultOpInfo.DefaultOps.push_back(TPN);
+ }
- // Insert it into the PredicateOperands map so we can find it later.
- PredicateOperands[PredOps[i]] = PredOpInfo;
+ // Insert it into the DefaultOperands map so we can find it later.
+ DefaultOperands[DefaultOps[iter][i]] = DefaultOpInfo;
+ }
}
}
@@ -1550,13 +1558,14 @@ void DAGISelEmitter::ParseInstructions() {
I->error("Operand #" + utostr(i) + " in operands list has no name!");
if (!InstInputsCheck.count(OpName)) {
- // If this is an predicate operand with an ExecuteAlways set filled in,
- // we can ignore this. When we codegen it, we will do so as always
- // executed.
- if (Op.Rec->isSubClassOf("PredicateOperand")) {
- // Does it have a non-empty ExecuteAlways field? If so, ignore this
+ // If this is an predicate operand or optional def operand with an
+ // DefaultOps set filled in, we can ignore this. When we codegen it,
+ // we will do so as always executed.
+ if (Op.Rec->isSubClassOf("PredicateOperand") ||
+ Op.Rec->isSubClassOf("OptionalDefOperand")) {
+ // Does it have a non-empty DefaultOps field? If so, ignore this
// operand.
- if (!getPredicateOperand(Op.Rec).AlwaysOps.empty())
+ if (!getDefaultOperand(Op.Rec).DefaultOps.empty())
continue;
}
I->error("Operand $" + OpName +
@@ -2813,19 +2822,20 @@ public:
// If this is a normal operand or a predicate operand without
// 'execute always', emit it.
Record *OperandNode = II.OperandList[InstOpNo].Rec;
- if (!OperandNode->isSubClassOf("PredicateOperand") ||
- ISE.getPredicateOperand(OperandNode).AlwaysOps.empty()) {
+ if ((!OperandNode->isSubClassOf("PredicateOperand") &&
+ !OperandNode->isSubClassOf("OptionalDefOperand")) ||
+ ISE.getDefaultOperand(OperandNode).DefaultOps.empty()) {
Ops = EmitResultCode(N->getChild(ChildNo), RetSelected,
InFlagDecled, ResNodeDecled);
AllOps.insert(AllOps.end(), Ops.begin(), Ops.end());
++ChildNo;
} else {
- // Otherwise, this is a predicate operand, emit the 'execute always'
- // operands.
- const DAGPredicateOperand &Pred =
- ISE.getPredicateOperand(II.OperandList[InstOpNo].Rec);
- for (unsigned i = 0, e = Pred.AlwaysOps.size(); i != e; ++i) {
- Ops = EmitResultCode(Pred.AlwaysOps[i], RetSelected,
+ // Otherwise, this is a predicate or optional def operand, emit the
+ // 'default ops' operands.
+ const DAGDefaultOperand &DefaultOp =
+ ISE.getDefaultOperand(II.OperandList[InstOpNo].Rec);
+ for (unsigned i = 0, e = DefaultOp.DefaultOps.size(); i != e; ++i) {
+ Ops = EmitResultCode(DefaultOp.DefaultOps[i], RetSelected,
InFlagDecled, ResNodeDecled);
AllOps.insert(AllOps.end(), Ops.begin(), Ops.end());
NumEAInputs += Ops.size();
@@ -3962,7 +3972,7 @@ OS << " unsigned NumKilled = ISelKilled.size();\n";
ParseNodeTransforms(OS);
ParseComplexPatterns();
ParsePatternFragments(OS);
- ParsePredicateOperands();
+ ParseDefaultOperands();
ParseInstructions();
ParsePatterns();