Skip to content

Commit

Permalink
Add assertion to make sure we don't do unnecessary work in LoopFragme…
Browse files Browse the repository at this point in the history
…nt detection.
  • Loading branch information
rschatz committed Feb 23, 2018
1 parent 43a9e83 commit 31c3b3c
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,20 @@ static class WorkListEntry {
this.usages = n.usages().iterator();
this.isLoopNode = loopNodes.isMarked(n);
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof WorkListEntry)) {
return false;
}
WorkListEntry other = (WorkListEntry) obj;
return this.n == other.n;
}

@Override
public int hashCode() {
return n.hashCode();
}
}

static TriState isLoopNode(Node n, NodeBitMap loopNodes, NodeBitMap nonLoopNodes) {
Expand Down Expand Up @@ -293,11 +307,17 @@ static TriState isLoopNode(Node n, NodeBitMap loopNodes, NodeBitMap nonLoopNodes
return TriState.UNKNOWN;
}

private static void pushWorkList(Deque<WorkListEntry> workList, Node node, NodeBitMap loopNodes) {
WorkListEntry entry = new WorkListEntry(node, loopNodes);
assert !workList.contains(entry) : "node " + node + " added to worklist twice";
workList.push(entry);
}

private static void markFloating(Deque<WorkListEntry> workList, Node start, NodeBitMap loopNodes, NodeBitMap nonLoopNodes) {
if (isLoopNode(start, loopNodes, nonLoopNodes).isKnown()) {
return;
}
workList.push(new WorkListEntry(start, loopNodes));
pushWorkList(workList, start, loopNodes);
while (!workList.isEmpty()) {
WorkListEntry currentEntry = workList.peek();
if (currentEntry.usages.hasNext()) {
Expand All @@ -308,7 +328,7 @@ private static void markFloating(Deque<WorkListEntry> workList, Node start, Node
currentEntry.isLoopNode = true;
}
} else {
workList.push(new WorkListEntry(current, loopNodes));
pushWorkList(workList, current, loopNodes);
}
} else {
workList.pop();
Expand Down

0 comments on commit 31c3b3c

Please sign in to comment.