llvm.org GIT mirror llvm / 8535624
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 Christopher Lamb 11 years ago
4 changed file(s) with 37 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
766766 //===----------------------------------------------------------------------===//
767767 // Complex pattern definitions.
768768 //
769
770 class CPAttribute;
771 // Pass the parent Operand as root to CP function rather
772 // than the root of the sub-DAG
773 def CPAttrParentAsRoot : CPAttribute;
774
769775 // Complex patterns, e.g. X86 addressing mode, requires pattern matching code
770776 // in C++. NumOperands is the number of operands returned by the select function;
771777 // SelectFunc is the name of the function used to pattern match the max. pattern;
773779 // e.g. X86 addressing mode - def addr : ComplexPattern<4, "SelectAddr", [add]>;
774780 //
775781 class ComplexPattern
776 list roots = [], list props = []> {
782 list roots = [], list props = [],
783 list attrs = []> {
777784 ValueType Ty = ty;
778785 int NumOperands = numops;
779786 string SelectFunc = fn;
780787 list RootNodes = roots;
781788 list Properties = props;
789 list Attributes = attrs;
782790 }
783791
784792 //===----------------------------------------------------------------------===//
350350 << "' on ComplexPattern '" << R->getName() << "'!\n";
351351 exit(1);
352352 }
353
354 // Parse the attributes.
355 Attributes = 0;
356 PropList = R->getValueAsListOfDefs("Attributes");
357 for (unsigned i = 0, e = PropList.size(); i != e; ++i)
358 if (PropList[i]->getName() == "CPAttrParentAsRoot") {
359 Attributes |= 1 << CPAttrParentAsRoot;
360 } else {
361 cerr << "Unsupported pattern attribute '" << PropList[i]->getName()
362 << "' on ComplexPattern '" << R->getName() << "'!\n";
363 exit(1);
364 }
353365 }
354366
355367 //===----------------------------------------------------------------------===//
4040 SDNPMayStore,
4141 SDNPSideEffect
4242 };
43
44 // ComplexPattern attributes.
45 enum CPAttr { CPAttrParentAsRoot };
4346
4447 /// getValueType - Return the MVT::ValueType that the specified TableGen record
4548 /// corresponds to.
171174 unsigned NumOperands;
172175 std::string SelectFunc;
173176 std::vector RootNodes;
174 unsigned Properties;
177 unsigned Properties; // Node properties
178 unsigned Attributes; // Pattern attributes
175179 public:
176180 ComplexPattern() : NumOperands(0) {};
177181 ComplexPattern(Record *R);
183187 return RootNodes;
184188 }
185189 bool hasProperty(enum SDNP Prop) const { return Properties & (1 << Prop); }
186
190 bool hasAttribute(enum CPAttr Attr) const { return Attributes & (1 << Attr); }
187191 };
188192
189193 } // End llvm namespace
549549 emitCheck(MaskPredicate + RootName + "0, cast(" +
550550 RootName + "1), " + itostr(II->getValue()) + ")");
551551
552 EmitChildMatchCode(N->getChild(0), N, RootName + utostr(0),
552 EmitChildMatchCode(N->getChild(0), N, RootName + utostr(0), RootName,
553553 ChainSuffix + utostr(0), FoundChain);
554554 return;
555555 }
560560 emitInit("SDOperand " + RootName + utostr(OpNo) + " = " +
561561 RootName + ".getOperand(" +utostr(OpNo) + ");");
562562
563 EmitChildMatchCode(N->getChild(i), N, RootName + utostr(OpNo),
563 EmitChildMatchCode(N->getChild(i), N, RootName + utostr(OpNo), RootName,
564564 ChainSuffix + utostr(OpNo), FoundChain);
565565 }
566566
592592 }
593593
594594 void EmitChildMatchCode(TreePatternNode *Child, TreePatternNode *Parent,
595 const std::string &RootName,
595 const std::string &RootName,
596 const std::string &ParentRootName,
596597 const std::string &ChainSuffix, bool &FoundChain) {
597598 if (!Child->isLeaf()) {
598599 // If it's not a leaf, recursively match.
648649 emitCode("SDOperand " + ChainName + ";");
649650 }
650651
651 std::string Code = Fn + "(N, ";
652 std::string Code = Fn + "(";
653 if (CP->hasAttribute(CPAttrParentAsRoot)) {
654 Code += ParentRootName + ", ";
655 } else {
656 Code += "N, ";
657 }
652658 if (CP->hasProperty(SDNPHasChain)) {
653659 std::string ParentName(RootName.begin(), RootName.end()-1);
654660 Code += ParentName + ", ";