Add some asserts to check SelectionDAG problems earlier.

llvm-svn: 93960
This commit is contained in:
David Greene 2010-01-20 00:59:23 +00:00
parent ad371258aa
commit 3b2a68ceb8
1 changed files with 12 additions and 0 deletions

View File

@ -5179,6 +5179,7 @@ unsigned SelectionDAG::AssignTopologicalOrder() {
allnodes_iterator Q = N; allnodes_iterator Q = N;
if (Q != SortedPos) if (Q != SortedPos)
SortedPos = AllNodes.insert(SortedPos, AllNodes.remove(Q)); SortedPos = AllNodes.insert(SortedPos, AllNodes.remove(Q));
assert(SortedPos != AllNodes.end() && "Overran node list");
++SortedPos; ++SortedPos;
} else { } else {
// Temporarily use the Node Id as scratch space for the degree count. // Temporarily use the Node Id as scratch space for the degree count.
@ -5190,22 +5191,33 @@ unsigned SelectionDAG::AssignTopologicalOrder() {
// such that by the time the end is reached all nodes will be sorted. // such that by the time the end is reached all nodes will be sorted.
for (allnodes_iterator I = allnodes_begin(),E = allnodes_end(); I != E; ++I) { for (allnodes_iterator I = allnodes_begin(),E = allnodes_end(); I != E; ++I) {
SDNode *N = I; SDNode *N = I;
// N is in sorted position, so all its uses have one less operand
// that needs to be sorted.
for (SDNode::use_iterator UI = N->use_begin(), UE = N->use_end(); for (SDNode::use_iterator UI = N->use_begin(), UE = N->use_end();
UI != UE; ++UI) { UI != UE; ++UI) {
SDNode *P = *UI; SDNode *P = *UI;
unsigned Degree = P->getNodeId(); unsigned Degree = P->getNodeId();
assert(Degree != 0 && "Invalid node degree");
--Degree; --Degree;
if (Degree == 0) { if (Degree == 0) {
// All of P's operands are sorted, so P may sorted now. // All of P's operands are sorted, so P may sorted now.
P->setNodeId(DAGSize++); P->setNodeId(DAGSize++);
if (P != SortedPos) if (P != SortedPos)
SortedPos = AllNodes.insert(SortedPos, AllNodes.remove(P)); SortedPos = AllNodes.insert(SortedPos, AllNodes.remove(P));
assert(SortedPos != AllNodes.end() && "Overran node list");
++SortedPos; ++SortedPos;
} else { } else {
// Update P's outstanding operand count. // Update P's outstanding operand count.
P->setNodeId(Degree); P->setNodeId(Degree);
} }
} }
if (I == SortedPos) {
allnodes_iterator J = I;
SDNode *S = ++J;
dbgs() << "Offending node:\n";
S->dumprFull();
assert(I != SortedPos && "Overran sorted position");
}
} }
assert(SortedPos == AllNodes.end() && assert(SortedPos == AllNodes.end() &&