@@ -956,6 +956,40 @@ bool SDTypeConstraint::ApplyTypeConstraint(TreePatternNode *N,
956
956
llvm_unreachable (" Invalid ConstraintType!" );
957
957
}
958
958
959
+ // Update the node type to match an instruction operand or result as specified
960
+ // in the ins or outs lists on the instruction definition. Return true if the
961
+ // type was actually changed.
962
+ bool TreePatternNode::UpdateNodeTypeFromInst (unsigned ResNo,
963
+ Record *Operand,
964
+ TreePattern &TP) {
965
+ // The 'unknown' operand indicates that types should be inferred from the
966
+ // context.
967
+ if (Operand->isSubClassOf (" unknown_class" ))
968
+ return false ;
969
+
970
+ // The Operand class specifies a type directly.
971
+ if (Operand->isSubClassOf (" Operand" ))
972
+ return UpdateNodeType (ResNo, getValueType (Operand->getValueAsDef (" Type" )),
973
+ TP);
974
+
975
+ // PointerLikeRegClass has a type that is determined at runtime.
976
+ if (Operand->isSubClassOf (" PointerLikeRegClass" ))
977
+ return UpdateNodeType (ResNo, MVT::iPTR, TP);
978
+
979
+ // Both RegisterClass and RegisterOperand operands derive their types from a
980
+ // register class def.
981
+ Record *RC = 0 ;
982
+ if (Operand->isSubClassOf (" RegisterClass" ))
983
+ RC = Operand;
984
+ else if (Operand->isSubClassOf (" RegisterOperand" ))
985
+ RC = Operand->getValueAsDef (" RegClass" );
986
+
987
+ assert (RC && " Unknown operand type" );
988
+ CodeGenTarget &Tgt = TP.getDAGPatterns ().getTargetInfo ();
989
+ return UpdateNodeType (ResNo, Tgt.getRegisterClass (RC).getValueTypes (), TP);
990
+ }
991
+
992
+
959
993
// ===----------------------------------------------------------------------===//
960
994
// SDNodeInfo implementation
961
995
//
@@ -1575,26 +1609,8 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
1575
1609
// (outs) list of the instruction.
1576
1610
// FIXME: Cap at one result so far.
1577
1611
unsigned NumResultsToAdd = InstInfo.Operands .NumDefs ? 1 : 0 ;
1578
- for (unsigned ResNo = 0 ; ResNo != NumResultsToAdd; ++ResNo) {
1579
- Record *ResultNode = Inst.getResult (ResNo);
1580
-
1581
- if (ResultNode->isSubClassOf (" PointerLikeRegClass" )) {
1582
- MadeChange |= UpdateNodeType (ResNo, MVT::iPTR, TP);
1583
- } else if (ResultNode->isSubClassOf (" RegisterOperand" )) {
1584
- Record *RegClass = ResultNode->getValueAsDef (" RegClass" );
1585
- const CodeGenRegisterClass &RC =
1586
- CDP.getTargetInfo ().getRegisterClass (RegClass);
1587
- MadeChange |= UpdateNodeType (ResNo, RC.getValueTypes (), TP);
1588
- } else if (ResultNode->isSubClassOf (" unknown_class" )) {
1589
- // Nothing to do.
1590
- } else {
1591
- assert (ResultNode->isSubClassOf (" RegisterClass" ) &&
1592
- " Operands should be register classes!" );
1593
- const CodeGenRegisterClass &RC =
1594
- CDP.getTargetInfo ().getRegisterClass (ResultNode);
1595
- MadeChange |= UpdateNodeType (ResNo, RC.getValueTypes (), TP);
1596
- }
1597
- }
1612
+ for (unsigned ResNo = 0 ; ResNo != NumResultsToAdd; ++ResNo)
1613
+ MadeChange |= UpdateNodeTypeFromInst (ResNo, Inst.getResult (ResNo), TP);
1598
1614
1599
1615
// If the instruction has implicit defs, we apply the first one as a result.
1600
1616
// FIXME: This sucks, it should apply all implicit defs.
@@ -1636,29 +1652,9 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
1636
1652
return false ;
1637
1653
}
1638
1654
1639
- MVT::SimpleValueType VT;
1640
1655
TreePatternNode *Child = getChild (ChildNo++);
1641
1656
unsigned ChildResNo = 0 ; // Instructions always use res #0 of their op.
1642
-
1643
- if (OperandNode->isSubClassOf (" RegisterClass" )) {
1644
- const CodeGenRegisterClass &RC =
1645
- CDP.getTargetInfo ().getRegisterClass (OperandNode);
1646
- MadeChange |= Child->UpdateNodeType (ChildResNo, RC.getValueTypes (), TP);
1647
- } else if (OperandNode->isSubClassOf (" RegisterOperand" )) {
1648
- Record *RegClass = OperandNode->getValueAsDef (" RegClass" );
1649
- const CodeGenRegisterClass &RC =
1650
- CDP.getTargetInfo ().getRegisterClass (RegClass);
1651
- MadeChange |= Child->UpdateNodeType (ChildResNo, RC.getValueTypes (), TP);
1652
- } else if (OperandNode->isSubClassOf (" Operand" )) {
1653
- VT = getValueType (OperandNode->getValueAsDef (" Type" ));
1654
- MadeChange |= Child->UpdateNodeType (ChildResNo, VT, TP);
1655
- } else if (OperandNode->isSubClassOf (" PointerLikeRegClass" )) {
1656
- MadeChange |= Child->UpdateNodeType (ChildResNo, MVT::iPTR, TP);
1657
- } else if (OperandNode->isSubClassOf (" unknown_class" )) {
1658
- // Nothing to do.
1659
- } else
1660
- llvm_unreachable (" Unknown operand type!" );
1661
-
1657
+ MadeChange |= Child->UpdateNodeTypeFromInst (ChildResNo, OperandNode, TP);
1662
1658
MadeChange |= Child->ApplyTypeConstraints (TP, NotRegisters);
1663
1659
}
1664
1660
0 commit comments