Skip to content

Commit 7089c35

Browse files
[LLVM][SelectionDAG] Allow verification of target ISD nodes. (#88121)
Patch includes an initial implementation for AArch64 that covers a handful of nodes where I've observed bogus nodes within the DAG.
1 parent 58d4470 commit 7089c35

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4873,6 +4873,11 @@ class TargetLowering : public TargetLoweringBase {
48734873
bool verifyReturnAddressArgumentIsConstant(SDValue Op,
48744874
SelectionDAG &DAG) const;
48754875

4876+
#ifndef NDEBUG
4877+
/// Check the given SDNode. Aborts if it is invalid.
4878+
virtual void verifyTargetSDNode(const SDNode *N) const {};
4879+
#endif
4880+
48764881
//===--------------------------------------------------------------------===//
48774882
// Inline Asm Support hooks
48784883
//

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,9 +1111,11 @@ void SelectionDAG::DeallocateNode(SDNode *N) {
11111111

11121112
#ifndef NDEBUG
11131113
/// VerifySDNode - Check the given SDNode. Aborts if it is invalid.
1114-
static void VerifySDNode(SDNode *N) {
1114+
static void VerifySDNode(SDNode *N, const TargetLowering *TLI) {
11151115
switch (N->getOpcode()) {
11161116
default:
1117+
if (N->getOpcode() > ISD::BUILTIN_OP_END)
1118+
TLI->verifyTargetSDNode(N);
11171119
break;
11181120
case ISD::BUILD_PAIR: {
11191121
EVT VT = N->getValueType(0);
@@ -1157,7 +1159,7 @@ void SelectionDAG::InsertNode(SDNode *N) {
11571159
AllNodes.push_back(N);
11581160
#ifndef NDEBUG
11591161
N->PersistentId = NextPersistentId++;
1160-
VerifySDNode(N);
1162+
VerifySDNode(N, TLI);
11611163
#endif
11621164
for (DAGUpdateListener *DUL = UpdateListeners; DUL; DUL = DUL->Next)
11631165
DUL->NodeInserted(N);

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27868,3 +27868,46 @@ bool AArch64TargetLowering::hasInlineStackProbe(
2786827868
return !Subtarget->isTargetWindows() &&
2786927869
MF.getInfo<AArch64FunctionInfo>()->hasStackProbing();
2787027870
}
27871+
27872+
#ifndef NDEBUG
27873+
void AArch64TargetLowering::verifyTargetSDNode(const SDNode *N) const {
27874+
switch (N->getOpcode()) {
27875+
default:
27876+
break;
27877+
case AArch64ISD::SUNPKLO:
27878+
case AArch64ISD::SUNPKHI:
27879+
case AArch64ISD::UUNPKLO:
27880+
case AArch64ISD::UUNPKHI: {
27881+
assert(N->getNumValues() == 1 && "Expected one result!");
27882+
assert(N->getNumOperands() == 1 && "Expected one operand!");
27883+
EVT VT = N->getValueType(0);
27884+
EVT OpVT = N->getOperand(0).getValueType();
27885+
assert(OpVT.isVector() && VT.isVector() && OpVT.isInteger() &&
27886+
VT.isInteger() && "Expected integer vectors!");
27887+
assert(OpVT.getSizeInBits() == VT.getSizeInBits() &&
27888+
"Expected vectors of equal size!");
27889+
// TODO: Enable assert once bogus creations have been fixed.
27890+
// assert(OpVT.getVectorElementCount() == VT.getVectorElementCount()*2 &&
27891+
// "Expected result vector with half the lanes of its input!");
27892+
break;
27893+
}
27894+
case AArch64ISD::TRN1:
27895+
case AArch64ISD::TRN2:
27896+
case AArch64ISD::UZP1:
27897+
case AArch64ISD::UZP2:
27898+
case AArch64ISD::ZIP1:
27899+
case AArch64ISD::ZIP2: {
27900+
assert(N->getNumValues() == 1 && "Expected one result!");
27901+
assert(N->getNumOperands() == 2 && "Expected two operands!");
27902+
EVT VT = N->getValueType(0);
27903+
EVT Op0VT = N->getOperand(0).getValueType();
27904+
EVT Op1VT = N->getOperand(1).getValueType();
27905+
assert(VT.isVector() && Op0VT.isVector() && Op1VT.isVector() &&
27906+
"Expected vectors!");
27907+
// TODO: Enable assert once bogus creations have been fixed.
27908+
// assert(VT == Op0VT && VT == Op1VT && "Expected matching vectors!");
27909+
break;
27910+
}
27911+
}
27912+
}
27913+
#endif

llvm/lib/Target/AArch64/AArch64ISelLowering.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,10 @@ class AArch64TargetLowering : public TargetLowering {
998998
/// True if stack clash protection is enabled for this functions.
999999
bool hasInlineStackProbe(const MachineFunction &MF) const override;
10001000

1001+
#ifndef NDEBUG
1002+
void verifyTargetSDNode(const SDNode *N) const override;
1003+
#endif
1004+
10011005
private:
10021006
/// Keep a pointer to the AArch64Subtarget around so that we can
10031007
/// make the right decision when generating code for different targets.

0 commit comments

Comments
 (0)