aboutsummaryrefslogtreecommitdiff
path: root/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
diff options
context:
space:
mode:
authorSergei Barannikov <barannikov88@gmail.com>2025-01-22 09:01:08 +0300
committerGitHub <noreply@github.com>2025-01-22 09:01:08 +0300
commit6aeffcdb913052e43335130e129e36babaa9b252 (patch)
tree5ec42abb1fac7a819bfc35443a2f564b87130c70 /llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
parent382bafc9579f40bd834b78df671ac45308310462 (diff)
downloadllvm-6aeffcdb913052e43335130e129e36babaa9b252.zip
llvm-6aeffcdb913052e43335130e129e36babaa9b252.tar.gz
llvm-6aeffcdb913052e43335130e129e36babaa9b252.tar.bz2
[TableGen] Add a backend generating SDNode descriptions (#123002)
This patch adds a simplistic backend that gathers all target-specific SelectionDAG nodes and emits descriptions for most of them. This includes generating node enumeration, node names, and information about node "prototype" that can be used to verify that a node is valid. The patch also extends SDNode by adding target-specific flags, which are also included in the generated tables. Part of #119709, [RFC](https://discourse.llvm.org/t/rfc-tablegen-erating-sdnode-descriptions/83627). Pull Request: https://github.com/llvm/llvm-project/pull/123002
Diffstat (limited to 'llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp')
-rw-r--r--llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp104
1 files changed, 80 insertions, 24 deletions
diff --git a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
index 013135a..59148a9 100644
--- a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
@@ -1537,21 +1537,19 @@ SDTypeConstraint::SDTypeConstraint(const Record *R, const CodeGenHwModes &CGH) {
ConstraintType = SDTCisVec;
} else if (R->isSubClassOf("SDTCisSameAs")) {
ConstraintType = SDTCisSameAs;
- x.SDTCisSameAs_Info.OtherOperandNum = R->getValueAsInt("OtherOperandNum");
+ OtherOperandNo = R->getValueAsInt("OtherOperandNum");
} else if (R->isSubClassOf("SDTCisVTSmallerThanOp")) {
ConstraintType = SDTCisVTSmallerThanOp;
- x.SDTCisVTSmallerThanOp_Info.OtherOperandNum =
- R->getValueAsInt("OtherOperandNum");
+ OtherOperandNo = R->getValueAsInt("OtherOperandNum");
} else if (R->isSubClassOf("SDTCisOpSmallerThanOp")) {
ConstraintType = SDTCisOpSmallerThanOp;
- x.SDTCisOpSmallerThanOp_Info.BigOperandNum =
- R->getValueAsInt("BigOperandNum");
+ OtherOperandNo = R->getValueAsInt("BigOperandNum");
} else if (R->isSubClassOf("SDTCisEltOfVec")) {
ConstraintType = SDTCisEltOfVec;
- x.SDTCisEltOfVec_Info.OtherOperandNum = R->getValueAsInt("OtherOpNum");
+ OtherOperandNo = R->getValueAsInt("OtherOpNum");
} else if (R->isSubClassOf("SDTCisSubVecOfVec")) {
ConstraintType = SDTCisSubVecOfVec;
- x.SDTCisSubVecOfVec_Info.OtherOperandNum = R->getValueAsInt("OtherOpNum");
+ OtherOperandNo = R->getValueAsInt("OtherOpNum");
} else if (R->isSubClassOf("SDTCVecEltisVT")) {
ConstraintType = SDTCVecEltisVT;
VVT = getValueTypeByHwMode(R->getValueAsDef("VT"), CGH);
@@ -1566,12 +1564,10 @@ SDTypeConstraint::SDTypeConstraint(const Record *R, const CodeGenHwModes &CGH) {
}
} else if (R->isSubClassOf("SDTCisSameNumEltsAs")) {
ConstraintType = SDTCisSameNumEltsAs;
- x.SDTCisSameNumEltsAs_Info.OtherOperandNum =
- R->getValueAsInt("OtherOperandNum");
+ OtherOperandNo = R->getValueAsInt("OtherOperandNum");
} else if (R->isSubClassOf("SDTCisSameSizeAs")) {
ConstraintType = SDTCisSameSizeAs;
- x.SDTCisSameSizeAs_Info.OtherOperandNum =
- R->getValueAsInt("OtherOperandNum");
+ OtherOperandNo = R->getValueAsInt("OtherOperandNum");
} else {
PrintFatalError(R->getLoc(),
"Unrecognized SDTypeConstraint '" + R->getName() + "'!\n");
@@ -1632,7 +1628,7 @@ bool SDTypeConstraint::ApplyTypeConstraint(TreePatternNode &N,
case SDTCisSameAs: {
unsigned OResNo = 0;
TreePatternNode &OtherNode =
- getOperandNum(x.SDTCisSameAs_Info.OtherOperandNum, N, NodeInfo, OResNo);
+ getOperandNum(OtherOperandNo, N, NodeInfo, OResNo);
return (int)NodeToApply.UpdateNodeType(ResNo, OtherNode.getExtType(OResNo),
TP) |
(int)OtherNode.UpdateNodeType(OResNo, NodeToApply.getExtType(ResNo),
@@ -1654,23 +1650,23 @@ bool SDTypeConstraint::ApplyTypeConstraint(TreePatternNode &N,
TypeSetByHwMode TypeListTmp(VVT);
unsigned OResNo = 0;
- TreePatternNode &OtherNode = getOperandNum(
- x.SDTCisVTSmallerThanOp_Info.OtherOperandNum, N, NodeInfo, OResNo);
+ TreePatternNode &OtherNode =
+ getOperandNum(OtherOperandNo, N, NodeInfo, OResNo);
return TI.EnforceSmallerThan(TypeListTmp, OtherNode.getExtType(OResNo),
/*SmallIsVT*/ true);
}
case SDTCisOpSmallerThanOp: {
unsigned BResNo = 0;
- TreePatternNode &BigOperand = getOperandNum(
- x.SDTCisOpSmallerThanOp_Info.BigOperandNum, N, NodeInfo, BResNo);
+ TreePatternNode &BigOperand =
+ getOperandNum(OtherOperandNo, N, NodeInfo, BResNo);
return TI.EnforceSmallerThan(NodeToApply.getExtType(ResNo),
BigOperand.getExtType(BResNo));
}
case SDTCisEltOfVec: {
unsigned VResNo = 0;
- TreePatternNode &VecOperand = getOperandNum(
- x.SDTCisEltOfVec_Info.OtherOperandNum, N, NodeInfo, VResNo);
+ TreePatternNode &VecOperand =
+ getOperandNum(OtherOperandNo, N, NodeInfo, VResNo);
// Filter vector types out of VecOperand that don't have the right element
// type.
return TI.EnforceVectorEltTypeIs(VecOperand.getExtType(VResNo),
@@ -1678,8 +1674,8 @@ bool SDTypeConstraint::ApplyTypeConstraint(TreePatternNode &N,
}
case SDTCisSubVecOfVec: {
unsigned VResNo = 0;
- TreePatternNode &BigVecOperand = getOperandNum(
- x.SDTCisSubVecOfVec_Info.OtherOperandNum, N, NodeInfo, VResNo);
+ TreePatternNode &BigVecOperand =
+ getOperandNum(OtherOperandNo, N, NodeInfo, VResNo);
// Filter vector types out of BigVecOperand that don't have the
// right subvector type.
@@ -1691,15 +1687,15 @@ bool SDTypeConstraint::ApplyTypeConstraint(TreePatternNode &N,
}
case SDTCisSameNumEltsAs: {
unsigned OResNo = 0;
- TreePatternNode &OtherNode = getOperandNum(
- x.SDTCisSameNumEltsAs_Info.OtherOperandNum, N, NodeInfo, OResNo);
+ TreePatternNode &OtherNode =
+ getOperandNum(OtherOperandNo, N, NodeInfo, OResNo);
return TI.EnforceSameNumElts(OtherNode.getExtType(OResNo),
NodeToApply.getExtType(ResNo));
}
case SDTCisSameSizeAs: {
unsigned OResNo = 0;
- TreePatternNode &OtherNode = getOperandNum(
- x.SDTCisSameSizeAs_Info.OtherOperandNum, N, NodeInfo, OResNo);
+ TreePatternNode &OtherNode =
+ getOperandNum(OtherOperandNo, N, NodeInfo, OResNo);
return TI.EnforceSameSize(OtherNode.getExtType(OResNo),
NodeToApply.getExtType(ResNo));
}
@@ -1707,6 +1703,58 @@ bool SDTypeConstraint::ApplyTypeConstraint(TreePatternNode &N,
llvm_unreachable("Invalid ConstraintType!");
}
+bool llvm::operator==(const SDTypeConstraint &LHS,
+ const SDTypeConstraint &RHS) {
+ if (std::tie(LHS.OperandNo, LHS.ConstraintType) !=
+ std::tie(RHS.OperandNo, RHS.ConstraintType))
+ return false;
+ switch (LHS.ConstraintType) {
+ case SDTypeConstraint::SDTCisVT:
+ case SDTypeConstraint::SDTCVecEltisVT:
+ return LHS.VVT == RHS.VVT;
+ case SDTypeConstraint::SDTCisPtrTy:
+ case SDTypeConstraint::SDTCisInt:
+ case SDTypeConstraint::SDTCisFP:
+ case SDTypeConstraint::SDTCisVec:
+ break;
+ case SDTypeConstraint::SDTCisSameAs:
+ case SDTypeConstraint::SDTCisVTSmallerThanOp:
+ case SDTypeConstraint::SDTCisOpSmallerThanOp:
+ case SDTypeConstraint::SDTCisEltOfVec:
+ case SDTypeConstraint::SDTCisSubVecOfVec:
+ case SDTypeConstraint::SDTCisSameNumEltsAs:
+ case SDTypeConstraint::SDTCisSameSizeAs:
+ return LHS.OtherOperandNo == RHS.OtherOperandNo;
+ }
+ return true;
+}
+
+bool llvm::operator<(const SDTypeConstraint &LHS, const SDTypeConstraint &RHS) {
+ if (std::tie(LHS.OperandNo, LHS.ConstraintType) !=
+ std::tie(RHS.OperandNo, RHS.ConstraintType))
+ return std::tie(LHS.OperandNo, LHS.ConstraintType) <
+ std::tie(RHS.OperandNo, RHS.ConstraintType);
+ switch (LHS.ConstraintType) {
+ case SDTypeConstraint::SDTCisVT:
+ case SDTypeConstraint::SDTCVecEltisVT:
+ return LHS.VVT < RHS.VVT;
+ case SDTypeConstraint::SDTCisPtrTy:
+ case SDTypeConstraint::SDTCisInt:
+ case SDTypeConstraint::SDTCisFP:
+ case SDTypeConstraint::SDTCisVec:
+ break;
+ case SDTypeConstraint::SDTCisSameAs:
+ case SDTypeConstraint::SDTCisVTSmallerThanOp:
+ case SDTypeConstraint::SDTCisOpSmallerThanOp:
+ case SDTypeConstraint::SDTCisEltOfVec:
+ case SDTypeConstraint::SDTCisSubVecOfVec:
+ case SDTypeConstraint::SDTCisSameNumEltsAs:
+ case SDTypeConstraint::SDTCisSameSizeAs:
+ return LHS.OtherOperandNo < RHS.OtherOperandNo;
+ }
+ return false;
+}
+
// Update the node type to match an instruction operand or result as specified
// in the ins or outs lists on the instruction definition. Return true if the
// type was actually changed.
@@ -1797,6 +1845,14 @@ SDNodeInfo::SDNodeInfo(const Record *R, const CodeGenHwModes &CGH) : Def(R) {
// Parse the properties.
Properties = parseSDPatternOperatorProperties(R);
+ IsStrictFP = R->getValueAsBit("IsStrictFP");
+
+ std::optional<int64_t> MaybeTSFlags =
+ R->getValueAsBitsInit("TSFlags")->convertInitializerToInt();
+ if (!MaybeTSFlags)
+ PrintFatalError(R->getLoc(), "Invalid TSFlags");
+ assert(isUInt<32>(*MaybeTSFlags) && "TSFlags bit width out of sync");
+ TSFlags = *MaybeTSFlags;
// Parse the type constraints.
for (const Record *R : TypeProfile->getValueAsListOfDefs("Constraints"))