Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 4c16916

Browse files
committed
Extract a method.
This computes the type of an instruction operand or result based on the records in the instruction's ins and outs lists. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@177244 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 8ee1c1c commit 4c16916

File tree

2 files changed

+42
-41
lines changed

2 files changed

+42
-41
lines changed

utils/TableGen/CodeGenDAGPatterns.cpp

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,40 @@ bool SDTypeConstraint::ApplyTypeConstraint(TreePatternNode *N,
956956
llvm_unreachable("Invalid ConstraintType!");
957957
}
958958

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+
959993
//===----------------------------------------------------------------------===//
960994
// SDNodeInfo implementation
961995
//
@@ -1575,26 +1609,8 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
15751609
// (outs) list of the instruction.
15761610
// FIXME: Cap at one result so far.
15771611
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);
15981614

15991615
// If the instruction has implicit defs, we apply the first one as a result.
16001616
// FIXME: This sucks, it should apply all implicit defs.
@@ -1636,29 +1652,9 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
16361652
return false;
16371653
}
16381654

1639-
MVT::SimpleValueType VT;
16401655
TreePatternNode *Child = getChild(ChildNo++);
16411656
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);
16621658
MadeChange |= Child->ApplyTypeConstraints(TP, NotRegisters);
16631659
}
16641660

utils/TableGen/CodeGenDAGPatterns.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,11 @@ class TreePatternNode {
463463
return Types[ResNo].MergeInTypeInfo(EEVT::TypeSet(InTy, TP), TP);
464464
}
465465

466+
// Update node type with types inferred from an instruction operand or result
467+
// def from the ins/outs lists.
468+
// Return true if the type changed.
469+
bool UpdateNodeTypeFromInst(unsigned ResNo, Record *Operand, TreePattern &TP);
470+
466471
/// ContainsUnresolvedType - Return true if this tree contains any
467472
/// unresolved types.
468473
bool ContainsUnresolvedType() const {

0 commit comments

Comments
 (0)