Author: clamb Date: Thu Jan 31 01:27:46 2008 New Revision: 46606 URL: http://llvm.org/viewvc/llvm-project?rev=46606&view=rev Log: 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. Modified: llvm/trunk/lib/Target/TargetSelectionDAG.td llvm/trunk/utils/TableGen/CodeGenTarget.cpp llvm/trunk/utils/TableGen/CodeGenTarget.h llvm/trunk/utils/TableGen/DAGISelEmitter.cpp Modified: llvm/trunk/lib/Target/TargetSelectionDAG.td URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetSelectionDAG.td?rev=46606&r1=46605&r2=46606&view=diff ============================================================================== --- llvm/trunk/lib/Target/TargetSelectionDAG.td (original) +++ llvm/trunk/lib/Target/TargetSelectionDAG.td Thu Jan 31 01:27:46 2008 @@ -767,6 +767,12 @@ //===----------------------------------------------------------------------===// // Complex pattern definitions. // + +class CPAttribute; +// Pass the parent Operand as root to CP function rather +// than the root of the sub-DAG +def CPAttrParentAsRoot : CPAttribute; + // Complex patterns, e.g. X86 addressing mode, requires pattern matching code // in C++. NumOperands is the number of operands returned by the select function; // SelectFunc is the name of the function used to pattern match the max. pattern; @@ -774,12 +780,14 @@ // e.g. X86 addressing mode - def addr : ComplexPattern<4, "SelectAddr", [add]>; // class ComplexPattern<ValueType ty, int numops, string fn, - list<SDNode> roots = [], list<SDNodeProperty> props = []> { + list<SDNode> roots = [], list<SDNodeProperty> props = [], + list<CPAttribute> attrs = []> { ValueType Ty = ty; int NumOperands = numops; string SelectFunc = fn; list<SDNode> RootNodes = roots; list<SDNodeProperty> Properties = props; + list<CPAttribute> Attributes = attrs; } //===----------------------------------------------------------------------===// Modified: llvm/trunk/utils/TableGen/CodeGenTarget.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenTarget.cpp?rev=46606&r1=46605&r2=46606&view=diff ============================================================================== --- llvm/trunk/utils/TableGen/CodeGenTarget.cpp (original) +++ llvm/trunk/utils/TableGen/CodeGenTarget.cpp Thu Jan 31 01:27:46 2008 @@ -351,6 +351,18 @@ << "' 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); + } } //===----------------------------------------------------------------------===// Modified: llvm/trunk/utils/TableGen/CodeGenTarget.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenTarget.h?rev=46606&r1=46605&r2=46606&view=diff ============================================================================== --- llvm/trunk/utils/TableGen/CodeGenTarget.h (original) +++ llvm/trunk/utils/TableGen/CodeGenTarget.h Thu Jan 31 01:27:46 2008 @@ -42,6 +42,9 @@ 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 @@ 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 @@ 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 Modified: llvm/trunk/utils/TableGen/DAGISelEmitter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/DAGISelEmitter.cpp?rev=46606&r1=46605&r2=46606&view=diff ============================================================================== --- llvm/trunk/utils/TableGen/DAGISelEmitter.cpp (original) +++ llvm/trunk/utils/TableGen/DAGISelEmitter.cpp Thu Jan 31 01:27:46 2008 @@ -550,7 +550,7 @@ 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 @@ 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 @@ } 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 @@ 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 + ", "; _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits