-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[SelectionDAG] Verify SDTCisVT and SDTCVecEltisVT constraints #150125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,10 @@ | |
//===----------------------------------------------------------------------===// | ||
|
||
#include "llvm/CodeGen/SDNodeInfo.h" | ||
#include "llvm/CodeGen/SelectionDAG.h" | ||
#include "llvm/CodeGen/SelectionDAGNodes.h" | ||
#include "llvm/CodeGen/TargetLowering.h" | ||
#include "llvm/CodeGen/TargetSubtargetInfo.h" | ||
|
||
using namespace llvm; | ||
|
||
|
@@ -40,6 +43,26 @@ static void checkOperandType(const SelectionDAG &DAG, const SDNode *N, | |
ExpectedVT.getEVTString() + ", got " + ActualVT.getEVTString()); | ||
} | ||
|
||
namespace { | ||
|
||
struct ConstraintOp { | ||
const SDNode *N; | ||
unsigned Idx; | ||
bool IsRes; | ||
|
||
SDValue getValue() const { | ||
return IsRes ? SDValue(const_cast<SDNode *>(N), Idx) : N->getOperand(Idx); | ||
} | ||
|
||
EVT getValueType() const { return getValue().getValueType(); } | ||
}; | ||
|
||
raw_ostream &operator<<(raw_ostream &OS, const ConstraintOp &Op) { | ||
return OS << (Op.IsRes ? "result" : "operand") << " #" << Op.Idx; | ||
} | ||
|
||
} // namespace | ||
|
||
void SDNodeInfo::verifyNode(const SelectionDAG &DAG, const SDNode *N) const { | ||
const SDNodeDesc &Desc = getDesc(N->getOpcode()); | ||
bool HasChain = Desc.hasProperty(SDNPHasChain); | ||
|
@@ -125,4 +148,86 @@ void SDNodeInfo::verifyNode(const SelectionDAG &DAG, const SDNode *N) const { | |
" must be Register or RegisterMask"); | ||
} | ||
} | ||
|
||
unsigned VTHwMode = | ||
DAG.getSubtarget().getHwMode(MCSubtargetInfo::HwMode_ValueType); | ||
|
||
auto GetConstraintOp = [&](unsigned Idx) { | ||
if (Idx < Desc.NumResults) | ||
return ConstraintOp{N, Idx, /*IsRes=*/true}; | ||
return ConstraintOp{N, HasChain + (Idx - Desc.NumResults), /*IsRes=*/false}; | ||
}; | ||
Comment on lines
+155
to
+159
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move to static member ConstraintOp::get? |
||
|
||
auto GetConstraintVT = [&](const SDTypeConstraint &C) { | ||
if (!C.NumHwModes) | ||
return static_cast<MVT::SimpleValueType>(C.VT); | ||
for (auto [Mode, VT] : ArrayRef(&VTByHwModeTable[C.VT], C.NumHwModes)) | ||
if (Mode == VTHwMode) | ||
return VT; | ||
llvm_unreachable("No value type for this HW mode"); | ||
}; | ||
|
||
SmallString<128> ES; | ||
raw_svector_ostream SS(ES); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1: preferably, yes, but this could come later? 2: I'm not sure the syntax has to be 1:1, but something to reference back to the constraint as written would be good. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, will do that after implementing more constraint checks. |
||
|
||
for (const SDTypeConstraint &C : getConstraints(N->getOpcode())) { | ||
ConstraintOp Op = GetConstraintOp(C.OpNo); | ||
EVT OpVT = Op.getValueType(); | ||
|
||
switch (C.Kind) { | ||
case SDTCisVT: { | ||
EVT ExpectedVT = GetConstraintVT(C); | ||
|
||
bool IsPtr = ExpectedVT == MVT::iPTR; | ||
if (IsPtr) | ||
ExpectedVT = | ||
DAG.getTargetLoweringInfo().getPointerTy(DAG.getDataLayout()); | ||
|
||
if (OpVT != ExpectedVT) { | ||
SS << Op << " must have type " << ExpectedVT; | ||
if (IsPtr) | ||
SS << " (iPTR)"; | ||
SS << ", but has type " << OpVT; | ||
reportNodeError(DAG, N, SS.str()); | ||
} | ||
break; | ||
} | ||
case SDTCisPtrTy: | ||
break; | ||
case SDTCisInt: | ||
break; | ||
case SDTCisFP: | ||
break; | ||
case SDTCisVec: | ||
break; | ||
case SDTCisSameAs: | ||
break; | ||
case SDTCisVTSmallerThanOp: | ||
break; | ||
case SDTCisOpSmallerThanOp: | ||
break; | ||
case SDTCisEltOfVec: | ||
break; | ||
case SDTCisSubVecOfVec: | ||
break; | ||
case SDTCVecEltisVT: { | ||
EVT ExpectedVT = GetConstraintVT(C); | ||
|
||
if (!OpVT.isVector()) { | ||
SS << Op << " must have vector type"; | ||
reportNodeError(DAG, N, SS.str()); | ||
} | ||
if (OpVT.getVectorElementType() != ExpectedVT) { | ||
SS << Op << " must have " << ExpectedVT << " element type, but has " | ||
<< OpVT.getVectorElementType() << " element type"; | ||
reportNodeError(DAG, N, SS.str()); | ||
} | ||
break; | ||
} | ||
case SDTCisSameNumEltsAs: | ||
break; | ||
case SDTCisSameSizeAs: | ||
break; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of all targets, only RISCV and LoongArch got a non-empty (two element) table.