diff options
author | Christopher Lamb <christopher.lamb@gmail.com> | 2008-01-31 07:27:46 +0000 |
---|---|---|
committer | Christopher Lamb <christopher.lamb@gmail.com> | 2008-01-31 07:27:46 +0000 |
commit | 059c7c93405e64692bda72c4c986f9d51ce64918 (patch) | |
tree | 805dabe014aa0a4759c10d0dfca36de28e5bf673 /utils | |
parent | e08d9ec236815bc0da1828c0231e92698a98d27c (diff) | |
download | external_llvm-059c7c93405e64692bda72c4c986f9d51ce64918.zip external_llvm-059c7c93405e64692bda72c4c986f9d51ce64918.tar.gz external_llvm-059c7c93405e64692bda72c4c986f9d51ce64918.tar.bz2 |
Allow ComplexExpressions in InstrInfo.td files to be slightly more... complex! ComplexExpressions can now have attributes which affect how TableGen interprets
the pattern when generating matchin code.
The first (and currently, only) attribute causes the immediate parent node of the ComplexPattern operand to be passed into the matching code rather than the node at the root of the entire DAG containing the pattern.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46606 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils')
-rw-r--r-- | utils/TableGen/CodeGenTarget.cpp | 12 | ||||
-rw-r--r-- | utils/TableGen/CodeGenTarget.h | 8 | ||||
-rw-r--r-- | utils/TableGen/DAGISelEmitter.cpp | 14 |
3 files changed, 28 insertions, 6 deletions
diff --git a/utils/TableGen/CodeGenTarget.cpp b/utils/TableGen/CodeGenTarget.cpp index cf33fe6..bc758b7 100644 --- a/utils/TableGen/CodeGenTarget.cpp +++ b/utils/TableGen/CodeGenTarget.cpp @@ -351,6 +351,18 @@ ComplexPattern::ComplexPattern(Record *R) { << "' on ComplexPattern '" << R->getName() << "'!\n"; exit(1); } + + // Parse the attributes. + Attributes = 0; + PropList = R->getValueAsListOfDefs("Attributes"); + for (unsigned i = 0, e = PropList.size(); i != e; ++i) + if (PropList[i]->getName() == "CPAttrParentAsRoot") { + Attributes |= 1 << CPAttrParentAsRoot; + } else { + cerr << "Unsupported pattern attribute '" << PropList[i]->getName() + << "' on ComplexPattern '" << R->getName() << "'!\n"; + exit(1); + } } //===----------------------------------------------------------------------===// diff --git a/utils/TableGen/CodeGenTarget.h b/utils/TableGen/CodeGenTarget.h index 922c2b4..a14f630 100644 --- a/utils/TableGen/CodeGenTarget.h +++ b/utils/TableGen/CodeGenTarget.h @@ -42,6 +42,9 @@ enum SDNP { SDNPSideEffect }; +// ComplexPattern attributes. +enum CPAttr { CPAttrParentAsRoot }; + /// getValueType - Return the MVT::ValueType that the specified TableGen record /// corresponds to. MVT::ValueType getValueType(Record *Rec); @@ -172,7 +175,8 @@ class ComplexPattern { unsigned NumOperands; std::string SelectFunc; std::vector<Record*> RootNodes; - unsigned Properties; + unsigned Properties; // Node properties + unsigned Attributes; // Pattern attributes public: ComplexPattern() : NumOperands(0) {}; ComplexPattern(Record *R); @@ -184,7 +188,7 @@ public: return RootNodes; } bool hasProperty(enum SDNP Prop) const { return Properties & (1 << Prop); } - + bool hasAttribute(enum CPAttr Attr) const { return Attributes & (1 << Attr); } }; } // End llvm namespace diff --git a/utils/TableGen/DAGISelEmitter.cpp b/utils/TableGen/DAGISelEmitter.cpp index d685f70..1f568ad 100644 --- a/utils/TableGen/DAGISelEmitter.cpp +++ b/utils/TableGen/DAGISelEmitter.cpp @@ -550,7 +550,7 @@ public: emitCheck(MaskPredicate + RootName + "0, cast<ConstantSDNode>(" + RootName + "1), " + itostr(II->getValue()) + ")"); - EmitChildMatchCode(N->getChild(0), N, RootName + utostr(0), + EmitChildMatchCode(N->getChild(0), N, RootName + utostr(0), RootName, ChainSuffix + utostr(0), FoundChain); return; } @@ -561,7 +561,7 @@ public: emitInit("SDOperand " + RootName + utostr(OpNo) + " = " + RootName + ".getOperand(" +utostr(OpNo) + ");"); - EmitChildMatchCode(N->getChild(i), N, RootName + utostr(OpNo), + EmitChildMatchCode(N->getChild(i), N, RootName + utostr(OpNo), RootName, ChainSuffix + utostr(OpNo), FoundChain); } @@ -593,7 +593,8 @@ public: } void EmitChildMatchCode(TreePatternNode *Child, TreePatternNode *Parent, - const std::string &RootName, + const std::string &RootName, + const std::string &ParentRootName, const std::string &ChainSuffix, bool &FoundChain) { if (!Child->isLeaf()) { // If it's not a leaf, recursively match. @@ -649,7 +650,12 @@ public: emitCode("SDOperand " + ChainName + ";"); } - std::string Code = Fn + "(N, "; + std::string Code = Fn + "("; + if (CP->hasAttribute(CPAttrParentAsRoot)) { + Code += ParentRootName + ", "; + } else { + Code += "N, "; + } if (CP->hasProperty(SDNPHasChain)) { std::string ParentName(RootName.begin(), RootName.end()-1); Code += ParentName + ", "; |