llvm.org GIT mirror llvm / 66a48bb
Teach tblgen to accept register source operands in patterns, e.g. def SHL8rCL : I<0xD2, MRM4r, (ops R8 :$dst, R8 :$src), "shl{b} {%cl, $dst|$dst, %CL}", [(set R8:$dst, (shl R8:$src, CL))]>, Imp<[CL],[]>; This generates a CopyToReg operand and added its 2nd result to the shl as a flag operand. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24557 91177308-0d34-0410-b5e6-96231b3b80d8 Evan Cheng 13 years ago
3 changed file(s) with 83 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
138138 std::vector Ops;
139139 Ops.push_back(Chain);
140140 Ops.push_back(getRegister(Reg, N.getValueType()));
141 Ops.push_back(N);
142 if (Flag.Val) Ops.push_back(Flag);
143 return getNode(ISD::CopyToReg, VTs, Ops);
144 }
145
146 // Similar to last getCopyToReg() except parameter Reg is a SDOperand
147 SDOperand getCopyToReg(SDOperand Chain, SDOperand Reg, SDOperand N,
148 SDOperand Flag) {
149 std::vector VTs;
150 VTs.push_back(MVT::Other);
151 VTs.push_back(MVT::Flag);
152 std::vector Ops;
153 Ops.push_back(Chain);
154 Ops.push_back(Reg);
141155 Ops.push_back(N);
142156 if (Flag.Val) Ops.push_back(Flag);
143157 return getNode(ISD::CopyToReg, VTs, Ops);
15731573 /// matches, and the SDNode for the result has the RootName specified name.
15741574 void DAGISelEmitter::EmitMatchForPattern(TreePatternNode *N,
15751575 const std::string &RootName,
1576 std::map &VarMap,
1576 std::map &VarMap,
15771577 unsigned PatternNo, std::ostream &OS) {
15781578 if (N->isLeaf()) {
15791579 if (IntInit *II = dynamic_cast(N->getLeafValue())) {
16361636 // Handle leaves of various types.
16371637 if (DefInit *DI = dynamic_cast(Child->getLeafValue())) {
16381638 Record *LeafRec = DI->getDef();
1639 if (LeafRec->isSubClassOf("RegisterClass")) {
1639 if (LeafRec->isSubClassOf("RegisterClass") ||
1640 LeafRec->isSubClassOf("Register")) {
16401641 // Handle register references. Nothing to do here.
16411642 } else if (LeafRec->isSubClassOf("ValueType")) {
16421643 // Make sure this is the specified value type.
16701671 << ".Val)) goto P" << PatternNo << "Fail;\n";
16711672 }
16721673
1674 /// getRegisterValueType - Look up and return ValueType of specified record
1675 static MVT::ValueType getRegisterValueType(Record *R, const CodeGenTarget &T) {
1676 const std::vector &RegisterClasses =
1677 T.getRegisterClasses();
1678
1679 for (unsigned i = 0, e = RegisterClasses.size(); i != e; ++i) {
1680 const CodeGenRegisterClass &RC = RegisterClasses[i];
1681 for (unsigned ei = 0, ee = RC.Elements.size(); ei != ee; ++ei) {
1682 if (R == RC.Elements[ei]) {
1683 return RC.VT;
1684 }
1685 }
1686 }
1687
1688 return MVT::Other;
1689 }
1690
1691
1692 /// EmitCopyToRegsForPattern - Emit the flag operands for the DAG that will be
1693 /// built in CodeGenPatternResult.
1694 void DAGISelEmitter::EmitCopyToRegsForPattern(TreePatternNode *N,
1695 const std::string &RootName,
1696 std::ostream &OS, bool &InFlag) {
1697 const CodeGenTarget &T = getTargetInfo();
1698 for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i) {
1699 TreePatternNode *Child = N->getChild(i);
1700 if (!Child->isLeaf()) {
1701 EmitCopyToRegsForPattern(Child, RootName + utostr(i), OS, InFlag);
1702 } else {
1703 if (DefInit *DI = dynamic_cast(Child->getLeafValue())) {
1704 Record *RR = DI->getDef();
1705 if (RR->isSubClassOf("Register")) {
1706 MVT::ValueType RVT = getRegisterValueType(RR, T);
1707 if (!InFlag) {
1708 OS << " SDOperand InFlag; // Null incoming flag value.\n";
1709 InFlag = true;
1710 }
1711 OS << " InFlag = CurDAG->getCopyToReg(CurDAG->getEntryNode()"
1712 << ", CurDAG->getRegister(" << getQualifiedName(RR)
1713 << ", MVT::" << getEnumName(RVT) << ")"
1714 << ", " << RootName << i << ", InFlag).getValue(1);\n";
1715
1716 }
1717 }
1718 }
1719 }
1720 }
1721
16731722 /// CodeGenPatternResult - Emit the action for a pattern. Now that it has
16741723 /// matched, we actually have to build a DAG!
16751724 unsigned DAGISelEmitter::
16761725 CodeGenPatternResult(TreePatternNode *N, unsigned &Ctr,
16771726 std::map &VariableMap,
1678 std::ostream &OS, bool isRoot) {
1727 std::ostream &OS, bool InFlag, bool isRoot) {
16791728 // This is something selected from the pattern we matched.
16801729 if (!N->getName().empty()) {
16811730 assert(!isRoot && "Root of pattern cannot be a leaf!");
17411790 // Emit all of the operands.
17421791 std::vector Ops;
17431792 for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i)
1744 Ops.push_back(CodeGenPatternResult(N->getChild(i), Ctr, VariableMap, OS));
1793 Ops.push_back(CodeGenPatternResult(N->getChild(i),
1794 Ctr, VariableMap, OS, InFlag));
17451795
17461796 CodeGenInstruction &II = Target.getInstruction(Op->getName());
17471797 unsigned ResNo = Ctr++;
17621812 << getEnumName(N->getType());
17631813 for (unsigned i = 0, e = Ops.size(); i != e; ++i)
17641814 OS << ", Tmp" << Ops[i];
1815 if (InFlag)
1816 OS << ", InFlag";
17651817 OS << ");\n";
17661818 OS << " } else {\n";
17671819 OS << " return CodeGenMap[N] = CurDAG->getTargetNode("
17691821 << getEnumName(N->getType());
17701822 for (unsigned i = 0, e = Ops.size(); i != e; ++i)
17711823 OS << ", Tmp" << Ops[i];
1824 if (InFlag)
1825 OS << ", InFlag";
17721826 OS << ");\n";
17731827 OS << " }\n";
17741828 }
17751829 return ResNo;
17761830 } else if (Op->isSubClassOf("SDNodeXForm")) {
17771831 assert(N->getNumChildren() == 1 && "node xform should have one child!");
1778 unsigned OpVal = CodeGenPatternResult(N->getChild(0), Ctr, VariableMap, OS);
1832 unsigned OpVal = CodeGenPatternResult(N->getChild(0),
1833 Ctr, VariableMap, OS, InFlag);
17791834
17801835 unsigned ResNo = Ctr++;
17811836 OS << " SDOperand Tmp" << ResNo << " = Transform_" << Op->getName()
18851940 // an unresolved type to add a check for, this returns true and we iterate,
18861941 // otherwise we are done.
18871942 } while (InsertOneTypeCheck(Pat, Pattern.first, "N", PatternNo, OS));
1943
1944 bool InFlag = false;
1945 EmitCopyToRegsForPattern(Pattern.first, "N", OS, InFlag);
18881946
18891947 unsigned TmpNo = 0;
1890 CodeGenPatternResult(Pattern.second, TmpNo,
1891 VariableMap, OS, true /*the root*/);
1948 CodeGenPatternResult(Pattern.second,
1949 TmpNo, VariableMap, OS, InFlag, true /*the root*/);
18921950 delete Pat;
18931951
18941952 OS << " }\n P" << PatternNo << "Fail:\n";
417417 void EmitMatchForPattern(TreePatternNode *N, const std::string &RootName,
418418 std::map &VarMap,
419419 unsigned PatternNo, std::ostream &OS);
420 void EmitCopyToRegsForPattern(TreePatternNode *N, const std::string &RootName,
421 std::ostream &OS, bool &InFlag);
420422 unsigned CodeGenPatternResult(TreePatternNode *N, unsigned &Ctr,
421423 std::map &VariableMap,
422 std::ostream &OS, bool isRoot = false);
424 std::ostream &OS, bool InFlag,
425 bool isRoot = false);
423426 void EmitCodeForPattern(PatternToMatch &Pattern, std::ostream &OS);
424427 void EmitInstructionSelector(std::ostream &OS);
425428 };